sl@0
|
1 |
/* E_COSH.C
|
sl@0
|
2 |
*
|
sl@0
|
3 |
* Portions Copyright (c) 1993-1999 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
4 |
* All rights reserved.
|
sl@0
|
5 |
*/
|
sl@0
|
6 |
|
sl@0
|
7 |
|
sl@0
|
8 |
/* @(#)e_cosh.c 5.1 93/09/24 */
|
sl@0
|
9 |
/*
|
sl@0
|
10 |
* ====================================================
|
sl@0
|
11 |
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
sl@0
|
12 |
*
|
sl@0
|
13 |
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
sl@0
|
14 |
* Permission to use, copy, modify, and distribute this
|
sl@0
|
15 |
* software is freely granted, provided that this notice
|
sl@0
|
16 |
* is preserved.
|
sl@0
|
17 |
* ====================================================
|
sl@0
|
18 |
*/
|
sl@0
|
19 |
|
sl@0
|
20 |
/* __ieee754_cosh(x)
|
sl@0
|
21 |
* Method :
|
sl@0
|
22 |
* mathematically cosh(x) if defined to be (exp(x)+exp(-x))/2
|
sl@0
|
23 |
* 1. Replace x by |x| (cosh(x) = cosh(-x)).
|
sl@0
|
24 |
* 2.
|
sl@0
|
25 |
* [ exp(x) - 1 ]^2
|
sl@0
|
26 |
* 0 <= x <= ln2/2 : cosh(x) := 1 + -------------------
|
sl@0
|
27 |
* 2*exp(x)
|
sl@0
|
28 |
*
|
sl@0
|
29 |
* exp(x) + 1/exp(x)
|
sl@0
|
30 |
* ln2/2 <= x <= 22 : cosh(x) := -------------------
|
sl@0
|
31 |
* 2
|
sl@0
|
32 |
* 22 <= x <= lnovft : cosh(x) := exp(x)/2
|
sl@0
|
33 |
* lnovft <= x <= ln2ovft: cosh(x) := exp(x/2)/2 * exp(x/2)
|
sl@0
|
34 |
* ln2ovft < x : cosh(x) := huge*huge (overflow)
|
sl@0
|
35 |
*
|
sl@0
|
36 |
* Special cases:
|
sl@0
|
37 |
* cosh(x) is |x| if x is +INF, -INF, or NaN.
|
sl@0
|
38 |
* only cosh(0)=1 is exact for finite x.
|
sl@0
|
39 |
*/
|
sl@0
|
40 |
|
sl@0
|
41 |
#include "FDLIBM.H"
|
sl@0
|
42 |
|
sl@0
|
43 |
static const double one = 1.0, half=0.5, huge = 1.0e300;
|
sl@0
|
44 |
|
sl@0
|
45 |
EXPORT_C double __ieee754_cosh(double x) __SOFTFP
|
sl@0
|
46 |
{
|
sl@0
|
47 |
double t,w;
|
sl@0
|
48 |
__int32_t ix;
|
sl@0
|
49 |
__uint32_t lx;
|
sl@0
|
50 |
|
sl@0
|
51 |
/* High word of |x|. */
|
sl@0
|
52 |
GET_HIGH_WORD(ix,x);
|
sl@0
|
53 |
ix &= 0x7fffffff;
|
sl@0
|
54 |
|
sl@0
|
55 |
/* x is INF or NaN */
|
sl@0
|
56 |
if(ix>=0x7ff00000) return x*x;
|
sl@0
|
57 |
|
sl@0
|
58 |
/* |x| in [0,0.5*ln2], return 1+expm1(|x|)^2/(2*exp(|x|)) */
|
sl@0
|
59 |
if(ix<0x3fd62e43) {
|
sl@0
|
60 |
t = expm1(fabs(x));
|
sl@0
|
61 |
w = one+t;
|
sl@0
|
62 |
if (ix<0x3c800000) return w; /* cosh(tiny) = 1 */
|
sl@0
|
63 |
return one+(t*t)/(w+w);
|
sl@0
|
64 |
}
|
sl@0
|
65 |
|
sl@0
|
66 |
/* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|)/2; */
|
sl@0
|
67 |
if (ix < 0x40360000) {
|
sl@0
|
68 |
t = __ieee754_exp(fabs(x));
|
sl@0
|
69 |
return half*t+half/t;
|
sl@0
|
70 |
}
|
sl@0
|
71 |
|
sl@0
|
72 |
/* |x| in [22, log(maxdouble)] return half*exp(|x|) */
|
sl@0
|
73 |
if (ix < 0x40862E42) return half*__ieee754_exp(fabs(x));
|
sl@0
|
74 |
|
sl@0
|
75 |
/* |x| in [log(maxdouble), overflowthresold] */
|
sl@0
|
76 |
GET_LOW_WORD(lx,x);
|
sl@0
|
77 |
if (ix<0x408633CE ||
|
sl@0
|
78 |
((ix==0x408633ce)&&(lx<=(__uint32_t)0x8fb9f87d))) {
|
sl@0
|
79 |
w = __ieee754_exp(half*fabs(x));
|
sl@0
|
80 |
t = half*w;
|
sl@0
|
81 |
return t*w;
|
sl@0
|
82 |
}
|
sl@0
|
83 |
|
sl@0
|
84 |
/* |x| > overflowthresold, cosh(x) overflow */
|
sl@0
|
85 |
return huge*huge;
|
sl@0
|
86 |
}
|