tarithmetics.nim 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. discard """
  2. matrix: "--mm:refc; --mm:orc"
  3. targets: "c cpp js"
  4. """
  5. import std/assertions
  6. # TODO: in future work move existing arithmetic tests (tests/arithm/*) into this file
  7. # FYI https://github.com/nim-lang/Nim/pull/17767
  8. template main =
  9. # put all arithmetic tests
  10. block tshr:
  11. block: # Signed types
  12. let
  13. a1 = -3
  14. a2 = -2
  15. b1 = -4'i8
  16. b2 = 1'i8
  17. c1 = -5'i16
  18. c2 = 1'i16
  19. d1 = -7i32
  20. d2 = 1'i32
  21. e1 = -9'i64
  22. e2 = 1'i64
  23. doAssert a1 shr a2 == -1
  24. doAssert b1 shr b2 == -2
  25. doAssert c1 shr c2 == -3
  26. doAssert d1 shr d2 == -4
  27. doAssert e1 shr e2 == -5
  28. block: # Unsigned types
  29. let
  30. a1 = 3'u
  31. a2 = 2'u
  32. b1 = 2'u8
  33. b2 = 1'u8
  34. c1 = 5'u16
  35. c2 = 1'u16
  36. d1 = 6'u32
  37. d2 = 1'u32
  38. e1 = 8'u64
  39. e2 = 1'u64
  40. doAssert a1 shr a2 == 0
  41. doAssert b1 shr b2 == 1
  42. doAssert c1 shr c2 == 2
  43. doAssert d1 shr d2 == 3
  44. doAssert e1 shr e2 == 4
  45. static: main()
  46. main()