/src/moddable/xs/tools/fdlibm/e_sinh.c
Line | Count | Source |
1 | | |
2 | | /* |
3 | | * ==================================================== |
4 | | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
5 | | * |
6 | | * Developed at SunSoft, 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 | | /* sinh(x) |
14 | | * Method : |
15 | | * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2 |
16 | | * 1. Replace x by |x| (sinh(-x) = -sinh(x)). |
17 | | * 2. |
18 | | * E + E/(E+1) |
19 | | * 0 <= x <= 22 : sinh(x) := --------------, E=expm1(x) |
20 | | * 2 |
21 | | * |
22 | | * 22 <= x <= lnovft : sinh(x) := exp(x)/2 |
23 | | * lnovft <= x <= ln2ovft: sinh(x) := exp(x/2)/2 * exp(x/2) |
24 | | * ln2ovft < x : sinh(x) := x*shuge (overflow) |
25 | | * |
26 | | * Special cases: |
27 | | * sinh(x) is |x| if x is +INF, -INF, or NaN. |
28 | | * only sinh(0)=0 is exact for finite x. |
29 | | */ |
30 | | |
31 | | #include "math_private.h" |
32 | | |
33 | | static const double one = 1.0, shuge = 1.0e307; |
34 | | |
35 | | double |
36 | | __ieee754_sinh(double x) |
37 | 276k | { |
38 | 276k | double t,h; |
39 | 276k | int32_t ix,jx; |
40 | | |
41 | | /* High word of |x|. */ |
42 | 276k | GET_HIGH_WORD(jx,x); |
43 | 276k | ix = jx&0x7fffffff; |
44 | | |
45 | | /* x is INF or NaN */ |
46 | 276k | if(ix>=0x7ff00000) return x+x; |
47 | | |
48 | 272k | h = 0.5; |
49 | 272k | if (jx<0) h = -h; |
50 | | /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */ |
51 | 272k | if (ix < 0x40360000) { /* |x|<22 */ |
52 | 271k | if (ix<0x3e300000) /* |x|<2**-28 */ |
53 | 84.7k | if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */ |
54 | 186k | t = s_expm1(fabs(x)); |
55 | 186k | if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one)); |
56 | 526 | return h*(t+t/(t+one)); |
57 | 186k | } |
58 | | |
59 | | /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */ |
60 | 1.43k | if (ix < 0x40862E42) return h*__ieee754_exp(fabs(x)); |
61 | | |
62 | | /* |x| in [log(maxdouble), overflowthresold] */ |
63 | 290 | if (ix<=0x408633CE) |
64 | 0 | return h*2.0*__ldexp_exp(fabs(x), -1); |
65 | | |
66 | | /* |x| > overflowthresold, sinh(x) overflow */ |
67 | 290 | return x*shuge; |
68 | 290 | } |