December 2005
Beginner to intermediate
618 pages
20h 19m
English
floor
Rounds a real number down to an integer value
#include <math.h> doublefloor( doublex); floatfloorf( floatx); (C99) long doublefloorl( long doublex); (C99)
The floor() function
returns the greatest integer that is less than or equal to its
argument. However, the function does not have an integer
type; it returns an integer
value, but with a floating-point type.
/* Scale a point by independent x and y factors */
struct point { int x, y; };
int width_orig = 1024, height_orig = 768;
int width_new = 800, height_new = 600;
struct point scale( struct point orig )
{
struct point new;
new.x = (int)floor( orig.x * (double)width_new / (double)width_orig );
new.y = (int)floor( orig.y * (double)height_new / (double)height_orig );
return new;
}ceil(), round(); the C99
rounding functions that return floating-point types: trunc(), rint(), nearbyint(), nextafter(), and
nexttoward(); the C99
rounding functions that return integer types: lrint(), lround(), llrint(), and llround(); the
fesetround() and
fegetround() functions,
which operate on the C99 floating-point environment.
Read now
Unlock full access