Report

Help us improve this tool

Floor Division Calculator

Calculate floor division (a // b = ⌊a/b⌋), remainder modulo, and compare standard vs truncated division with step-by-step breakdown.

O M T

What Is Floor Division?

Floor division (commonly denoted as \(a // b\) in Python or \(\lfloor a/b \rfloor\) in mathematics) is a mathematical division operation that divides two numbers and rounds the quotient down to the nearest integer less than or equal to the real quotient.

The mathematical floor function \(\lfloor x \rfloor\) is defined as:

$$\lfloor x \rfloor = \max \{ m \in \mathbb{Z} \mid m \leq x \}$$

For positive numbers, floor division discards the decimal fraction (e.g., \(\lfloor 9 / 2 \rfloor = \lfloor 4.5 \rfloor = 4\)). However, for negative numbers, floor division rounds down away from zero towards negative infinity (e.g., \(\lfloor -7 / 5 \rfloor = \lfloor -1.4 \rfloor = -2\)).

Floor Division vs. Truncated Integer Division

Different programming languages implement integer division in distinct ways:

  • Floor Division (Python, Ruby): Rounds towards \(-\infty\). The remainder always has the same sign as the divisor \(b\).
  • Truncated Division (C, C++, Java, JavaScript Math.trunc): Rounds towards zero (chops off decimal places). The remainder always has the same sign as the dividend \(a\).
  • Ceiling Division: Rounds towards \(+\infty\), defined as \(\lceil a/b \rceil\).

Comparison Table: Positive and Negative Operands

Operation Real Division Floor Division (\(//\)) Truncated Division
35 / 4 8.75 8 8
-7 / 5 -1.4 -2 -1
7 / -5 -1.4 -2 -1
-15 / -4 3.75 3 3

Division Algorithm Identity

In Euclidean arithmetic, any dividend \(a\) and non-zero divisor \(b\) satisfy the fundamental division theorem:

$$a = b \cdot q + r \quad \text{where} \quad q = \lfloor a/b \rfloor \quad \text{and} \quad 0 \leq r < |b|$$

For \(-7 // 5\), we have \(q = -2\) and remainder \(r = -7 - 5(-2) = -7 + 10 = 3\). The identity confirms:

$$-7 = 5 \cdot (-2) + 3$$

Related Mathematics Calculators

Explore other useful integer arithmetic and modular tools:

Frequently Asked Questions

What is the difference between regular division and floor division?

Regular division produces exact fractional or decimal results (for example, \(35 / 4 = 8.75\)), whereas floor division always rounds the result down to the largest integer less than or equal to the quotient (\(\lfloor 35 / 4 \rfloor = 8\)).

Why is -7 // 5 equal to -2 instead of -1?

Standard division of \(-7\) by \(5\) gives \(-1.4\). The largest integer less than or equal to \(-1.4\) is \(-2\) (because \(-2 < -1.4 < -1\)). Truncating towards zero gives \(-1\), but floor division rounds towards \(-\infty\), yielding \(-2\).

What symbol is used for floor division in programming?

In Python, the double forward slash (//) represents floor division. In mathematical notation, floor brackets \(\lfloor x \rfloor\) represent the floor function.

When do floor division and standard division produce identical results?

Floor division and standard division produce the same result if and only if the divisor \(b\) evenly divides the dividend \(a\) without any remainder (\(a \pmod b = 0\)).

Can floor division be applied to floating-point numbers?

Yes. For example, in Python, 7.5 // 2.1 computes \(\lfloor 7.5 / 2.1 \rfloor = \lfloor 3.5714... \rfloor = 3.0\).