tcasts.nim 622 B

123456789101112131415161718192021222324252627
  1. import std/[strutils]
  2. import std/[assertions, objectdollar]
  3. # bug #19101
  4. type
  5. Small = object
  6. a: int
  7. Big = object
  8. a, b, c, d: int
  9. proc main =
  10. var
  11. n = 1'i8
  12. f = 2.0
  13. s = Small(a: 1)
  14. b = Big(a: 12345, b: 23456, c: 34567, d: 45678)
  15. doAssert $cast[int](f).toBin(64) == "0100000000000000000000000000000000000000000000000000000000000000"
  16. f = cast[float](n)
  17. doAssert $cast[int](f).toBin(64) == "0000000000000000000000000000000000000000000000000000000000000001"
  18. doAssert $b == "(a: 12345, b: 23456, c: 34567, d: 45678)"
  19. b = cast[Big](s)
  20. doAssert $b == "(a: 1, b: 0, c: 0, d: 0)"
  21. main()