Mike Speciner on 2011-07-20 03:45:02
This does not work for negative arg. It also suffers from poor precision for |arg| << 1. To fix the first problem, try return Math.log(Math.abs(arg) + Math.sqrt(arg * arg + 1))*(arg<0?-1:1); The second problem is much harder to fix; best might be a rational function approximation for small args. If there were a builtin function log1p(x) := log(1+x), and similarly expm1(x) := exp(x)-1, things would be much simpler for all the hyperbolic functions and their inverses.