is there a variation of the floor function that accepts a double parameter and returns an int?
is there a variation of the floor function that accepts a double parameter and returns an int?
Well, the standard floor() accepts a double and returns a 'whole' double.
So you could simply cast the result back to an int, ie
Or something, providing it fits in an integerCode:int my_floor(double n) { return (int) floor(n); }
Last edited by zacs7; 03-28-2008 at 09:08 PM.
No. (There are some rounding functions that return long int, like lround.)
Woudnt casting it to an int have the same effect as floor()?
EDIT: changed "int round(double a)" to "int floor(double a)"Code:int floor(double a) { return (int)a; }
Last edited by 39ster; 03-28-2008 at 11:10 PM.
Cast after you 'floor', truncating the 0 isn't going to mean anything.
ie, floor 9.82 = 9.0, cast 9.0 = 9
casting worked! lround() doesn't seem to work despite including math.h as a header file.
Yes, I used lround() after performing floor(), but the compiler indicated "undefined reference to lround".