floor, floorf, floorl

计算一个值的下限。

语法

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
);
#define floor(X) // Requires C11 or higher

参数

x
浮点值。

返回值

floor 函数将返回表示小于或等于 x 的最大整数的浮点值。 无错误返回。

输入 SEH 异常 _matherr 异常
± QNaN、IND _DOMAIN

floor 具有使用流式处理 SIMD 扩展 2 (SSE2) 的实现。 有关使用 SSE2 实现的信息和限制,请参阅 _set_SSE2_enable

备注

C++ 允许重载,因此你可以调用采用并返回 floatlong double 值的 floor 重载。 在 C 程序中,除非使用 <tgmath.h> 宏调用此函数,否则 floor 始终采用并返回 double

如果使用 <tgmath.h>floor() 宏,则参数的类型将决定选择哪个版本的函数。 有关详细信息,请参阅泛型类型数学

默认情况下,此函数的全局状态范围限定为应用程序。 若要更改此行为,请参阅 CRT 中的全局状态

要求

函数 必需的标头
floor, floorf, floorl <math.h>
floor <tgmath.h>

有关兼容性的详细信息,请参阅 兼容性

示例

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

另请参阅

数学和浮点支持
ceilceilfceill
roundroundfroundl
fmodfmodf