@@ -139,8 +139,27 @@ function _bessely1_compute(x::Float64)
139
139
p = p * sc[1 ] + w * q * sc[2 ]
140
140
return p * SQ2OPI (T) / sqrt (x)
141
141
else
142
-
143
- return besseljy_large_argument (1.0 , x)[2 ]
142
+ xinv = inv (x)
143
+ x2 = xinv* xinv
144
+ if x < 130.0
145
+ p1 = (one (T), 3 / 16 , - 99 / 512 , 6597 / 8192 , - 4057965 / 524288 , 1113686901 / 8388608 , - 951148335159 / 268435456 , 581513783771781 / 4294967296 )
146
+ q1 = (3 / 8 , - 21 / 128 , 1899 / 5120 , - 543483 / 229376 , 8027901 / 262144 , - 30413055339 / 46137344 , 9228545313147 / 436207616 )
147
+ p = evalpoly (x2, p1)
148
+ q = evalpoly (x2, q1)
149
+ else
150
+ p2 = (one (T), 3 / 16 , - 99 / 512 , 6597 / 8192 )
151
+ q2 = (3 / 8 , - 21 / 128 , 1899 / 5120 , - 543483 / 229376 )
152
+ p = evalpoly (x2, p2)
153
+ q = evalpoly (x2, q2)
154
+ end
155
+
156
+ a = SQ2OPI (T) * sqrt (xinv) * p
157
+ xn = muladd (xinv, q, - 3 * PIO4 (T))
158
+
159
+ # the following computes b = sin(x + xn) more accurately
160
+ # see src/misc.jl
161
+ b = sin_sum (x, xn)
162
+ return a * b
144
163
end
145
164
end
146
165
function _bessely1_compute (x:: Float32 )
@@ -172,18 +191,18 @@ function _bessely(nu, x::T) where T
172
191
nu == 0 && return bessely0 (x)
173
192
nu == 1 && return bessely1 (x)
174
193
175
- # large argument branch see src/asymptotics.jl
176
- besseljy_large_argument_cutoff (nu, x) && return besseljy_large_argument (nu, x)[2 ]
177
-
178
194
# x < ~nu branch see src/U_polynomials.jl
179
195
besseljy_debye_cutoff (nu, x) && return besseljy_debye (nu, x)[2 ]
180
196
181
197
# x > ~nu branch see src/U_polynomials.jl on computing Hankel function
182
198
hankel_debye_cutoff (nu, x) && return imag (hankel_debye (nu, x))
183
199
184
- # use forward recurrence if nu is an integer up until it becomes inefficient
200
+ # large argument branch see src/asymptotics.jl
201
+ besseljy_large_argument_cutoff (nu, x) && return besseljy_large_argument (nu, x)[2 ]
202
+
203
+ # use forward recurrence if nu is an integer up until it becomes inefficient
185
204
(isinteger (nu) && nu < 250 ) && return besselj_up_recurrence (x, bessely1 (x), bessely0 (x), 1 , nu)[1 ]
186
-
205
+
187
206
# use power series for small x and for when nu > x
188
207
bessely_series_cutoff (nu, x) && return bessely_power_series (nu, x)
189
208
@@ -192,7 +211,7 @@ function _bessely(nu, x::T) where T
192
211
193
212
# at this point x > 19.0 (for Float64) and fairly close to nu
194
213
# shift nu down and use the debye expansion for Hankel function (valid x > nu) then use forward recurrence
195
- nu_shift = floor (nu) - ceil (Int, - 4.0657 + 0.9976 * x + Base. Math. _approx_cbrt (- 276.915 * x))
214
+ nu_shift = floor (nu) - ceil (Int, - 1.5 + x + Base. Math. _approx_cbrt (- 411 * x))
196
215
v2 = nu - maximum ((nu_shift, modf (nu)[1 ] + 1 ))
197
216
return besselj_up_recurrence (x, imag (hankel_debye (v2, x)), imag (hankel_debye (v2 - 1 , x)), v2, nu)[1 ]
198
217
end
0 commit comments