tdollar_float.nim 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #[
  2. merge into tests/system/tdollars.nim once https://github.com/nim-lang/Nim/pull/14122
  3. is merged
  4. ]#
  5. import unittest
  6. block: # https://github.com/timotheecour/Nim/issues/133
  7. # simple test
  8. var a: float = 2
  9. check $a == "2.0"
  10. # systematic tests
  11. template fun(a2: static float) =
  12. const a: float = a2 # needed pending https://github.com/timotheecour/Nim/issues/132
  13. var b = a
  14. check $b == $a
  15. fun 2
  16. fun 2.0
  17. fun 2.1
  18. fun 1_000
  19. fun 1_000.1
  20. fun 1_000_000_000.1
  21. fun 1_000_000_000_000.1
  22. # negatives
  23. fun -2.0
  24. fun -2.1
  25. # 0
  26. fun 0
  27. fun -0
  28. fun 0.0
  29. block:
  30. var a = -0.0
  31. check $a in ["-0.0", "0.0"]
  32. # exponents
  33. block:
  34. var a = 5e20
  35. check $a in ["5e20", "500000000000000000000.0"]
  36. fun 3.4e1'f32
  37. fun 3.4e-1'f32
  38. fun -3.4e-1'f32
  39. fun 3.4e-1'f32
  40. fun 3e-1'f32
  41. block:
  42. var a = 3.4e38'f32
  43. check $a in ["3.4e+38", "3.4e+038"]
  44. # on windows, printf (used in VM) prints as 3.4e+038
  45. # but js prints as 3.4e+38
  46. # on osx, both print as 3.4e+38
  47. # see https://github.com/timotheecour/Nim/issues/138
  48. when false: # edge cases
  49. fun -0.0 # see https://github.com/timotheecour/Nim/issues/136
  50. fun 5e20
  51. fun 3.4e38'f32