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 拡張機能 (SSE2) を使用して実装されています。 SSE2 実装の使い方の詳細および制約については、「_set_SSE2_enable」を参照してください。

解説

C++ ではオーバーロードが可能であるため、floor および float の値を受け取って返す long double のオーバーロードを呼び出すことができます。 C プログラムでは、tgmath.h マクロを<使用してこの関数を呼び出していない限り、floor常に double.>

<tgmath.h>floor() マクロを使用する場合は、引数の型によって、この関数のどのバージョンが選択されるかが決定されます。 詳細については、「ジェネリック型数値演算」を参照してください。

既定では、この関数のグローバル状態の適用対象は、アプリケーションになります。 この動作を変更するには、「CRT のグローバル状態」を参照してください

必要条件

機能 必須ヘッダー
floor, floorf, floorl <math.h>
floor マクロ <tgmath.h>

互換性の詳細については、「 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

関連項目

数学と浮動小数点のサポート
ceil, ceilf, ceill
round, roundf, roundl
fmod, fmodf