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 none _DOMAIN

floor 具有使用 Streaming SIMD Extensions 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

另請參閱

數學和浮點支援
ceil, ceilf, ceill
round, roundf, roundl
fmod, fmodf