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
7fc33f75
Commit
7fc33f75
authored
Apr 03, 2015
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
calculate 2**N in PY_LONG_LONG if it's larger than long and the value fits
parent
bcbdbb10
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
0 deletions
+7
-0
Cython/Utility/Optimize.c
Cython/Utility/Optimize.c
+3
-0
tests/run/powop.pyx
tests/run/powop.pyx
+4
-0
No files found.
Cython/Utility/Optimize.c
View file @
7fc33f75
...
...
@@ -470,6 +470,9 @@ static PyObject* __Pyx__PyNumber_PowerOf2(PyObject *two, PyObject *exp, PyObject
if
((
size_t
)
shiftby
<=
sizeof
(
long
)
*
8
-
2
)
{
long
value
=
1L
<<
shiftby
;
return
PyInt_FromLong
(
value
);
}
else
if
((
size_t
)
shiftby
<=
sizeof
(
unsigned
PY_LONG_LONG
)
*
8
-
1
)
{
unsigned
PY_LONG_LONG
value
=
((
unsigned
PY_LONG_LONG
)
1
)
<<
shiftby
;
return
PyLong_FromUnsignedLongLong
(
value
);
}
else
{
PyObject
*
one
=
PyInt_FromLong
(
1L
);
if
(
unlikely
(
!
one
))
return
NULL
;
...
...
tests/run/powop.pyx
View file @
7fc33f75
...
...
@@ -107,6 +107,10 @@ def optimised_pow2(n):
1073741824
>>> print(repr(optimised_pow2(32)).rstrip('L'))
4294967296
>>> print(repr(optimised_pow2(60)).rstrip('L'))
1152921504606846976
>>> print(repr(optimised_pow2(64)).rstrip('L'))
18446744073709551616
>>> print(repr(optimised_pow2(100)).rstrip('L'))
1267650600228229401496703205376
>>> optimised_pow2(30000) == 2 ** 30000
...
...
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