floor()、floorf()、floorl() - 整数値への切り捨て

標準

標準/拡張機能 C/C++ 依存項目

ISO C
POSIX.1
XPG4
XPG4.2
ISO/ANSI C++
C99
Single UNIX Specification、バージョン 3
C++ TR1 C99

両方  

形式

#include <math.h>

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);

機能説明

x 以下の最大整数を計算します。
注: これらの関数は、IEEE 2 進数浮動小数点形式と 16 進浮動小数点形式の両方で機能します。 IEEE 2 進数浮動小数点の詳細は、IEEE 2 進数浮動小数点を参照してください。

戻り値

double、浮動、または long double の値として表された整数の計算値を戻します。結果は範囲エラーにはなりません。

CELEBF24
⁄* CELEBF24                                      

   This example assigns y the value of the largest integer that is less         
   than or equal to 2.8, and it assigns z the value of the largest integer      
   that is less than or equal to -2.8.                                          

 *⁄                                                                             
#include <math.h>                                                               
#include <stdio.h>                                                              
                                                                                
int main(void)                                                                  
{                                                                               
   double y, z;                                                                 
                                                                                
   y = floor(2.8);                                                              
   z = floor(-2.8);                                                             
                                                                                
   printf("floor(  2.8 ) = %f¥n", y);
   printf("floor( -2.8 ) = %f¥n", z);
}                                                                               
                                                                                
出力:
floor(  2.8 ) = 2.000000
floor( -2.8 ) = -3.000000

関連情報