]> Cypherpunks repositories - gostls13.git/commitdiff
strconv: document handling of NaN and ±Inf
authorAndrew Gerrand <adg@golang.org>
Fri, 31 May 2019 10:59:35 +0000 (20:59 +1000)
committerAndrew Gerrand <adg@golang.org>
Fri, 31 May 2019 11:26:23 +0000 (11:26 +0000)
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>

src/strconv/atof.go
src/strconv/example_test.go

index 504b9613fb06a63ef611efadc77ea9fb1c56d59a..0903fa155ae7cd8cf52a004630b0ac81ffe40a9f 100644 (file)
@@ -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)
index 46cfd432fbf535d1327a25f6d44c0437df897b40..50f6b20fee22547f3d8dca92f457b15158e886a3 100644 (file)
@@ -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 {