ceil() — Find Integer >=Argument

Format

#include <math.h>
double ceil(double x);

Language Level: ANSI

Threadsafe: Yes.

Description

The ceil() function computes the smallest integer that is greater than or equal to x.

Return Value

The ceil() function returns the integer as a double value.

Example that uses ceil()

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 = %.2f ; z = %.2f\n", y, z);
}
/***************** Output should be similar to: ***********************
 
 y = 2.00 ; z = -1.00
**********************************************************************/

Related Information



[ Top of Page | Previous Page | Next Page | Contents | Index ]