summaryrefslogtreecommitdiff
path: root/ccc2012/exp.py
blob: 39b50353cf9bc68e45584fdc1a18316b18cdf9f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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