# Re: arbitrary long integer aritmetics

Discussion in 'Python' started by Fredrik Lundh, Jul 2, 2003.

1. ### Fredrik LundhGuest

"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>

Fredrik Lundh, Jul 2, 2003

2. ### Russell ReaganGuest

"Fredrik Lundh" <> 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

Russell Reagan, Jul 2, 2003

3. ### Erik Max FrancisGuest

Russell Reagan wrote:

> "Fredrik Lundh" <> 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.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ Divorces are made in Heaven.
\__/ Oscar Wilde

Erik Max Francis, Jul 2, 2003