fix Long.toString for Long.MIN_VALUE case

This commit is contained in:
Joel Dice 2008-07-13 17:54:44 -06:00
parent bf58eaa6ba
commit a016eeaba0
2 changed files with 8 additions and 4 deletions

View File

@ -60,16 +60,17 @@ public final class Long extends Number implements Comparable<Long> {
}
boolean negative = v < 0;
if (negative) v = -v;
int size = (negative ? 1 : 0);
for (long n = v; n > 0; n /= radix) ++size;
for (long n = v; n != 0; n /= radix) ++size;
char[] array = new char[size];
int i = array.length - 1;
for (long n = v; n > 0; n /= radix) {
for (long n = v; n != 0; n /= radix) {
long digit = n % radix;
if (negative) digit = -digit;
if (digit >= 0 && digit <= 9) {
array[i] = (char) ('0' + digit);
} else {

View File

@ -102,7 +102,10 @@ public class Misc {
expect(foo > 0);
}
expect(String.valueOf(25214903884l).equals("25214903884"));
expect(String.valueOf(25214903884L).equals("25214903884"));
expect(String.valueOf(-9223372036854775808L).equals
("-9223372036854775808"));
{ boolean p = true;
int[] array = new int[] { 1, 2 };