Rev 4872 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4349 | Serge | 1 | |
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 | |||
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 | |||
32 | |||
33 | |||
34 | |||
35 | |||
36 | static const double one = 1.0, shuge = 1.0e307; |
||
37 | #else |
||
38 | static double one = 1.0, shuge = 1.0e307; |
||
39 | #endif |
||
40 | |||
41 | |||
42 | double __ieee754_sinh(double x) |
||
43 | #else |
||
44 | double __ieee754_sinh(x) |
||
45 | double x; |
||
46 | #endif |
||
47 | { |
||
48 | double t,w,h; |
||
49 | __int32_t ix,jx; |
||
50 | __uint32_t lx; |
||
51 | |||
52 | |||
53 | GET_HIGH_WORD(jx,x); |
||
54 | ix = jx&0x7fffffff; |
||
55 | |||
56 | |||
57 | if(ix>=0x7ff00000) return x+x; |
||
58 | |||
59 | |||
60 | if (jx<0) h = -h; |
||
61 | /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */ |
||
62 | if (ix < 0x40360000) { /* |x|<22 */ |
||
63 | if (ix<0x3e300000) /* |x|<2**-28 */ |
||
64 | if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */ |
||
65 | t = expm1(fabs(x)); |
||
66 | if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one)); |
||
67 | return h*(t+t/(t+one)); |
||
68 | } |
||
69 | |||
70 | |||
71 | if (ix < 0x40862E42) return h*__ieee754_exp(fabs(x)); |
||
72 | |||
73 | |||
74 | GET_LOW_WORD(lx,x); |
||
75 | if (ix<0x408633CE || (ix==0x408633ce && lx<=(__uint32_t)0x8fb9f87d)) { |
||
76 | w = __ieee754_exp(0.5*fabs(x)); |
||
77 | t = h*w; |
||
78 | return t*w; |
||
79 | } |
||
80 | |||
81 | |||
82 | return x*shuge; |
||
83 | } |
||
84 | |||
85 | |||
86 |