Home · Math · Ratios & Proportions · Modulo Operations with Negative Numbers

Modulo Operations with Negative Numbers

With the floored convention the remainder takes the sign of the divisor, so −7 mod 3 = 2 because −7 = 3 × (−3) + 2. This differs from truncated remainder in some programming languages.

Your figures

Example result — edit the figures to make it yours

2

Remainder of a mod b

Quotient (floor division)-3

What this calculator does

With the floored convention the remainder takes the sign of the divisor, so −7 mod 3 = 2 because −7 = 3 × (−3) + 2. This differs from truncated remainder in some programming languages. Every figure on this page is computed from the formula or definition stated below, with no hidden rounding steps, and the method notes name the exact convention where more than one exists.

The formula and method

a mod b = a − b × floor(a ÷ b)

With the floored convention the remainder takes the sign of the divisor, so −7 mod 3 = 2 because −7 = 3 × (−3) + 2. This differs from truncated remainder in some programming languages.

Inputs use the units shown in the field labels and every denominator or total must be non-zero. The result is an arithmetic value from the stated formula only; it is not a quote, a rating or professional advice.

Worked example

With the example inputs this page opens with (dividend (a, may be negative) -7, divisor (b) 3), the result is 2 — remainder of a mod b. Change any figure and the result updates with the same formula.

Quick reference

Quick reference — varying dividend (a, may be negative)
Dividend (a, may be negative)Remainder of a mod b
-3.53
-5.60
-72
-8.750
-10.52
-141

Computed with the same formulas as the calculator above — enter any values there for figures beyond this table.

Common questions

How does the Modulo Operations with Negative Numbers work?

With the floored convention the remainder takes the sign of the divisor, so −7 mod 3 = 2 because −7 = 3 × (−3) + 2. This differs from truncated remainder in some programming languages. Dividend · Divisor → Remainder of a mod b. The result updates as you type, and the formula and method on this page state the exact definitions used, so you can reproduce the calculation by hand.

What inputs does the Modulo Operations with Negative Numbers need?

Dividend · Divisor → Remainder of a mod b. Invalid entries — such as a zero denominator, an out-of-range value or a malformed list — produce a plain-language message instead of a misleading number.

Is the Modulo Operations with Negative Numbers free to use?

Yes. It runs entirely in your browser with no sign-up, and the same calculator is available as an embeddable widget via the Embed button, so it can be placed on another site with its calculation intact.