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
Boxiang Sun
cython
Commits
8c9d947e
Commit
8c9d947e
authored
Mar 25, 2009
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cython.cdiv and cython.cmod for CEP 516
parent
a60c7801
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
11 deletions
+40
-11
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+19
-11
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+12
-0
tests/run/cdivision_CEP_516.pyx
tests/run/cdivision_CEP_516.pyx
+9
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
8c9d947e
...
@@ -4232,7 +4232,11 @@ class MulNode(NumBinopNode):
...
@@ -4232,7 +4232,11 @@ class MulNode(NumBinopNode):
class
DivNode
(
NumBinopNode
):
class
DivNode
(
NumBinopNode
):
# '/' or '//' operator.
# '/' or '//' operator.
cdivision
=
None
def
generate_evaluation_code
(
self
,
code
):
def
generate_evaluation_code
(
self
,
code
):
if
not
self
.
type
.
is_pyobject
:
if
self
.
cdivision
is
None
:
self
.
cdivision
=
(
code
.
globalstate
.
directives
[
'cdivision'
]
self
.
cdivision
=
(
code
.
globalstate
.
directives
[
'cdivision'
]
or
not
self
.
type
.
signed
or
not
self
.
type
.
signed
or
self
.
type
.
is_float
)
or
self
.
type
.
is_float
)
...
@@ -4255,12 +4259,16 @@ class DivNode(NumBinopNode):
...
@@ -4255,12 +4259,16 @@ class DivNode(NumBinopNode):
class
ModNode
(
NumBinopNode
):
class
ModNode
(
NumBinopNode
):
# '%' operator.
# '%' operator.
cdivision
=
None
def
is_py_operation
(
self
):
def
is_py_operation
(
self
):
return
(
self
.
operand1
.
type
.
is_string
return
(
self
.
operand1
.
type
.
is_string
or
self
.
operand2
.
type
.
is_string
or
self
.
operand2
.
type
.
is_string
or
NumBinopNode
.
is_py_operation
(
self
))
or
NumBinopNode
.
is_py_operation
(
self
))
def
generate_evaluation_code
(
self
,
code
):
def
generate_evaluation_code
(
self
,
code
):
if
not
self
.
type
.
is_pyobject
:
if
self
.
cdivision
is
None
:
self
.
cdivision
=
code
.
globalstate
.
directives
[
'cdivision'
]
or
not
self
.
type
.
signed
self
.
cdivision
=
code
.
globalstate
.
directives
[
'cdivision'
]
or
not
self
.
type
.
signed
if
not
self
.
cdivision
:
if
not
self
.
cdivision
:
math_h_modifier
=
getattr
(
self
.
type
,
'math_h_modifier'
,
'__Pyx_INT'
)
math_h_modifier
=
getattr
(
self
.
type
,
'math_h_modifier'
,
'__Pyx_INT'
)
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
8c9d947e
...
@@ -951,6 +951,18 @@ class TransformBuiltinMethods(EnvTransform):
...
@@ -951,6 +951,18 @@ class TransformBuiltinMethods(EnvTransform):
error
(
node
.
function
.
pos
,
u"sizeof takes exactly one argument"
%
function
)
error
(
node
.
function
.
pos
,
u"sizeof takes exactly one argument"
%
function
)
else
:
else
:
node
=
AmpersandNode
(
node
.
function
.
pos
,
operand
=
node
.
args
[
0
])
node
=
AmpersandNode
(
node
.
function
.
pos
,
operand
=
node
.
args
[
0
])
elif
function
==
'cmod'
:
if
len
(
node
.
args
)
!=
2
:
error
(
node
.
function
.
pos
,
u"cmod takes exactly one argument"
%
function
)
else
:
node
=
binop_node
(
node
.
function
.
pos
,
'%'
,
node
.
args
[
0
],
node
.
args
[
1
])
node
.
cdivision
=
True
elif
function
==
'cdiv'
:
if
len
(
node
.
args
)
!=
2
:
error
(
node
.
function
.
pos
,
u"cmod takes exactly one argument"
%
function
)
else
:
node
=
binop_node
(
node
.
function
.
pos
,
'/'
,
node
.
args
[
0
],
node
.
args
[
1
])
node
.
cdivision
=
True
else
:
else
:
error
(
node
.
function
.
pos
,
u"'%s' not a valid cython language construct"
%
function
)
error
(
node
.
function
.
pos
,
u"'%s' not a valid cython language construct"
%
function
)
...
...
tests/run/cdivision_CEP_516.pyx
View file @
8c9d947e
...
@@ -23,6 +23,9 @@ True
...
@@ -23,6 +23,9 @@ True
[1, -2, 1, -2]
[1, -2, 1, -2]
>>> [div_int_c(a, b) for a, b in v]
>>> [div_int_c(a, b) for a, b in v]
[1, -1, 1, -1]
[1, -1, 1, -1]
>>> [test_cdiv_cmod(a, b) for a, b in v]
[(1, 7), (-1, -7), (1, -7), (-1, 7)]
"""
"""
cimport
cython
cimport
cython
...
@@ -64,3 +67,9 @@ def div_int_py(int a, int b):
...
@@ -64,3 +67,9 @@ def div_int_py(int a, int b):
def
div_int_c
(
int
a
,
int
b
):
def
div_int_c
(
int
a
,
int
b
):
return
a
//
b
return
a
//
b
@
cython
.
cdivision
(
False
)
def
test_cdiv_cmod
(
short
a
,
short
b
):
cdef
short
q
=
cython
.
cdiv
(
a
,
b
)
cdef
short
r
=
cython
.
cmod
(
a
,
b
)
return
q
,
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