Floor Function Calculator

Calculate floor(x) = ⌊x⌋ and compare with ceiling, round, and truncate. Handles negative numbers correctly.

Enter a Number

Comparison Table: Floor vs Ceil vs Round vs Trunc

x⌊x⌋⌈x⌉round(x)trunc(x)
3.73443
3.23433
3.53443
-3.2-4-3-3-3
-3.7-4-3-4-3
-3.5-4-3-3-3
5.05555
-5.0-5-5-5-5

Result

Floor Function
3
⌊3.7⌋ = 3
Floor
3
Ceiling
4
Round
4
Truncate
3
Input (x) 3.7
Floor: ⌊x⌋ 3
Ceiling: ⌈x⌉ 4
Round: round(x) 4
Truncate: trunc(x) 3
Fractional part: x - ⌊x⌋ 0.7
Is integer? No

Step-by-Step Solution

⌊3.7⌋ = 3

Understanding the Floor Function

The floor function, denoted ⌊x⌋ or floor(x), 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 toward negative infinity. For positive numbers, this means dropping the decimal part. For negative numbers, the behavior is more subtle: ⌊-3.2⌋ = -4, not -3, because -4 is the greatest integer that is less than or equal to -3.2.

The floor function is fundamental in mathematics and computer science. It appears in number theory, combinatorics, algorithm design, and digital signal processing.

Rounding Functions Compared

Floor Function ⌊x⌋

Greatest integer less than or equal to x. Rounds toward negative infinity.

⌊3.7⌋ = 3, ⌊-3.2⌋ = -4

Ceiling Function ⌈x⌉

Smallest integer greater than or equal to x. Rounds toward positive infinity.

⌈3.2⌉ = 4, ⌈-3.7⌉ = -3

Round Function

Rounds to the nearest integer. Ties (0.5) typically round to even ("banker's rounding") or up.

round(3.5) = 4, round(2.5) = 2 or 3

Truncate Function

Removes the fractional part. Rounds toward zero.

trunc(3.7) = 3, trunc(-3.7) = -3

Fractional Part

The difference between x and its floor: {x} = x - ⌊x⌋. Always in [0, 1).

{3.7} = 0.7, {-3.2} = 0.8

Floor-Ceiling Identity

For non-integer x: ⌈x⌉ = ⌊x⌋ + 1. For integer x: both are equal to x.

⌈x⌉ = ⌊x⌋ + 1 (x not integer)

Key Properties of the Floor Function

  • Idempotent: ⌊⌊x⌋⌋ = ⌊x⌋ (applying floor twice gives the same result).
  • Integer shift: ⌊x + n⌋ = ⌊x⌋ + n for any integer n.
  • Monotone: If x ≤ y, then ⌊x⌋ ≤ ⌊y⌋.
  • Bounds: ⌊x⌋ ≤ x < ⌊x⌋ + 1 for all real x.
  • Negation: ⌊-x⌋ = -⌈x⌉ for all real x.
  • Hermite's identity: ⌊nx⌋ = sum of ⌊x + k/n⌋ for k = 0 to n-1.

Applications of the Floor Function

  • Computing array indices from continuous coordinates in computer graphics.
  • Implementing integer division in programming languages.
  • Counting multiples of a number in a range (e.g., ⌊n/p⌋ multiples of p up to n).
  • Generating discrete distributions in probability and statistics.
  • Digital signal processing: sample rate conversion and quantization.

Floor Function in Programming

Most programming languages provide a floor function: Math.floor() in JavaScript, math.floor() in Python, Math.Floor() in C#, and floor() in C/C++. Be aware that integer division in C/C++ and Java truncates toward zero, which differs from floor division for negative numbers.