Important: The information in this document is obsolete and should not be used for new development.
rinttol
You can use therinttol
function to round a real number to the nearest integer in the current rounding direction.
long int rinttol (double_t x);
x
- Any floating-point number.
DESCRIPTION
Therinttol
function rounds its argument to the nearest integer in the current rounding direction and places the result in along int
type. The available rounding directions are upward, downward, to nearest, and toward zero.The
rinttol
function provides the floating-point to integer conversion as described in the IEEE standard. It differs fromrint
(described on page 6-13) in that it returns the value in an integer type;rint
returns the value in a floating-point type.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-1 shows the results when the argument to therinttol
function is a zero, a NaN, or an Infinity.
Special cases for the rinttol
functionOperation Result Exceptions raised +0 None None Undefined None[12] Undefined Invalid Undefined Invalid EXAMPLES
z = rinttol(+INFINITY);/* z = unspecified value for all rounding directions because +INFINITY exceeds the range of long int. The invalid exception is raised. */ z = rinttol(300.1); /* z = 301 if rounding direction is upward else z = 300. The inexact exception is raised.*/ z = rinttol(-300.1); /* z = -301 if rounding direction is downward else z = -300. The inexact exception is raised. */
[12] If the NaN is a signaling NaN, the invalid exception is raised.