Rev 4872 | Details | Compare with Previous | 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 | * wrapper jn(int n, double x), yn(int n, double x) |
||
15 | * floating point Bessel's function of the 1st and 2nd kind |
||
16 | * of order n |
||
17 | * |
||
18 | * Special cases: |
||
19 | * y0(0)=y1(0)=yn(n,0) = -inf with division by zero signal; |
||
20 | * y0(-ve)=y1(-ve)=yn(n,-ve) are NaN with invalid signal. |
||
21 | * Note 2. About jn(n,x), yn(n,x) |
||
22 | * For n=0, j0(x) is called, |
||
23 | * for n=1, j1(x) is called, |
||
24 | * for n |
||
25 | * from values of j0(x) and j1(x). |
||
26 | * for n>x, a continued fraction approximation to |
||
27 | * j(n,x)/j(n-1,x) is evaluated and then backward |
||
28 | * recursion is used starting from a supposed value |
||
29 | * for j(n,x). The resulting value of j(0,x) is |
||
30 | * compared with the actual value to correct the |
||
31 | * supposed value of j(n,x). |
||
32 | * |
||
33 | * yn(n,x) is similar in all respects, except |
||
34 | * that forward recursion is used for all |
||
35 | * values of n>1. |
||
36 | * |
||
37 | */ |
||
38 | |||
39 | |||
40 | #include |
||
41 | |||
42 | |||
43 | |||
44 | |||
45 | double jn(int n, double x) /* wrapper jn */ |
||
46 | #else |
||
47 | double jn(n,x) /* wrapper jn */ |
||
48 | double x; int n; |
||
49 | #endif |
||
50 | { |
||
51 | #ifdef _IEEE_LIBM |
||
52 | return __ieee754_jn(n,x); |
||
53 | #else |
||
54 | double z; |
||
55 | struct exception exc; |
||
56 | z = __ieee754_jn(n,x); |
||
57 | if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z; |
||
58 | if(fabs(x)>X_TLOSS) { |
||
59 | /* jn(|x|>X_TLOSS) */ |
||
60 | exc.type = TLOSS; |
||
61 | exc.name = "jn"; |
||
62 | exc.err = 0; |
||
63 | exc.arg1 = n; |
||
64 | exc.arg2 = x; |
||
65 | exc.retval = 0.0; |
||
66 | if (_LIB_VERSION == _POSIX_) |
||
67 | errno = ERANGE; |
||
68 | else if (!matherr(&exc)) { |
||
69 | errno = ERANGE; |
||
70 | } |
||
71 | if (exc.err != 0) |
||
72 | errno = exc.err; |
||
73 | return exc.retval; |
||
74 | } else |
||
75 | return z; |
||
76 | #endif |
||
77 | } |
||
78 | |||
79 | |||
80 | double yn(int n, double x) /* wrapper yn */ |
||
81 | #else |
||
82 | double yn(n,x) /* wrapper yn */ |
||
83 | double x; int n; |
||
84 | #endif |
||
85 | { |
||
86 | #ifdef _IEEE_LIBM |
||
87 | return __ieee754_yn(n,x); |
||
88 | #else |
||
89 | double z; |
||
90 | struct exception exc; |
||
91 | z = __ieee754_yn(n,x); |
||
92 | if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z; |
||
93 | if(x <= 0.0){ |
||
94 | /* yn(n,0) = -inf or yn(x<0) = NaN */ |
||
95 | #ifndef HUGE_VAL |
||
96 | #define HUGE_VAL inf |
||
97 | double inf = 0.0; |
||
98 | |||
99 | |||
100 | #endif |
||
101 | exc.type = DOMAIN; /* should be SING for IEEE */ |
||
102 | exc.name = "yn"; |
||
103 | exc.err = 0; |
||
104 | exc.arg1 = n; |
||
105 | exc.arg2 = x; |
||
106 | if (_LIB_VERSION == _SVID_) |
||
107 | exc.retval = -HUGE; |
||
108 | else |
||
109 | exc.retval = -HUGE_VAL; |
||
110 | if (_LIB_VERSION == _POSIX_) |
||
111 | errno = EDOM; |
||
112 | else if (!matherr(&exc)) { |
||
113 | errno = EDOM; |
||
114 | } |
||
115 | if (exc.err != 0) |
||
116 | errno = exc.err; |
||
117 | return exc.retval; |
||
118 | } |
||
119 | if(x>X_TLOSS) { |
||
120 | /* yn(x>X_TLOSS) */ |
||
121 | exc.type = TLOSS; |
||
122 | exc.name = "yn"; |
||
123 | exc.err = 0; |
||
124 | exc.arg1 = n; |
||
125 | exc.arg2 = x; |
||
126 | exc.retval = 0.0; |
||
127 | if (_LIB_VERSION == _POSIX_) |
||
128 | errno = ERANGE; |
||
129 | else if (!matherr(&exc)) { |
||
130 | errno = ERANGE; |
||
131 | } |
||
132 | if (exc.err != 0) |
||
133 | errno = exc.err; |
||
134 | return exc.retval; |
||
135 | } else |
||
136 | return z; |
||
137 | #endif |
||
138 | } |
||
139 | |||
140 | |||
141 |