Important: The information in this document is obsolete and should not be used for new development.
round
You can use theround
function to round a real number to the integer value obtained by adding 1/2 to the magnitude and truncating.
double_t round (double_t x);
x
- Any floating-point number.
DESCRIPTION
Theround
function adds 1/2 to the magnitude of its argument and chops to integer. The result is returned in a floating-point data type.This function is not affected by the current rounding direction. Notice that the
round
function rounds halfway cases (1.5, 2.5, and so on) away from 0. With the default rounding direction,rint
(described on page 6-13) rounds halfway cases to the even integer.EXCEPTIONS
When x is finite and nonzero, either the result of is exact or it raises the following exception:
- inexact (if x is not an integer value)
SPECIAL CASES
Table 9-6 shows the results when the argument to theround
function is a zero, a NaN, or an Infinity.
Special cases for the round
functionOperation Result Exceptions raised +0 None None NaN None[17] + None None EXAMPLES
z = round(+INFINITY); /* z = +INFINITY because + is already an integer value by definition. */ z = round(0.5); /* z = 1.0 because |0.5| + 0.5 = 1.0. The inexact exception is raised. */ z = round(-0.9); /* z = -1.0 because |-0.9| + 0.5 = 1.4. The inexact exception is raised. */
[17] If the NaN is a signaling NaN, the invalid exception is raised.