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


floor

You can use the floor function to round a real number downward to the next integer value.

double_t floor (double_t x);
x
Any floating-point number.
DESCRIPTION
The floor function rounds its argument downward. 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_DOWNWARD);   /* round downward */
rint(x);                   /* round to integer */
fesetround(r);             /* restore rounding direction */
EXCEPTIONS
When x is finite and nonzero, the result of floor(x) is exact.

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

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

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

Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996