In mathematics, the floor function is the function that takes as input a real number , and gives as output the greatest integer less than or equal to , denoted or . Similarly, the ceiling function maps to the least integer greater than or equal to , denoted or . For example, for floor: , , and for ceiling: , and . The floor of is also called the integral part, integer part, greatest integer, or entier of , and was historically denoted (among other notations). However, the same term, "integer part", is also used for truncation towards zero, which differs from the floor function for negative numbers. For an integer , . Although and produce graphs that appear exactly alike, they are not the same when the value of is an exact integer. For example, when , . However, if , then , while . Notation. The "integral part" or "integer part" of a number ( in the original) was first defined in 1798 by Adrien-Marie Legendre in his proof of the Legendre's formula. Carl Friedrich Gauss introduced the square bracket notation in his third proof of quadratic reciprocity (1808). This remained the standard in mathematics until Kenneth E. Iverson introduced, in his 1962 book "A Programming Language", the names "floor" and "ceiling" and the corresponding notations and . (Iverson used square brackets for a different purpose, the Iverson 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 are used for floor, and reversed brackets or for ceiling. The fractional part is the sawtooth function, denoted by for real 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 codice_1 and codice_1 commands in math mode. LaTeX has supported UTF-8 since 2018, so the Unicode characters can now be used directly. Larger versions arecodice_1 and codice_1. Definition and properties. Given real numbers "x" and "y", integers "m" and "n" and the set of integers formula_1, floor and ceiling may be defined by the equations formula_2 formula_3 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 formula_4 where formula_5 and formula_6 may also be taken as the definition of floor and ceiling. Equivalences. These formulas can be used to simplify expressions involving floors and ceilings. formula_7 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. formula_8 These formulas show how adding an integer to the arguments affects the functions: formula_9 The above are never true if is not an integer; however, for every and , the following inequalities hold: formula_10 Monotonicity. Both floor and ceiling functions are monotonically non-decreasing functions: formula_11 Relations among the functions. It is clear from the definitions that formula_12 with equality if and only if "x" is an integer, i.e. formula_13 In fact, for integers "n", both floor and ceiling functions are the identity: formula_14 Negating the argument switches floor and ceiling and changes the sign: formula_15 and: formula_16 formula_17 Negating the argument complements the fractional part: formula_18 The floor, ceiling, and fractional part functions are idempotent: formula_19 The result of nested floor or ceiling functions is the innermost function: formula_20 due to the identity property for integers. Quotients. If "m" and "n" are integers and "n" ≠ 0, formula_21 If "n" is positive formula_22 formula_23 If "m" is positive formula_24 formula_25 For "m" = 2 these imply formula_26 More generally, for positive "m" (See Hermite's identity) formula_27 formula_28 The following can be used to convert floors to ceilings and vice versa (with "m" being positive) formula_29 formula_30 For all "m" and "n" strictly positive integers: formula_31 which, for positive and coprime "m" and "n", reduces to formula_32 and similarly for the ceiling and fractional part functions (still for positive and coprime "m" and "n"), formula_33 formula_34 Since the right-hand side of the general case is symmetrical in "m" and "n", this implies that formula_35 More generally, if "m" and "n" are positive, formula_36 This is sometimes called a reciprocity law. Division by positive integers gives rise to an interesting and sometimes useful property. Assuming formula_37, formula_38 Similarly, formula_39 Indeed, formula_40 keeping in mind that formula_41 The second equivalence involving the ceiling function can be proved similarly. Nested divisions. For a positive integer "n", and arbitrary real numbers "m" and "x": formula_42 Continuity and series expansions. None of the functions discussed in this article are continuous, but all are piecewise linear: the functions formula_43, formula_44, and formula_45 have discontinuities at the integers. formula_43 is upper semi-continuous and formula_44 and formula_45 are lower semi-continuous. 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 formula_49 for 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: for "y" fixed and "x" a multiple of "y" the Fourier series given converges to "y"/2, rather than to "x" mod "y" = 0. At points of continuity the series converges to the true value. Using the formula formula_50 gives formula_51 for not an integer. Applications. Mod operator. For an integer "x" and a positive integer "y", the modulo operation, denoted by "x" mod "y", gives the value of the remainder when "x" is divided by "y". This definition can be extended to real "x" and "y", "y" ≠ 0, by the formula formula_52 Then it follows from the definition of floor function that this extended operation satisfies many natural properties. Notably, "x" mod "y" is always between 0 and "y", i.e., if "y" is positive, formula_53 and if "y" is negative, formula_54 Quadratic reciprocity. Gauss's third proof of quadratic reciprocity, as modified by Eisenstein, has two basic steps. Let "p" and "q" be distinct positive odd prime numbers, and let formula_55 formula_56 First, Gauss's lemma is used to show that the Legendre symbols are given by formula_57 The second step is to use a geometric argument to show that formula_58 Combining these formulas gives quadratic reciprocity in the form formula_59 There are formulas that use floor to express the quadratic character of small numbers mod odd primes "p": formula_60 Rounding. For an arbitrary real number formula_61, rounding formula_61 to the nearest integer with tie breaking towards positive infinity is given by formula_63 rounding towards negative infinity is given as formula_64 If tie-breaking is away from 0, then the rounding function is formula_65 (where formula_66 is the sign function), and rounding towards even can be expressed with the more cumbersome formula_67 which is the above expression for rounding towards positive infinity formula_68 minus an integrality indicator for formula_69. Rounding a real number formula_61 to the nearest integer value forms a very basic type of quantizer – a "uniform" one. A typical ("mid-tread") uniform quantizer with a quantization "step size" equal to some value formula_71 can be expressed as formula_72, Number of digits. The number of digits in base "b" of a positive integer "k" is formula_73 Number of strings without repeated characters. The number of possible strings of arbitrary length that doesn't use any character twice is given by formula_74 where: For = 26, this comes out to 1096259850353149530222034277. Factors of factorials. Let "n" be a positive integer and "p" a positive prime number. The exponent of the highest power of "p" that divides "n"! is given by a version of Legendre's formula formula_76 where formula_77 is the way of writing "n" in base "p". This is a finite sum, since the floors are zero when "p""k" > "n". Beatty sequence. 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. Euler's constant (γ). There are formulas for Euler's constant γ = 0.57721 56649 ... that involve the floor and ceiling, e.g. formula_78 formula_79 and formula_80 Riemann zeta function (ζ). The fractional part function also shows up in integral representations of the Riemann zeta function. It is straightforward to prove (using integration by parts) that if formula_81 is any function with a continuous derivative in the closed interval ["a", "b"], formula_82 Letting formula_83 for real part of "s" greater than 1 and letting "a" and "b" be integers, and letting "b" approach infinity gives formula_84 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. For "s" = "σ" + "it" in the critical strip 0 < "σ" < 1, formula_85 In 1947 van der Pol used this representation to construct an analogue computer for finding roots of the zeta function. Formulas for prime numbers. The floor function appears in several formulas characterizing prime numbers. For example, since formula_86 it follows that a positive integer "n" is a prime if and only if formula_87 One may also give formulas for producing the prime numbers. For example, let "p""n" be the "n"-th prime, and for any integer "r" > 1, define the real number "α" by the sum formula_88 Then formula_89 A similar result is that there is a number "θ" = 1.3064... (Mills' constant) with the property that formula_90 are all prime. There is also a number "ω" = 1.9287800... with the property that formula_91 are all prime. Let ("x") be the number of primes less than or equal to "x". It is a straightforward deduction from Wilson's theorem that formula_92 Also, if "n" ≥ 2, formula_93 None of the formulas in this section are of any practical use. Solved problems. Ramanujan submitted these problems to the "Journal of the Indian Mathematical Society". If "n" is a positive integer, prove that Some generalizations to the above floor function identities have been proven. Unsolved problem. The study of Waring's problem has led to an unsolved problem: Are there any positive integers "k" ≥ 6 such that formula_94 Mahler has proved there can only be a finite number of such "k"; none are known. Computer implementations. 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 used ones' complement and truncation was simpler to implement (floor is simpler in two'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. An arithmetic right-shift of a signed integer formula_61 by formula_96 is the same as formula_97. 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. Many programming languages (including C, C++, C#, Java, Julia, PHP, R, and Python) provide standard functions for floor and ceiling, usually called codice_5 and codice_6, or less commonly codice_7. The language APL uses codice_8 for floor. The J Programming Language, a follow-on to APL that is designed to use standard keyboard symbols, uses codice_9 for floor and codice_10 for ceiling. ALGOL usescodice_11 for floor. In Microsoft Excel the function codice_12 rounds down rather than toward zero, while codice_13 rounds toward zero, the opposite of what "int" and "floor" do in other languages. Since 2010 codice_13 has been changed to error if the number is negative. The OpenDocument file format, as used by OpenOffice.org, Libreoffice and others, codice_12 and codice_13 both do floor, and codice_13 has a third argument to reproduce Excel's earlier behavior.