Smallest float different from 0.0?

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Mon Sep 7 23:02:43 EDT 2009


On 2009年9月07日 08:23:58 -0700, Mark Dickinson wrote:
> On Sep 7, 3:47 pm, kj <no.em... at please.post> 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:
http://mail.python.org/pipermail/python-list/2001-August/099152.html
Unfortunately, it doesn't work for negative floats, zero or denormalised 
floats.
-- 
Steven


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /