1# test floating point floor divide and modulus
2# it has some tricky corner cases
3
4# pyboard has 32-bit floating point and gives different (but still
5# correct) answers for certain combinations of divmod arguments.
6
7
8def test(x, y):
9    div, mod = divmod(x, y)
10    print(div == x // y, mod == x % y, abs(div * y + mod - x) < 1e-6)
11
12
13test(1.23456, 0.7)
14test(-1.23456, 0.7)
15test(1.23456, -0.7)
16test(-1.23456, -0.7)
17
18a = 1.23456
19b = 0.7
20test(a, b)
21test(a, -b)
22test(-a, b)
23test(-a, -b)
24
25for i in range(25):
26    x = (i - 12.5) / 6
27    for j in range(25):
28        y = (j - 12.5) / 6
29        test(x, y)
30
31# test division by zero error
32try:
33    divmod(1.0, 0)
34except ZeroDivisionError:
35    print("ZeroDivisionError")
36