title: Strange behaviour of macros C/C++
body: <p>I'm using some macros, and observing some strange behaviour.</p>
  
  <p>I've defined PI as a constant, and then used it in macros to convert degrees to radians and radians to degrees. Degrees to radians works fine, but radians to degrees does not:</p>
  
  <p>piTest.cpp:</p>
  
  <pre><code>#include &lt;cmath&gt;
  #include &lt;iostream&gt;
  using namespace std;
  
  #define PI atan(1) * 4
  #define radians(deg)  deg * PI / 180
  #define degrees(rad)  rad * 180 / PI
  
  int main()
  {
    cout &lt;&lt; "pi: " &lt;&lt; PI &lt;&lt; endl;
    cout &lt;&lt; "PI, in degrees: " &lt;&lt; degrees(PI) &lt;&lt; endl;
    cout &lt;&lt; "45 degrees, in rad: " &lt;&lt; radians(45) &lt;&lt; endl;
    cout &lt;&lt; "PI * 180 / PI: " &lt;&lt; (PI * 180 / PI) &lt;&lt; endl;
    cout &lt;&lt; "3.14159 * 180 / 3.14159: " &lt;&lt; (3.14159 * 180 / 3.14159) &lt;&lt; endl;
    cout &lt;&lt; "PI * 180 / 3.14159: " &lt;&lt; (PI * 180 / 3.14159) &lt;&lt; endl;
    cout &lt;&lt; "3.14159 * 180 / PI: " &lt;&lt; (3.14159 * 180 / PI) &lt;&lt; endl;
  
    return 0;
  
  }
  </code></pre>
  
  <p>When I compile and run, I get the following output: </p>
  
  <pre><code>pi: 3.14159
  PI, in degrees: 2880
  45 degrees, in rad: 0.785398
  PI * 180 / PI: 2880
  3.14159 * 180 / 3.14159: 180
  PI * 180 / 3.14159: 180
  3.14159 * 180 / PI: 2880
  </code></pre>
  
  <p>It seems like my constant PI works in the numerator, but not the denominator. I've observed the same behaviour in C. I'm running gcc version 4.6.3</p>
  
  <p>Can anyone explain why I'm getting this behaviour?</p>