Skip to content

Commit e0b19ed

Browse files
committed
add tests
1 parent 23539a7 commit e0b19ed

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/bessely.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ function bessely_positive_args(nu, x::T) where T
317317

318318
# at this point x > 19.0 (for Float64) and fairly close to nu
319319
# shift nu down and use the debye expansion for Hankel function (valid x > nu) then use forward recurrence
320-
nu_shift = floor(nu) - ceil(Int, -1.5 + x + Base.Math._approx_cbrt(-411*x))
320+
nu_shift = ceil(nu) - floor(Int, -1.5 + x + Base.Math._approx_cbrt(-411*x)) + 4
321321
v2 = nu - maximum((nu_shift, modf(nu)[1] + 1))
322322
return besselj_up_recurrence(x, imag(hankel_debye(v2, x)), imag(hankel_debye(v2 - 1, x)), v2, nu)[1]
323323
end

src/sphericalbessel.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ end
6767
# if (x<nu) we can use forward recurrence from sphericalbesselj_recurrence and
6868
# then use a continued fraction approach. However, for largish orders (>60) the
6969
# continued fraction is slower converging and more efficient to use other methods
70-
function sphericalbesselj_recurrence(nu::Integer, x)
70+
function sphericalbesselj_recurrence(nu::Integer, x::T) where T
7171
if x >= nu
7272
# forward recurrence if stable
7373
xinv = inv(x)

test/sphericalbessel_test.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# test very small inputs
2+
x = 1e-15
3+
@test Bessels.sphericalbesselj(0, x) SpecialFunctions.sphericalbesselj(0, x)
4+
@test Bessels.sphericalbesselj(1, x) SpecialFunctions.sphericalbesselj(1, x)
5+
@test Bessels.sphericalbesselj(5.5, x) SpecialFunctions.sphericalbesselj(5.5, x)
6+
@test Bessels.sphericalbesselj(10, x) SpecialFunctions.sphericalbesselj(10, x)
7+
@test Bessels.sphericalbessely(0, x) SpecialFunctions.sphericalbessely(0, x)
8+
@test Bessels.sphericalbessely(1, x) SpecialFunctions.sphericalbessely(1, x)
9+
@test Bessels.sphericalbessely(5.5, x) SpecialFunctions.sphericalbessely(5.5, x)
10+
@test Bessels.sphericalbessely(10, x) SpecialFunctions.sphericalbessely(10, x)
11+
12+
for x in 0.5:1.0:100.0, v in [0, 1, 5.5, 10]
13+
@test isapprox(Bessels.sphericalbesselj(v, x), SpecialFunctions.sphericalbesselj(v, x), rtol=1e-12)
14+
@test isapprox(Bessels.sphericalbessely(v, x), SpecialFunctions.sphericalbessely(v, x), rtol=1e-12)
15+
end
16+
17+
for x in 5.5:4.0:160.0, v in [20, 25.0, 32.4, 40.0, 45.12, 50.0, 55.2, 60.124, 70.23, 75.0, 80.0, 92.3, 100.0, 120.0]
18+
@test isapprox(Bessels.sphericalbesselj(v, x), SpecialFunctions.sphericalbesselj(v, x), rtol=3e-12)
19+
@test isapprox(Bessels.sphericalbessely(v, x), SpecialFunctions.sphericalbessely(v, x), rtol=3e-12)
20+
end

0 commit comments

Comments
 (0)