initial check-in, version 0.5.0
[musl] / src / math / e_sinh.c
1
2 /* @(#)e_sinh.c 1.3 95/01/18 */
3 /*
4  * ====================================================
5  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6  *
7  * Developed at SunSoft, a Sun Microsystems, Inc. business.
8  * Permission to use, copy, modify, and distribute this
9  * software is freely granted, provided that this notice 
10  * is preserved.
11  * ====================================================
12  */
13
14 /* sinh(x)
15  * Method : 
16  * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
17  *      1. Replace x by |x| (sinh(-x) = -sinh(x)). 
18  *      2. 
19  *                                                  E + E/(E+1)
20  *          0        <= x <= 22     :  sinh(x) := --------------, E=expm1(x)
21  *                                                      2
22  *
23  *          22       <= x <= lnovft :  sinh(x) := exp(x)/2 
24  *          lnovft   <= x <= ln2ovft:  sinh(x) := exp(x/2)/2 * exp(x/2)
25  *          ln2ovft  <  x           :  sinh(x) := x*shuge (overflow)
26  *
27  * Special cases:
28  *      sinh(x) is |x| if x is +INF, -INF, or NaN.
29  *      only sinh(0)=0 is exact for finite x.
30  */
31
32 #include <math.h>
33 #include "math_private.h"
34
35 static const double one = 1.0, shuge = 1.0e307;
36
37 double
38 sinh(double x)
39 {
40         double t,w,h;
41         int32_t ix,jx;
42         uint32_t lx;
43
44     /* High word of |x|. */
45         GET_HIGH_WORD(jx,x);
46         ix = jx&0x7fffffff;
47
48     /* x is INF or NaN */
49         if(ix>=0x7ff00000) return x+x;  
50
51         h = 0.5;
52         if (jx<0) h = -h;
53     /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
54         if (ix < 0x40360000) {          /* |x|<22 */
55             if (ix<0x3e300000)          /* |x|<2**-28 */
56                 if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */
57             t = expm1(fabs(x));
58             if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one));
59             return h*(t+t/(t+one));
60         }
61
62     /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
63         if (ix < 0x40862E42)  return h*exp(fabs(x));
64
65     /* |x| in [log(maxdouble), overflowthresold] */
66         GET_LOW_WORD(lx,x);
67         if (ix<0x408633CE || ((ix==0x408633ce)&&(lx<=(uint32_t)0x8fb9f87d))) {
68             w = exp(0.5*fabs(x));
69             t = h*w;
70             return t*w;
71         }
72
73     /* |x| > overflowthresold, sinh(x) overflow */
74         return x*shuge;
75 }