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 #if defined(LIBM_SCCS) && !defined(lint)
13 static char rcsid
[] = "$NetBSD: e_cosh.c,v 1.7 1995/05/10 20:44:58 jtc Exp $";
18 * mathematically coshl(x) if defined to be (exp(x)+exp(-x))/2
19 * 1. Replace x by |x| (coshl(x) = coshl(-x)).
22 * 0 <= x <= ln2/2 : coshl(x) := 1 + -------------------
26 * ln2/2 <= x <= 22 : coshl(x) := -------------------
28 * 22 <= x <= lnovft : coshl(x) := expl(x)/2
29 * lnovft <= x <= ln2ovft: coshl(x) := expl(x/2)/2 * expl(x/2)
30 * ln2ovft < x : coshl(x) := huge*huge (overflow)
33 * coshl(x) is |x| if x is +INF, -INF, or NaN.
34 * only coshl(0)=1 is exact for finite x.
38 #include <math_private.h>
40 static const long double one
= 1.0, half
=0.5, huge
= 1.0e4900L
;
43 __ieee754_coshl (long double x
)
49 /* High word of |x|. */
50 GET_LDOUBLE_WORDS(ex
,mx
,lx
,x
);
54 if (ex
< 0x4003 || (ex
== 0x4003 && mx
< 0xb0000000u
)) {
55 /* |x| in [0,0.5*ln2], return 1+expm1l(|x|)^2/(2*expl(|x|)) */
56 if(ex
< 0x3ffd || (ex
== 0x3ffd && mx
< 0xb17217f7u
)) {
57 if (ex
<0x3fbc) return one
; /* cosh(tiny) = 1 */
58 t
= __expm1l(fabsl(x
));
60 return one
+(t
*t
)/(w
+w
);
63 /* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|)/2; */
64 t
= __ieee754_expl(fabsl(x
));
68 /* |x| in [22, ln(maxdouble)] return half*exp(|x|) */
69 if (ex
< 0x400c || (ex
== 0x400c && mx
< 0xb1700000u
))
70 return half
*__ieee754_expl(fabsl(x
));
72 /* |x| in [log(maxdouble), log(2*maxdouble)) */
73 if (ex
== 0x400c && (mx
< 0xb174ddc0u
74 || (mx
== 0xb174ddc0u
&& lx
< 0x31aec0ebu
)))
76 w
= __ieee754_expl(half
*fabsl(x
));
82 if(ex
==0x7fff) return x
*x
;
84 /* |x| >= log(2*maxdouble), cosh(x) overflow */
87 strong_alias (__ieee754_coshl
, __coshl_finite
)