aboutsummaryrefslogtreecommitdiff
path: root/src/strconv
diff options
context:
space:
mode:
authorAlex Myasoedov <msoedov@gmail.com>2019-04-28 15:43:46 +0300
committerBenny Siegert <bsiegert@gmail.com>2019-04-29 11:07:31 +0000
commit203b80ab8639ff9dc0710e22c2b33f2df861363b (patch)
treea392e299741bea01ed42f02e6bd4bd5da3f3d7fc /src/strconv
parentd016330241c526f09b5ec70cdf17bfd0c257006b (diff)
downloadgo-203b80ab8639ff9dc0710e22c2b33f2df861363b.tar.gz
go-203b80ab8639ff9dc0710e22c2b33f2df861363b.zip
strconv: Document ParseFloat's special cases
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>
Diffstat (limited to 'src/strconv')
-rw-r--r--src/strconv/example_test.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/strconv/example_test.go b/src/strconv/example_test.go
index 2d1a2a9dbf..46cfd432fb 100644
--- a/src/strconv/example_test.go
+++ b/src/strconv/example_test.go
@@ -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() {