The smallest and largest values of numeric types

Michael Hoffman cam.ac.uk at mh391.invalid
Tue Apr 17 14:41:52 EDT 2007


fumanchu wrote:
> On Apr 17, 7:12 am, t... at finland.com wrote:
>> How can I determine the smallest and largest values
>> of numeric types (for example int) possible in my
>> system? I think there exists a function for this task
>> but I don't know it.
> 
> This should work for ints:
> 
> import sys
> print sys.maxint

One should note that ints bigger than sys.maxint are possible almost 
seamlessly since Python will use longs for these numbers:

Python 2.5 (r25:51908, Mar 13 2007, 08:13:14)
[GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> import sys
 >>> sys.maxint
2147483647
 >>> sys.maxint+1
2147483648L
 >>> sys.maxint*2
4294967294L
 >>> sys.maxint**10
2085924830053169311564321191305931199741711560688200050463950578047164169337729650765802242049L

Of course performance decreases for longer longs.
-- 
Michael Hoffman



More information about the Python-list mailing list