title: sum of double numbers in c++
body: <p>I want to calculate the sum of three double numbers and I expect to get 1. </p>
  
  <pre><code>double a=0.0132;
  double b=0.9581;
  double c=0.0287;
  cout &lt;&lt; "sum= "&lt;&lt; a+b+c &lt;&lt;endl;
  if (a+b+c != 1)
  cout &lt;&lt; "error" &lt;&lt; endl;
  </code></pre>
  
  <p>The sum is equal to 1 but I still get the error! I also tried:</p>
  
  <pre><code>cout&lt;&lt; a+b+c-1
  </code></pre>
  
  <p>and it gives me   -1.11022e-16</p>
  
  <p>I could fix the problem by changing the code to</p>
  
  <p><code>if (a+b+c-1 &gt; 0.00001)
     cout &lt;&lt; "error" &lt;&lt;  endl;</code></p>
  
  <p>and it works (no error). How can a negative number be greater than a positive number and why the numbers don't add up to 1?
  Maybe it is something basic with summation and under/overflow but I really appreciate your help.
  Thanks </p>