Smallest float different from 0.0?

kj no.email at please.post
Mon Sep 7 12:08:56 EDT 2009


In <f253109c-1da7-45f6-82e4-77fdeda64a9e at k39g2000yqe.googlegroups.com> Mark Dickinson <dickinsm at gmail.com> writes:

>The smallest positive subnormal value
>is usually 2**-1074.  If you want something that would still work
>if Python ever switched to using IEEE 754 binary128 format (or some
>other IEEE 754 format), then

>sys.float_info.min * 2**(1-sys.float_info.mant_dig)

Hmmm.  This close-to-the-metal IEEE stuff make a "HERE BE DRAGONS!"
alarms go off in my head...  (What's up with that correction by 1
to sys.float_info.mant_dig?  Or, probably equivalently, why would
sys.float_info.min_exp (-1021) be off by 1 relative to log2 of
sys.float_info.min (-1022)?)

I suppose that

2**(sys.float_info.min_exp - sys.float_info.mant_dig)

would also work?

I must confess, this stuff is way beyond me...  I'm glad that
sys.float_info is available...

kynn



More information about the Python-list mailing list