tarithmetics.nim 1.0 KB

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