{
  "id": "integer",
  "version": "54b062a3c4e3",
  "status": "published",
  "name": "Integer Calculator",
  "question": "How do I add or multiply integers?",
  "summary": "Adds, subtracts, multiplies or divides positive and negative integers of any size, exactly, and explains the sign rule for each step.",
  "category": "math",
  "subcategory": "arithmetic",
  "url": "https://www.acalculator.org/math/integer-calculator",
  "markdown": "https://www.acalculator.org/math/integer-calculator.md",
  "kind": "function",
  "method": "Addition: same signs, add the absolute values and keep the sign; different signs, subtract the smaller absolute value from the larger and take the sign of the larger. Subtraction: a − b = a + (−b). Multiplication and division: same signs give a positive answer, different signs a negative one.",
  "assumptions": [
    "Integers can have any number of digits; the arithmetic is exact.",
    "A quotient that is not a whole number is shown as a fraction in lowest terms and as a decimal to 10 significant figures. Dividing by 0 has no answer."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "a": {
        "title": "First integer",
        "description": "A whole number, positive, negative or 0.",
        "type": "string",
        "pattern": "^-?\\d+$"
      },
      "op": {
        "title": "Operation",
        "description": "Add, subtract, multiply or divide.",
        "type": "string",
        "enum": [
          "add",
          "sub",
          "mul",
          "div"
        ]
      },
      "b": {
        "title": "Second integer",
        "description": "A whole number, positive, negative or 0.",
        "type": "string",
        "pattern": "^-?\\d+$"
      }
    }
  },
  "outputs": {
    "result": {
      "label": "Result",
      "description": "The exact answer; a quotient that is not whole is a fraction in lowest terms.",
      "format": "text"
    },
    "expression": {
      "label": "Problem",
      "description": "The problem and its answer.",
      "format": "text"
    },
    "rule": {
      "label": "Sign rule",
      "description": "The rule for the sign of the answer.",
      "format": "text"
    },
    "decimal": {
      "label": "Decimal",
      "description": "A quotient as a decimal to 10 significant figures.",
      "format": "text"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "a": -8,
      "op": "add",
      "b": 5
    },
    "outputs": {
      "result": "−3",
      "expression": "−8 + 5 = −3",
      "rule": "different signs: subtract 8 − 5 = 3 and take the sign of −8: −3"
    },
    "text": "−8 + 5 = −3."
  },
  "examples": [
    {
      "given": {
        "a": -8,
        "op": "add",
        "b": 5
      },
      "expect": {
        "result": "−3",
        "expression": "−8 + 5 = −3",
        "rule": "different signs: subtract 8 − 5 = 3 and take the sign of −8: −3"
      },
      "source": "OpenStax, Prealgebra 2e, §3.2 Add Integers (same signs: add and keep the sign; different signs: subtract, take the sign of the larger absolute value), https://openstax.org/books/prealgebra-2e/pages/3-2-add-integers (retrieved 2026-10-05); hand calculation in content.mdx"
    },
    {
      "given": {
        "a": -7,
        "op": "add",
        "b": -4
      },
      "expect": {
        "result": "−11",
        "rule": "same signs: add 7 + 4 = 11 and keep the sign: −11"
      },
      "source": "OpenStax, Prealgebra 2e, §3.2 Add Integers (same signs: add and keep the sign; different signs: subtract, take the sign of the larger absolute value), https://openstax.org/books/prealgebra-2e/pages/3-2-add-integers (retrieved 2026-10-05); hand calculation in content.mdx"
    },
    {
      "given": {
        "a": 3,
        "op": "sub",
        "b": -6
      },
      "expect": {
        "result": "9",
        "expression": "3 − (−6) = 9"
      },
      "source": "OpenStax, Prealgebra 2e, §3.3 Subtract Integers (a − b = a + (−b)), https://openstax.org/books/prealgebra-2e/pages/3-3-subtract-integers (retrieved 2026-10-05); hand calculation in content.mdx: 3 + 6 = 9"
    },
    {
      "given": {
        "a": -9,
        "op": "mul",
        "b": -4
      },
      "expect": {
        "result": "36",
        "rule": "same signs, so the answer is positive: 9 × 4 = 36, so 36"
      },
      "source": "OpenStax, Prealgebra 2e, §3.4 Multiply and Divide Integers (same signs give a positive, different signs a negative), https://openstax.org/books/prealgebra-2e/pages/3-4-multiply-and-divide-integers (retrieved 2026-10-05); hand calculation in content.mdx"
    },
    {
      "given": {
        "a": -63,
        "op": "div",
        "b": 7
      },
      "expect": {
        "result": "−9",
        "decimal": "−9"
      },
      "source": "OpenStax, Prealgebra 2e, §3.4 Multiply and Divide Integers (same signs give a positive, different signs a negative), https://openstax.org/books/prealgebra-2e/pages/3-4-multiply-and-divide-integers (retrieved 2026-10-05); hand calculation in content.mdx: 63 ÷ 7 = 9, different signs"
    },
    {
      "given": {
        "a": 10,
        "op": "div",
        "b": -4
      },
      "expect": {
        "result": "−5/2",
        "decimal": "−2.5"
      },
      "source": "OpenStax, Prealgebra 2e, §3.4 Multiply and Divide Integers (same signs give a positive, different signs a negative), https://openstax.org/books/prealgebra-2e/pages/3-4-multiply-and-divide-integers (retrieved 2026-10-05); hand calculation in content.mdx: 10 ÷ 4 = 5/2, different signs"
    },
    {
      "given": {
        "a": "123456789012345678901234567890",
        "op": "mul",
        "b": -2
      },
      "expect": {
        "result": "−246913578024691357802469135780"
      },
      "source": "OpenStax, Prealgebra 2e, §3.4 Multiply and Divide Integers (same signs give a positive, different signs a negative), https://openstax.org/books/prealgebra-2e/pages/3-4-multiply-and-divide-integers (retrieved 2026-10-05); Python 3: 123456789012345678901234567890 * -2"
    }
  ],
  "sources": [
    "OpenStax, Prealgebra 2e, §3.2 Add Integers: same signs, add and keep the sign; different signs, subtract and use the sign of the larger absolute value. CC BY 4.0. Retrieved 2026-10-05. https://openstax.org/books/prealgebra-2e/pages/3-2-add-integers",
    "OpenStax, Prealgebra 2e, §3.3 Subtract Integers: a − b = a + (−b). CC BY 4.0. Retrieved 2026-10-05. https://openstax.org/books/prealgebra-2e/pages/3-3-subtract-integers",
    "OpenStax, Prealgebra 2e, §3.4 Multiply and Divide Integers: same signs give a positive, different signs a negative. CC BY 4.0. Retrieved 2026-10-05. https://openstax.org/books/prealgebra-2e/pages/3-4-multiply-and-divide-integers"
  ],
  "related": [
    "absolute-value",
    "least-to-greatest",
    "greater-than-less-than",
    "division",
    "multiplication"
  ],
  "changelog": []
}
