Compare commits

...

2 commits

Author SHA1 Message Date
cdpzyafk
edad2a24e0
Merge 04b54abf9e into 547861c49b 2024-04-03 21:27:23 +00:00
terry
04b54abf9e use to determine whether it equals 0 or not.
r.Cmp(zeroInt) != 0 => r.Sign() != 0
2022-11-05 14:10:29 +08:00

View file

@ -1246,7 +1246,7 @@ func (d Decimal) IsInteger() bool {
q := new(big.Int).Set(d.value)
for z := abs(d.exp); z > 0; z-- {
q.QuoRem(q, tenInt, &r)
if r.Cmp(zeroInt) != 0 {
if r.Sign() != 0 {
return false
}
}
@ -1508,7 +1508,7 @@ func (d Decimal) Round(places int32) Decimal {
// floor for positive numbers, ceil for negative numbers
_, m := ret.value.DivMod(ret.value, tenInt, new(big.Int))
ret.exp++
if ret.value.Sign() < 0 && m.Cmp(zeroInt) != 0 {
if ret.value.Sign() < 0 && m.Sign() != 0 {
ret.value.Add(ret.value, oneInt)
}
@ -1710,7 +1710,7 @@ func (d Decimal) Ceil() Decimal {
exp.Exp(exp, big.NewInt(-int64(d.exp)), nil)
z, m := new(big.Int).DivMod(d.value, exp, new(big.Int))
if m.Cmp(zeroInt) != 0 {
if m.Sign() != 0 {
z.Add(z, oneInt)
}
return Decimal{value: z, exp: 0}