|
Lines 1-4
Link Here
|
| 1 |
|
|
|
| 2 |
/* @(#)e_jn.c 1.4 95/01/18 */ |
1 |
/* @(#)e_jn.c 1.4 95/01/18 */ |
| 3 |
/* |
2 |
/* |
| 4 |
* ==================================================== |
3 |
* ==================================================== |
|
Lines 6-12
Link Here
|
| 6 |
* |
5 |
* |
| 7 |
* Developed at SunSoft, a Sun Microsystems, Inc. business. |
6 |
* Developed at SunSoft, a Sun Microsystems, Inc. business. |
| 8 |
* Permission to use, copy, modify, and distribute this |
7 |
* Permission to use, copy, modify, and distribute this |
| 9 |
* software is freely granted, provided that this notice |
8 |
* software is freely granted, provided that this notice |
| 10 |
* is preserved. |
9 |
* is preserved. |
| 11 |
* ==================================================== |
10 |
* ==================================================== |
| 12 |
*/ |
11 |
*/ |
|
Lines 18-24
Link Here
|
| 18 |
* __ieee754_jn(n, x), __ieee754_yn(n, x) |
17 |
* __ieee754_jn(n, x), __ieee754_yn(n, x) |
| 19 |
* floating point Bessel's function of the 1st and 2nd kind |
18 |
* floating point Bessel's function of the 1st and 2nd kind |
| 20 |
* of order n |
19 |
* of order n |
| 21 |
* |
20 |
* |
| 22 |
* Special cases: |
21 |
* Special cases: |
| 23 |
* y0(0)=y1(0)=yn(n,0) = -inf with division by zero signal; |
22 |
* y0(0)=y1(0)=yn(n,0) = -inf with division by zero signal; |
| 24 |
* y0(-ve)=y1(-ve)=yn(n,-ve) are NaN with invalid signal. |
23 |
* y0(-ve)=y1(-ve)=yn(n,-ve) are NaN with invalid signal. |
|
Lines 37-43
Link Here
|
| 37 |
* yn(n,x) is similar in all respects, except |
36 |
* yn(n,x) is similar in all respects, except |
| 38 |
* that forward recursion is used for all |
37 |
* that forward recursion is used for all |
| 39 |
* values of n>1. |
38 |
* values of n>1. |
| 40 |
* |
|
|
| 41 |
*/ |
39 |
*/ |
| 42 |
|
40 |
|
| 43 |
#include "math.h" |
41 |
#include "math.h" |
|
Lines 66-72
Link Here
|
| 66 |
ix = 0x7fffffff&hx; |
64 |
ix = 0x7fffffff&hx; |
| 67 |
/* if J(n,NaN) is NaN */ |
65 |
/* if J(n,NaN) is NaN */ |
| 68 |
if((ix|((u_int32_t)(lx|-lx))>>31)>0x7ff00000) return x+x; |
66 |
if((ix|((u_int32_t)(lx|-lx))>>31)>0x7ff00000) return x+x; |
| 69 |
if(n<0){ |
67 |
if(n<0){ |
| 70 |
n = -n; |
68 |
n = -n; |
| 71 |
x = -x; |
69 |
x = -x; |
| 72 |
hx ^= 0x80000000; |
70 |
hx ^= 0x80000000; |
|
Lines 77-90
Link Here
|
| 77 |
x = fabs(x); |
75 |
x = fabs(x); |
| 78 |
if((ix|lx)==0||ix>=0x7ff00000) /* if x is 0 or inf */ |
76 |
if((ix|lx)==0||ix>=0x7ff00000) /* if x is 0 or inf */ |
| 79 |
b = zero; |
77 |
b = zero; |
| 80 |
else if((double)n<=x) { |
78 |
else if((double)n<=x) { |
| 81 |
/* Safe to use J(n+1,x)=2n/x *J(n,x)-J(n-1,x) */ |
79 |
/* Safe to use J(n+1,x)=2n/x *J(n,x)-J(n-1,x) */ |
| 82 |
if(ix>=0x52D00000) { /* x > 2**302 */ |
80 |
if(ix>=0x52D00000) { /* x > 2**302 */ |
| 83 |
/* (x >> n**2) |
81 |
/* (x >> n**2) |
| 84 |
* Jn(x) = cos(x-(2n+1)*pi/4)*sqrt(2/x*pi) |
82 |
* Jn(x) = cos(x-(2n+1)*pi/4)*sqrt(2/x*pi) |
| 85 |
* Yn(x) = sin(x-(2n+1)*pi/4)*sqrt(2/x*pi) |
83 |
* Yn(x) = sin(x-(2n+1)*pi/4)*sqrt(2/x*pi) |
| 86 |
* Let s=sin(x), c=cos(x), |
84 |
* Let s=sin(x), c=cos(x), |
| 87 |
* xn=x-(2n+1)*pi/4, sqt2 = sqrt(2),then |
85 |
* xn=x-(2n+1)*pi/4, sqt2 = sqrt(2), then |
| 88 |
* |
86 |
* |
| 89 |
* n sin(xn)*sqt2 cos(xn)*sqt2 |
87 |
* n sin(xn)*sqt2 cos(xn)*sqt2 |
| 90 |
* ---------------------------------- |
88 |
* ---------------------------------- |
|
Lines 100-106
Link Here
|
| 100 |
case 3: temp = cos(x)-sin(x); break; |
98 |
case 3: temp = cos(x)-sin(x); break; |
| 101 |
} |
99 |
} |
| 102 |
b = invsqrtpi*temp/sqrt(x); |
100 |
b = invsqrtpi*temp/sqrt(x); |
| 103 |
} else { |
101 |
} else { |
| 104 |
a = __ieee754_j0(x); |
102 |
a = __ieee754_j0(x); |
| 105 |
b = __ieee754_j1(x); |
103 |
b = __ieee754_j1(x); |
| 106 |
for(i=1;i<n;i++){ |
104 |
for(i=1;i<n;i++){ |
|
Lines 111-117
Link Here
|
| 111 |
} |
109 |
} |
| 112 |
} else { |
110 |
} else { |
| 113 |
if(ix<0x3e100000) { /* x < 2**-29 */ |
111 |
if(ix<0x3e100000) { /* x < 2**-29 */ |
| 114 |
/* x is tiny, return the first Taylor expansion of J(n,x) |
112 |
/* x is tiny, return the first Taylor expansion of J(n,x) |
| 115 |
* J(n,x) = 1/n!*(x/2)^n - ... |
113 |
* J(n,x) = 1/n!*(x/2)^n - ... |
| 116 |
*/ |
114 |
*/ |
| 117 |
if(n>33) /* underflow */ |
115 |
if(n>33) /* underflow */ |
|
Lines 126-139
Link Here
|
| 126 |
} |
124 |
} |
| 127 |
} else { |
125 |
} else { |
| 128 |
/* use backward recurrence */ |
126 |
/* use backward recurrence */ |
| 129 |
/* x x^2 x^2 |
127 |
/* x x^2 x^2 |
| 130 |
* J(n,x)/J(n-1,x) = ---- ------ ------ ..... |
128 |
* J(n,x)/J(n-1,x) = ---- ------ ------ ..... |
| 131 |
* 2n - 2(n+1) - 2(n+2) |
129 |
* 2n - 2(n+1) - 2(n+2) |
| 132 |
* |
130 |
* |
| 133 |
* 1 1 1 |
131 |
* 1 1 1 |
| 134 |
* (for large x) = ---- ------ ------ ..... |
132 |
* (for large x) = ---- ------ ------ ..... |
| 135 |
* 2n 2(n+1) 2(n+2) |
133 |
* 2n 2(n+1) 2(n+2) |
| 136 |
* -- - ------ - ------ - |
134 |
* -- - ------ - ------ - |
| 137 |
* x x x |
135 |
* x x x |
| 138 |
* |
136 |
* |
| 139 |
* Let w = 2n/x and h=2/x, then the above quotient |
137 |
* Let w = 2n/x and h=2/x, then the above quotient |
|
Lines 149-157
Link Here
|
| 149 |
* To determine how many terms needed, let |
147 |
* To determine how many terms needed, let |
| 150 |
* Q(0) = w, Q(1) = w(w+h) - 1, |
148 |
* Q(0) = w, Q(1) = w(w+h) - 1, |
| 151 |
* Q(k) = (w+k*h)*Q(k-1) - Q(k-2), |
149 |
* Q(k) = (w+k*h)*Q(k-1) - Q(k-2), |
| 152 |
* When Q(k) > 1e4 good for single |
150 |
* When Q(k) > 1e4 good for single |
| 153 |
* When Q(k) > 1e9 good for double |
151 |
* When Q(k) > 1e9 good for double |
| 154 |
* When Q(k) > 1e17 good for quadruple |
152 |
* When Q(k) > 1e17 good for quadruple |
| 155 |
*/ |
153 |
*/ |
| 156 |
/* determine k */ |
154 |
/* determine k */ |
| 157 |
double t,v; |
155 |
double t,v; |
|
Lines 237-247
Link Here
|
| 237 |
if(n==1) return(sign*__ieee754_y1(x)); |
235 |
if(n==1) return(sign*__ieee754_y1(x)); |
| 238 |
if(ix==0x7ff00000) return zero; |
236 |
if(ix==0x7ff00000) return zero; |
| 239 |
if(ix>=0x52D00000) { /* x > 2**302 */ |
237 |
if(ix>=0x52D00000) { /* x > 2**302 */ |
| 240 |
/* (x >> n**2) |
238 |
/* (x >> n**2) |
| 241 |
* Jn(x) = cos(x-(2n+1)*pi/4)*sqrt(2/x*pi) |
239 |
* Jn(x) = cos(x-(2n+1)*pi/4)*sqrt(2/x*pi) |
| 242 |
* Yn(x) = sin(x-(2n+1)*pi/4)*sqrt(2/x*pi) |
240 |
* Yn(x) = sin(x-(2n+1)*pi/4)*sqrt(2/x*pi) |
| 243 |
* Let s=sin(x), c=cos(x), |
241 |
* Let s=sin(x), c=cos(x), |
| 244 |
* xn=x-(2n+1)*pi/4, sqt2 = sqrt(2),then |
242 |
* xn=x-(2n+1)*pi/4, sqt2 = sqrt(2), then |
| 245 |
* |
243 |
* |
| 246 |
* n sin(xn)*sqt2 cos(xn)*sqt2 |
244 |
* n sin(xn)*sqt2 cos(xn)*sqt2 |
| 247 |
* ---------------------------------- |
245 |
* ---------------------------------- |