[LCP]Rounding questions

Greg Black gjb at gbch.net
Fri Sep 6 01:31:06 UTC 2002


Chuck Martin wrote:

| On Thu, Sep 05, 2002 at 12:54:51PM +0300, Muli Ben-Yehuda wrote:
| > because round returns a double and you're printing a float... 
| 
| The %f takes a double.  If I change "round((double) 390.0)" to
| "(double) 390.0", the output is "390.000000" and a newline.

If you left out all these pointless casts, it would be easier to
believe that you knew what you were doing.  What you've shown us
looks like a bug in your implementation of round(), but there is
so much superfluous noise and so little clear exposition of
exactly what you did and what happened that it's difficult to be
sure about this.

A complete minimal program and the compilation line used to
build it and the complete output would be a good start.  The
whole thing should be about five lines of C, one compilation
line and one line of output.

Just for the benefit of the C newbies, "(double) 390.0" is in
fact identical to "390.0" -- the cast adds absolutely nothing
and only obfuscates the code.  Equally, in other examples, where
a prototype is in scope there is no point in casting arguments
to functions where those arguments are declared in the function
prototype.

Greg




More information about the linuxCprogramming mailing list