Skip to content

Commit 392c8c6

Browse files
committed
add tests for hankel
1 parent 90731ea commit 392c8c6

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

src/Bessels.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,23 @@ export besselk0x
2222
export besselk1
2323
export besselk1x
2424

25+
export besselh
26+
export hankelh1
27+
export hankelh2
28+
2529
include("besseli.jl")
2630
include("besselj.jl")
2731
include("besselk.jl")
2832
include("bessely.jl")
29-
include("constants.jl")
33+
include("hankel.jl")
3034

3135
include("Float128/besseli.jl")
3236
include("Float128/besselj.jl")
3337
include("Float128/besselk.jl")
3438
include("Float128/bessely.jl")
3539
include("Float128/constants.jl")
3640

41+
include("constants.jl")
3742
include("math_constants.jl")
3843
include("U_polynomials.jl")
3944
include("recurrence.jl")
@@ -42,6 +47,4 @@ include("Polynomials/besselj_polys.jl")
4247
include("asymptotics.jl")
4348
include("gamma.jl")
4449

45-
include("hankel.jl")
46-
4750
end

src/hankel.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function besseljy_positive_args(nu::Real, x::T) where T
9797

9898
Hnu = hankel_debye(v2, x)
9999
Hnum1 = hankel_debye(v2 - 1, x)
100-
100+
101101
# forward recurrence is stable for Hankel when x >= nu
102102
if x >= nu
103103
H = besselj_up_recurrence(x, Hnu, Hnum1, v2, nu)[1]
@@ -133,7 +133,7 @@ function besselj_ratio_jnu_jnum1(n, x::T) where T
133133
return h
134134
end
135135

136-
function besselh(nu::Float64, k::Integer, x::AbstractFloat)
136+
function besselh(nu::Real, k::Integer, x)
137137
Jn, Yn = besseljy(nu, x)
138138
if k == 1
139139
return complex(Jn, Yn)
@@ -144,5 +144,5 @@ function besselh(nu::Float64, k::Integer, x::AbstractFloat)
144144
end
145145
end
146146

147-
hankelh1(nu, z) = besselh(nu, 1, z)
148-
hankelh2(nu, z) = besselh(nu, 2, z)
147+
hankelh1(nu, x) = besselh(nu, 1, x)
148+
hankelh2(nu, x) = besselh(nu, 2, x)

test/hankel_test.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# most of the tests are contained in bessely_test and besselj_test which test the besseljy function
2+
# which is called by hankelh1 and besselh
3+
# here we will test just a few cases of the overal hankel function
4+
# focusing on negative arguments and reflection
5+
6+
v, x = 1.5, 1.3
7+
@test isapprox(hankelh1(v, x), SpecialFunctions.hankelh1(v, x), rtol=2e-13)
8+
@test isapprox(hankelh2(v, x), SpecialFunctions.hankelh2(v, x), rtol=2e-13)
9+
@test isapprox(besselh(v, 1, x), SpecialFunctions.besselh(v, 1, x), rtol=2e-13)
10+
@test isapprox(besselh(v, 2, x), SpecialFunctions.besselh(v, 2, x), rtol=2e-13)
11+
12+
v, x = -2.6, 9.2
13+
@test isapprox(hankelh1(v, x), SpecialFunctions.hankelh1(v, x), rtol=2e-13)
14+
@test isapprox(hankelh2(v, x), SpecialFunctions.hankelh2(v, x), rtol=2e-13)
15+
@test isapprox(besselh(v, 1, x), SpecialFunctions.besselh(v, 1, x), rtol=2e-13)
16+
@test isapprox(besselh(v, 2, x), SpecialFunctions.besselh(v, 2, x), rtol=2e-13)
17+
18+
v, x = -4.0, 11.4
19+
@test isapprox(hankelh1(v, x), SpecialFunctions.hankelh1(v, x), rtol=2e-13)
20+
@test isapprox(hankelh2(v, x), SpecialFunctions.hankelh2(v, x), rtol=2e-13)
21+
@test isapprox(besselh(v, 1, x), SpecialFunctions.besselh(v, 1, x), rtol=2e-13)
22+
@test isapprox(besselh(v, 2, x), SpecialFunctions.besselh(v, 2, x), rtol=2e-13)
23+
24+
v, x = 14.3, 29.4
25+
@test isapprox(hankelh1(v, x), SpecialFunctions.hankelh1(v, x), rtol=2e-13)
26+
@test isapprox(hankelh2(v, x), SpecialFunctions.hankelh2(v, x), rtol=2e-13)
27+
@test isapprox(besselh(v, 1, x), SpecialFunctions.besselh(v, 1, x), rtol=2e-13)
28+
@test isapprox(besselh(v, 2, x), SpecialFunctions.besselh(v, 2, x), rtol=2e-13)

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ import SpecialFunctions
66
@time @testset "besselk" begin include("besselk_test.jl") end
77
@time @testset "besselj" begin include("besselj_test.jl") end
88
@time @testset "bessely" begin include("bessely_test.jl") end
9+
@time @testset "hankel" begin include("hankel_test.jl") end
910
@time @testset "gamma" begin include("gamma_test.jl") end

0 commit comments

Comments
 (0)