I was trying to run some little numerical experiments in Python, and I ran into some unexpected behavior. I wrote a program to find the smallest (positive) float in standard Python. Here it is:
x = 1.0
while True :
y = x
x /= 2.0
if x == 0:
break
print(y)
If I'm not mistaken, vanilla Python uses double precision floats, and the smallest (positive) number should be 2^(-1022) (or 2^(-1023) or 2^(-1024), not quite sure).
However, my program returned something very different. It returns 5e-324.
Now, if we want to turn 2^(-1022) into the form of 5*10^(x), we have to solve the equation 2^(-1022) = 5*10^(x), whose solution is log [2^(-1022)/5] (where the logarithm is base 10).
However, the solution in WolframAlpha is about -308, which is pretty far from -324. I tried using 2^(-1023) and 2^(-1024), and the result is still about -308.
Can you please help me understand this discrepancy? Thanks, any help is appreciated!