Blame sysdeps/ieee754/dbl-64/e_cosh.c

Packit 6c4009
/* Optimized by Ulrich Drepper <drepper@gmail.com>, 2011 */
Packit 6c4009
/*
Packit 6c4009
 * ====================================================
Packit 6c4009
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
Packit 6c4009
 *
Packit 6c4009
 * Developed at SunPro, a Sun Microsystems, Inc. business.
Packit 6c4009
 * Permission to use, copy, modify, and distribute this
Packit 6c4009
 * software is freely granted, provided that this notice
Packit 6c4009
 * is preserved.
Packit 6c4009
 * ====================================================
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
/* __ieee754_cosh(x)
Packit 6c4009
 * Method :
Packit 6c4009
 * mathematically cosh(x) if defined to be (exp(x)+exp(-x))/2
Packit 6c4009
 *	1. Replace x by |x| (cosh(x) = cosh(-x)).
Packit 6c4009
 *	2.
Packit 6c4009
 *							[ exp(x) - 1 ]^2
Packit 6c4009
 *	    0        <= x <= ln2/2  :  cosh(x) := 1 + -------------------
Packit 6c4009
 *							   2*exp(x)
Packit 6c4009
 *
Packit 6c4009
 *						  exp(x) +  1/exp(x)
Packit 6c4009
 *	    ln2/2    <= x <= 22     :  cosh(x) := -------------------
Packit 6c4009
 *							  2
Packit 6c4009
 *	    22       <= x <= lnovft :  cosh(x) := exp(x)/2
Packit 6c4009
 *	    lnovft   <= x <= ln2ovft:  cosh(x) := exp(x/2)/2 * exp(x/2)
Packit 6c4009
 *	    ln2ovft  <  x	    :  cosh(x) := huge*huge (overflow)
Packit 6c4009
 *
Packit 6c4009
 * Special cases:
Packit 6c4009
 *	cosh(x) is |x| if x is +INF, -INF, or NaN.
Packit 6c4009
 *	only cosh(0)=1 is exact for finite x.
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
#include <math.h>
Packit 6c4009
#include <math-narrow-eval.h>
Packit 6c4009
#include <math_private.h>
Packit 6c4009
Packit 6c4009
static const double one = 1.0, half = 0.5, huge = 1.0e300;
Packit 6c4009
Packit 6c4009
double
Packit 6c4009
__ieee754_cosh (double x)
Packit 6c4009
{
Packit 6c4009
  double t, w;
Packit 6c4009
  int32_t ix;
Packit 6c4009
  uint32_t lx;
Packit 6c4009
Packit 6c4009
  /* High word of |x|. */
Packit 6c4009
  GET_HIGH_WORD (ix, x);
Packit 6c4009
  ix &= 0x7fffffff;
Packit 6c4009
Packit 6c4009
  /* |x| in [0,22] */
Packit 6c4009
  if (ix < 0x40360000)
Packit 6c4009
    {
Packit 6c4009
      /* |x| in [0,0.5*ln2], return 1+expm1(|x|)^2/(2*exp(|x|)) */
Packit 6c4009
      if (ix < 0x3fd62e43)
Packit 6c4009
	{
Packit 6c4009
	  if (ix < 0x3c800000)
Packit 6c4009
	    return one;                                   /* cosh(tiny) = 1 */
Packit 6c4009
	  t = __expm1 (fabs (x));
Packit 6c4009
	  w = one + t;
Packit 6c4009
	  return one + (t * t) / (w + w);
Packit 6c4009
	}
Packit 6c4009
Packit 6c4009
      /* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|)/2; */
Packit 6c4009
      t = __ieee754_exp (fabs (x));
Packit 6c4009
      return half * t + half / t;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  /* |x| in [22, log(maxdouble)] return half*exp(|x|) */
Packit 6c4009
  if (ix < 0x40862e42)
Packit 6c4009
    return half * __ieee754_exp (fabs (x));
Packit 6c4009
Packit 6c4009
  /* |x| in [log(maxdouble), overflowthresold] */
Packit 6c4009
  GET_LOW_WORD (lx, x);
Packit 6c4009
  if (ix < 0x408633ce || ((ix == 0x408633ce) && (lx <= (uint32_t) 0x8fb9f87d)))
Packit 6c4009
    {
Packit 6c4009
      w = __ieee754_exp (half * fabs (x));
Packit 6c4009
      t = half * w;
Packit 6c4009
      return t * w;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  /* x is INF or NaN */
Packit 6c4009
  if (ix >= 0x7ff00000)
Packit 6c4009
    return x * x;
Packit 6c4009
Packit 6c4009
  /* |x| > overflowthresold, cosh(x) overflow */
Packit 6c4009
  return math_narrow_eval (huge * huge);
Packit 6c4009
}
Packit 6c4009
strong_alias (__ieee754_cosh, __cosh_finite)