summaryrefslogtreecommitdiff
path: root/src/lib/strconv/decimal.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2008-11-19 12:50:34 -0800
committerRuss Cox <rsc@golang.org>2008-11-19 12:50:34 -0800
commitd50e9592957199d766080f283deabed170f71ba8 (patch)
tree95c5b99eab6e3cc755f12490f049910116c3a1eb /src/lib/strconv/decimal.go
parenta6b71cb1ad58a14a778e28107cea6360b84591f3 (diff)
downloadgolang-d50e9592957199d766080f283deabed170f71ba8.tar.gz
essentially 100% coverage of strconv in tests.
fix a few bugs. R=r DELTA=294 (275 added, 9 deleted, 10 changed) OCL=19595 CL=19595
Diffstat (limited to 'src/lib/strconv/decimal.go')
-rw-r--r--src/lib/strconv/decimal.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/lib/strconv/decimal.go b/src/lib/strconv/decimal.go
index ee6dd0e78..b30c842ff 100644
--- a/src/lib/strconv/decimal.go
+++ b/src/lib/strconv/decimal.go
@@ -42,6 +42,9 @@ func (a *Decimal) String() string {
buf := new([]byte, n);
w := 0;
switch {
+ case a.nd == 0:
+ return "0";
+
case a.dp <= 0:
// zeros fill space between decimal point and digits
buf[w] = '0';
@@ -136,10 +139,11 @@ func RightShift(a *Decimal, k uint) {
for ; n>>k == 0; r++ {
if r >= a.nd {
if n == 0 {
+ // a == 0; shouldn't get here, but handle anyway.
a.nd = 0;
return;
}
- for n >> k == 0 {
+ for n>>k == 0 {
n = n*10;
r++;
}
@@ -276,7 +280,7 @@ func LeftShift(a *Decimal, k uint) {
if w != 0 {
// TODO: Remove - has no business panicking.
- panic("fmt: bad LeftShift");
+ panicln("strconv: bad LeftShift", w);
}
a.nd += delta;
a.dp += delta;
@@ -287,6 +291,8 @@ func LeftShift(a *Decimal, k uint) {
// Returns receiver for convenience.
func (a *Decimal) Shift(k int) *Decimal {
switch {
+ case a.nd == 0:
+ // nothing to do: a == 0
case k > 0:
for k > MaxShift {
LeftShift(a, MaxShift);