Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
2be278c7
Commit
2be278c7
authored
Aug 29, 2016
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Plain Diff
Merge heads
parents
1f932619
84e6311d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
103 additions
and
0 deletions
+103
-0
Doc/library/cmath.rst
Doc/library/cmath.rst
+28
-0
Lib/test/test_cmath.py
Lib/test/test_cmath.py
+17
-0
Misc/NEWS
Misc/NEWS
+4
-0
Modules/cmathmodule.c
Modules/cmathmodule.c
+54
-0
No files found.
Doc/library/cmath.rst
View file @
2be278c7
...
...
@@ -259,6 +259,34 @@ Constants
.. versionadded:: 3.6
.. data:: inf
Floating-point positive infinity. Equivalent to ``float('inf')``.
.. versionadded:: 3.6
.. data:: infj
Complex number with zero real part and positive infinity imaginary
part. Equivalent to ``complex(0.0, float('inf'))``.
.. versionadded:: 3.6
.. data:: nan
A floating-point "not a number" (NaN) value. Equivalent to
``float('nan')``.
.. versionadded:: 3.6
.. data:: nanj
Complex number with zero real part and NaN imaginary part. Equivalent to
``complex(0.0, float('nan'))``.
.. versionadded:: 3.6
.. index:: module: math
Note that the selection of functions is similar, but not identical, to that in
...
...
Lib/test/test_cmath.py
View file @
2be278c7
...
...
@@ -154,6 +154,23 @@ class CMathTests(unittest.TestCase):
self
.
assertAlmostEqual
(
cmath
.
e
,
e_expected
,
places
=
9
,
msg
=
"cmath.e is {}; should be {}"
.
format
(
cmath
.
e
,
e_expected
))
def
test_infinity_and_nan_constants
(
self
):
self
.
assertEqual
(
cmath
.
inf
.
real
,
math
.
inf
)
self
.
assertEqual
(
cmath
.
inf
.
imag
,
0.0
)
self
.
assertEqual
(
cmath
.
infj
.
real
,
0.0
)
self
.
assertEqual
(
cmath
.
infj
.
imag
,
math
.
inf
)
self
.
assertTrue
(
math
.
isnan
(
cmath
.
nan
.
real
))
self
.
assertEqual
(
cmath
.
nan
.
imag
,
0.0
)
self
.
assertEqual
(
cmath
.
nanj
.
real
,
0.0
)
self
.
assertTrue
(
math
.
isnan
(
cmath
.
nanj
.
imag
))
# Check consistency with reprs.
self
.
assertEqual
(
repr
(
cmath
.
inf
),
"inf"
)
self
.
assertEqual
(
repr
(
cmath
.
infj
),
"infj"
)
self
.
assertEqual
(
repr
(
cmath
.
nan
),
"nan"
)
self
.
assertEqual
(
repr
(
cmath
.
nanj
),
"nanj"
)
def
test_user_object
(
self
):
# Test automatic calling of __complex__ and __float__ by cmath
# functions
...
...
Misc/NEWS
View file @
2be278c7
...
...
@@ -49,6 +49,10 @@ Core and Builtins
Library
-------
- Issue #23229: Add new ``cmath`` constants: ``cmath.inf`` and ``cmath.nan`` to
match ``math.inf`` and ``math.nan``, and also ``cmath.infj`` and
``cmath.nanj`` to match the format used by complex repr.
- Issue #27861: Fixed a crash in sqlite3.Connection.cursor() when a factory
creates not a cursor. Patch by Xiang Zhang.
...
...
Modules/cmathmodule.c
View file @
2be278c7
...
...
@@ -81,6 +81,54 @@ else {
#endif
#define CM_SCALE_DOWN (-(CM_SCALE_UP+1)/2)
/* Constants cmath.inf, cmath.infj, cmath.nan, cmath.nanj.
cmath.nan and cmath.nanj are defined only when either
PY_NO_SHORT_FLOAT_REPR is *not* defined (which should be
the most common situation on machines using an IEEE 754
representation), or Py_NAN is defined. */
static
double
m_inf
(
void
)
{
#ifndef PY_NO_SHORT_FLOAT_REPR
return
_Py_dg_infinity
(
0
);
#else
return
Py_HUGE_VAL
;
#endif
}
static
Py_complex
c_infj
(
void
)
{
Py_complex
r
;
r
.
real
=
0
.
0
;
r
.
imag
=
m_inf
();
return
r
;
}
#if !defined(PY_NO_SHORT_FLOAT_REPR) || defined(Py_NAN)
static
double
m_nan
(
void
)
{
#ifndef PY_NO_SHORT_FLOAT_REPR
return
_Py_dg_stdnan
(
0
);
#else
return
Py_NAN
;
#endif
}
static
Py_complex
c_nanj
(
void
)
{
Py_complex
r
;
r
.
real
=
0
.
0
;
r
.
imag
=
m_nan
();
return
r
;
}
#endif
/* forward declarations */
static
Py_complex
cmath_asinh_impl
(
PyObject
*
,
Py_complex
);
static
Py_complex
cmath_atanh_impl
(
PyObject
*
,
Py_complex
);
...
...
@@ -1240,6 +1288,12 @@ PyInit_cmath(void)
PyFloat_FromDouble
(
Py_MATH_PI
));
PyModule_AddObject
(
m
,
"e"
,
PyFloat_FromDouble
(
Py_MATH_E
));
PyModule_AddObject
(
m
,
"tau"
,
PyFloat_FromDouble
(
Py_MATH_TAU
));
/* 2pi */
PyModule_AddObject
(
m
,
"inf"
,
PyFloat_FromDouble
(
m_inf
()));
PyModule_AddObject
(
m
,
"infj"
,
PyComplex_FromCComplex
(
c_infj
()));
#if !defined(PY_NO_SHORT_FLOAT_REPR) || defined(Py_NAN)
PyModule_AddObject
(
m
,
"nan"
,
PyFloat_FromDouble
(
m_nan
()));
PyModule_AddObject
(
m
,
"nanj"
,
PyComplex_FromCComplex
(
c_nanj
()));
#endif
/* initialize special value tables */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment