diff options
| author | Brad Fitzpatrick <bradfitz@golang.org> | 2011-07-11 07:25:45 -0700 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2011-07-11 07:25:45 -0700 |
| commit | f19b24a182c445ceb3d998b2ebc20f1d8718df9b (patch) | |
| tree | 16a683db8420e3e45b0676b22ecc9fbfd6cef525 /src/pkg | |
| parent | d366c369450991ad9d942fc5aa3ea7e6c99e40a0 (diff) | |
| download | go-f19b24a182c445ceb3d998b2ebc20f1d8718df9b.tar.xz | |
strconv: handle [-+]Infinity in atof
This is the form as returned by Postgres, as well
as JavaScript.
I've tried and failed to find authorative docs online
about the proper string serialization, if any.
R=golang-dev, gri, r, r, rsc
CC=golang-dev
https://golang.org/cl/4650077
Diffstat (limited to 'src/pkg')
| -rw-r--r-- | src/pkg/strconv/atof.go | 10 | ||||
| -rw-r--r-- | src/pkg/strconv/atof_test.go | 3 |
2 files changed, 9 insertions, 4 deletions
diff --git a/src/pkg/strconv/atof.go b/src/pkg/strconv/atof.go index a91e8bfa4a..38b38053ce 100644 --- a/src/pkg/strconv/atof.go +++ b/src/pkg/strconv/atof.go @@ -43,11 +43,13 @@ func special(s string) (f float64, ok bool) { switch { case equalIgnoreCase(s, "nan"): return math.NaN(), true - case equalIgnoreCase(s, "-inf"): + case equalIgnoreCase(s, "-inf"), + equalIgnoreCase(s, "-infinity"): return math.Inf(-1), true - case equalIgnoreCase(s, "+inf"): - return math.Inf(1), true - case equalIgnoreCase(s, "inf"): + case equalIgnoreCase(s, "+inf"), + equalIgnoreCase(s, "+infinity"), + equalIgnoreCase(s, "inf"), + equalIgnoreCase(s, "infinity"): return math.Inf(1), true } return diff --git a/src/pkg/strconv/atof_test.go b/src/pkg/strconv/atof_test.go index 6d8396ee73..0fdd0ea982 100644 --- a/src/pkg/strconv/atof_test.go +++ b/src/pkg/strconv/atof_test.go @@ -47,6 +47,9 @@ var atoftests = []atofTest{ {"inf", "+Inf", nil}, {"-Inf", "-Inf", nil}, {"+INF", "+Inf", nil}, + {"-Infinity", "-Inf", nil}, + {"+INFINITY", "+Inf", nil}, + {"Infinity", "+Inf", nil}, // largest float64 {"1.7976931348623157e308", "1.7976931348623157e+308", nil}, |
