Kai Tietz | 815a664 | 2009-02-19 10:54:09 +0000 | [diff] [blame] | 1 | /** |
| 2 | * This file has no copyright assigned and is placed in the Public Domain. |
| 3 | * This file is part of the w64 mingw-runtime package. |
| 4 | * No warranty is given; refer to the file DISCLAIMER within this package. |
| 5 | */ |
| 6 | #include <math.h> |
| 7 | #include <errno.h> |
| 8 | #include "fastmath.h" |
| 9 | |
| 10 | /* acosh(x) = log (x + sqrt(x * x - 1)) */ |
| 11 | double acosh (double x) |
| 12 | { |
| 13 | if (isnan (x)) |
| 14 | return x; |
| 15 | |
| 16 | if (x < 1.0) |
| 17 | { |
| 18 | errno = EDOM; |
| 19 | return nan(""); |
| 20 | } |
| 21 | |
| 22 | if (x > 0x1p32) |
| 23 | /* Avoid overflow (and unnecessary calculation when |
| 24 | sqrt (x * x - 1) == x). GCC optimizes by replacing |
| 25 | the long double M_LN2 const with a fldln2 insn. */ |
| 26 | return __fast_log (x) + 6.9314718055994530941723E-1L; |
| 27 | |
| 28 | /* Since x >= 1, the arg to log will always be greater than |
| 29 | the fyl2xp1 limit (approx 0.29) so just use logl. */ |
| 30 | return __fast_log (x + __fast_sqrt((x + 1.0) * (x - 1.0))); |
| 31 | } |