Advertisement
Guest User

calculating e

a guest
Jun 19th, 2024
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | Software | 0 0
  1. #calculation of e, twice as fast as naive (1 + 1/n)n method.
  2. from math import *
  3. from decimal import *
  4. d = Decimal
  5.  
  6. def sstr(var, cut=16)
  7. return d()
  8.  
  9.  
  10. i = d(2)
  11. while i < 600_000:
  12. standard = (e/((1+d(1/i))**i))
  13. improved = (e/(1/((1/((((1+d(1/(i-1)))**i) - ((1+d(1/(i-0)))**i))))/d(i-(1/i)))))
  14. print(f"i: {i}, standard: {sstr(standard)}, result: {sstr(improved)}, percent improved: {sstr((improved/standard)*100)}%")
  15. i = i + 1
  16.  
  17.  
  18.  
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement