While loading chunks, check if double values can be represented as integers,

and load them as LIntegers instead of LDoubles if so. Also change test2 so that
it does not fail because of the rounding problem. With these changes, 4 out of
7 test cases in LuaJTest now pass.
This commit is contained in:
Ian Farmer
2007-07-09 01:31:31 +00:00
parent 241edfbf37
commit 62022d5881
4 changed files with 115 additions and 4 deletions

View File

@@ -189,14 +189,33 @@ public class LoadState {
return new LString( s );
}
static LNumber longBitsToLuaNumber( long bits ) {
if ( ( bits & ( ( 1L << 63 ) - 1 ) ) == 0L ) {
return new LInteger( 0 );
}
int e = (int)((bits >> 52) & 0x7ffL) - 1023;
if ( e >= 0 && e < 31 ) {
long f = bits & 0xFFFFFFFFFFFFFL;
int shift = 52 - e;
long intPrecMask = ( 1L << shift ) - 1;
if ( ( f & intPrecMask ) == 0 ) {
int intValue = (int)( f >> shift ) | ( 1 << e );
return new LInteger( ( ( bits >> 63 ) != 0 ) ? -intValue : intValue );
}
}
double value = Double.longBitsToDouble(bits);
return new LDouble( value );
}
LNumber loadNumber() throws IOException {
if ( this.luacIsNumberIntegral ) {
int value = loadInt();
return new LInteger( value );
} else {
long bits = loadInt64();
double value = Double.longBitsToDouble(bits);
return new LDouble( value );
return longBitsToLuaNumber( loadInt64() );
}
}
//