OSDN Git Service

e8452c2871214ee6d23b9faa7aba23c1874c7b22
[uclinux-h8/uClibc.git] / libm / e_sinh.c
1 /* @(#)e_sinh.c 5.1 93/09/24 */
2 /*
3  * ====================================================
4  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5  *
6  * Developed at SunPro, a Sun Microsystems, Inc. business.
7  * Permission to use, copy, modify, and distribute this
8  * software is freely granted, provided that this notice
9  * is preserved.
10  * ====================================================
11  */
12
13 #if defined(LIBM_SCCS) && !defined(lint)
14 static char rcsid[] = "$NetBSD: e_sinh.c,v 1.7 1995/05/10 20:46:13 jtc Exp $";
15 #endif
16
17 /* __ieee754_sinh(x)
18  * Method :
19  * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
20  *      1. Replace x by |x| (sinh(-x) = -sinh(x)).
21  *      2.
22  *                                                  E + E/(E+1)
23  *          0        <= x <= 22     :  sinh(x) := --------------, E=expm1(x)
24  *                                                      2
25  *
26  *          22       <= x <= lnovft :  sinh(x) := exp(x)/2
27  *          lnovft   <= x <= ln2ovft:  sinh(x) := exp(x/2)/2 * exp(x/2)
28  *          ln2ovft  <  x           :  sinh(x) := x*shuge (overflow)
29  *
30  * Special cases:
31  *      sinh(x) is |x| if x is +INF, -INF, or NaN.
32  *      only sinh(0)=0 is exact for finite x.
33  */
34
35 #include "math.h"
36 #include "math_private.h"
37
38 libm_hidden_proto(expm1)
39 libm_hidden_proto(fabs)
40
41 #ifdef __STDC__
42 static const double one = 1.0, shuge = 1.0e307;
43 #else
44 static double one = 1.0, shuge = 1.0e307;
45 #endif
46
47 #ifdef __STDC__
48         double attribute_hidden __ieee754_sinh(double x)
49 #else
50         double attribute_hidden __ieee754_sinh(x)
51         double x;
52 #endif
53 {
54         double t,w,h;
55         int32_t ix,jx;
56         u_int32_t lx;
57
58     /* High word of |x|. */
59         GET_HIGH_WORD(jx,x);
60         ix = jx&0x7fffffff;
61
62     /* x is INF or NaN */
63         if(ix>=0x7ff00000) return x+x;
64
65         h = 0.5;
66         if (jx<0) h = -h;
67     /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
68         if (ix < 0x40360000) {          /* |x|<22 */
69             if (ix<0x3e300000)          /* |x|<2**-28 */
70                 if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */
71             t = expm1(fabs(x));
72             if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one));
73             return h*(t+t/(t+one));
74         }
75
76     /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
77         if (ix < 0x40862E42)  return h*__ieee754_exp(fabs(x));
78
79     /* |x| in [log(maxdouble), overflowthresold] */
80         GET_LOW_WORD(lx,x);
81         if (ix<0x408633CE || ((ix==0x408633ce)&&(lx<=(u_int32_t)0x8fb9f87d))) {
82             w = __ieee754_exp(0.5*fabs(x));
83             t = h*w;
84             return t*w;
85         }
86
87     /* |x| > overflowthresold, sinh(x) overflow */
88         return x*shuge;
89 }