"tings" <ti******@hotma il.com> writes:
An article states: "In floating point maths, where if you divide by a
sufficiently large number sufficiently often, you will always be able to
reach a value too small to distinguish from zero, given the finite precision
you have."
What happens when "a value too small to distinguish from zero" is reached by
the above division? Underflow?
What does it mean "sufficient ly often" since only one division should be
enough to cause underflow in division between two floating point numbers?
When underflow happens, the result of the above division should be regarded
as "undefined behavior"? In other words, the result could be any floating
number or just a meanless "number." Is this correct?
The quotation from the article is a rather vague statement of a more
general principle.
Floating-point overflow occurs when the mathematical result of an
operation is too large in magnitude to be represented (for example, if
a double result would be greater than DBL_MAX or less than -DBL_MAX).
Floating-point underflow occurs when the mathematical result is
non-zero, but too small to be represented. In C, I don't believe this
is considered an error; the result can be either 0.0 or some tiny
value. A flag of some sort might or might not be set.
Starting with some arbitrary value and repeatedly dividing it by some
sufficiently large value is one way to cause an underflow. For example:
#include <stdio.h>
int main(void)
{
double x = 1.0;
double previous;
int count = 0;
while (1) {
x /= 10.0;
count ++;
if (x == previous) {
printf("x = %g after %d iterations\n", x, count);
return 0;
}
else if (count >= 1000) {
printf("x = %g, bailing out after %d iterations\n", x, count);
return 0;
}
previous = x;
}
return 0;
}
On one system I just tried, this produces the output:
x = 0 after 325 iterations
You can, of course, get the same effect by repeatedly multiplying by a
small number, or by dividing or multiplying just once by a very large
or small number, respectively. Underflow is determined by the
mathematical result of the operation. The sentence you quoted should
be considered merely an example of what can cause it.
--
Keith Thompson (The_Other_Keit h)
ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.