{
  "schemaVersion": 1,
  "slug": "long-division-calculator",
  "category": "math",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "b9611a0f601ca9103f7e51a8654fb11afb4f6e6236689332361e37e0384643cd",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/long-division-calculator.json",
    "src/engine.js"
  ],
  "runtimeSource": "/sources/engine.txt",
  "runtimeHash": "5c888d8898afbdee36267bb9977829e1e2ac568f6677c8ee87469c139864645c",
  "scope": "The compute function records implemented equations, constants, lookup tables and custom rules. Inputs record defaults and allowed values; outputs record precision and units. Defaults are examples, not recommendations. General background references are not evidence for this specific algorithm.",
  "publishedFormula": {
    "formula": "q = floor(n ÷ d); r = n − q × d; cur₀ = 0; cᵢ = curᵢ₋₁ × 10 + δᵢ; qdᵢ = floor(cᵢ ÷ d); curᵢ = cᵢ − qdᵢ × d",
    "vars": [
      [
        "n",
        "dividend (non-negative)"
      ],
      [
        "d",
        "divisor (≥ 1)"
      ],
      [
        "q",
        "quotient"
      ],
      [
        "r",
        "remainder"
      ],
      [
        "cur",
        "carried remainder after each step"
      ],
      [
        "qd",
        "quotient digit at each step"
      ],
      [
        "c",
        "working value after bringing down digit δ"
      ],
      [
        "δ",
        "digit of n processed at step i"
      ]
    ],
    "note": "Dividend is a nonnegative integer; divisor is a positive integer. Decimal output rounds to 0–12 places. Working lists the first six digit steps; remainder and check use the full input."
  },
  "externalEvidence": {
    "reviewedAt": "2026-10-12",
    "sources": [
      {
        "name": "OpenStax — Arithmetic operations",
        "url": "https://openstax.org/books/prealgebra-2e/pages/1-5-divide-whole-numbers"
      }
    ],
    "referenceRole": "definition",
    "implementationHash": "b9611a0f601ca9103f7e51a8654fb11afb4f6e6236689332361e37e0384643cd",
    "basis": "q = floor(n ÷ d); r = n − q × d; cur₀ = 0; cᵢ = curᵢ₋₁ × 10 + δᵢ; qdᵢ = floor(cᵢ ÷ d); curᵢ = cᵢ − qdᵢ × d",
    "limitations": "The references explain definitions and methods; any extra preset must be checked against the assumptions on this page."
  },
  "contract": {
    "compute": "if(!Number.isInteger(dividend)||dividend<0||!Number.isInteger(divisor)||divisor<1||!Number.isInteger(decimalPlaces)||decimalPlaces<0||decimalPlaces>12)return{quotient:null,remainder:null,decimalResult:null,steps:null,checkMultiplication:null,__error:'inputError'};const n=dividend,d=divisor,places=decimalPlaces,q=Math.floor(n/d),r=n%d,digits=String(n).split('').map(Number);let cur=0;const steps=[];for(let k=0;k<digits.length;k++){cur=cur*10+digits[k];const qd=Math.floor(cur/d),rem=cur-qd*d;if(steps.length<6)steps.push(cur+' ÷ '+d+' = '+qd+'; '+cur+' − '+qd+'×'+d+' = '+rem);cur=rem;}const scale=10n**BigInt(places),den=BigInt(d),rounded=(2n*BigInt(n)*scale+den)/(2n*den),raw=String(rounded).padStart(places+1,'0'),decimalResult=places?raw.slice(0,-places)+'.'+raw.slice(-places):raw;return{quotient:q,remainder:r,decimalResult,steps:steps.join(' | ')+(digits.length>6?' | …':''),checkMultiplication:q*d+r};",
    "inputs": [
      {
        "name": "dividend",
        "type": "number",
        "default": 12345,
        "min": 0,
        "max": 1000000000000,
        "step": 1
      },
      {
        "name": "divisor",
        "type": "number",
        "default": 12,
        "min": 1,
        "max": 1000000,
        "step": 1
      },
      {
        "name": "decimalPlaces",
        "type": "number",
        "default": 4,
        "min": 0,
        "max": 12,
        "step": 1,
        "slider": true
      }
    ],
    "outputs": [
      {
        "name": "quotient",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "remainder",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "decimalResult",
        "precision": 12,
        "type": "decimal",
        "unit": ""
      },
      {
        "name": "steps",
        "precision": 0,
        "unit": "",
        "type": "text"
      },
      {
        "name": "checkMultiplication",
        "precision": 0,
        "unit": ""
      }
    ],
    "interpret": null
  }
}
