The smallest and largest values of numeric types

fumanchu fumanchu at
Tue Apr 17 17:53:46 CEST 2007

On Apr 17, 7:12 am, t... at 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

For floats, just try until it fails. This is from

# Determine max binary digits for float on this system. Crude but
maxfloat_digits = 2
while True:
    L = (2 ** (maxfloat_digits + 1)) - 1
    if int(float(L)) != L:
    maxfloat_digits += 1

Note this will get you the number of binary digits, which is not a
simple matter to translate to maximum and minimum values, since floats
are inexact numerics. IEEE 754 floats are stored with one bit for the
sign, some bits for the exponent (which is biased) and some for the
significand. See for a
visual example of how it works.

Robert Brewer
System Architect
Amor Ministries
fumanchu at

More information about the Python-list mailing list