xref: /dflybsd-src/contrib/openbsd_libm/src/e_sinhf.c (revision 4382f29d99a100bd77a81697c2f699c11f6a472a)
1*05a0b428SJohn Marino /* e_sinhf.c -- float version of e_sinh.c.
2*05a0b428SJohn Marino  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3*05a0b428SJohn Marino  */
4*05a0b428SJohn Marino 
5*05a0b428SJohn Marino /*
6*05a0b428SJohn Marino  * ====================================================
7*05a0b428SJohn Marino  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8*05a0b428SJohn Marino  *
9*05a0b428SJohn Marino  * Developed at SunPro, a Sun Microsystems, Inc. business.
10*05a0b428SJohn Marino  * Permission to use, copy, modify, and distribute this
11*05a0b428SJohn Marino  * software is freely granted, provided that this notice
12*05a0b428SJohn Marino  * is preserved.
13*05a0b428SJohn Marino  * ====================================================
14*05a0b428SJohn Marino  */
15*05a0b428SJohn Marino 
16*05a0b428SJohn Marino #include "math.h"
17*05a0b428SJohn Marino #include "math_private.h"
18*05a0b428SJohn Marino 
19*05a0b428SJohn Marino static const float one = 1.0, shuge = 1.0e37;
20*05a0b428SJohn Marino 
21*05a0b428SJohn Marino float
sinhf(float x)22*05a0b428SJohn Marino sinhf(float x)
23*05a0b428SJohn Marino {
24*05a0b428SJohn Marino 	float t,w,h;
25*05a0b428SJohn Marino 	int32_t ix,jx;
26*05a0b428SJohn Marino 
27*05a0b428SJohn Marino 	GET_FLOAT_WORD(jx,x);
28*05a0b428SJohn Marino 	ix = jx&0x7fffffff;
29*05a0b428SJohn Marino 
30*05a0b428SJohn Marino     /* x is INF or NaN */
31*05a0b428SJohn Marino 	if(ix>=0x7f800000) return x+x;
32*05a0b428SJohn Marino 
33*05a0b428SJohn Marino 	h = 0.5;
34*05a0b428SJohn Marino 	if (jx<0) h = -h;
35*05a0b428SJohn Marino     /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
36*05a0b428SJohn Marino 	if (ix < 0x41b00000) {		/* |x|<22 */
37*05a0b428SJohn Marino 	    if (ix<0x31800000) 		/* |x|<2**-28 */
38*05a0b428SJohn Marino 		if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */
39*05a0b428SJohn Marino 	    t = expm1f(fabsf(x));
40*05a0b428SJohn Marino 	    if(ix<0x3f800000) return h*((float)2.0*t-t*t/(t+one));
41*05a0b428SJohn Marino 	    return h*(t+t/(t+one));
42*05a0b428SJohn Marino 	}
43*05a0b428SJohn Marino 
44*05a0b428SJohn Marino     /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
45*05a0b428SJohn Marino 	if (ix < 0x42b17180)  return h*expf(fabsf(x));
46*05a0b428SJohn Marino 
47*05a0b428SJohn Marino     /* |x| in [log(maxdouble), overflowthresold] */
48*05a0b428SJohn Marino 	if (ix<=0x42b2d4fc) {
49*05a0b428SJohn Marino 	    w = expf((float)0.5*fabsf(x));
50*05a0b428SJohn Marino 	    t = h*w;
51*05a0b428SJohn Marino 	    return t*w;
52*05a0b428SJohn Marino 	}
53*05a0b428SJohn Marino 
54*05a0b428SJohn Marino     /* |x| > overflowthresold, sinh(x) overflow */
55*05a0b428SJohn Marino 	return x*shuge;
56*05a0b428SJohn Marino }
57