Skip to content

Commit 3a24a09

Browse files
authored
unmarshal nan and infinite values correctly (#715)
1 parent 624594e commit 3a24a09

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

typedapi/types/float64.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ func (f Float64) MarshalJSON() ([]byte, error) {
4646
func (f *Float64) UnmarshalJSON(data []byte) error {
4747
switch {
4848
case bytes.Equal(data, []byte(`"NaN"`)):
49-
nan := Float64(math.NaN())
50-
f = &nan
49+
*f = Float64(math.NaN())
50+
case bytes.Equal(data, []byte(`"+Infinity"`)):
51+
*f = Float64(math.Inf(1))
52+
case bytes.Equal(data, []byte(`"-Infinity"`)):
53+
*f = Float64(math.Inf(-1))
5154
case bytes.Equal(data, []byte(`null`)):
5255
return nil
5356
default:

0 commit comments

Comments
 (0)