python - OverflowError occurs when using cython with a large int -


python 3.4, windows 10, cython 0.21.1

i'm compiling function c cython

def weakchecksum(data):    """    generates weak checksum iterable set of bytes.    """    cdef long a, b, l    = b = 0    l = len(data)    in range(l):        += data[i]        b += (l - i)*data[i]     return (b << 16) | a, a, b 

which produces error: "overflowerror: python int large convert c long"

i've tried declaring them unsigned longs. type use work large numbers? if it's large c long there workarounds?

if make sure calculations in c (for instance, declare long, , put data element cdefed variable or cast before calculation), won't error. actual results, though, vary depending on platform, depending (potentially) on exact assembly code generated , resulting treatment of overflows. there better algorithms this, @cod3monk3y has noted (look @ "simple checksums" link).


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -