2.9
[glibc/nacl-glibc.git] / sysdeps / ieee754 / ldbl-128ibm / e_sinhl.c
blob38ae71d4b793f299c95cb13c782d30ae5b08eb34
1 /*
2 * ====================================================
3 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5 * Developed at SunPro, a Sun Microsystems, Inc. business.
6 * Permission to use, copy, modify, and distribute this
7 * software is freely granted, provided that this notice
8 * is preserved.
9 * ====================================================
13 #if defined(LIBM_SCCS) && !defined(lint)
14 static char rcsid[] = "$NetBSD: e_sinh.c,v 1.7 1995/05/10 20:46:13 jtc Exp $";
15 #endif
17 /* __ieee754_sinh(x)
18 * Method :
19 * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
20 * 1. Replace x by |x| (sinh(-x) = -sinh(x)).
21 * 2.
22 * E + E/(E+1)
23 * 0 <= x <= 22 : sinh(x) := --------------, E=expm1(x)
24 * 2
26 * 22 <= x <= lnovft : sinh(x) := exp(x)/2
27 * lnovft <= x <= ln2ovft: sinh(x) := exp(x/2)/2 * exp(x/2)
28 * ln2ovft < x : sinh(x) := x*shuge (overflow)
30 * Special cases:
31 * sinh(x) is |x| if x is +INF, -INF, or NaN.
32 * only sinh(0)=0 is exact for finite x.
35 #include "math.h"
36 #include "math_private.h"
38 #ifdef __STDC__
39 static const long double one = 1.0, shuge = 1.0e307;
40 #else
41 static long double one = 1.0, shuge = 1.0e307;
42 #endif
44 #ifdef __STDC__
45 long double __ieee754_sinhl(long double x)
46 #else
47 long double __ieee754_sinhl(x)
48 long double x;
49 #endif
51 long double t,w,h;
52 int64_t ix,jx;
54 /* High word of |x|. */
55 GET_LDOUBLE_MSW64(jx,x);
56 ix = jx&0x7fffffffffffffffLL;
58 /* x is INF or NaN */
59 if(ix>=0x7ff0000000000000LL) return x+x;
61 h = 0.5;
62 if (jx<0) h = -h;
63 /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
64 if (ix < 0x4036000000000000LL) { /* |x|<22 */
65 if (ix<0x3e20000000000000LL) /* |x|<2**-29 */
66 if(shuge+x>one) return x;/* sinhl(tiny) = tiny with inexact */
67 t = __expm1l(fabsl(x));
68 if(ix<0x3ff0000000000000LL) return h*(2.0*t-t*t/(t+one));
69 return h*(t+t/(t+one));
72 /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
73 if (ix < 0x40862e42fefa39efLL) return h*__ieee754_expl(fabsl(x));
75 /* |x| in [log(maxdouble), overflowthresold] */
76 if (ix <= 0x408633ce8fb9f87dLL) {
77 w = __ieee754_expl(0.5*fabsl(x));
78 t = h*w;
79 return t*w;
82 /* |x| > overflowthresold, sinh(x) overflow */
83 return x*shuge;