diff options
Diffstat (limited to 'libgo/go/math/big/decimal.go')
-rw-r--r-- | libgo/go/math/big/decimal.go | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/libgo/go/math/big/decimal.go b/libgo/go/math/big/decimal.go index 2595e5f8c12..2c0c9daebc1 100644 --- a/libgo/go/math/big/decimal.go +++ b/libgo/go/math/big/decimal.go @@ -20,7 +20,7 @@ package big // A decimal represents an unsigned floating-point number in decimal representation. -// The value of a non-zero decimal x is x.mant * 10 ** x.exp with 0.5 <= x.mant < 1, +// The value of a non-zero decimal d is d.mant * 10**d.exp with 0.5 <= d.mant < 1, // with the most-significant mantissa digit at index 0. For the zero decimal, the // mantissa length and exponent are 0. // The zero value for decimal represents a ready-to-use 0.0. @@ -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<<maxShift - 1)*10 + 9 must fit into Word. const maxShift = _W - 4 @@ -72,7 +80,7 @@ func (x *decimal) init(m nat, shift int) { } // Convert mantissa into decimal representation. - s := m.decimalString() // TODO(gri) avoid string conversion here + s := m.utoa(10) n := len(s) x.exp = n // Trim trailing zeros; instead the exponent is tracking @@ -92,12 +100,6 @@ func (x *decimal) init(m nat, shift int) { } } -// Possibly optimization: The current implementation of nat.string takes -// a charset argument. When a right shift is needed, we could provide -// "\x00\x01...\x09" instead of "012..9" (as in nat.decimalString) and -// avoid the repeated +'0' and -'0' operations in decimal.shr (and do a -// single +'0' pass at the end). - // shr implements x >> s, for s <= maxShift. func shr(x *decimal, s uint) { // Division by 1<<s using shift-and-subtract algorithm. |