Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: arbitrary long integer aritmetics

Reply
Thread Tools

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>




 
Reply With Quote
 
 
 
 
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
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.maxint

2147483647
>>> 2147483647 * 2147483647 * 2147483647

9903520300447984150353281023L



 
Reply With Quote
 
 
 
 
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Size of Integer , long Integer, Long double Suresh V C++ 5 07-05-2010 08:09 AM
Having compilation error: no match for call to (const __gnu_cxx::hash<long long int>) (const long long int&) veryhotsausage C++ 1 07-04-2008 05:41 PM
calling an arbitrary function w/ arbitrary arguments Honestmath C++ 5 12-13-2004 06:18 AM
Re: long long integer and double precision number cyberdude C Programming 2 06-25-2003 07:54 PM
Re: long long integer and double precision number Dan Pop C Programming 0 06-24-2003 12:11 PM



Advertisments