1 /* @(#)e_sinh.c 5.1 93/09/24 */
2 /*
3  * ====================================================
4  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5  *
6  * Developed at SunPro, a Sun Microsystems, Inc. business.
7  * Permission to use, copy, modify, and distribute this
8  * software is freely granted, provided that this notice
9  * is preserved.
10  * ====================================================
11  */
12 
13 /* sinhl(x)
14  * Method :
15  * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
16  *	1. Replace x by |x| (sinhl(-x) = -sinhl(x)).
17  *	2.
18  *		                                     E + E/(E+1)
19  *	    0        <= x <= 25     :  sinhl(x) := --------------, E=expm1l(x)
20  *			       			         2
21  *
22  *	    25       <= x <= lnovft :  sinhl(x) := expl(x)/2
23  *	    lnovft   <= x <= ln2ovft:  sinhl(x) := expl(x/2)/2 * expl(x/2)
24  *	    ln2ovft  <  x	    :  sinhl(x) := x*shuge (overflow)
25  *
26  * Special cases:
27  *	sinhl(x) is |x| if x is +INF, -INF, or NaN.
28  *	only sinhl(0)=0 is exact for finite x.
29  */
30 
31 
32 
33 static const long double one = 1.0l, shuge = 1.0e4931L;
34 
35 long double
sinhl(long double x)36 sinhl(long double x)
37 {
38 	long double t,w,h;
39 	u_int32_t jx,ix,i0,i1;
40 
41     /* Words of |x|. */
42 	GET_LDOUBLE_WORDS(jx,i0,i1,x);
43 	ix = jx&0x7fff;
44 
45     /* x is INF or NaN */
46 	if(ix==0x7fff) return x+x;
47 
48 	h = 0.5l;
49 	if (jx & 0x8000) h = -h;
50     /* |x| in [0,25], return sign(x)*0.5*(E+E/(E+1))) */
51 	if (ix < 0x4003 || (ix == 0x4003 && i0 <= 0xc8000000)) { /* |x|<25 */
52 	    if (ix<0x3fdf)		 /* |x|<2**-32 */
53 		if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */
54 	    t = expm1l(fabsl(x));
55 	    if(ix<0x3fff) return h*(2.0l*t-t*t/(t+one));
56 	    return h*(t+t/(t+one));
57 	}
58 
59     /* |x| in [25, log(maxdouble)] return 0.5*exp(|x|) */
60 	if (ix < 0x400c || (ix == 0x400c && i0 < 0xb17217f7))
61 		return h*expl(fabsl(x));
62 
63     /* |x| in [log(maxdouble), overflowthreshold] */
64 	if (ix<0x400c || (ix == 0x400c && (i0 < 0xb174ddc0
65 					   || (i0 == 0xb174ddc0
66 					       && i1 <= 0x31aec0ea)))) {
67 	    w = expl(0.5l*fabsl(x));
68 	    t = h*w;
69 	    return t*w;
70 	}
71 
72     /* |x| > overflowthreshold, sinhl(x) overflow */
73 	return x*shuge;
74 }
75