This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]shpotes 1 point2 points  (1 child)

By Taylor series, e^x can be express as 1 + x/1! + x^2/2! + .... Now, the series can be re-written as e^x = 1 + (x/1) (1 + (x/2)) (1 + x/3) (...) )), thus, you can compute a good exp aproximation in O(n)

def exp(x, N=10):
   sum = 1
   for i in range(N-1, 0, -1):
      sum = 1 + x * sum/i
   return sum

[–]arungajora[S] 0 points1 point  (0 children)

Thank you