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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
6880c0a0
Commit
6880c0a0
authored
Jul 18, 2017
by
Robert Bradshaw
Committed by
GitHub
Jul 18, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1778 from scoder/compile_time_complex
Repair compile time complex expressions
parents
3bac3dd7
ead8f773
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 @
6880c0a0
...
@@ -1649,15 +1649,15 @@ class IdentifierStringNode(StringNode):
...
@@ -1649,15 +1649,15 @@ class IdentifierStringNode(StringNode):
class
ImagNode
(
AtomicExprNode
):
class
ImagNode
(
AtomicExprNode
):
# Imaginary number literal
# Imaginary number literal
#
#
# value
float imaginary part
# value
string imaginary part (float value)
type
=
PyrexTypes
.
c_double_complex_type
type
=
PyrexTypes
.
c_double_complex_type
def
calculate_constant_result
(
self
):
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
):
def
compile_time_value
(
self
,
denv
):
return
complex
(
0.0
,
self
.
value
)
return
complex
(
0.0
,
float
(
self
.
value
)
)
def
analyse_types
(
self
,
env
):
def
analyse_types
(
self
,
env
):
self
.
type
.
create_declaration_utility_code
(
env
)
self
.
type
.
create_declaration_utility_code
(
env
)
...
...
Cython/Compiler/Parsing.py
View file @
6880c0a0
...
@@ -771,6 +771,15 @@ def wrap_compile_time_constant(pos, value):
...
@@ -771,6 +771,15 @@ def wrap_compile_time_constant(pos, value):
return
ExprNodes
.
IntNode
(
pos
,
value
=
rep
,
constant_result
=
value
)
return
ExprNodes
.
IntNode
(
pos
,
value
=
rep
,
constant_result
=
value
)
elif
isinstance
(
value
,
float
):
elif
isinstance
(
value
,
float
):
return
ExprNodes
.
FloatNode
(
pos
,
value
=
rep
,
constant_result
=
value
)
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
):
elif
isinstance
(
value
,
_unicode
):
return
ExprNodes
.
UnicodeNode
(
pos
,
value
=
EncodedString
(
value
))
return
ExprNodes
.
UnicodeNode
(
pos
,
value
=
EncodedString
(
value
))
elif
isinstance
(
value
,
_bytes
):
elif
isinstance
(
value
,
_bytes
):
...
...
tests/run/complex_numbers_T305.pyx
View file @
6880c0a0
...
@@ -4,6 +4,8 @@ from cpython.object cimport Py_EQ, Py_NE
...
@@ -4,6 +4,8 @@ from cpython.object cimport Py_EQ, Py_NE
cimport
cython
cimport
cython
DEF
C21
=
2
-
1j
cdef
class
Complex3j
:
cdef
class
Complex3j
:
"""
"""
...
@@ -137,15 +139,17 @@ def test_coercion(int a, float b, double c, float complex d, double complex e):
...
@@ -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
):
def
test_compare
(
double
complex
a
,
double
complex
b
):
"""
"""
>>> test_compare(3, 3)
>>> test_compare(3, 3)
(True, False, False, False, False, True)
(True, False, False, False, False, True
, False
)
>>> test_compare(3j, 3j)
>>> test_compare(3j, 3j)
(True, False, True, True, True, False)
(True, False, True, True, True, False
, False
)
>>> test_compare(3j, 4j)
>>> test_compare(3j, 4j)
(False, True, True, False, True, True)
(False, True, True, False, True, True
, False
)
>>> test_compare(3, 4)
>>> 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
):
def
test_compare_coerce
(
double
complex
a
,
int
b
):
...
@@ -165,9 +169,10 @@ 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
():
def
test_literal
():
"""
"""
>>> 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
):
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