Skip to content

Commit

Permalink
=correct MethodErrors for JuliaLang#17474
Browse files Browse the repository at this point in the history
  • Loading branch information
oxinabox committed Nov 24, 2016
1 parent dca8256 commit c96f578
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
16 changes: 8 additions & 8 deletions base/special/gamma.jl
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ for f in (:digamma, :trigamma, :zeta, :eta, :invdigamma)

function $f(z::Number)
x = float(z)
typeof(x) == typeof(z) && throw(MethodError($f, (z,)))
typeof(x) === typeof(z) && throw(MethodError($f, (z,)))
# There is nothing to fallback to, since this didn't change the argument types
$f(x)
end
Expand Down Expand Up @@ -675,30 +675,30 @@ function zeta(s::Complex{Int}, z::ComplexOrReal{Float64})::Complex{Float64}
end

function zeta(s::Integer, z::Number)
x = float(z)
t = Int(s) # One could worry here about converting a BigInteger into a Int32/Int64
if typeof(x) === typeof(z) && typeof(t) === typeof(s)
x = float(z)
if typeof(t) === typeof(s) && typeof(x) === typeof(z)
# There is nothing to fallback to, since this didn't work
throw(MethodError(zeta,(s,t)))
throw(MethodError(zeta,(s,z)))
end
zeta(t, x)
end


function zeta(s::Number, z::Number)
x = float(z)
t = float(s)
if typeof(x) === typeof(z) && typeof(t) === typeof(s)
x = float(z)
if typeof(t) === typeof(s) && typeof(x) === typeof(z)
# There is nothing to fallback to, since this didn't work
throw(MethodError(zeta,(s,t)))
throw(MethodError(zeta,(s,z)))
end
zeta(t, x)
end


function polygamma(m::Integer, z::Number)
x = float(z)
typeof(x) == typeof(z) && throw(MethodError(polygamma, (m,z)))
typeof(x) === typeof(z) && throw(MethodError(polygamma, (m,z)))
# There is nothing to fallback to, since this didn't work
polygamma(m, x)
end
11 changes: 11 additions & 0 deletions test/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -948,11 +948,22 @@ end
@test typeof(eta(big"2")) == BigFloat
@test typeof(zeta(big"2")) == BigFloat
@test typeof(digamma(big"2")) == BigFloat

@test_throws MethodError trigamma(big"2")
@test_throws MethodError trigamma(big"2.0")
@test_throws MethodError invdigamma(big"2")
@test_throws MethodError invdigamma(big"2.0")

@test_throws MethodError eta(Complex(big"2"))
@test_throws MethodError eta(Complex(big"2.0"))
@test_throws MethodError zeta(Complex(big"2"))
@test_throws MethodError zeta(Complex(big"2.0"))
@test_throws MethodError zeta(1.0,big"2")
@test_throws MethodError zeta(1.0,big"2.0")
@test_throws MethodError zeta(big"1.0",2.0)

@test typeof(zeta(complex(1),2.0)) == Complex{Float64}
@test typeof(polygamma(3, 0x2)) == Float64
@test typeof(polygamma(big"3", 2f0)) == Float32
@test typeof(zeta(big"1",2.0)) == Float64 #Is this really desirable behavour?

0 comments on commit c96f578

Please sign in to comment.