title: Why apply an Exponential Moving Average towards 0.0 is slower?
body: <p>This is <a href="http://coliru.stacked-crooked.com/a/e4d62c4ff3632e12" rel="nofollow noreferrer">my code</a>:</p>
  
  <pre><code>#include &lt;math.h&gt; 
  #include &lt;iostream&gt;
  
  using namespace std;
  
  inline void Task(double start, double target) {
      double a0 = 0.0101252;
      double z = start;
  
      double value = -1.0;
      double temp = 0.0;
      int counter = 0;    
      while (value != temp) {
          temp = value;
  
          // exponential moving average
          z += a0 * (target - z);
          value = z;
  
          counter++;
      }
  
      cout &lt;&lt; "start: " &lt;&lt; start &lt;&lt; " | target: " &lt;&lt; target &lt;&lt; " | iterations: " &lt;&lt; counter &lt;&lt; std::endl;    
  }
  
  int main() 
  {   
      Task(0.0, 0.01);
      Task(0.01, 0.0);
  
      Task(0.01, 0.02);
      Task(0.02, 0.01);    
  }
  </code></pre>
  
  <p>Applying <a href="https://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average" rel="nofollow noreferrer">Exponential Moving Average</a> from 0.1 to 0.2 (or from 0.2 to 0.1 or 0.0 to 0.1) results in somethings around 3100 iterations:</p>
  
  <pre><code>start: 0 | target: 0.01 | iterations: 3173
  start: 0.01 | target: 0.02 | iterations: 3105
  start: 0.02 | target: 0.01 | iterations: 3173
  </code></pre>
  
  <p>Instead, if I go to 0.0, its somethings like 25 times more expensive in terms of iterations: </p>
  
  <pre><code>start: 0.01 | target: 0 | iterations: 72305
  </code></pre>
  
  <p>Why? Where's the tricky part here? I can't figure it out. Denormals?</p>