1 /*
2  * ====================================================
3  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
4  *
5  * Developed at SunPro, a Sun Microsystems, Inc. business.
6  * Permission to use, copy, modify, and distribute this
7  * software is freely granted, provided that this notice
8  * is preserved.
9  * ====================================================
10  */
11 
12 
13 /* __ieee754_sinh(x)
14  * Method :
15  * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
16  *	1. Replace x by |x| (sinh(-x) = -sinh(x)).
17  *	2.
18  *						    E + E/(E+1)
19  *	    0        <= x <= 40     :  sinh(x) := --------------, E=expm1(x)
20  *							2
21  *
22  *	    40       <= x <= lnovft :  sinh(x) := exp(x)/2
23  *	    lnovft   <= x <= ln2ovft:  sinh(x) := exp(x/2)/2 * exp(x/2)
24  *	    ln2ovft  <  x	    :  sinh(x) := x*shuge (overflow)
25  *
26  * Special cases:
27  *	sinh(x) is |x| if x is +INF, -INF, or NaN.
28  *	only sinh(0)=0 is exact for finite x.
29  */
30 
31 #include <float.h>
32 #include <math.h>
33 #include <math_private.h>
34 #include <math-underflow.h>
35 #include <libm-alias-finite.h>
36 
37 static const long double one = 1.0, shuge = 1.0e307;
38 
39 long double
__ieee754_sinhl(long double x)40 __ieee754_sinhl(long double x)
41 {
42 	long double t,w,h;
43 	int64_t ix,jx;
44 	double xhi;
45 
46     /* High word of |x|. */
47 	xhi = ldbl_high (x);
48 	EXTRACT_WORDS64 (jx, xhi);
49 	ix = jx&0x7fffffffffffffffLL;
50 
51     /* x is INF or NaN */
52 	if(ix>=0x7ff0000000000000LL) return x+x;
53 
54 	h = 0.5;
55 	if (jx<0) h = -h;
56     /* |x| in [0,40], return sign(x)*0.5*(E+E/(E+1))) */
57 	if (ix < 0x4044000000000000LL) {	/* |x|<40 */
58 	    if (ix<0x3c90000000000000LL) {	/* |x|<2**-54 */
59 		math_check_force_underflow (x);
60 		if(shuge+x>one) return x;/* sinhl(tiny) = tiny with inexact */
61 	    }
62 	    t = __expm1l(fabsl(x));
63 	    if(ix<0x3ff0000000000000LL) return h*(2.0*t-t*t/(t+one));
64 	    w = t/(t+one);
65 	    return h*(t+w);
66 	}
67 
68     /* |x| in [40, log(maxdouble)] return 0.5*exp(|x|) */
69 	if (ix < 0x40862e42fefa39efLL)  return h*__ieee754_expl(fabsl(x));
70 
71     /* |x| in [log(maxdouble), overflowthresold] */
72 	if (ix <= 0x408633ce8fb9f87eLL) {
73 	    w = __ieee754_expl(0.5*fabsl(x));
74 	    t = h*w;
75 	    return t*w;
76 	}
77 
78     /* |x| > overflowthresold, sinh(x) overflow */
79 	return x*shuge;
80 }
81 libm_alias_finite (__ieee754_sinhl, __sinhl)
82