{
  "id": "mod",
  "version": "de95bed6b84b",
  "status": "published",
  "name": "Modulo Calculator",
  "question": "What is A modulo B?",
  "summary": "Finds the remainder of one number divided by another (A mod B), with the whole-number quotient.",
  "category": "math",
  "subcategory": "arithmetic",
  "url": "https://www.acalculator.org/math/mod-calculator",
  "markdown": "https://www.acalculator.org/math/mod-calculator.md",
  "kind": "function",
  "method": "A mod B = A − B × ⌊A ÷ B⌋ (floored); truncated uses A ÷ B rounded toward 0 instead of ⌊A ÷ B⌋.",
  "assumptions": [
    "The divisor B cannot be 0.",
    "Floored (the default) gives a result with the sign of B, as in Python and in mathematics. Truncated gives the sign of A, as in C, Java and JavaScript. Both agree when neither number is negative.",
    "Decimals are taken exactly as typed: 5.5 mod 2 = 1.5 and 2.4 mod 0.2 = 0."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "dividend": {
        "title": "Dividend (A)",
        "description": "The number being divided: A in A mod B.",
        "type": "number"
      },
      "divisor": {
        "title": "Divisor (B)",
        "description": "The number to divide by: B in A mod B. It cannot be 0.",
        "type": "number"
      },
      "mode": {
        "title": "Remainder sign",
        "description": "Which sign the result takes when a number is negative: floored follows the divisor, truncated follows the dividend.",
        "type": "string",
        "enum": [
          "floored",
          "truncated"
        ]
      }
    }
  },
  "outputs": {
    "remainder": {
      "label": "A mod B",
      "description": "The remainder after dividing A by B a whole number of times.",
      "format": "number"
    },
    "whole": {
      "label": "Quotient",
      "description": "How many whole times B fits into A: ⌊A ÷ B⌋, or rounded toward 0 when truncated.",
      "format": "number"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "dividend": 17,
      "divisor": 5,
      "mode": "floored"
    },
    "outputs": {
      "remainder": 2,
      "whole": 3
    },
    "text": "17 mod 5 = 2."
  },
  "examples": [
    {
      "given": {
        "dividend": 17,
        "divisor": 5,
        "mode": "floored"
      },
      "expect": {
        "remainder": 2,
        "whole": 3
      },
      "source": "hand calculation in content.mdx: 17 − 5 × 3 = 2; Ted Sundstrom, Mathematical Reasoning: Writing and Proof, §3.5 The Division Algorithm and Congruence (for integers a and b with b > 0 there are unique q and r with a = bq + r and 0 ≤ r < b, −17 = 5(−4) + 3). https://math.libretexts.org/Bookshelves/Mathematical_Logic_and_Proof/Book:_Mathematical_Reasoning__Writing_and_Proof_(Sundstrom)/03:_Constructing_and_Writing_Proofs_in_Mathematics/3.05:_The_Division_Algorithm_and_Congruence"
    },
    {
      "given": {
        "dividend": -7,
        "divisor": 3,
        "mode": "floored"
      },
      "expect": {
        "remainder": 2,
        "whole": -3
      },
      "source": "hand calculation in content.mdx: ⌊−7 ÷ 3⌋ = −3, −7 − 3 × (−3) = 2; Python 3: -7 % 3 = 2; Ted Sundstrom, Mathematical Reasoning: Writing and Proof, §3.5 The Division Algorithm and Congruence (for integers a and b with b > 0 there are unique q and r with a = bq + r and 0 ≤ r < b, −17 = 5(−4) + 3). https://math.libretexts.org/Bookshelves/Mathematical_Logic_and_Proof/Book:_Mathematical_Reasoning__Writing_and_Proof_(Sundstrom)/03:_Constructing_and_Writing_Proofs_in_Mathematics/3.05:_The_Division_Algorithm_and_Congruence"
    },
    {
      "given": {
        "dividend": -7,
        "divisor": 3,
        "mode": "truncated"
      },
      "expect": {
        "remainder": -1,
        "whole": -2
      },
      "source": "hand calculation in content.mdx: −7 ÷ 3 toward 0 is −2, −7 − 3 × (−2) = −1; Ted Sundstrom, Mathematical Reasoning: Writing and Proof, §3.5 The Division Algorithm and Congruence (for integers a and b with b > 0 there are unique q and r with a = bq + r and 0 ≤ r < b, −17 = 5(−4) + 3). https://math.libretexts.org/Bookshelves/Mathematical_Logic_and_Proof/Book:_Mathematical_Reasoning__Writing_and_Proof_(Sundstrom)/03:_Constructing_and_Writing_Proofs_in_Mathematics/3.05:_The_Division_Algorithm_and_Congruence"
    },
    {
      "given": {
        "dividend": 7,
        "divisor": -3,
        "mode": "floored"
      },
      "expect": {
        "remainder": -2,
        "whole": -3
      },
      "source": "hand calculation in content.mdx: ⌊7 ÷ −3⌋ = −3, 7 − (−3) × (−3) = −2; Python 3: 7 % -3 = -2; Ted Sundstrom, Mathematical Reasoning: Writing and Proof, §3.5 The Division Algorithm and Congruence (for integers a and b with b > 0 there are unique q and r with a = bq + r and 0 ≤ r < b, −17 = 5(−4) + 3). https://math.libretexts.org/Bookshelves/Mathematical_Logic_and_Proof/Book:_Mathematical_Reasoning__Writing_and_Proof_(Sundstrom)/03:_Constructing_and_Writing_Proofs_in_Mathematics/3.05:_The_Division_Algorithm_and_Congruence"
    },
    {
      "given": {
        "dividend": 5.5,
        "divisor": 2,
        "mode": "floored"
      },
      "expect": {
        "remainder": 1.5,
        "whole": 2
      },
      "source": "hand calculation in content.mdx: 5.5 − 2 × 2 = 1.5; Ted Sundstrom, Mathematical Reasoning: Writing and Proof, §3.5 The Division Algorithm and Congruence (for integers a and b with b > 0 there are unique q and r with a = bq + r and 0 ≤ r < b, −17 = 5(−4) + 3). https://math.libretexts.org/Bookshelves/Mathematical_Logic_and_Proof/Book:_Mathematical_Reasoning__Writing_and_Proof_(Sundstrom)/03:_Constructing_and_Writing_Proofs_in_Mathematics/3.05:_The_Division_Algorithm_and_Congruence"
    },
    {
      "given": {
        "dividend": 2.4,
        "divisor": 0.2,
        "mode": "floored"
      },
      "expect": {
        "remainder": 0,
        "whole": 12
      },
      "source": "hand calculation in content.mdx: 0.2 × 12 = 2.4 exactly (×10: 24 mod 2 = 0); Ted Sundstrom, Mathematical Reasoning: Writing and Proof, §3.5 The Division Algorithm and Congruence (for integers a and b with b > 0 there are unique q and r with a = bq + r and 0 ≤ r < b, −17 = 5(−4) + 3). https://math.libretexts.org/Bookshelves/Mathematical_Logic_and_Proof/Book:_Mathematical_Reasoning__Writing_and_Proof_(Sundstrom)/03:_Constructing_and_Writing_Proofs_in_Mathematics/3.05:_The_Division_Algorithm_and_Congruence"
    },
    {
      "given": {
        "dividend": 1000000000000000,
        "divisor": 7,
        "mode": "floored"
      },
      "expect": {
        "remainder": 6,
        "whole": 142857142857142
      },
      "source": "hand calculation in content.mdx: 7 × 142,857,142,857,142 = 999,999,999,999,994; Python 3: 10**15 % 7 = 6; Ted Sundstrom, Mathematical Reasoning: Writing and Proof, §3.5 The Division Algorithm and Congruence (for integers a and b with b > 0 there are unique q and r with a = bq + r and 0 ≤ r < b, −17 = 5(−4) + 3). https://math.libretexts.org/Bookshelves/Mathematical_Logic_and_Proof/Book:_Mathematical_Reasoning__Writing_and_Proof_(Sundstrom)/03:_Constructing_and_Writing_Proofs_in_Mathematics/3.05:_The_Division_Algorithm_and_Congruence"
    }
  ],
  "sources": [
    "Ted Sundstrom, Mathematical Reasoning: Writing and Proof, §3.5 The Division Algorithm and Congruence (for integers a and b with b > 0 there are unique q and r with a = bq + r and 0 ≤ r < b; −17 = 5(−4) + 3). https://math.libretexts.org/Bookshelves/Mathematical_Logic_and_Proof/Book:_Mathematical_Reasoning__Writing_and_Proof_(Sundstrom)/03:_Constructing_and_Writing_Proofs_in_Mathematics/3.05:_The_Division_Algorithm_and_Congruence"
  ],
  "related": [],
  "changelog": [
    {
      "date": "2026-09-29",
      "note": "Worked examples name a published reference for their rule."
    }
  ]
}
