int_constfolding.py 520 B

12345678910111213141516171819202122232425262728293031323334353637
  1. # tests int constant folding in compiler
  2. # positive
  3. print(+1)
  4. print(+100)
  5. # negation
  6. print(-1)
  7. print(-(-1))
  8. # 1's complement
  9. print(~0)
  10. print(~1)
  11. print(~-1)
  12. # addition
  13. print(1 + 2)
  14. # subtraction
  15. print(1 - 2)
  16. print(2 - 1)
  17. # multiplication
  18. print(1 * 2)
  19. print(123 * 456)
  20. # floor div and modulo
  21. print(123 // 7, 123 % 7)
  22. print(-123 // 7, -123 % 7)
  23. print(123 // -7, 123 % -7)
  24. print(-123 // -7, -123 % -7)
  25. # won't fold so an exception can be raised at runtime
  26. try:
  27. 1 << -1
  28. except ValueError:
  29. print('ValueError')