1# test floating point floor divide and modulus 2# it has some tricky corner cases 3 4 5def test(x, y): 6 div, mod = divmod(x, y) 7 print("%.8f %.8f %.8f %.8f" % (x // y, x % y, div, mod)) 8 print(div == x // y, mod == x % y, abs(div * y + mod - x) < 1e-15) 9 10 11test(1.23456, 0.7) 12test(-1.23456, 0.7) 13test(1.23456, -0.7) 14test(-1.23456, -0.7) 15 16a = 1.23456 17b = 0.7 18test(a, b) 19test(a, -b) 20test(-a, b) 21test(-a, -b) 22 23for i in range(25): 24 x = (i - 12.5) / 6 25 for j in range(25): 26 y = (j - 12.5) / 6 27 test(x, y) 28