maximum value for long?

Skip Montanaro skip at
Tue Nov 18 18:43:02 CET 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

    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.


More information about the Python-list mailing list