Skip to content

Commit cd0f62b

Browse files
committed
add complex polygamma and Hurwitz zeta functions (fixes JuliaLang#7033)
1 parent ff6bde7 commit cd0f62b

File tree

4 files changed

+368
-260
lines changed

4 files changed

+368
-260
lines changed

base/math.jl

+27
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,33 @@ macro horner(x, p...)
4848
ex
4949
end
5050

51+
# Evaluate p[1] + z*p[2] + z^2*p[3] + ... + z^(n-1)*p[n], assuming
52+
# the p[k] are *real* coefficients. This uses Horner's method if z
53+
# is real, but for complex z it uses a more efficient algorithm described
54+
# in Knuth, TAOCP vol. 2, section 4.6.4, equation (3).
55+
macro chorner(z, p...)
56+
a = :($(esc(p[end])))
57+
b = :($(esc(p[end-1])))
58+
as = {}
59+
for i = length(p)-2:-1:1
60+
ai = symbol(string("a", i))
61+
push!(as, :($ai = $a))
62+
a = :($b + r*$ai)
63+
b = :($(esc(p[i])) - s * $ai)
64+
end
65+
ai = :a0
66+
push!(as, :($ai = $a))
67+
C = Expr(:block,
68+
:(x = real($(esc(z)))),
69+
:(y = imag($(esc(z)))),
70+
:(r = x + x),
71+
:(s = x*x + y*y),
72+
as...,
73+
:(Complex($ai * x + $b, $ai * y)))
74+
R = Expr(:macrocall, symbol("@horner"), z, p...)
75+
:(isa($(esc(z)), Real) ? $R : $C)
76+
end
77+
5178
rad2deg(z::Real) = oftype(z, 57.29577951308232*z)
5279
deg2rad(z::Real) = oftype(z, 0.017453292519943295*z)
5380
rad2deg(z::Integer) = rad2deg(float(z))

0 commit comments

Comments
 (0)