TOPICS
Search

Nearest Integer Function


The nearest integer function, also called nint or the round function, is defined such that nint(x) is the integer closest to x. While the notation |_x] is sometimes used to denote the nearest integer function (Hastad et al. 1988), this notation is rather cumbersome and is not recommended. Also note that while [x] is sometimes used to denote the nearest integer function, [x] is also commonly used to denote the floor function |_x_| (including by Gauss in his third proof of quadratic reciprocity in 1808), so this notational use is also discouraged.

NearestIntegerFunction

Since the definition is ambiguous for half-integers, the additional rule that half-integers are always rounded to even numbers is usually added in order to avoid statistical biasing. For example, nint(1.5)=2, nint(2.5)=2, nint(3.5)=4, nint(4.5)=4, etc. This convention is followed in the C math.h library function rint, as well as in the Wolfram Language, where the nearest integer function is implemented as Round[x].

Since usage concerning fractional part/value and integer part/value can be confusing, the following table gives a summary of names and notations used. Here, S&O indicates Spanier and Oldham (1987).

notationnameS&OGraham et al. Wolfram Language
[x]ceiling function--ceiling, least integerCeiling[x]
mod(m,n)congruence----Mod[m, n]
|_x_|floor functionInt(x)floor, greatest integer, integer partFloor[x]
x-|_x_|fractional valuefrac(x)fractional part or {x}SawtoothWave[x]
sgn(x)(|x|-|_|x|_|)fractional partFp(x)no nameFractionalPart[x]
sgn(x)|_|x|_|integer partIp(x)no nameIntegerPart[x]
nint(x)nearest integer function----Round[x]
m\nquotient----Quotient[m, n]
NearestIntegerDiff

The plots above illustrate x^(1/n)-[x^(1/n)] for small n.

NearestIntegerFunctionReImAbs
Min Max
Re
Im Powered by webMathematica

The nearest integer function can also be extended to the complex plane, as illustrated above.


See also

Ceiling Function, Floor Function, Fractional Part, Integer Part, Mod, Nint Zeta Function, Quotient, Staircase Function

Related Wolfram sites

http://functions.wolfram.com/IntegerFunctions/Round/

Explore with Wolfram|Alpha

References

Graham, R. L.; Knuth, D. E.; and Patashnik, O. "Integer Functions." Ch. 3 in Concrete Mathematics: A Foundation for Computer Science, 2nd ed. Reading, MA: Addison-Wesley, pp. 67-101, 1994.Hastad, J.; Just, B.; Lagarias, J. C.; and Schnorr, C. P. "Polynomial Time Algorithms for Finding Integer Relations among Real Numbers." SIAM J. Comput. 18, 859-881, 1988.Spanier, J.; Myland, J.; and Oldham, K. B. An Atlas of Functions, 2nd ed. Washington, DC: Hemisphere, 1987.

Referenced on Wolfram|Alpha

Nearest Integer Function

Cite this as:

Weisstein, Eric W. "Nearest Integer Function." From MathWorld--A Wolfram Web Resource. https://mathworld.wolfram.com/NearestIntegerFunction.html

Subject classifications