|
From: | Paul Schneider |
Subject: | Re: g++ 3.4.2 strange behavior |
Date: | Mon, 01 Nov 2004 19:53:26 +0100 |
User-agent: | Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20041009 |
Ulrich Eckhardt wrote:
I am well aware of the real number representation problem. I was not aware of the fact that ( I just tried it):Paul Schneider wrote: [ (1000.0-0.0)/0.001 yields 99999 ]where it should be 100000 straight in my opinion. What am I doing wrong.Try representing 0.001 in binary, it can't be done accurately, just as 1/3 can't in decimal. IOW, the computer has to use a value slightly lower orhigher, which is why your result differs from what you expect. The reason it didn't do so with the other number might be that they werealready computed at compile-time or with higher precision or with adifferent algorithm.Uli
double b = 1000.0; double a = 0.0; double c = 0.01; static_cast<size_t>((b-a)/c); is different from static_cast<size_t>((1000.0 - 0.0)/0.01);as you just suggested. Personally I find this very disturbing. Thanks for your answer.
cheers, Paul
[Prev in Thread] | Current Thread | [Next in Thread] |