Skip to content

Commit

Permalink
Decimal: implement IsInt
Browse files Browse the repository at this point in the history
db47h committed May 6, 2020
1 parent f1654da commit 7e163cc
Showing 3 changed files with 16 additions and 18 deletions.
17 changes: 0 additions & 17 deletions dec_test.go
Original file line number Diff line number Diff line change
@@ -49,20 +49,3 @@ func TestDec_digit(t *testing.T) {
})
}
}

var (
benchU uint
)

func BenchmarkDec_Digits(b *testing.B) {
rand.Seed(0xdeadbeefbadf00d)
d := dec(nil).make(10000)
for i := range d {
d[i] = Word(rand.Uint64()) % _BD
}
for i := 0; i < b.N; i++ {
d[0] = Word(rand.Uint64()) % _BD
d[len(d)-1] = Word(rand.Uint64()) % _BD
benchU = d.digits()
}
}
15 changes: 14 additions & 1 deletion decimal.go
Original file line number Diff line number Diff line change
@@ -79,7 +79,20 @@ func (x *Decimal) IsInf() bool {
}

func (x *Decimal) IsInt() bool {
panic("not implemented")
if debugDecimal {
x.validate()
}
// special cases
if x.form != finite {
return x.form == zero
}
// x.form == finite
if x.exp <= 0 {
return false
}
// x.exp > 0
// mant[0:prec] * 10**exp >= 0 || mant[0:mant.MinPrec()]*10**exp >= 0
return x.prec <= uint32(x.exp) || x.MinPrec() <= uint(x.exp)
}

func (x *Decimal) MantExp(mant *Decimal) (exp int) {
2 changes: 2 additions & 0 deletions decimal_test.go
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@ import (
"time"
)

var benchU uint

var intData = []struct {
s string
b int

0 comments on commit 7e163cc

Please sign in to comment.