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
f2fd034c
Commit
f2fd034c
authored
May 16, 2014
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prevent "2**intsubtype" from being incorrectly optimised if intsubtype overrides __rpow__()
parent
c8724307
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
3 deletions
+31
-3
Cython/Utility/Optimize.c
Cython/Utility/Optimize.c
+3
-3
tests/run/powop.pyx
tests/run/powop.pyx
+28
-0
No files found.
Cython/Utility/Optimize.c
View file @
f2fd034c
...
...
@@ -438,13 +438,13 @@ static PyObject* __Pyx__PyNumber_PowerOf2(PyObject *two, PyObject *exp, PyObject
static
PyObject
*
__Pyx__PyNumber_PowerOf2
(
PyObject
*
two
,
PyObject
*
exp
,
PyObject
*
none
,
int
inplace
)
{
// in CPython, 1<<N is substantially faster than 2**N
//
TODO: disable this in Py3.5 if http://bugs.python.org/issue21420 gets accepted
//
see http://bugs.python.org/issue21420
#if CYTHON_COMPILING_IN_CPYTHON
Py_ssize_t
shiftby
;
if
(
likely
(
PyLong_Check
(
exp
)))
{
if
(
likely
(
PyLong_Check
Exact
(
exp
)))
{
shiftby
=
PyLong_AsSsize_t
(
exp
);
#if PY_MAJOR_VERSION < 3
}
else
if
(
likely
(
PyInt_Check
(
exp
)))
{
}
else
if
(
likely
(
PyInt_Check
Exact
(
exp
)))
{
shiftby
=
PyInt_AsLong
(
exp
);
#endif
}
else
{
...
...
tests/run/powop.pyx
View file @
f2fd034c
...
...
@@ -67,6 +67,34 @@ def int_pow(short a, short b):
return
a
**
b
class
I
(
int
):
"""
Copied from CPython's test_descr.py
>>> I(2) ** I(3)
I(8)
>>> 2 ** I(3)
I(8)
>>> I(3).pow2()
I(8)
"""
def
__repr__
(
self
):
return
'I(%s)'
%
int
(
self
)
def
__pow__
(
self
,
other
,
mod
=
None
):
if
mod
is
None
:
return
I
(
pow
(
int
(
self
),
int
(
other
)))
else
:
return
I
(
pow
(
int
(
self
),
int
(
other
),
int
(
mod
)))
def
__rpow__
(
self
,
other
,
mod
=
None
):
if
mod
is
None
:
return
I
(
pow
(
int
(
other
),
int
(
self
),
mod
))
else
:
return
I
(
pow
(
int
(
other
),
int
(
self
),
int
(
mod
)))
def
pow2
(
self
):
return
2
**
self
def
optimised_pow2
(
n
):
"""
>>> optimised_pow2(0)
...
...
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