function
<cmath> <ctgmath>

ceil

double ceil (double x);
     double ceil  (double x);      float ceilf (float x);long double ceill (long double x);
     double ceil (double x);      float ceil (float x);long double ceil (long double x);
     double ceil (double x);      float ceil (float x);long double ceil (long double x);     double ceil (T x);           // additional overloads for integral types
Round up value
Rounds x upward, returning the smallest integral value that is not less than x.

Header <tgmath.h> provides a type-generic macro version of this function.
Additional overloads are provided in this header (<cmath>) for the integral types: These overloads effectively cast x to a double before calculations (defined for T being any integral type).

Parameters

x
Value to round up.

Return Value

The smallest integral value that is not less than x (as a floating-point value).

Example

1
2
3
4
5
6
7
8
9
10
11
12
/* ceil example */
#include <stdio.h>      /* printf */
#include <math.h>       /* ceil */

int main ()
{
  printf ( "ceil of 2.3 is %.1f\n", ceil(2.3) );
  printf ( "ceil of 3.8 is %.1f\n", ceil(3.8) );
  printf ( "ceil of -2.3 is %.1f\n", ceil(-2.3) );
  printf ( "ceil of -3.8 is %.1f\n", ceil(-3.8) );
  return 0;
}

Output:

ceil of 2.3 is 3.0
ceil of 3.8 is 4.0
ceil of -2.3 is -2.0
ceil of -3.8 is -3.0


See also