Inmathematics, thefloor function is thefunction that takes as input areal numberx, and gives as output the greatestinteger less than or equal tox, denoted⌊x⌋ orfloor(x). Similarly, theceiling function mapsx to the least integer greater than or equal tox, denoted⌈x⌉ orceil(x).[1]
For example, for floor:⌊2.4⌋ = 2,⌊−2.4⌋ = −3, and for ceiling:⌈2.4⌉ = 3, and⌈−2.4⌉ = −2.
The floor ofx is also called theintegral part,integer part,greatest integer, orentier ofx, and was historically denoted[x] (among other notations).[2] However, the same term,integer part, is also used fortruncation towards zero, which differs from the floor function for negative numbers.
For an integern,⌊n⌋ = ⌈n⌉ =n.
Althoughfloor(x + 1) andceil(x) produce graphs that appear exactly alike, they are not the same when the value ofx is an exact integer. For example, whenx = 2.0001,⌊2.0001 + 1⌋ = ⌈2.0001⌉ = 3. However, ifx = 2, then⌊2 + 1⌋ = 3, while⌈2⌉ = 2.
Theintegral part orinteger part of a number (partie entière in the original) was first defined in 1798 byAdrien-Marie Legendre in his proof of theLegendre's formula.
Carl Friedrich Gauss introduced the square bracket notation[x] in his third proof ofquadratic reciprocity (1808).[3] This remained the standard[4] in mathematics untilKenneth E. Iverson introduced, in his 1962 bookA Programming Language, the names "floor" and "ceiling" and the corresponding notations⌊x⌋ and⌈x⌉.[5][6] (Iverson used square brackets for a different purpose, theIverson bracket notation.) Both notations are now used in mathematics, although Iverson's notation will be followed in this article.
In some sources, boldface or double brackets⟦x⟧ are used for floor, and reversed brackets⟧x⟦ or]x[ for ceiling.[7][8]
In theLaTeX typesetting system, these symbols can be specified with the\lceil, \rceil, \lfloor, and\rfloor commands in math mode. LaTeX has supported UTF-8 since 2018, so the Unicode characters can now be used directly.[10] Larger versions are\left\lceil, \right\rceil, \left\lfloor, and\right\rfloor.
These formulas can be used to simplify expressions involving floors and ceilings.[11]
In the language oforder theory, the floor function is aresiduated mapping, that is, part of aGalois connection: it is the upper adjoint of the function that embeds the integers into the reals.
These formulas show how adding an integern to the arguments affects the functions:
The above are never true ifn is not an integer; however, for everyx andy, the following inequalities hold:
Since none of the functions discussed in this article are continuous, none of them have apower series expansion. Since floor and ceiling are not periodic, they do not have uniformly convergentFourier series expansions. The fractional part function has Fourier series expansion[19]forx not an integer.
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: fory fixed andx a multiple ofy the Fourier series given converges toy/2, rather than tox mod y = 0. At points of continuity the series converges to the true value.
For an integerx and a positive integery, themodulo operation, denoted byx mody, gives the value of the remainder whenx is divided byy. This definition can be extended to realx andy,y ≠ 0, by the formula
Then it follows from the definition of floor function that this extended operation satisfies many natural properties. Notably,x mody is always between 0 andy, i.e.,
For an arbitrary real number,rounding to the nearest integer withtie breaking towards positive infinity is given by; rounding towards negative infinity is given as.
If tie-breaking is away from 0, then the rounding function is (seesign function), androunding towards even can be expressed with the more cumbersome, which is the above expression for rounding towards positive infinity minus anintegralityindicator for.
Rounding areal number to the nearest integer value forms a very basic type ofquantizer – auniform one. A typical (mid-tread) uniform quantizer with a quantizationstep size equal to some value can be expressed as
Letn be a positive integer andp a positive prime number. The exponent of the highest power ofp that dividesn! is given by a version ofLegendre's formula[24]
where is the way of writingn in basep. This is a finite sum, since the floors are zero whenpk >n.
The fractional part function also shows up in integral representations of theRiemann zeta function. It is straightforward to prove (using integration by parts)[27] that if is any function with a continuous derivative in the closed interval [a,b],
Letting forreal part ofs greater than 1 and lettinga andb be integers, and lettingb approach infinity gives
This formula is valid for alls with real part greater than −1, (excepts = 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]
Fors =σ +it in the critical strip 0 <σ < 1,
In 1947van 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, since is equal to 1 ifm dividesn, and to 0 otherwise, it follows that a positive integern is a primeif and only if[30]
One may also give formulas for producing the prime numbers. For example, letpn be then-th prime, and for any integerr > 1, define the real numberα by the sum
In most programming languages, the simplest method to convert a floating point number to an integer does not do floor or ceiling, but truncation. The reason for this is historical, as the first machines usedones' complement and truncation was simpler to implement (floor is simpler intwo's complement).FORTRAN was defined to require this behavior and thus almost all processors implement conversion this way. Some consider this to be an unfortunate historical design decision that has led to bugs handling negative offsets and graphics on the negative side of the origin.[citation needed]
Anarithmetic right-shift of a signed integer by is the same as. 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.[citation needed]
InMicrosoft Excel the functionINT rounds down rather than toward zero,[54] whileFLOOR rounds toward zero, the opposite of what "int" and "floor" do in other languages. Since 2010FLOOR has been changed to error if the number is negative.[55] TheOpenDocument file format, as used byOpenOffice.org,Libreoffice and others,INT[56] andFLOOR both do floor, andFLOOR has a third argument to reproduce Excel's earlier behavior.[57]
^1) Luke Heaton,A Brief History of Mathematical Thought, 2015,ISBN1472117158 (n.p.) 2) Albert A. Blanket al.,Calculus: Differential Calculus, 1968, p. 259 3) John W. Warris, Horst Stocker,Handbook of mathematics and computational science, 1998,ISBN0387947469, p. 151
^Crandall & Pomerance, Ex. 1.3, p. 46. The infinite upper limit of the sum can be replaced withn. An equivalent condition isn > 1 is prime if and only if .
^Ribenboim, p. 180 says that "Despite the nil practical value of the formulas ... [they] may have some relevance to logicians who wish to understand clearly how various parts of arithmetic may be deduced from different axiomatzations ... "
^Hardy & Wright, pp. 344—345 "Any one of these formulas (or any similar one) would attain a different status if the exact value of the number α ... could be expressed independently of the primes. There seems no likelihood of this, but it cannot be ruled out as entirely impossible."
J.W.S. Cassels (1957),An introduction to Diophantine approximation, Cambridge Tracts in Mathematics and Mathematical Physics, vol. 45,Cambridge University Press
Ribenboim, Paulo (1996),The New Book of Prime Number Records, New York: Springer,ISBN0-387-94457-5
Michael Sullivan.Precalculus, 8th edition, p. 86
Titchmarsh, Edward Charles; Heath-Brown, David Rodney ("Roger") (1986),The Theory of the Riemann Zeta-function (2nd ed.), Oxford: Oxford U. P.,ISBN0-19-853369-1
Štefan Porubský,"Integer rounding functions",Interactive Information Portal for Algorithmic Mathematics, Institute of Computer Science of the Czech Academy of Sciences, Prague, Czech Republic, retrieved 24 October 2008