Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: PowerPC Numerics / Part 2 - The PowerPC Numerics C Implementation
Chapter 9 - Conversion Functions / Rounding Floating-Point Numbers to Integers


ceil

You can use the ceil function to round a real number upward to the nearest integer value.

double_t ceil (double_t x);
x
Any floating-point number.
DESCRIPTION
The ceil function rounds its argument upward. This is an ANSI standard C library function. The result is returned in a floating-point data type.

This function is the same as performing the following code sequence:

r = fegetround();       /* save current rounding direction */
fesetround(FE_UPWARD);  /* round upward */
rint(x);                /* round to integer */
fesetround(r);          /* restore rounding direction */
EXCEPTIONS
When x is finite and nonzero, the result of ceil(x) is exact.

SPECIAL CASES
Table 9-3 shows the results when the argument to the ceil function is a zero, a NaN, or an Infinity.
Special cases for the ceil function
OperationResultExceptions raised
ceil(+0) +0None
ceil(-0) -0 None
ceil(NaN) NaNNone[14]
ceil(+ ) + None
ceil(- ) - None

EXAMPLES
z = ceil(+INFINITY); /* z = +INFINITY because +INFINITY is already 
                        an integer value by definition. */
z = ceil(300.1);     /* z = 301.0 */
z = ceil(-300.1);    /* z = -300.0 */

[14] If the NaN is a signaling NaN, the invalid exception is raised.

Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996