title: Why is acos() resulting in "nan(ind)" when using the result of a dot product?
body: <p>I'm very confused with the issue. The code I am running is:</p>
  
  <pre><code>double dotProduct = dot(A, B);
  std::cout &lt;&lt; dotProduct &lt;&lt; std::endl;
  theta = acos(dotProduct);
  std::cout &lt;&lt; theta &lt;&lt; std::endl;
  </code></pre>
  
  <p>The output of which is</p>
  
  <pre><code>-1
  ANGLE: -nan(ind)
  </code></pre>
  
  <p>However, the following works:</p>
  
  <pre><code>double dotProduct = dot(A, B);
  std::cout &lt;&lt; dotProduct &lt;&lt; std::endl;
  dotProduct = -1;
  theta = acos(dotProduct);
  </code></pre>
  
  <p>Giving the output:</p>
  
  <pre><code>-1
  ANGLE: 3.14159
  </code></pre>
  
  <p>Also, if I cast dotProduct to a float, acos() outputs the angle correctly:</p>
  
  <pre><code>double dotProduct = dot(A, B);
  std::cout &lt;&lt; dotProduct &lt;&lt; std::endl;
  theta = acos((float) dotProduct);
  </code></pre>
  
  <p>Also resulting in the output</p>
  
  <pre><code>-1
  ANGLE: 3.14159
  </code></pre>
  
  <p>For the dot() function, I am using the Armadillo library. What I don't understand is why acos() should work when I set dotProduct = -1, but will not when it is outputted by the dot() function. What am I doing wrong?</p>