diff options
| author | Robert Griesemer <gri@golang.org> | 2019-03-18 16:10:07 -0700 |
|---|---|---|
| committer | Robert Griesemer <gri@golang.org> | 2019-03-25 22:29:26 +0000 |
| commit | e4ba40030f9ba4b61bb28dbf78bb41a7b14e6788 (patch) | |
| tree | 583c2cfc55917fad02865f2627169a277da68465 /src/math/big/floatconv.go | |
| parent | a591fd08dd30de0e22e759df0fcff961fb3d32d8 (diff) | |
| download | go-e4ba40030f9ba4b61bb28dbf78bb41a7b14e6788.tar.xz | |
math/big: accept non-decimal floats with Rat.SetString
This fixes an old oversight. Rat.SetString already permitted
fractions a/b where both a and b could independently specify
a base prefix. With this CL, it now also accepts non-decimal
floating-point numbers.
Fixes #29799.
Change-Id: I9cc65666a5cebb00f0202da2e4fc5654a02e3234
Reviewed-on: https://go-review.googlesource.com/c/go/+/168237
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Diffstat (limited to 'src/math/big/floatconv.go')
| -rw-r--r-- | src/math/big/floatconv.go | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/math/big/floatconv.go b/src/math/big/floatconv.go index 88216f5600..95e32d3319 100644 --- a/src/math/big/floatconv.go +++ b/src/math/big/floatconv.go @@ -70,8 +70,8 @@ func (z *Float) scan(r io.ByteScanner, base int) (f *Float, b int, err error) { } // len(z.mant) > 0 - // The mantissa may have a decimal point (fcount <= 0) and there - // may be a nonzero exponent exp. The decimal point amounts to a + // The mantissa may have a radix point (fcount <= 0) and there + // may be a nonzero exponent exp. The radix point amounts to a // division by b**(-fcount). An exponent means multiplication by // ebase**exp. Finally, mantissa normalization (shift left) requires // a correcting multiplication by 2**(-shiftcount). Multiplications @@ -85,11 +85,11 @@ func (z *Float) scan(r io.ByteScanner, base int) (f *Float, b int, err error) { exp2 := int64(len(z.mant))*_W - fnorm(z.mant) exp5 := int64(0) - // determine binary or decimal exponent contribution of decimal point + // determine binary or decimal exponent contribution of radix point if fcount < 0 { - // The mantissa has a "decimal" point ddd.dddd; and - // -fcount is the number of digits to the right of '.'. - // Adjust relevant exponent accordingly. + // The mantissa has a radix point ddd.dddd; and + // -fcount is the number of digits to the right + // of '.'. Adjust relevant exponent accordingly. d := int64(fcount) switch b { case 10: @@ -111,7 +111,7 @@ func (z *Float) scan(r io.ByteScanner, base int) (f *Float, b int, err error) { switch ebase { case 10: exp5 += exp - fallthrough + fallthrough // see fallthrough above case 2: exp2 += exp default: |
