If a float is repeatedly multiplied by a number that is less than one, is it plausible that the the float could become zero?
Here is an example:
float number = 1.0f;
for ( int i = 0; i < ONE_BILLION; ++i )
{
number *= 0.01f;
}
But please don’t limit your answer to the example.
Thanks!
Yes, when the result of the multiplication would be smaller than the representable number closest to zero, it will become zero. With IEEE floating point, this will happen for any multiplier less than or equal to
0.5f(but greater than zero); however, if the multiplier is even slightly larger than0.5f(for instance,0.5f + FLT_EPSILON) the result will converge to the smallest representable positive number and stay there forever. Compare the behavior of this program with and without-DGREATER: