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 /*
14  * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
15  *
16  * Permission to use, copy, modify, and distribute this software for any
17  * purpose with or without fee is hereby granted, provided that the above
18  * copyright notice and this permission notice appear in all copies.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
21  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
22  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
23  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
24  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
25  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
26  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
27  */
28 
29 /* sinhl(x)
30  * Method :
31  * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
32  *      1. Replace x by |x| (sinhl(-x) = -sinhl(x)).
33  *      2.
34  *                                                   E + E/(E+1)
35  *          0        <= x <= 25     :  sinhl(x) := --------------, E=expm1l(x)
36  *                                                       2
37  *
38  *          25       <= x <= lnovft :  sinhl(x) := expl(x)/2
39  *          lnovft   <= x <= ln2ovft:  sinhl(x) := expl(x/2)/2 * expl(x/2)
40  *          ln2ovft  <  x           :  sinhl(x) := x*shuge (overflow)
41  *
42  * Special cases:
43  *      sinhl(x) is |x| if x is +INF, -INF, or NaN.
44  *      only sinhl(0)=0 is exact for finite x.
45  */
46 
47 
48 
49 static const long double one = 1.0L, shuge = 1.0e4931L,
50 ovf_thresh = 1.1357216553474703894801348310092223067821E4L;
51 
52 long double
sinhl(long double x)53 sinhl(long double x)
54 {
55   long double t, w, h;
56   int32_t jx;
57   u_int32_t ix;
58   ieee_quad_shape_type u;
59 
60   /* Words of |x|. */
61   u.value = x;
62   jx = u.parts32.mswhi;
63   ix = jx & 0x7fffffff;
64 
65   /* x is INF or NaN */
66   if (ix >= 0x7fff0000)
67     return x + x;
68 
69   h = 0.5L;
70   if (jx < 0)
71     h = -h;
72 
73   /* Absolute value of x.  */
74   u.parts32.mswhi = ix;
75 
76   /* |x| in [0,40], return sign(x)*0.5*(E+E/(E+1))) */
77   if (ix <= 0x40044000)
78     {
79       if (ix < 0x3fc60000) /* |x| < 2^-57 */
80 	if (shuge + x > one)
81 	  return x;		/* sinh(tiny) = tiny with inexact */
82       t = expm1l (u.value);
83       if (ix < 0x3fff0000)
84 	return h * (2.0L * t - t * t / (t + one));
85       return h * (t + t / (t + one));
86     }
87 
88   /* |x| in [40, log(maxdouble)] return 0.5*exp(|x|) */
89   if (ix <= 0x400c62e3) /* 11356.375 */
90     return h * expl (u.value);
91 
92   /* |x| in [log(maxdouble), overflowthreshold]
93      Overflow threshold is log(2 * maxdouble).  */
94   if (u.value <= ovf_thresh)
95     {
96       w = expl (0.5L * u.value);
97       t = h * w;
98       return t * w;
99     }
100 
101   /* |x| > overflowthreshold, sinhl(x) overflow */
102   return __math_oflowl(jx < 0);
103 }
104