3 ms·
FLT_EPSILON is not 0.01, it's 0.00000011920929. But it's impossible to have a number that's 0.00000011920929 less than 5.0, or 0.00000011920929 more than 5.0,
by hmry 2y ago
FLT_EPSILON is not 0.01, it's 0.00000011920929.
But it's impossible to have a number that's 0.00000011920929 less than 5.0, or 0.00000011920929 more than 5.0, because the floats with enough magnitude to represent 5 are spaced further apart than that. Only numbers with magnitude < 2 are spaced close enough together.
In other words, the only 32-bit float that's within ±0.00000011920929 of 5.0 is 5.0 itself.
- jdthedisciple 2y agoOh you're right, thanks for the explanation! Gotta research now where the 0.00000011920929 number comes from...
- masklinn 2y agoIt's the distance between 1.0 and the next representable float.
- jdthedisciple 2y agoI got that but I am curious how to derive that number. Is it representable as a non-trivial ratio of integers?
- hmry 2y agoGood question! It's 1/(2**23), because 32 bit floats have 23 bits after the decimal point