Integer Overflow
Ursus Horibilis
ursus_horibilis at hotmail.com
Tue Nov 27 13:41:24 EST 2001
"Michael Hudson" <mwh at python.net> wrote in message
news:u8zcst6uj.fsf at python.net...
> "Ursus Horibilis" <ursus_horibilis at hotmail.com> writes:
>
> > Okay. My next project was to do the same thing with 64-bit
> > numbers.
>
> This makes a difference how, exactly?
It doesn't make a difference; that was the point!
>
> > So how do I disable trapping for integer overflow?
>
> You can't, in the way you want anyway.
>
> You could always write a class that uses longs and chops off
all but
> the first n bits of the result. This wouldn't do performance
any
> favours, I uspect.
It sounds like such algorithms must be written in C or some
other language and then integrated into the Python program.
>
> Not that in 2.1:
>
> >>> 2*sys.maxint
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> OverflowError: integer multiplication
>
> but in 2.2:
>
> >>> 2*sys.maxint
> 4294967294L
>
At the moment, I'm working with 2.0. Is it legal to assign a
(long) to an (int) if the long contains a number that is bigger
than the (int) can store?
More information about the Python-list
mailing list