classpath
[Top][All Lists]
Advanced

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

Bug in Long.toOctalString


From: Eric Blake
Subject: Bug in Long.toOctalString
Date: Wed, 18 Jul 2001 18:24:16 +0100

Yet another bug in the wrapper classes.  Plus, the previous commit didn't
update the (c) date for Byte.java.

class Foo
{
    public static void main(String[] args)
    {
        if (Long.toOctalString(0111222333444555L) != "111222333444555")
             throw new RuntimeException("oops");
    }
}

The code in Classpath does not seem to follow any consistent standards.  Are
.java files supposed to follow Sun's recommendation (hanging open braces) or
GNU convention (open braces on new line)?  When there is enough indentation,
should I use TABs or 8 spaces?  And different files in java.lang disagree
whether indentation is 2, 4, or 8 spaces; but both Sun and GNU recommend 4.

--
Eric Blake, Elixent, Castlemead, Lwr Castle St., Bristol BS1 3AG, UK
address@hidden   tel:+44(0)117 917 5611


2001-07-18  Eric Blake  <address@hidden>

        * java/lang/Long.java (toUnsignedString): Fix bug
        that broke toOctalString
        * java/lang/Byte.java: Update copyright

Index: java/lang/Byte.java
===================================================================
RCS file: /cvs/classpath/java/lang/Byte.java,v
retrieving revision 1.15
diff -u -r1.15 Byte.java
--- java/lang/Byte.java 2001/07/17 23:06:09     1.15
+++ java/lang/Byte.java 2001/07/18 10:55:50
@@ -1,5 +1,5 @@
 /* Byte.java -- object wrapper for byte
-   Copyright (C) 1998 Free Software Foundation, Inc.
+   Copyright (C) 1998, 2001 Free Software Foundation, Inc.

 This file is part of GNU Classpath.

Index: java/lang/Long.java
===================================================================
RCS file: /cvs/classpath/java/lang/Long.java,v
retrieving revision 1.10
diff -u -r1.10 Long.java
--- java/lang/Long.java 2001/07/17 23:06:09     1.10
+++ java/lang/Long.java 2001/07/18 11:03:39
@@ -182,26 +182,25 @@
     }
   }

-  private static String toUnsignedString(long value, int bits) {
-    StringBuffer bp = new StringBuffer(64 / bits);
-    long hi = value >>> 32;
-    if (hi != 0) {
-      long lo = value & 0xffffffff;
-      for (int cnt = 32 / bits; cnt > 0; --cnt) {
-       bp.append(digits[(int)(lo & ((1L << bits) - 1))]);
-       lo >>>= bits;
-      }
+    /**
+     * Helper method called by toHexString, toOctalString, toBinaryString
+     *
+     * @param value the value to convert
+     * @param bits the bits/character ratio
+     * @return the converted String
+     */
+    private static String toUnsignedString(long value, int bits)
+    {
+        StringBuffer bp = new StringBuffer(64 / bits);
+        int mask = (1 << bits) - 1;
+        do
+          {
+            bp.append(digits[(int)value & mask]);
+            value >>>= bits;
+          }
+        while (value != 0);
+        return bp.reverse().toString();
     }
-    else
-      hi = value & 0xffffffff;
-
-    do {
-      bp.append(digits[(int)(hi & ((1 << bits) - 1))]);
-      hi >>>= bits;
-    } while (hi != 0);
-
-    return bp.reverse().toString();
-  }

     /**
      * Converts the <code>long</code> to a <code>String</code> assuming it
is




reply via email to

[Prev in Thread] Current Thread [Next in Thread]