summaryrefslogtreecommitdiffstatshomepage
path: root/tests/basics/int_divmod.py
blob: 71a990823e385ca81c89d1a77029e804d7f59423 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# test integer floor division and modulo

# test all combination of +/-/0 cases
for i in range(-2, 3):
    for j in range(-4, 5):
        if j != 0:
            print(i, j, i // j, i % j, divmod(i, j))

# this tests compiler constant folding
print(123 // 7, 123 % 7)
print(-123 // 7, -123 % 7)
print(123 // -7, 123 % -7)
print(-123 // -7, -123 % -7)

# this tests bignum modulo
a = 987654321987987987987987987987
b = 19
print(a % b)
print(a % -b)
print(-a % b)
print(-a % -b)