summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2019-01-15 05:50:28 -0800
committerAndreas Rumpf <rumpf_a@web.de>2019-01-15 14:50:28 +0100
commit4355f23ee5fd53acfdaa8ecb5dbb50f9b43f98b2 (patch)
tree9818d08fec2a5dcd2051c557d0632370122009ba /tests
parent9a92bc15b38b60a889815a1be9f87cca5038f747 (diff)
downloadNim-4355f23ee5fd53acfdaa8ecb5dbb50f9b43f98b2.tar.gz
fix #10305 nim cpp is now nan-correct at CT (#10310)
* fix #10305 nim cpp is now nan-correct at CT
* add example where simply `nim cpp -d:release` would exhibit nan bug
Diffstat (limited to 'tests')
-rw-r--r--tests/float/tfloatnan.nim28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/float/tfloatnan.nim b/tests/float/tfloatnan.nim
index 29937a862..8f384c3d9 100644
--- a/tests/float/tfloatnan.nim
+++ b/tests/float/tfloatnan.nim
@@ -14,3 +14,31 @@ echo "Nim: ", f32, " (float)"
 
 let f64: float64 = NaN
 echo "Nim: ", f64, " (double)"
+
+block: # issue #10305
+  # with `-O3 -ffast-math`, generated C/C++ code is not nan compliant
+  # user can pass `--passC:-ffast-math` if he doesn't care.
+  proc fun() =
+    # this was previously failing at compile time with a nim compiler
+    # that was compiled with `nim cpp -d:release`
+    let a1 = 0.0
+    let a = 0.0/a1
+    let b1 = a == 0.0
+    let b2 = a == a
+    doAssert not b1
+    doAssert not b2
+
+  proc fun2(i: int) =
+    # this was previously failing simply with `nim cpp -d:release`; the
+    # difference with above example is that optimization (const folding) can't
+    # take place in this example to hide the non-compliant nan bug.
+    let a = 0.0/(i.float)
+    let b1 = a == 0.0
+    let b2 = a == a
+    doAssert not b1
+    doAssert not b2
+
+  static: fun()
+  fun()
+  fun2(0)
+