Skip to content

Commit

Permalink
Fix integer evaluation (#29)
Browse files Browse the repository at this point in the history
* Fix integer arguments

* Update Project.toml
  • Loading branch information
dlfivefifty authored Aug 28, 2020
1 parent f4461b4 commit 5866fe5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "HypergeometricFunctions"
uuid = "34004b35-14d8-5ef3-9330-4cdb6864b03a"
version = "0.3.2"
version = "0.3.3"

[deps]
DualNumbers = "fa6b7ba4-c1ee-5f82-b5fc-ecf0adba8f74"
Expand Down
18 changes: 9 additions & 9 deletions src/specialfunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ end


function _₂F₁maclaurin(a::Number, b::Number, c::Number, z::Number)
T = promote_type(typeof(a), typeof(b), typeof(c), typeof(z))
T = float(promote_type(typeof(a), typeof(b), typeof(c), typeof(z)))
S₀, S₁, j = one(T), one(T)+a*b*z/c, 1
while errcheck(S₀, S₁, 10eps(real(T))) || j 1
rⱼ = (a+j)/(j+1)*(b+j)/(c+j)
Expand All @@ -358,7 +358,7 @@ function _₂F₁maclaurin(a::Number, b::Number, c::Number, z::Number)
end

function _₂F₁maclaurinalt(a::Number, b::Number, c::Number, z::Number)
T = promote_type(typeof(a), typeof(b), typeof(c), typeof(z))
T = float(promote_type(typeof(a), typeof(b), typeof(c), typeof(z)))
C, S, j = one(T), one(T), 0
while abs(C) > 10abs(S)*eps(real(T)) || j 1
C *= (a+j)/(j+1)*(b+j)/(c+j)*z
Expand All @@ -369,7 +369,7 @@ function _₂F₁maclaurinalt(a::Number, b::Number, c::Number, z::Number)
end

function _₂F₁continuation(s::Number, t::Number, c::Number, z₀::Number, z::Number)
T = promote_type(typeof(s), typeof(t), typeof(c), typeof(z₀), typeof(z))
T = float(promote_type(typeof(s), typeof(t), typeof(c), typeof(z₀), typeof(z)))
izz₀, d0, d1 = inv(z-z₀), one(T), s/(2s-t+one(T))*((s+1)*(1-2z₀)+(t+1)*z₀-c)
S₀, S₁, izz₀j, j = one(T), one(T)+d1*izz₀, izz₀, 2
while errcheck(S₀, S₁, 10eps(real(T))) || j 2
Expand All @@ -381,7 +381,7 @@ function _₂F₁continuation(s::Number, t::Number, c::Number, z₀::Number, z::
end

function _₂F₁continuationalt(a::Number, c::Number, z₀::Number, z::Number)
T = promote_type(typeof(a), typeof(c), typeof(z₀), typeof(z))
T = float(promote_type(typeof(a), typeof(c), typeof(z₀), typeof(z)))
izz₀ = inv(z-z₀)
e0, e1 = one(T), (a+one(T))*(one(T)-2z₀)+(2a+one(T))*z₀-c
f0, f1 = zero(T), one(T)-2z₀
Expand All @@ -402,7 +402,7 @@ function _₂F₁continuationalt(a::Number, c::Number, z₀::Number, z::Number)
end

function _₂F₁logsum(a::Number, b::Number, z::Number, w::Number, s::Int)
T = promote_type(typeof(a), typeof(b), typeof(z), typeof(w))
T = float(promote_type(typeof(a), typeof(b), typeof(z), typeof(w)))
cⱼ = 2digamma(one(T))-digamma(a)-digamma(b)+s*log1p(-z)
C, S, j = one(T), cⱼ, 0
while abs(C) > 10abs(S)*eps(real(T)) || j 1
Expand All @@ -415,7 +415,7 @@ function _₂F₁logsum(a::Number, b::Number, z::Number, w::Number, s::Int)
end

function _₂F₁logsumalt(a::Number, b::Number, z::Number, w::Number)
T = promote_type(typeof(a), typeof(b), typeof(z), typeof(w))
T = float(promote_type(typeof(a), typeof(b), typeof(z), typeof(w)))
d, cⱼ = one(T)-b, 2digamma(one(T))-digamma(a)-digamma(b)-log(-w)
C, S, j = one(T), cⱼ, 0
while abs(C) > 10abs(S)*eps(real(T)) || j 1
Expand All @@ -428,7 +428,7 @@ function _₂F₁logsumalt(a::Number, b::Number, z::Number, w::Number)
end

function _₂F₁taylor(a::Number, b::Number, c::Number, z::Number)
T = promote_type(typeof(a), typeof(b), typeof(c), typeof(z))
T = float(promote_type(typeof(a), typeof(b), typeof(c), typeof(z)))
z₀ = abs(z) < 1 ? ρϵ*sign(z) : sign(z)/ρϵ
q₀, q₁ = _₂F₁(a, b, c, z₀), a*b/c*_₂F₁(a+1, b+1, c+1, z₀)
S₀, zz₀ = q₀, z-z₀
Expand All @@ -443,7 +443,7 @@ function _₂F₁taylor(a::Number, b::Number, c::Number, z::Number)
end

function _₃F₂maclaurin(a₁, a₂, a₃, b₁, b₂, z)
T = promote_type(typeof(a₁), typeof(a₂), typeof(a₃), typeof(b₁), typeof(b₂), typeof(z))
T = float(promote_type(typeof(a₁), typeof(a₂), typeof(a₃), typeof(b₁), typeof(b₂), typeof(z)))
S₀, S₁, j = one(T), one(T)+(a₁*a₂*a₃*z)/(b₁*b₂), 1
while errcheck(S₀, S₁, 10eps(real(T))) || j 1
rⱼ = ((a₁+j)*(a₂+j)*(a₃+j))/((b₁+j)*(b₂+j)*(j+1))
Expand All @@ -454,7 +454,7 @@ function _₃F₂maclaurin(a₁, a₂, a₃, b₁, b₂, z)
end

function pFqmaclaurin(a::AbstractVector{S}, b::AbstractVector{U}, z::V) where {S, U, V}
T = promote_type(S, U, V)
T = float(promote_type(S, U, V))
S₀, S₁, j = one(T), one(T)+prod(a)*z/prod(b), 1
while errcheck(S₀, S₁, 10eps(real(T))) || j 1
rⱼ = inv(j+one(T))
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -424,4 +424,8 @@ end
@test pFqweniger(S[α, β], S[γ], z) CS(pFq(T[α, β], T[γ], CT(z))) atol=atol rtol=rtol
end
end

@testset "Integer arguments" begin
@test _₂F₁(1, 0, 3, -1) _₂F₁(1.0, 0, 3, -1) 1.0
end
end

2 comments on commit 5866fe5

@dlfivefifty
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/20456

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.3 -m "<description of version>" 5866fe52e6d2cf61b311936becb6def057ddf22a
git push origin v0.3.3

Please sign in to comment.