Velocity Reviews > Re: arbitrary long integer aritmetics

Re: arbitrary long integer aritmetics

Fredrik Lundh
Guest
Posts: n/a

 07-02-2003
"Leo" wrote:

> is there a python module around allow using arbitrary long integers?

nope, but it's built into the language:

http://www.python.org/doc/current/ref/integers.html
http://www.python.org/doc/current/ref/types.html

> i.e. the result of an integer operation is as long as necessary, so that a*b
> never produces an overflow error.

what's an overflow error?

\$ python
Python 2.2
>>> import sys
>>> sys.maxint

2147483647
>>> 2147483647 * 2147483647 * 2147483647

4611686014132420609L

(note the trailing L).

</F>

Russell Reagan
Guest
Posts: n/a

 07-02-2003
"Fredrik Lundh" <(E-Mail Removed)> wrote

> \$ python
> Python 2.2
> >>> import sys
> >>> sys.maxint

> 2147483647
> >>> 2147483647 * 2147483647 * 2147483647

> 4611686014132420609L
>
> (note the trailing L).

Oddly, I get a different answer than you. What's the problem?

\$ python
Python 2.2.3 (#1, Jun 19 2003, 12:10:13)
[GCC 3.2 20020927 (prerelease)] on cygwin
>>> import sys
>>> sys.maxint

2147483647
>>> 2147483647 * 2147483647 * 2147483647

9903520300447984150353281023L

Erik Max Francis
Guest
Posts: n/a

 07-02-2003
Russell Reagan wrote:

> "Fredrik Lundh" <(E-Mail Removed)> wrote
>
> > >>> 2147483647 * 2147483647 * 2147483647

> > 4611686014132420609L
> >
> > (note the trailing L).

>
> Oddly, I get a different answer than you. What's the problem?

Probably because he pasted in an incomplete transcript. The calculation
he shows is multiplying it twice, not three times:

>>> x = 2147483647L
>>> x**2

4611686014132420609L
>>> x**3

9903520300447984150353281023L

--
Erik Max Francis && http://www.velocityreviews.com/forums/(E-Mail Removed) && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ Divorces are made in Heaven.
\__/ Oscar Wilde