Skip to content

Commit d542b61

Browse files
committed
fix ellipk and ellipe
1 parent 31e3c1a commit d542b61

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/ellip.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ As suggested in this paper, the domain is restricted to ``(-\infty,1]``.
3636
ellipk(m::Real) = _ellipk(float(m))
3737

3838
function _ellipk(m::Float64)
39+
isnan(m) && return NaN
40+
(m == -Inf) && return 0.0
41+
3942
flag_is_m_neg = false
4043
if m < 0.0
4144
x = m / (m-1) #dealing with negative args
@@ -49,7 +52,7 @@ function _ellipk(m::Float64)
4952
return Float64(halfπ)
5053

5154
elseif x == 1.0
52-
return Inf
55+
return flag_is_m_neg ? 0.0 : Inf
5356

5457
elseif x > 1.0
5558
throw(DomainError(m, "`m` must lie between -Inf and 1 ---- Domain: (-Inf,1.0]"))
@@ -207,6 +210,9 @@ As suggested in this paper, the domain is restricted to ``(-\infty,1]``.
207210
ellipe(m::Real) = _ellipe(float(m))
208211

209212
function _ellipe(m::Float64)
213+
isnan(m) && return NaN
214+
(m == -Inf) && return Inf
215+
210216
flag_is_m_neg = false
211217
if m < 0.0
212218
x = m / (m-1) #dealing with negative args
@@ -219,7 +225,7 @@ function _ellipe(m::Float64)
219225
if x == 0.0
220226
return Float64(halfπ)
221227
elseif x == 1.0
222-
return 1.0
228+
return flag_is_m_neg ? Inf : 1.0
223229

224230
elseif x > 1.0
225231
throw(DomainError(m,"`m` must lie between -Inf and 1 ---- Domain : (-inf,1.0]"))

test/ellip.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
@test ellipk(1.0) == Inf
1818
@test ellipk(Float16(0.92)) 2.683551406315229344 rtol=2*eps(Float16)
1919
@test ellipk(Float32(0.92)) 2.683551406315229344 rtol=2*eps(Float32)
20+
@test isnan(ellipk(NaN))
21+
@test ellipk(-Inf) == 0.0
22+
@test ellipk(-1e30) 0.0 atol=1e-13
2023
@test_throws MethodError ellipk(BigFloat(0.5))
2124
@test_throws DomainError ellipk(1.1)
2225
end
@@ -38,6 +41,9 @@
3841
@test ellipe(1.0) 1.00 rtol=2*eps()
3942
@test ellipe(Float16(0.865)) 1.1322436887003925 rtol=2*eps(Float16)
4043
@test ellipe(Float32(0.865)) 1.1322436887003925 rtol=2*eps(Float32)
44+
@test isnan(ellipe(NaN))
45+
@test ellipe(-Inf) == Inf
46+
@test ellipe(-1e16) > ellipe(-1e15)
4147
@test_throws MethodError ellipe(BigFloat(-1))
4248
@test_throws DomainError ellipe(1.2)
4349
end

0 commit comments

Comments
 (0)