title: gdb gives strange output when using math.h functions
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/5122570/why-does-gdb-evaluate-sqrt3-to-0">Why does gdb evaluate sqrt(3) to 0?</a>  </p>
  </blockquote>
  
  
  
  <p>C newbie here. There must be an obvious explanation why gdb gives strange outputs when trying to use math.h functions in-line. For example, the <code>fabs</code> function below is supposed to take the absolute value, and return a double. </p>
  
  <pre><code>(gdb) p cos(2*3.141/4)
  $13 = 1073291460
  (gdb) p fabs(-3)    
  $14 = 0
  (gdb) p fabs(3)
  $15 = 0
  (gdb) p fabs(3.333)
  $16 = 1
  (gdb) p (double) fabs(-3.234)
  $17 = 1
  (gdb) p (double) fabs((double)-3.234)
  $18 = 1
  (gdb) p ((double(*)(double))fabs)(-3)
  $19 = 682945
  </code></pre>
  
  <p>The code I'm using has included math.h, and the actual code appears to execute correctly, although the same code placed in-line in gdb produces strange results. I could ignore it, but it seems a good learning opportunity.</p>