summary refs log tree commit diff stats
path: root/tests/stdlib
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2021-01-28 01:40:18 -0800
committerGitHub <noreply@github.com>2021-01-28 10:40:18 +0100
commitb0f38a63c4916be139f1a289264a5df68bcb4c07 (patch)
tree730fa475d6dba289223314a2f7dc4ccb9161eb01 /tests/stdlib
parent37a98c6c58d25d69f0a4cb655d976c40375097db (diff)
downloadNim-b0f38a63c4916be139f1a289264a5df68bcb4c07.tar.gz
fix #16815 round(x,places) works again in vm (#16825)
* fix #16815 round+places works again in vm

* improve tests; fix for linux 32bit

* fix test for windows
Diffstat (limited to 'tests/stdlib')
-rw-r--r--tests/stdlib/tmath.nim58
1 files changed, 30 insertions, 28 deletions
diff --git a/tests/stdlib/tmath.nim b/tests/stdlib/tmath.nim
index edab62a66..7af9eb73e 100644
--- a/tests/stdlib/tmath.nim
+++ b/tests/stdlib/tmath.nim
@@ -168,14 +168,6 @@ block:
       let x: seq[float] = @[]
       doAssert prod(x) == 1.0
 
-    block: # round() tests
-      # Round to 0 decimal places
-      doAssert round(54.652) == 55.0
-      doAssert round(54.352) == 54.0
-      doAssert round(-54.652) == -55.0
-      doAssert round(-54.352) == -54.0
-      doAssert round(0.0) == 0.0
-
     block: # splitDecimal() tests
       doAssert splitDecimal(54.674).intpart == 54.0
       doAssert splitDecimal(54.674).floatpart ==~ 0.674
@@ -372,26 +364,36 @@ template main =
     doAssert copySign(-NaN, -0.0).isNaN
 
     block: # round() tests
-      # Round to 0 decimal places
-      doAssert round(54.652) == 55.0
-      doAssert round(54.352) == 54.0
-      doAssert round(-54.652) == -55.0
-      doAssert round(-54.352) == -54.0
-      doAssert round(0.0) == 0.0
-      doAssert 1 / round(0.0) == Inf
-      doAssert 1 / round(-0.0) == -Inf
-      doAssert round(Inf) == Inf
-      doAssert round(-Inf) == -Inf
-      doAssert round(NaN).isNaN
-      doAssert round(-NaN).isNaN
-      doAssert round(-0.5) == -1.0
-      doAssert round(0.5) == 1.0
-      doAssert round(-1.5) == -2.0
-      doAssert round(1.5) == 2.0
-      doAssert round(-2.5) == -3.0
-      doAssert round(2.5) == 3.0
-      doAssert round(2.5'f32) == 3.0'f32
-      doAssert round(2.5'f64) == 3.0'f64
+      block: # Round to 0 decimal places
+        doAssert round(54.652) == 55.0
+        doAssert round(54.352) == 54.0
+        doAssert round(-54.652) == -55.0
+        doAssert round(-54.352) == -54.0
+        doAssert round(0.0) == 0.0
+        doAssert 1 / round(0.0) == Inf
+        doAssert 1 / round(-0.0) == -Inf
+        doAssert round(Inf) == Inf
+        doAssert round(-Inf) == -Inf
+        doAssert round(NaN).isNaN
+        doAssert round(-NaN).isNaN
+        doAssert round(-0.5) == -1.0
+        doAssert round(0.5) == 1.0
+        doAssert round(-1.5) == -2.0
+        doAssert round(1.5) == 2.0
+        doAssert round(-2.5) == -3.0
+        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) =
+          doAssert round(x, 2).almostEqual 54.35
+          doAssert round(x, 2).almostEqual 54.35
+          doAssert round(x, -1).almostEqual 50.0
+          doAssert round(x, -2).almostEqual 100.0
+          doAssert round(x, -3).almostEqual 0.0
+        fn(54.346)
+        fn(54.346'f32)
 
     when nimvm:
       discard