floor(), floorf(), floorl() — Round down to integral value
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
ISO C |
both |
Format
#include <math.h>
double floor(double x);
float floor(float x); /* C++ only */
long double floor(long double x); /* C++ only */
float floorf(float x);
long double floorl(long double x);
General description
Calculates the largest
integer that is less than or equal to x.
Note: These functions work in both IEEE Binary Floating-Point and
hexadecimal floating-point formats. See IEEE binary floating-point for
more information about IEEE Binary Floating-Point.
Returned value
Returns the calculated integral value expressed as a double, float, or long double value. The result cannot have a range error.
Example
CELEBF24
/* CELEBF24
This example assigns y the value of the largest integer that is less
than or equal to 2.8, and it assigns z the value of the largest integer
that is less than or equal to -2.8.
*/
#include <math.h>
#include <stdio.h>
int main(void)
{
double y, z;
y = floor(2.8);
z = floor(-2.8);
printf("floor( 2.8 ) = %f\n", y);
printf("floor( -2.8 ) = %f\n", z);
}
Output
floor( 2.8 ) = 2.000000
floor( -2.8 ) = -3.000000