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
9b7cc754
Commit
9b7cc754
authored
May 14, 2009
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Complex negation
parent
3bd0078f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
6 deletions
+11
-6
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+7
-2
tests/run/complex_numbers_T305.pyx
tests/run/complex_numbers_T305.pyx
+4
-4
No files found.
Cython/Compiler/ExprNodes.py
View file @
9b7cc754
...
@@ -3706,6 +3706,7 @@ class UnopNode(ExprNode):
...
@@ -3706,6 +3706,7 @@ class UnopNode(ExprNode):
# - Allocate temporary for result if needed.
# - Allocate temporary for result if needed.
subexprs
=
[
'operand'
]
subexprs
=
[
'operand'
]
infix
=
True
def
calculate_constant_result
(
self
):
def
calculate_constant_result
(
self
):
func
=
compile_time_unary_operators
[
self
.
operator
]
func
=
compile_time_unary_operators
[
self
.
operator
]
...
@@ -3820,13 +3821,17 @@ class UnaryMinusNode(UnopNode):
...
@@ -3820,13 +3821,17 @@ class UnaryMinusNode(UnopNode):
self
.
type
=
self
.
operand
.
type
self
.
type
=
self
.
operand
.
type
else
:
else
:
self
.
type_error
()
self
.
type_error
()
if
self
.
type
.
is_complex
:
self
.
infix
=
env
.
directives
[
'c99_complex'
]
def
py_operation_function
(
self
):
def
py_operation_function
(
self
):
return
"PyNumber_Negative"
return
"PyNumber_Negative"
def
calculate_result_code
(
self
):
def
calculate_result_code
(
self
):
return
"(-%s)"
%
self
.
operand
.
result
()
if
self
.
infix
:
return
"(-%s)"
%
self
.
operand
.
result
()
else
:
return
"%s(%s)"
%
(
self
.
operand
.
type
.
unary_op
(
'-'
),
self
.
operand
.
result
())
class
TildeNode
(
UnopNode
):
class
TildeNode
(
UnopNode
):
# unary '~' operator
# unary '~' operator
...
...
tests/run/complex_numbers_T305.pyx
View file @
9b7cc754
...
@@ -5,11 +5,11 @@ __doc__ = u"""
...
@@ -5,11 +5,11 @@ __doc__ = u"""
(-0.5+2j)
(-0.5+2j)
>>> test_arithmetic(2j, 4j)
>>> test_arithmetic(2j, 4j)
(6j, -2j, (-8+0j), (0.5+0j))
(
-2j,
6j, -2j, (-8+0j), (0.5+0j))
>>> test_arithmetic(6+12j, 3j)
>>> test_arithmetic(6+12j, 3j)
((6+15j), (6+9j), (-36+18j), (4-2j))
((
-6-12j), (
6+15j), (6+9j), (-36+18j), (4-2j))
>>> test_arithmetic(5-10j, 3+4j)
>>> test_arithmetic(5-10j, 3+4j)
((8-6j), (2-14j), (55-10j), (-1-2j))
((
-5+10j), (
8-6j), (2-14j), (55-10j), (-1-2j))
>>> test_div_by_zero(4j)
>>> test_div_by_zero(4j)
-0.25j
-0.25j
...
@@ -57,7 +57,7 @@ def test_object_conversion(o):
...
@@ -57,7 +57,7 @@ def test_object_conversion(o):
return
z
return
z
def
test_arithmetic
(
double
complex
z
,
double
complex
w
):
def
test_arithmetic
(
double
complex
z
,
double
complex
w
):
return
z
+
w
,
z
-
w
,
z
*
w
,
z
/
w
return
-
z
,
z
+
w
,
z
-
w
,
z
*
w
,
z
/
w
@
cython
.
cdivision
(
False
)
@
cython
.
cdivision
(
False
)
def
test_div_by_zero
(
double
complex
z
):
def
test_div_by_zero
(
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