{
  "schemaVersion": 1,
  "slug": "cost-per-unit-calculator",
  "category": "finance",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "2bb2f6b390320c41b780b179748918510998f9ab0a0653594b2cb2c00ea42b6c",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/cost-per-unit-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": "CPU = TC ÷ Q",
    "vars": [
      [
        "TC",
        "Total cost"
      ],
      [
        "Q",
        "Number of units"
      ]
    ],
    "note": "Cost per unit = total cost ÷ positive quantity. A zero or invalid quantity is an input error."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "if(!Number.isFinite(Number(totalCost))||Number(totalCost)<0||!Number.isFinite(Number(quantity))||Number(quantity)<=0)return{costPerUnit:null,__error:'inputError'};return{costPerUnit:totalCost/quantity};",
    "inputs": [
      {
        "name": "totalCost",
        "type": "number",
        "default": 500,
        "min": 0,
        "max": 100000000,
        "step": 10
      },
      {
        "name": "quantity",
        "type": "number",
        "default": 40,
        "min": 0,
        "max": 100000000,
        "step": 1
      }
    ],
    "outputs": [
      {
        "name": "costPerUnit",
        "precision": 4,
        "unit": "$"
      }
    ],
    "interpret": null
  }
}
