diff options
author | Andrew Gerrand <adg@golang.org> | 2019-05-31 20:59:35 +1000 |
---|---|---|
committer | Andrew Gerrand <adg@golang.org> | 2019-05-31 11:26:23 +0000 |
commit | 2165452a37b156d154a6e2dc85495b23a4a61565 (patch) | |
tree | 4f8200e046dbc3020fcfb2d190bc76a325fa4acf /src/strconv | |
parent | d53f380e620c59cb3f30736584879c3c104ee488 (diff) | |
download | go-2165452a37b156d154a6e2dc85495b23a4a61565.tar.gz go-2165452a37b156d154a6e2dc85495b23a4a61565.zip |
strconv: document handling of NaN and ±Inf
In addition to the example that was added in 203b80ab, mention these
special cases in the doc comment. This change also adjusts the example
to include "+Inf", as it was not otherwise mentioned that the plus
symbol may be present.
Fix #30990
Change-Id: I97d66f4aff6a17a6ccc0ee2e7f32e39ae91ae454
Reviewed-on: https://go-review.googlesource.com/c/go/+/179738
Reviewed-by: Alex Miasoedov <msoedov@gmail.com>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Run-TryBot: Benny Siegert <bsiegert@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/strconv')
-rw-r--r-- | src/strconv/atof.go | 3 | ||||
-rw-r--r-- | src/strconv/example_test.go | 2 |
2 files changed, 4 insertions, 1 deletions
diff --git a/src/strconv/atof.go b/src/strconv/atof.go index 504b9613fb..0903fa155a 100644 --- a/src/strconv/atof.go +++ b/src/strconv/atof.go @@ -654,6 +654,9 @@ func atof64(s string) (f float64, err error) { // If s is syntactically well-formed but is more than 1/2 ULP // away from the largest floating point number of the given size, // ParseFloat returns f = ±Inf, err.Err = ErrRange. +// +// ParseFloat recognizes the strings "NaN", "+Inf", and "-Inf" as their +// respective special floating point values. It ignores case when matching. func ParseFloat(s string, bitSize int) (float64, error) { if !underscoreOK(s) { return 0, syntaxError(fnParseFloat, s) diff --git a/src/strconv/example_test.go b/src/strconv/example_test.go index 46cfd432fb..50f6b20fee 100644 --- a/src/strconv/example_test.go +++ b/src/strconv/example_test.go @@ -232,7 +232,7 @@ func ExampleParseFloat() { if s, err := strconv.ParseFloat("inf", 32); err == nil { fmt.Printf("%T, %v\n", s, s) } - if s, err := strconv.ParseFloat("Inf", 32); err == nil { + if s, err := strconv.ParseFloat("+Inf", 32); err == nil { fmt.Printf("%T, %v\n", s, s) } if s, err := strconv.ParseFloat("-Inf", 32); err == nil { |