Is there an implementation of Trefethen's contour integrals for evaluating [1 - exp(-x)] / x as x->0?

I’m not sure why you would need TaylorSeries at all here; expm1 is already accurate for small arguments.

f(x) = iszero(x) ? float(one(x)) : -expm1(-x)/x

x = exp10.(range(-300,log10(700),length=10^7)); x = [-x; x]
err(x) = let exact=f(big(x)); Float64(abs(f(x)-exact) / abs(exact)); end
maximum(err, x) / eps(Float64)

gives 1.02 (≈1ulp).

That will give a much larger error — your h(x) = (1 - exp(-x)) / x has an error of ≈24ulps when x=0.01.

7 Likes