]>
Commit | Line | Data |
---|---|---|
2aa62f2b | 1 | /* @(#)e_cosh.c 5.1 93/09/24 */\r |
2 | /*\r | |
3 | * ====================================================\r | |
4 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\r | |
5 | *\r | |
6 | * Developed at SunPro, a Sun Microsystems, Inc. business.\r | |
7 | * Permission to use, copy, modify, and distribute this\r | |
8 | * software is freely granted, provided that this notice\r | |
9 | * is preserved.\r | |
10 | * ====================================================\r | |
11 | */\r | |
12 | #include <LibConfig.h>\r | |
13 | #include <sys/EfiCdefs.h>\r | |
14 | #if defined(LIBM_SCCS) && !defined(lint)\r | |
15 | __RCSID("$NetBSD: e_cosh.c,v 1.11 2002/05/26 22:01:49 wiz Exp $");\r | |
16 | #endif\r | |
17 | \r | |
18 | #if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */\r | |
19 | // C4756: overflow in constant arithmetic\r | |
20 | #pragma warning ( disable : 4756 )\r | |
21 | #endif\r | |
22 | \r | |
23 | /* __ieee754_cosh(x)\r | |
24 | * Method :\r | |
25 | * mathematically cosh(x) if defined to be (exp(x)+exp(-x))/2\r | |
26 | * 1. Replace x by |x| (cosh(x) = cosh(-x)).\r | |
27 | * 2.\r | |
28 | * [ exp(x) - 1 ]^2\r | |
29 | * 0 <= x <= ln2/2 : cosh(x) := 1 + -------------------\r | |
30 | * 2*exp(x)\r | |
31 | *\r | |
32 | * exp(x) + 1/exp(x)\r | |
33 | * ln2/2 <= x <= 22 : cosh(x) := -------------------\r | |
34 | * 2\r | |
35 | * 22 <= x <= lnovft : cosh(x) := exp(x)/2\r | |
36 | * lnovft <= x <= ln2ovft: cosh(x) := exp(x/2)/2 * exp(x/2)\r | |
37 | * ln2ovft < x : cosh(x) := huge*huge (overflow)\r | |
38 | *\r | |
39 | * Special cases:\r | |
40 | * cosh(x) is |x| if x is +INF, -INF, or NaN.\r | |
41 | * only cosh(0)=1 is exact for finite x.\r | |
42 | */\r | |
43 | \r | |
44 | #include "math.h"\r | |
45 | #include "math_private.h"\r | |
46 | \r | |
47 | static const double one = 1.0, half=0.5, huge = 1.0e300;\r | |
48 | \r | |
49 | double\r | |
50 | __ieee754_cosh(double x)\r | |
51 | {\r | |
52 | double t,w;\r | |
53 | int32_t ix;\r | |
54 | u_int32_t lx;\r | |
55 | \r | |
56 | /* High word of |x|. */\r | |
57 | GET_HIGH_WORD(ix,x);\r | |
58 | ix &= 0x7fffffff;\r | |
59 | \r | |
60 | /* x is INF or NaN */\r | |
61 | if(ix>=0x7ff00000) return x*x;\r | |
62 | \r | |
63 | /* |x| in [0,0.5*ln2], return 1+expm1(|x|)^2/(2*exp(|x|)) */\r | |
64 | if(ix<0x3fd62e43) {\r | |
65 | t = expm1(fabs(x));\r | |
66 | w = one+t;\r | |
67 | if (ix<0x3c800000) return w; /* cosh(tiny) = 1 */\r | |
68 | return one+(t*t)/(w+w);\r | |
69 | }\r | |
70 | \r | |
71 | /* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|)/2; */\r | |
72 | if (ix < 0x40360000) {\r | |
73 | t = __ieee754_exp(fabs(x));\r | |
74 | return half*t+half/t;\r | |
75 | }\r | |
76 | \r | |
77 | /* |x| in [22, log(maxdouble)] return half*exp(|x|) */\r | |
78 | if (ix < 0x40862E42) return half*__ieee754_exp(fabs(x));\r | |
79 | \r | |
80 | /* |x| in [log(maxdouble), overflowthresold] */\r | |
81 | GET_LOW_WORD(lx,x);\r | |
82 | if (ix<0x408633CE ||\r | |
83 | ((ix==0x408633ce)&&(lx<=(u_int32_t)0x8fb9f87d))) {\r | |
84 | w = __ieee754_exp(half*fabs(x));\r | |
85 | t = half*w;\r | |
86 | return t*w;\r | |
87 | }\r | |
88 | \r | |
89 | /* |x| > overflowthresold, cosh(x) overflow */\r | |
90 | return huge*huge;\r | |
91 | }\r |