maximum value for long?

Skip Montanaro skip at pobox.com
Tue Nov 18 12:43:02 EST 2003


    S> I have set ulong_max above to the C compilers ULONG_MAX definition
    S> from limits.h I would have expected Python to complain when setting
    S> the value of the variable very_long_long to anything greater than
    S> ULONG_MAX.  Since I am currently doing computations with integer
    S> values *much* bigger than ULONG_MAX, this behaviour suites me, but I
    S> am wondering if this is a "standard" Python behaviour since I do not
    S> want my scripts to become dependant on some obscure non-standard
    S> feature...

Python has a builtin unbounded long type.  In 2.3, most (all?) operations on
integers will return longs if the op would overflow the machine's int
(typically 32- or 64-bits):

    >>> print 17**100
    1108899372780783641306111715875094966436017167649879524402769841278887580501366697712424694256005093589248451503068397608001

    S> Also, if Python really can handle longs that are bigger than the
    S> machines native longs, the interpreter has to do some sort of
    S> arbitrary precision math somewhere. Could you please point me to the
    S> according interpreter's source file(s)?

Look at Objects/longobject.c in the source distribution.

Skip





More information about the Python-list mailing list