Skip to content

Commit d398c55

Browse files
authored
close #13196 now that we have dragonbox (#18316)
1 parent 2deb701 commit d398c55

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

tests/stdlib/tjson.nim

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import std/[json,parsejson,strutils]
1111
from std/math import isNaN
1212
when not defined(js):
1313
import std/streams
14+
import stdtest/testutils
15+
from std/fenv import epsilon
1416

1517
proc testRoundtrip[T](t: T, expected: string) =
1618
# checks that `T => json => T2 => json2` is such that json2 = json
@@ -325,6 +327,15 @@ block: # bug #18007
325327
let a = parseJson($(%NaN)).to(float)
326328
doAssert a.isNaN
327329
330+
whenRuntimeJs: discard # refs bug #18009
331+
do:
332+
testRoundtripVal(0.0): "0.0"
333+
testRoundtripVal(-0.0): "-0.0"
334+
335+
block: # bug #15397, bug #13196
336+
testRoundtripVal(1.0 + epsilon(float64)): "1.0000000000000002"
337+
testRoundtripVal(0.12345678901234567890123456789): "0.12345678901234568"
338+
328339
block:
329340
let a = "18446744073709551615"
330341
let b = a.parseJson

tests/stdlib/tjsonutils.nim

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ discard """
55
import std/jsonutils
66
import std/json
77
from std/math import isNaN, signbit
8+
from std/fenv import epsilon
89
from stdtest/testutils import whenRuntimeJs
910

1011
proc testRoundtrip[T](t: T, expected: string) =
@@ -160,6 +161,16 @@ template fn() =
160161
doAssert b[2].signbit
161162
doAssert not b[3].signbit
162163

164+
block: # bug #15397, bug #13196
165+
let a = 0.1
166+
let x = 0.12345678901234567890123456789
167+
let b = (a + 0.2, 0.3, x)
168+
testRoundtripVal(b): "[0.30000000000000004,0.3,0.12345678901234568]"
169+
170+
testRoundtripVal(0.12345678901234567890123456789): "0.12345678901234568"
171+
testRoundtripVal(epsilon(float64)): "2.220446049250313e-16"
172+
testRoundtripVal(1.0 + epsilon(float64)): "1.0000000000000002"
173+
163174
block: # case object
164175
type Foo = object
165176
x0: float

0 commit comments

Comments
 (0)