138 |
|
|
139 |
// When the value is MIN_VALUE, it overflows when made positive |
// When the value is MIN_VALUE, it overflows when made positive |
140 |
if (num < 0) |
if (num < 0) |
141 |
return "" + MIN_VALUE; |
{ |
142 |
|
buffer[--i] = digits[(int) (-(num + radix) % radix)]; |
143 |
|
num = -(num / radix); |
144 |
|
} |
145 |
} |
} |
146 |
|
|
147 |
do |
do |
583 |
} |
} |
584 |
if (index == len) |
if (index == len) |
585 |
throw new NumberFormatException(); |
throw new NumberFormatException(); |
586 |
|
|
587 |
|
int max = MAX_VALUE / radix; |
588 |
|
// We can't directly write `max = (MAX_VALUE + 1) / radix'. |
589 |
|
// So instead we fake it. |
590 |
|
if (isNeg && MAX_VALUE % radix == radix - 1) |
591 |
|
++max; |
592 |
|
|
593 |
int val = 0; |
int val = 0; |
594 |
while (index < len) |
while (index < len) |
595 |
{ |
{ |
596 |
|
if (val < 0 || val > max) |
597 |
|
throw new NumberFormatException(); |
598 |
|
|
599 |
ch = Character.digit(str.charAt(index++), radix); |
ch = Character.digit(str.charAt(index++), radix); |
600 |
val = val * radix + ch; |
val = val * radix + ch; |
601 |
if (ch < 0 || (val < 0 && (index < len || ! isNeg |
if (ch < 0 || (val < 0 && (! isNeg || val != MIN_VALUE))) |
|
|| val != MIN_VALUE))) |
|
602 |
throw new NumberFormatException(); |
throw new NumberFormatException(); |
603 |
} |
} |
604 |
return isNeg ? -val : val; |
return isNeg ? -val : val; |