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
0d2fac1f
Commit
0d2fac1f
authored
Jun 23, 2015
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #24489: ensure a previously set C errno doesn't disturb cmath.polar().
parent
94870434
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
12 deletions
+58
-12
Lib/test/test_cmath.py
Lib/test/test_cmath.py
+41
-10
Misc/NEWS
Misc/NEWS
+3
-1
Modules/_testcapimodule.c
Modules/_testcapimodule.c
+12
-0
Modules/cmathmodule.c
Modules/cmathmodule.c
+2
-1
No files found.
Lib/test/test_cmath.py
View file @
0d2fac1f
from
test.test_support
import
run_unittest
from
test.test_support
import
run_unittest
,
cpython_only
from
test.test_math
import
parse_testfile
,
test_file
import
unittest
import
cmath
,
math
...
...
@@ -351,17 +351,48 @@ class CMathTests(unittest.TestCase):
self
.
rAssertAlmostEqual
(
expected
.
imag
,
actual
.
imag
,
msg
=
error_message
)
def
assertCISEqual
(
self
,
a
,
b
):
eps
=
1E-7
if
abs
(
a
[
0
]
-
b
[
0
])
>
eps
or
abs
(
a
[
1
]
-
b
[
1
])
>
eps
:
self
.
fail
((
a
,
b
))
def
check_polar
(
self
,
func
):
def
check
(
arg
,
expected
):
got
=
func
(
arg
)
for
e
,
g
in
zip
(
expected
,
got
):
self
.
rAssertAlmostEqual
(
e
,
g
)
check
(
0
,
(
0.
,
0.
))
check
(
1
,
(
1.
,
0.
))
check
(
-
1
,
(
1.
,
pi
))
check
(
1j
,
(
1.
,
pi
/
2
))
check
(
-
3j
,
(
3.
,
-
pi
/
2
))
inf
=
float
(
'inf'
)
check
(
complex
(
inf
,
0
),
(
inf
,
0.
))
check
(
complex
(
-
inf
,
0
),
(
inf
,
pi
))
check
(
complex
(
3
,
inf
),
(
inf
,
pi
/
2
))
check
(
complex
(
5
,
-
inf
),
(
inf
,
-
pi
/
2
))
check
(
complex
(
inf
,
inf
),
(
inf
,
pi
/
4
))
check
(
complex
(
inf
,
-
inf
),
(
inf
,
-
pi
/
4
))
check
(
complex
(
-
inf
,
inf
),
(
inf
,
3
*
pi
/
4
))
check
(
complex
(
-
inf
,
-
inf
),
(
inf
,
-
3
*
pi
/
4
))
nan
=
float
(
'nan'
)
check
(
complex
(
nan
,
0
),
(
nan
,
nan
))
check
(
complex
(
0
,
nan
),
(
nan
,
nan
))
check
(
complex
(
nan
,
nan
),
(
nan
,
nan
))
check
(
complex
(
inf
,
nan
),
(
inf
,
nan
))
check
(
complex
(
-
inf
,
nan
),
(
inf
,
nan
))
check
(
complex
(
nan
,
inf
),
(
inf
,
nan
))
check
(
complex
(
nan
,
-
inf
),
(
inf
,
nan
))
def
test_polar
(
self
):
self
.
assertCISEqual
(
polar
(
0
),
(
0.
,
0.
))
self
.
assertCISEqual
(
polar
(
1.
),
(
1.
,
0.
))
self
.
assertCISEqual
(
polar
(
-
1.
),
(
1.
,
pi
))
self
.
assertCISEqual
(
polar
(
1j
),
(
1.
,
pi
/
2
))
self
.
assertCISEqual
(
polar
(
-
1j
),
(
1.
,
-
pi
/
2
))
self
.
check_polar
(
polar
)
@
cpython_only
def
test_polar_errno
(
self
):
# Issue #24489: check a previously set C errno doesn't disturb polar()
from
_testcapi
import
set_errno
def
polar_with_errno_set
(
z
):
set_errno
(
11
)
try
:
return
polar
(
z
)
finally
:
set_errno
(
0
)
self
.
check_polar
(
polar_with_errno_set
)
def
test_phase
(
self
):
self
.
assertAlmostEqual
(
phase
(
0
),
0.
)
...
...
Misc/NEWS
View file @
0d2fac1f
+++++++++++
+++++++++++
Python
News
+++++++++++
...
...
@@ -30,6 +30,8 @@ Core and Builtins
Library
-------
- Issue #24489: ensure a previously set C errno doesn'
t
disturb
cmath
.
polar
().
-
Issue
#
19543
:
io
.
TextIOWrapper
(
and
hence
io
.
open
())
now
uses
the
internal
codec
marking
system
added
to
emit
deprecation
warning
for
known
non
-
text
encodings
at
stream
construction
time
when
Python
is
ran
with
the
-
3
option
.
...
...
Modules/_testcapimodule.c
View file @
0d2fac1f
...
...
@@ -1373,6 +1373,17 @@ raise_exception(PyObject *self, PyObject *args)
return
NULL
;
}
static
PyObject
*
set_errno
(
PyObject
*
self
,
PyObject
*
args
)
{
int
new_errno
;
if
(
!
PyArg_ParseTuple
(
args
,
"i:set_errno"
,
&
new_errno
))
return
NULL
;
errno
=
new_errno
;
Py_RETURN_NONE
;
}
static
int
test_run_counter
=
0
;
...
...
@@ -2032,6 +2043,7 @@ pymarshal_read_object_from_file(PyObject* self, PyObject *args)
static
PyMethodDef
TestMethods
[]
=
{
{
"raise_exception"
,
raise_exception
,
METH_VARARGS
},
{
"set_errno"
,
set_errno
,
METH_VARARGS
},
{
"test_config"
,
(
PyCFunction
)
test_config
,
METH_NOARGS
},
{
"test_datetime_capi"
,
test_datetime_capi
,
METH_NOARGS
},
{
"test_list_api"
,
(
PyCFunction
)
test_list_api
,
METH_NOARGS
},
...
...
Modules/cmathmodule.c
View file @
0d2fac1f
...
...
@@ -941,9 +941,10 @@ cmath_polar(PyObject *self, PyObject *args)
double
r
,
phi
;
if
(
!
PyArg_ParseTuple
(
args
,
"D:polar"
,
&
z
))
return
NULL
;
errno
=
0
;
PyFPE_START_PROTECT
(
"polar function"
,
return
0
)
phi
=
c_atan2
(
z
);
/* should not cause any exception */
r
=
c_abs
(
z
);
/* sets errno to ERANGE on overflow
; otherwise 0
*/
r
=
c_abs
(
z
);
/* sets errno to ERANGE on overflow */
PyFPE_END_PROTECT
(
r
)
if
(
errno
!=
0
)
return
math_error
();
...
...
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