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
d2c94b6e
Commit
d2c94b6e
authored
Oct 22, 2009
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix in-place division in Py3
parent
a1e88e9c
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
120 additions
and
77 deletions
+120
-77
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+3
-0
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+1
-1
tests/run/future_division.pyx
tests/run/future_division.pyx
+58
-38
tests/run/non_future_division.pyx
tests/run/non_future_division.pyx
+58
-38
No files found.
Cython/Compiler/ModuleNode.py
View file @
d2c94b6e
...
...
@@ -511,11 +511,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code
.
putln
(
" #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask"
)
code
.
putln
(
" #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask"
)
code
.
putln
(
" #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y)"
)
code
.
putln
(
" #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y)"
)
code
.
putln
(
"#else"
)
if
Future
.
division
in
env
.
context
.
future_directives
:
code
.
putln
(
" #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y)"
)
code
.
putln
(
" #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y)"
)
else
:
code
.
putln
(
" #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y)"
)
code
.
putln
(
" #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y)"
)
code
.
putln
(
" #define PyBytes_Type PyString_Type"
)
code
.
putln
(
"#endif"
)
...
...
Cython/Compiler/Nodes.py
View file @
d2c94b6e
...
...
@@ -3199,7 +3199,7 @@ class InPlaceAssignmentNode(AssignmentNode):
"+"
:
"PyNumber_InPlaceAdd"
,
"-"
:
"PyNumber_InPlaceSubtract"
,
"*"
:
"PyNumber_InPlaceMultiply"
,
"/"
:
"PyNumber_InPlaceDivide"
,
"/"
:
"
__Pyx_
PyNumber_InPlaceDivide"
,
"%"
:
"PyNumber_InPlaceRemainder"
,
"<<"
:
"PyNumber_InPlaceLshift"
,
">>"
:
"PyNumber_InPlaceRshift"
,
...
...
tests/run/future_division.pyx
View file @
d2c94b6e
from
__future__
import
division
__doc__
=
u"""
>>> doit(1,2)
(0.5, 0)
>>> doit(4,3)
(1.3333333333333333, 1)
>>> doit(4,3.0)
(1.3333333333333333, 1.0)
>>> doit(4,2)
(2.0, 2)
>>> constants()
(0.5, 0, 2.5, 2.0, 2.5, 2)
>>> py_mix(1)
(0.5, 0, 0.5, 0.0, 0.5, 0)
>>> py_mix_rev(4)
(0.25, 0, 1.25, 1.0, 1.25, 1)
>>> py_mix(1.0)
(0.5, 0.0, 0.5, 0.0, 0.5, 0.0)
>>> py_mix_rev(4.0)
(0.25, 0.0, 1.25, 1.0, 1.25, 1.0)
>>> int_mix(1)
(0.5, 0, 0.5, 0.0, 0.5, 0)
>>> int_mix_rev(4)
(0.25, 0, 1.25, 1.0, 1.25, 1)
>>> float_mix(1.0)
(0.5, 0.0, 0.5, 0.0, 0.5, 0.0)
>>> float_mix_rev(4.0)
(0.25, 0.0, 1.25, 1.0, 1.25, 1.0)
"""
def
doit
(
x
,
y
):
"""
>>> doit(1,2)
(0.5, 0)
>>> doit(4,3)
(1.3333333333333333, 1)
>>> doit(4,3.0)
(1.3333333333333333, 1.0)
>>> doit(4,2)
(2.0, 2)
"""
return
x
/
y
,
x
//
y
def
doit_inplace
(
x
,
y
):
"""
>>> doit_inplace(1,2)
0.5
"""
x
/=
y
return
x
def
doit_inplace_floor
(
x
,
y
):
"""
>>> doit_inplace_floor(1,2)
0
"""
x
//=
y
return
x
def
constants
():
"""
>>> constants()
(0.5, 0, 2.5, 2.0, 2.5, 2)
"""
return
1
/
2
,
1
//
2
,
5
/
2.0
,
5
//
2.0
,
5
/
2
,
5
//
2
def
py_mix
(
a
):
"""
>>> py_mix(1)
(0.5, 0, 0.5, 0.0, 0.5, 0)
>>> py_mix(1.0)
(0.5, 0.0, 0.5, 0.0, 0.5, 0.0)
"""
return
a
/
2
,
a
//
2
,
a
/
2.0
,
a
//
2.0
,
a
/
2
,
a
//
2
def
py_mix_rev
(
a
):
"""
>>> py_mix_rev(4)
(0.25, 0, 1.25, 1.0, 1.25, 1)
>>> py_mix_rev(4.0)
(0.25, 0.0, 1.25, 1.0, 1.25, 1.0)
"""
return
1
/
a
,
1
//
a
,
5.0
/
a
,
5.0
//
a
,
5
/
a
,
5
//
a
def
int_mix
(
int
a
):
"""
>>> int_mix(1)
(0.5, 0, 0.5, 0.0, 0.5, 0)
"""
return
a
/
2
,
a
//
2
,
a
/
2.0
,
a
//
2.0
,
a
/
2
,
a
//
2
def
int_mix_rev
(
int
a
):
"""
>>> int_mix_rev(4)
(0.25, 0, 1.25, 1.0, 1.25, 1)
"""
return
1
/
a
,
1
//
a
,
5.0
/
a
,
5.0
//
a
,
5
/
a
,
5
//
a
def
float_mix
(
float
a
):
"""
>>> float_mix(1.0)
(0.5, 0.0, 0.5, 0.0, 0.5, 0.0)
"""
return
a
/
2
,
a
//
2
,
a
/
2.0
,
a
//
2.0
,
a
/
2
,
a
//
2
def
float_mix_rev
(
float
a
):
"""
>>> float_mix_rev(4.0)
(0.25, 0.0, 1.25, 1.0, 1.25, 1.0)
"""
return
1
/
a
,
1
//
a
,
5.0
/
a
,
5.0
//
a
,
5
/
a
,
5
//
a
tests/run/non_future_division.pyx
View file @
d2c94b6e
# Py2.x mixed true-div/floor-div behaviour of '/' operator
__doc__
=
u"""
>>> doit(1,2)
(0, 0)
>>> doit(4,3)
(1, 1)
>>> doit(4,3.0)
(1.3333333333333333, 1.0)
>>> doit(4,2)
(2, 2)
>>> constants()
(0, 0, 2.5, 2.0, 2, 2)
>>> py_mix(1)
(0, 0, 0.5, 0.0, 0, 0)
>>> py_mix_rev(4)
(0, 0, 1.25, 1.0, 1, 1)
>>> py_mix(1.0)
(0.5, 0.0, 0.5, 0.0, 0.5, 0.0)
>>> py_mix_rev(4.0)
(0.25, 0.0, 1.25, 1.0, 1.25, 1.0)
>>> int_mix(1)
(0, 0, 0.5, 0.0, 0, 0)
>>> int_mix_rev(4)
(0, 0, 1.25, 1.0, 1, 1)
>>> float_mix(1.0)
(0.5, 0.0, 0.5, 0.0, 0.5, 0.0)
>>> float_mix_rev(4.0)
(0.25, 0.0, 1.25, 1.0, 1.25, 1.0)
"""
def
doit
(
x
,
y
):
"""
>>> doit(1,2)
(0, 0)
>>> doit(4,3)
(1, 1)
>>> doit(4,3.0)
(1.3333333333333333, 1.0)
>>> doit(4,2)
(2, 2)
"""
return
x
/
y
,
x
//
y
def
doit_inplace
(
x
,
y
):
"""
>>> doit_inplace(1,2)
0
"""
x
/=
y
return
x
def
doit_inplace_floor
(
x
,
y
):
"""
>>> doit_inplace_floor(1,2)
0
"""
x
//=
y
return
x
def
constants
():
"""
>>> constants()
(0, 0, 2.5, 2.0, 2, 2)
"""
return
1
/
2
,
1
//
2
,
5
/
2.0
,
5
//
2.0
,
5
/
2
,
5
//
2
def
py_mix
(
a
):
"""
>>> py_mix(1)
(0, 0, 0.5, 0.0, 0, 0)
>>> py_mix(1.0)
(0.5, 0.0, 0.5, 0.0, 0.5, 0.0)
"""
return
a
/
2
,
a
//
2
,
a
/
2.0
,
a
//
2.0
,
a
/
2
,
a
//
2
def
py_mix_rev
(
a
):
"""
>>> py_mix_rev(4)
(0, 0, 1.25, 1.0, 1, 1)
>>> py_mix_rev(4.0)
(0.25, 0.0, 1.25, 1.0, 1.25, 1.0)
"""
return
1
/
a
,
1
//
a
,
5.0
/
a
,
5.0
//
a
,
5
/
a
,
5
//
a
def
int_mix
(
int
a
):
"""
>>> int_mix(1)
(0, 0, 0.5, 0.0, 0, 0)
"""
return
a
/
2
,
a
//
2
,
a
/
2.0
,
a
//
2.0
,
a
/
2
,
a
//
2
def
int_mix_rev
(
int
a
):
"""
>>> int_mix_rev(4)
(0, 0, 1.25, 1.0, 1, 1)
"""
return
1
/
a
,
1
//
a
,
5.0
/
a
,
5.0
//
a
,
5
/
a
,
5
//
a
def
float_mix
(
float
a
):
"""
>>> float_mix(1.0)
(0.5, 0.0, 0.5, 0.0, 0.5, 0.0)
"""
return
a
/
2
,
a
//
2
,
a
/
2.0
,
a
//
2.0
,
a
/
2
,
a
//
2
def
float_mix_rev
(
float
a
):
"""
>>> float_mix_rev(4.0)
(0.25, 0.0, 1.25, 1.0, 1.25, 1.0)
"""
return
1
/
a
,
1
//
a
,
5.0
/
a
,
5.0
//
a
,
5
/
a
,
5
//
a
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