man.bsd.lv manual page server

Manual Page Search Parameters

RINT(3) Library Functions Manual RINT(3)

rintround-to-closest integer functions

#include <math.h>

double
rint(double x);

The () function finds the integer (represented as a double precision number) nearest to x in the direction of the prevailing rounding mode.

On a VAX, rint(x) is equivalent to adding half to the magnitude and then rounding towards zero.

In the default rounding mode, to nearest, on a machine that conforms to IEEE 754, (x) is the integer nearest x with the additional stipulation that if |rint(x)-x|=1/2 then rint(x) is even. Other rounding modes can make rint() act like floor(), or like ceil(), or round towards zero.

Another way to obtain an integer near x is to declare (in C)

double x;     int k;    k = x;

Most C compilers round x towards 0 to get the integer k, but some do otherwise. If in doubt, use (), (), or rint() first, whichever you intend. Also note that, if x is larger than k can accommodate, the value of k and the presence or absence of an integer overflow are hard to predict.

abs(3), fabs(3), ceil(3), floor(3), ieee(3), math(3)

A rint() function appeared in Version 6 AT&T UNIX.

4.4BSD-Lite2 December 11, 1993 RINT(3)