Author: Steve Papanik <[email protected]>
Branch: py3.6
Changeset: r92879:4a3e6bc30cc8
Date: 2017-10-30 12:46 +0000
http://bitbucket.org/pypy/pypy/changeset/4a3e6bc30cc8/
Log: Add inf and nan to cmath
This also adds the corresponding complex constants.
diff --git a/pypy/module/cmath/__init__.py b/pypy/module/cmath/__init__.py
--- a/pypy/module/cmath/__init__.py
+++ b/pypy/module/cmath/__init__.py
@@ -40,6 +40,10 @@
interpleveldefs = {
'pi': 'space.newfloat(interp_cmath.pi)',
'e': 'space.newfloat(interp_cmath.e)',
+ 'inf': 'space.newfloat(interp_cmath.inf)',
+ 'nan': 'space.newfloat(interp_cmath.nan)',
+ 'infj': 'space.newcomplex(0.0, interp_cmath.inf)',
+ 'nanj': 'space.newcomplex(0.0, interp_cmath.nan)',
'isclose': 'interp_cmath.isclose',
}
interpleveldefs.update(dict([(name, 'interp_cmath.wrapped_' + name)
diff --git a/pypy/module/cmath/interp_cmath.py
b/pypy/module/cmath/interp_cmath.py
--- a/pypy/module/cmath/interp_cmath.py
+++ b/pypy/module/cmath/interp_cmath.py
@@ -6,8 +6,13 @@
from pypy.module.cmath import names_and_docstrings
from rpython.rlib import rcomplex, rfloat
-pi = math.pi
-e = math.e
+pi = math.pi
+e = math.e
+inf = float('inf')
+nan = float('nan')
+infj = complex(0.0, inf)
+nanj = complex(0.0, nan)
+
@specialize.arg(0)
def call_c_func(c_func, space, x, y):
diff --git a/pypy/module/cmath/test/test_cmath.py
b/pypy/module/cmath/test/test_cmath.py
--- a/pypy/module/cmath/test/test_cmath.py
+++ b/pypy/module/cmath/test/test_cmath.py
@@ -134,6 +134,24 @@
assert cmath.isclose(100000j, 100001j, abs_tol=1.5)
assert not cmath.isclose(100000j, 100001j, abs_tol=0.5)
+ def test_infinity_and_nan_constants(self):
+ import cmath, math
+ assert cmath.inf.real == math.inf
+ assert cmath.inf.imag == 0.0
+ assert cmath.infj.real == 0.0
+ assert cmath.infj.imag == math.inf
+
+ assert math.isnan(cmath.nan.real)
+ assert cmath.nan.imag == 0.0
+ assert cmath.nanj.real == 0.0
+ assert math.isnan(cmath.nanj.imag)
+
+ # Check consistency with reprs.
+ assert repr(cmath.inf) == "inf"
+ assert repr(cmath.infj) == "infj"
+ assert repr(cmath.nan) == "nan"
+ assert repr(cmath.nanj) == "nanj"
+
def parse_testfile(fname):
"""Parse a file with test values
@@ -211,7 +229,7 @@
def test_specific_values():
#if not float.__getformat__("double").startswith("IEEE"):
# return
-
+
import rpython
# too fragile...
fname = os.path.join(os.path.dirname(rpython.rlib.__file__), 'test',
'rcomplex_testcases.txt')
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit