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


nearbyint

You can use the nearbyint function to round a real number to the nearest integer in the current rounding direction.

double_t nearbyint (double_t x);
x
Any floating-point number.
DESCRIPTION
The nearbyint function rounds its argument to the nearest integer in the current rounding direction. The available rounding directions are upward, downward, to nearest, and toward zero.

The nearbyint function provides the floating-point to integer conversion described in the IEEE Standard 854. It differs from rint (described on page 6-13) only in that it does not raise the inexact flag when the argument is not already an integer.

EXCEPTIONS
When x is finite and nonzero, the result of nearbyint(x) is exact.

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

EXAMPLES
z = nearbyint(+INFINITY);  /* z = +INFINITY for all rounding 
                              directions. */
z = nearbyint(300.1);      /* z = 301.0 if rounding direction is 
                              upward, else z = 300.0. */
z = nearbyint(-300.1);     /* z = -301.0 if rounding direction is 
                              downward, else z = -300.0. */

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

Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996