mruby/mruby — pull request #2537 by chasonr (2014-08-16 03:33:09+00:00)
Title: Improve replacement math functions for Visual C++.

This change provides improved versions of asinh, acosh, atanh and cbrt for versions of Visual C++ that lack these functions:

* For asinh and acosh, the term pow(x, 2.0) overflows for |x| greater than sqrt(DBL_MAX). For large positive x, sqrt(x*x+1) is indistinguishable from x, and so the basic formulas both reduce to log(2*x), coded as log(x) + log(2).
* For asinh, the term x - sqrt(x*x-1) approaches x - x and loses significance as x becomes more negative; but asinh is an odd function. Coding asinh explicitly as an odd function also simplifies the overflow check.
* cbrt also needs to be explicitly coded as an odd function, because pow(x, y) returns NaN for x < 0 and y not an integer.
* For atanh, the sums 1+x and 1-x lose precision for small x. Measurable error appears for |x| less than about 1E-2. A polynomial approximation of four terms gives an accurate result for such small x.