title: Why do sin(45) and cos(45) give different results?
body: <p>This is something I wasn't expecting. I know these numbers are not 100% exact, but I wasn't expecting complementary angles giving different results of <code>sin</code> and <code>cos</code>:</p>
  <p>This following function returns <code>0.70710678118654746000000...</code></p>
  <pre><code>sin(45 * PI / 180.0);
  </code></pre>
  <p>while this following function returns <code>0.70710678118654757000000...</code></p>
  <pre><code>cos(45 * PI / 180.0);
  </code></pre>
  <p>so, it's:</p>
  <pre><code>0.707106781186547**46**000000... vs
  0.707106781186547**57**000000...
  </code></pre>
  <hr />
  <p>and not only those... <code>sin(1 * PI / 180.0)</code> also returns a slightly different number than <code>cos(89 * PI / 180.0)</code> although they should be the same.</p>
  <p>Moreover it's not only a <code>sin</code> vs <code>cos</code> problem, it's also a <code>sin</code> vs <code>sin</code> problem: <code>sin(1 * PI / 180.0)</code> returns a different value than <code>sin(179 * PI / 180.0)</code>, again they should be the same.</p>
  <p>I tried to use radians and not degrees, and there is exactly the same difference, I tried to use a small PI value, a huge PI value (around 100 decimals and more) and they're still different, I tried to use <code>cmath</code> instead of <code>math.h</code>, I tried to use <code>M_PI</code> instead of a <code>PI</code> defined by myself.</p>
  <p>The difference is always the same, around the 16th decimal. Don't get me wrong, I know I will never get a 100% precise value of these numbers, but AT LEAST I was expecting to get the same &quot;imprecise&quot; value of <code>sin</code> and <code>cos</code> of complementary angles. What the hell is wrong with all this?</p>
  <hr />
  <p>I need them to be the same because the program I'm working on (a gravity simulator I was asked to do) uses objects that have <code>double</code> (I also tried <code>float</code>) variables which are basically angles (degrees or radians, I've tried both). Those are the directions the objects use to move, also I need the angles to calculate the interactions between the objects.</p>
  <p>The angles change in every iteration of the program, and in every iteration, the angles change basing on the calculations on the previous iteration's angles, so if there is any minimally wrong angle value at any point, that error gets amplified more and more in every iteration.</p>
  <p>The program runs thousands and even millions of iterations, so the value's error gets absurdly huge! To put it clear, planets eventually get out of their balance and everything becomes a disaster, I'm really mad :(</p>
  <p>P.s. I'm on Windows 7, 32 bits.</p>