In mathematics, the floor function is the function that takes as input a real number x, and gives as output the greatest integer less than or equal to x, denoted ⌊x⌋ or floor(x).
[2] However, the same term, integer part, is also used for truncation towards zero, which differs from the floor function for negative numbers.
Carl Friedrich Gauss introduced the square bracket notation [x] in his third proof of quadratic reciprocity (1808).
[3] This remained the standard[4] in mathematics until Kenneth E. Iverson introduced, in his 1962 book A Programming Language, the names "floor" and "ceiling" and the corresponding notations ⌊x⌋ and ⌈x⌉.
[7][8] The fractional part is the sawtooth function, denoted by {x} for real x and defined by the formula For all x, These characters are provided in Unicode: In the LaTeX typesetting system, these symbols can be specified with the \lceil, \rceil, \lfloor, and \rfloor commands in math mode.
, floor and ceiling may be defined by the equations Since there is exactly one integer in a half-open interval of length one, for any real number x, there are unique integers m and n satisfying the equation where
[11] In the language of order theory, the floor function is a residuated mapping, that is, part of a Galois connection: it is the upper adjoint of the function that embeds the integers into the reals.
[17] Division by positive integers gives rise to an interesting and sometimes useful property.
The second equivalence involving the ceiling function can be proved similarly.
Since none of the functions discussed in this article are continuous, none of them have a power series expansion.
Since floor and ceiling are not periodic, they do not have uniformly convergent Fourier series expansions.
The fractional part function has Fourier series expansion[19]
At points of discontinuity, a Fourier series converges to a value that is the average of its limits on the left and the right, unlike the floor, ceiling and fractional part functions: for y fixed and x a multiple of y the Fourier series given converges to y/2, rather than to x mod y = 0.
Notably, x mod y is always between 0 and y, i.e., if y is positive, and if y is negative, Gauss's third proof of quadratic reciprocity, as modified by Eisenstein, has two basic steps.
First, Gauss's lemma is used to show that the Legendre symbols are given by The second step is to use a geometric argument to show that Combining these formulas gives quadratic reciprocity in the form There are formulas that use floor to express the quadratic character of small numbers mod odd primes p:[22] For an arbitrary real number
to the nearest integer value forms a very basic type of quantizer – a uniform one.
is the way of writing n in base p. This is a finite sum, since the floors are zero when pk > n. The Beatty sequence shows how every positive irrational number gives rise to a partition of the natural numbers into two sequences via the floor function.
[25] There are formulas for Euler's constant γ = 0.57721 56649 ... that involve the floor and ceiling, e.g.[26] and The fractional part function also shows up in integral representations of the Riemann zeta function.
for real part of s greater than 1 and letting a and b be integers, and letting b approach infinity gives This formula is valid for all s with real part greater than −1, (except s = 1, where there is a pole) and combined with the Fourier expansion for {x} can be used to extend the zeta function to the entire complex plane and to prove its functional equation.
[28] For s = σ + it in the critical strip 0 < σ < 1, In 1947 van der Pol used this representation to construct an analogue computer for finding roots of the zeta function.
[29] The floor function appears in several formulas characterizing prime numbers.
For example, let pn be the n-th prime, and for any integer r > 1, define the real number α by the sum Then[31] A similar result is that there is a number θ = 1.3064... (Mills' constant) with the property that are all prime.
It is a straightforward deduction from Wilson's theorem that[33] Also, if n ≥ 2,[34] None of the formulas in this section are of any practical use.
[35][36] Ramanujan submitted these problems to the Journal of the Indian Mathematical Society.
[37] If n is a positive integer, prove that Some generalizations to the above floor function identities have been proven.
[40] In most programming languages, the simplest method to convert a floating point number to an integer does not do floor or ceiling, but truncation.
FORTRAN was defined to require this behavior and thus almost all processors implement conversion this way.
Division by a power of 2 is often written as a right-shift, not for optimization as might be assumed, but because the floor of negative results is required.
Assuming such shifts are "premature optimization" and replacing them with division can break software.
The J Programming Language, a follow-on to APL that is designed to use standard keyboard symbols, uses <.