maximum value for long?

S.Susnjar forth at
Tue Nov 18 18:06:23 CET 2003

Hello all,

I have been programming in Python only for a month or so and have stumbled
over a "problem" that I could not solve through rtfm.

$ python
Python 2.2.2 (#1, Nov  6 2003, 09:19:47) 
[GCC 3.3] on irix646
Type "help", "copyright", "credits" or "license" for more information.
>>> ulong_max=18446744073709551615
>>> type(ulong_max)
<type 'long'>
>>> print ulong_max
>>> very_long_long=1844674407370955161518446744073709551615
>>> type(very_long_long)
<type 'long'>
>>> print very_long_long
>>> result=very_long_long/15
>>> type(result)
<type 'long'>
>>> print result

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

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

TIA + Regards,

More information about the Python-list mailing list