blob: 270b2a49640dbb2104f8c6288e1abb874380ff75 [file] [log] [blame]
Kai Tietz815a6642009-02-19 10:54:09 +00001/**
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)) */
11double 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}