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 , and which is the smallest one that is not less than ?
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,
The fractional part is . The negative example matters: discarding the digits after the decimal point would give , which is truncation toward zero, rather than the floor function's value . At an integer, the floor function and ceiling function agree and the fractional part vanishes.
Figure 1.
Floor and ceiling give enclosing integers; fractional part repeats on each unit interval
. Details.
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
follows by reflecting the ordered integers across zero: the largest one below becomes the smallest one above . For every integer , translation gives and . 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 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. [ref]
For real numbers , the integers in the closed interval begin at and end at , if there are any. Their number is therefore
The extra one includes both ends of the resulting integer interval. The maximum with zero handles an empty intersection: contains no integer, even though it has positive length.
For , the ceiling function selects and the floor function selects , giving . The four points are . For , the count is five, not four: the real length and the number of integer points are different quantities.
The endpoint convention matters. For the half-open interval with , the last allowed integer is , so the count becomes . This handles an integer endpoint without including it accidentally. For example, has four integer points.
The floor is the greatest integer not exceeding the real number . Equivalently, exactly when , for an integer . The floor function is constant on each such half-open interval and has a discontinuity of a function at each integer.
For nonnegative integers and positive integers , is the number of complete groups of size that fit into items. With and , five complete groups use 100 items. Euclidean division writes , retaining the two-item remainder rather than treating the quotient as a number of complete groups.
The fractional part of a real number is
It is the amount left after removing the lower enclosing integer, even for negative inputs. Thus . It is not the signed string of digits obtained by truncation toward zero.
Translation by an integer leaves the fractional part unchanged: . It is therefore a periodic function with period one, increasing from zero toward one on each unit interval, then returning to zero at the next integer. In Euclidean division with , ; for , this is .
The notation is useful for following repeated motion modulo an integer. In normality and equidistribution under integer multiplication, the values shift the digits of a positional notation; the fractional part discards the leading integer portion without losing the remaining digits. Its braces must be distinguished by context from the braces denoting a set.
The ceiling function gives the least integer large enough to meet a real lower bound. For a real number ,
Thus , , and . The operation rounds upward in the total order on the real numbers, which can move a negative input towards zero. Its difference from the input obeys . Python's math.ceil implements this least-integer definition. [ref].
The ceiling count for fixed-size batches is a direct application. Suppose each box holds at most items, with positive integer , and there are items. The smallest number of boxes with enough capacity is : a candidate count must satisfy . For , , six boxes are needed, leaving unused places. Exactly 100 items need only five boxes, and zero items need zero boxes. Adding one to the floor function result unconditionally would therefore overcount at exact multiples of .
Figure 1.
The ceiling function retains the endpoint on the left and counts enough whole containers
. Left: open and filled endpoints distinguish the half-open intervals where , including negative inputs. Right: the original capacity example uses 20 items per box; 101 items need six boxes, while an exact multiple of 20 needs no extra box. The right-hand inputs are integer item counts. Details.
For nonnegative integer and positive integer , Euclidean division gives the exact identity
Write , . The count is when the remainder is zero and otherwise, and the right-hand side encodes these two cases. This argument specifies the domain of the identity; arbitrary negative denominators require their own sign conventions.
The ceiling function is a nondecreasing function, constant on each of the half-open intervals , and has a discontinuity of a function at every integer. It is tied to the floor function by . Adding an integer shifts its output by the same amount: . At an integer the floor and ceiling agree; at every other input they differ by one. These statements refer to exact real numbers; an input already perturbed by floating-point arithmetic can land on the other side of a threshold.
Suppose is a nonnegative integer count of items and each batch holds at most items, where is a positive integer. The smallest sufficient number of batches is
Indeed, exactly when the integer is at least . If , no batches are needed. If is a multiple of , no partly filled batch is needed.
For items with capacity per batch, . Five batches can be full and the sixth holds two items, leaving unused places. This is a different question from the five complete groups counted by .
Figure 1.
Endpoint-aware integer counts and six twenty-place batches needed for 102 items
. Details.
Writing the Euclidean division , , gives the equivalent rule when , and when . This explains the ceiling function's jump: one extra item beyond a complete multiple demands a whole additional batch. For exact integer arithmetic, the identity avoids a fractional intermediate value; an implementation still needs an integer representation large enough to hold .
Truncation toward zero removes the fractional magnitude of a real number, giving the integer obtained by applying the floor function to its absolute value and restoring the original sign; a magnitude below one gives zero. More precisely,
The result is zero for . For example, and , whereas . Python's math.trunc uses this towards-zero convention, so replacing it by math.floor changes calculations with negative noninteger inputs. [ref].
Figure 1.
Truncation toward zero is symmetric in sign, while the fractional part defined by the floor function is always nonnegative
. Left: exact integer endpoint values distinguish the two sign-dependent truncation rules; a whole neighborhood of zero maps to zero. Right: takes the sign of a noninteger input, while lies in on both sides of zero. Open endpoints show excluded limiting values. Details.
For every real number ,
The discarded difference has the sign of when is noninteger. In contrast, the fractional part is always in . At , these two differences are and . Thus specifying a signed fractional remainder requires specifying which integer-valued operation is used.
Unlike the floor function and ceiling function, truncation toward zero need not commute with adding an integer. At and , , whereas . This matters if negative coordinates are assigned to equal-width bins by converting a quotient to an integer: belongs to the bin under the floor function, but truncation gives zero. The appropriate operation follows from the declared bin intervals.
Truncation toward zero is a nondecreasing function with a discontinuity of a function at each nonzero integer. It has no discontinuity of a function at zero, because it is identically zero on . Its agreement with the floor function on the positive side and the ceiling function on the negative side explains the different closed endpoints in the diagram.

Articles by others on the same topic (1)

The floor and ceiling functions are mathematical functions that map real numbers to integers. ### Floor Function The **floor function**, denoted as \( \lfloor x \rfloor \), is defined as the greatest integer less than or equal to \( x \). In other words, it "rounds down" a real number to the nearest integer. **Example:** - \( \lfloor 3.7 \rfloor = 3 \) - \( \lfloor -2.