Encode ±INFINITY as ±1e5000

The V8 behavior of encoding infinity as null doesn't make sense to me.
Using ±1e5000 is better, because JSON.parse decodes it as INFINITY and
the information is preserved. This could be a breaking change for some
This commit is contained in:
Justine Tunney 2024-06-01 03:15:23 -07:00
parent 9b6718ac99
commit fae1c32267
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
3 changed files with 7 additions and 12 deletions

View file

@ -22,7 +22,7 @@ assert(EncodeJson(0) == "0")
assert(EncodeJson(0.0) == "0")
assert(EncodeJson(3.14) == "3.14")
assert(EncodeJson(0/0) == "null")
assert(EncodeJson(math.huge) == "null")
assert(EncodeJson(math.huge) == "1e5000")
assert(EncodeJson(123.456e-789) == '0')
assert(EncodeJson(9223372036854775807) == '9223372036854775807')
assert(EncodeJson(-9223372036854775807 - 1) == '-9223372036854775808')