This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

floatToRawIntBits, doubleToRawLongBits, + cleanups.


We were missing the Float.floatToRawIntBits and
Double.doubleToRawLongBits methods; this patch adds them. Presumably
these are supposed to be different to their non-raw counterparts
somehow, but I can't figure out how. The JDK seems to return the same
values for all the inputs I've tried, including NaN. Also, I cleaned
up a bunch of redunant null and instanceof checks in the
java/lang/Number classes.

Checking this in.

regards

  [ bryce ]


2001-02-08  Bryce McKinlay  <bryce@albatross.co.nz>

	* java/lang/Byte.java: Remove redundant instanceof and null checks.
	* java/lang/Integer.java: Likewise.
	* java/lang/Long.java: Likewise.
	* java/lang/Short.java: Likewise.
	* java/lang/Double.java: Likewise.
	(doubleToRawLongBits): New method.
	* java/lang/Float.java: As above.
	(floatToRawIntBits): New method.

Index: Byte.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/lang/Byte.java,v
retrieving revision 1.4
diff -u -r1.4 Byte.java
--- Byte.java	2000/09/08 19:37:08	1.4
+++ Byte.java	2001/02/09 02:44:36
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998, 1999, 2000  Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -115,17 +115,15 @@
   }
 
   // Added in JDK 1.2
-  public int compareTo(Object o) throws ClassCastException
+  /** @throws ClassCastException */
+  public int compareTo(Object o)
   {
-    if (o instanceof Byte)
-      return this.value - ((Byte) o).value;
-    else
-      throw new ClassCastException();
+    return this.value - ((Byte) o).value;
   }
 
   public boolean equals(Object obj)
   {
-    return obj != null && (obj instanceof Byte) && ((Byte)obj).value == value;
+    return (obj instanceof Byte) && ((Byte)obj).value == value;
   }
 
   // Verified that hashCode is returns plain value (see Boolean_1 test).
Index: Double.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/lang/Double.java,v
retrieving revision 1.7
diff -u -r1.7 Double.java
--- Double.java	2000/11/17 04:51:25	1.7
+++ Double.java	2001/02/09 02:44:36
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998, 1999, 2000  Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -54,9 +54,6 @@
 
   public boolean equals (Object obj)
   {
-    if (obj == null)
-      return false;
-
     if (!(obj instanceof Double))
       return false;
 
@@ -108,12 +105,8 @@
     return toString (v, false);
   }
 
-  public static Double valueOf (String s) throws NullPointerException, 
-    NumberFormatException
+  public static Double valueOf (String s) throws NumberFormatException
   {
-    if (s == null)
-      throw new NullPointerException ();
-
     return new Double (parseDouble (s));
   }
 
@@ -145,6 +138,12 @@
   }
 
   public static native long doubleToLongBits (double value);
+
+  public static long doubleToRawLongBits (double value)
+  {
+    // FIXME: Check that this is correct with respect to NaN values.
+    return doubleToLongBits (value);
+  }
 
   public static native double longBitsToDouble (long bits);
 
Index: Float.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/lang/Float.java,v
retrieving revision 1.6
diff -u -r1.6 Float.java
--- Float.java	2001/02/09 02:21:27	1.6
+++ Float.java	2001/02/09 02:44:36
@@ -64,9 +64,6 @@
 
   public boolean equals (Object obj)
   {
-    if (obj == null)
-      return false;
-
     if (!(obj instanceof Float))
       return false;
 
@@ -115,12 +112,8 @@
     return Double.toString ((double) v, true);
   } 
 
-  public static Float valueOf (String s) throws NullPointerException, 
-    NumberFormatException
+  public static Float valueOf (String s) throws NumberFormatException
   {
-    if (s == null)
-      throw new NullPointerException ();
-
     return new Float (Double.valueOf (s).floatValue ());
   }
 
@@ -152,6 +145,13 @@
   }
 
   public static native int floatToIntBits (float value);
