Use QuoRem to avoid extra ops

This commit is contained in:
Connor Peet 2016-10-06 09:37:00 -07:00
parent 2faaec71dd
commit 080be114dd
No known key found for this signature in database
GPG key ID: CF8FD2EA0DBC61BD

View file

@ -440,11 +440,10 @@ func (d Decimal) RoundFair(places int32) Decimal {
// First, truncate the number to see if there are trailing decimal places. // First, truncate the number to see if there are trailing decimal places.
// If there are it can't end in 5. // If there are it can't end in 5.
exp := new(big.Int).Exp(tenInt, shift, zeroInt)
rounded := new(big.Int).Quo(d.value, exp)
tmp := new(big.Int) tmp := new(big.Int)
if tmp.Mul(rounded, exp).Cmp(d.value) != 0 { exp := new(big.Int).Exp(tenInt, shift, zeroInt)
rounded, _ := new(big.Int).QuoRem(d.value, exp, tmp)
if tmp.Cmp(zeroInt) != 0 {
return d.Round(places) return d.Round(places)
} }