(__ieee754_sqrt): Remove unused variables b and n.
[kopensolaris-gnu/glibc.git] / sysdeps / ieee754 / ldbl-96 / e_coshl.c
1 /*
2  * ====================================================
3  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
4  *
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
8  * is preserved.
9  * ====================================================
10  */
11
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 $";
14 #endif
15
16 /* __ieee754_coshl(x)
17  * Method :
18  * mathematically coshl(x) if defined to be (exp(x)+exp(-x))/2
19  *      1. Replace x by |x| (coshl(x) = coshl(-x)).
20  *      2.
21  *                                                      [ exp(x) - 1 ]^2
22  *          0        <= x <= ln2/2  :  coshl(x) := 1 + -------------------
23  *                                                         2*exp(x)
24  *
25  *                                                 exp(x) +  1/exp(x)
26  *          ln2/2    <= x <= 22     :  coshl(x) := -------------------
27  *                                                         2
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)
31  *
32  * Special cases:
33  *      coshl(x) is |x| if x is +INF, -INF, or NaN.
34  *      only coshl(0)=1 is exact for finite x.
35  */
36
37 #include "math.h"
38 #include "math_private.h"
39
40 #ifdef __STDC__
41 static const long double one = 1.0, half=0.5, huge = 1.0e4900L;
42 #else
43 static long double one = 1.0, half=0.5, huge = 1.0e4900L;
44 #endif
45
46 #ifdef __STDC__
47         long double __ieee754_coshl(long double x)
48 #else
49         long double __ieee754_coshl(x)
50         long double x;
51 #endif
52 {
53         long double t,w;
54         int32_t ex;
55         u_int32_t mx,lx;
56
57     /* High word of |x|. */
58         GET_LDOUBLE_WORDS(ex,mx,lx,x);
59         ex &= 0x7fff;
60
61     /* x is INF or NaN */
62         if(ex==0x7fff) return x*x;
63
64     /* |x| in [0,0.5*ln2], return 1+expm1l(|x|)^2/(2*expl(|x|)) */
65         if(ex < 0x3ffd || (ex == 0x3ffd && mx < 0xb17217f7u)) {
66             t = __expm1l(fabsl(x));
67             w = one+t;
68             if (ex<0x3fbc) return w;    /* cosh(tiny) = 1 */
69             return one+(t*t)/(w+w);
70         }
71
72     /* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|)/2; */
73         if (ex < 0x4003 || (ex == 0x4003 && mx < 0xb0000000u)) {
74                 t = __ieee754_expl(fabsl(x));
75                 return half*t+half/t;
76         }
77
78     /* |x| in [22, ln(maxdouble)] return half*exp(|x|) */
79         if (ex < 0x400c || (ex == 0x400c && mx < 0xb1700000u))
80                 return half*__ieee754_expl(fabsl(x));
81
82     /* |x| in [log(maxdouble), overflowthresold] */
83         if (ex < 0x400d
84             || (ex == 0x400d && (mx < 0xb170b513u
85                                   || (mx == 0xb170b513u && lx < 0xa1dfd60cu))))
86         {
87             w = __ieee754_expl(half*fabsl(x));
88             t = half*w;
89             return t*w;
90         }
91
92     /* |x| > overflowthresold, cosh(x) overflow */
93         return huge*huge;
94 }