From d13c3dc88e04e9261cc1f64ea90792d129323e0d Mon Sep 17 00:00:00 2001 From: Emery Berger Date: Wed, 12 Jan 2022 12:44:56 -0500 Subject: [PATCH] Removed unnecessary computations, now at 16000x faster, H/T mikeblas. --- test/test-martinheinz.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/test-martinheinz.py b/test/test-martinheinz.py index 32c7d19bd..eca467999 100644 --- a/test/test-martinheinz.py +++ b/test/test-martinheinz.py @@ -19,6 +19,7 @@ def exp(x): print("Original:") + d1_orig = exp(Decimal(150)) d2_orig = exp(Decimal(400)) d3_orig = exp(Decimal(3000)) @@ -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 @@ -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) +