Skip to content

Commit 203b80a

Browse files
msoedovbsiegert
authored andcommitted
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 <[email protected]> Run-TryBot: Benny Siegert <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent d016330 commit 203b80a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/strconv/example_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,39 @@ func ExampleParseFloat() {
222222
if s, err := strconv.ParseFloat(v, 64); err == nil {
223223
fmt.Printf("%T, %v\n", s, s)
224224
}
225+
if s, err := strconv.ParseFloat("NaN", 32); err == nil {
226+
fmt.Printf("%T, %v\n", s, s)
227+
}
228+
// ParseFloat is case insensitive
229+
if s, err := strconv.ParseFloat("nan", 32); err == nil {
230+
fmt.Printf("%T, %v\n", s, s)
231+
}
232+
if s, err := strconv.ParseFloat("inf", 32); err == nil {
233+
fmt.Printf("%T, %v\n", s, s)
234+
}
235+
if s, err := strconv.ParseFloat("Inf", 32); err == nil {
236+
fmt.Printf("%T, %v\n", s, s)
237+
}
238+
if s, err := strconv.ParseFloat("-Inf", 32); err == nil {
239+
fmt.Printf("%T, %v\n", s, s)
240+
}
241+
if s, err := strconv.ParseFloat("-0", 32); err == nil {
242+
fmt.Printf("%T, %v\n", s, s)
243+
}
244+
if s, err := strconv.ParseFloat("+0", 32); err == nil {
245+
fmt.Printf("%T, %v\n", s, s)
246+
}
225247

226248
// Output:
227249
// float64, 3.1415927410125732
228250
// float64, 3.1415926535
251+
// float64, NaN
252+
// float64, NaN
253+
// float64, +Inf
254+
// float64, +Inf
255+
// float64, -Inf
256+
// float64, -0
257+
// float64, 0
229258
}
230259

231260
func ExampleParseInt() {

0 commit comments

Comments
 (0)