@@ -468,7 +468,9 @@ function polygamma(m::Integer, z::ComplexOrReal{Float64})
468
468
# constants. We throw a DomainError() since the definition is unclear.
469
469
real (m) < 0 && throw (DomainError ())
470
470
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.
472
474
if real (z) <= 0 # reflection formula
473
475
(zeta (s, 1 - z) + signflip (m, cotderiv (m,z))) * (- gamma (s))
474
476
else
@@ -633,14 +635,14 @@ end
633
635
634
636
for f in (:digamma , :trigamma , :zeta , :eta , :invdigamma )
635
637
@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
639
641
640
642
function $f (z:: Number )
641
643
x = float (z)
642
644
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
644
646
$ f (x)
645
647
end
646
648
end
@@ -650,15 +652,10 @@ end
650
652
for T1 in (Float16, Float32, Float64), T2 in (Float16, Float32, Float64)
651
653
(T1 == T2 == Float64) && continue # Avoid redefining base definition
652
654
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
662
659
end
663
660
664
661
@@ -672,13 +669,6 @@ function zeta(s::Number, z::Number)
672
669
zeta (t, x)
673
670
end
674
671
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
-
682
672
683
673
function polygamma (m:: Integer , z:: Union{ComplexOrReal{Float16}, ComplexOrReal{Float32}} )
684
674
oftype (z, polygamma (m, f64 (z)))
0 commit comments