{
  "schemaVersion": 1,
  "slug": "molarity-calculator",
  "category": "science",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "c0890cc3faea650ee057538dab78ee4bbd9cf31d4f204bca06055a202018d00e",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/molarity-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": "n = m ÷ M; c = n ÷ V",
    "vars": [
      [
        "n",
        "amount of substance, mol"
      ],
      [
        "m",
        "solute mass, g"
      ],
      [
        "M",
        "molar mass, g/mol"
      ],
      [
        "c",
        "molarity, mol/L"
      ],
      [
        "V",
        "solution volume, L"
      ]
    ],
    "note": "Moles = mass / molar mass; molarity = moles / solution volume. The volume required for a 1 M solution is undefined when the entered solute mass is zero."
  },
  "externalEvidence": {
    "reviewedAt": "2026-10-04",
    "sources": [
      {
        "name": "OpenStax Chemistry — Molarity and dilution",
        "url": "https://openstax.org/books/chemistry-2e/pages/3-3-molarity"
      }
    ],
    "basis": "M = (mass / molar mass) / solution volume in litres.",
    "limitations": "Use final solution volume, not added solvent volume; assumes the entered solute molar mass is correct.",
    "implementationHash": "c0890cc3faea650ee057538dab78ee4bbd9cf31d4f204bca06055a202018d00e",
    "domain": "math"
  },
  "contract": {
    "compute": "if(molarMass<=0||volume<=0)return{moles:null,millimoles:null,molarity:null,millimolarity:null,gramsPerLitre:null,volumeFor1M:null,__error:'inputError'};const mol=mass/molarMass,m=mol/volume;return{moles:mol,millimoles:mol*1000,molarity:m,millimolarity:m*1000,gramsPerLitre:mass/volume,volumeFor1M:mol>0?mol:null}",
    "inputs": [
      {
        "name": "mass",
        "type": "number",
        "default": 58.44,
        "min": 0,
        "max": 100000,
        "step": 0.001
      },
      {
        "name": "molarMass",
        "type": "number",
        "default": 58.44,
        "min": 0.001,
        "max": 10000,
        "step": 0.001
      },
      {
        "name": "volume",
        "type": "number",
        "default": 1,
        "min": 0.001,
        "max": 10000,
        "step": 0.001
      }
    ],
    "outputs": [
      {
        "name": "molarity",
        "precision": 5,
        "unit": "M"
      },
      {
        "name": "moles",
        "precision": 6,
        "unit": "mol"
      },
      {
        "name": "millimoles",
        "precision": 3,
        "unit": "mmol"
      },
      {
        "name": "millimolarity",
        "precision": 3,
        "unit": "mM"
      },
      {
        "name": "gramsPerLitre",
        "precision": 4,
        "unit": "g/L"
      },
      {
        "name": "volumeFor1M",
        "precision": 4,
        "unit": "L",
        "optional": true
      }
    ],
    "interpret": null
  }
}
