Thin book is a great, wonderful, and fantastic.
How can he write this book, is he a genious?In the floating point operation,
double dwNormal = 1.0;
double dwSum = 0;
int i = 0;
for (i=0; i<10; i++)
{
dwSum += 0.1;
TRACE("dwSum: %1.20f\n", dwSum);
}
if (dwSum == dwNormal)
{
TRACE("Numbers are the Same.");
}
else
{
TRACE("Numbers are Differnet.");
}
Can you guess the result?
dwSum == dwNormal is True or False?
In normal case, the result is False.
dwSum = 0.99999999999999989
In normal case, floating point precision, usually be represented to only 7 ot 15 digits of accuracy.
dwSum: 0.10000000000000001000
dwSum: 0.20000000000000001000
dwSum: 0.30000000000000004000
dwSum: 0.40000000000000002000
dwSum: 0.50000000000000000000
dwSum: 0.59999999999999998000
dwSum: 0.69999999999999996000
dwSum: 0.79999999999999993000
dwSum: 0.89999999999999991000
dwSum: 0.99999999999999989000
No comments:
Post a Comment