tcast1.nim 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. discard """
  2. output: '''
  3. @[1.0, 2.0, 3.0]
  4. @[1.0, 2.0, 3.0]
  5. '''
  6. """
  7. # bug #6406
  8. import sequtils
  9. proc remap1(s: seq[int], T: typedesc): seq[T] =
  10. s.map do (x: int) -> T:
  11. x.T
  12. proc remap2[T](s: seq[int], typ: typedesc[T]): seq[T] =
  13. s.map do (x: int) -> T:
  14. x.T
  15. echo remap1(@[1,2,3], float)
  16. echo remap2(@[1,2,3], float)
  17. #--------------------------------------------------------------------
  18. # conversion to bool, issue #13744
  19. proc test_conv_to_bool =
  20. var
  21. i0 = 0
  22. i1 = 1
  23. ih = high(uint)
  24. il = low(int)
  25. f0 = 0.0
  26. f1 = 1.0
  27. fh = Inf
  28. fl = -Inf
  29. f_nan = NaN
  30. doAssert(bool(i0) == false)
  31. doAssert(bool(i1) == true)
  32. doAssert(bool(-i1) == true)
  33. doAssert(bool(il) == true)
  34. doAssert(bool(ih) == true)
  35. doAssert(bool(f0) == false)
  36. doAssert(bool(-f0) == false)
  37. doAssert(bool(f1) == true)
  38. doAssert(bool(-f1) == true)
  39. doAssert(bool(fh) == true)
  40. doAssert(bool(fl) == true)
  41. doAssert(bool(fnan) == true) # NaN to bool gives true according to standard
  42. static:
  43. doAssert(bool(0) == false)
  44. doAssert(bool(-1) == true)
  45. doAssert(bool(2) == true)
  46. doAssert(bool(NaN) == true)
  47. doAssert(bool(0.0) == false)
  48. doAssert(bool(-0.0) == false)
  49. test_conv_to_bool()
  50. test_conv_to_bool()