Skip to content

Commit

Permalink
Removed unnecessary computations, now at 16000x faster, H/T mikeblas.
Browse files Browse the repository at this point in the history
  • Loading branch information
emeryberger committed Jan 12, 2022
1 parent de49af1 commit d13c3dc
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions test/test-martinheinz.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def exp(x):

print("Original:")


d1_orig = exp(Decimal(150))
d2_orig = exp(Decimal(400))
d3_orig = exp(Decimal(3000))
Expand All @@ -34,8 +35,8 @@ def exp_opt(x):
while s != lasts:
lasts = s
i += 1
fact *= i
num *= x
# was: fact *= i
# was: num *= x
nf *= (x / i) ### update nf to be num / fact
s += nf ### was: s += num / fact
getcontext().prec -= 2
Expand All @@ -59,3 +60,5 @@ def exp_opt(x):
assert d2_orig == d2_opt
assert d3_orig == d3_opt

print("All equivalent? ", d1_orig == d1_opt and d2_orig == d2_opt and d3_orig == d3_opt)

0 comments on commit d13c3dc

Please sign in to comment.