Reputation: 29096
I noticed in C/C++ that FLT_MIN
is about 1.1754943508222875e-38
while FLT_MAX
is 3.40282346639e+38
, I was expecting more symmetric values around zero until I realized that FLT_MIN
represents the minimum value close to zero, not the absolute minimum value which is in this case -FLT_MAX
. So I wrote this:
>>> exp = 0
>>> mantissa = 0
>>> 2**(exp - 126) * (1 + mantissa / 2**23)
1.1754943508222875e-38
I was confident, but when I played around with this excellent FloatConverter I found that my interpretation is wrong:
When exp==0
and mantissa==0
I don't get 1.1754943508222875e-38
, but 0
:
Moreover, the above FLT_MIN
value isn't quite achieved in the same way:
It seems if the exponent is equal to 0
, we are in a special case named denormalized
in which we get rid of the +1
:
2**((exp if exp else 1) - 127) * ((1 if exp else 0) + mantissa / 2**23)
In this case, I could have: mantissa = 1
, and therefore my number equals: 1.401298464324817e-45
which is smaller than FLT_MIN
. Oh damned!
So I don't understand why I can get smaller values than the smallest value.
Upvotes: 1
Views: 34