Important: The information in this document is obsolete and should not be used for new development.
nearbyint
You can use thenearbyintfunction 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
Thenearbyintfunction 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
nearbyintfunction provides the floating-point to integer conversion described in the IEEE Standard 854. It differs fromrint(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 is exact.SPECIAL CASES
Table 9-5 shows the results when the argument to thenearbyintfunction is a zero, a NaN, or an Infinity.
Special cases for the nearbyintfunctionOperation Result Exceptions raised +0 None None NaN None[16] + ![]()
None 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.