Created
February 28, 2022 11:23
-
-
Save md2perpe/f563180998e575a8fa4001695677db6e to your computer and use it in GitHub Desktop.
Sum big and small numbers
This file contains 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
BIG = 1_000_000.0 | |
SMALL = 1e-12 | |
COUNT = 1_000_000 | |
def big_first(): | |
yield BIG | |
for _ in range(COUNT): | |
yield SMALL | |
def big_last(): | |
for _ in range(COUNT): | |
yield SMALL | |
yield BIG | |
def main(): | |
print(f"Sum using big_first: {sum(big_first())}") | |
print(f"Sum using big_last: {sum(big_last())}") | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment