Nearest integer function

A plot of the nearest integer function, rounding to the nearest even integer
In computer science, the nearest integer function of real number x denoted variously by
,[1]
,
,[2] nint(x), or Round(x), is a function which returns the nearest integer to x. To avoid ambiguity when operating on half-integers, a rounding rule must be chosen. On most computer implementations, the selected rule is to round half-integers to the nearest even integer—for example,
![[1.25] = 1](../I/m/633510b692274509ea088f034c3e8568.png)
![[1.50] = 2](../I/m/7b284ba22bd1b57f45a71ea577d5f6b0.png)
![[1.75] = 2](../I/m/06bf04049fb7564d30a1cde81fbc7b16.png)
![[2.25] = 2](../I/m/17a3e394b714956439b4959c98482fcf.png)
![[2.50] = 2](../I/m/9514ec98213b5f7feb6e627c858e0f92.png)
![[2.75] = 3](../I/m/8926a333bc676841a88fb519bfc1b272.png)
![[3.25] = 3](../I/m/453e8ff7104f441ca9a29fc0088544ce.png)
![[3.50] = 4](../I/m/3ff1e2e04bc8843f3e745c58242b3c3e.png)
![[3.75] = 4](../I/m/f229f3bbf3ee6afac38df5ce21a26bc4.png)
![[4.50] = 4](../I/m/b1011d344feb0bdc4d7cd81982140e38.png)
- etc.
This is in accordance with the IEEE 754 standards and helps reduce bias in the result.
There are many other possible rules for tie breaking when rounding a half integer include rounding up, rounding down, rounding to or away from zero, or random rounding up or down.
See also
References
- ↑ Weisstein, Eric W., "Nearest Integer Function", MathWorld.
- ↑ J.W.S. Cassels (1957). An introduction to Diophantine approximation. Cambridge Tracts in Mathematics and Mathematical Physics 45. Cambridge University Press. p. 1.
This article is issued from Wikipedia - version of the Thursday, May 05, 2016. The text is available under the Creative Commons Attribution/Share Alike but additional terms may apply for the media files.