Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: PowerPC Numerics / Part 1 - The PowerPC Numerics Environment
Chapter 6 - Numeric Operations and Functions / Arithmetic Operations


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
The rint 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 223 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 rint(x) 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
OperationResultExceptions raised
rint(+0) +0None
rint(-0) -0 None
rint(NaN) NaNNone[11]
rint(+ ) + None
rint(- ) - None

EXAMPLES
Table 6-10 shows some example results of rint, given different rounding directions.
Examples of rint
ExampleCurrent rounding direction 
To nearestToward 0DownwardUpward 
rint(1.5)2112 
rint(2.5)2223 
rint(-2.2)-2-2-3-2 


[11] If the NaN is a signaling NaN, the invalid exception is raised.

Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996