In
mathematicsMathematics is the study of quantity, space, structure, and change. Mathematicians seek out patterns and formulate new conjectures. Mathematicians resolve the truth or falsity of conjectures by mathematical proofs, which are arguments sufficient to convince other mathematicians of their validity...
and
computer scienceComputer science or computing science is the study of the theoretical foundations of information and computation and of practical techniques for their implementation and application in computer systems...
, the
floor and
ceiling functionIn mathematics, a function associates one quantity, the argument of the function, also known as the input, with another quantity, the value of the function, also known as the output. A function assigns exactly one output to each input. The argument and the value may be real numbers, but they can...
s map a
real numberIn mathematics, a real number is a value that represents a quantity along a continuum, such as 5 , 4/3 , 8.6 , √2 and π...
to the largest previous or the smallest following
integerThe integers are formed by the natural numbers together with the negatives of the nonzero natural numbers .They are known as Positive and Negative Integers respectively...
, respectively. More precisely, floor(
x) =
is the largest integer not greater than
x and ceiling(
x) =
is the smallest integer not less than
x.
Notation
Carl Friedrich GaussJohann Carl Friedrich Gauss was a German mathematician and scientist who contributed significantly to many fields, including number theory, statistics, analysis, differential geometry, geodesy, geophysics, electrostatics, astronomy and optics.Sometimes referred to as the Princeps mathematicorum...
introduced the square bracket notation [
x] for the floor function in his third proof of
quadratic reciprocityIn number theory, the law of quadratic reciprocity is a theorem about modular arithmetic which gives conditions for the solvability of quadratic equations modulo prime numbers...
(1808).
This remained the standard in mathematics until
Kenneth E. IversonKenneth Eugene Iverson was a Canadian computer scientist noted for the development of the APL programming language in 1962. He was honored with the Turing Award in 1979 for his contributions to mathematical notation and programming language theory...
introduced the names "floor" and "ceiling" and the corresponding notations
x and
x in his 1962 book
A Programming Language. Both notations are now used in mathematics; this article follows Iverson.
The floor function is also called the
greatest integer or
entier (French for "integer") function, and its value at
x is called the
integral part or
integer part of
x; for negative values of
x the latter terms are sometimes instead taken to be the value of the
ceiling function, i.e., the value of
x rounded to an integer towards 0. The language APL (programming language) uses
⌊x
; other computer languages commonly use notations like
entier(x)
(Algol),
INT(x)
(
BASICBASIC is a family of generalpurpose, highlevel programming languages whose design philosophy emphasizes ease of use  the name is an acronym from Beginner's Allpurpose Symbolic Instruction Code....
), or
floor(x)
(
CC is a generalpurpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....
,
C++C++ is a statically typed, freeform, multiparadigm, compiled, generalpurpose programming language. It is regarded as an intermediatelevel language, as it comprises a combination of both highlevel and lowlevel language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...
,
RR is a programming language and software environment for statistical computing and graphics. The R language is widely used among statisticians for developing statistical software, and R is widely used for statistical software development and data analysis....
, and
PythonPython is a generalpurpose, highlevel programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...
). In mathematics, it can also be written with boldface or double brackets
.
The ceiling function is usually denoted by
ceil(x)
or
ceiling(x)
in nonAPL computer languages that have a notation for this function. The
J Programming LanguageThe J programming language, developed in the early 1990s by Kenneth E. Iverson and Roger Hui, is a synthesis of APL and the FP and FL functionlevel languages created by John Backus....
, a follow on to APL that is designed to use standard keyboard symbols, uses >. for ceiling and <. for floor. In mathematics, there is another notation with reversed boldface or double brackets
or just using normal reversed brackets
]x[.
The
fractional part sawtooth function, denoted by
for real
x, is defined by the formula
For all
x,
Examples
Sample value x 
Floor 
Ceiling 
Fractional part 

12/5 = 2.4 
2 
3 
2/5 = 0.4 
2.7 
2 
3 
0.7 
−2.7 
−3 
−2 
0.3 
−2 
−2 
−2 
0 
Definition and properties
In the following formulas,
x and
y are real numbers,
k,
m, and
n are integers, and
is the set of
integerThe integers are formed by the natural numbers together with the negatives of the nonzero natural numbers .They are known as Positive and Negative Integers respectively...
s (positive, negative, and zero).
Floor and ceiling may be defined by the set equations
Since there is exactly one integer in a halfopen interval of length one, for any real
x there are unique integers
m and
n satisfying
Then
and
may also be taken as the definition of floor and ceiling.
Equivalences
These formulas can be used to simplify expressions involving floors and ceilings.
In the language of
order theoryOrder theory is a branch of mathematics which investigates our intuitive notion of order using binary relations. It provides a formal framework for describing statements such as "this is less than that" or "this precedes that". This article introduces the field and gives some basic definitions...
, the floor function is a
residuated mappingIn mathematics, the concept of a residuated mapping arises in the theory of partially ordered sets. It refines the concept of a monotone function....
, that is, part of a
Galois connectionIn mathematics, especially in order theory, a Galois connection is a particular correspondence between two partially ordered sets . The same notion can also be defined on preordered sets or classes; this article presents the common case of posets. Galois connections generalize the correspondence...
: it is the upper adjoint of the function that embeds the integers into the reals.
These formulas show how adding integers to the arguments affect the functions:
The above are not necessarily true if
n is not an integer; however:
Relations among the functions
It is clear from the definitions that
with equality if and only if
x is an integer, i.e.
In fact, since for integers
n:
Negating the argument switches floor and ceiling and changes the sign:
i.e.
Negating the argument complements the fractional part:
The floor, ceiling, and fractional part functions are
idempotentIdempotence is the property of certain operations in mathematics and computer science, that they can be applied multiple times without changing the result beyond the initial application...
:
The result of nested floor or ceiling functions is the innermost function:
For fixed
y,
x mod
y is idempotent:
Also, from the definitions,
Quotients
If
m and
n are integers and
n ≠ 0,
If
n is positive
If
m is positive
For
m = 2 these imply
More generally, for positive
m (See
Hermite's identity)
The following can be used to convert floors to ceilings and viceversa (
m positive)
If
m and
n are positive and
coprimeIn number theory, a branch of mathematics, two integers a and b are said to be coprime or relatively prime if the only positive integer that evenly divides both of them is 1. This is the same thing as their greatest common divisor being 1...
, then
Since the righthand side is symmetrical in
m and
n, this implies that
More generally, if
m and
n are positive,
This is sometimes called a reciprocity law.
Nested divisions
For positive integers
m,
n, and arbitrary real number
x:


Continuity
None of the functions discussed in this article are
continuousIn mathematics, a continuous function is a function for which, intuitively, "small" changes in the input result in "small" changes in the output. Otherwise, a function is said to be "discontinuous". A continuous function with a continuous inverse function is called "bicontinuous".Continuity of...
, but all are piecewise linear.
and
are piecewise
constant functionIn mathematics, a constant function is a function whose values do not vary and thus are constant. For example the function f = 4 is constant since f maps any value to 4...
s, with discontinuites at the integers.
also has discontinuites at the integers, and
as a function of
x for fixed
y is discontinuous at multiples of
y.
is
upper semicontinuousIn mathematical analysis, semicontinuity is a property of extended realvalued functions that is weaker than continuity...
and
and
are lower semicontinuous.
x mod
y is lower semicontinuous for positive
y and upper semicontinuous for negative
y.
Series expansions
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
Fourier seriesIn mathematics, a Fourier series decomposes periodic functions or periodic signals into the sum of a set of simple oscillating functions, namely sines and cosines...
expansions.
x mod
y for fixed
y has the Fourier series expansion
in particular {
x} =
x mod 1 is given by
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 {x} = x − floor(x), floor(x) = x − {x} gives
Mod operator
The
mod operator, denoted by
x mod
y for real
x and
y,
y ≠ 0, is defined by the formula
x mod
y is always between 0 and
y; i.e.
if
y is positive,
and if
y is negative,
If
x is an integer and
y is a positive integer,
x mod
y for a fixed
y is a
sawtooth function.
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
First,
Gauss's lemmaGauss's lemma in number theory gives a condition for an integer to be a quadratic residue. Although it is not useful computationally, it has theoretical significance, being involved in some proofs of quadratic reciprocity....
is used to show that the
Legendre symbolIn number theory, the Legendre symbol is a multiplicative function with values 1, −1, 0 that is a quadratic character modulo a prime number p: its value on a quadratic residue mod p is 1 and on a quadratic nonresidue is −1....
s are given by
and
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:
Rounding
The ordinary
roundingRounding a numerical value means replacing it by another value that is approximately equal but has a shorter, simpler, or more explicit representation; for example, replacing $23.4476 with $23.45, or the fraction 312/937 with 1/3, or the expression √2 with 1.414.Rounding is often done on purpose to...
of the positive number
x to the nearest integer can be expressed as
The ordinary
roundingRounding a numerical value means replacing it by another value that is approximately equal but has a shorter, simpler, or more explicit representation; for example, replacing $23.4476 with $23.45, or the fraction 312/937 with 1/3, or the expression √2 with 1.414.Rounding is often done on purpose to...
of the negative number
x to the nearest integer can be expressed as
Truncation
The
truncationIn mathematics and computer science, truncation is the term for limiting the number of digits right of the decimal point, by discarding the least significant ones.For example, consider the real numbersThe result would be: Truncation and floor function :...
of a nonnegative number is given by
The truncation of a nonpositive number is given by
.
The truncation of any real number can be given by:
, where sgn(x) is the
sign functionIn mathematics, the sign function is an odd mathematical function that extracts the sign of a real number. To avoid confusion with the sine function, this function is often called the signum function ....
.
Number of digits
The number of digits in base
b of a positive integer
k is

with the right side of the equation also holding true for
.
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 the formula
Note that this is a finite sum, since the floors are zero when
p^{k} >
n.
Beatty sequence
The
Beatty sequenceIn mathematics, a Beatty sequence is the sequence of integers found by taking the floor of the positive multiplesof a positive irrational number...
shows how every positive
irrational numberIn mathematics, an irrational number is any real number that cannot be expressed as a ratio a/b, where a and b are integers, with b nonzero, and is therefore not a rational number....
gives rise to a partition of the
natural numberIn mathematics, the natural numbers are the ordinary whole numbers used for counting and ordering . These purposes are related to the linguistic notions of cardinal and ordinal numbers, respectively...
s into two sequences via the floor function.
Euler's constant (γ)
There are formulas for
Euler's constantThe Euler–Mascheroni constant is a mathematical constant recurring in analysis and number theory, usually denoted by the lowercase Greek letter ....
γ = 0.57721 56649 ... that involve the floor and ceiling, e.g.
and
Riemann 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 φ(
x) is any function with a continuous derivative in the closed interval [
a,
b],
Letting φ(
n) =
n^{−s} 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.
For
s = σ +
i t in the critical strip (i.e. 0 < σ < 1),
In 1947
van der PolBalthasar van der Pol was a Dutch physicist.Van der Pol studied physics in Utrecht, and in 1920 he was awarded his doctorate . He studied experimental physics with John Ambrose Fleming and Sir J. J. Thomson in England...
used this representation to construct an analogue computer for finding roots of the zeta function.
Formulas for prime numbers
n is a prime if and only if
Let
r > 1 be an integer,
p_{n} be the
n^{th} prime, and define
Then
There is a number θ = 1.3064... (Mill's constant) with the property that
are all prime.
There is also a number ω = 1.9287800... with the property that
are all prime.
π(
x) is the number of primes less than or equal to
x. It is a straightforward deduction from
Wilson's theorem that
Also, if
n ≥ 2,
None of the formulas in this section is of any practical use.
Solved problem
Ramanujan submitted this problem to the
Journal of the Indian Mathematical Society.
If
n is a positive integer, prove that
(i)
(ii)
(iii)
Unsolved problem
The study of
Waring's problemIn number theory, Waring's problem, proposed in 1770 by Edward Waring, asks whether for every natural number k there exists an associated positive integer s such that every natural number is the sum of at most s kth powers of natural numbers...
has led to an unsolved problem:
Are there any positive integers
k,
k ≥ 6, such that
MahlerKurt Mahler was a mathematician and Fellow of the Royal Society.He was a student at the universities in Frankfurt and Göttingen, graduating with a Ph.D...
has proved there can only be a finite number of such
k; none are known.
Computer implementations
Many programming languages (including
CC is a generalpurpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....
,
C++C++ is a statically typed, freeform, multiparadigm, compiled, generalpurpose programming language. It is regarded as an intermediatelevel language, as it comprises a combination of both highlevel and lowlevel language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...
,,
PHPPHP is a generalpurpose serverside scripting language originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document...
, and
PythonPython is a generalpurpose, highlevel programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...
) provide standard functions for floor and ceiling.
Spreadsheet software
Most
spreadsheetA spreadsheet is a computer application that simulates a paper accounting worksheet. It displays multiple cells usually in a twodimensional matrix or grid consisting of rows and columns. Each cell contains alphanumeric text, numeric values or formulas...
programs support some form of a
ceiling
function. Although the details differ between programs, most implementations support a second parameter—a multiple of which the given number is to be rounded to. For example,
ceiling(2, 3)
rounds 2 up to the nearest multiple of 3, giving 3. The definition of what "round up" means, however, differs from program to program.
Until Excel 2010,
Microsoft ExcelMicrosoft Excel is a proprietary commercial spreadsheet application written and distributed by Microsoft for Microsoft Windows and Mac OS X. It features calculation, graphing tools, pivot tables, and a macro programming language called Visual Basic for Applications...
's
ceiling
function was incorrect for negative arguments; ceiling(4.5) was 5.
. This has followed through to the Office Open XML file format. The correct ceiling function can be implemented using "
INT(value)
". Excel 2010 now follows the standard definition.
The
OpenDocumentThe Open Document Format for Office Applications is an XMLbased file format for representing electronic documents such as spreadsheets, charts, presentations and word processing documents....
file format, as used by
OpenOffice.orgOpenOffice.org, commonly known as OOo or OpenOffice, is an opensource application suite whose main components are for word processing, spreadsheets, presentations, graphics, and databases. OpenOffice is available for a number of different computer operating systems, is distributed as free software...
and others, follows the mathematical definition of ceiling for its
ceiling
function, with an optional parameter for Excel compatibility. For example,
CEILING(4.5)
returns −4.
Typesetting
The floor and ceiling function are usually typeset with left and right square brackets where the upper (for floor function) or lower (for ceiling function) horizontal bars are missing, and, e.g., in the
LaTeXLaTeX is a document markup language and document preparation system for the TeX typesetting program. Within the typesetting system, its name is styled as . The term LaTeX refers only to the language in which documents are written, not to the editor used to write those documents. In order to...
typesetting system these symbols can be specified with the \lfloor, \rfloor, \lceil and \rceil commands in math mode. HTML 4.0 uses the same names:
⌊,
⌋,
⌈, and
⌉.
UnicodeUnicode is a computing industry standard for the consistent encoding, representation and handling of text expressed in most of the world's writing systems...
contains codepoints for these symbols at
U+2308
–
U+230B
: ⌈
x⌉, ⌊
x⌋.
External links
 Š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