Double.java: More Classpath merging
authorMark Wielaard <mark@klomp.org>
Sat, 20 Oct 2001 06:26:45 +0000 (06:26 +0000)
committerMark Wielaard <mark@gcc.gnu.org>
Sat, 20 Oct 2001 06:26:45 +0000 (06:26 +0000)
* 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
libjava/java/lang/Double.java
libjava/java/lang/Float.java
libjava/java/lang/natDouble.cc

index 2554add64f4497f9cad5073933be8fe0115083b2..3e8675fb6d8b519eb7841cf8836c9040669777d0 100644 (file)
@@ -1,3 +1,14 @@
+2001-10-19  Mark Wielaard  <mark@klomp.org>
+
+       * 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  <mark@klomp.org>
 
        * javax/naming/BinaryRefAddr.java: New file
index caaa406d1334d1ce4be551e0027675730cbc250d..63ee265924edad9130caf542c737dbde09490b8b 100644 (file)
@@ -146,6 +146,14 @@ public final class Double extends Number implements Comparable
    * <code>instanceof</code> <code>Double</code>, and represents
    * the same primitive <code>double</code> value return 
    * <code>true</code>.  Otherwise <code>false</code> is returned.
+   * <p>
+   * Note that there are two differences between <code>==</code> and
+   * <code>equals()</code>. <code>0.0d == -0.0d</code> returns <code>true</code>
+   * but <code>new Double(0.0d).equals(new Double(-0.0d))</code> returns
+   * <code>false</code>. And <code>Double.NaN == Double.NaN</code> returns
+   * <code>false</code>, but
+   * <code>new Double(Double.NaN).equals(new Double(Double.NaN))</code> returns
+   * <code>true</code>.
    *
    * @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 ();
 }
index 91da0754d6000081b768942a63db93776d160173..9e26143f77374100240434abe95d341cbe55c2be 100644 (file)
@@ -215,6 +215,14 @@ public final class Float extends Number implements Comparable
    * <code>instanceof</code> <code>Float</code>, and represents
    * the same primitive <code>float</code> value return 
    * <code>true</code>.  Otherwise <code>false</code> is returned.
+   * <p>
+   * Note that there are two differences between <code>==</code> and
+   * <code>equals()</code>. <code>0.0f == -0.0f</code> returns <code>true</code>
+   * but <code>new Float(0.0f).equals(new Float(-0.0f))</code> returns
+   * <code>false</code>. And <code>Float.NaN == Float.NaN</code> returns
+   * <code>false</code>, but
+   * <code>new Float(Float.NaN).equals(new Float(Float.NaN))</code> returns
+   * <code>true</code>.
    *
    * @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);
   }
 
   /**
index 7e8e0b74797c779b0678a8290a5dde95c568e1c9..b0b24a7547c2fbd829fa264964cfaa7f6f958ab1 100644 (file)
@@ -186,3 +186,9 @@ java::lang::Double::parseDouble(jstring str)
     }
   throw new NumberFormatException;
 }
+
+void
+java::lang::Double::initIDs()
+{
+  // Not used in libgcj
+}