Re: arbitrary long integer aritmetics

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

  1. "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
    #1
    1. Advertising

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

    2147483647
    >>> 2147483647 * 2147483647 * 2147483647

    9903520300447984150353281023L
     
    Russell Reagan, Jul 2, 2003
    #2
    1. Advertising

  3. 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
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Honestmath
    Replies:
    5
    Views:
    559
    Honestmath
    Dec 13, 2004
  2. Dan Pop
    Replies:
    0
    Views:
    1,183
    Dan Pop
    Jun 24, 2003
  3. cyberdude
    Replies:
    2
    Views:
    5,129
    Keith Thompson
    Jun 25, 2003
  4. music4
    Replies:
    3
    Views:
    914
    CBFalconer
    Jan 5, 2004
  5. Suresh V
    Replies:
    5
    Views:
    3,731
    SaticCaster
    Jul 5, 2010
Loading...

Share This Page