1/*
2 * Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26/* __ieee754_sinh(x)
27 * Method :
28 * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
29 *      1. Replace x by |x| (sinh(-x) = -sinh(x)).
30 *      2.
31 *                                                  E + E/(E+1)
32 *          0        <= x <= 22     :  sinh(x) := --------------, E=expm1(x)
33 *                                                      2
34 *
35 *          22       <= x <= lnovft :  sinh(x) := exp(x)/2
36 *          lnovft   <= x <= ln2ovft:  sinh(x) := exp(x/2)/2 * exp(x/2)
37 *          ln2ovft  <  x           :  sinh(x) := x*shuge (overflow)
38 *
39 * Special cases:
40 *      sinh(x) is |x| if x is +INF, -INF, or NaN.
41 *      only sinh(0)=0 is exact for finite x.
42 */
43
44#include "fdlibm.h"
45
46#ifdef __STDC__
47static const double one = 1.0, shuge = 1.0e307;
48#else
49static double one = 1.0, shuge = 1.0e307;
50#endif
51
52#ifdef __STDC__
53        double __ieee754_sinh(double x)
54#else
55        double __ieee754_sinh(x)
56        double x;
57#endif
58{
59        double t,w,h;
60        int ix,jx;
61        unsigned lx;
62
63    /* High word of |x|. */
64        jx = __HI(x);
65        ix = jx&0x7fffffff;
66
67    /* x is INF or NaN */
68        if(ix>=0x7ff00000) return x+x;
69
70        h = 0.5;
71        if (jx<0) h = -h;
72    /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
73        if (ix < 0x40360000) {          /* |x|<22 */
74            if (ix<0x3e300000)          /* |x|<2**-28 */
75                if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */
76            t = expm1(fabs(x));
77            if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one));
78            return h*(t+t/(t+one));
79        }
80
81    /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
82        if (ix < 0x40862E42)  return h*__ieee754_exp(fabs(x));
83
84    /* |x| in [log(maxdouble), overflowthresold] */
85        lx = *( (((*(unsigned*)&one)>>29)) + (unsigned*)&x);
86        if (ix<0x408633CE || ((ix==0x408633ce)&&(lx<=(unsigned)0x8fb9f87d))) {
87            w = __ieee754_exp(0.5*fabs(x));
88            t = h*w;
89            return t*w;
90        }
91
92    /* |x| > overflowthresold, sinh(x) overflow */
93        return x*shuge;
94}
95