{
  "schemaVersion": 1,
  "slug": "big-numbers-calculator",
  "category": "everyday",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "e265af7839af5fc85aa12d982b106070719ad8938a2ede457431b2870521875c",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/big-numbers-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": "r = a + b | a − b | a × b; r ≈ a ÷ b (n d.p.)",
    "vars": [
      [
        "a",
        "First large integer"
      ],
      [
        "b",
        "Second large integer"
      ],
      [
        "n",
        "Decimal places for division"
      ],
      [
        "r",
        "Result"
      ]
    ],
    "note": "Signed whole-number inputs only, up to 1000 digits each. BigInt addition, subtraction and multiplication are exact. Division uses integer quotient/remainder arithmetic and rounds halfway values away from zero to 0–20 decimal places; it does not convert the operands to floating-point numbers. Decimal inputs are rejected rather than truncated."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const A=String(numberA==null?'':numberA).trim(),B=String(numberB==null?'':numberB).trim(); if(!['add','subtract','multiply','compare','divide'].includes(operation)||(operation==='divide'&&(!Number.isInteger(scale)||scale<0||scale>20))||!/^-?\\d+$/.test(A)||!/^-?\\d+$/.test(B)||A.replace(/^-/, '').length>1000||B.replace(/^-/, '').length>1000)return{result:null,digits:null,named:null,comparison:null,note:null,__error:'inputError'}; const a=BigInt(A),b=BigInt(B); const cmp=a>b?'A is larger':a<b?'B is larger':'The two are equal'; let res; if(operation==='add')res=(a+b).toString(); else if(operation==='subtract')res=(a-b).toString(); else if(operation==='multiply')res=(a*b).toString(); else if(operation==='compare')res=cmp; else if(b===0n)return{result:null,digits:null,named:null,comparison:cmp,note:null,__error:'inputError'}; else {const places=Math.max(0,Math.min(20,Math.round(Number(scale)||0))),neg=(a<0n)!==(b<0n),aa=a<0n?-a:a,bb=b<0n?-b:b,f=10n**BigInt(places);let q=aa*f/bb,rem=aa*f%bb;if(rem*2n>=bb)q++;let s=q.toString();if(places){s=s.padStart(places+1,'0');s=s.slice(0,-places)+'.'+s.slice(-places);s=s.replace(/\\.?0+$/,'');}res=(neg&&q!==0n?'-':'')+s;} const digits=operation==='compare'?null:(res.match(/\\d/g)||[]).length; const abs=a<0n?-a:a,text=abs.toString(),names=['thousand','million','billion','trillion','quadrillion','quintillion','sextillion','septillion'];let named='Less than a thousand';if(text.length>=4){const group=Math.floor((text.length-1)/3),whole=text.length-group*3,lead=text.slice(0,whole),frac=text.slice(whole,whole+2).padEnd(2,'0');named=group<=8?lead+'.'+frac+' '+names[group-1]:text[0]+'.'+text.slice(1,3).padEnd(2,'0')+' × 10^'+(text.length-1);}return{result:res,digits,named,comparison:cmp,note:'Integer operations are exact. Division is rounded to the selected decimal places; each input accepts up to 1,000 digits and an optional minus sign.'};",
    "inputs": [
      {
        "name": "numberA",
        "type": "text",
        "default": "123456789012345678901234567890",
        "step": 1,
        "requiredValue": true,
        "preserveEmpty": true
      },
      {
        "name": "numberB",
        "type": "text",
        "default": "987654321098765432109876543210",
        "step": 1,
        "requiredValue": true,
        "preserveEmpty": true
      },
      {
        "name": "operation",
        "type": "select",
        "default": "add",
        "options": [
          {
            "value": "add"
          },
          {
            "value": "subtract"
          },
          {
            "value": "multiply"
          },
          {
            "value": "compare"
          },
          {
            "value": "divide"
          }
        ]
      },
      {
        "name": "scale",
        "type": "number",
        "default": 0,
        "min": 0,
        "max": 20,
        "step": 1,
        "slider": true,
        "requiredValue": true,
        "strictRange": true,
        "showWhen": {
          "operation": [
            "divide"
          ]
        }
      }
    ],
    "outputs": [
      {
        "name": "result",
        "precision": 0,
        "unit": "",
        "type": "text",
        "display": "code"
      },
      {
        "name": "digits",
        "precision": 0,
        "unit": "digits",
        "optional": true
      },
      {
        "name": "named",
        "precision": 0,
        "unit": "",
        "type": "text"
      },
      {
        "name": "comparison",
        "precision": 0,
        "unit": "",
        "type": "text"
      },
      {
        "name": "note",
        "precision": 0,
        "unit": "",
        "type": "text"
      }
    ],
    "interpret": null
  }
}
