Important: The information in this document is obsolete and should not be used for new development.
rint
You can use the round-to-integer operation (rint
function) to round a number to the nearest integer in the current rounding direction.
double_t rint(double_t x);
x
- Any floating-point number.
DESCRIPTION
Therint
function rounds its argument to an integer in the current rounding direction. The available rounding directions are upward, downward, to nearest (default), and toward zero. With the default rounding direction, if the argument is equally near two integers, the even integer is used as the result.In each floating-point data type, all values of sufficiently great magnitude are integers. For example, in single format, all numbers whose magnitudes are at least are integers. This means that + and are already integers and return exact results.
The
rint
function performs the round-to-integer arithmetic operation described in the IEEE standard. For other C functions that perform rounding to integer, see Chapter 9, "Conversion Functions."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)
SPECIAL CASES
Table 6-9 shows the results when the argument to the round-to-integer operation is a zero, a NaN, or an Infinity.
Table 6-9 Special cases for floating-point round-to-integer Operation Result Exceptions raised +0 None None NaN None[11] + None None EXAMPLES
Table 6-10 shows some example results ofrint
, given different rounding directions.
Examples of rint
Example Current rounding direction To nearest Toward 0 Downward Upward rint(1.5) 2 1 1 2 rint(2.5) 2 2 2 3 rint(-2.2) -2 -2 -3 -2
[11] If the NaN is a signaling NaN, the invalid exception is raised.