Floor Function Calculator
Calculate floor function instantly with our math tool. Shows detailed work, formulas used, and multiple solution methods.
Reviewed for accuracy by Manoj Kumar, Mathematics Educator
Floor Function Calculator
Calculator
Adjust values & calculateEnter your values below. Every result is computed in your browser โ no data is sent to any server.
Formula: floor(x) = max { n in Z : n <= x }
Worked example โ floor(-3.7) = -4 | ceil(-3.7) = -3 | trunc(-3.7) = -3 | frac = 0.3
Formula
floor(x) = max { n in Z : n <= x }The floor of x is the greatest integer n that is less than or equal to x. Equivalently, it is the unique integer satisfying floor(x) <= x < floor(x) + 1. The fractional part is {x} = x - floor(x), always in [0, 1).
Worked Examples
Example 1: Floor, Ceiling, and Truncation Comparison
Problem:Compare floor, ceiling, truncation, and rounding for the value -3.7.
Solution:Input: x = -3.7 floor(-3.7) = -4 (greatest integer <= -3.7) ceil(-3.7) = -3 (smallest integer >= -3.7) trunc(-3.7) = -3 (remove decimal, round toward zero) round(-3.7) = -4 (round to nearest integer) Fractional part: {-3.7} = -3.7 - (-4) = 0.3 Distance to floor: 0.3 Distance to ceiling: 0.7
Result:floor(-3.7) = -4 | ceil(-3.7) = -3 | trunc(-3.7) = -3 | frac = 0.3
Example 2: Floor Function at an Integer
Problem:Evaluate the floor function and related functions at x = 5.0.
Solution:Input: x = 5.0 floor(5.0) = 5 ceil(5.0) = 5 trunc(5.0) = 5 round(5.0) = 5 Fractional part: {5.0} = 5.0 - 5 = 0.0 All rounding functions agree when x is an integer. Property: floor(x) = ceil(x) = x when x is an integer.
Result:floor(5.0) = ceil(5.0) = trunc(5.0) = round(5.0) = 5
Frequently Asked Questions
What is the floor function in mathematics?
The floor function, denoted by floor(x) or using floor brackets, maps a real number x to the greatest integer less than or equal to x. In other words, it rounds DOWN to the nearest integer, always toward negative infinity. For positive numbers, floor(3.7) = 3 and floor(3.0) = 3. For negative numbers, floor(-2.3) = -3 (not -2), because -3 is the greatest integer that is still less than or equal to -2.3. The floor function is also called the greatest integer function or the integer part function in some textbooks. It is a fundamental function in discrete mathematics, number theory, and computer science, appearing in countless algorithms and mathematical formulas.
How does the floor function differ from the ceiling function?
The ceiling function (ceil) is the complementary counterpart to the floor function. While floor rounds down to the nearest integer (toward negative infinity), ceiling rounds UP to the nearest integer (toward positive infinity). For positive numbers: floor(3.2) = 3 and ceil(3.2) = 4. For negative numbers: floor(-3.2) = -4 and ceil(-3.2) = -3. An important identity connects them: floor(x) + ceil(-x) = 0, or equivalently ceil(x) = -floor(-x). When x is already an integer, floor(x) = ceil(x) = x. The floor and ceiling functions together form the basis for integer rounding in computing, and their difference ceil(x) - floor(x) equals 0 when x is an integer and 1 otherwise.
What is the fractional part function and how does it relate to floor?
The fractional part of x, denoted {x} or frac(x), is defined as x minus floor(x). It represents the portion of x that lies between consecutive integers. For positive numbers, {3.7} = 3.7 - 3 = 0.7. The fractional part is always in the range 0 (inclusive) to 1 (exclusive), meaning 0 <= {x} < 1. For negative numbers, {-2.3} = -2.3 - floor(-2.3) = -2.3 - (-3) = 0.7, which may be surprising but is consistent with the definition. This means the fractional part is always non-negative. The identity x = floor(x) + {x} holds for all real numbers. The fractional part function is periodic with period 1 and creates a sawtooth wave pattern when graphed.
How is the floor function different from truncation?
Truncation (also called the integer part or trunc function) removes the decimal portion of a number, effectively rounding toward zero. For positive numbers, floor and truncation give the same result: floor(3.7) = trunc(3.7) = 3. The crucial difference appears with negative numbers: floor(-2.3) = -3 (rounds toward negative infinity) while trunc(-2.3) = -2 (rounds toward zero). Another way to understand it: truncation always moves toward zero on the number line, while floor always moves to the left (toward negative infinity). In programming, C and Java use truncation for integer casting, while Python uses floor for its // operator. This distinction is the source of many subtle bugs when working with negative numbers.
What are the key mathematical properties of the floor function?
The floor function satisfies several important properties. First, the defining inequalities: floor(x) <= x < floor(x) + 1, meaning x is always trapped between floor(x) and the next integer. Second, floor is idempotent: floor(floor(x)) = floor(x). Third, it distributes over integer addition: floor(x + n) = floor(x) + n for any integer n. Fourth, the relationship floor(-x) = -ceil(x) connects floor and ceiling. Fifth, for positive integers a and b: floor(a/b) gives the quotient in integer division. The floor function is also a step function that is right-continuous: at each integer n, floor(n) = n, but approaching from the left, floor(n - epsilon) = n - 1. These properties are used extensively in proofs involving number theory.
How is the floor function used in computer science?
The floor function is ubiquitous in computer science. In binary search, the midpoint is calculated as floor((low + high) / 2) to ensure an integer index. Hash tables use floor(n * fraction) for hash distribution. Memory allocation uses floor to determine how many fixed-size blocks fit in available space. Page numbering in pagination: items on page k start at index k * page_size, determined by floor(item_index / page_size). In graphics programming, pixel coordinates use floor to convert floating-point positions to discrete grid positions. The floor function also appears in analysis of algorithms: the height of a balanced binary tree with n nodes is floor(log2(n)). Time complexity of merge sort uses the recurrence T(n) = T(floor(n/2)) + T(ceil(n/2)) + n.
What is the Hermite identity involving the floor function?
The Hermite identity (also known as the Hermite subdivision formula) states that for any real number x and positive integer n: floor(x) + floor(x + 1/n) + floor(x + 2/n) + ... + floor(x + (n-1)/n) = floor(nx). For example, with x = 1.3 and n = 3: floor(1.3) + floor(1.3 + 1/3) + floor(1.3 + 2/3) = 1 + 1 + 1 = 3, and floor(3 * 1.3) = floor(3.9) = 3. This identity is used in number theory proofs, particularly in counting lattice points and in Ramanujan-type formulas. It generalizes the simple observation that floor(2x) = floor(x) + floor(x + 1/2), which splits the floor of a doubled value into two floor evaluations.
How does the floor function appear in number theory?
The floor function is central to many number theory results. Legendre's formula uses it to count the power of a prime p in n!: the exponent equals floor(n/p) + floor(n/p^2) + floor(n/p^3) + ... This determines trailing zeros in factorials. The floor function also counts lattice points: the number of integer points (x,y) with 0 < x <= a and 0 < y <= b*x/a is given by a sum involving floor(b*k/a). In the theory of continued fractions, the floor function extracts the integer part at each step of the continued fraction expansion. Beatty's theorem uses floors to partition the positive integers: if 1/r + 1/s = 1, then floor(nr) and floor(ns) partition the natural numbers.
What are common mistakes when using the floor function?
The most common mistake is confusing floor with truncation for negative numbers. Many people assume floor(-2.7) = -2 when it is actually -3. Another frequent error is assuming floor distributes over multiplication: floor(a) * floor(b) does NOT equal floor(a * b) in general. For example, floor(1.5) * floor(1.5) = 1 * 1 = 1, but floor(1.5 * 1.5) = floor(2.25) = 2. Floating-point precision can also cause issues: due to binary representation, a number that should be exactly 3.0 might be stored as 2.9999999999999996, causing floor to return 2 instead of 3. Adding a small epsilon before flooring can mitigate this but introduces its own risks.
How do you graph the floor function and what does it look like?
The graph of the floor function is a step function (also called a staircase function). For each integer n, the function value is n on the interval [n, n+1). This means the graph consists of horizontal line segments at each integer height, with closed dots on the left endpoint and open dots on the right. At x = 0, the step goes from -1 (for negative x approaching 0) to 0. At x = 1, it jumps from 0 to 1, and so on. The function is right-continuous: it is continuous from the right at each integer but has a jump discontinuity from the left. The ceiling function has a similar staircase shape but shifted: it is left-continuous instead. Understanding this graph helps visualize why floor(x) equals x only when x is an integer.
References
Reviewed for accuracy by Manoj Kumar, Mathematics Educator ยท Editorial policy
Related Calculators
๐งฎBessel Function Calculator
Calculate bessel function with inputs, formulas, and instant results.
๐งฎComposite Function Calculator
Calculate composite function with inputs, formulas, and instant results.
๐งฎError Function Calculator
Calculate error function with inputs, formulas, and instant results.
๐งฎFunction Domain Calculator
Calculate function domain with inputs, formulas, and instant results.
๐งฎFunction Range Calculator
Calculate function range with inputs, formulas, and instant results.
๐งฎGamma Function Calculator
Calculate gamma function with inputs, formulas, and instant results.
๐งฎInverse Function Calculator
Calculate inverse function with inputs, formulas, and instant results.
๐งฎPiecewise Function Evaluator
Calculate piecewise function evaluator with inputs, formulas, and instant results.