cpython to pyd binary - "long" converted to "int" badly before shift / division operator
See original GitHub issuecython 0.29 python 3.6.6 compiler mingw-w64 os windows 7
command used:
python setup.py build_ext --inplace
setup.py:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
extensions = [Extension("shiftoperator", ['shiftoperator.py']]
setup(
ext_modules=cythonize(extensions)
)
shiftoperator.py:
#!python
#cython: language_level=3
def longtoint():
value = 80082 # int using more than 2 bytes == long
print(value)
shiftedby3 = value>>3
dividedby8 = value//8
print(shiftedby3)
print(dividedby8)
shiftedby3 = 80082>>3
dividedby8 = 80082//8
print(shiftedby3)
print(dividedby8)
test_shift.py
import shiftoperator
shiftoperator.longtoint()
with cpython shiftoperator.py library used:
C:\scripts\tests>python test_shift.py
80082
10010
10010
10010
10010
with binary shiftoperator.cp36-win_amd64.pyd used:
C:\scripts\tests>python test_shift.py
80082
1818
1818
10010
10010
it seems the higher bit (65536 before shifting / 8192 after shifting) is dropped before the shifting process is done in case original long is saved on a variable
Can you check? Thks
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:13 (3 by maintainers)
Top Results From Across the Web
Convert integer to binary and then do a left bit shift in python
The problem is bin(i) returns a string, so I had to convert it into int but then using the shift operator shifts the...
Read more >Troubleshooting and tips — Numba 0.50.1 documentation
A common reason for Numba failing to compile (especially in nopython mode) is a type inference failure, essentially Numba cannot work out what...
Read more >Source Files and Compilation - Cython's Documentation
The cythonize command takes a .py or .pyx file and compiles it into a C/C++ file. It then compiles the C/C++ file into...
Read more >Python | Binary list to integer - GeeksforGeeks
In this method, the entire list is first converted to string and then type conversion into int and then binary number is obtained....
Read more >Representing Rational Numbers With Python Fractions
Convert between decimal and fractional notation; Perform rational number ... or a fraction, of two integers as long as the denominator is nonzero....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@gui36 I have a similar issue with my code and had a discussion in the cython-users Google group. The problem is in the header
pyport.h
, in whichSIZEOF_VOID_P
is defined based on whetherMS_WIN64
is defined or not. The solution is to pass-DMS_WIN64
when compiling with MinGW.Is there any other possibility for building Cython packages with MinGW? Or maybe official Python team needs to support something?
As MinGW is the only lightweight compiler, in comparison to VS Build Tools, it would be very useful to support it.