1*627f7eb2Smrg /* e_sinhl.c -- long double version of e_sinh.c.
2*627f7eb2Smrg * Conversion to long double by Ulrich Drepper,
3*627f7eb2Smrg * Cygnus Support, drepper@cygnus.com.
4*627f7eb2Smrg */
5*627f7eb2Smrg
6*627f7eb2Smrg /*
7*627f7eb2Smrg * ====================================================
8*627f7eb2Smrg * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9*627f7eb2Smrg *
10*627f7eb2Smrg * Developed at SunPro, a Sun Microsystems, Inc. business.
11*627f7eb2Smrg * Permission to use, copy, modify, and distribute this
12*627f7eb2Smrg * software is freely granted, provided that this notice
13*627f7eb2Smrg * is preserved.
14*627f7eb2Smrg * ====================================================
15*627f7eb2Smrg */
16*627f7eb2Smrg
17*627f7eb2Smrg /* Changes for 128-bit long double are
18*627f7eb2Smrg Copyright (C) 2001 Stephen L. Moshier <moshier@na-net.ornl.gov>
19*627f7eb2Smrg and are incorporated herein by permission of the author. The author
20*627f7eb2Smrg reserves the right to distribute this material elsewhere under different
21*627f7eb2Smrg copying permissions. These modifications are distributed here under
22*627f7eb2Smrg the following terms:
23*627f7eb2Smrg
24*627f7eb2Smrg This library is free software; you can redistribute it and/or
25*627f7eb2Smrg modify it under the terms of the GNU Lesser General Public
26*627f7eb2Smrg License as published by the Free Software Foundation; either
27*627f7eb2Smrg version 2.1 of the License, or (at your option) any later version.
28*627f7eb2Smrg
29*627f7eb2Smrg This library is distributed in the hope that it will be useful,
30*627f7eb2Smrg but WITHOUT ANY WARRANTY; without even the implied warranty of
31*627f7eb2Smrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32*627f7eb2Smrg Lesser General Public License for more details.
33*627f7eb2Smrg
34*627f7eb2Smrg You should have received a copy of the GNU Lesser General Public
35*627f7eb2Smrg License along with this library; if not, see
36*627f7eb2Smrg <http://www.gnu.org/licenses/>. */
37*627f7eb2Smrg
38*627f7eb2Smrg /* sinhq(x)
39*627f7eb2Smrg * Method :
40*627f7eb2Smrg * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
41*627f7eb2Smrg * 1. Replace x by |x| (sinhl(-x) = -sinhl(x)).
42*627f7eb2Smrg * 2.
43*627f7eb2Smrg * E + E/(E+1)
44*627f7eb2Smrg * 0 <= x <= 25 : sinhl(x) := --------------, E=expm1q(x)
45*627f7eb2Smrg * 2
46*627f7eb2Smrg *
47*627f7eb2Smrg * 25 <= x <= lnovft : sinhl(x) := expq(x)/2
48*627f7eb2Smrg * lnovft <= x <= ln2ovft: sinhl(x) := expq(x/2)/2 * expq(x/2)
49*627f7eb2Smrg * ln2ovft < x : sinhl(x) := x*shuge (overflow)
50*627f7eb2Smrg *
51*627f7eb2Smrg * Special cases:
52*627f7eb2Smrg * sinhl(x) is |x| if x is +INF, -INF, or NaN.
53*627f7eb2Smrg * only sinhl(0)=0 is exact for finite x.
54*627f7eb2Smrg */
55*627f7eb2Smrg
56*627f7eb2Smrg #include "quadmath-imp.h"
57*627f7eb2Smrg
58*627f7eb2Smrg static const __float128 one = 1.0, shuge = 1.0e4931Q,
59*627f7eb2Smrg ovf_thresh = 1.1357216553474703894801348310092223067821E4Q;
60*627f7eb2Smrg
61*627f7eb2Smrg __float128
sinhq(__float128 x)62*627f7eb2Smrg sinhq (__float128 x)
63*627f7eb2Smrg {
64*627f7eb2Smrg __float128 t, w, h;
65*627f7eb2Smrg uint32_t jx, ix;
66*627f7eb2Smrg ieee854_float128 u;
67*627f7eb2Smrg
68*627f7eb2Smrg /* Words of |x|. */
69*627f7eb2Smrg u.value = x;
70*627f7eb2Smrg jx = u.words32.w0;
71*627f7eb2Smrg ix = jx & 0x7fffffff;
72*627f7eb2Smrg
73*627f7eb2Smrg /* x is INF or NaN */
74*627f7eb2Smrg if (ix >= 0x7fff0000)
75*627f7eb2Smrg return x + x;
76*627f7eb2Smrg
77*627f7eb2Smrg h = 0.5;
78*627f7eb2Smrg if (jx & 0x80000000)
79*627f7eb2Smrg h = -h;
80*627f7eb2Smrg
81*627f7eb2Smrg /* Absolute value of x. */
82*627f7eb2Smrg u.words32.w0 = ix;
83*627f7eb2Smrg
84*627f7eb2Smrg /* |x| in [0,40], return sign(x)*0.5*(E+E/(E+1))) */
85*627f7eb2Smrg if (ix <= 0x40044000)
86*627f7eb2Smrg {
87*627f7eb2Smrg if (ix < 0x3fc60000) /* |x| < 2^-57 */
88*627f7eb2Smrg {
89*627f7eb2Smrg math_check_force_underflow (x);
90*627f7eb2Smrg if (shuge + x > one)
91*627f7eb2Smrg return x; /* sinh(tiny) = tiny with inexact */
92*627f7eb2Smrg }
93*627f7eb2Smrg t = expm1q (u.value);
94*627f7eb2Smrg if (ix < 0x3fff0000)
95*627f7eb2Smrg return h * (2.0 * t - t * t / (t + one));
96*627f7eb2Smrg return h * (t + t / (t + one));
97*627f7eb2Smrg }
98*627f7eb2Smrg
99*627f7eb2Smrg /* |x| in [40, log(maxdouble)] return 0.5*exp(|x|) */
100*627f7eb2Smrg if (ix <= 0x400c62e3) /* 11356.375 */
101*627f7eb2Smrg return h * expq (u.value);
102*627f7eb2Smrg
103*627f7eb2Smrg /* |x| in [log(maxdouble), overflowthreshold]
104*627f7eb2Smrg Overflow threshold is log(2 * maxdouble). */
105*627f7eb2Smrg if (u.value <= ovf_thresh)
106*627f7eb2Smrg {
107*627f7eb2Smrg w = expq (0.5 * u.value);
108*627f7eb2Smrg t = h * w;
109*627f7eb2Smrg return t * w;
110*627f7eb2Smrg }
111*627f7eb2Smrg
112*627f7eb2Smrg /* |x| > overflowthreshold, sinhl(x) overflow */
113*627f7eb2Smrg return x * shuge;
114*627f7eb2Smrg }
115