title: (Java) Strange NaN in a double while using Math.acos
body: <p>I have a strange problem on my code: I want to compute an arc-cosinus, and I use the Math.acos for that. But when I try to compute it, it sometimes returns NaN (I said "sometimes" because it occurs 1/10 time with the <strong><em>same value</em></strong>).</p>
  
  <p>And the worst is that:</p>
  
  <pre><code>double angle = Math.acos((v.xdest-v.xi)/Math.sqrt(Math.pow(v.xdest-v.xi,2)+Math.pow(v.ydest-v.yi,2)));
  System.out.println(angle);
      /* 
      Some code
      */
  System.out.println(Math.acos((v.xdest-v.xi)/Math.sqrt(Math.pow(v.xdest-v.xi,2)+Math.pow(v.ydest-v.yi,2))));
  </code></pre>
  
  <p>When I run this code, I get:</p>
  
  <pre><code>NaN 
  2.620575634136091
  </code></pre>
  
  <p>Even if it is the <strong><em>same</em></strong> calculation!</p>
  
  <p>And if I run:</p>
  
  <pre><code>double angle = Math.acos((v.xdest-v.xi)/Math.sqrt(Math.pow(v.xdest-v.xi,2)+Math.pow(v.ydest-v.yi,2)));
  System.out.println(angle);
  System.out.println(Math.acos((v.xdest-v.xi)/Math.sqrt(Math.pow(v.xdest-v.xi,2)+Math.pow(v.ydest-v.yi,2))));
          /* 
          Some code
          */
  </code></pre>
  
  <p>I get </p>
  
  <pre><code>NaN
  NaN
  </code></pre>
  
  <p>It looks like the code between the two calculations makes it possible. But this code doesn't modify anything. </p>
  
  <p>I don't know what to do.</p>
  
  <p>(<code>xdest-xi</code> and <code>ydest-yi</code> are always the same, so they are not the source of my problem)</p>