 <p><code>double</code> is <em>not</em> an exact type, as you can see by applying the <a href="http://en.cppreference.com/w/cpp/types/numeric_limits/is_exact"><code>std::numeric_limits</code> typetrait</a>:</p> <pre><code>#include &lt;limits&gt; static_assert(std::numeric_limits&lt;double&gt;::is_exact == false); </code></pre> <p>Thus computations involving doubles are only approximate, and there is nothing wrong about what you observe.</p> <p><em>There is no problem with your code.</em></p>