Stand-alone Python code for exp(x) - 1

See the corresponding page for C++ for an explantion of the problem and the solution.

The Python code is trivial:


import math

def expm1(x):
    if abs(x) < 1e-5:
        return x + 0.5*x*x
    else:
        return math.exp(x) - 1.0

Stand-alone numerical code

 

Home