I am quite a newbie to c. So when i writing a small game demo, i face a really strange problem.
void testC()
{
float a = 825300160;
float b = a + 0.1;
assert(a != b);
}
The above assert statement can’t passed. Very strange.
My environment is mac os ml. gcc 4.2.1
The fractional portion of a
floatconsists of 23 bits. You need 30 bits to represent 825300160, so the less significant portion of the number is dropped. Adding.1does not make a difference – you need to add roughly32for the number to change: