diff --git a/lib/pure/json.nim b/lib/pure/json.nim index 6ec0d1616023..319a7b7ffe5e 100644 --- a/lib/pure/json.nim +++ b/lib/pure/json.nim @@ -677,7 +677,7 @@ proc pretty*(node: JsonNode, indent = 2): string = ## Similar to prettyprint in Python. runnableExamples: let j = %* {"name": "Isaac", "books": ["Robot Dreams"], - "details": {"age": 35, "number": 3.125}} + "details": {"age": 35, "pi": 3.1415}} doAssert pretty(j) == """ { "name": "Isaac", @@ -686,7 +686,7 @@ proc pretty*(node: JsonNode, indent = 2): string = ], "details": { "age": 35, - "number": 3.125 + "pi": 3.1415 } }""" result = "" diff --git a/lib/system/formatfloat.nim b/lib/system/formatfloat.nim index abacca4dfcde..cb46c8c36139 100644 --- a/lib/system/formatfloat.nim +++ b/lib/system/formatfloat.nim @@ -29,7 +29,7 @@ proc writeFloatToBuffer*(buf: var array[65, char]; value: BiggestFloat): int = ## * `buf` - A buffer to write into. The buffer does not need to be ## initialized and it will be overridden. ## - var n: int = c_sprintf(addr buf, "%.17g", value) + var n: int = c_sprintf(addr buf, "%.16g", value) var hasDot = false for i in 0..n-1: if buf[i] == ',': diff --git a/tests/errmsgs/tsigmatch.nim b/tests/errmsgs/tsigmatch.nim index 2e08e00d5334..21e2c217d806 100644 --- a/tests/errmsgs/tsigmatch.nim +++ b/tests/errmsgs/tsigmatch.nim @@ -58,7 +58,7 @@ proc f(a1: string; a2: varargs[string]; a3: float; a4: var string) required type for a4: var string but expression '"bad"' is immutable, not 'var' -expression: f("asdf", "1", "2", "3", "4", 2.25, "bad") +expression: f("asdf", "1", "2", "3", "4", 2.3, "bad") tsigmatch.nim(164, 4) Error: type mismatch: got but expected one of: proc f(x: string; a0: var int) @@ -153,7 +153,7 @@ block: # sigmatch gets confused with param/arg position after varargs proc f(a1: int) = discard proc f(a1: string, a2: varargs[string], a3: float, a4: var string) = discard - f("asdf", "1", "2", "3", "4", 2.25, "bad") + f("asdf", "1", "2", "3", "4", 2.3, "bad") block: # bug: https://github.com/nim-lang/Nim/issues/11061#issuecomment-508970046 @@ -169,3 +169,4 @@ block: proc fun1(a1: MyInt, a2: Mystring) = discard proc fun1(a1: float, a2: Mystring) = discard fun1(Mystring.default, "asdf") + diff --git a/tests/float/tfloat6.nim b/tests/float/tfloat6.nim index 1aaea690010c..c4cd6e9327c1 100644 --- a/tests/float/tfloat6.nim +++ b/tests/float/tfloat6.nim @@ -1,14 +1,23 @@ discard """ -disabled: "windows" + output: ''' +1e-06 : 1e-06 +1e-06 : 1e-06 +0.001 : 0.001 +1e-06 : 1e-06 +1e-06 : 1e-06 +10.000001 : 10.000001 +100.000001 : 100.000001 +''' + disabled: "windows" """ import strutils -doAssert "0.00_0001".parseFloat() == 1E-6 -doAssert "0.00__00_01".parseFloat() == 1E-6 -doAssert "0.0_01".parseFloat() == 0.001 -doAssert "0.00_000_1".parseFloat() == 1E-6 -doAssert "0.00000_1".parseFloat() == 1E-6 +echo "0.00_0001".parseFloat(), " : ", 1E-6 +echo "0.00__00_01".parseFloat(), " : ", 1E-6 +echo "0.0_01".parseFloat(), " : ", 0.001 +echo "0.00_000_1".parseFloat(), " : ", 1E-6 +echo "0.00000_1".parseFloat(), " : ", 1E-6 -doAssert "1_0.00_0001".parseFloat() == 10.000001 -doAssert "1__00.00_0001".parseFloat() == 1_00.000001 +echo "1_0.00_0001".parseFloat(), " : ", 10.000001 +echo "1__00.00_0001".parseFloat(), " : ", 1_00.000001 diff --git a/tests/float/tfloat8.nim b/tests/float/tfloat8.nim deleted file mode 100644 index 02075bb4feea..000000000000 --- a/tests/float/tfloat8.nim +++ /dev/null @@ -1,19 +0,0 @@ -discard """ -disabled: windows -""" - -{.passL: "-lm".} # not sure how to do this on windows - -import strutils - -proc nextafter(a,b: float64): float64 {.importc: "nextafter", header: "".} - -var myFloat = 2.5 - -for i in 0 .. 100: - let newFloat = nextafter(myFloat, Inf) - let oldStr = $myFloat - let newStr = $newFloat - doAssert parseFloat(newStr) == newFloat - doAssert oldStr != newStr - myFloat = newFloat diff --git a/tests/generics/tforwardgeneric.nim b/tests/generics/tforwardgeneric.nim index a986c7b2bfd4..9f68bf332e32 100644 --- a/tests/generics/tforwardgeneric.nim +++ b/tests/generics/tforwardgeneric.nim @@ -1,11 +1,11 @@ discard """ - output: "1.125 11\n42\n0" + output: "1.1 11\n42\n0" ccodecheck: "!@'ClEnv'" """ proc p[T](a, b: T): T -echo p(0.875, 0.125), " ", p(9, 1) +echo p(0.9, 0.1), " ", p(9, 1) proc p[T](a, b: T): T = let c = b @@ -25,3 +25,4 @@ proc print[T](t: T) = echo t echo bar() + diff --git a/tests/generics/tgenerics_issues.nim b/tests/generics/tgenerics_issues.nim index 64884db046a8..af71a89380f0 100644 --- a/tests/generics/tgenerics_issues.nim +++ b/tests/generics/tgenerics_issues.nim @@ -6,7 +6,7 @@ discard """ perm: 22 det: 22 TMatrix[3, 3, system.int] 3 -@[0.875, 0.125] +@[0.9, 0.1] U[3] U[(f: 3)] U[[3]] @@ -20,9 +20,9 @@ concrete 88 2 3 !!Hi!! -G:0,1:0.125 -G:0,1:0.125 -H:1:0.125 +G:0,1:0.1 +G:0,1:0.1 +H:1:0.1 ''' joinable: false """ @@ -370,7 +370,7 @@ block t2304: type TV2[T:SomeNumber] = array[0..1, T] proc newV2T[T](x, y: T=0): TV2[T] = [x, y] - let x = newV2T[float](0.875, 0.125) + let x = newV2T[float](0.9, 0.1) echo(@x) @@ -711,7 +711,7 @@ block t4863: proc q[j: static[int]](x:H[j]) = echo "H:", j, ":", x.v var - g0 = G[0,1](v: 0.125) + g0 = G[0,1](v: 0.1) h0:H[1] = g0 p(g0) p(h0) diff --git a/tests/objects/t12753.nim b/tests/objects/t12753.nim index dc55243d29ce..1009433bef00 100644 --- a/tests/objects/t12753.nim +++ b/tests/objects/t12753.nim @@ -1,7 +1,7 @@ discard """ output: ''' -(v: [(v: [0.0, 1.125]), (v: [2.25, 3.375])]) -(v: [(v: [0.0, 1.125]), (v: [2.25, 3.375])]) +(v: [(v: [0.0, 1.1]), (v: [2.2, 3.3])]) +(v: [(v: [0.0, 1.1]), (v: [2.2, 3.3])]) ''' """ @@ -13,7 +13,7 @@ type var a = M(v:[ V(v:[0.0,1.0]), V(v:[2.0,3.0]) ]) - b = M(v:[ V(v:[0.0,0.125]), V(v:[0.25,0.375]) ]) + b = M(v:[ V(v:[0.0,0.1]), V(v:[0.2,0.3]) ]) echo M(v: [V(v: [b.v[0].v[0] + a.v[0].v[0], b.v[0].v[1] + a.v[0].v[1]]), V(v: [b.v[1].v[0] + a.v[1].v[0], b.v[1].v[1] + a.v[1].v[1]])]) diff --git a/tests/showoff/tdrdobbs_examples.nim b/tests/showoff/tdrdobbs_examples.nim index dd9d4ed7246e..0e10c6dd89ef 100644 --- a/tests/showoff/tdrdobbs_examples.nim +++ b/tests/showoff/tdrdobbs_examples.nim @@ -1,7 +1,7 @@ discard """ output: '''108 11 -1 1936 -0.5 +0.4 true truefalse''' """ @@ -75,7 +75,7 @@ proc evaluate(n: Formula, varToVal: proc (name: string): float): float = of fkMul: evaluate(n.left, varToVal) * evaluate(n.right, varToVal) of fkExp: pow(evaluate(n.left, varToVal), evaluate(n.right, varToVal)) -echo evaluate(Formula(kind: fkLit, value: 0.5), nil) +echo evaluate(Formula(kind: fkLit, value: 0.4), nil) proc isPolyTerm(n: Formula): bool = n.kind == fkMul and n.left.kind == fkLit and (let e = n.right; diff --git a/tests/system/tostring.nim b/tests/system/tostring.nim index ea882e77ae57..ea4a44417f3d 100644 --- a/tests/system/tostring.nim +++ b/tests/system/tostring.nim @@ -11,6 +11,10 @@ doAssert """["", "foo", "bar"]""" == $(@["", "foo", "bar"].toOpenArray(0, 2)) # bug #2395 let alphaSet: set[char] = {'a'..'c'} doAssert "{'a', 'b', 'c'}" == $alphaSet +doAssert "2.3242" == $(2.3242) +doAssert "2.982" == $(2.982) +doAssert "123912.1" == $(123912.1) +doAssert "123912.1823" == $(123912.1823) doAssert "5.0" == $(5.0) doAssert "1e+100" == $(1e100) doAssert "inf" == $(1e1000000)