[Python-Dev] small floating point number problem

Josiah Carlson jcarlson at uci.edu
Wed Feb 8 09:07:12 CET 2006

"Smith" <smiles at worksmail.net> wrote:
> I just ran into a curious behavior with small floating points, trying
> to find the limits of them on my machine (XP). Does anyone know why the
> '0.0' is showing up for one case below but not for the other? According
> to my tests, the smallest representable float on my machine is much
> smaller than 1e-308: it is

There are all sorts of ugly bits when working with all binary fp numbers
(for the small ones, look for a reference on 'denormals'). I'm sure that
Raymond has more than a few things to say about them (and fp in general),
but I will speed up the discussion by saying that you should read the
IEEE 754 standard for floating point, or alternatively ask on
comp.lang.python where more users would get more out of the answers that
you will recieve there.

One thing to remember is that decimal is not the native representation
of binary floating point, so 1e-100 differs from 1e-101 significantly in
various bit positions.  You can use struct.pack('d', flt) to see this,
or you can try any one of the dozens of IEEE 754 javascript calculators
out there.

 - Josiah

More information about the Python-Dev mailing list