diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2021-02-21 23:47:00 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-22 08:47:00 +0100 |
commit | cde950e1bc4f8fa3ac9b243cb6117dab1eab3645 (patch) | |
tree | 9aa61a808d264a6c197e58c41441dba4b73f55b3 /tests/stdlib | |
parent | 04b11203343b76cb854fcba66cf25d5f7bba3683 (diff) | |
download | Nim-cde950e1bc4f8fa3ac9b243cb6117dab1eab3645.tar.gz |
make copySign for js consistent with other backends (#16609)
* make copySign work more robustly in js * improve tests * improve tests/vm/tcastint.nim
Diffstat (limited to 'tests/stdlib')
-rw-r--r-- | tests/stdlib/tmath.nim | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/tests/stdlib/tmath.nim b/tests/stdlib/tmath.nim index 894c79369..769d89b64 100644 --- a/tests/stdlib/tmath.nim +++ b/tests/stdlib/tmath.nim @@ -197,6 +197,14 @@ template main() = doAssert: compiles(5.5 ^ 2.uint8) doAssert: not compiles(5.5 ^ 2.2) + block: # isNaN + doAssert NaN.isNaN + doAssert not Inf.isNaN + doAssert isNaN(Inf - Inf) + doAssert not isNaN(0.0) + doAssert not isNaN(3.1415926) + doAssert not isNaN(0'f32) + block: # signbit doAssert not signbit(0.0) doAssert signbit(-0.0) @@ -207,14 +215,6 @@ template main() = doAssert signbit(-Inf) doAssert not signbit(NaN) - block: # isNaN - doAssert NaN.isNaN - doAssert not Inf.isNaN - doAssert isNaN(Inf - Inf) - doAssert not isNaN(3.1415926) - doAssert not isNaN(0'f32) - - block: # signbit let x1 = NaN let x2 = -NaN let x3 = -x1 @@ -269,6 +269,10 @@ template main() = doAssert copySign(-NaN, 0.0).isNaN doAssert copySign(-NaN, -0.0).isNaN + doAssert copySign(-1.0, NaN) == 1.0 + doAssert copySign(-1.0, -NaN) == -1.0 + doAssert copySign(1.0, copySign(NaN, -1.0)) == -1.0 + block: # almostEqual doAssert almostEqual(3.141592653589793, 3.1415926535897936) doAssert almostEqual(1.6777215e7'f32, 1.6777216e7'f32) @@ -279,7 +283,7 @@ template main() = doAssert not almostEqual(Inf, NaN) doAssert not almostEqual(NaN, NaN) - block: # round() tests + block: # round block: # Round to 0 decimal places doAssert round(54.652) == 55.0 doAssert round(54.352) == 54.0 @@ -300,6 +304,7 @@ template main() = doAssert round(2.5) == 3.0 doAssert round(2.5'f32) == 3.0'f32 doAssert round(2.5'f64) == 3.0'f64 + block: # func round*[T: float32|float64](x: T, places: int): T doAssert round(54.345, 0) == 54.0 template fn(x) = @@ -311,15 +316,7 @@ template main() = fn(54.346) fn(54.346'f32) - when nimvm: - discard - else: - when not defined(js): - doAssert copySign(-1.0, -NaN) == -1.0 - doAssert copySign(10.0, -NaN) == -10.0 - doAssert copySign(1.0, copySign(NaN, -1.0)) == -1.0 # fails in VM - - block: + block: # abs doAssert 1.0 / abs(-0.0) == Inf doAssert 1.0 / abs(0.0) == Inf doAssert -1.0 / abs(-0.0) == -Inf |