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 2 - The PowerPC Numerics C Implementation
Chapter 9 - Conversion Functions / Converting Floating-Point to Integer Formats


rinttol

You can use the rinttol 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
The rinttol function rounds its argument to the nearest integer in the current rounding direction and places the result in a long 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 from rint (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 rinttol(x) 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 the rinttol function is a zero, a NaN, or an Infinity.
Special cases for the rinttol function
OperationResultExceptions raised
rinttol(+0) +0None
rinttol(-0) -0 None
rinttol(NaN) UndefinedNone[12]
rinttol(+ ) UndefinedInvalid
rinttol(- ) UndefinedInvalid

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.

Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996