floor


floor

Rounds a real number down to an integer value

 #include <math.h> double floor ( double x  ); float floorf ( float x  );         (C99) long double floorl ( long double x  );         (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.

Example

 /* 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; } 

See Also

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.



C(c) In a Nutshell
C in a Nutshell (In a Nutshell (OReilly))
ISBN: 0596006977
EAN: 2147483647
Year: 2006
Pages: 473

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net