2.9
[glibc/nacl-glibc.git] / sysdeps / ieee754 / ldbl-128 / e_sinhl.c
blob93f4179c6580dd3e231c057951c24389b7d6febc
1 /* e_sinhl.c -- long double version of e_sinh.c.
2 * Conversion to long double by Ulrich Drepper,
3 * Cygnus Support, drepper@cygnus.com.
4 */
6 /*
7 * ====================================================
8 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
10 * Developed at SunPro, a Sun Microsystems, Inc. business.
11 * Permission to use, copy, modify, and distribute this
12 * software is freely granted, provided that this notice
13 * is preserved.
14 * ====================================================
17 /* Changes for 128-bit long double are
18 Copyright (C) 2001 Stephen L. Moshier <moshier@na-net.ornl.gov>
19 and are incorporated herein by permission of the author. The author
20 reserves the right to distribute this material elsewhere under different
21 copying permissions. These modifications are distributed here under
22 the following terms:
24 This library is free software; you can redistribute it and/or
25 modify it under the terms of the GNU Lesser General Public
26 License as published by the Free Software Foundation; either
27 version 2.1 of the License, or (at your option) any later version.
29 This library is distributed in the hope that it will be useful,
30 but WITHOUT ANY WARRANTY; without even the implied warranty of
31 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32 Lesser General Public License for more details.
34 You should have received a copy of the GNU Lesser General Public
35 License along with this library; if not, write to the Free Software
36 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
38 /* __ieee754_sinhl(x)
39 * Method :
40 * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
41 * 1. Replace x by |x| (sinhl(-x) = -sinhl(x)).
42 * 2.
43 * E + E/(E+1)
44 * 0 <= x <= 25 : sinhl(x) := --------------, E=expm1l(x)
45 * 2
47 * 25 <= x <= lnovft : sinhl(x) := expl(x)/2
48 * lnovft <= x <= ln2ovft: sinhl(x) := expl(x/2)/2 * expl(x/2)
49 * ln2ovft < x : sinhl(x) := x*shuge (overflow)
51 * Special cases:
52 * sinhl(x) is |x| if x is +INF, -INF, or NaN.
53 * only sinhl(0)=0 is exact for finite x.
56 #include "math.h"
57 #include "math_private.h"
59 #ifdef __STDC__
60 static const long double one = 1.0, shuge = 1.0e4931L,
61 ovf_thresh = 1.1357216553474703894801348310092223067821E4L;
62 #else
63 static long double one = 1.0, shuge = 1.0e4931L,
64 ovf_thresh = 1.1357216553474703894801348310092223067821E4L;
65 #endif
67 #ifdef __STDC__
68 long double
69 __ieee754_sinhl (long double x)
70 #else
71 long double
72 __ieee754_sinhl (x)
73 long double x;
74 #endif
76 long double t, w, h;
77 u_int32_t jx, ix;
78 ieee854_long_double_shape_type u;
80 /* Words of |x|. */
81 u.value = x;
82 jx = u.parts32.w0;
83 ix = jx & 0x7fffffff;
85 /* x is INF or NaN */
86 if (ix >= 0x7fff0000)
87 return x + x;
89 h = 0.5;
90 if (jx & 0x80000000)
91 h = -h;
93 /* Absolute value of x. */
94 u.parts32.w0 = ix;
96 /* |x| in [0,40], return sign(x)*0.5*(E+E/(E+1))) */
97 if (ix <= 0x40044000)
99 if (ix < 0x3fc60000) /* |x| < 2^-57 */
100 if (shuge + x > one)
101 return x; /* sinh(tiny) = tiny with inexact */
102 t = __expm1l (u.value);
103 if (ix < 0x3fff0000)
104 return h * (2.0 * t - t * t / (t + one));
105 return h * (t + t / (t + one));
108 /* |x| in [40, log(maxdouble)] return 0.5*exp(|x|) */
109 if (ix <= 0x400c62e3) /* 11356.375 */
110 return h * __ieee754_expl (u.value);
112 /* |x| in [log(maxdouble), overflowthreshold]
113 Overflow threshold is log(2 * maxdouble). */
114 if (u.value <= ovf_thresh)
116 w = __ieee754_expl (0.5 * u.value);
117 t = h * w;
118 return t * w;
121 /* |x| > overflowthreshold, sinhl(x) overflow */
122 return x * shuge;