Skip to main content

Floor Function Calculator

Calculate floor function instantly with our math tool. Shows detailed work, formulas used, and multiple solution methods.

Share this calculator

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\n\nfloor(-3.7) = -4 (greatest integer <= -3.7)\nceil(-3.7) = -3 (smallest integer >= -3.7)\ntrunc(-3.7) = -3 (remove decimal, round toward zero)\nround(-3.7) = -4 (round to nearest integer)\n\nFractional part: {-3.7} = -3.7 - (-4) = 0.3\nDistance to floor: 0.3\nDistance 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\n\nfloor(5.0) = 5\nceil(5.0) = 5\ntrunc(5.0) = 5\nround(5.0) = 5\n\nFractional part: {5.0} = 5.0 - 5 = 0.0\nAll rounding functions agree when x is an integer.\nProperty: 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.

References