Smallest float different from 0.0?

Steven D'Aprano steven at
Tue Sep 8 05:02:43 CEST 2009

On Mon, 07 Sep 2009 08:23:58 -0700, Mark Dickinson wrote:

> On Sep 7, 3:47 pm, kj <no.em... at> wrote:
>> Is there some standardized way (e.g. some "official" module of such
>> limit constants) to get the smallest positive float that Python will
>> regard as distinct from 0.0?
>> TIA!
>> kj
> There's sys.float_info.min:
> But that only gives you the smallest *normal* positive float, which is
> 2**-1022 on most systems.

The IEEE standard mandates a "nextafter" function which takes a float as 
an argument, and returns the next greater float. Tim Peters gave an 
implementation here:

Unfortunately, it doesn't work for negative floats, zero or denormalised 


More information about the Python-list mailing list