Calculate the floor of a value.
#include <math.h>
double floor( double x );
long double _floorl( long double x );
x | Floating-point value |
The floor and _floorl functions return a floating-point value representing the largest integer that is less than or equal to x.
The _floorl function is the 80-bit counterpart, and it uses the 80-bit, 10-byte coprocessor form of arguments and return values. See the reference page on the long double functions for more details on this data type.
These functions return the floating-point result. There is no error return.
floor
Standards:ANSI, UNIX
16-Bit:DOS, QWIN, WIN, WIN DLL
32-Bit:DOS32X
_floorl
Standards:None
16-Bit:DOS, QWIN, WIN, WIN DLL
32-Bit:None
/* FLOOR.C: This example displays the largest integers less than or equal
* to the floating-point values 2.8 and -2.8. It then shows the smallest
* integers greater than or equal to 2.8 and -2.8.
*/
#include <math.h>
#include <stdio.h>
void main( void )
{
double y;
y = floor( 2.8 );
printf( "The floor of 2.8 is %f\n", y );
y = floor( -2.8 );
printf( "The floor of -2.8 is %f\n", y );
y = ceil( 2.8 );
printf( "The ceil of 2.8 is %f\n", y );
y = ceil( -2.8 );
printf( "The ceil of -2.8 is %f\n", y );
}
The floor of 2.8 is 2.000000
The floor of -2.8 is -3.000000
The ceil of 2.8 is 3.000000
The ceil of -2.8 is -2.000000