From 90de0447aaf7a4f50c9cc8db27594c4ad0edc54c Mon Sep 17 00:00:00 2001 From: Jeff Armstrong Date: Sat, 13 Oct 2012 13:30:42 -0400 Subject: Added example exponential code. --- ccc2012/exp.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 ccc2012/exp.py (limited to 'ccc2012/exp.py') diff --git a/ccc2012/exp.py b/ccc2012/exp.py new file mode 100644 index 0000000..39b5035 --- /dev/null +++ b/ccc2012/exp.py @@ -0,0 +1,23 @@ +from math import factorial + +def exp_right(x): + ret = 1 + negative = (x < 0) + + xa = abs(x) + + for i in range(1, 128): + ret = ret + xa**float(i) / float(factorial(i)) + + if negative: + ret = 1.0/ret + + return ret + +def exp_wrong(x): + ret = 1 + + for i in range(1, 128): + ret = ret + x**float(i) / float(factorial(i)) + + return ret -- cgit v1.2.3