Skip to content

Commit e81314f

Browse files
committed
=remove last of the special casing for Integers
1 parent 6334dda commit e81314f

File tree

2 files changed

+16
-26
lines changed

2 files changed

+16
-26
lines changed

base/special/gamma.jl

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,9 @@ function polygamma(m::Integer, z::ComplexOrReal{Float64})
468468
# constants. We throw a DomainError() since the definition is unclear.
469469
real(m) < 0 && throw(DomainError())
470470

471-
s = m+1
471+
s = Float64(m+1)
472+
# It is safe to convert any integer (including `BigInt`) to a float here
473+
# as underflow occurs before precision issues.
472474
if real(z) <= 0 # reflection formula
473475
(zeta(s, 1-z) + signflip(m, cotderiv(m,z))) * (-gamma(s))
474476
else
@@ -633,14 +635,14 @@ end
633635

634636
for f in (:digamma, :trigamma, :zeta, :eta, :invdigamma)
635637
@eval begin
636-
function $f(z::Union{ComplexOrReal{Float16}, ComplexOrReal{Float32}})
637-
oftype(z, $f(f64(z)))
638-
end
638+
function $f(z::Union{ComplexOrReal{Float16}, ComplexOrReal{Float32}})
639+
oftype(z, $f(f64(z)))
640+
end
639641

640642
function $f(z::Number)
641643
x = float(z)
642644
typeof(x) === typeof(z) && throw(MethodError($f, (z,)))
643-
# There is nothing to fallback to, since this didn't change the argument types
645+
# There is nothing to fallback to, as this didn't change the argument types
644646
$f(x)
645647
end
646648
end
@@ -650,15 +652,10 @@ end
650652
for T1 in (Float16, Float32, Float64), T2 in (Float16, Float32, Float64)
651653
(T1 == T2 == Float64) && continue # Avoid redefining base definition
652654

653-
@eval function zeta(s::ComplexOrReal{$T1}, z::ComplexOrReal{$T2})
654-
ζ = zeta(f64(s), f64(z))
655-
656-
if typeof(s) <: Complex || typeof(z) <: Complex
657-
convert(Complex{$T2}, ζ)
658-
else
659-
convert(typeof(z), ζ)
660-
end
661-
end
655+
@eval function zeta(s::ComplexOrReal{$T1}, z::ComplexOrReal{$T2})
656+
ζ = zeta(f64(s), f64(z))
657+
convert(promote_type(typeof(s), typeof(z)), ζ)
658+
end
662659
end
663660

664661

@@ -672,13 +669,6 @@ function zeta(s::Number, z::Number)
672669
zeta(t, x)
673670
end
674671

675-
# It is safe to convert `s` to a float as underflow will occur before precision issues
676-
zeta(s::Integer, z::Number) = zeta(oftype(z, s), z)
677-
function zeta(s::Integer, z::Integer)
678-
x=float(z)
679-
zeta(oftype(x, s), x)
680-
end
681-
682672

683673
function polygamma(m::Integer, z::Union{ComplexOrReal{Float16}, ComplexOrReal{Float32}})
684674
oftype(z, polygamma(m, f64(z)))

test/math.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -960,13 +960,13 @@ end
960960
@test_throws MethodError zeta(1.0,big"2")
961961
@test_throws MethodError zeta(1.0,big"2.0")
962962
@test_throws MethodError zeta(big"1.0",2.0)
963+
@test_throws MethodError zeta(big"1",2.0)
963964

964965

965-
@test typeof(zeta(complex(1), 2.0)) == Complex{Float64}
966966
@test typeof(polygamma(3, 0x2)) == Float64
967967
@test typeof(polygamma(big"3", 2f0)) == Float32
968-
@test typeof(zeta(big"1", 2.0)) == Float64
969-
@test typeof(zeta(big"1", 2f0)) == Float32
970-
@test typeof(zeta(2f0, 2f0)) == Float32
968+
@test typeof(zeta(1, 2.0)) == Float64
969+
@test typeof(zeta(1, 2f0)) == Float64 # BitIntegers result in Float64 returns
971970
@test typeof(zeta(2f0, complex(2f0,0f0))) == Complex{Float32}
972-
@test typeof(zeta(complex(1,1), 2f0)) == Complex{Float32}
971+
@test typeof(zeta(complex(1,1), 2f0)) == Complex{Float64}
972+
@test typeof(zeta(complex(1), 2.0)) == Complex{Float64}

0 commit comments

Comments
 (0)