1 | |
---|
2 | /* @(#)w_j0.c 5.1 93/09/24 */ |
---|
3 | /* |
---|
4 | * ==================================================== |
---|
5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
---|
6 | * |
---|
7 | * Developed at SunPro, a Sun Microsystems, Inc. business. |
---|
8 | * Permission to use, copy, modify, and distribute this |
---|
9 | * software is freely granted, provided that this notice |
---|
10 | * is preserved. |
---|
11 | * ==================================================== |
---|
12 | */ |
---|
13 | |
---|
14 | /* |
---|
15 | FUNCTION |
---|
16 | <<jN>>, <<jNf>>, <<yN>>, <<yNf>>---Bessel functions |
---|
17 | |
---|
18 | INDEX |
---|
19 | j0 |
---|
20 | INDEX |
---|
21 | j0f |
---|
22 | INDEX |
---|
23 | j1 |
---|
24 | INDEX |
---|
25 | j1f |
---|
26 | INDEX |
---|
27 | jn |
---|
28 | INDEX |
---|
29 | jnf |
---|
30 | INDEX |
---|
31 | y0 |
---|
32 | INDEX |
---|
33 | y0f |
---|
34 | INDEX |
---|
35 | y1 |
---|
36 | INDEX |
---|
37 | y1f |
---|
38 | INDEX |
---|
39 | yn |
---|
40 | INDEX |
---|
41 | ynf |
---|
42 | |
---|
43 | SYNOPSIS |
---|
44 | #include <math.h> |
---|
45 | double j0(double <[x]>); |
---|
46 | float j0f(float <[x]>); |
---|
47 | double j1(double <[x]>); |
---|
48 | float j1f(float <[x]>); |
---|
49 | double jn(int <[n]>, double <[x]>); |
---|
50 | float jnf(int <[n]>, float <[x]>); |
---|
51 | double y0(double <[x]>); |
---|
52 | float y0f(float <[x]>); |
---|
53 | double y1(double <[x]>); |
---|
54 | float y1f(float <[x]>); |
---|
55 | double yn(int <[n]>, double <[x]>); |
---|
56 | float ynf(int <[n]>, float <[x]>); |
---|
57 | |
---|
58 | DESCRIPTION |
---|
59 | The Bessel functions are a family of functions that solve the |
---|
60 | differential equation |
---|
61 | @ifnottex |
---|
62 | . 2 2 2 |
---|
63 | . x y'' + xy' + (x - p )y = 0 |
---|
64 | @end ifnottex |
---|
65 | @tex |
---|
66 | $$x^2{d^2y\over dx^2} + x{dy\over dx} + (x^2-p^2)y = 0$$ |
---|
67 | @end tex |
---|
68 | These functions have many applications in engineering and physics. |
---|
69 | |
---|
70 | <<jn>> calculates the Bessel function of the first kind of order |
---|
71 | <[n]>. <<j0>> and <<j1>> are special cases for order 0 and order |
---|
72 | 1 respectively. |
---|
73 | |
---|
74 | Similarly, <<yn>> calculates the Bessel function of the second kind of |
---|
75 | order <[n]>, and <<y0>> and <<y1>> are special cases for order 0 and |
---|
76 | 1. |
---|
77 | |
---|
78 | <<jnf>>, <<j0f>>, <<j1f>>, <<ynf>>, <<y0f>>, and <<y1f>> perform the |
---|
79 | same calculations, but on <<float>> rather than <<double>> values. |
---|
80 | |
---|
81 | RETURNS |
---|
82 | The value of each Bessel function at <[x]> is returned. |
---|
83 | |
---|
84 | PORTABILITY |
---|
85 | None of the Bessel functions are in ANSI C. |
---|
86 | */ |
---|
87 | |
---|
88 | /* |
---|
89 | * wrapper j0(double x), y0(double x) |
---|
90 | */ |
---|
91 | |
---|
92 | #include "fdlibm.h" |
---|
93 | #include <errno.h> |
---|
94 | |
---|
95 | #ifndef _DOUBLE_IS_32BITS |
---|
96 | |
---|
97 | #ifdef __STDC__ |
---|
98 | double j0(double x) /* wrapper j0 */ |
---|
99 | #else |
---|
100 | double j0(x) /* wrapper j0 */ |
---|
101 | double x; |
---|
102 | #endif |
---|
103 | { |
---|
104 | #ifdef _IEEE_LIBM |
---|
105 | return __ieee754_j0(x); |
---|
106 | #else |
---|
107 | struct exception exc; |
---|
108 | double z = __ieee754_j0(x); |
---|
109 | if(_LIB_VERSION == _IEEE_ || isnan(x)) return z; |
---|
110 | if(fabs(x)>X_TLOSS) { |
---|
111 | /* j0(|x|>X_TLOSS) */ |
---|
112 | exc.type = TLOSS; |
---|
113 | exc.name = "j0"; |
---|
114 | exc.err = 0; |
---|
115 | exc.arg1 = exc.arg2 = x; |
---|
116 | exc.retval = 0.0; |
---|
117 | if (_LIB_VERSION == _POSIX_) |
---|
118 | errno = ERANGE; |
---|
119 | else if (!matherr(&exc)) { |
---|
120 | errno = ERANGE; |
---|
121 | } |
---|
122 | if (exc.err != 0) |
---|
123 | errno = exc.err; |
---|
124 | return exc.retval; |
---|
125 | } else |
---|
126 | return z; |
---|
127 | #endif |
---|
128 | } |
---|
129 | |
---|
130 | #ifdef __STDC__ |
---|
131 | double y0(double x) /* wrapper y0 */ |
---|
132 | #else |
---|
133 | double y0(x) /* wrapper y0 */ |
---|
134 | double x; |
---|
135 | #endif |
---|
136 | { |
---|
137 | #ifdef _IEEE_LIBM |
---|
138 | return __ieee754_y0(x); |
---|
139 | #else |
---|
140 | double z; |
---|
141 | struct exception exc; |
---|
142 | z = __ieee754_y0(x); |
---|
143 | if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z; |
---|
144 | if(x <= 0.0){ |
---|
145 | #ifndef HUGE_VAL |
---|
146 | #define HUGE_VAL inf |
---|
147 | double inf = 0.0; |
---|
148 | |
---|
149 | SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */ |
---|
150 | #endif |
---|
151 | /* y0(0) = -inf or y0(x<0) = NaN */ |
---|
152 | exc.type = DOMAIN; /* should be SING for IEEE y0(0) */ |
---|
153 | exc.name = "y0"; |
---|
154 | exc.err = 0; |
---|
155 | exc.arg1 = exc.arg2 = x; |
---|
156 | if (_LIB_VERSION == _SVID_) |
---|
157 | exc.retval = -HUGE; |
---|
158 | else |
---|
159 | exc.retval = -HUGE_VAL; |
---|
160 | if (_LIB_VERSION == _POSIX_) |
---|
161 | errno = EDOM; |
---|
162 | else if (!matherr(&exc)) { |
---|
163 | errno = EDOM; |
---|
164 | } |
---|
165 | if (exc.err != 0) |
---|
166 | errno = exc.err; |
---|
167 | return exc.retval; |
---|
168 | } |
---|
169 | if(x>X_TLOSS) { |
---|
170 | /* y0(x>X_TLOSS) */ |
---|
171 | exc.type = TLOSS; |
---|
172 | exc.name = "y0"; |
---|
173 | exc.err = 0; |
---|
174 | exc.arg1 = exc.arg2 = x; |
---|
175 | exc.retval = 0.0; |
---|
176 | if (_LIB_VERSION == _POSIX_) |
---|
177 | errno = ERANGE; |
---|
178 | else if (!matherr(&exc)) { |
---|
179 | errno = ERANGE; |
---|
180 | } |
---|
181 | if (exc.err != 0) |
---|
182 | errno = exc.err; |
---|
183 | return exc.retval; |
---|
184 | } else |
---|
185 | return z; |
---|
186 | #endif |
---|
187 | } |
---|
188 | |
---|
189 | #endif /* defined(_DOUBLE_IS_32BITS) */ |
---|
190 | |
---|
191 | |
---|
192 | |
---|
193 | |
---|
194 | |
---|
195 | |
---|
196 | |
---|