diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 04df52c4b5e..27cbd78f533 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,13 @@ +2002-01-15 Tom Tromey + + * java/lang/Float.java (equals): Preserve old code. + * java/lang/Double.java (equals): Preserve old code. + +2002-01-15 Eric Blake + + * java/lang/Double.java (equals, compare): Fix 0.0 vs. -0.0 math. + * java/lang/Float.java (equals, compare): Ditto. + 2002-01-13 Mark Wielaard * java/net/DatagramSocket.java (getReceiveBufferSize): new 1.2 method. diff --git a/libjava/java/lang/Double.java b/libjava/java/lang/Double.java index 773e8824e55..87f5d03bf05 100644 --- a/libjava/java/lang/Double.java +++ b/libjava/java/lang/Double.java @@ -1,5 +1,5 @@ /* Double.java -- object wrapper for double primitive - Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -163,9 +163,12 @@ public final class Double extends Number implements Comparable if (!(obj instanceof Double)) return false; - Double d = (Double) obj; + double d = ((Double) obj).value; - return doubleToLongBits (value) == doubleToLongBits (d.doubleValue ()); + // GCJ LOCAL: this implementation is probably faster than + // Classpath's, especially once we inline doubleToLongBits. + return doubleToLongBits (value) == doubleToLongBits (d); + // END GCJ LOCAL } /** @@ -334,10 +337,9 @@ public final class Double extends Number implements Comparable return isNaN (y) ? 0 : 1; if (isNaN (y)) return -1; - if (x == 0.0d && y == -0.0d) - return 1; - if (x == -0.0d && y == 0.0d) - return -1; + // recall that 0.0 == -0.0, so we convert to infinites and try again + if (x == 0 && y == 0) + return (int) (1 / x - 1 / y); if (x == y) return 0; diff --git a/libjava/java/lang/Float.java b/libjava/java/lang/Float.java index e44503fbcd4..65caf430f54 100644 --- a/libjava/java/lang/Float.java +++ b/libjava/java/lang/Float.java @@ -1,5 +1,5 @@ /* java.lang.Float - Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -232,9 +232,12 @@ public final class Float extends Number implements Comparable if (!(obj instanceof Float)) return false; - Float f = (Float) obj; + float f = ((Float) obj).value; - return floatToIntBits (value) == floatToIntBits (f.floatValue ()); + // GCJ LOCAL: this implementation is probably faster than + // Classpath's, especially once we inline floatToIntBits. + return floatToIntBits (value) == floatToIntBits (f); + // END GCJ LOCAL } /** @@ -484,10 +487,9 @@ public final class Float extends Number implements Comparable return isNaN (y) ? 0 : 1; if (isNaN (y)) return -1; - if (x == 0.0 && y == -0.0) - return 1; - if (x == -0.0 && y == 0.0) - return -1; + // recall that 0.0 == -0.0, so we convert to infinities and try again + if (x == 0 && y == 0) + return (int) (1 / x - 1 / y); if (x == y) return 0;