{
  "schemaVersion": 1,
  "slug": "body-fat-calculator",
  "category": "health",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "a9c345d356c37dbb533b1705944d3a3586b3a707af42644a45b281b797902a31",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/body-fat-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": "BF = 495/(1.29579 − 0.35004·log10(W+Hp−N) + 0.22100·log10(H)) − 450 ♀; 495/(1.0324 − 0.19077·log10(W−N) + 0.15456·log10(H)) − 450 ♂",
    "vars": [
      [
        "H",
        "Height (in)"
      ],
      [
        "N",
        "Neck circumference (in)"
      ],
      [
        "W",
        "Waist circumference (in)"
      ],
      [
        "Hp",
        "Hip circumference, female only (in)"
      ],
      [
        "BF",
        "Body fat percentage"
      ]
    ],
    "note": "US Navy circumference method; centimetres are converted to inches (÷2.54); BF is clamped to 2–70%; fat mass = weight × BF/100."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const h=height/2.54,n=neck/2.54,w=waist/2.54,hp=hip/2.54;if((sex==='female'&&w+hp<=n)||(sex!=='female'&&w<=n))return{bodyFat:null,fatMass:null,leanMass:null,__error:'body-fat'};const lg=Math.log10;let bf;if(sex==='female'){const inner=1.29579-0.35004*lg(w+hp-n)+0.22100*lg(h);bf=495/inner-450}else{const inner=1.0324-0.19077*lg(w-n)+0.15456*lg(h);bf=495/inner-450}if(!Number.isFinite(bf)||bf<0||bf>100)return{bodyFat:null,fatMass:null,leanMass:null,__error:'body-fat'};const fatMass=weight*bf/100;return{bodyFat:bf,fatMass,leanMass:weight-fatMass};",
    "inputs": [
      {
        "name": "sex",
        "type": "select",
        "default": "male",
        "options": [
          {
            "value": "male"
          },
          {
            "value": "female"
          }
        ]
      },
      {
        "name": "height",
        "type": "number",
        "default": 178,
        "min": 100,
        "max": 250,
        "step": 0.5,
        "slider": true
      },
      {
        "name": "neck",
        "type": "number",
        "default": 38,
        "min": 20,
        "max": 100,
        "step": 0.5,
        "slider": true
      },
      {
        "name": "waist",
        "type": "number",
        "default": 85,
        "min": 40,
        "max": 250,
        "step": 0.5,
        "slider": true
      },
      {
        "name": "hip",
        "type": "number",
        "default": 95,
        "min": 40,
        "max": 250,
        "step": 0.5,
        "slider": true,
        "showWhen": {
          "sex": [
            "female"
          ]
        }
      },
      {
        "name": "weight",
        "type": "number",
        "default": 80,
        "min": 20,
        "max": 400,
        "step": 0.5,
        "slider": true
      }
    ],
    "outputs": [
      {
        "name": "bodyFat",
        "precision": 1,
        "unit": "%"
      },
      {
        "name": "fatMass",
        "precision": 1,
        "unit": "kg"
      },
      {
        "name": "leanMass",
        "precision": 1,
        "unit": "kg"
      }
    ],
    "interpret": null
  }
}
