xref: /freebsd/lib/msun/src/e_sinh.c (revision 2e3507c25e42292b45a5482e116d278f5515d04d)
1 
2 /*
3  * ====================================================
4  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5  *
6  * Developed at SunSoft, 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 #include <sys/cdefs.h>
14 /* sinh(x)
15  * Method :
16  * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
17  *	1. Replace x by |x| (sinh(-x) = -sinh(x)).
18  *	2.
19  *		                                    E + E/(E+1)
20  *	    0        <= x <= 22     :  sinh(x) := --------------, E=expm1(x)
21  *			       			        2
22  *
23  *	    22       <= x <= lnovft :  sinh(x) := exp(x)/2
24  *	    lnovft   <= x <= ln2ovft:  sinh(x) := exp(x/2)/2 * exp(x/2)
25  *	    ln2ovft  <  x	    :  sinh(x) := x*shuge (overflow)
26  *
27  * Special cases:
28  *	sinh(x) is |x| if x is +INF, -INF, or NaN.
29  *	only sinh(0)=0 is exact for finite x.
30  */
31 
32 #include <float.h>
33 
34 #include "math.h"
35 #include "math_private.h"
36 
37 static const double one = 1.0, shuge = 1.0e307;
38 
39 double
40 sinh(double x)
41 {
42 	double t,h;
43 	int32_t ix,jx;
44 
45     /* High word of |x|. */
46 	GET_HIGH_WORD(jx,x);
47 	ix = jx&0x7fffffff;
48 
49     /* x is INF or NaN */
50 	if(ix>=0x7ff00000) return x+x;
51 
52 	h = 0.5;
53 	if (jx<0) h = -h;
54     /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
55 	if (ix < 0x40360000) {		/* |x|<22 */
56 	    if (ix<0x3e300000) 		/* |x|<2**-28 */
57 		if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */
58 	    t = expm1(fabs(x));
59 	    if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one));
60 	    return h*(t+t/(t+one));
61 	}
62 
63     /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
64 	if (ix < 0x40862E42)  return h*exp(fabs(x));
65 
66     /* |x| in [log(maxdouble), overflowthresold] */
67 	if (ix<=0x408633CE)
68 	    return h*2.0*__ldexp_exp(fabs(x), -1);
69 
70     /* |x| > overflowthresold, sinh(x) overflow */
71 	return x*shuge;
72 }
73 
74 #if (LDBL_MANT_DIG == 53)
75 __weak_reference(sinh, sinhl);
76 #endif
77