ceil()、ceilf()、ceill() - 整数値への切り上げ

標準

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

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

両方  

形式

#include <math.h>

double ceil(double x);
float ceil(float x);                  /* C++ only */
long double ceil(long double x);      /* C++ only */
float ceilf(float x);
long double ceill(long double x);

機能説明

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

戻り値

計算値を double、浮動、または long double の値として戻します。

オーバーフローが起こると、関数は errno に ERANGE を設定し、HUGE_VAL を 戻します。

IEEE の特殊な動作: ceil() 関数は、常に正常に実行されます。

CELEBC04
/* CELEBC04                                      

   This example sets y to the smallest integer greater than                     
   1.05, and then to the smallest integer greater than -1.05.                   
                                                                                
   The results are 2.0 and -1.0, respectively.                                  
                                                                               
 */                                                                             
#include <math.h>                                                               
#include <stdio.h>                                                              
int main(void)                                                                  
{                                                                               
   double y, z;                                                                 
                                                                                
   y = ceil(1.05);       /* y = 2.0 */                                          
   z = ceil(-1.05);      /* z = -1.0 */                                         
   printf("y = %f¥n z = %f¥n", y, z);                                           
}