diff --git a/src/math/big/decimal.go b/src/math/big/decimal.go index 7789677f76..b9e181dba3 100644 --- a/src/math/big/decimal.go +++ b/src/math/big/decimal.go @@ -29,6 +29,14 @@ type decimal struct { exp int // exponent } +// at returns the i'th mantissa digit, starting with the most significant digit at 0. +func (d *decimal) at(i int) byte { + if 0 <= i && i < len(d.mant) { + return d.mant[i] + } + return '0' +} + // Maximum shift amount that can be done in one pass without overflow. // A Word has _W bits and (1<> s, for s <= maxShift. func shr(x *decimal, s uint) { // Division by 1< 0 { buf = append(buf, '.') for i := 0; i < prec; i++ { - ch := byte('0') - if j := d.exp + i; 0 <= j && j < len(d.mant) { - ch = d.mant[j] - } - buf = append(buf, ch) + buf = append(buf, d.at(d.exp+i)) } }