blob: cf617126102ca6e66f7d6476612a093adfbe3c49 [file] [log] [blame]
Kai Tietz518dd332007-08-10 09:54:15 +00001#include <math.h>
2#include <errno.h>
3#include "fastmath.h"
4
5/* acosh(x) = log (x + sqrt(x * x - 1)) */
6double 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}