NAME
rint(), nearbyint() — round to nearest int function
SYNOPSIS
#include <math.h>
double rint(double x);
double nearbyint(double x);
DESCRIPTION
rint()
and
nearbyint()
return the integer (represented as a double precision number)
nearest
x
according to the current rounding direction mode. These functions meet
the requirement of the IEEE-754 standard for an operation that rounds
to integer in floating-point format.
The two functions are identical except that
rint()
raises the inexact
exception, while
nearbyint()
does not.
In the default rounding direction (round to nearest),
rint(x)
is the integer nearest
x
with the additional stipulation that if |rint(x)
-x|=1/2,
then
rint(x)
is even. (The same statement applies to
nearbyint(x).)
If the current rounding direction is toward negative infinity,
rint()
and
nearbyint()
are identical to
floor().
If the current rounding direction is toward positive infinity,
rint()
and
nearbyint()
are identical to
ceil().
The ISO/ANSI C committee has approved the
rint()
and
nearbyint()
functions for inclusion in the C9X draft standard.
To use these functions, compile either with the default
-Ae
option or with the
-Aa
and
-D_HPUX_SOURCE
options. Make sure your program includes
<math.h>.
Link in the math library by specifying
-lm
on the compiler or linker command line.
RETURN VALUE
If
x
is ±INFINITY, the
rint()
and
nearbyint()
functions return ±INFINITY respectively.
If
x
is NaN, the
rint()
and
nearbyint()
functions return NaN.
ERRORS
No errors are defined.
SEE ALSO
ceil(3M),
floor(3M),
fabs(3M),
fmod(3M),
fegetround(3M),
fesetround(3M),
lrint(3M),
llrint(3M),
lround(3M),
llround(3M),
round(3M),
trunc(3M),
math(5),
fenv(5).
STANDARDS CONFORMANCE
rint(): XPG4.2, IEEE-754