Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
ead8f773
Commit
ead8f773
authored
Jul 17, 2017
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
repair compile time evaluation of complex numbers
parent
99c86175
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
10 deletions
+24
-10
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+3
-3
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+9
-0
tests/run/complex_numbers_T305.pyx
tests/run/complex_numbers_T305.pyx
+12
-7
No files found.
Cython/Compiler/ExprNodes.py
View file @
ead8f773
...
...
@@ -1649,15 +1649,15 @@ class IdentifierStringNode(StringNode):
class
ImagNode
(
AtomicExprNode
):
# Imaginary number literal
#
# value
float imaginary part
# value
string imaginary part (float value)
type
=
PyrexTypes
.
c_double_complex_type
def
calculate_constant_result
(
self
):
self
.
constant_result
=
complex
(
0.0
,
self
.
value
)
self
.
constant_result
=
complex
(
0.0
,
float
(
self
.
value
)
)
def
compile_time_value
(
self
,
denv
):
return
complex
(
0.0
,
self
.
value
)
return
complex
(
0.0
,
float
(
self
.
value
)
)
def
analyse_types
(
self
,
env
):
self
.
type
.
create_declaration_utility_code
(
env
)
...
...
Cython/Compiler/Parsing.py
View file @
ead8f773
...
...
@@ -771,6 +771,15 @@ def wrap_compile_time_constant(pos, value):
return
ExprNodes
.
IntNode
(
pos
,
value
=
rep
,
constant_result
=
value
)
elif
isinstance
(
value
,
float
):
return
ExprNodes
.
FloatNode
(
pos
,
value
=
rep
,
constant_result
=
value
)
elif
isinstance
(
value
,
complex
):
node
=
ExprNodes
.
ImagNode
(
pos
,
value
=
repr
(
value
.
imag
),
constant_result
=
complex
(
0.0
,
value
.
imag
))
if
value
.
real
:
# FIXME: should we care about -0.0 ?
# probably not worth using the '-' operator for negative imag values
node
=
ExprNodes
.
binop_node
(
pos
,
'+'
,
ExprNodes
.
FloatNode
(
pos
,
value
=
repr
(
value
.
real
),
constant_result
=
value
.
real
),
node
,
constant_result
=
value
)
return
node
elif
isinstance
(
value
,
_unicode
):
return
ExprNodes
.
UnicodeNode
(
pos
,
value
=
EncodedString
(
value
))
elif
isinstance
(
value
,
_bytes
):
...
...
tests/run/complex_numbers_T305.pyx
View file @
ead8f773
...
...
@@ -4,6 +4,8 @@ from cpython.object cimport Py_EQ, Py_NE
cimport
cython
DEF
C21
=
2
-
1j
cdef
class
Complex3j
:
"""
...
...
@@ -137,15 +139,17 @@ def test_coercion(int a, float b, double c, float complex d, double complex e):
def
test_compare
(
double
complex
a
,
double
complex
b
):
"""
>>> test_compare(3, 3)
(True, False, False, False, False, True)
(True, False, False, False, False, True
, False
)
>>> test_compare(3j, 3j)
(True, False, True, True, True, False)
(True, False, True, True, True, False
, False
)
>>> test_compare(3j, 4j)
(False, True, True, False, True, True)
(False, True, True, False, True, True
, False
)
>>> test_compare(3, 4)
(False, True, False, False, False, True)
(False, True, False, False, False, True, False)
>>> test_compare(2-1j, 4)
(False, True, False, False, False, True, True)
"""
return
a
==
b
,
a
!=
b
,
a
==
3j
,
3j
==
b
,
a
==
Complex3j
(),
Complex3j
()
!=
b
return
a
==
b
,
a
!=
b
,
a
==
3j
,
3j
==
b
,
a
==
Complex3j
(),
Complex3j
()
!=
b
,
a
==
C21
def
test_compare_coerce
(
double
complex
a
,
int
b
):
...
...
@@ -165,9 +169,10 @@ def test_compare_coerce(double complex a, int b):
def
test_literal
():
"""
>>> test_literal()
(5j, (1-2.5j))
(5j, (1-2.5j)
, (2-1j)
)
"""
return
5j
,
1
-
2.5j
return
5j
,
1
-
2.5j
,
C21
def
test_real_imag
(
double
complex
z
):
"""
...
...
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