Skip to content

Commit b838a20

Browse files
committed
add definitions at infinity
1 parent 6e72ef6 commit b838a20

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

src/airy.jl

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ _airyai(z::ComplexF16) = ComplexF16(_airyai(ComplexF32(z)))
2222
function _airyai(z::ComplexOrReal{T}) where T <: Union{Float32, Float64}
2323
if ~isfinite(z)
2424
isnan(z) && return z
25-
isinf(z) && return throw(DomainError(z, "airyai(z) not defined at infinity"))
25+
if abs(angle(z)) < 2π/3
26+
return exp(-z)
27+
else
28+
return 1 / z
29+
end
2630
end
2731
x, y = real(z), imag(z)
2832
zabs = abs(z)
@@ -63,7 +67,11 @@ _airyaiprime(z::ComplexF16) = ComplexF16(_airyaiprime(ComplexF32(z)))
6367
function _airyaiprime(z::ComplexOrReal{T}) where T <: Union{Float32, Float64}
6468
if ~isfinite(z)
6569
isnan(z) && return z
66-
isinf(z) && return throw(DomainError(z, "airyai(z) not defined at infinity"))
70+
if abs(angle(z)) < 2π/3
71+
return -exp(-z)
72+
else
73+
return 1 / z
74+
end
6775
end
6876
x, y = real(z), imag(z)
6977
zabs = abs(z)
@@ -104,7 +112,11 @@ _airybi(z::ComplexF16) = ComplexF16(_airybi(ComplexF32(z)))
104112
function _airybi(z::ComplexOrReal{T}) where T <: Union{Float32, Float64}
105113
if ~isfinite(z)
106114
isnan(z) && return z
107-
isinf(z) && return throw(DomainError(z, "airyai(z) not defined at infinity"))
115+
if abs(angle(z)) < 2π/3
116+
return exp(z)
117+
else
118+
return 1 / z
119+
end
108120
end
109121
x, y = real(z), imag(z)
110122
zabs = abs(z)
@@ -147,6 +159,14 @@ _airybiprime(x::Float16) = Float16(_airybiprime(Float32(x)))
147159
_airybiprime(z::ComplexF16) = ComplexF16(_airybiprime(ComplexF32(z)))
148160

149161
function _airybiprime(z::ComplexOrReal{T}) where T <: Union{Float32, Float64}
162+
if ~isfinite(z)
163+
isnan(z) && return z
164+
if abs(angle(z)) < 2π/3
165+
return exp(z)
166+
else
167+
return -1 / z
168+
end
169+
end
150170
x, y = real(z), imag(z)
151171
zabs = abs(z)
152172

@@ -262,6 +282,11 @@ function airybi_power_series(x::ComplexOrReal{T}) where T
262282
end
263283
return (ai1*3^(-T(1)/6) + ai2*3^(-T(5)/6))
264284
end
285+
286+
#####
287+
##### Power series for airybiprime(x)
288+
#####
289+
265290
function airybiprime_power_series(x::ComplexOrReal{T}) where T
266291
S = eltype(x)
267292
iszero(x) && return S(0.4482883573538264)

test/airy_test.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,21 @@ for x in [0.0, 0.01, 0.5, 1.0, 2.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 50.0], a
2525
end
2626

2727
# test Inf
28-
# no longer set up
29-
#=
28+
3029
@test iszero(airyai(Inf))
3130
@test iszero(airyaiprime(Inf))
3231
@test isinf(airybi(Inf))
3332
@test isinf(airybiprime(Inf))
34-
=#
33+
34+
@test airyai(Inf + 0.0im) === exp(-(Inf + 0.0im))
35+
@test airyaiprime(Inf + 0.0im) === -exp(-(Inf + 0.0im))
36+
@test airyai(-Inf + 0.0im) === 1 / (-Inf + 0.0im)
37+
@test airyaiprime(-Inf + 0.0im) === 1 / (-Inf + 0.0im)
38+
@test airybi(Inf + Inf*im) === exp((Inf + Inf*im))
39+
@test airybi(-Inf + 10.0*im) === 1 / (-Inf + 10.0*im)
40+
@test airybiprime(Inf + 0.0*im) === exp((Inf + 0.0*im))
41+
@test airybiprime(-Inf + 0.0*im) === -1 / (-Inf + 0.0*im)
42+
3543

3644
# test Float16 types
3745
@test airyai(Float16(1.2)) isa Float16

0 commit comments

Comments
 (0)