ceil(), ceilf(), ceill() — Round up to integral value

Standards

Standards / Extensions C or C++ Dependencies

ISO C
POSIX.1
XPG4
XPG4.2
ISO/ANSI C++
C99
Single UNIX Specification, Version 3
C++ TR1 C99

both  

Format

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

General description

Computes the smallest integer that is greater than or equal to x.
Note: These functions work in both IEEE Binary Floating-Point and hexadecimal floating-point formats. See IEEE binary floating-point for more information about IEEE Binary Floating-Point.

Returned value

Returns the calculated value as a double, float, or long double value.

If there is an overflow, the function sets errno to ERANGE and returns HUGE_VAL.

Special behavior for IEEE: The ceil() functions are always successful.

Example

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

Related information