From 1e80ccbb1cb60a674a901a49ea850cd40539bba3 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Fri, 15 Feb 2019 20:48:07 +0300 Subject: [PATCH] Correct mpf initialization from tuple for f(n)inf/fnan Closes #438 --- mpmath/ctx_mp_python.py | 6 ++++-- mpmath/tests/test_basic_ops.py | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/mpmath/ctx_mp_python.py b/mpmath/ctx_mp_python.py index 9e40b4ff..3e0462ea 100644 --- a/mpmath/ctx_mp_python.py +++ b/mpmath/ctx_mp_python.py @@ -67,9 +67,11 @@ class _mpf(mpnumeric): v._mpf_ = from_man_exp(val[0], val[1], prec, rounding) return v if len(val) == 4: - sign, man, exp, bc = val + if val not in (finf, fninf, fnan): + sign, man, exp, bc = val + val = normalize(sign, MPZ(man), exp, bc, prec, rounding) v = new(cls) - v._mpf_ = normalize(sign, MPZ(man), exp, bc, prec, rounding) + v._mpf_ = val return v raise ValueError else: diff --git a/mpmath/tests/test_basic_ops.py b/mpmath/tests/test_basic_ops.py index f8d38d5c..e00baf8a 100644 --- a/mpmath/tests/test_basic_ops.py +++ b/mpmath/tests/test_basic_ops.py @@ -443,3 +443,9 @@ def test_isnan_etc(): assert mp.isnpint(-1.1+0j) == False assert mp.isnpint(-1+0.1j) == False assert mp.isnpint(0+0.1j) == False + + +def test_issue_438(): + assert mpf(finf) == mpf('inf') + assert mpf(fninf) == mpf('-inf') + assert mpf(fnan)._mpf_ == mpf('nan')._mpf_