{
  "schemaVersion": 1,
  "slug": "average-calculator",
  "category": "math",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "b7d4d87508ccd67236310292976a77226bd7da21bdb712b577b42e532c08b137",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/average-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": "x̄ = Σ xᵢ ÷ n",
    "vars": [
      [
        "xᵢ",
        "Each input value"
      ],
      [
        "n",
        "Number of values"
      ],
      [
        "x̄",
        "Arithmetic mean"
      ]
    ],
    "note": "Each value has equal weight. Separate values with commas or spaces; use semicolons with decimal commas, without thousands separators. Floating-point calculations have limited precision; displayed decimals are rounded. Invalid entries or a non-finite total produce an error."
  },
  "externalEvidence": {
    "reviewedAt": "2026-10-22",
    "sources": [
      {
        "name": "NIST — Measures of Location",
        "url": "https://www.itl.nist.gov/div898/handbook/eda/section3/eda351.htm"
      }
    ],
    "implementationHash": "b7d4d87508ccd67236310292976a77226bd7da21bdb712b577b42e532c08b137",
    "basis": "Arithmetic mean is sum(values) / count(values). Compensated summation reduces cancellation error but retains floating-point limits. Commas or whitespace separate decimal-point values; semicolons select decimal-comma parsing. Every token must be finite. Empty text is preserved and rejected.",
    "limitations": "Not arbitrary-precision arithmetic. Displayed decimals are rounded. Empty lists, invalid tokens and non-finite running or corrected sums produce errors; values are not silently discarded."
  },
  "contract": {
    "compute": "const raw=String(values).trim(); const decimalComma=raw.includes(';'); const parts=raw.split(decimalComma ? /[;\\s]+/ : /[,\\s]+/).filter(v=>v.length); if(!parts.length) return { average:null, sum:null, count:null, minimum:null, maximum:null, __error:'average' }; const normalized=parts.map(v=>decimalComma ? v.replace(',', '.') : v); const numericPattern=/^[+-]?(?:(?:\\d+(?:\\.\\d*)?)|(?:\\.\\d+))(?:[eE][+-]?\\d+)?$/; if(normalized.some(v=>!numericPattern.test(v) || !Number.isFinite(Number(v)))) return { average:null, sum:null, count:null, minimum:null, maximum:null, __error:'inputError' }; const xs=normalized.map(Number); let sum=0,correction=0,minimum=Infinity,maximum=-Infinity; for(const x of xs){const next=sum+x;if(!Number.isFinite(next)) return { average:null,sum:null,count:null,minimum:null,maximum:null,__error:'unavailable' };correction+=Math.abs(sum)>=Math.abs(x)?(sum-next)+x:(x-next)+sum;sum=next;if(x<minimum)minimum=x;if(x>maximum)maximum=x;} sum+=correction; if(!Number.isFinite(sum)) return { average:null,sum:null,count:null,minimum:null,maximum:null,__error:'unavailable' }; return { average:sum/xs.length, sum, count:xs.length, minimum, maximum };",
    "inputs": [
      {
        "name": "values",
        "type": "text",
        "default": "10, 20, 30, 40, 50",
        "step": 1,
        "preserveEmpty": true
      }
    ],
    "outputs": [
      {
        "name": "average",
        "precision": 4,
        "unit": "",
        "trimTrailingZeros": true
      },
      {
        "name": "sum",
        "precision": 4,
        "unit": "",
        "trimTrailingZeros": true
      },
      {
        "name": "count",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "minimum",
        "precision": 4,
        "unit": "",
        "trimTrailingZeros": true
      },
      {
        "name": "maximum",
        "precision": 4,
        "unit": "",
        "trimTrailingZeros": true
      }
    ],
    "interpret": null
  }
}
