2 * ====================================================
3 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5 * Developed at SunPro, a Sun Microsystems, Inc. business.
6 * Permission to use, copy, modify, and distribute this
7 * software is freely granted, provided that this notice
9 * ====================================================
12 /* Changes for 128-bit long double contributed by
13 Stephen L. Moshier <moshier@na-net.ornl.gov> */
17 * mathematically coshl(x) if defined to be (exp(x)+exp(-x))/2
18 * 1. Replace x by |x| (coshl(x) = coshl(-x)).
21 * 0 <= x <= ln2/2 : coshl(x) := 1 + -------------------
25 * ln2/2 <= x <= 22 : coshl(x) := -------------------
27 * 22 <= x <= lnovft : coshl(x) := expl(x)/2
28 * lnovft <= x <= ln2ovft: coshl(x) := expl(x/2)/2 * expl(x/2)
29 * ln2ovft < x : coshl(x) := huge*huge (overflow)
32 * coshl(x) is |x| if x is +INF, -INF, or NaN.
33 * only coshl(0)=1 is exact for finite x.
37 #include "math_private.h"
40 static const long double one
= 1.0, half
= 0.5, huge
= 1.0e4900L
,
41 ovf_thresh
= 1.1357216553474703894801348310092223067821E4L
;
43 static long double one
= 1.0, half
= 0.5, huge
= 1.0e4900L
,
44 ovf_thresh
= 1.1357216553474703894801348310092223067821E4L
;
49 __ieee754_coshl (long double x
)
59 ieee854_long_double_shape_type u
;
62 ex
= u
.parts32
.w0
& 0x7fffffff;
64 /* Absolute value of x. */
71 /* |x| in [0,0.5*ln2], return 1+expm1l(|x|)^2/(2*expl(|x|)) */
72 if (ex
< 0x3ffd62e4) /* 0.3465728759765625 */
74 t
= __expm1l (u
.value
);
76 if (ex
< 0x3fc60000) /* |x| < 2^-57 */
77 return w
; /* cosh(tiny) = 1 */
79 return one
+ (t
* t
) / (w
+ w
);
82 /* |x| in [0.5*ln2,40], return (exp(|x|)+1/exp(|x|)/2; */
85 t
= __ieee754_expl (u
.value
);
86 return half
* t
+ half
/ t
;
89 /* |x| in [22, ln(maxdouble)] return half*exp(|x|) */
90 if (ex
<= 0x400c62e3) /* 11356.375 */
91 return half
* __ieee754_expl (u
.value
);
93 /* |x| in [log(maxdouble), overflowthresold] */
94 if (u
.value
<= ovf_thresh
)
96 w
= __ieee754_expl (half
* u
.value
);
101 /* |x| > overflowthresold, cosh(x) overflow */