1*2fe8fb19SBen Gras /* @(#)e_sinh.c 5.1 93/09/24 */
2*2fe8fb19SBen Gras /*
3*2fe8fb19SBen Gras * ====================================================
4*2fe8fb19SBen Gras * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5*2fe8fb19SBen Gras *
6*2fe8fb19SBen Gras * Developed at SunPro, a Sun Microsystems, Inc. business.
7*2fe8fb19SBen Gras * Permission to use, copy, modify, and distribute this
8*2fe8fb19SBen Gras * software is freely granted, provided that this notice
9*2fe8fb19SBen Gras * is preserved.
10*2fe8fb19SBen Gras * ====================================================
11*2fe8fb19SBen Gras */
12*2fe8fb19SBen Gras
13*2fe8fb19SBen Gras #include <sys/cdefs.h>
14*2fe8fb19SBen Gras #if defined(LIBM_SCCS) && !defined(lint)
15*2fe8fb19SBen Gras __RCSID("$NetBSD: e_sinh.c,v 1.11 2002/05/26 22:01:52 wiz Exp $");
16*2fe8fb19SBen Gras #endif
17*2fe8fb19SBen Gras
18*2fe8fb19SBen Gras /* __ieee754_sinh(x)
19*2fe8fb19SBen Gras * Method :
20*2fe8fb19SBen Gras * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
21*2fe8fb19SBen Gras * 1. Replace x by |x| (sinh(-x) = -sinh(x)).
22*2fe8fb19SBen Gras * 2.
23*2fe8fb19SBen Gras * E + E/(E+1)
24*2fe8fb19SBen Gras * 0 <= x <= 22 : sinh(x) := --------------, E=expm1(x)
25*2fe8fb19SBen Gras * 2
26*2fe8fb19SBen Gras *
27*2fe8fb19SBen Gras * 22 <= x <= lnovft : sinh(x) := exp(x)/2
28*2fe8fb19SBen Gras * lnovft <= x <= ln2ovft: sinh(x) := exp(x/2)/2 * exp(x/2)
29*2fe8fb19SBen Gras * ln2ovft < x : sinh(x) := x*shuge (overflow)
30*2fe8fb19SBen Gras *
31*2fe8fb19SBen Gras * Special cases:
32*2fe8fb19SBen Gras * sinh(x) is |x| if x is +INF, -INF, or NaN.
33*2fe8fb19SBen Gras * only sinh(0)=0 is exact for finite x.
34*2fe8fb19SBen Gras */
35*2fe8fb19SBen Gras
36*2fe8fb19SBen Gras #include "math.h"
37*2fe8fb19SBen Gras #include "math_private.h"
38*2fe8fb19SBen Gras
39*2fe8fb19SBen Gras static const double one = 1.0, shuge = 1.0e307;
40*2fe8fb19SBen Gras
41*2fe8fb19SBen Gras double
__ieee754_sinh(double x)42*2fe8fb19SBen Gras __ieee754_sinh(double x)
43*2fe8fb19SBen Gras {
44*2fe8fb19SBen Gras double t,w,h;
45*2fe8fb19SBen Gras int32_t ix,jx;
46*2fe8fb19SBen Gras u_int32_t lx;
47*2fe8fb19SBen Gras
48*2fe8fb19SBen Gras /* High word of |x|. */
49*2fe8fb19SBen Gras GET_HIGH_WORD(jx,x);
50*2fe8fb19SBen Gras ix = jx&0x7fffffff;
51*2fe8fb19SBen Gras
52*2fe8fb19SBen Gras /* x is INF or NaN */
53*2fe8fb19SBen Gras if(ix>=0x7ff00000) return x+x;
54*2fe8fb19SBen Gras
55*2fe8fb19SBen Gras h = 0.5;
56*2fe8fb19SBen Gras if (jx<0) h = -h;
57*2fe8fb19SBen Gras /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
58*2fe8fb19SBen Gras if (ix < 0x40360000) { /* |x|<22 */
59*2fe8fb19SBen Gras if (ix<0x3e300000) /* |x|<2**-28 */
60*2fe8fb19SBen Gras if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */
61*2fe8fb19SBen Gras t = expm1(fabs(x));
62*2fe8fb19SBen Gras if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one));
63*2fe8fb19SBen Gras return h*(t+t/(t+one));
64*2fe8fb19SBen Gras }
65*2fe8fb19SBen Gras
66*2fe8fb19SBen Gras /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
67*2fe8fb19SBen Gras if (ix < 0x40862E42) return h*__ieee754_exp(fabs(x));
68*2fe8fb19SBen Gras
69*2fe8fb19SBen Gras /* |x| in [log(maxdouble), overflowthresold] */
70*2fe8fb19SBen Gras GET_LOW_WORD(lx,x);
71*2fe8fb19SBen Gras if (ix<0x408633CE || ((ix==0x408633ce)&&(lx<=(u_int32_t)0x8fb9f87d))) {
72*2fe8fb19SBen Gras w = __ieee754_exp(0.5*fabs(x));
73*2fe8fb19SBen Gras t = h*w;
74*2fe8fb19SBen Gras return t*w;
75*2fe8fb19SBen Gras }
76*2fe8fb19SBen Gras
77*2fe8fb19SBen Gras /* |x| > overflowthresold, sinh(x) overflow */
78*2fe8fb19SBen Gras return x*shuge;
79*2fe8fb19SBen Gras }
80