A 32 bit floating point number has 23 + 1 bits of mantissa and an 8 bit exponent (-126 to 127 is used though) so the largest number you can represent is:
(1 + 1 / 2 + ... 1 / (2 ^ 23)) * (2 ^ 127) =
(2 ^ 23 + 2 ^ 23 + .... 1) * (2 ^ (127 - 23)) =
(2 ^ 24 - 1) * (2 ^ 104) ~= 3.4e38
Answer from Andreas Brinck on Stack OverflowA 32 bit floating point number has 23 + 1 bits of mantissa and an 8 bit exponent (-126 to 127 is used though) so the largest number you can represent is:
(1 + 1 / 2 + ... 1 / (2 ^ 23)) * (2 ^ 127) =
(2 ^ 23 + 2 ^ 23 + .... 1) * (2 ^ (127 - 23)) =
(2 ^ 24 - 1) * (2 ^ 104) ~= 3.4e38
These numbers come from the IEEE-754 standard, which defines the standard representation of floating point numbers. Wikipedia article at the link explains how to arrive at these ranges knowing the number of bits used for the signs, mantissa, and the exponent.
Videos
I am taking my first programming class, and I have done a few assignments, but Iโm not clear on when to use float and when to use double? I know that float uses 4 bits and double uses 8 bits but Im just not sure about what situations call for which. (sorry if this is the wrong community for this question)
$1.2\times 10^{-38}$ is a decimal value. You need to convert it to binary exponential notation to see how the bits are set.
Another small mistake: $2^6+...2^1+2^0$ does not equal $2^{27}$, it equals $2^7-1$.
With 7 exponent bits and one sign bit for the exponent (a total of 8 bits), you can express numbers in the range of $2^{-127}\approx 5.9\cdot 10^{-39}$ to $2^{+127} \approx 1.7\cdot 10^{38}$.
But then you multiply these numbers by numbers of the form $1.bbbbbbb...$ in binary notation, where each of the $b$ stands for one of the 23 bits of the mantissa (i.e., each $b$ is either zero or one). This already gives you a nonsymmetric distribution.
But then not all bit combinations are valid anyway. For example, if I recall correctly, an exponent of -127 is not valid and is interpreted as marking the floating point number as some infinity or NaN, and so in reality, the numbers you can then represent are all of the form $$ 1.bbbbbbb... \cdot 2^{-126} \quad\text{to}\quad 1.bbbbbbb... \cdot 2^{+127}. $$