* compiler/vmhooks: add getVar to allow vmops with var params * addFloat vmops with var param * cgen now renders float32 literals in c backend using roundtrip float to string
This commit is contained in:
parent
a8b3e7c059
commit
cf0cf32d27
21 changed files with 286 additions and 199 deletions
|
|
@ -34,3 +34,5 @@ hint("Processing", off)
|
|||
switch("define", "nimExperimentalAsyncjsThen")
|
||||
switch("define", "nimExperimentalJsfetch")
|
||||
switch("define", "nimExperimentalLinenoiseExtra")
|
||||
|
||||
switch("define", "nimFpRoundtrips")
|
||||
|
|
|
|||
|
|
@ -13,12 +13,12 @@ treportunused.nim(30, 5) Hint: 's8' is declared but not used [XDeclaredButNotUse
|
|||
treportunused.nim(31, 5) Hint: 's9' is declared but not used [XDeclaredButNotUsed]
|
||||
treportunused.nim(32, 6) Hint: 's10' is declared but not used [XDeclaredButNotUsed]
|
||||
treportunused.nim(33, 6) Hint: 's11' is declared but not used [XDeclaredButNotUsed]
|
||||
treportunused.nim(37, 3) Hint: 'v0.99' is declared but not used [XDeclaredButNotUsed]
|
||||
treportunused.nim(38, 3) Hint: 'v0.99.99' is declared but not used [XDeclaredButNotUsed]
|
||||
'''
|
||||
action: compile
|
||||
"""
|
||||
|
||||
#treportunused.nim(37, 3) Hint: 'v0.99' is declared but not used [XDeclaredButNotUsed]
|
||||
#treportunused.nim(38, 3) Hint: 'v0.99.99' is declared but not used [XDeclaredButNotUsed]
|
||||
# bug #9764
|
||||
iterator s1(a:string): int = discard
|
||||
iterator s2(): int = discard
|
||||
|
|
@ -32,9 +32,7 @@ var s9: int
|
|||
type s10 = object
|
||||
type s11 = type(1.2)
|
||||
|
||||
when false:
|
||||
# enabled again when Nim bootstraps with -d:nimFpRoundtrips
|
||||
# https://github.com/nim-lang/Nim/issues/14407
|
||||
let
|
||||
`v0.99` = "0.99"
|
||||
`v0.99.99` = "0.99.99"
|
||||
# bug #14407 (requires `compiler/nim.cfg` containing define:nimFpRoundtrips)
|
||||
let
|
||||
`v0.99` = "0.99"
|
||||
`v0.99.99` = "0.99.99"
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
-d:nimFpRoundtrips
|
||||
|
|
@ -1,13 +1,14 @@
|
|||
discard """
|
||||
matrix: "-d:nimFpRoundtrips; -u:nimFpRoundtrips"
|
||||
targets: "c cpp js"
|
||||
"""
|
||||
# disabled: "windows"
|
||||
|
||||
#[
|
||||
xxx merge all or most float tests into this file
|
||||
]#
|
||||
|
||||
import std/[fenv, math, strutils]
|
||||
import stdtest/testutils
|
||||
|
||||
proc equalsOrNaNs(a, b: float): bool =
|
||||
if isNaN(a): isNaN(b)
|
||||
|
|
@ -62,27 +63,103 @@ template main =
|
|||
reject "1_.0"
|
||||
reject "1.0_"
|
||||
|
||||
block: # bug #18148
|
||||
var a = 1.1'f32
|
||||
doAssert $a == "1.1", $a # was failing
|
||||
block: # bugs mentioned in https://github.com/nim-lang/Nim/pull/18504#issuecomment-881635317
|
||||
block: # example 1
|
||||
let a = 0.1+0.2
|
||||
doAssert a != 0.3
|
||||
when defined(nimFpRoundtrips):
|
||||
doAssert $a == "0.30000000000000004"
|
||||
else:
|
||||
whenRuntimeJs: discard
|
||||
do: doAssert $a == "0.3"
|
||||
block: # example 2
|
||||
const a = 0.1+0.2
|
||||
when defined(nimFpRoundtrips):
|
||||
doAssert $($a, a) == """("0.30000000000000004", 0.30000000000000004)"""
|
||||
else:
|
||||
whenRuntimeJs: discard
|
||||
do: doAssert $($a, a) == """("0.3", 0.3)"""
|
||||
block: # example 3
|
||||
const a1 = 0.1+0.2
|
||||
let a2 = a1
|
||||
doAssert a1 != 0.3
|
||||
when defined(nimFpRoundtrips):
|
||||
doAssert $[$a1, $a2] == """["0.30000000000000004", "0.30000000000000004"]"""
|
||||
else:
|
||||
whenRuntimeJs: discard
|
||||
do: doAssert $[$a1, $a2] == """["0.3", "0.3"]"""
|
||||
|
||||
proc runtimeOnlyTests =
|
||||
# enable for 'static' once -d:nimFpRoundtrips became the default
|
||||
block: # bug #7717
|
||||
proc test(f: float) =
|
||||
let f2 = $f
|
||||
let f3 = parseFloat(f2)
|
||||
doAssert equalsOrNaNs(f, f3), $(f, f2, f3)
|
||||
when defined(nimFpRoundtrips):
|
||||
block: # bug #18148
|
||||
var a = 1.1'f32
|
||||
doAssert $a == "1.1", $a # was failing
|
||||
|
||||
test 1.0 + epsilon(float64)
|
||||
test 1000000.0000000123
|
||||
test log2(100000.0)
|
||||
test maximumPositiveValue(float32)
|
||||
test maximumPositiveValue(float64)
|
||||
test minimumPositiveValue(float32)
|
||||
test minimumPositiveValue(float64)
|
||||
block: # bug #18400
|
||||
block:
|
||||
let a1 = 0.1'f32
|
||||
let a2 = 0.2'f32
|
||||
let a3 = a1 + a2
|
||||
var s = ""
|
||||
s.addFloat(a3)
|
||||
whenVMorJs: discard # xxx refs #12884
|
||||
do:
|
||||
doAssert a3 == 0.3'f32
|
||||
doAssert $a3 == "0.3"
|
||||
|
||||
block:
|
||||
let a1 = 0.1
|
||||
let a2 = 0.2
|
||||
let a3 = a1 + a2
|
||||
var s = ""
|
||||
s.addFloat(a3)
|
||||
doAssert a3 != 0.3
|
||||
doAssert $a3 == "0.30000000000000004"
|
||||
|
||||
block:
|
||||
var s = [-13.888888'f32]
|
||||
whenRuntimeJs: discard
|
||||
do:
|
||||
doAssert $s == "[-13.888888]"
|
||||
doAssert $s[0] == "-13.888888"
|
||||
|
||||
block: # bug #7717
|
||||
proc test(f: float) =
|
||||
let f2 = $f
|
||||
let f3 = parseFloat(f2)
|
||||
doAssert equalsOrNaNs(f, f3), $(f, f2, f3)
|
||||
test 1.0 + epsilon(float64)
|
||||
test 1000000.0000000123
|
||||
test log2(100000.0)
|
||||
test maximumPositiveValue(float32)
|
||||
test maximumPositiveValue(float64)
|
||||
test minimumPositiveValue(float32)
|
||||
test minimumPositiveValue(float64)
|
||||
|
||||
block: # bug #12884
|
||||
block: # example 1
|
||||
const x0: float32 = 1.32
|
||||
let x1 = 1.32
|
||||
let x2 = 1.32'f32
|
||||
var x3: float32 = 1.32
|
||||
doAssert $(x0, x1, x2, x3) == "(1.32, 1.32, 1.32, 1.32)"
|
||||
block: # example https://github.com/nim-lang/Nim/issues/12884#issuecomment-564967962
|
||||
let x = float(1.32'f32)
|
||||
when nimvm: discard # xxx prints 1.3
|
||||
else:
|
||||
when not defined(js):
|
||||
doAssert $x == "1.3200000524520874"
|
||||
doAssert $1.32 == "1.32"
|
||||
doAssert $1.32'f32 == "1.32"
|
||||
let x2 = 1.32'f32
|
||||
doAssert $x2 == "1.32"
|
||||
block:
|
||||
var x = 1.23456789012345'f32
|
||||
when nimvm:
|
||||
discard # xxx, refs #12884
|
||||
else:
|
||||
when not defined(js):
|
||||
doAssert x == 1.2345679'f32
|
||||
doAssert $x == "1.2345679"
|
||||
|
||||
static: main()
|
||||
main()
|
||||
|
||||
runtimeOnlyTests()
|
||||
|
|
|
|||
|
|
@ -303,7 +303,7 @@ let jsonNode = %*mynode
|
|||
doAssert $jsonNode == """{"kind":"P","pChildren":[{"kind":"Text","textStr":"mychild"},{"kind":"Br"}]}"""
|
||||
doAssert $jsonNode.to(ContentNode) == """(kind: P, pChildren: @[(kind: Text, textStr: "mychild"), (kind: Br)])"""
|
||||
|
||||
when defined(nimFpRoundtrips): # bug #17383
|
||||
block: # bug #17383
|
||||
testRoundtrip(int32.high): "2147483647"
|
||||
testRoundtrip(uint32.high): "4294967295"
|
||||
when int.sizeof == 4:
|
||||
|
|
@ -316,7 +316,7 @@ when defined(nimFpRoundtrips): # bug #17383
|
|||
testRoundtrip(int64.high): "9223372036854775807"
|
||||
testRoundtrip(uint64.high): "18446744073709551615"
|
||||
|
||||
when defined(nimFpRoundtrips): # bug #18007
|
||||
block: # bug #18007
|
||||
testRoundtrip([NaN, Inf, -Inf, 0.0, -0.0, 1.0]): """["nan","inf","-inf",0.0,-0.0,1.0]"""
|
||||
# pending https://github.com/nim-lang/Nim/issues/18025 use:
|
||||
# testRoundtrip([float32(NaN), Inf, -Inf, 0.0, -0.0, 1.0])
|
||||
|
|
@ -332,7 +332,7 @@ when defined(nimFpRoundtrips): # bug #18007
|
|||
testRoundtripVal(0.0): "0.0"
|
||||
testRoundtripVal(-0.0): "-0.0"
|
||||
|
||||
when defined(nimFpRoundtrips): # bug #15397, bug #13196
|
||||
block: # bug #15397, bug #13196
|
||||
testRoundtripVal(1.0 + epsilon(float64)): "1.0000000000000002"
|
||||
testRoundtripVal(0.12345678901234567890123456789): "0.12345678901234568"
|
||||
|
||||
|
|
|
|||
|
|
@ -161,16 +161,15 @@ template fn() =
|
|||
doAssert b[2].signbit
|
||||
doAssert not b[3].signbit
|
||||
|
||||
when defined(nimFpRoundtrips):
|
||||
block: # bug #15397, bug #13196
|
||||
let a = 0.1
|
||||
let x = 0.12345678901234567890123456789
|
||||
let b = (a + 0.2, 0.3, x)
|
||||
testRoundtripVal(b): "[0.30000000000000004,0.3,0.12345678901234568]"
|
||||
block: # bug #15397, bug #13196
|
||||
let a = 0.1
|
||||
let x = 0.12345678901234567890123456789
|
||||
let b = (a + 0.2, 0.3, x)
|
||||
testRoundtripVal(b): "[0.30000000000000004,0.3,0.12345678901234568]"
|
||||
|
||||
testRoundtripVal(0.12345678901234567890123456789): "0.12345678901234568"
|
||||
testRoundtripVal(epsilon(float64)): "2.220446049250313e-16"
|
||||
testRoundtripVal(1.0 + epsilon(float64)): "1.0000000000000002"
|
||||
testRoundtripVal(0.12345678901234567890123456789): "0.12345678901234568"
|
||||
testRoundtripVal(epsilon(float64)): "2.220446049250313e-16"
|
||||
testRoundtripVal(1.0 + epsilon(float64)): "1.0000000000000002"
|
||||
|
||||
block: # case object
|
||||
type Foo = object
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue