Re: [cp-patches] Other class libraries

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 2008-07-01 at 11:42 +0100, Andrew Haley wrote:
> Hmm, I'm not sure that explanations should be punted to unfree
> documentation.  If the logic is so obscure that it needs a
> reference, then it perhaps should be spelled out.

Here's the patch for Integer.  I have also added a Mauve test.

- twisti

---

Index: ChangeLog
===================================================================
RCS file: /sources/classpath/classpath/ChangeLog,v
retrieving revision 1.9670
diff -u -3 -p -r1.9670 ChangeLog
--- ChangeLog	1 Jul 2008 10:43:47 -0000	1.9670
+++ ChangeLog	1 Jul 2008 10:55:09 -0000
@@ -1,3 +1,9 @@
+2008-07-01  Christian Thalinger  <twisti@xxxxxxxxxxxxxxxxxxxxx>
+
+	* java/lang/Integer.java (signum): Implemented properly as
+	described in Hacker's Delight Section 2-7, plus Andrew Haley's
+	explanation.
+
 2008-07-01  Andrew Haley  <aph@xxxxxxxxxx>
 
 	* java/lang/Long.java: Comment change only.
Index: java/lang/Integer.java
===================================================================
RCS file: /sources/classpath/classpath/java/lang/Integer.java,v
retrieving revision 1.39
diff -u -3 -p -r1.39 Integer.java
--- java/lang/Integer.java	6 Jun 2008 00:23:50 -0000	1.39
+++ java/lang/Integer.java	1 Jul 2008 10:55:09 -0000
@@ -687,7 +687,14 @@ public final class Integer extends Numbe
    */
   public static int signum(int x)
   {
-    return (x >> 31) - (-x >> 31);
+    return (x >> 31) | (-x >>> 31);
+
+    // The LHS propagates the sign bit through every bit in the word;
+    // if X < 0, every bit is set to 1, else 0.  if X > 0, the RHS
+    // negates x and shifts the resulting 1 in the sign bit to the
+    // LSB, leaving every other bit 0.
+
+    // Hacker's Delight, Section 2-7
   }
 
   /**




[Index of Archives]     [Linux Kernel]     [Linux Cryptography]     [Fedora]     [Fedora Directory]     [Red Hat Development]

  Powered by Linux