Commit 314b358a authored by Robert Griesemer's avatar Robert Griesemer

gofmt-ify strconv

(and remove an empty line at the end of a file)

R=rsc
http://go/go-review/1017046
parent 5d377054
...@@ -16,10 +16,10 @@ import "bytes" ...@@ -16,10 +16,10 @@ import "bytes"
type decimal struct { type decimal struct {
// TODO(rsc): Can make d[] a bit smaller and add // TODO(rsc): Can make d[] a bit smaller and add
// truncated bool; // truncated bool;
d [2000] byte; // digits d [2000]byte; // digits
nd int; // number of digits used nd int; // number of digits used
dp int; // decimal point dp int; // decimal point
}; }
func (a *decimal) String() string { func (a *decimal) String() string {
n := 10 + a.nd; n := 10 + a.nd;
...@@ -42,20 +42,20 @@ func (a *decimal) String() string { ...@@ -42,20 +42,20 @@ func (a *decimal) String() string {
w++; w++;
buf[w] = '.'; buf[w] = '.';
w++; w++;
w += digitZero(buf[w:w+-a.dp]); w += digitZero(buf[w : w + -a.dp]);
w += bytes.Copy(buf[w:w+a.nd], a.d[0:a.nd]); w += bytes.Copy(buf[w : w + a.nd], a.d[0 : a.nd]);
case a.dp < a.nd: case a.dp < a.nd:
// decimal point in middle of digits // decimal point in middle of digits
w += bytes.Copy(buf[w:w+a.dp], a.d[0:a.dp]); w += bytes.Copy(buf[w : w + a.dp], a.d[0 : a.dp]);
buf[w] = '.'; buf[w] = '.';
w++; w++;
w += bytes.Copy(buf[w:w+a.nd-a.dp], a.d[a.dp:a.nd]); w += bytes.Copy(buf[w : w + a.nd - a.dp], a.d[a.dp : a.nd]);
default: default:
// zeros fill space between digits and decimal point // zeros fill space between digits and decimal point
w += bytes.Copy(buf[w:w+a.nd], a.d[0:a.nd]); w += bytes.Copy(buf[w : w + a.nd], a.d[0 : a.nd]);
w += digitZero(buf[w:w+a.dp-a.nd]); w += digitZero(buf[w : w + a.dp - a.nd]);
} }
return string(buf[0:w]); return string(buf[0:w]);
} }
...@@ -78,7 +78,7 @@ func digitZero(dst []byte) int { ...@@ -78,7 +78,7 @@ func digitZero(dst []byte) int {
// (They are meaningless; the decimal point is tracked // (They are meaningless; the decimal point is tracked
// independent of the number of digits.) // independent of the number of digits.)
func trim(a *decimal) { func trim(a *decimal) {
for a.nd > 0 && a.d[a.nd-1] == '0' { for a.nd > 0 && a.d[a.nd - 1] == '0' {
a.nd--; a.nd--;
} }
if a.nd == 0 { if a.nd == 0 {
...@@ -95,14 +95,14 @@ func (a *decimal) Assign(v uint64) { ...@@ -95,14 +95,14 @@ func (a *decimal) Assign(v uint64) {
for v > 0 { for v > 0 {
v1 := v/10; v1 := v/10;
v -= 10*v1; v -= 10*v1;
buf[n] = byte(v + '0'); buf[n] = byte(v+'0');
n++; n++;
v = v1; v = v1;
} }
// Reverse again to produce forward decimal in a.d. // Reverse again to produce forward decimal in a.d.
a.nd = 0; a.nd = 0;
for n--; n>=0; n-- { for n--; n >= 0; n-- {
a.d[a.nd] = buf[n]; a.d[a.nd] = buf[n];
a.nd++; a.nd++;
} }
...@@ -141,7 +141,7 @@ func rightShift(a *decimal, k uint) { ...@@ -141,7 +141,7 @@ func rightShift(a *decimal, k uint) {
break; break;
} }
c := int(a.d[r]); c := int(a.d[r]);
n = n*10 + c-'0'; n = n*10 + c - '0';
} }
a.dp -= r-1; a.dp -= r-1;
...@@ -152,7 +152,7 @@ func rightShift(a *decimal, k uint) { ...@@ -152,7 +152,7 @@ func rightShift(a *decimal, k uint) {
n -= dig<<k; n -= dig<<k;
a.d[w] = byte(dig+'0'); a.d[w] = byte(dig+'0');
w++; w++;
n = n*10 + c-'0'; n = n*10 + c - '0';
} }
// Put down extra digits. // Put down extra digits.
...@@ -183,7 +183,7 @@ type leftCheat struct { ...@@ -183,7 +183,7 @@ type leftCheat struct {
cutoff string; // minus one digit if original < a. cutoff string; // minus one digit if original < a.
} }
var leftcheats = []leftCheat { var leftcheats = []leftCheat{
// Leading digits of 1/2^i = 5^i. // Leading digits of 1/2^i = 5^i.
// 5^23 is not an exact 64-bit floating point number, // 5^23 is not an exact 64-bit floating point number,
// so have to use bc for the math. // so have to use bc for the math.
...@@ -196,34 +196,34 @@ var leftcheats = []leftCheat { ...@@ -196,34 +196,34 @@ var leftcheats = []leftCheat {
int(log2*NR+1), $0, 2**NR) int(log2*NR+1), $0, 2**NR)
}' }'
*/ */
leftCheat{ 0, "" }, leftCheat{0, ""},
leftCheat{ 1, "5" }, // * 2 leftCheat{1, "5"}, // * 2
leftCheat{ 1, "25" }, // * 4 leftCheat{1, "25"}, // * 4
leftCheat{ 1, "125" }, // * 8 leftCheat{1, "125"}, // * 8
leftCheat{ 2, "625" }, // * 16 leftCheat{2, "625"}, // * 16
leftCheat{ 2, "3125" }, // * 32 leftCheat{2, "3125"}, // * 32
leftCheat{ 2, "15625" }, // * 64 leftCheat{2, "15625"}, // * 64
leftCheat{ 3, "78125" }, // * 128 leftCheat{3, "78125"}, // * 128
leftCheat{ 3, "390625" }, // * 256 leftCheat{3, "390625"}, // * 256
leftCheat{ 3, "1953125" }, // * 512 leftCheat{3, "1953125"}, // * 512
leftCheat{ 4, "9765625" }, // * 1024 leftCheat{4, "9765625"}, // * 1024
leftCheat{ 4, "48828125" }, // * 2048 leftCheat{4, "48828125"}, // * 2048
leftCheat{ 4, "244140625" }, // * 4096 leftCheat{4, "244140625"}, // * 4096
leftCheat{ 4, "1220703125" }, // * 8192 leftCheat{4, "1220703125"}, // * 8192
leftCheat{ 5, "6103515625" }, // * 16384 leftCheat{5, "6103515625"}, // * 16384
leftCheat{ 5, "30517578125" }, // * 32768 leftCheat{5, "30517578125"}, // * 32768
leftCheat{ 5, "152587890625" }, // * 65536 leftCheat{5, "152587890625"}, // * 65536
leftCheat{ 6, "762939453125" }, // * 131072 leftCheat{6, "762939453125"}, // * 131072
leftCheat{ 6, "3814697265625" }, // * 262144 leftCheat{6, "3814697265625"}, // * 262144
leftCheat{ 6, "19073486328125" }, // * 524288 leftCheat{6, "19073486328125"}, // * 524288
leftCheat{ 7, "95367431640625" }, // * 1048576 leftCheat{7, "95367431640625"}, // * 1048576
leftCheat{ 7, "476837158203125" }, // * 2097152 leftCheat{7, "476837158203125"}, // * 2097152
leftCheat{ 7, "2384185791015625" }, // * 4194304 leftCheat{7, "2384185791015625"}, // * 4194304
leftCheat{ 7, "11920928955078125" }, // * 8388608 leftCheat{7, "11920928955078125"}, // * 8388608
leftCheat{ 8, "59604644775390625" }, // * 16777216 leftCheat{8, "59604644775390625"}, // * 16777216
leftCheat{ 8, "298023223876953125" }, // * 33554432 leftCheat{8, "298023223876953125"}, // * 33554432
leftCheat{ 8, "1490116119384765625" }, // * 67108864 leftCheat{8, "1490116119384765625"}, // * 67108864
leftCheat{ 9, "7450580596923828125" }, // * 134217728 leftCheat{9, "7450580596923828125"}, // * 134217728
} }
// Is the leading prefix of b lexicographically less than s? // Is the leading prefix of b lexicographically less than s?
...@@ -242,7 +242,7 @@ func prefixIsLessThan(b []byte, s string) bool { ...@@ -242,7 +242,7 @@ func prefixIsLessThan(b []byte, s string) bool {
// Binary shift left (/ 2) by k bits. k <= maxShift to avoid overflow. // Binary shift left (/ 2) by k bits. k <= maxShift to avoid overflow.
func leftShift(a *decimal, k uint) { func leftShift(a *decimal, k uint) {
delta := leftcheats[k].delta; delta := leftcheats[k].delta;
if prefixIsLessThan(a.d[0:a.nd], leftcheats[k].cutoff) { if prefixIsLessThan(a.d[0 : a.nd], leftcheats[k].cutoff) {
delta--; delta--;
} }
...@@ -252,7 +252,7 @@ func leftShift(a *decimal, k uint) { ...@@ -252,7 +252,7 @@ func leftShift(a *decimal, k uint) {
// Pick up a digit, put down a digit. // Pick up a digit, put down a digit.
for r--; r >= 0; r-- { for r--; r >= 0; r-- {
n += (int(a.d[r])-'0') << k; n += (int(a.d[r])-'0')<<k;
quo := n/10; quo := n/10;
rem := n - 10*quo; rem := n - 10*quo;
w--; w--;
...@@ -302,7 +302,7 @@ func shouldRoundUp(a *decimal, nd int) bool { ...@@ -302,7 +302,7 @@ func shouldRoundUp(a *decimal, nd int) bool {
return false; return false;
} }
if a.d[nd] == '5' && nd+1 == a.nd { // exactly halfway - round to even if a.d[nd] == '5' && nd+1 == a.nd { // exactly halfway - round to even
return (a.d[nd-1] - '0') % 2 != 0; return (a.d[nd-1] - '0')%2 != 0;
} }
// not halfway - digit tells all // not halfway - digit tells all
return a.d[nd] >= '5'; return a.d[nd] >= '5';
...@@ -375,4 +375,3 @@ func (a *decimal) RoundedInteger() uint64 { ...@@ -375,4 +375,3 @@ func (a *decimal) RoundedInteger() uint64 {
} }
return n; return n;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment