mirror of
https://github.com/golang/go
synced 2024-11-24 05:30:24 -07:00
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>
This commit is contained in:
parent
d016330241
commit
203b80ab86
@ -222,10 +222,39 @@ func ExampleParseFloat() {
|
|||||||
if s, err := strconv.ParseFloat(v, 64); err == nil {
|
if s, err := strconv.ParseFloat(v, 64); err == nil {
|
||||||
fmt.Printf("%T, %v\n", s, s)
|
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:
|
// Output:
|
||||||
// float64, 3.1415927410125732
|
// float64, 3.1415927410125732
|
||||||
// float64, 3.1415926535
|
// float64, 3.1415926535
|
||||||
|
// float64, NaN
|
||||||
|
// float64, NaN
|
||||||
|
// float64, +Inf
|
||||||
|
// float64, +Inf
|
||||||
|
// float64, -Inf
|
||||||
|
// float64, -0
|
||||||
|
// float64, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExampleParseInt() {
|
func ExampleParseInt() {
|
||||||
|
Loading…
Reference in New Issue
Block a user