Skip to content

Commit

Permalink
Decimal: fix wrong precisions in Decimal.scan
Browse files Browse the repository at this point in the history
  • Loading branch information
db47h committed May 16, 2020
1 parent 709091c commit aea669e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions decimal_conv.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (z *Decimal) SetString(s string) (*Decimal, bool) {
func (z *Decimal) scan(r io.ByteScanner, base int) (f *Decimal, b int, err error) {
prec := z.prec
if prec == 0 {
prec = _DW
prec = DefaultDecimalPrec
}

// A reasonable value in case of an error.
Expand Down Expand Up @@ -87,7 +87,7 @@ func (z *Decimal) scan(r io.ByteScanner, base int) (f *Decimal, b int, err error
d := int64(fcount)
switch b {
case 10:
exp10 = d
exp10 += d
case 2:
exp2 += d
case 8:
Expand Down
6 changes: 3 additions & 3 deletions decimal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ var intData = []struct {
pr uint
e int32
}{
{"00000000000000000001232", 10, 0, dec{1232000000000000000}, 19, 4},
{"00000000000000000001232", 10, 0, dec{1232000000000000000}, DefaultDecimalPrec, 4},
{"1234567890123456789_0123456789012345678_9012345678901234567_8901234567890123456_78901234567890", 0, 90,
dec{7890123456789000000, 8901234567890123456, 9012345678901234567, 123456789012345678, 1234567890123456789},
90, 90},
{"1235", 0, 0, dec{1235000000000000000}, _DW, 4},
{"1235", 0, 0, dec{1235000000000000000}, DefaultDecimalPrec, 4},
{"1235", 0, 3, dec{1240000000000000000}, 3, 4},
{"1245", 0, 3, dec{1240000000000000000}, 3, 4},
{"12451", 0, 3, dec{1250000000000000000}, 3, 5},
{"0", 0, 0, nil, _DW, 0},
{"0", 0, 0, nil, DefaultDecimalPrec, 0},
}

func TestDecimal_dnorm(t *testing.T) {
Expand Down

0 comments on commit aea669e

Please sign in to comment.