floor
Return the largest integer that is not greater than the input x.
Interface Definition
C interface:
float floorf(float x);
double floor(double x);
long double floorl(long double x);
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
x |
|
Floating-point value of the input data. |
Input |
Return Value
- The rounded value of x is returned. x ∈ (-inf, inf)
- If the input is +0, the return value is +0.
- If the input is -0, the return value is -0.
- If the input is ±∞, the return value is ±∞.
- If the input is NaN, the return value is NaN.
Dependency
C: "km.h"
Example
C interface:
// typical usage
double x1 = 0.0, x2 = -0.0, x3 = 1.5, x4 = -2.5;
// special handing
double a = INFINITY, b = -INFINITY, c = NAN;
// print result
printf("floor(0.0) = %.15f\n", floor(x1));
printf("floor(-0.0) = %.15f\n", floor(x2));
printf("floor(1.5) = %.15f\n", floor(x3));
printf("floor(-2.5) = %.15f\n", floor(x4));
printf("floor(INFINITY) = %.15f\n", floor(a));
printf("floor(-INFINITY) = %.15f\n", floor(b));
printf("floor(NAN) = %.15f\n", floor(c));
/*
* floor(0.0) = 0.000000000000000
* floor(-0.0) = -0.000000000000000
* floor(1.5) = 1.000000000000000
* floor(-2.5) = -3.000000000000000
* floor(INFINITY) = inf
* floor(-INFINITY) = -inf
* floor(NAN) = nan
* */
Parent topic: Rounding Functions