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:
@@ -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() );
|
||||
}
|
||||
}
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user