title: atan problems in c++
body: <p>before I get into my problem, I want to point out a couple of things:  1)I know there is already an atan2 function in the cmath library, this is purely as an exercise and for my own practice, and 2) I know that  the code does not account for 0.</p>
  
  <p>ok, so tan(theta) = y / x, where y and x are coordinates on a plane... that means:</p>
  
  <p>theta = atan(y/x) in Quads I and IV, and
   theta = atan(y/x) + 180 in Quads II and III</p>
  
  <p>so why when I use the following code:</p>
  
  <pre><code>float atan(float y, float x)
   {
   float result = 0.0f;
  
  if (x &gt; 0) //quads I and IV if x is positive
   { 
  result = atanf(y/x);
   }
   else if (x &lt; 0)
   {
   result = atan(y/x) + 180; //quads II and III if x is negative
   }
  
  return result;
  
   }
  </code></pre>
  
  <p>does it spit me junk?
  example, for coordinates (-4,4) it gave me the result of: 179.215, when it should be 135:</p>
  
  <p>atan(4/-4) = -45 degrees + 180 degrees = 135 degrees</p>
  
  <p>but what's happening is it is computing</p>
  
  <p>atan(4.0f/-4.0f) = -0.785398 + 180 degrees = 179.215.</p>
  
  <p>am I missing some step here?</p>