@@ -225,12 +225,15 @@ function besselk_positive_args(nu, x::T) where T <: Union{Float32, Float64}
225
225
226
226
# dispatch to avoid uniform expansion when nu = 0
227
227
iszero (nu) && return besselk0 (x)
228
+
229
+ # pre-compute the uniform asymptotic expansion cutoff:
230
+ debye_cut = besselik_debye_cutoff (nu, x)
228
231
229
232
# check if nu is a half-integer:
230
- besselk_vhalfint_check (nu, x ) && return besselk_vhalfint (nu, x)
233
+ ( isinteger (nu - 1 / 2 ) && ! debye_cut ) && return sphericalbesselk_int (nu- 1 / 2 , x) * SQRT_PID2 (T) * sqrt ( x)
231
234
232
235
# use uniform debye expansion if x or nu is large
233
- besselik_debye_cutoff (nu, x) && return besselk_large_orders (nu, x)
236
+ debye_cut && return besselk_large_orders (nu, x)
234
237
235
238
# for integer nu use forward recurrence starting with K_0 and K_1
236
239
isinteger (nu) && return besselk_up_recurrence (x, besselk1 (x), besselk0 (x), 1 , nu)[1 ]
428
431
besselk_power_series_cutoff (nu, x:: Float64 ) = x < 2.0 || nu > 1.6 x - 1.0
429
432
besselk_power_series_cutoff (nu, x:: Float32 ) = x < 10.0f0 || nu > 1.65f0 * x - 8.0f0
430
433
431
-
432
- """
433
- besselk_vhalfint(nu, x::T) where T <: {Float32, Float64}
434
-
435
- Computes `K_{ν}(x)` when `v + 1/2` is an integer using the fact that the
436
- asymptotic expansion actually terminates and is exact for those specific `v` values.
437
- """
438
- function besselk_vhalfint (v, x:: T ) where T
439
- v = abs (v)
440
- invx = inv (x)
441
- b0 = b1 = SQRT_PID2 (T)* sqrt (invx)* exp (- x)
442
- twodx = 2 * invx
443
- _v = T (1 / 2 )
444
- while _v < v
445
- b0, b1 = b1, muladd (b1, twodx* _v, b0)
446
- _v += one (T)
447
- end
448
- b1
449
- end
450
- besselk_vhalfint_check (nu, x) = isinteger (nu- 1 / 2 ) && (nu < 41.5 ) # @inline?
451
-
0 commit comments