mirror of
https://github.com/golang/go
synced 2024-11-19 14:14:40 -07:00
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
This commit is contained in:
parent
d366c36945
commit
f19b24a182
@ -43,11 +43,13 @@ func special(s string) (f float64, ok bool) {
|
|||||||
switch {
|
switch {
|
||||||
case equalIgnoreCase(s, "nan"):
|
case equalIgnoreCase(s, "nan"):
|
||||||
return math.NaN(), true
|
return math.NaN(), true
|
||||||
case equalIgnoreCase(s, "-inf"):
|
case equalIgnoreCase(s, "-inf"),
|
||||||
|
equalIgnoreCase(s, "-infinity"):
|
||||||
return math.Inf(-1), true
|
return math.Inf(-1), true
|
||||||
case equalIgnoreCase(s, "+inf"):
|
case equalIgnoreCase(s, "+inf"),
|
||||||
return math.Inf(1), true
|
equalIgnoreCase(s, "+infinity"),
|
||||||
case equalIgnoreCase(s, "inf"):
|
equalIgnoreCase(s, "inf"),
|
||||||
|
equalIgnoreCase(s, "infinity"):
|
||||||
return math.Inf(1), true
|
return math.Inf(1), true
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -47,6 +47,9 @@ var atoftests = []atofTest{
|
|||||||
{"inf", "+Inf", nil},
|
{"inf", "+Inf", nil},
|
||||||
{"-Inf", "-Inf", nil},
|
{"-Inf", "-Inf", nil},
|
||||||
{"+INF", "+Inf", nil},
|
{"+INF", "+Inf", nil},
|
||||||
|
{"-Infinity", "-Inf", nil},
|
||||||
|
{"+INFINITY", "+Inf", nil},
|
||||||
|
{"Infinity", "+Inf", nil},
|
||||||
|
|
||||||
// largest float64
|
// largest float64
|
||||||
{"1.7976931348623157e308", "1.7976931348623157e+308", nil},
|
{"1.7976931348623157e308", "1.7976931348623157e+308", nil},
|
||||||
|
Loading…
Reference in New Issue
Block a user