Repository: mpmath/mpmath (python)

Issue:
polylog at negative floating point infinity
```
>>> mpmath.polylog(2, -1e10)                                                         
mpf('-266.73983959066811')

>>> mpmath.polylog(3, -1e10)                                                         
mpf('-2072.554598906404')

>>> mpmath.polylog(4, -1e10)                                                         
mpf('-12150.509195825773')

>>> mpmath.polylog(5, -1e10)                                                         
mpf('-57328.817524624101')
```
That is, polylog limits to -infinity as x -> -infinity

If we try evaluating at -infinity, we sometimes get reasonable but not ideal results:
```
>>> mpmath.polylog(2, -inf)                                                         
mpf('nan')

>>> mpmath.polylog(3, -inf)                                                         
mpf('nan')
```
(`-inf` would be a better answer.)


For some other values, we can get garbage answers:
```
>>> mpmath.polylog(4, -inf)                                                         
mpf('0.0')

>>> mpmath.polylog(5, -inf)                                                         
mpf('0.0')
```

Pull request:
Add special case for ±inf in polylog_continuation()
Closes #473

Patch:
diff --git a/mpmath/functions/zeta.py b/mpmath/functions/zeta.py
index 3e3b542..40db1d2 100644
--- a/mpmath/functions/zeta.py
+++ b/mpmath/functions/zeta.py
@@ -402,6 +402,8 @@ def polylog_series(ctx, s, z):
 def polylog_continuation(ctx, n, z):
     if n < 0:
         return z*0
+    if ctx._is_real_type(z) and ctx.isinf(z) and n > 0:
+        return ctx.ninf
     twopij = 2j * ctx.pi
     a = -twopij**n/ctx.fac(n) * ctx.bernpoly(n, ctx.ln(z)/twopij)
     if ctx._is_real_type(z) and z < 0:


Test patch:
diff --git a/mpmath/tests/test_functions2.py b/mpmath/tests/test_functions2.py
index 1176fb4..6d860f8 100644
--- a/mpmath/tests/test_functions2.py
+++ b/mpmath/tests/test_functions2.py
@@ -2420,3 +2420,10 @@ def test_issue_511():
     assert mp.laguerre(1, 2, mp.inf) == -mp.inf
     assert mp.laguerre(1, 7.2, mp.inf) == -mp.inf
     assert fp.laguerre(1, 7.2, fp.inf) == -fp.inf
+
+def test_issue_473():
+    assert mp.polylog(1, -mp.inf) == -mp.inf
+    assert mp.polylog(2, -mp.inf) == -mp.inf
+    assert mp.polylog(3, -mp.inf) == -mp.inf
+    assert mp.polylog(4, -mp.inf) == -mp.inf
+    assert mp.polylog(5, -mp.inf) == -mp.inf