title: g++ and double precision
body: <p>Can anyone explain to me why executing the following code returns that (1./3.)*3. is equal to 1.? I was assuming that the rounding would prevent such an equality but apparently it doesn't work that way. Any explanation?</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  int main()
  {
    double x = 1./3.;
    double y = 3.*x;
    std::cout.precision(30);
    std::cout &lt;&lt; "x = " &lt;&lt; x &lt;&lt; std::endl;
    std::cout &lt;&lt; "y = " &lt;&lt; y &lt;&lt; std::endl;
    if (y == 1.)
      std::cout &lt;&lt; "Equality!" &lt;&lt; std::endl;
    else
      std::cout &lt;&lt; "Not equality." &lt;&lt; std::endl;
  
    return 0;
  }
  </code></pre>
  
  <p>It returns:</p>
  
  <p>$ g++ test_dp.cpp -o test_dp.exe</p>
  
  <p>$ ./test_dp.exe </p>
  
  <p>x = 0.333333333333333314829616256247</p>
  
  <p>y = 1</p>
  
  <p>Equality!</p>