[Python-modules-team] Bug#781222: mpmath.polyroots fails with "NameError: global name 'orig' is not defined"

Richard B. Kreckel kreckel at in.terlu.de
Thu Mar 26 08:05:23 UTC 2015

Package: python-mpmath
Version: 0.19-1
Severity: serious
Tags: patch

How to reproduce:
$ python
Python 2.7.9 (default, Mar  1 2015, 12:57:24)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from mpmath import mp
>>> mp.polyroots([4,3,2], error=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
"/usr/lib/python2.7/dist-packages/mpmath/calculus/polynomials.py", line
201, in polyroots
    err = max(err, ctx.ldexp(1, -orig+1))
NameError: global name 'orig' is not defined

Jeez, this silly glitch renders a significand portion of mpmath unusable!

Fix is (stolen from upstream git repository):
--- a/usr/lib/python2.7/dist-packages/mpmath/calculus/polynomials.py
+++ b/usr/lib/python2.7/dist-packages/mpmath/calculus/polynomials.py
@@ -156,6 +156,7 @@
         # Constant polynomial with no roots
         return []

+    orig = ctx.prec
     tol = +ctx.eps
     with ctx.extraprec(extraprec):
         deg = len(coeffs) - 1

Richard B. Kreckel

More information about the Python-modules-team mailing list