Coerce doubles into integers wherever possible, use hash code for doubles that is compatible with integers.

This commit is contained in:
James Roseborough
2009-05-22 14:51:42 +00:00
parent a55ddfa2d9
commit c4b2ab86f7
11 changed files with 26 additions and 20 deletions

View File

@@ -54,13 +54,7 @@ public class LoadStateTest extends TestCase {
private LNumber simpleBitsToLuaNumber( long bits ) {
double value = Double.longBitsToDouble( bits );
int valueAsInt = (int) value;
if ( value == (double) valueAsInt ) {
return LInteger.valueOf( valueAsInt );
} else {
return new LDouble( value );
}
return LDouble.numberOf(value);
}
public void testLongBitsToLuaNumberSpeed() throws InterruptedException {

View File

@@ -228,8 +228,8 @@ public class MathLibTest extends TestCase {
private void tryMathOp(int id, double a, double b) {
try {
double expected = j2se.mathop(id, LDouble.valueOf(a), LDouble.valueOf(b)).toJavaDouble();
double actual = j2me.mathop(id, LDouble.valueOf(a), LDouble.valueOf(b)).toJavaDouble();
double expected = j2se.mathop(id, LDouble.numberOf(a), LDouble.numberOf(b)).toJavaDouble();
double actual = j2me.mathop(id, LDouble.numberOf(a), LDouble.numberOf(b)).toJavaDouble();
if ( supportedOnJ2me )
assertEquals( expected, actual, 1.e-5 );
else

View File

@@ -209,4 +209,16 @@ for i,test in ipairs(tests) do
print( 't[nil]', pcall( function() return testtable[nil] end ) )
print( 't[nil]=nil', pcall( function() testtable[nil]=nil end ) )
print( 't[nil]', pcall( function() return testtable[nil] end ) )
end
end
-- tables with doubles
local t = { [1]='a', [2]='b', [3.0]='c', [7]='d', [9]='e', [20]='f', [30.0]='g', [12.5]='h' }
print(#t)
print(t[1], t[2], t[3], t[7], t[9], t[20], t[30])
print(t[1.0], t[2.0], t[3.0], t[7.0], t[9.0], t[20.0], t[30.0], t[12.5])
local i,j,k,l,m,n,o = math.ceil(0.7),math.floor(2.1),math.abs(-3.0),math.sqrt(49.0),math.ceil(8.6),math.floor(20.5),math.max(1.2,30.0)
print(i, j, k, l, m, n, o)
print(t[i], t[j], t[k], t[l], t[m], t[n], t[o])
local half,two = .5,2
print(t[1.5-half], t[1.5+half], t[6/2], t[3.5*2], t[8.5+half], t[20.5-half], t[60*half], t[13-half])
print(#t)