4.3.0 strange problem with computation and optimization

Andrew Haley aph@redhat.com
Wed Mar 12 17:34:00 GMT 2008


Lasse Kliemann wrote:
> Greetings,
> 
> I have a C++ program that does some linear programming optimization. Out of 
> this linear programming, I get a vector of doubles `x' and a double `opt' 
> that should be the sum of the entries in `x' (`x' is the solution vector and 
> `opt' is the optimal value). As a consistency chek, I compute the sum of the 
> elements of `x' and then compute the difference to `opt'. It should be close 
> to zero. Here is a snippet from the code:
> 
>    double sum = 0;
>    const double *x = model->getColSolution();
>    for (unsigned int j=0; j<m; ++j) sum += x[j];
>    double d=opt-sum;
>    cout << "difference: " << d << endl;
> 
> If I compile that with g++ version 4.3.0 and -O0, -O1, or -Os, everything 
> looks OK; in rare cases the difference is zero, and in most cases it is a 
> very small number.  Now, if I compile that with -O2 or -O3, the difference is 
> *always* printed to be zero, which I presume is wrong.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=323\



More information about the Gcc-help mailing list