{
  "schemaVersion": 1,
  "slug": "factorial-calculator",
  "category": "math",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "ede9a0d1ac356b2df0fb2053461fabf59fbc45c9cd74b36287e925d71f8f7a0f",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/factorial-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": "n! = Π_{i=1}^{k} i; D = floor(Σ_{i=1}^{k} log10 i) + 1; Z = Σ_{j: 5^j ≤ k} floor(k ÷ 5^j)",
    "vars": [
      [
        "k",
        "floor of n"
      ],
      [
        "n!",
        "factorial"
      ],
      [
        "D",
        "digit count"
      ],
      [
        "Z",
        "trailing zeros"
      ]
    ],
    "note": "Input must be an integer 0–170. 0! = 1. Floating-point factorial values can round above 18!; digit count uses log10 sums and trailing zeros use powers of five."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "if(!Number.isInteger(n)||n<0||n>170)return{factorial:null,digits:null,trailingZeros:null,__error:'inputError'};let r=1;for(let i=2;i<=n;i++)r*=i;let lg=0;for(let i=2;i<=n;i++)lg+=Math.log10(i);let z=0;for(let p=5;p<=n;p*=5)z+=Math.floor(n/p);return{factorial:r,digits:n<2?1:Math.floor(lg)+1,trailingZeros:z};",
    "inputs": [
      {
        "name": "n",
        "type": "number",
        "default": 10,
        "min": 0,
        "max": 170,
        "step": 1,
        "slider": true
      }
    ],
    "outputs": [
      {
        "name": "factorial",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "digits",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "trailingZeros",
        "precision": 0,
        "unit": ""
      }
    ],
    "interpret": null
  }
}
