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 | #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 |
16 | |
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 |
25 | * |
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) |
29 | * |
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. |
33 | */ |
34 | |
35 | #include <float.h> |
36 | #include <math.h> |
37 | #include <math-narrow-eval.h> |
38 | #include <math_private.h> |
39 | #include <math-underflow.h> |
40 | |
41 | static const double one = 1.0, shuge = 1.0e307; |
42 | |
43 | double |
44 | __ieee754_sinh (double x) |
45 | { |
46 | double t, w, h; |
47 | int32_t ix, jx; |
48 | uint32_t lx; |
49 | |
50 | /* High word of |x|. */ |
51 | GET_HIGH_WORD (jx, x); |
52 | ix = jx & 0x7fffffff; |
53 | |
54 | /* x is INF or NaN */ |
55 | if (__glibc_unlikely (ix >= 0x7ff00000)) |
56 | return x + x; |
57 | |
58 | h = 0.5; |
59 | if (jx < 0) |
60 | h = -h; |
61 | /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */ |
62 | if (ix < 0x40360000) /* |x|<22 */ |
63 | { |
64 | if (__glibc_unlikely (ix < 0x3e300000)) { /* |x|<2**-28 */ |
65 | math_check_force_underflow (x); |
66 | if (shuge + x > one) |
67 | return x; |
68 | /* sinh(tiny) = tiny with inexact */ |
69 | } |
70 | t = __expm1 (fabs (x)); |
71 | if (ix < 0x3ff00000) |
72 | return h * (2.0 * t - t * t / (t + one)); |
73 | return h * (t + t / (t + one)); |
74 | } |
75 | |
76 | /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */ |
77 | if (ix < 0x40862e42) |
78 | return h * __ieee754_exp (fabs (x)); |
79 | |
80 | /* |x| in [log(maxdouble), overflowthresold] */ |
81 | GET_LOW_WORD (lx, x); |
82 | if (ix < 0x408633ce || ((ix == 0x408633ce) && (lx <= (uint32_t) 0x8fb9f87d))) |
83 | { |
84 | w = __ieee754_exp (0.5 * fabs (x)); |
85 | t = h * w; |
86 | return t * w; |
87 | } |
88 | |
89 | /* |x| > overflowthresold, sinh(x) overflow */ |
90 | return math_narrow_eval (x * shuge); |
91 | } |
92 | strong_alias (__ieee754_sinh, __sinh_finite) |
93 | |