1. ## int floor(double)?

is there a variation of the floor function that accepts a double parameter and returns an int?

2. Well, the standard floor() accepts a double and returns a 'whole' double.

So you could simply cast the result back to an int, ie

Code:
```int my_floor(double n)
{
return (int) floor(n);
}```
Or something, providing it fits in an integer

3. No. (There are some rounding functions that return long int, like lround.)

4. Woudnt casting it to an int have the same effect as floor()?
Code:
```int floor(double a)
{
return (int)a;
}```
EDIT: changed "int round(double a)" to "int floor(double a)"

5. Originally Posted by 39ster
Woudnt casting it to an int have the same effect as floor()?
Code:
```int round(double a)
{
return (int)a;
}```
Casting to int truncates, so -9.82 would go to -9, not -10.

6. Cast after you 'floor', truncating the 0 isn't going to mean anything.

ie, floor 9.82 = 9.0, cast 9.0 = 9

7. Originally Posted by 39ster
Woudnt casting it to an int have the same effect as floor()?
Code:
```int round(double a)
{
return (int)a;
}```
Code:
```int round(double a)
{
return (int) ( a + .5 );
}```

8. casting worked! lround() doesn't seem to work despite including math.h as a header file.

9. Originally Posted by chickenandfries
casting worked! lround() doesn't seem to work despite including math.h as a header file.
I thought it was clear from the name, but lround() rounds to nearest and doesn't calculate a floor. Or did you mean that it wasn't there? It's in math.h as of C99 at least.

10. Yes, I used lround() after performing floor(), but the compiler indicated "undefined reference to lround".

11. Originally Posted by chickenandfries
is there a variation of the floor function that accepts a double parameter and returns an int?
The best way to achieve this is exactly as you stated. Pass to floor(), and cast the result to int.

12. Originally Posted by chickenandfries
Yes, I used lround() after performing floor(), but the compiler indicated "undefined reference to lround".
What compiler? If gcc, be sure to include "-lm" at the end so that the linker finds the math library. If MSVC6, well, that's missing some C99 things. Everything else I'm aware of should have it.

13. Originally Posted by tabstop
Casting to int truncates, so -9.82 would go to -9, not -10.

Originally Posted by Aia
Code:
```int round(double a)
{
return (int) ( a + .5 );
}```
Whoops. I meant int floor(double a), but it woudnt work anyways (as stated by tabstop)