Smallest float different from 0.0?
Diez B. Roggisch
deets at nospam.web.de
Mon Sep 7 11:15:58 EDT 2009
Paul McGuire wrote:
> On Sep 7, 9:47 am, 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
>
> You could find it for yourself:
>
>>>> for i in range(400):
> ... if 10**-i == 0:
> ... print i
> ... break
> ...
> 324
I think this is even a bit closer:
for i in xrange(10000):
try:
v = 1 / (2**-i)
except ZeroDivisionError:
print i, v
break
-> 1075
If you test the inverse (10 ** 324 and 2 ** 1075) you see that the binary
variant is 4.something * 10 ** 323.
Diez
More information about the Python-list
mailing list