sys.float_info.epsilon

Mark Dickinson dickinsm at gmail.com
Wed Feb 4 14:57:20 EST 2009


On Feb 4, 7:18 pm, Tim Rowe <digi... at gmail.com> wrote:
> I didn't realise that float() could return anything with an absolute
> value less than sys.float_value.epsilon other than 0.0 (which I think
> all representations can represent exactly).  What am I missing here?

There are many positive floating-point values smaller than
sys.float_info.epsilon.

sys.float_info.epsilon is defined as the difference between 1.0 and
the next largest representable floating-point number.  On your system,
the next largest float is almost certainly 1 + 2**-52, so
sys.float_info.epsilon will be exactly 2**-52, which is around
2.2e-16.  This number is a good guide to the relative error
from rounding that you can expect from a basic floating-point
operation.

The smallest positive floating-point number is *much* smaller:
again, unless you have a very unusual platform, it's going to
be 2**-1074, or around 4.9e-324.  In between 2**-1074 and
2**-52 there are approximately 4.4 million million million
different floating-point numbers.  Take your pick!

If you want a specific example, how about float('6.626e-34').

Mark



More information about the Python-list mailing list