/[classpath]/classpath/java/lang/Long.java
ViewVC logotype

Diff of /classpath/java/lang/Long.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.16 by ericb, Sat Mar 9 21:20:04 2002 UTC revision 1.17 by tromey, Thu Jun 13 17:28:54 2002 UTC
# Line 142  public final class Long extends Number i Line 142  public final class Long extends Number i
142    
143          // When the value is MIN_VALUE, it overflows when made positive          // When the value is MIN_VALUE, it overflows when made positive
144          if (num < 0)          if (num < 0)
145            return "" + MIN_VALUE;            {
146                buffer[--i] = digits[(int) (-(num + radix) % radix)];
147                num = -(num / radix);
148              }
149        }        }
150    
151      do      do
# Line 516  public final class Long extends Number i Line 519  public final class Long extends Number i
519     */     */
520    private static String toUnsignedString(long num, int exp)    private static String toUnsignedString(long num, int exp)
521    {    {
522      // Use the Integer toString for efficiency if possible.      // Use the Integer toUnsignedString for efficiency if possible.
523      if ((int) num == num)      // If NUM<0 then this particular optimization doesn't work
524        // properly.
525        if (num >= 0 && (int) num == num)
526        return Integer.toUnsignedString((int) num, exp);        return Integer.toUnsignedString((int) num, exp);
527    
528      // Use an array large enough for a binary number.      // Use an array large enough for a binary number.
# Line 586  public final class Long extends Number i Line 591  public final class Long extends Number i
591        }        }
592      if (index == len)      if (index == len)
593        throw new NumberFormatException();        throw new NumberFormatException();
594    
595        long max = MAX_VALUE / radix;
596        // We can't directly write `max = (MAX_VALUE + 1) / radix'.
597        // So instead we fake it.
598        if (isNeg && MAX_VALUE % radix == radix - 1)
599          ++max;
600    
601      long val = 0;      long val = 0;
602      while (index < len)      while (index < len)
603        {        {
604            if (val < 0 || val > max)
605              throw new NumberFormatException();
606    
607          ch = Character.digit(str.charAt(index++), radix);          ch = Character.digit(str.charAt(index++), radix);
608          val = val * radix + ch;          val = val * radix + ch;
609          if (ch < 0 || (val < 0 && (index < len || ! isNeg          if (ch < 0 || (val < 0 && (! isNeg || val != MIN_VALUE)))
                                    || val != MIN_VALUE)))  
610            throw new NumberFormatException();            throw new NumberFormatException();
611        }        }
612      return isNeg ? -val : val;      return isNeg ? -val : val;

Legend:
Removed from v.1.16  
changed lines
  Added in v.1.17

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26