Number fixes.
(1) Change how LDouble computes hashCode to match standard Lua.
(2) Change how toJavaString deals with NaN, infinity, and -0.
(3) Move 0 * -2 case to end of mathlib test case so that problematic tests
are towards the end.
This commit is contained in:
@@ -35,14 +35,23 @@ public class LDouble extends LNumber {
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return (int) m_value;
|
||||
if ( m_value == 0 ) {
|
||||
return 0;
|
||||
} else {
|
||||
long bits = Double.doubleToLongBits( m_value );
|
||||
return ( (int) bits >> 32 ) + ( (int) bits );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String toJavaString() {
|
||||
if ( Double.isNaN(m_value) )
|
||||
return "-1.#IND";
|
||||
return "nan";
|
||||
if ( Double.isInfinite(m_value) )
|
||||
return (m_value>0? "1.#INF": "-1.#INF");
|
||||
return (m_value>0? "inf": "-inf");
|
||||
if ( m_value == 0.0 ) {
|
||||
long bits = Double.doubleToLongBits( m_value );
|
||||
return ( bits >> 63 == 0 ) ? "0" : "-0";
|
||||
}
|
||||
long l = (long) m_value;
|
||||
if ( (m_value == (double) l) && (m_value <= Long.MAX_VALUE) && (m_value >= Long.MIN_VALUE) ) {
|
||||
return Long.toString( l );
|
||||
|
||||
@@ -17,7 +17,6 @@ function binops( a, b )
|
||||
return '--'
|
||||
end
|
||||
print( pcall( binops, 2, 0 ) )
|
||||
print( pcall( binops, -2, 0 ) )
|
||||
print( pcall( binops, 2.5, 0 ) )
|
||||
print( pcall( binops, -2.5, 0 ) )
|
||||
print( pcall( binops, 2, 1 ) )
|
||||
@@ -41,9 +40,10 @@ print( pcall( binops, 2.25, 0 ) )
|
||||
print( pcall( binops, 2.25, 2 ) )
|
||||
print( pcall( binops, 2.25, .5 ) )
|
||||
print( pcall( binops, 2.25, 2.5 ) )
|
||||
|
||||
print( pcall( binops, -2, 0 ) )
|
||||
|
||||
-- random tests
|
||||
print("Random tests")
|
||||
print( math.random(5,10) )
|
||||
print( math.random(5,10) )
|
||||
print( math.random(5,10) )
|
||||
|
||||
Reference in New Issue
Block a user