{
  "schemaVersion": 1,
  "slug": "gas-mileage-calculator",
  "category": "automotive",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "f88070fc94d17811536e7f0b7caab9d8ad1911b3ed79f044b59f5f68ea948020",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/gas-mileage-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": "mpg = d/gal; L100 = gal x 3.785411784 / (d x 1.609344) x 100; km/L = d x 1.609344 / (gal x 3.785411784); mpgUK = d/(gal/1.20095)",
    "vars": [
      [
        "d",
        "distance (miles)"
      ],
      [
        "gal",
        "fuel used (US gallons)"
      ],
      [
        "mpg",
        "US miles per gallon"
      ],
      [
        "mpgUK",
        "imperial mpg"
      ],
      [
        "L100",
        "litres per 100 km"
      ],
      [
        "km/L",
        "kilometres per litre"
      ]
    ],
    "note": "Fuel is normalized to US gallons. mpg (US) = miles ÷ US gallons; L/100 km and km/L use 3.785411784 L/US gal and 1.609344 km/mile. Imperial gallons are 1.20095 US gallons. These are unit conversions, not a vehicle-efficiency rating."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const galUS = unit === 'usgal' ? fuelUsed : unit === 'impgal' ? fuelUsed*1.20095 : fuelUsed*0.264172; const mpg = galUS > 0 ? distance/galUS : 0; const km = distance*1.609344; const litres = galUS*3.785411784; return { mpg, mpgImperial: galUS > 0 ? distance/(galUS/1.20095) : 0, lPer100km: litres > 0 && km > 0 ? litres/km*100 : 0, kmPerLitre: litres > 0 ? km/litres : 0 };",
    "inputs": [
      {
        "name": "distance",
        "type": "number",
        "default": 320,
        "min": 0,
        "max": 20000,
        "step": 1
      },
      {
        "name": "fuelUsed",
        "type": "number",
        "default": 10,
        "min": 0.1,
        "max": 2000,
        "step": 0.1
      },
      {
        "name": "unit",
        "type": "select",
        "default": "usgal",
        "options": [
          {
            "value": "usgal"
          },
          {
            "value": "impgal"
          },
          {
            "value": "litres"
          }
        ]
      }
    ],
    "outputs": [
      {
        "name": "mpg",
        "precision": 2,
        "unit": "mpg"
      },
      {
        "name": "mpgImperial",
        "precision": 2,
        "unit": "mpg"
      },
      {
        "name": "lPer100km",
        "precision": 2,
        "unit": "L/100km"
      },
      {
        "name": "kmPerLitre",
        "precision": 2,
        "unit": "km/L"
      }
    ],
    "interpret": null
  }
}
