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