In my quest for a better
exp function, I discovered that having a more accurate
evalpoly function is necessary if you want low error. Our builtin version is very fast (1 flop per degree), but has an unfortunately high max error (near 1 ULP). Below is a version that uses extended precision to get below .5ULP (at least when the higher order terms tend to zero). The biggest downside is it is 6x slower, but this is still faster than evaluation with higher precision arithmetic from my testing.
If this should go in a package
DoubleFloats? I’d be happy to make a PR.
@inline function exthorner(x, p::Tuple) hi, lo = p[end], zero(x) for i in length(p)-1:-1:1 pi = p[i] prod = hi*x err = fma(hi, x, -prod) hi = pi+prod lo = fma(lo, x, prod - (hi - pi) + err) end return hi, lo end