[1] http://www.embedded.com/design/other/4216719/Performing-effi...
[2] https://stackoverflow.com/questions/6118028/fast-hyperbolic-...
[1] http://www.embedded.com/design/other/4216719/Performing-effi...
[2] https://stackoverflow.com/questions/6118028/fast-hyperbolic-...
Looks like f(x)=x+x^3/5 gets you two decimal digits everywhere [1], and you could improve that with more terms in the polynomial.
Edit: you can derive f(x) by doing a series expansion of tanh(x)/√(1-tanh(x)²) about x=0, and Mathematica tells me the first few terms are
f(x) = x + x^3/6 + x^5/120 + x^7/5040 + O(x^9)
And yes, the Taylor series is pretty good but you can usually squeeze a bit more accuracy-over-range by, eg, using an optimizer for the coefficients. Also, note that in your notebook you have x^3/5 but x^3/6 is probably what you wanted.
> Avoid special cases, because a special case means slow code
So yeah, handling of special cases will bite you on the performance side. Sometimes it's inevitable, but if you have a lot of control (or you're very specific) of what values get passed as parameters, then you can get away with not handling special cases (or just handling the ones you care about).
[1] http://www.java-gaming.org/topics/extremely-fast-atan2/36467...