import time import matplotlib.pyplot as plt NOW_NS = int(time.time()) * 10 ** 9 THEN_NS = NOW_NS + 10000 fig, (plt1, plt2) = plt.subplots(2) fig.canvas.set_window_title("Comparing division errors over 10 us") # Nanoseconds xs = range(NOW_NS, THEN_NS + 1) y1 = [int(x / 10**9 * 10**9) - x for x in xs] y2 = [int(x / 1e9 * 1e9) - x for x in xs] y3 = [abs(a) - abs(b) for a, b in zip(y1, y2)] plt1.set_title('Errors in nanoseconds') plt1.plot(y1, drawstyle='steps-mid', color="red", label="Errors with '/ 10**9'") plt1.plot(y2, drawstyle='steps-mid', color="blue", label="Errors with '/ 1e9'") plt1.plot(y3, drawstyle='steps-mid', color="green", label="Comparing absolute errors") plt1.legend(loc="upper right") # Hundreds of nanoseconds xs = range(NOW_NS // 100, (THEN_NS // 100) + 1) y1 = [int(x / 10**7 * 10**7) - x for x in xs] y2 = [int(x / 1e7 * 1e7) - x for x in xs] y3 = [abs(a) - abs(b) for a, b in zip(y1, y2)] plt2.set_title('Errors in hundreds of nanoseconds') plt2.plot(y1, drawstyle='steps-mid', color="red", label="Errors with '/ 10**7'") plt2.plot(y2, drawstyle='steps-mid', color="blue", label="Errors with '/ 1e7'") plt2.plot(y3, drawstyle='steps-mid', color="green", label="Comparing absolute errors") plt2.legend() plt.show() # r = 1580301619906185900 # print("Ref :", r) # print("10**7 :", int(r // 100 / 10**7 * 10 ** 7) * 100) # print("1e7 :", int(r // 100 / 1e7 * 10 ** 7) * 100) # print("10**9 :", int(r / 10**9 * 10**9)) # print("1e9 :", int(r / 1e9 * 10**9))