+  
+  public static int floatToRawIntBits (float value)
+  {
+    // FIXME: Is this supposed to be different? NaN values seem to be handled
+    // the same in the JDK.
+    return floatToIntBits (value);
+  }
 
   public static native float intBitsToFloat (int bits);
 
Index: Integer.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/lang/Integer.java,v
retrieving revision 1.5
diff -u -r1.5 Integer.java
--- Integer.java	2000/09/08 19:37:08	1.5
+++ Integer.java	2001/02/09 02:44:36
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998, 1999, 2000  Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -86,11 +86,9 @@
   }
 
   // Added in JDK 1.2
+  /** @throws ClassCastException */
   public int compareTo(Object o) throws ClassCastException
   {
-    if (!(o instanceof Integer))
-      throw new ClassCastException();
-
     return this.compareTo((Integer) o);
   }
 
@@ -101,7 +99,7 @@
     int radix = 10;
     final int len;
 
-    if (str == null || (len = str.length()) == 0)
+    if ((len = str.length()) == 0)
       throw new NumberFormatException();
 
     // Negative numbers are always radix 10.
@@ -140,8 +138,7 @@
 
   public boolean equals(Object obj)
   {
-    return (obj != null && (obj instanceof Integer)
-            && ((Integer) obj).value == value);
+    return (obj instanceof Integer && ((Integer) obj).value == value);
   }
 
   public static Integer getInteger(String prop)
@@ -181,7 +178,7 @@
   {
     final int len;
 
-    if (str == null || (len = str.length()) == 0 ||
+    if ((len = str.length()) == 0 ||
         radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)
       throw new NumberFormatException();
 
Index: Long.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/lang/Long.java,v
retrieving revision 1.5
diff -u -r1.5 Long.java
--- Long.java	2000/09/08 19:37:08	1.5
+++ Long.java	2001/02/09 02:44:36
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998, 1999, 2000  Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -86,11 +86,9 @@
   }
 
   // Added in JDK 1.2
-  public int compareTo(Object o) throws ClassCastException
+  /** @throws ClassCastException */
+  public int compareTo(Object o)
   {
-    if (!(o instanceof Long))
-      throw new ClassCastException();
-
     return this.compareTo((Long) o);
   }
 
@@ -102,7 +100,7 @@
     int radix = 10;
     final int len;
 
-    if (str == null || (len = str.length()) == 0)
+    if ((len = str.length()) == 0)
       throw new NumberFormatException();
 
     // Negative numbers are always radix 10.
@@ -141,8 +139,7 @@
 
   public boolean equals(Object obj)
   {
-    return (obj != null && (obj instanceof Long)
-            && ((Long) obj).value == value);
+    return (obj instanceof Long && ((Long) obj).value == value);
   }
 
   public static Long getLong(String prop)
@@ -183,8 +180,8 @@
   {
     final int len;
 
-    if (str == null || (len = str.length()) == 0 ||
-        radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)
+    if ((len = str.length()) == 0 || radix < Character.MIN_RADIX 
+         || radix > Character.MAX_RADIX)
       throw new NumberFormatException();
 
     boolean isNeg = false;
Index: Short.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/lang/Short.java,v
retrieving revision 1.4
diff -u -r1.4 Short.java
--- Short.java	2000/09/08 19:37:08	1.4
+++ Short.java	2001/02/09 02:44:36
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998, 1999, 2000  Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -115,18 +115,15 @@
   }
 
   // Added in JDK 1.2
-  public int compareTo(Object o) throws ClassCastException
+  /** @throws ClassCastException */
+  public int compareTo(Object o)
   {
-    if (o instanceof Short)
-      return this.value - ((Short) o).value;
-    else
-      throw new ClassCastException();
+    return this.value - ((Short) o).value;
   }
 
   public boolean equals(Object obj)
   {
-    return (obj != null && (obj instanceof Short)
-	    && ((Short) obj).value == value);
+    return (obj instanceof Short) && ((Short) obj).value == value;
   }
 
   // Verified that hashCode is returns plain value (see Short_1 test).

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]