BSD 4_4 development
[unix-history] / usr / share / man / cat3 / rint.0
RINT(3) BSD Programmer's Manual RINT(3)
N\bNA\bAM\bME\bE
r\bri\bin\bnt\bt - and round-to-closest integer functions
S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS
#\b#i\bin\bnc\bcl\blu\bud\bde\be <\b<m\bma\bat\bth\bh.\b.h\bh>\b>
_\bd_\bo_\bu_\bb_\bl_\be
r\bri\bin\bnt\bt(_\bd_\bo_\bu_\bb_\bl_\be _\bx);
D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
The r\bri\bin\bnt\bt() function finds the integer (represented as a double precision
number) nearest to _\bx in the direction of the prevailing rounding mode.
N\bNO\bOT\bTE\bES\bS
On a VAX, r\bri\bin\bnt\bt(_\bx) 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, r\bri\bin\bnt\bt(_\bx) is the integer nearest _\bx with the additional stipula-
tion that if |rint(x)-x|=1/2 then r\bri\bin\bnt\bt(_\bx) is even. Other rounding modes
can make r\bri\bin\bnt\bt() act like f\bfl\blo\boo\bor\br(), or like c\bce\bei\bil\bl(), or round towards zero.
Another way to obtain an integer near _\bx is to declare (in C)
double x; int k; k = x;
Most C compilers round _\bx towards 0 to get the integer _\bk, but some do oth-
erwise. If in doubt, use f\bfl\blo\boo\bor\br(), c\bce\bei\bil\bl(), or r\bri\bin\bnt\bt() first, whichever you
intend. Also note that, if x is larger than _\bk can accommodate, the value
of _\bk and the presence or absence of an integer overflow are hard to pre-
dict.
S\bSE\bEE\bE A\bAL\bLS\bSO\bO
abs(3), fabs(3), ceil(3), floor(3), ieee(3), math(3)
H\bHI\bIS\bST\bTO\bOR\bRY\bY
A r\bri\bin\bnt\bt() function appeared in Version 6 AT&T UNIX.
4.4BSD June 4, 1993 1