float limits
Terry Reedy
tjreedy at home.com
Wed Jan 30 10:03:50 EST 2002
"Alexandre Fayolle" <alf at leo.logilab.fr> wrote in message
> Is there a way of knowing what the value of the smallest positive
float
> available on a given machine from within python? A bit like
sys.maxint,
> but for mindouble. Similarly, I'd like to know the value of the
biggest
> positive float, maxfloat. If the solution is portable, that's all
the better.
There is a standard algorithm that numerical analysts use to calculate
machine epsilon:
I believe its something like
eps1 = 1.0
eps2 = 0.5
while (1.0+eps2 != 1.0):
eps1 = eps2
eps2 /= 2.0
I think adding 0.0 instead of 1.0 and comparing might be theoretically
just as good, but good compilers will optimize away addition. Simply
testing eps2 against 0.0 fails if min/2 = min instead of 0.
Terry J. Reedy
More information about the Python-list
mailing list