Skip to content

Commit

Permalink
Decimal: add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
db47h committed May 25, 2020
1 parent bd1bb29 commit 39c92df
Show file tree
Hide file tree
Showing 4 changed files with 335 additions and 326 deletions.
6 changes: 3 additions & 3 deletions dec_arith.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var pow10tab = [...]uint64{

func pow10(n uint) Word { return Word(pow10tab[n]) }

var maxDigits = [...]uint{
var pow2digitsTab = [...]uint{
1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5,
5, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10,
10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 15,
Expand All @@ -49,15 +49,15 @@ func decDigits(x uint) (n uint) {
}

func decDigits64(x uint64) (n uint) {
n = maxDigits[bits.Len64(x)]
n = pow2digitsTab[bits.Len64(x)]
if x < uint64(pow10(n-1)) {
n--
}
return n
}

func decDigits32(x uint) (n uint) {
n = maxDigits[bits.Len(x)]
n = pow2digitsTab[bits.Len(x)]
if x < uint(pow10(n-1)) {
n--
}
Expand Down
8 changes: 8 additions & 0 deletions dec_arith_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,11 @@ func BenchmarkAddMul10VVW(b *testing.B) {
})
}
}

func BenchmarkShl10VU(b *testing.B) {
x := dec(rnd10V(1000))
z := dec(nil).make(1000)
for i := 0; i < b.N; i++ {
z.shl(x, 8)
}
}
4 changes: 2 additions & 2 deletions decimal_marsh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ func TestDecimalCorruptGob(t *testing.T) {
func TestDecimalJSONEncoding(t *testing.T) {
for _, test := range floatVals {
for _, sign := range []string{"", "+", "-"} {
for _, prec := range []uint{0, 1, 2, 10, 53, 64, 100, 1000} {
if prec > 53 && testing.Short() {
for _, prec := range []uint{0, 1, 2, 3, 19, 34, 300} {
if prec > 19 && testing.Short() {
continue
}
x := sign + test
Expand Down
Loading

0 comments on commit 39c92df

Please sign in to comment.