output error in c++
<p>I am having a very strange problem in a simple program and have been unable to reach any logical conclusion. When I redirect output from my program to a file, then I get a different result that I get when printing to stdout. When I print to a file, the result is correct. I don't understand why it would be different in the first place. Here is a snippet. Any ideas?</p>

<pre><code>for (int i = 1; i &lt;= N; i++) {
    double x = i*h;
    for (int j = 1; j &lt;= N; j++) {
        double y = j*h;
        double bi = h*h*f(x,y);
        if (x+h == 1.0) {
            bi += boundary_f(1,y);
        }
    if (y+h == 1.0) {
        bi += boundary_f(x,1);
    }
    cout &lt;&lt; "i=" &lt;&lt; i &lt;&lt; "; j=" &lt;&lt; j &lt;&lt; "; b=" &lt;&lt; bi &lt;&lt; "\n";
    b(k,1) = bi;
    ++k;
}
</code></pre>

<p>I get different results when printing to stdout and redirect to file! It seems like the conditions y+h==1.0 does not evaluate to true even when y+h is 1.0 when the output to stdout but when redirected to file, it evaluates correctly.</p>
