Commit f19b24a1 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

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
parent d366c369
......@@ -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
......
......@@ -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},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment