From: Brad Fitzpatrick Date: Mon, 11 Jul 2011 14:25:45 +0000 (-0700) Subject: strconv: handle [-+]Infinity in atof X-Git-Tag: weekly.2011-07-19~131 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f19b24a182c445ceb3d998b2ebc20f1d8718df9b;p=gostls13.git 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 --- 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},