]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/libm/e_sinh.c
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / libm / e_sinh.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 /* __ieee754_sinh(x)
13  * Method :
14  * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
15  *      1. Replace x by |x| (sinh(-x) = -sinh(x)).
16  *      2.
17  *                                                  E + E/(E+1)
18  *          0        <= x <= 22     :  sinh(x) := --------------, E=expm1(x)
19  *                                                      2
20  *
21  *          22       <= x <= lnovft :  sinh(x) := exp(x)/2
22  *          lnovft   <= x <= ln2ovft:  sinh(x) := exp(x/2)/2 * exp(x/2)
23  *          ln2ovft  <  x           :  sinh(x) := x*shuge (overflow)
24  *
25  * Special cases:
26  *      sinh(x) is |x| if x is +INF, -INF, or NaN.
27  *      only sinh(0)=0 is exact for finite x.
28  */
29
30 #include "math.h"
31 #include "math_private.h"
32
33 static const double one = 1.0, shuge = 1.0e307;
34
35 double __ieee754_sinh(double x)
36 {
37         double t,w,h;
38         int32_t ix,jx;
39         u_int32_t lx;
40
41     /* High word of |x|. */
42         GET_HIGH_WORD(jx,x);
43         ix = jx&0x7fffffff;
44
45     /* x is INF or NaN */
46         if(ix>=0x7ff00000) return x+x;
47
48         h = 0.5;
49         if (jx<0) h = -h;
50     /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
51         if (ix < 0x40360000) {          /* |x|<22 */
52             if (ix<0x3e300000)          /* |x|<2**-28 */
53                 if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */
54             t = expm1(fabs(x));
55             if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one));
56             return h*(t+t/(t+one));
57         }
58
59     /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
60         if (ix < 0x40862E42)  return h*__ieee754_exp(fabs(x));
61
62     /* |x| in [log(maxdouble), overflowthresold] */
63         GET_LOW_WORD(lx,x);
64         if (ix<0x408633CE || ((ix==0x408633ce)&&(lx<=(u_int32_t)0x8fb9f87d))) {
65             w = __ieee754_exp(0.5*fabs(x));
66             t = h*w;
67             return t*w;
68         }
69
70     /* |x| > overflowthresold, sinh(x) overflow */
71         return x*shuge;
72 }
73
74 /*
75  * wrapper sinh(x)
76  */
77 #ifndef _IEEE_LIBM
78 double sinh(double x)
79 {
80         double z = __ieee754_sinh(x);
81         if (_LIB_VERSION == _IEEE_)
82                 return z;
83         if (!isfinite(z) && isfinite(x))
84                 return __kernel_standard(x, x, 25); /* sinh overflow */
85         return z;
86 }
87 #else
88 strong_alias(__ieee754_sinh, sinh)
89 #endif
90 libm_hidden_def(sinh)