master
 1/**
 2 * This file has no copyright assigned and is placed in the Public Domain.
 3 * This file is part of the mingw-w64 runtime package.
 4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
 5 */
 6#include <math.h>
 7#include <errno.h>
 8#include <float.h>
 9#include "fastmath.h"
10
11 /* asinh(x) = copysign(log(fabs(x) + sqrt(x * x + 1.0)), x) */
12long double asinhl(long double x)
13{
14  long double z;
15  if (!isfinite (x))
16    return x;
17
18  z = fabsl (x);
19
20  /* Avoid setting FPU underflow exception flag in x * x. */
21#if 0
22  if ( z < 0x1p-32)
23    return x;
24#endif
25
26  /* See commentary in asinh */
27  const long double asinhCutover = powl(2,LDBL_MAX_EXP/2);
28
29  if (z < asinhCutover)
30    z = __fast_log1pl (z + z * (z / (__fast_sqrtl (z * z + 1.0) + 1.0)));
31  else
32    z = __fast_logl(2) + __fast_logl(z);
33  return copysignl(z, x); //ensure 0.0 -> 0.0 and -0.0 -> -0.0.
34}