|
Packit |
6c4009 |
/* @(#)e_cosh.c 5.1 93/09/24 */
|
|
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 <= 40 : cosh(x) := -------------------
|
|
Packit |
6c4009 |
* 2
|
|
Packit |
6c4009 |
* 40 <= 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_private.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static const long double one = 1.0L, half=0.5L, huge = 1.0e300L;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
long double
|
|
Packit |
6c4009 |
__ieee754_coshl (long double x)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
long double t,w;
|
|
Packit |
6c4009 |
int64_t ix;
|
|
Packit |
6c4009 |
double xhi;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* High word of |x|. */
|
|
Packit |
6c4009 |
xhi = ldbl_high (x);
|
|
Packit |
6c4009 |
EXTRACT_WORDS64 (ix, xhi);
|
|
Packit |
6c4009 |
ix &= 0x7fffffffffffffffLL;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* x is INF or NaN */
|
|
Packit |
6c4009 |
if(ix>=0x7ff0000000000000LL) return x*x;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* |x| in [0,0.5*ln2], return 1+expm1(|x|)^2/(2*exp(|x|)) */
|
|
Packit |
6c4009 |
if(ix<0x3fd62e42fefa39efLL) {
|
|
Packit |
6c4009 |
if (ix<0x3c80000000000000LL) return one; /* cosh(tiny) = 1 */
|
|
Packit |
6c4009 |
t = __expm1l(fabsl(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,40], return (exp(|x|)+1/exp(|x|)/2; */
|
|
Packit |
6c4009 |
if (ix < 0x4044000000000000LL) {
|
|
Packit |
6c4009 |
t = __ieee754_expl(fabsl(x));
|
|
Packit |
6c4009 |
return half*t+half/t;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* |x| in [40, log(maxdouble)] return half*exp(|x|) */
|
|
Packit |
6c4009 |
if (ix < 0x40862e42fefa39efLL) return half*__ieee754_expl(fabsl(x));
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* |x| in [log(maxdouble), overflowthresold] */
|
|
Packit |
6c4009 |
if (ix < 0x408633ce8fb9f87fLL) {
|
|
Packit |
6c4009 |
w = __ieee754_expl(half*fabsl(x));
|
|
Packit |
6c4009 |
t = half*w;
|
|
Packit |
6c4009 |
return t*w;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* |x| > overflowthresold, cosh(x) overflow */
|
|
Packit |
6c4009 |
return huge*huge;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
strong_alias (__ieee754_coshl, __coshl_finite)
|