os/ossrv/genericopenlibs/cstdlib/LMATH/E_COSH.C
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/LMATH/E_COSH.C	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,86 @@
     1.4 +/* E_COSH.C
     1.5 + * 
     1.6 + * Portions Copyright (c) 1993-1999 Nokia Corporation and/or its subsidiary(-ies).
     1.7 + * All rights reserved.
     1.8 + */
     1.9 +
    1.10 +
    1.11 +/* @(#)e_cosh.c 5.1 93/09/24 */
    1.12 +/*
    1.13 + * ====================================================
    1.14 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
    1.15 + *
    1.16 + * Developed at SunPro, a Sun Microsystems, Inc. business.
    1.17 + * Permission to use, copy, modify, and distribute this
    1.18 + * software is freely granted, provided that this notice 
    1.19 + * is preserved.
    1.20 + * ====================================================
    1.21 + */
    1.22 +
    1.23 +/* __ieee754_cosh(x)
    1.24 + * Method : 
    1.25 + * mathematically cosh(x) if defined to be (exp(x)+exp(-x))/2
    1.26 + *	1. Replace x by |x| (cosh(x) = cosh(-x)). 
    1.27 + *	2. 
    1.28 + *		                                        [ exp(x) - 1 ]^2 
    1.29 + *	    0        <= x <= ln2/2  :  cosh(x) := 1 + -------------------
    1.30 + *			       			           2*exp(x)
    1.31 + *
    1.32 + *		                                  exp(x) +  1/exp(x)
    1.33 + *	    ln2/2    <= x <= 22     :  cosh(x) := -------------------
    1.34 + *			       			          2
    1.35 + *	    22       <= x <= lnovft :  cosh(x) := exp(x)/2 
    1.36 + *	    lnovft   <= x <= ln2ovft:  cosh(x) := exp(x/2)/2 * exp(x/2)
    1.37 + *	    ln2ovft  <  x	    :  cosh(x) := huge*huge (overflow)
    1.38 + *
    1.39 + * Special cases:
    1.40 + *	cosh(x) is |x| if x is +INF, -INF, or NaN.
    1.41 + *	only cosh(0)=1 is exact for finite x.
    1.42 + */
    1.43 +
    1.44 +#include "FDLIBM.H"
    1.45 +
    1.46 +static const double one = 1.0, half=0.5, huge = 1.0e300;
    1.47 +
    1.48 +EXPORT_C double __ieee754_cosh(double x) __SOFTFP
    1.49 +{	
    1.50 +	double t,w;
    1.51 +	__int32_t ix;
    1.52 +	__uint32_t lx;
    1.53 +
    1.54 +    /* High word of |x|. */
    1.55 +	GET_HIGH_WORD(ix,x);
    1.56 +	ix &= 0x7fffffff;
    1.57 +
    1.58 +    /* x is INF or NaN */
    1.59 +	if(ix>=0x7ff00000) return x*x;	
    1.60 +
    1.61 +    /* |x| in [0,0.5*ln2], return 1+expm1(|x|)^2/(2*exp(|x|)) */
    1.62 +	if(ix<0x3fd62e43) {
    1.63 +	    t = expm1(fabs(x));
    1.64 +	    w = one+t;
    1.65 +	    if (ix<0x3c800000) return w;	/* cosh(tiny) = 1 */
    1.66 +	    return one+(t*t)/(w+w);
    1.67 +	}
    1.68 +
    1.69 +    /* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|)/2; */
    1.70 +	if (ix < 0x40360000) {
    1.71 +		t = __ieee754_exp(fabs(x));
    1.72 +		return half*t+half/t;
    1.73 +	}
    1.74 +
    1.75 +    /* |x| in [22, log(maxdouble)] return half*exp(|x|) */
    1.76 +	if (ix < 0x40862E42)  return half*__ieee754_exp(fabs(x));
    1.77 +
    1.78 +    /* |x| in [log(maxdouble), overflowthresold] */
    1.79 +	GET_LOW_WORD(lx,x);
    1.80 +	if (ix<0x408633CE || 
    1.81 +	      ((ix==0x408633ce)&&(lx<=(__uint32_t)0x8fb9f87d))) {
    1.82 +	    w = __ieee754_exp(half*fabs(x));
    1.83 +	    t = half*w;
    1.84 +	    return t*w;
    1.85 +	}
    1.86 +
    1.87 +    /* |x| > overflowthresold, cosh(x) overflow */
    1.88 +	return huge*huge;
    1.89 +}