floor, floorf, floorl

Header: <math.h>

1-3) Computes the largest integer value not greater than arg.

# Declarations

float floorf( float arg );

(since C99)

double floor( double arg );
long double floorl( long double arg );

(since C99)

#define floor( arg )

(since C99)

# Parameters

# Return value

If no errors occur, the largest integer value not greater than arg, that is ⌊arg⌋, is returned.

# Notes

FE_INEXACT may be (but isn’t required to be) raised when rounding a non-integer finite value.

The largest representable floating-point values are exact integers in all standard floating-point formats, so this function never overflows on its own; however the result may overflow any integer type (including intmax_t), when stored in an integer variable.

# Example

#include <math.h>
#include <stdio.h>
 
int main(void)
{
    printf("floor(+2.7) = %+.1f\n", floor(2.7));
    printf("floor(-2.7) = %+.1f\n", floor(-2.7));
    printf("floor(-0.0) = %+.1f\n", floor(-0.0));
    printf("floor(-Inf) = %+f\n",   floor(-INFINITY));
}

# See also