sl@0: /* E_COSH.C
sl@0:  * 
sl@0:  * Portions Copyright (c) 1993-1999 Nokia Corporation and/or its subsidiary(-ies).
sl@0:  * All rights reserved.
sl@0:  */
sl@0: 
sl@0: 
sl@0: /* @(#)e_cosh.c 5.1 93/09/24 */
sl@0: /*
sl@0:  * ====================================================
sl@0:  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
sl@0:  *
sl@0:  * Developed at SunPro, a Sun Microsystems, Inc. business.
sl@0:  * Permission to use, copy, modify, and distribute this
sl@0:  * software is freely granted, provided that this notice 
sl@0:  * is preserved.
sl@0:  * ====================================================
sl@0:  */
sl@0: 
sl@0: /* __ieee754_cosh(x)
sl@0:  * Method : 
sl@0:  * mathematically cosh(x) if defined to be (exp(x)+exp(-x))/2
sl@0:  *	1. Replace x by |x| (cosh(x) = cosh(-x)). 
sl@0:  *	2. 
sl@0:  *		                                        [ exp(x) - 1 ]^2 
sl@0:  *	    0        <= x <= ln2/2  :  cosh(x) := 1 + -------------------
sl@0:  *			       			           2*exp(x)
sl@0:  *
sl@0:  *		                                  exp(x) +  1/exp(x)
sl@0:  *	    ln2/2    <= x <= 22     :  cosh(x) := -------------------
sl@0:  *			       			          2
sl@0:  *	    22       <= x <= lnovft :  cosh(x) := exp(x)/2 
sl@0:  *	    lnovft   <= x <= ln2ovft:  cosh(x) := exp(x/2)/2 * exp(x/2)
sl@0:  *	    ln2ovft  <  x	    :  cosh(x) := huge*huge (overflow)
sl@0:  *
sl@0:  * Special cases:
sl@0:  *	cosh(x) is |x| if x is +INF, -INF, or NaN.
sl@0:  *	only cosh(0)=1 is exact for finite x.
sl@0:  */
sl@0: 
sl@0: #include "FDLIBM.H"
sl@0: 
sl@0: static const double one = 1.0, half=0.5, huge = 1.0e300;
sl@0: 
sl@0: EXPORT_C double __ieee754_cosh(double x) __SOFTFP
sl@0: {	
sl@0: 	double t,w;
sl@0: 	__int32_t ix;
sl@0: 	__uint32_t lx;
sl@0: 
sl@0:     /* High word of |x|. */
sl@0: 	GET_HIGH_WORD(ix,x);
sl@0: 	ix &= 0x7fffffff;
sl@0: 
sl@0:     /* x is INF or NaN */
sl@0: 	if(ix>=0x7ff00000) return x*x;	
sl@0: 
sl@0:     /* |x| in [0,0.5*ln2], return 1+expm1(|x|)^2/(2*exp(|x|)) */
sl@0: 	if(ix<0x3fd62e43) {
sl@0: 	    t = expm1(fabs(x));
sl@0: 	    w = one+t;
sl@0: 	    if (ix<0x3c800000) return w;	/* cosh(tiny) = 1 */
sl@0: 	    return one+(t*t)/(w+w);
sl@0: 	}
sl@0: 
sl@0:     /* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|)/2; */
sl@0: 	if (ix < 0x40360000) {
sl@0: 		t = __ieee754_exp(fabs(x));
sl@0: 		return half*t+half/t;
sl@0: 	}
sl@0: 
sl@0:     /* |x| in [22, log(maxdouble)] return half*exp(|x|) */
sl@0: 	if (ix < 0x40862E42)  return half*__ieee754_exp(fabs(x));
sl@0: 
sl@0:     /* |x| in [log(maxdouble), overflowthresold] */
sl@0: 	GET_LOW_WORD(lx,x);
sl@0: 	if (ix<0x408633CE || 
sl@0: 	      ((ix==0x408633ce)&&(lx<=(__uint32_t)0x8fb9f87d))) {
sl@0: 	    w = __ieee754_exp(half*fabs(x));
sl@0: 	    t = half*w;
sl@0: 	    return t*w;
sl@0: 	}
sl@0: 
sl@0:     /* |x| > overflowthresold, cosh(x) overflow */
sl@0: 	return huge*huge;
sl@0: }