Commit 2165452a authored by Andrew Gerrand's avatar Andrew Gerrand

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/+/179738Reviewed-by: default avatarAlex Miasoedov <msoedov@gmail.com>
Reviewed-by: default avatarBenny Siegert <bsiegert@gmail.com>
Run-TryBot: Benny Siegert <bsiegert@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent d53f380e
...@@ -654,6 +654,9 @@ func atof64(s string) (f float64, err error) { ...@@ -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 // If s is syntactically well-formed but is more than 1/2 ULP
// away from the largest floating point number of the given size, // away from the largest floating point number of the given size,
// ParseFloat returns f = ±Inf, err.Err = ErrRange. // 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) { func ParseFloat(s string, bitSize int) (float64, error) {
if !underscoreOK(s) { if !underscoreOK(s) {
return 0, syntaxError(fnParseFloat, s) return 0, syntaxError(fnParseFloat, s)
......
...@@ -232,7 +232,7 @@ func ExampleParseFloat() { ...@@ -232,7 +232,7 @@ func ExampleParseFloat() {
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) 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) 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 {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment