Created
May 22, 2014 19:01
-
-
Save PhDP/a18f737b3f1e21651c9a to your computer and use it in GitHub Desktop.
Why directional rounding is odd. Try with python2 (rounds ties away from zero, which is bad) and python3 (rounds ties to nearest even number).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import randint as rand | |
max = 10000000 | |
sum = 0 | |
sumR = 0 | |
for i in range(0, max): | |
x = rand(1, 1000) / 2.0 | |
sum += x | |
sumR += round(x) | |
print((sumR - sum) / max) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment