Revert "printing float values will have one more digit. (#13276) [backport]" (#13363)

This reverts commit b2c6db97f9.
This commit is contained in:
Timothee Cour 2020-02-08 00:30:24 -08:00 • committed by GitHub
commit e4415422fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 41 additions and 45 deletions

View file

@ -677,7 +677,7 @@ proc pretty*(node: JsonNode, indent = 2): string =
## Similar to prettyprint in Python. ## Similar to prettyprint in Python.
runnableExamples: runnableExamples:
let j = %* {"name": "Isaac", "books": ["Robot Dreams"], let j = %* {"name": "Isaac", "books": ["Robot Dreams"],
"details": {"age": 35, "number": 3.125}} "details": {"age": 35, "pi": 3.1415}}
doAssert pretty(j) == """ doAssert pretty(j) == """
{ {
"name": "Isaac", "name": "Isaac",
@ -686,7 +686,7 @@ proc pretty*(node: JsonNode, indent = 2): string =
], ],
"details": { "details": {
"age": 35, "age": 35,
"number": 3.125 "pi": 3.1415
} }
}""" }"""
result = "" result = ""

View file

@ -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 ## * `buf` - A buffer to write into. The buffer does not need to be
## initialized and it will be overridden. ## 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 var hasDot = false
for i in 0..n-1: for i in 0..n-1:
if buf[i] == ',': if buf[i] == ',':

View file

@ -58,7 +58,7 @@ proc f(a1: string; a2: varargs[string]; a3: float; a4: var string)
required type for a4: var string required type for a4: var string
but expression '"bad"' is immutable, not 'var' 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 <string, a0: int literal(12)> tsigmatch.nim(164, 4) Error: type mismatch: got <string, a0: int literal(12)>
but expected one of: but expected one of:
proc f(x: string; a0: var int) proc f(x: string; a0: var int)
@ -153,7 +153,7 @@ block:
# sigmatch gets confused with param/arg position after varargs # sigmatch gets confused with param/arg position after varargs
proc f(a1: int) = discard proc f(a1: int) = discard
proc f(a1: string, a2: varargs[string], a3: float, a4: var string) = 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: block:
# bug: https://github.com/nim-lang/Nim/issues/11061#issuecomment-508970046 # 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: MyInt, a2: Mystring) = discard
proc fun1(a1: float, a2: Mystring) = discard proc fun1(a1: float, a2: Mystring) = discard
fun1(Mystring.default, "asdf") fun1(Mystring.default, "asdf")

View file

@ -1,14 +1,23 @@
discard """ discard """
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" disabled: "windows"
""" """
import strutils import strutils
doAssert "0.00_0001".parseFloat() == 1E-6 echo "0.00_0001".parseFloat(), " : ", 1E-6
doAssert "0.00__00_01".parseFloat() == 1E-6 echo "0.00__00_01".parseFloat(), " : ", 1E-6
doAssert "0.0_01".parseFloat() == 0.001 echo "0.0_01".parseFloat(), " : ", 0.001
doAssert "0.00_000_1".parseFloat() == 1E-6 echo "0.00_000_1".parseFloat(), " : ", 1E-6
doAssert "0.00000_1".parseFloat() == 1E-6 echo "0.00000_1".parseFloat(), " : ", 1E-6
doAssert "1_0.00_0001".parseFloat() == 10.000001 echo "1_0.00_0001".parseFloat(), " : ", 10.000001
doAssert "1__00.00_0001".parseFloat() == 1_00.000001 echo "1__00.00_0001".parseFloat(), " : ", 1_00.000001

View file

@ -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: "<math.h>".}
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

View file

@ -1,11 +1,11 @@
discard """ discard """
output: "1.125 11\n42\n0" output: "1.1 11\n42\n0"
ccodecheck: "!@'ClEnv'" ccodecheck: "!@'ClEnv'"
""" """
proc p[T](a, b: T): T 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 = proc p[T](a, b: T): T =
let c = b let c = b
@ -25,3 +25,4 @@ proc print[T](t: T) =
echo t echo t
echo bar() echo bar()

View file

@ -6,7 +6,7 @@ discard """
perm: 22 det: 22 perm: 22 det: 22
TMatrix[3, 3, system.int] TMatrix[3, 3, system.int]
3 3
@[0.875, 0.125] @[0.9, 0.1]
U[3] U[3]
U[(f: 3)] U[(f: 3)]
U[[3]] U[[3]]
@ -20,9 +20,9 @@ concrete 88
2 2
3 3
!!Hi!! !!Hi!!
G:0,1:0.125 G:0,1:0.1
G:0,1:0.125 G:0,1:0.1
H:1:0.125 H:1:0.1
''' '''
joinable: false joinable: false
""" """
@ -370,7 +370,7 @@ block t2304:
type TV2[T:SomeNumber] = array[0..1, T] type TV2[T:SomeNumber] = array[0..1, T]
proc newV2T[T](x, y: T=0): TV2[T] = [x, y] 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) echo(@x)
@ -711,7 +711,7 @@ block t4863:
proc q[j: static[int]](x:H[j]) = echo "H:", j, ":", x.v proc q[j: static[int]](x:H[j]) = echo "H:", j, ":", x.v
var var
g0 = G[0,1](v: 0.125) g0 = G[0,1](v: 0.1)
h0:H[1] = g0 h0:H[1] = g0
p(g0) p(g0)
p(h0) p(h0)

View file

@ -1,7 +1,7 @@
discard """ discard """
output: ''' output: '''
(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.125]), (v: [2.25, 3.375])]) (v: [(v: [0.0, 1.1]), (v: [2.2, 3.3])])
''' '''
""" """
@ -13,7 +13,7 @@ type
var var
a = M(v:[ V(v:[0.0,1.0]), V(v:[2.0,3.0]) ]) 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]]), 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]])]) V(v: [b.v[1].v[0] + a.v[1].v[0], b.v[1].v[1] + a.v[1].v[1]])])

View file

@ -1,7 +1,7 @@
discard """ discard """
output: '''108 output: '''108
11 -1 1936 11 -1 1936
0.5 0.4
true true
truefalse''' 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 fkMul: evaluate(n.left, varToVal) * evaluate(n.right, varToVal)
of fkExp: pow(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 = proc isPolyTerm(n: Formula): bool =
n.kind == fkMul and n.left.kind == fkLit and (let e = n.right; n.kind == fkMul and n.left.kind == fkLit and (let e = n.right;

View file

@ -11,6 +11,10 @@ doAssert """["", "foo", "bar"]""" == $(@["", "foo", "bar"].toOpenArray(0, 2))
# bug #2395 # bug #2395
let alphaSet: set[char] = {'a'..'c'} let alphaSet: set[char] = {'a'..'c'}
doAssert "{'a', 'b', 'c'}" == $alphaSet 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 "5.0" == $(5.0)
doAssert "1e+100" == $(1e100) doAssert "1e+100" == $(1e100)
doAssert "inf" == $(1e1000000) doAssert "inf" == $(1e1000000)