Non-arbitrary integer math

mykroft gregczajkowski at
Wed Oct 3 20:59:20 CEST 2001

Skip Montanaro <skip at> wrote in message news:<mailman.1002056223.23802.python-list at>...
> mykroft> I've tried searching "the vaults" and previous c.l.p posts,
>     mykroft> without much success. The struct and array module's won't do
>     mykroft> either.
> Why won't struct or array work?  Have you looked at NumPy?

Array is close, but there are several problems with it. It only
supports upto 4-byte signed/unsigned integers. On some platforms this
could be upto 8 (Python Essential Reference p.127), and thus not

All individual numbers
would have to be treated as arrays or an element of an array. Unless I
wrote a wrapper class around each type.

And also they are not true integers in the C sense.

>>> a = array.array('B', [255])
>>> a[0] += 1
Traceback (innermost last):
  File "<interactive input>", line 1, in ?
OverflowError: unsigned byte integer is greater than maximum

ie. There is no wrap-around.

Ive looked at Numpy before, but it was missing most of the unsigned
types, it only has unsigned 1-byte.

The struct module is not used for math operations.

Thanks for the reply though. But Im still stuck for now.

More information about the Python-list mailing list