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