Created
January 30, 2023 15:59
-
-
Save chipbuster/90abef9f662d3a6e0d63fb1655422421 to your computer and use it in GitHub Desktop.
A Demonstration of Floating Point Precision in Python
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
# In principle, this should be simple enough to reconstruct on the fly | |
# In practice, every time I come back to it, it takes me 10-20 minutes | |
# to recall the correct sequence of operations to get the dang thing | |
# to diverge, so I'm going to gist this. | |
x = 1/3 | |
print(f"Initially, x is {x}") | |
for _ in range(540): | |
x *= 4.0 | |
x -= 1.0 | |
print(f"After executing x = 4x - 1, x is {x}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment