From 080be114dda9651785cfd21b85992a51789222f8 Mon Sep 17 00:00:00 2001 From: Connor Peet Date: Thu, 6 Oct 2016 09:37:00 -0700 Subject: [PATCH] Use QuoRem to avoid extra ops --- decimal.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/decimal.go b/decimal.go index 9e2d9a4..3d7a676 100644 --- a/decimal.go +++ b/decimal.go @@ -440,11 +440,10 @@ func (d Decimal) RoundFair(places int32) Decimal { // First, truncate the number to see if there are trailing decimal places. // 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) - 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) }