libm: Sync with FreeBSD (gains 6 long double functions)
[dragonfly.git] / lib / libm / src / e_sinh.c
CommitLineData
6ff43c94
PA
1
2/* @(#)e_sinh.c 1.3 95/01/18 */
b34b60bc
JS
3/*
4 * ====================================================
5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6 *
6ff43c94 7 * Developed at SunSoft, a Sun Microsystems, Inc. business.
b34b60bc 8 * Permission to use, copy, modify, and distribute this
6ff43c94 9 * software is freely granted, provided that this notice
b34b60bc
JS
10 * is preserved.
11 * ====================================================
b34b60bc
JS
12 */
13
2fedfd5c 14
6ff43c94
PA
15/* __ieee754_sinh(x)
16 * Method :
b34b60bc 17 * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
6ff43c94
PA
18 * 1. Replace x by |x| (sinh(-x) = -sinh(x)).
19 * 2.
b34b60bc
JS
20 * E + E/(E+1)
21 * 0 <= x <= 22 : sinh(x) := --------------, E=expm1(x)
22 * 2
23 *
6ff43c94 24 * 22 <= x <= lnovft : sinh(x) := exp(x)/2
b34b60bc
JS
25 * lnovft <= x <= ln2ovft: sinh(x) := exp(x/2)/2 * exp(x/2)
26 * ln2ovft < x : sinh(x) := x*shuge (overflow)
27 *
28 * Special cases:
29 * sinh(x) is |x| if x is +INF, -INF, or NaN.
30 * only sinh(0)=0 is exact for finite x.
31 */
32
2fedfd5c
JM
33#include <float.h>
34
6ff43c94 35#include "math.h"
b34b60bc
JS
36#include "math_private.h"
37
38static const double one = 1.0, shuge = 1.0e307;
39
40double
6ff43c94 41__ieee754_sinh(double x)
b34b60bc 42{
6ff43c94 43 double t,h;
b34b60bc 44 int32_t ix,jx;
b34b60bc
JS
45
46 /* High word of |x|. */
47 GET_HIGH_WORD(jx,x);
48 ix = jx&0x7fffffff;
49
50 /* x is INF or NaN */
6ff43c94 51 if(ix>=0x7ff00000) return x+x;
b34b60bc
JS
52
53 h = 0.5;
54 if (jx<0) h = -h;
55 /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
56 if (ix < 0x40360000) { /* |x|<22 */
57 if (ix<0x3e300000) /* |x|<2**-28 */
58 if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */
59 t = expm1(fabs(x));
60 if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one));
61 return h*(t+t/(t+one));
62 }
63
64 /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
6ff43c94 65 if (ix < 0x40862E42) return h*__ieee754_exp(fabs(x));
b34b60bc
JS
66
67 /* |x| in [log(maxdouble), overflowthresold] */
6ff43c94
PA
68 if (ix<=0x408633CE)
69 return h*2.0*__ldexp_exp(fabs(x), -1);
b34b60bc
JS
70
71 /* |x| > overflowthresold, sinh(x) overflow */
72 return x*shuge;
73}
2fedfd5c
JM
74
75#if (LDBL_MANT_DIG == 53)
76__weak_reference(sinh, sinhl);
77#endif