fix issue #534: digamma hangs for some complex input

This commit is contained in:
fredrik
2022-02-14 09:51:53 +01:00
parent 35d15f7048
commit f3bb6dbb76
2 changed files with 7 additions and 1 deletions
+3 -1
View File
@@ -750,6 +750,7 @@ def mpc_psi0(z, prec, rnd=round_fast):
z2 = mpc_square(z, wp)
t = mpc_one
prev = mpc_zero
szprev = fzero
k = 1
eps = mpf_shift(fone, -wp+2)
while 1:
@@ -758,9 +759,10 @@ def mpc_psi0(z, prec, rnd=round_fast):
term = mpc_mpf_div(bern, mpc_mul_int(t, 2*k, wp), wp)
s = mpc_sub(s, term, wp)
szterm = mpc_abs(term, 10)
if k > 2 and mpf_le(szterm, eps):
if k > 2 and (mpf_le(szterm, eps) or mpf_le(szprev, szterm)):
break
prev = term
szprev = szterm
k += 1
return s
+4
View File
@@ -379,6 +379,10 @@ def test_polygamma():
assert isnan(psi(2,mpc(inf,inf)))
assert isnan(psi(2,mpc(nan,nan)))
assert isnan(psi(2,mpc(-inf,-inf)))
mp.dps = 30
# issue #534
assert digamma(-0.75+1j).ae(mpc('0.46317279488182026118963809283042317', '2.4821070143037957102007677817351115'))
mp.dps = 15
def test_polygamma_high_prec():
mp.dps = 100