Skip to content

Commit 6a030e3

Browse files
committed
add tests
1 parent c169983 commit 6a030e3

File tree

4 files changed

+32
-22
lines changed

4 files changed

+32
-22
lines changed

src/Bessels.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ export besselh
2626
export hankelh1
2727
export hankelh2
2828

29+
export airyai
30+
export airyaiprime
31+
export airybi
32+
export airybiprime
33+
2934
include("besseli.jl")
3035
include("besselj.jl")
3136
include("besselk.jl")

src/airy.jl

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
"""
22
airyai(x)
33
Airy function of the first kind ``\\operatorname{Ai}(x)``.
4-
External links: [DLMF](https://dlmf.nist.gov/9.2), [Wikipedia](https://en.wikipedia.org/wiki/Airy_function)
5-
See also: [`airyaix`](@ref), [`airyaiprime`](@ref), [`airybi`](@ref)
64
"""
75
function airyai(x::T) where T
86
if x > zero(T)
@@ -15,15 +13,13 @@ function airyai(x::T) where T
1513
Jmv = (Jv - sqrt(T(3)) * Yv) / 2
1614
return sqrt(x_abs) * (Jmv + Jv) / 3
1715
elseif iszero(x)
18-
return inv(3^(T(2)/3) * GAMMA_TWO_THIRDS(T))
16+
return T(0.3550280538878172)
1917
end
2018
end
2119

2220
"""
2321
airyaiprime(x)
2422
Derivative of the Airy function of the first kind ``\\operatorname{Ai}'(x)``.
25-
External links: [DLMF](https://dlmf.nist.gov/9.2), [Wikipedia](https://en.wikipedia.org/wiki/Airy_function)
26-
See also: [`airyaiprimex`](@ref), [`airyai`](@ref), [`airybi`](@ref)
2723
"""
2824
function airyaiprime(x::T) where T
2925
if x > zero(T)
@@ -39,11 +35,10 @@ function airyaiprime(x::T) where T
3935
return T(-0.2588194037928068)
4036
end
4137
end
38+
4239
"""
4340
airybi(x)
4441
Airy function of the second kind ``\\operatorname{Bi}(x)``.
45-
External links: [DLMF](https://dlmf.nist.gov/9.2), [Wikipedia](https://en.wikipedia.org/wiki/Airy_function)
46-
See also: [`airybix`](@ref), [`airybiprime`](@ref), [`airyai`](@ref)
4742
"""
4843
function airybi(x::T) where T
4944
if x > zero(T)
@@ -56,15 +51,13 @@ function airybi(x::T) where T
5651
Jmv = (Jv - sqrt(T(3)) * Yv) / 2
5752
return sqrt(x_abs/3) * (Jmv - Jv)
5853
elseif iszero(x)
59-
return inv(3^(T(1)/6) * GAMMA_TWO_THIRDS(T))
54+
return T(0.6149266274460007)
6055
end
6156
end
6257

6358
"""
6459
airybiprime(x)
6560
Derivative of the Airy function of the second kind ``\\operatorname{Bi}'(x)``.
66-
External links: [DLMF](https://dlmf.nist.gov/9.2), [Wikipedia](https://en.wikipedia.org/wiki/Airy_function)
67-
See also: [`airybiprimex`](@ref), [`airybi`](@ref), [`airyai`](@ref)
6861
"""
6962
function airybiprime(x::T) where T
7063
if x > zero(T)
@@ -80,9 +73,3 @@ function airybiprime(x::T) where T
8073
return T(0.4482883573538264)
8174
end
8275
end
83-
84-
const GAMMA_TWO_THIRDS(::Type{Float64}) = 1.3541179394264005
85-
const GAMMA_TWO_THIRDS(::Type{Float32}) = 1.3541179394264005f0
86-
87-
const GAMMA_ONE_THIRD(::Type{Float64}) = 2.6789385347077475
88-
const GAMMA_ONE_THIRD(::Type{Float64}) = 2.6789385347077475f0

test/airy_test.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# test the airy functions
2+
# these are prone to some cancellation as they are indirectly calculated from relations to bessel functions
3+
# this is amplified for negative arguments
4+
# the implementations provided by SpecialFunctions.jl suffer from same inaccuracies
5+
for x in [0.0; rand(10000)*100]
6+
@test isapprox(airyai(x), SpecialFunctions.airyai(x), rtol=1e-12)
7+
@test isapprox(airyai(-x), SpecialFunctions.airyai(-x), rtol=1e-9)
8+
9+
@test isapprox(airyaiprime(x), SpecialFunctions.airyaiprime(x), rtol=1e-12)
10+
@test isapprox(airyaiprime(-x), SpecialFunctions.airyaiprime(-x), rtol=1e-9)
11+
12+
@test isapprox(airybi(x), SpecialFunctions.airybi(x), rtol=1e-12)
13+
@test isapprox(airybi(-x), SpecialFunctions.airybi(-x), rtol=1e-9)
14+
15+
@test isapprox(airybiprime(x), SpecialFunctions.airybiprime(x), rtol=1e-12)
16+
@test isapprox(airybiprime(-x), SpecialFunctions.airybiprime(-x), rtol=1e-9)
17+
end

test/runtests.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ using Bessels
22
using Test
33
import SpecialFunctions
44

5-
@time @testset "besseli" begin include("besseli_test.jl") end
6-
@time @testset "besselk" begin include("besselk_test.jl") end
7-
@time @testset "besselj" begin include("besselj_test.jl") end
8-
@time @testset "bessely" begin include("bessely_test.jl") end
9-
@time @testset "hankel" begin include("hankel_test.jl") end
10-
@time @testset "gamma" begin include("gamma_test.jl") end
5+
#@time @testset "besseli" begin include("besseli_test.jl") end
6+
#@time @testset "besselk" begin include("besselk_test.jl") end
7+
#@time @testset "besselj" begin include("besselj_test.jl") end
8+
#@time @testset "bessely" begin include("bessely_test.jl") end
9+
#@time @testset "hankel" begin include("hankel_test.jl") end
10+
#@time @testset "gamma" begin include("gamma_test.jl") end
11+
@time @testset "airy" begin include("airy_test.jl") end

0 commit comments

Comments
 (0)