C++ and pin tool -- very weird DOUBLE variable issue with IF statement
<p>I am working with pin tool that simulates a processor and having a very strange problem.
In the code snippet below, Router::Evaluate() is called repeatedly many times. After it is called several million times, strange behavior occurs intermittently where "_cycles != 0" is evaluated to be true in the first IF statement and to be false in the immediately following IF statement, falling into ELSE block.</p>

<pre><code>void Router::Evaluate( )
{     
  //---------debug print code---------
  if (_cycles != 0) {
    cout &lt;&lt; "not a zero" &lt;&lt; endl;

    if (_cycles != 0) cout &lt;&lt; "---not a zero" &lt;&lt; endl;
    else cout &lt;&lt; "---zero" &lt;&lt; endl;

  }        
  //----------------------------------

  _cycles += _speedup;
  while ( _cycles &gt;= 1.0 ) {
    _Step();
    _cycles -= 1.0;
  }
}

//class definition
class Router : public TimedModule {
  Protected:
    double _speedup;  //initialized to 1.0
    double _cycles;  //initialized to 0.0
  ...
}
</code></pre>

<p>Below is the output of the code where "not a zero" followed by "---zero" is printed out from time to time seemingly randomly. </p>

<pre><code>not a zero
---zero
(...some other output...)
not a zero
---zero
(...some other output...)
</code></pre>

<p>How could this possibly happen? This is not a multi-threaded program, so synchronization is not an issue. The program is compiled with gcc4.2.4 and executed on 32-bit CentOS. Does anybody have a clue? 
Thanks.</p>

<p>--added---</p>

<p>I should have mentioned this, too. I did try printing the value of _cycles each time, and it is always 0.0, which should not be possible... 
I also used the following g++ options: "-MM -MG -march=i686 -g -ggdb -g1 -finline-functions -O3 -fPIC"</p>
