tfloatnan.nim 1006 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. discard """
  2. output: '''
  3. Nim: nan
  4. Nim: nan (float)
  5. Nim: nan (double)
  6. '''
  7. """
  8. let f = NaN
  9. echo "Nim: ", f
  10. let f32: float32 = NaN
  11. echo "Nim: ", f32, " (float)"
  12. let f64: float64 = NaN
  13. echo "Nim: ", f64, " (double)"
  14. block: # issue #10305
  15. # with `-O3 -ffast-math`, generated C/C++ code is not nan compliant
  16. # user can pass `--passC:-ffast-math` if he doesn't care.
  17. proc fun() =
  18. # this was previously failing at compile time with a nim compiler
  19. # that was compiled with `nim cpp -d:release`
  20. let a1 = 0.0
  21. let a = 0.0/a1
  22. let b1 = a == 0.0
  23. let b2 = a == a
  24. doAssert not b1
  25. doAssert not b2
  26. proc fun2(i: int) =
  27. # this was previously failing simply with `nim cpp -d:release`; the
  28. # difference with above example is that optimization (const folding) can't
  29. # take place in this example to hide the non-compliant nan bug.
  30. let a = 0.0/(i.float)
  31. let b1 = a == 0.0
  32. let b2 = a == a
  33. doAssert not b1
  34. doAssert not b2
  35. static: fun()
  36. fun()
  37. fun2(0)