Jump to content

Nearest integer function

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by JayBeeEll (talk | contribs) at 11:59, 19 July 2018 (Reverted 1 edit by BG5115 (talk): Read what you're editing! (TW)). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

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[citation needed], the selected rule is to round half-integers to the nearest even integer—for example,

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

  1. ^ Weisstein, Eric W. "Nearest Integer Function". MathWorld. Retrieved 2008-08-15. {{cite web}}: More than one of |accessdate= and |access-date= specified (help)
  2. ^ J.W.S. Cassels (1957). An introduction to Diophantine approximation. Cambridge Tracts in Mathematics and Mathematical Physics. Vol. 45. Cambridge University Press. p. 1.