floor, floorf, floorl

Calculates the floor of a value.


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


Floating-point value.

Return Value

The floor functions return a floating-point value that represents the largest integer that is less than or equal to x. There is no error return.

Input SEH Exception Matherr Exception

floor has an implementation that uses Streaming SIMD Extensions 2 (SSE2). For information and restrictions about using the SSE2 implementation, see _set_SSE2_enable.


C++ allows overloading, so you can call overloads of floor that take and return float and long double values. In a C program, floor always takes and returns a double.


Function Required header
floor, floorf, floorl <math.h>

For additional compatibility information, see Compatibility.


// crt_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>

int 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

See also

Floating-Point Support
ceil, ceilf, ceill
round, roundf, roundl
fmod, fmodf