diff options
| author | Robert Griesemer <gri@golang.org> | 2016-10-05 15:01:15 -0700 |
|---|---|---|
| committer | Robert Griesemer <gri@golang.org> | 2016-10-06 20:37:01 +0000 |
| commit | 95a6572b2b84e8cbfd821c4e5f774f20d37c007e (patch) | |
| tree | f0c9e20e2208601812ac3d40f5a207a536b73149 /src/math/big/floatconv.go | |
| parent | 4103fedf199dbc80c11455ffe75e3ecf89c77da5 (diff) | |
| download | go-95a6572b2b84e8cbfd821c4e5f774f20d37c007e.tar.xz | |
math/big: Rat.SetString to report error if input is not consumed entirely
Also, document behavior explicitly for all SetString implementations.
Fixes #17001.
Change-Id: Iccc882b4bc7f8b61b6092f330e405c146a80dc98
Reviewed-on: https://go-review.googlesource.com/30472
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/math/big/floatconv.go')
| -rw-r--r-- | src/math/big/floatconv.go | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/math/big/floatconv.go b/src/math/big/floatconv.go index a884df6fe1..4ba03bc105 100644 --- a/src/math/big/floatconv.go +++ b/src/math/big/floatconv.go @@ -14,7 +14,9 @@ import ( // SetString sets z to the value of s and returns z and a boolean indicating // success. s must be a floating-point number of the same format as accepted -// by Parse, with base argument 0. +// by Parse, with base argument 0. The entire string (not just a prefix) must +// be valid for success. If the operation failed, the value of z is undefined +// but the returned value is nil. func (z *Float) SetString(s string) (*Float, bool) { if f, _, err := z.Parse(s, 0); err == nil { return f, true @@ -212,6 +214,7 @@ func (z *Float) pow5(n uint64) *Float { // // It sets z to the (possibly rounded) value of the corresponding floating- // point value, and returns z, the actual base b, and an error err, if any. +// The entire string (not just a prefix) must be consumed for success. // If z's precision is 0, it is changed to 64 before rounding takes effect. // The number must be of the form: // |
