From f0fdd66ba4fa07d5ef314eab9aee404750ae3ef4 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Sat, 20 Oct 2001 06:26:45 +0000 Subject: [PATCH] Double.java: More Classpath merging * java/lang/Double.java: More Classpath merging (isInfinite): Don't use doubleToLongBits (isNaN (Object)): return v != v (initIDs): make native * java/lang/Float.java: Ditto (isInfinite): Don't use floatToIntBits (isNaN (Object)): return v != v * java/lang/natDouble.cc: add empty initIDs() From-SVN: r46370 --- libjava/ChangeLog | 11 +++++++++++ libjava/java/lang/Double.java | 23 +++++++++++++---------- libjava/java/lang/Float.java | 21 ++++++++++++--------- libjava/java/lang/natDouble.cc | 6 ++++++ 4 files changed, 42 insertions(+), 19 deletions(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 2554add64f4..3e8675fb6d8 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,14 @@ +2001-10-19 Mark Wielaard + + * java/lang/Double.java: More Classpath merging + (isInfinite): Don't use doubleToLongBits + (isNaN (Object)): return v != v + (initIDs): make native + * java/lang/Float.java: Ditto + (isInfinite): Don't use floatToIntBits + (isNaN (Object)): return v != v + * java/lang/natDouble.cc: add empty initIDs() + 2001-10-19 Mark Wielaard * javax/naming/BinaryRefAddr.java: New file diff --git a/libjava/java/lang/Double.java b/libjava/java/lang/Double.java index caaa406d133..63ee265924e 100644 --- a/libjava/java/lang/Double.java +++ b/libjava/java/lang/Double.java @@ -146,6 +146,14 @@ public final class Double extends Number implements Comparable * instanceof Double, and represents * the same primitive double value return * true. Otherwise false is returned. + *

+ * Note that there are two differences between == and + * equals(). 0.0d == -0.0d returns true + * but new Double(0.0d).equals(new Double(-0.0d)) returns + * false. And Double.NaN == Double.NaN returns + * false, but + * new Double(Double.NaN).equals(new Double(Double.NaN)) returns + * true. * * @param obj the object to compare to * @return whether the objects are semantically equal. @@ -248,11 +256,9 @@ public final class Double extends Number implements Comparable */ public static boolean isNaN (double v) { - long bits = doubleToLongBits (v); - long e = bits & 0x7ff0000000000000L; - long f = bits & 0x000fffffffffffffL; - - return e == 0x7ff0000000000000L && f != 0L; + // This works since NaN != NaN is the only reflexive inequality + // comparison which returns true. + return v != v; } /** @@ -277,10 +283,7 @@ public final class Double extends Number implements Comparable */ public static boolean isInfinite (double v) { - long bits = doubleToLongBits (v); - long f = bits & 0x7fffffffffffffffL; - - return f == 0x7ff0000000000000L; + return (v == POSITIVE_INFINITY || v == NEGATIVE_INFINITY); } /** @@ -508,5 +511,5 @@ public final class Double extends Number implements Comparable * Initialize JNI cache. This method is called only by the * static initializer when using JNI. */ - private static void initIDs () { /* Not used in libgcj */ }; + private static native void initIDs (); } diff --git a/libjava/java/lang/Float.java b/libjava/java/lang/Float.java index 91da0754d60..9e26143f773 100644 --- a/libjava/java/lang/Float.java +++ b/libjava/java/lang/Float.java @@ -215,6 +215,14 @@ public final class Float extends Number implements Comparable * instanceof Float, and represents * the same primitive float value return * true. Otherwise false is returned. + *

+ * Note that there are two differences between == and + * equals(). 0.0f == -0.0f returns true + * but new Float(0.0f).equals(new Float(-0.0f)) returns + * false. And Float.NaN == Float.NaN returns + * false, but + * new Float(Float.NaN).equals(new Float(Float.NaN)) returns + * true. * * @param obj the object to compare to * @return whether the objects are semantically equal. @@ -364,11 +372,9 @@ public final class Float extends Number implements Comparable */ public static boolean isNaN (float v) { - int bits = floatToIntBits (v); - int e = bits & 0x7f800000; - int f = bits & 0x007fffff; - - return e == 0x7f800000 && f != 0; + // This works since NaN != NaN is the only reflexive inequality + // comparison which returns true. + return v != v; } /** @@ -393,10 +399,7 @@ public final class Float extends Number implements Comparable */ public static boolean isInfinite (float v) { - int bits = floatToIntBits (v); - int f = bits & 0x7fffffff; - - return f == 0x7f800000; + return (v == POSITIVE_INFINITY || v == NEGATIVE_INFINITY); } /** diff --git a/libjava/java/lang/natDouble.cc b/libjava/java/lang/natDouble.cc index 7e8e0b74797..b0b24a7547c 100644 --- a/libjava/java/lang/natDouble.cc +++ b/libjava/java/lang/natDouble.cc @@ -186,3 +186,9 @@ java::lang::Double::parseDouble(jstring str) } throw new NumberFormatException; } + +void +java::lang::Double::initIDs() +{ + // Not used in libgcj +} -- 2.30.2