title: How am I incorrectly using the round() function in C?
body: <p>I'm getting unexpected results from the <code>round()</code> and <code>roundf()</code> functions in the <code>math.h</code> library.  Here is the sample code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;math.h&gt;
  
  int main(void)
  {
      float f;
      double d;
  
      /* Note man page says that roundf() returns a float
         and round() returns a double */
      f = roundf(1.2);
      d = round(1.2);
  
      printf("%f\n", f);
      printf("%lf\n", d);
  
      return 0;
  }
  </code></pre>
  
  <p>When I complie and run the program I get:</p>
  
  <pre><code>gcc -lm round.c
  ./a.out
  288.000000
  524288.000000
  </code></pre>
  
  <p>Wierd huh?</p>
  
  <p><strong>Update:</strong>  Along with the answers I've confirmed that the code works properly on a newer complier.  (I think %lf is not the correct printf specifier but that doesn't affect the end result in this case.)  I'll need to figure out why may compiler is behaving this way because I have running code that uses round() and has been compiler on the same machine.  I'll update the post when I figure it out.</p>
  
  <pre><code>gcc -v
  Reading specs from /usr/lib/gcc-lib/i386-slackware-linux/2.95.3/specs
  gcc version 2.95.3 20010315 (release)
  </code></pre>