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
d81d4326
Commit
d81d4326
authored
May 27, 2019
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix C++ division when true division is enabled.
This fixes Github issue #1950.
parent
5a8c077a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
6 deletions
+8
-6
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+2
-2
tests/run/cpp_operators.pyx
tests/run/cpp_operators.pyx
+6
-4
No files found.
Cython/Compiler/ExprNodes.py
View file @
d81d4326
...
...
@@ -11532,7 +11532,7 @@ class DivNode(NumBinopNode):
self
.
operand2
=
self
.
operand2
.
coerce_to_simple
(
env
)
def
compute_c_result_type
(
self
,
type1
,
type2
):
if
self
.
operator
==
'/'
and
self
.
ctruedivision
:
if
self
.
operator
==
'/'
and
self
.
ctruedivision
and
not
self
.
is_cpp_operation
()
:
if
not
type1
.
is_float
and
not
type2
.
is_float
:
widest_type
=
PyrexTypes
.
widest_numeric_type
(
type1
,
PyrexTypes
.
c_double_type
)
widest_type
=
PyrexTypes
.
widest_numeric_type
(
type2
,
widest_type
)
...
...
@@ -11623,7 +11623,7 @@ class DivNode(NumBinopNode):
code
.
putln
(
"}"
)
def
calculate_result_code
(
self
):
if
self
.
type
.
is_complex
:
if
self
.
type
.
is_complex
or
self
.
is_cpp_operation
()
:
return
NumBinopNode
.
calculate_result_code
(
self
)
elif
self
.
type
.
is_float
and
self
.
operator
==
'//'
:
return
"floor(%s / %s)"
%
(
...
...
tests/run/cpp_operators.pyx
View file @
d81d4326
# mode: run
# tag: cpp, werror
from
__future__
import
division
from
cython
cimport
typeof
cimport
cython.operator
...
...
@@ -239,7 +241,7 @@ def test_nonmember_binop():
nonmember binary2 >> [const_char *]
nonmember binary2 COMMA [const_char *]
"""
cdef
TestOps
*
t
=
new
TestOps
()
out
(
1
+
t
[
0
],
typeof
(
1
+
t
[
0
]))
out
(
1
-
t
[
0
],
typeof
(
1
-
t
[
0
]))
...
...
@@ -251,10 +253,10 @@ def test_nonmember_binop():
out
(
1
^
t
[
0
],
typeof
(
1
^
t
[
0
]))
out
(
1
<<
t
[
0
],
typeof
(
1
<<
t
[
0
]))
out
(
1
>>
t
[
0
],
typeof
(
1
>>
t
[
0
]))
x
=
cython
.
operator
.
comma
(
1
,
t
[
0
])
out
(
x
,
typeof
(
x
))
# now test float operators defined outside class
out
(
1.
+
t
[
0
],
typeof
(
1.
+
t
[
0
]))
# operator - deliberately omitted
...
...
@@ -266,7 +268,7 @@ def test_nonmember_binop():
out
(
1.
^
t
[
0
],
typeof
(
1.
^
t
[
0
]))
out
(
1.
<<
t
[
0
],
typeof
(
1.
<<
t
[
0
]))
out
(
1.
>>
t
[
0
],
typeof
(
1.
>>
t
[
0
]))
# for some reason we need a cdef here - not sure this is quite right
y
=
cython
.
operator
.
comma
(
1.
,
t
[
0
])
out
(
y
,
typeof
(
y
))
...
...
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