Skip to content

Commit 552a0f9

Browse files
committed
=correct MethodErrors for #17474
1 parent 7aea83d commit 552a0f9

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

base/special/gamma.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ for f in (:digamma, :trigamma, :zeta, :eta, :invdigamma)
640640

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

677677
function zeta(s::Integer, z::Number)
678-
x = float(z)
679678
t = Int(s) # One could worry here about converting a BigInteger into a Int32/Int64
680-
if typeof(x) === typeof(z) && typeof(t) === typeof(s)
679+
x = float(z)
680+
if typeof(t) === typeof(s) && typeof(x) === typeof(z)
681681
# There is nothing to fallback to, since this didn't work
682-
throw(MethodError(zeta,(s,t)))
682+
throw(MethodError(zeta,(s,z)))
683683
end
684684
zeta(t, x)
685685
end
686686

687687

688688
function zeta(s::Number, z::Number)
689-
x = float(z)
690689
t = float(s)
691-
if typeof(x) === typeof(z) && typeof(t) === typeof(s)
690+
x = float(z)
691+
if typeof(t) === typeof(s) && typeof(x) === typeof(z)
692692
# There is nothing to fallback to, since this didn't work
693-
throw(MethodError(zeta,(s,t)))
693+
throw(MethodError(zeta,(s,z)))
694694
end
695695
zeta(t, x)
696696
end
697697

698698

699699
function polygamma(m::Integer, z::Number)
700700
x = float(z)
701-
typeof(x) == typeof(z) && throw(MethodError(polygamma, (m,z)))
701+
typeof(x) === typeof(z) && throw(MethodError(polygamma, (m,z)))
702702
# There is nothing to fallback to, since this didn't work
703703
polygamma(m, x)
704704
end

test/math.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,11 +946,22 @@ end
946946
@test typeof(eta(big"2")) == BigFloat
947947
@test typeof(zeta(big"2")) == BigFloat
948948
@test typeof(digamma(big"2")) == BigFloat
949+
949950
@test_throws MethodError trigamma(big"2")
950951
@test_throws MethodError trigamma(big"2.0")
951952
@test_throws MethodError invdigamma(big"2")
952953
@test_throws MethodError invdigamma(big"2.0")
954+
953955
@test_throws MethodError eta(Complex(big"2"))
954956
@test_throws MethodError eta(Complex(big"2.0"))
955957
@test_throws MethodError zeta(Complex(big"2"))
956958
@test_throws MethodError zeta(Complex(big"2.0"))
959+
@test_throws MethodError zeta(1.0,big"2")
960+
@test_throws MethodError zeta(1.0,big"2.0")
961+
@test_throws MethodError zeta(big"1.0",2.0)
962+
963+
@test typeof(zeta(complex(1),2.0)) == Complex{Float64}
964+
@test typeof(polygamma(3, 0x2)) == Float64
965+
@test typeof(polygamma(big"3", 2f0)) == Float32
966+
@test typeof(zeta(big"1",2.0)) == Float64 #Is this really desirable behavour?
967+

0 commit comments

Comments
 (0)