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
759920c5
Commit
759920c5
authored
Oct 10, 2014
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Plain Diff
Issue #22604: Fix assertion error in debug mode when dividing a complex number by (nan+0j).
parents
fc260a9a
9086f926
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
4 deletions
+16
-4
Lib/test/test_complex.py
Lib/test/test_complex.py
+7
-2
Misc/NEWS
Misc/NEWS
+3
-0
Objects/complexobject.c
Objects/complexobject.c
+6
-2
No files found.
Lib/test/test_complex.py
View file @
759920c5
...
@@ -27,7 +27,7 @@ class ComplexTest(unittest.TestCase):
...
@@ -27,7 +27,7 @@ class ComplexTest(unittest.TestCase):
unittest
.
TestCase
.
assertAlmostEqual
(
self
,
a
,
b
)
unittest
.
TestCase
.
assertAlmostEqual
(
self
,
a
,
b
)
def
assertCloseAbs
(
self
,
x
,
y
,
eps
=
1e-9
):
def
assertCloseAbs
(
self
,
x
,
y
,
eps
=
1e-9
):
"""Return true iff floats x and y "are close
\
"
"""
"""Return true iff floats x and y "are close
".
"""
# put the one with larger magnitude second
# put the one with larger magnitude second
if
abs
(
x
)
>
abs
(
y
):
if
abs
(
x
)
>
abs
(
y
):
x
,
y
=
y
,
x
x
,
y
=
y
,
x
...
@@ -62,7 +62,7 @@ class ComplexTest(unittest.TestCase):
...
@@ -62,7 +62,7 @@ class ComplexTest(unittest.TestCase):
self
.
fail
(
msg
.
format
(
x
,
y
))
self
.
fail
(
msg
.
format
(
x
,
y
))
def
assertClose
(
self
,
x
,
y
,
eps
=
1e-9
):
def
assertClose
(
self
,
x
,
y
,
eps
=
1e-9
):
"""Return true iff complexes x and y "are close
\
"
"""
"""Return true iff complexes x and y "are close
".
"""
self
.
assertCloseAbs
(
x
.
real
,
y
.
real
,
eps
)
self
.
assertCloseAbs
(
x
.
real
,
y
.
real
,
eps
)
self
.
assertCloseAbs
(
x
.
imag
,
y
.
imag
,
eps
)
self
.
assertCloseAbs
(
x
.
imag
,
y
.
imag
,
eps
)
...
@@ -104,6 +104,11 @@ class ComplexTest(unittest.TestCase):
...
@@ -104,6 +104,11 @@ class ComplexTest(unittest.TestCase):
self
.
assertAlmostEqual
(
complex
.
__truediv__
(
2
+
0j
,
1
+
1j
),
1
-
1j
)
self
.
assertAlmostEqual
(
complex
.
__truediv__
(
2
+
0j
,
1
+
1j
),
1
-
1j
)
self
.
assertRaises
(
ZeroDivisionError
,
complex
.
__truediv__
,
1
+
1j
,
0
+
0j
)
self
.
assertRaises
(
ZeroDivisionError
,
complex
.
__truediv__
,
1
+
1j
,
0
+
0j
)
for
denom_real
,
denom_imag
in
[(
0
,
NAN
),
(
NAN
,
0
),
(
NAN
,
NAN
)]:
z
=
complex
(
0
,
0
)
/
complex
(
denom_real
,
denom_imag
)
self
.
assertTrue
(
isnan
(
z
.
real
))
self
.
assertTrue
(
isnan
(
z
.
imag
))
def
test_floordiv
(
self
):
def
test_floordiv
(
self
):
self
.
assertRaises
(
TypeError
,
complex
.
__floordiv__
,
3
+
0j
,
1.5
+
0j
)
self
.
assertRaises
(
TypeError
,
complex
.
__floordiv__
,
3
+
0j
,
1.5
+
0j
)
self
.
assertRaises
(
TypeError
,
complex
.
__floordiv__
,
3
+
0j
,
0
+
0j
)
self
.
assertRaises
(
TypeError
,
complex
.
__floordiv__
,
3
+
0j
,
0
+
0j
)
...
...
Misc/NEWS
View file @
759920c5
...
@@ -10,6 +10,9 @@ Release date: TBA
...
@@ -10,6 +10,9 @@ Release date: TBA
Core and Builtins
Core and Builtins
-----------------
-----------------
- Issue #22604: Fix assertion error in debug mode when dividing a complex
number by (nan+0j).
- Issue #20152: Convert the array module to Argument Clinic.
- Issue #20152: Convert the array module to Argument Clinic.
- Issue #21052: Do not raise ImportWarning when sys.path_hooks or sys.meta_path
- Issue #21052: Do not raise ImportWarning when sys.path_hooks or sys.meta_path
...
...
Objects/complexobject.c
View file @
759920c5
...
@@ -78,7 +78,7 @@ _Py_c_quot(Py_complex a, Py_complex b)
...
@@ -78,7 +78,7 @@ _Py_c_quot(Py_complex a, Py_complex b)
const
double
abs_breal
=
b
.
real
<
0
?
-
b
.
real
:
b
.
real
;
const
double
abs_breal
=
b
.
real
<
0
?
-
b
.
real
:
b
.
real
;
const
double
abs_bimag
=
b
.
imag
<
0
?
-
b
.
imag
:
b
.
imag
;
const
double
abs_bimag
=
b
.
imag
<
0
?
-
b
.
imag
:
b
.
imag
;
if
(
abs_breal
>=
abs_bimag
)
{
if
(
abs_breal
>=
abs_bimag
)
{
/* divide tops and bottom by b.real */
/* divide tops and bottom by b.real */
if
(
abs_breal
==
0
.
0
)
{
if
(
abs_breal
==
0
.
0
)
{
errno
=
EDOM
;
errno
=
EDOM
;
...
@@ -91,7 +91,7 @@ _Py_c_quot(Py_complex a, Py_complex b)
...
@@ -91,7 +91,7 @@ _Py_c_quot(Py_complex a, Py_complex b)
r
.
imag
=
(
a
.
imag
-
a
.
real
*
ratio
)
/
denom
;
r
.
imag
=
(
a
.
imag
-
a
.
real
*
ratio
)
/
denom
;
}
}
}
}
else
{
else
if
(
abs_bimag
>=
abs_breal
)
{
/* divide tops and bottom by b.imag */
/* divide tops and bottom by b.imag */
const
double
ratio
=
b
.
real
/
b
.
imag
;
const
double
ratio
=
b
.
real
/
b
.
imag
;
const
double
denom
=
b
.
real
*
ratio
+
b
.
imag
;
const
double
denom
=
b
.
real
*
ratio
+
b
.
imag
;
...
@@ -99,6 +99,10 @@ _Py_c_quot(Py_complex a, Py_complex b)
...
@@ -99,6 +99,10 @@ _Py_c_quot(Py_complex a, Py_complex b)
r
.
real
=
(
a
.
real
*
ratio
+
a
.
imag
)
/
denom
;
r
.
real
=
(
a
.
real
*
ratio
+
a
.
imag
)
/
denom
;
r
.
imag
=
(
a
.
imag
*
ratio
-
a
.
real
)
/
denom
;
r
.
imag
=
(
a
.
imag
*
ratio
-
a
.
real
)
/
denom
;
}
}
else
{
/* At least one of b.real or b.imag is a NaN */
r
.
real
=
r
.
imag
=
Py_NAN
;
}
return
r
;
return
r
;
}
}
...
...
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