Subversion Repositories Kolibri OS

Rev

Rev 1906 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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