-
-
Save 1995eaton/f35b50ab6dcff9630a3a to your computer and use it in GitHub Desktop.
E calculator
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
from gmpy2 import mpz, get_context | |
# 19 loops maxes out 64-bit floating point number | |
# ~~ 2.718281828459045 == math.e ~~ | |
def E(prec=19): | |
num, den = 0, 1 | |
for i in range(1, prec): | |
# add fraction keeping GCD | |
# allows for greater precision | |
num = (num + 1) * i | |
den *= i | |
return num / den | |
def gmp_E(prec=19): | |
num, den = mpz(0), mpz(1) | |
for i in range(1, prec): | |
num = (num + 1) * i | |
den *= i | |
return num / den |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment