xref: /netbsd-src/lib/libm/src/e_sinh.c (revision 2a399c6883d870daece976daec6ffa7bb7f934ce)
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 #include <sys/cdefs.h>
14 #if defined(LIBM_SCCS) && !defined(lint)
15 __RCSID("$NetBSD: e_sinh.c,v 1.9 1997/10/09 11:30:00 lukem Exp $");
16 #endif
17 
18 /* __ieee754_sinh(x)
19  * Method :
20  * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
21  *	1. Replace x by |x| (sinh(-x) = -sinh(x)).
22  *	2.
23  *		                                    E + E/(E+1)
24  *	    0        <= x <= 22     :  sinh(x) := --------------, E=expm1(x)
25  *			       			        2
26  *
27  *	    22       <= x <= lnovft :  sinh(x) := exp(x)/2
28  *	    lnovft   <= x <= ln2ovft:  sinh(x) := exp(x/2)/2 * exp(x/2)
29  *	    ln2ovft  <  x	    :  sinh(x) := x*shuge (overflow)
30  *
31  * Special cases:
32  *	sinh(x) is |x| if x is +INF, -INF, or NaN.
33  *	only sinh(0)=0 is exact for finite x.
34  */
35 
36 #include "math.h"
37 #include "math_private.h"
38 
39 #ifdef __STDC__
40 static const double one = 1.0, shuge = 1.0e307;
41 #else
42 static double one = 1.0, shuge = 1.0e307;
43 #endif
44 
45 #ifdef __STDC__
46 	double __ieee754_sinh(double x)
47 #else
48 	double __ieee754_sinh(x)
49 	double x;
50 #endif
51 {
52 	double t,w,h;
53 	int32_t ix,jx;
54 	u_int32_t lx;
55 
56     /* High word of |x|. */
57 	GET_HIGH_WORD(jx,x);
58 	ix = jx&0x7fffffff;
59 
60     /* x is INF or NaN */
61 	if(ix>=0x7ff00000) return x+x;
62 
63 	h = 0.5;
64 	if (jx<0) h = -h;
65     /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
66 	if (ix < 0x40360000) {		/* |x|<22 */
67 	    if (ix<0x3e300000) 		/* |x|<2**-28 */
68 		if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */
69 	    t = expm1(fabs(x));
70 	    if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one));
71 	    return h*(t+t/(t+one));
72 	}
73 
74     /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
75 	if (ix < 0x40862E42)  return h*__ieee754_exp(fabs(x));
76 
77     /* |x| in [log(maxdouble), overflowthresold] */
78 	GET_LOW_WORD(lx,x);
79 	if (ix<0x408633CE || ((ix==0x408633ce)&&(lx<=(u_int32_t)0x8fb9f87d))) {
80 	    w = __ieee754_exp(0.5*fabs(x));
81 	    t = h*w;
82 	    return t*w;
83 	}
84 
85     /* |x| > overflowthresold, sinh(x) overflow */
86 	return x*shuge;
87 }
88