Skip to content

Instantly share code, notes, and snippets.

@md2perpe
Created February 28, 2022 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save md2perpe/f563180998e575a8fa4001695677db6e to your computer and use it in GitHub Desktop.
Save md2perpe/f563180998e575a8fa4001695677db6e to your computer and use it in GitHub Desktop.
Sum big and small numbers
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