Skip to content

Commit

Permalink
Minor bigdec speedups (#7538)
Browse files Browse the repository at this point in the history
  • Loading branch information
ValarDragon authored Feb 19, 2024
1 parent d563553 commit 37e96c8
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions osmomath/decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@ func NewBigDec(i int64) BigDec {
// create a new BigDec from integer with decimal place at prec
// CONTRACT: prec <= BigDecPrecision
func NewBigDecWithPrec(i, prec int64) BigDec {
bi := big.NewInt(i)
return BigDec{
new(big.Int).Mul(big.NewInt(i), precisionMultiplier(prec)),
bi.Mul(bi, precisionMultiplier(prec)),
}
}

Expand Down Expand Up @@ -850,11 +851,9 @@ func (d BigDec) Ceil() BigDec {
quo, rem = quo.QuoRem(tmp, precisionReuse, rem)

// no need to round with a zero remainder regardless of sign
if rem.Cmp(zeroInt) == 0 {
if rem.Sign() == 0 {
return NewBigDecFromBigInt(quo)
}

if rem.Sign() == -1 {
} else if rem.Sign() == -1 {
return NewBigDecFromBigInt(quo)
}

Expand Down Expand Up @@ -953,7 +952,7 @@ func (d *BigDec) MarshalTo(data []byte) (n int, err error) {
d.i = new(big.Int)
}

if d.i.Cmp(zeroInt) == 0 {
if d.i.Sign() == 0 {
copy(data, []byte{0x30})
return 1, nil
}
Expand Down

0 comments on commit 37e96c8

Please sign in to comment.