diff --git a/decimal.go b/decimal.go index efdf414..bde4127 100644 --- a/decimal.go +++ b/decimal.go @@ -1043,7 +1043,7 @@ func (z *Decimal) SetFloat(x *big.Float) *Decimal { exp2 -= int64(fprec) if exp2 != 0 { // multiply / divide by 2**exp with increased precision - z.prec += 1 + z.prec++ t := new(Decimal).SetPrec(uint(z.prec)) if exp2 < 0 { if exp2 < MinExp { @@ -1056,7 +1056,7 @@ func (z *Decimal) SetFloat(x *big.Float) *Decimal { } else { z = z.Mul(z, t.pow2(uint64(exp2))) } - z.prec -= 1 + z.prec-- } z.round(0) return z @@ -1097,14 +1097,14 @@ func (z *Decimal) SetFloat64(x float64) *Decimal { z.exp = int32(len(z.mant))*_DW - int32(dnorm(z.mant)) if exp2 != 0 { // multiply / divide by 2**exp with increased precision - z.prec += 1 + z.prec++ t := new(Decimal).SetPrec(uint(z.prec)) if exp2 < 0 { z = z.Quo(z, t.pow2(uint64(-exp2))) } else { z = z.Mul(z, t.pow2(uint64(exp2))) } - z.prec -= 1 + z.prec-- } z.round(0) return z @@ -1617,8 +1617,10 @@ func (z *Decimal) umul(x, y *Decimal) { } const ( - DigitsPerWord = _DW // number of decimal digits per 32 or 64 bits mantissa Word - DecimalBase = _DB // decimal base + // DigitsPerWord is the number of decimal digits per 32 or 64 bits mantissa Word. + DigitsPerWord = _DW + // DecimalBase is the decimal base for a 32 or 64 bits mantissa Word. + DecimalBase = _DB ) // BitsExp provides raw (unchecked but fast) access to x by returning its diff --git a/decimal_toa.go b/decimal_toa.go index 4713c66..745ce3f 100644 --- a/decimal_toa.go +++ b/decimal_toa.go @@ -31,7 +31,7 @@ import ( // // Note that the 'b' and 'p' formats differ from big.Float: an hexadecimal // representation does not make sense for decimals. These formats use a full -// decimal representaion instead. +// decimal representation instead. // // If format is a different character, Text returns a "%" followed by the // unrecognized format character. @@ -179,7 +179,7 @@ func (x *Decimal) bufSizeForFmt(fmt byte, prec int) int { sz += prec + 1 } case 'f': - sz += 1 + sz++ if prec < 0 { sz += digits if exp < 0 || exp > digits { @@ -438,7 +438,7 @@ func (x *Decimal) Format(s fmt.State, format rune) { } // toa returns x.mant.utoa(base) and x.exp with least significant zero Words removed -// this function retuns nil, 0 for non-finite numbers. +// this function returns nil, 0 for non-finite numbers. func (x *Decimal) toa(base int) ([]byte, int) { if x.form == finite { m := x.mant