Re: Floating point precision problem

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Victor Bazarov wrote:

How did you arrive at that number?  Here is my example:

#include <iomanip>
#include <iostream>
using namespace std;

int main()
{
    double db = 98653258.0002;
    double gg = 2569.003;

    double qq = db + gg;
    double qqq = 98655827.0032; // expected

    cout << setprecision(17) << qq << ' ' << (qq-qqq)/qqq << endl;
}


Victor:

Actually, your program is incorrect. The internal representation of your "expected" qqq also has floating point errors in it, so your qq-qqq does not represent the true error in the calculated qq.

My confusion was that I took the calculated value 98655827.00320009 from the OP. The correct value, as Brian Muth pointed out, is 98655827.003200009.

David

.



Relevant Pages