Example #1
0
/* acosh(x) = log (x + sqrt(x * x - 1)) */
long double acoshl (long double x)
{
  if (isnan (x)) 
    return x;

  if (x < 1.0L)
    {
      errno = EDOM;
      return nanl("");
    }
  if (x > 0x1p32L)
    /* Avoid overflow (and unnecessary calculation when
       sqrt (x * x - 1) == x).
       The M_LN2 define doesn't have enough precison for
       long double so use this one. GCC optimizes by replacing
       the const with a fldln2 insn. */
    return __fast_logl (x) + 6.9314718055994530941723E-1L;

   /* Since  x >= 1, the arg to log will always be greater than
      the fyl2xp1 limit (approx 0.29) so just use logl. */ 
   return __fast_logl (x + __fast_sqrtl((x + 1.0L) * (x - 1.0L)));
}
Example #2
0
 /* asinh(x) = copysign(log(fabs(x) + sqrt(x * x + 1.0)), x) */
long double asinhl(long double x)
{
  long double z;
  if (!isfinite (x))
    return x;

  z = fabsl (x);

  /* Avoid setting FPU underflow exception flag in x * x. */
#if 0
  if ( z < 0x1p-32)
    return x;
#endif

  /* Use log1p to avoid cancellation with small x. Put
     x * x in denom, so overflow is harmless. 
     asinh(x) = log1p (x + sqrt (x * x + 1.0) - 1.0)
              = log1p (x + x * x / (sqrt (x * x + 1.0) + 1.0))  */

  z = __fast_log1pl (z + z * z / (__fast_sqrtl (z * z + 1.0L) + 1.0L));

  return ( x > 0.0 ? z : -z);
}