2015-10-08 08:02:00 -04:00
|
|
|
# tests int constant folding in compiler
|
|
|
|
|
|
|
|
# positive
|
|
|
|
print(+1)
|
|
|
|
print(+100)
|
|
|
|
|
|
|
|
# negation
|
|
|
|
print(-1)
|
|
|
|
print(-(-1))
|
|
|
|
print(-0x3fffffff) # 32-bit edge case
|
|
|
|
print(-0x3fffffffffffffff) # 64-bit edge case
|
|
|
|
print(-(-0x3fffffff - 1)) # 32-bit edge case
|
|
|
|
print(-(-0x3fffffffffffffff - 1)) # 64-bit edge case
|
|
|
|
|
|
|
|
# 1's complement
|
|
|
|
print(~0)
|
|
|
|
print(~1)
|
|
|
|
print(~-1)
|
|
|
|
print(~0x3fffffff) # 32-bit edge case
|
|
|
|
print(~0x3fffffffffffffff) # 64-bit edge case
|
|
|
|
print(~(-0x3fffffff - 1)) # 32-bit edge case
|
|
|
|
print(~(-0x3fffffffffffffff - 1)) # 64-bit edge case
|
|
|
|
|
|
|
|
# addition
|
|
|
|
print(1 + 2)
|
|
|
|
|
|
|
|
# subtraction
|
|
|
|
print(1 - 2)
|
|
|
|
print(2 - 1)
|
|
|
|
|
|
|
|
# multiplication
|
|
|
|
print(1 * 2)
|
|
|
|
print(123 * 456)
|
|
|
|
|
|
|
|
# floor div and modulo
|
|
|
|
print(123 // 7, 123 % 7)
|
|
|
|
print(-123 // 7, -123 % 7)
|
|
|
|
print(123 // -7, 123 % -7)
|
|
|
|
print(-123 // -7, -123 % -7)
|
|
|
|
|
2016-10-16 20:43:47 -04:00
|
|
|
# zero big-num on rhs
|
|
|
|
print(1 + ((1 << 65) - (1 << 65)))
|
|
|
|
|
|
|
|
# negative big-num on rhs
|
|
|
|
print(1 + (-(1 << 65)))
|