Skip to content

Commit 2165452

Browse files
committed
strconv: document handling of NaN and ±Inf
In addition to the example that was added in 203b80a, 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 <[email protected]> Reviewed-by: Benny Siegert <[email protected]> Run-TryBot: Benny Siegert <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent d53f380 commit 2165452

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/strconv/atof.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,9 @@ func atof64(s string) (f float64, err error) {
654654
// If s is syntactically well-formed but is more than 1/2 ULP
655655
// away from the largest floating point number of the given size,
656656
// ParseFloat returns f = ±Inf, err.Err = ErrRange.
657+
//
658+
// ParseFloat recognizes the strings "NaN", "+Inf", and "-Inf" as their
659+
// respective special floating point values. It ignores case when matching.
657660
func ParseFloat(s string, bitSize int) (float64, error) {
658661
if !underscoreOK(s) {
659662
return 0, syntaxError(fnParseFloat, s)

src/strconv/example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func ExampleParseFloat() {
232232
if s, err := strconv.ParseFloat("inf", 32); err == nil {
233233
fmt.Printf("%T, %v\n", s, s)
234234
}
235-
if s, err := strconv.ParseFloat("Inf", 32); err == nil {
235+
if s, err := strconv.ParseFloat("+Inf", 32); err == nil {
236236
fmt.Printf("%T, %v\n", s, s)
237237
}
238238
if s, err := strconv.ParseFloat("-Inf", 32); err == nil {

0 commit comments

Comments
 (0)