Kai Tietz | 518dd33 | 2007-08-10 09:54:15 +0000 | [diff] [blame^] | 1 | #include <math.h>
|
| 2 | #include <errno.h>
|
| 3 | #include "fastmath.h"
|
| 4 |
|
| 5 | /* acosh(x) = log (x + sqrt(x * x - 1)) */
|
| 6 | double acosh (double x)
|
| 7 | {
|
| 8 | if (isnan (x))
|
| 9 | return x;
|
| 10 |
|
| 11 | if (x < 1.0)
|
| 12 | {
|
| 13 | errno = EDOM;
|
| 14 | return nan("");
|
| 15 | }
|
| 16 |
|
| 17 | if (x > 0x1p32)
|
| 18 | /* Avoid overflow (and unnecessary calculation when
|
| 19 | sqrt (x * x - 1) == x). GCC optimizes by replacing
|
| 20 | the long double M_LN2 const with a fldln2 insn. */
|
| 21 | return __fast_log (x) + 6.9314718055994530941723E-1L;
|
| 22 |
|
| 23 | /* Since x >= 1, the arg to log will always be greater than
|
| 24 | the fyl2xp1 limit (approx 0.29) so just use logl. */
|
| 25 | return __fast_log (x + __fast_sqrt((x + 1.0) * (x - 1.0)));
|
| 26 | }
|