Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: arbitrary long integer aritmetics (http://www.velocityreviews.com/forums/t319125-re-arbitrary-long-integer-aritmetics.html)

Fredrik Lundh 07-02-2003 10:05 AM

Re: arbitrary long integer aritmetics
 
"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 07-02-2003 04:40 PM

Re: arbitrary long integer aritmetics
 
"Fredrik Lundh" <fredrik@pythonware.com> 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
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.maxint

2147483647
>>> 2147483647 * 2147483647 * 2147483647

9903520300447984150353281023L




Erik Max Francis 07-02-2003 10:14 PM

Re: arbitrary long integer aritmetics
 
Russell Reagan wrote:

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


All times are GMT. The time now is 09:08 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.