= Floor and ceiling functions
{title2=$\lfloor x\rfloor,\quad\lceil x\rceil$}
{wiki}
The <floor function> and <ceiling function> turn a <real number> into directed <integer> bounds. They answer two different questions: which <integer> is the largest one that does not exceed $x$, and which is the smallest one that is not less than $x$?
$$
\lfloor x\rfloor\leq x<\lfloor x\rfloor+1,\qquad
\lceil x\rceil-1<x\leq\lceil x\rceil.
$$
Both outputs are <integers>. These are exact mathematical operations; they need not choose the closest <integer>, and they do not refer to <roundoff error> in <floating-point arithmetic>.
For example,
$$
\begin{array}{c|r|r|r}
x&\lfloor x\rfloor&\lceil x\rceil&\{x\}\\\hline
2.7&2&3&0.7\\
2&2&2&0\\
-2.7&-3&-2&0.3\\
-2&-2&-2&0
\end{array}
$$
The <fractional part> is $\{x\}=x-\lfloor x\rfloor$. The negative example matters: discarding the digits after the decimal point would give $-2$, which is <truncation toward zero>, rather than the <floor function>'s value $-3$. At an <integer>, the <floor function> and <ceiling function> agree and the <fractional part> vanishes.
\Image[/floor-ceiling-and-fractional-part.png]
{title=Floor and ceiling give enclosing integers; fractional part repeats on each unit interval}
The usefulness is a bridge from continuous quantities to discrete decisions. An <integer count in a closed interval> uses both bounds. A <ceiling count for fixed-size batches> counts how many containers or pages are needed; a <floor function> counts how many complete groups fit. In <Euclidean division>, the same bounds specify the quotient, while the <fractional part> records the scaled <remainder>. A small amount of notation removes many cases that would otherwise have to be stated separately.
The reflection identity
$$
\lceil x\rceil=-\lfloor-x\rfloor
$$
follows by reflecting the ordered <integers> across zero: the largest one below $-x$ becomes the smallest one above $x$. For every <integer> $m$, translation gives $\lfloor x+m\rfloor=\lfloor x\rfloor+m$ and $\lceil x+m\rceil=\lceil x\rceil+m$. These formulas turn upper bounds into lower bounds and move examples between neighboring <intervals>.
For a historical example of the notation in use, Kenneth E. Iverson's 1962 conference paper \i[A Programming Language] lists the <floor function>, <ceiling function> and residue operation alongside the ordinary <arithmetic operations>. It states the two defining inequalities above, then extends operations component by component to <vectors> and <matrices>. This shows their role as tools for describing <algorithms>, rather than merely conventions for writing decimal numbers. https://www.jsoftware.com/papers/AFIPS196205a.htm[Iverson, A Programming Language, AFIPS Spring Joint Computer Conference, May 1962, Basic Operations; transcription with typography changes documented at the end]{ref}
Back to article page