float a = 0;
while (true)
{
a++;
if (a > 16777216)
break; // Will never break... a stops at 16777216
}
Can anyone explain this t
Short roundup of IEEE-754 floating point numbers (32-bit) off the top of my head:
(sign ? -1 : +1) * 2^exponent * (1.0 + mantissa)
1001 0000 0000 0000 0000 000 = 2^-1 + 2^-4 = .5 + .0625 = .5625 and the value in front of the decimal separator is not stored but implicitly assumed as 1 (if exponent is 255, 0 is assumed but that's not important here), so for an exponent of 30, for instance, this mantissa example represents the value 1.5625Now to your example:
16777216 is exactly 224, and would be represented as 32-bit float like so:
10010111)0 10010111 00000000000000000000000(+1) * 2^24 * (1.0 + .0) = 2^24 = 16777216Now let's look at the number 16777217, or exactly 224+1:
(+1) * 2^24 * (1.0 + 2^-24) = 2^24 + 1 = 16777217