{
  "schemaVersion": 1,
  "slug": "ratio-calculator",
  "category": "math",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "f2ad7ba22ebb18a6225e499188f40a932c019aeebeafd2632f4f84a970226298",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/ratio-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 = a×s÷b; r = a÷b; p = 100×a÷(a+b)",
    "vars": [
      [
        "a",
        "First term"
      ],
      [
        "b",
        "Second term"
      ],
      [
        "s",
        "Scale factor"
      ],
      [
        "x",
        "Scaled value of a"
      ],
      [
        "r",
        "Decimal ratio"
      ],
      [
        "p",
        "Percentage of total"
      ]
    ],
    "note": "A zero denominator or zero total is undefined and produces an input error."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "if (b === 0 || a + b === 0)return{scaledFirst:null,decimalRatio:null,percentage:null,__error:'inputError'};  const reciprocal=Math.sign(b)/Math.abs(b); return {scaledFirst:a*scale*reciprocal,decimalRatio:a*reciprocal,percentage:100*a/(a+b)};",
    "inputs": [
      {
        "name": "a",
        "type": "number",
        "default": 24,
        "min": -1000000000,
        "max": 1000000000,
        "step": 0.01
      },
      {
        "name": "b",
        "type": "number",
        "default": 36,
        "min": -1000000000,
        "max": 1000000000,
        "step": 0.01
      },
      {
        "name": "scale",
        "type": "number",
        "default": 3,
        "min": -1000000000,
        "max": 1000000000,
        "step": 0.01
      }
    ],
    "outputs": [
      {
        "name": "scaledFirst",
        "precision": 4,
        "unit": ""
      },
      {
        "name": "decimalRatio",
        "precision": 6,
        "unit": ""
      },
      {
        "name": "percentage",
        "precision": 2,
        "unit": "%"
      }
    ],
    "interpret": null
  }
}
