]> Cypherpunks repositories - gostls13.git/commitdiff
strconv: Document ParseFloat's special cases
authorAlex Myasoedov <msoedov@gmail.com>
Sun, 28 Apr 2019 12:43:46 +0000 (15:43 +0300)
committerBenny Siegert <bsiegert@gmail.com>
Mon, 29 Apr 2019 11:07:31 +0000 (11:07 +0000)
Updates #30990

Change-Id: I968fb13251ab3796328089046a3f0fc5c7eb9df9
Reviewed-on: https://go-review.googlesource.com/c/go/+/174204
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Run-TryBot: Benny Siegert <bsiegert@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/strconv/example_test.go

index 2d1a2a9dbfd506eaaa55f46e2be56b4bec3984b9..46cfd432fbf535d1327a25f6d44c0437df897b40 100644 (file)
@@ -222,10 +222,39 @@ func ExampleParseFloat() {
        if s, err := strconv.ParseFloat(v, 64); err == nil {
                fmt.Printf("%T, %v\n", s, s)
        }
+       if s, err := strconv.ParseFloat("NaN", 32); err == nil {
+               fmt.Printf("%T, %v\n", s, s)
+       }
+       // ParseFloat is case insensitive
+       if s, err := strconv.ParseFloat("nan", 32); err == nil {
+               fmt.Printf("%T, %v\n", s, s)
+       }
+       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 {
+               fmt.Printf("%T, %v\n", s, s)
+       }
+       if s, err := strconv.ParseFloat("-Inf", 32); err == nil {
+               fmt.Printf("%T, %v\n", s, s)
+       }
+       if s, err := strconv.ParseFloat("-0", 32); err == nil {
+               fmt.Printf("%T, %v\n", s, s)
+       }
+       if s, err := strconv.ParseFloat("+0", 32); err == nil {
+               fmt.Printf("%T, %v\n", s, s)
+       }
 
        // Output:
        // float64, 3.1415927410125732
        // float64, 3.1415926535
+       // float64, NaN
+       // float64, NaN
+       // float64, +Inf
+       // float64, +Inf
+       // float64, -Inf
+       // float64, -0
+       // float64, 0
 }
 
 func ExampleParseInt() {