tarithmetics.nim 1007 B

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