{
  "schemaVersion": 1,
  "slug": "density-calculator",
  "category": "conversion",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "7e2db3b260645a81edbade43ee101a79b15fab3bfe95f3f745dad62819e7fdc3",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/density-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": "ρ = m ÷ V",
    "vars": [
      [
        "m",
        "Mass in kg"
      ],
      [
        "V",
        "Volume in m³"
      ],
      [
        "ρ",
        "Density (kg/m³)"
      ]
    ],
    "note": "Mass is converted to kg and volume to m³. Litres per kilogram = 1,000 ÷ density in kg/m³."
  },
  "externalEvidence": {
    "reviewedAt": "2026-10-04",
    "sources": [
      {
        "name": "NIST SP 811 — Conversion factors by quantity",
        "url": "https://www.nist.gov/pml/special-publication-811/nist-guide-si-appendix-b-conversion-factors/nist-guide-si-appendix-b9"
      }
    ],
    "basis": "Convert mass density via kilograms per cubic metre.",
    "limitations": "Only the displayed unit definitions are converted; rounding and measurement uncertainty are separate.",
    "implementationHash": "7e2db3b260645a81edbade43ee101a79b15fab3bfe95f3f745dad62819e7fdc3",
    "domain": "conversion"
  },
  "contract": {
    "compute": "if((!Number.isFinite(mass)||mass<0.000001||mass>1000000000000)||(!Number.isFinite(volume)||volume<0||volume>1000000000000)||![\"kg\",\"g\",\"lb\"].includes(massUnit)||![\"l\",\"ml\",\"m3\",\"gal\"].includes(volumeUnit))return {\"result\":null,\"kgm3\":null,\"gcm3\":null,\"lbft3\":null,\"litresPerKg\":null,\"__error\":\"inputError\"};if(![\"kgm3\",\"gcm3\",\"lbft3\"].includes(resultUnit))return {\"result\":null,\"kgm3\":null,\"gcm3\":null,\"lbft3\":null,\"litresPerKg\":null,\"__error\":\"inputError\"};const out=(function(mass,massUnit,volume,volumeUnit){const M={kg:1,g:0.001,lb:0.45359237},V={l:0.001,ml:1e-6,m3:1,gal:0.003785411784},kg=mass*M[massUnit],m3=volume*V[volumeUnit];if(!(m3>0)||!(kg>0)||!Number.isFinite(m3)||!Number.isFinite(kg))return {kgm3:null,gcm3:null,lbft3:null,litresPerKg:null,__error:'inputError'};const d=kg/m3;return {kgm3:d,gcm3:d/1000,lbft3:d*0.062427960576145,litresPerKg:d>0?1000/d:null};})(mass,massUnit,volume,volumeUnit);if(out.__error)return {...{\"result\":null,\"kgm3\":null,\"gcm3\":null,\"lbft3\":null,\"litresPerKg\":null},...out};out.result=out[resultUnit];out.__resultUnit={\"kg\":\"kg\",\"g\":\"g\",\"lb\":\"lb\",\"l\":\"L\",\"ml\":\"mL\",\"m3\":\"m³\",\"gal\":\"US gal\",\"kgm3\":\"kg/m³\",\"gcm3\":\"g/cm³\",\"lbft3\":\"lb/ft³\"}[resultUnit];return out;",
    "inputs": [
      {
        "name": "mass",
        "type": "number",
        "default": 10,
        "min": 0.000001,
        "max": 1000000000000,
        "step": 0.01,
        "requiredValue": true,
        "strictRange": true,
        "unitField": "massUnit",
        "unitLabels": {
          "kg": "kg",
          "g": "g",
          "lb": "lb",
          "l": "L",
          "ml": "mL",
          "m3": "m³",
          "gal": "US gal",
          "kgm3": "kg/m³",
          "gcm3": "g/cm³",
          "lbft3": "lb/ft³"
        }
      },
      {
        "name": "massUnit",
        "type": "select",
        "default": "kg",
        "options": [
          {
            "value": "kg"
          },
          {
            "value": "g"
          },
          {
            "value": "lb"
          }
        ]
      },
      {
        "name": "volume",
        "type": "number",
        "default": 10,
        "min": 0,
        "max": 1000000000000,
        "step": 0.01,
        "requiredValue": true,
        "strictRange": true,
        "unitField": "volumeUnit",
        "unitLabels": {
          "kg": "kg",
          "g": "g",
          "lb": "lb",
          "l": "L",
          "ml": "mL",
          "m3": "m³",
          "gal": "US gal",
          "kgm3": "kg/m³",
          "gcm3": "g/cm³",
          "lbft3": "lb/ft³"
        }
      },
      {
        "name": "volumeUnit",
        "type": "select",
        "default": "l",
        "options": [
          {
            "value": "l"
          },
          {
            "value": "ml"
          },
          {
            "value": "m3"
          },
          {
            "value": "gal"
          }
        ]
      },
      {
        "name": "resultUnit",
        "type": "select",
        "default": "kgm3",
        "options": [
          {
            "value": "kgm3"
          },
          {
            "value": "gcm3"
          },
          {
            "value": "lbft3"
          }
        ]
      }
    ],
    "outputs": [
      {
        "name": "result",
        "precision": 4,
        "trimTrailingZeros": true,
        "unitField": "__resultUnit",
        "notation": "auto"
      },
      {
        "name": "kgm3",
        "precision": 3,
        "unit": "kg/m³",
        "showWhen": {
          "resultUnit": [
            "gcm3",
            "lbft3"
          ]
        },
        "notation": "auto"
      },
      {
        "name": "gcm3",
        "precision": 4,
        "unit": "g/cm³",
        "showWhen": {
          "resultUnit": [
            "kgm3",
            "lbft3"
          ]
        },
        "notation": "auto"
      },
      {
        "name": "lbft3",
        "precision": 3,
        "unit": "lb/ft³",
        "showWhen": {
          "resultUnit": [
            "kgm3",
            "gcm3"
          ]
        },
        "notation": "auto"
      },
      {
        "name": "litresPerKg",
        "precision": 4,
        "unit": "L/kg",
        "notation": "auto"
      }
    ],
    "interpret": null
  }
}
