]>
Commit | Line | Data |
---|---|---|
f7eac6eb RM |
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 | |
0ac5ae23 | 8 | * software is freely granted, provided that this notice |
f7eac6eb RM |
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) | |
0ac5ae23 | 18 | * Method : |
f7eac6eb | 19 | * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2 |
0ac5ae23 UD |
20 | * 1. Replace x by |x| (sinh(-x) = -sinh(x)). |
21 | * 2. | |
22 | * E + E/(E+1) | |
f7eac6eb | 23 | * 0 <= x <= 22 : sinh(x) := --------------, E=expm1(x) |
0ac5ae23 | 24 | * 2 |
f7eac6eb | 25 | * |
0ac5ae23 | 26 | * 22 <= x <= lnovft : sinh(x) := exp(x)/2 |
f7eac6eb RM |
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 | ||
1ed0291c RH |
35 | #include <math.h> |
36 | #include <math_private.h> | |
f7eac6eb | 37 | |
f7eac6eb | 38 | static const double one = 1.0, shuge = 1.0e307; |
f7eac6eb | 39 | |
0ac5ae23 | 40 | double |
c5d5d574 | 41 | __ieee754_sinh (double x) |
0ac5ae23 | 42 | { |
c5d5d574 OB |
43 | double t, w, h; |
44 | int32_t ix, jx; | |
45 | u_int32_t lx; | |
f7eac6eb | 46 | |
c5d5d574 OB |
47 | /* High word of |x|. */ |
48 | GET_HIGH_WORD (jx, x); | |
49 | ix = jx & 0x7fffffff; | |
f7eac6eb | 50 | |
c5d5d574 | 51 | /* x is INF or NaN */ |
a1ffb40e | 52 | if (__glibc_unlikely (ix >= 0x7ff00000)) |
c5d5d574 | 53 | return x + x; |
f7eac6eb | 54 | |
c5d5d574 OB |
55 | h = 0.5; |
56 | if (jx < 0) | |
57 | h = -h; | |
58 | /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */ | |
59 | if (ix < 0x40360000) /* |x|<22 */ | |
60 | { | |
a1ffb40e | 61 | if (__glibc_unlikely (ix < 0x3e300000)) /* |x|<2**-28 */ |
c5d5d574 OB |
62 | if (shuge + x > one) |
63 | return x; | |
64 | /* sinh(tiny) = tiny with inexact */ | |
65 | t = __expm1 (fabs (x)); | |
66 | if (ix < 0x3ff00000) | |
67 | return h * (2.0 * t - t * t / (t + one)); | |
68 | return h * (t + t / (t + one)); | |
69 | } | |
f7eac6eb | 70 | |
c5d5d574 OB |
71 | /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */ |
72 | if (ix < 0x40862e42) | |
73 | return h * __ieee754_exp (fabs (x)); | |
f7eac6eb | 74 | |
c5d5d574 OB |
75 | /* |x| in [log(maxdouble), overflowthresold] */ |
76 | GET_LOW_WORD (lx, x); | |
77 | if (ix < 0x408633ce || ((ix == 0x408633ce) && (lx <= (u_int32_t) 0x8fb9f87d))) | |
78 | { | |
79 | w = __ieee754_exp (0.5 * fabs (x)); | |
80 | t = h * w; | |
81 | return t * w; | |
82 | } | |
f7eac6eb | 83 | |
c5d5d574 OB |
84 | /* |x| > overflowthresold, sinh(x) overflow */ |
85 | return x * shuge; | |
f7eac6eb | 86 | } |
0ac5ae23 | 87 | strong_alias (__ieee754_sinh, __sinh_finite) |