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:
Ian Farmer
2008-06-02 04:18:42 +00:00
parent 807541ace2
commit ef2c087c1b
2 changed files with 15 additions and 6 deletions

View File

@@ -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 );

View File

@@ -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) )