RINT

Section: C Library Functions (3)
Index Return to Main Contents

BSD mandoc
 

NAME

rint - and round-to-closest integer functions  

SYNOPSIS

Fd #include <math.h> Ft double Fn rint double x  

DESCRIPTION

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

NOTES

On a VAX Fn 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, Fn rint x is the integer nearest Fa x with the additional stipulation that if |rint(x)-x|=1/2 then Fn rint x is even. Other rounding modes can make Fn rint act like Fn floor , or like Fn ceil , or round towards zero.

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

double x;     int k;    k = x;

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

SEE ALSO

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

HISTORY

A Fn rint function appeared in AT&T System v6 .


 

Index

NAME
SYNOPSIS
DESCRIPTION
NOTES
SEE ALSO
HISTORY

This document was created by man2html, using the manual pages.
Time: 08:43:27 GMT, September 19, 2022