Christian Thalinger wrote:
> On Fri, 2008-06-27 at 10:21 +0100, Andrew John Hughes wrote:
>> I thought you already had :D
>
> No, but I did now.
> diff -u -3 -p -r1.26 Long.java
> --- java/lang/Long.java 18 Apr 2008 21:00:11 -0000 1.26
> +++ java/lang/Long.java 1 Jul 2008 08:11:42 -0000
> @@ -689,7 +689,8 @@ public final class Long extends Number i
> */
> public static int signum(long x)
> {
> - return (int)(x >> 63) - (int)(-x >> 63);
> + // Hacker's Delight, Section 2-7
> + return (int) ((x >> 63) | (-x >>> 63));
> }
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.
I'm committing this patch.
Andrew.
2008-07-01 Andrew Haley <[EMAIL PROTECTED]>
* java/lang/Long.java: Comment change only.
Index: java/lang/Long.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/Long.java,v
retrieving revision 1.27
diff -u -r1.27 Long.java
--- java/lang/Long.java 1 Jul 2008 08:12:31 -0000 1.27
+++ java/lang/Long.java 1 Jul 2008 10:35:48 -0000
@@ -689,8 +689,14 @@
*/
public static int signum(long x)
{
- // Hacker's Delight, Section 2-7
return (int) ((x >> 63) | (-x >>> 63));
+
+ // 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
}
/**