title: machine epsilon - long double in c++
body: <p>I wanted to calculate the machine Epsilon, the smallest possible number <code>e</code> that gives <code>1 + e &gt; 1</code> using different data types of C++: <code>float</code>, <code>double</code> and <code>long double</code>.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>#include &lt;cstdio&gt;
  
  template&lt;typename T&gt;
  T machineeps() {
  
    T epsilon = 1;
    T expression;
  
    do {
      epsilon = epsilon / 2;
      expression = 1 + epsilon;
    } while(expression &gt; 1);
  
    return epsilon;
  }
  
  int main() {
    auto epsf = machineeps&lt;float&gt;();
    auto epsd = machineeps&lt;double&gt;();
    auto epsld = machineeps&lt;long double&gt;();
  
    std::printf("epsilon float: %22.17e\nepsilon double: %22.17e\nepsilon long double: %Le\n", epsf, epsd, epsld);
  
    return 0;
  }
  </code></pre>
  
  <p>But I get this strange output:</p>
  
  <pre><code>epsilon float: 5.96046447753906250e-008
  epsilon double: 1.11022302462515650e-016
  epsilon long double: -0.000000e+000
  </code></pre>
  
  <p>The values for <code>float</code> and <code>double</code> are what I was expecting, but, I cannot explain the <code>long double</code> behavior.</p>
  
  <p>Can somebody tell me what went wrong?</p>