Algebra • Number Theory • Computer Science

Floor Division Calculator

Compute mathematical floor division ⌊a / b⌋, evaluate exact quotients, calculate Euclidean modulo remainders, and compare Python floored division with C, C++, and Java truncated integer division.

|
Last Updated: September 2026
|
Verified Accurate: Discrete Mathematics & Computational Number Theory
Arithmetic • Number Theory • Programming Exact Floor Computed
Common Division Test Cases: Click to calculate & compare
numerator
denominator
Floor Division Result ⌊ a / b ⌋ (Python //)
2
7 // 3 = 2 with remainder r = 1
Real Quotient (a / b)
2.3333
Floored Remainder (r)
1
Truncated / (C/Java)
2
Ceiling ⌈ a / b ⌉
3
Euclidean Division Identity Check (a = b · q + r)
7 = (3 · 2) + 1 = 6 + 1 = 7
Number Line Rounding Towards -∞
The Floor Rule: For any real number $x$, $\lfloor x \rfloor$ selects the largest integer $\le x$. Moving downwards (leftwards) on the number line ensures consistent algebraic monotonicity.
Comparison Across Programming Languages & Mathematical Conventions
Division Method Quotient Rounding Direction Representative Syntax
Mathematical Floor 2 Rounds towards -∞ Python: a // b, Math: ⌊a/b⌋
Truncated Division 2 Rounds towards 0 (chops decimal) C, C++, Java, JS: Math.trunc(a/b)
Ceiling Division 3 Rounds towards +∞ Math: ⌈a/b⌉, JS: Math.ceil(a/b)
Standard Rounding 2 Nearest integer (half up) JS: Math.round(a/b)
Direct Answer & Overview
Verified Educational Guide

How Floor Division Works in Mathematics and Programming

Floor division computes the real quotient of two numbers and rounds it down to the greatest integer less than or equal to that value: q = ⌊a / b⌋. In Python, this is executed with the // operator. For positive numbers, 7 // 3 = 2. For negative quotients, it rounds downward toward negative infinity: -7 // 3 = -3, maintaining the Euclidean remainder relation a = b·q + r with a positive remainder r = 2.

Primary Mathematical Formula Floor Division and Euclidean Remainder Relation
Standard Equation
ƒ(x)
Q.E.D.
q=⌊ab⌋,r=a−b⋅q  ⟹  a=b⋅q+rq = \left\lfloor \frac{a}{b} \right\rfloor, \quad r = a - b \cdot q \implies a = b \cdot q + r
Where a is the dividend, b is the non-zero divisor, q is the floored integer quotient, and r is the associated remainder satisfying 0 ≤ r < b for b > 0.
Exact Formula
Input Parameters
Required
1
Dividend (a) — The number being divided (numerator)
2
Divisor (b) — The number dividing by (denominator, b ≠ 0)
Expected Outputs
Calculated
Floored Quotient ⌊a/b⌋ — The greatest integer less than or equal to a / b
Real Decimal Quotient — Exact continuous quotient a / b
Floored Remainder (Modulo) — Remainder satisfying r = a - b·⌊a/b⌋
Truncated Comparison — Comparison against C/C++/Java truncated division
Worked Numerical Example
Instant Verification
Floor Division of Negative Dividend: -7 // 3
1 Compute continuous real division: -7 / 3 = -2.3333...
2 Apply floor function ⌊-2.3333...⌋: Rounds down toward -∞ to yield -3
3 Calculate Euclidean remainder: r = -7 - 3(-3) = -7 + 9 = 2
4 Verify Euclidean identity: -7 = (3 × -3) + 2 = -9 + 2 = -7

Formal Mathematical Definition: The Floor Function

The concept of floor division rests upon the mathematical floor function, first introduced by Carl Friedrich Gauss in his proofs of quadratic reciprocity and later popularized with standard square bracket notation $\lfloor x \rfloor$ by Kenneth Iverson in 1962.

For any real number $x \in \mathbb{R}$, the floor of $x$, denoted $\lfloor x \rfloor$, is formally defined as the greatest integer that is less than or equal to $x$:

\lfloor x \rfloor = \max { n \in \mathbb{Z} : n \le x }

Floor division takes a dividend $a$ and a non-zero divisor $b$, computes their exact continuous real quotient $\frac{a}{b}$, and immediately maps that quotient into the integers via the floor function:

q = a // b = \left\lfloor \frac{a}{b} \right\rfloor

Crucially, the floor function satisfies the strict bounding inequalities $x - 1 < \lfloor x \rfloor \le x$. This ensures that floor division always rounds strictly downwards along the real number line toward negative infinity ($-\infty$). For algebraic polynomial calculations, explore our find coefficients calculator and factoring polynomials guide.

The Division Algorithm and Euclidean Remainder Identity

In number theory, the Division Algorithm states that for any two integers $a$ and $b$ (with $b \neq 0$), there exist unique integers $q$ (the quotient) and $r$ (the remainder) that satisfy:

a = b \cdot q + r

When quotient $q$ is defined via mathematical floor division ($q = \lfloor a / b \rfloor$), the remainder $r$ is algebraically locked into the formula:

r = a - b \cdot \left\lfloor \frac{a}{b} \right\rfloor

When the divisor $b$ is positive ($b > 0$), the remainder $r$ is guaranteed to satisfy the canonical Euclidean bounds:

0 \le r < b

This property is profound: under floor division, the remainder $r$ is always strictly non-negative, even when the dividend $a$ is negative. This consistency forms the bedrock of modular arithmetic and cyclical indexing.

Floor Division vs. Truncated Division: The Negative Number Divergence

One of the most persistent sources of bugs across software engineering is the subtle distinction between Floored Division and Truncated Division. For positive operands, both methods behave identically. However, as soon as negative numbers are introduced, their outputs diverge:

Expression Real Quotient Floor Division (Python //) Truncated Division (C/Java /)
7 / 3 +2.3333 2 2
-7 / 3 -2.3333 -3 (rounds down to -∞) -2 (chops fractional part)
7 / -3 -2.3333 -3 -2
-7 / -3 +2.3333 2 2

Notice the consequences for the remainder: in C/C++/Java, because truncated division computes $-7 / 3 = -2$, the remainder evaluates to $-7 - 3(-2) = -1$, yielding a negative remainder! In contrast, Python's floored division yields $-7 // 3 = -3$, producing a clean positive remainder: $-7 - 3(-3) = +2$.

How Major Programming Languages Implement Integer Division

The choice of rounding mode in integer division represents a fundamental design decision across modern programming language ecosystems:

Languages Adopting Floored Division

  • Python: Uses a // b for floor division and a % b for floored modulo.
  • Ruby: Division between integers defaults to floor division.
  • R: Provides a %/% b for integer floor division.
  • Julia: Provides div(a, b, RoundDown) or fld(a, b).

Languages Adopting Truncated Division

  • C & C++ (C99 and later): The / operator on integers strictly truncates toward zero.
  • Java & C#: Integer division a / b truncates toward zero. Use Math.floorDiv(a, b) for floor division.
  • JavaScript (ES6): Uses Math.trunc(a / b) for truncation and Math.floor(a / b) for floor division.
  • Rust: Integer division a / b truncates toward zero; provides div_floor() in standard traits.

Computational Applications: Array Indexing, Pagination, and Hashing

Floor division serves as a critical primitive across foundational computer algorithms:

1. Two-Dimensional Grid Mapping from 1D Linear Indices

When storing a 2D matrix of width $W$ inside a 1D flat array, converting a linear index $i$ to its 2D coordinates $(row, col)$ requires floor division and modulo:

row = \lfloor i / W \rfloor, \quad col = i \pmod W

2. Pagination and Chunking

To determine which page an item with index $k$ belongs to given a fixed page size $P$, floor division identifies the zero-indexed page: $page = \lfloor k / P \rfloor$. To calculate the total number of pages needed for $N$ total items, ceiling division is used: $totalPages = \lceil N / P \rceil = \lfloor (N + P - 1) / P \rfloor$.

3. Hash Table Bucket Assignment

Hash functions map arbitrary keys to 32-bit or 64-bit integers. If hash codes produce negative integers, applying floored modulo $h \pmod M$ guarantees a valid array index within $[0, M-1]$, whereas truncated modulo can yield an invalid negative index leading to an out-of-bounds crash.

Step-by-Step Worked Division Problems with Negative and Decimal Operands

Example 1: Standard Positive Integers

Compute the floor division and remainder of $19 // 4$.

1. Continuous real division: $\frac{19}{4} = 4.75$.

2. Apply floor function: $\lfloor 4.75 \rfloor = 4$.

3. Calculate remainder: $r = 19 - 4(4) = 19 - 16 = 3$.

4. Verify Euclidean Identity: $19 = (4 \times 4) + 3 = 16 + 3 = 19$.

Example 2: Negative Dividend

Compute the floor division and remainder of $-19 // 4$.

1. Continuous real division: $\frac{-19}{4} = -4.75$.

2. Apply floor function: The greatest integer $\le -4.75$ is $-5$ (since $-5 < -4.75$).

3. Calculate remainder: $r = -19 - 4(-5) = -19 + 20 = 1$.

4. Verify Euclidean Identity: $-19 = (4 \times -5) + 1 = -20 + 1 = -19$.

Example 3: Floating-Point Real Operands

Compute the floor division of $10.8 // 2.5$.

1. Continuous real division: $\frac{10.8}{2.5} = 4.32$.

2. Apply floor function: $\lfloor 4.32 \rfloor = 4$.

3. Calculate remainder: $r = 10.8 - (2.5 \times 4) = 10.8 - 10.0 = 0.8$.

4. Verify Euclidean Identity: $10.8 = (2.5 \times 4) + 0.8 = 10.8$.

Common Mistakes and Floating-Point Precision Pitfalls

Assuming Negative Quotients Truncate

Programmers transitioning from C, Java, or C++ to Python often write algorithms assuming $-7 // 3$ will equal $-2$. In Python, it evaluates to $-3$. When migrating cross-language code, wrap with int(a / b) to match truncation.

IEEE 754 Floating-Point Imprecision

In floating-point math, $0.3 / 0.1$ can evaluate to $2.9999999999999996$ due to binary fraction rounding. Applying the floor function yields $2.0$ instead of the mathematically expected $3.0$. For exact arithmetic, use integer scaling or arbitrary-precision decimal libraries.

Fact-Checked & Verified • Computational Accuracy Standards
Updated September 2026 • Editorial Policy
Authored By
Sanjay Samanta

Lead Developer & Founder of Basic Math Tools. Specializes in browser-native computational algorithms and applied mathematics.

Reviewed & Verified By
Academic Review Board

Mathematics & curriculum specialists. Audited against standard algebraic and arithmetic principles.

Found an error or have an improvement suggestion? Report a calculation issue

Frequently Asked Questions

What is floor division?
Floor division is a mathematical operation between two numbers that computes their quotient and rounds it down to the nearest integer less than or equal to that quotient. Symbolically denoted as ⌊a / b⌋ or written as a // b in Python, it consistently rounds toward negative infinity.
How does floor division handle negative numbers?
Because floor division rounds toward negative infinity (downwards on the number line), dividing a negative dividend by a positive divisor rounds to the lower integer. For example, -7 / 3 = -2.333..., so floor division ⌊-7 / 3⌋ evaluates to -3 (not -2). The corresponding remainder is positive: r = -7 - (3)(-3) = 2.
What is the difference between floor division and truncated division?
Floor division rounds toward negative infinity (downward), whereas truncated division rounds toward zero (simply discarding the decimal fraction). For positive quotients, both produce identical results (e.g., 7 // 3 = 2). For negative quotients, they diverge: -7 // 3 is -3 in floor division, but -2 in truncated division (as implemented in C, C++, and Java).
Why does Python use floor division for the // operator?
Python creator Guido van Rossum designed the // operator and % modulo operator to satisfy the fundamental Euclidean identity a = (a // b) * b + (a % b) while ensuring that the modulo remainder is always non-negative and strictly periodic when the divisor b is positive. This mathematical consistency simplifies array indexing, time conversions, and calendar arithmetic.
Can you perform floor division with decimal floating-point numbers?
Yes. The floor function ⌊x⌋ is defined for all real numbers x. In Python, evaluating 10.8 // 2.5 calculates 10.8 / 2.5 = 4.32, which floors to 4.0. The mathematical principle remains identical regardless of whether inputs are integers or rational real numbers.