Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.
import { pow } from "./math_pow.ts"; ← from math.pow ^1.0.0 · built alongside by fune
import { roundFloat } from "./math_round_float.ts"; ← from math.round-float ^1.0.0 · built alongside by fune
import { type BodySurfaceArea } from "./health_bsa_types.ts";
function checkRange(name: string, value: number, low: number, high: number, unit: string): void {
if (typeof value !== "number" || !Number.isFinite(value) || value < low || value > high) {
throw new RangeError(`${name} must be a number from ${low} to ${high} ${unit}, received ${value}`);
}
}
/**
* Body surface area by both published formulas. They differ by up to a few
* per cent, and a dose protocol names one, so both are returned rather than a
* silent default. Powers go through math.pow, never Math.pow or Math.sqrt,
* so the three languages agree to the bit before rounding.
*/
export function bodySurfaceArea(weightKg: number, heightCm: number): BodySurfaceArea {
checkRange("weightKg", weightKg, 1, 650, "kg");
// Height in metres (1.75) is the commonest unit slip.
checkRange("heightCm", heightCm, 30, 272, "cm");
// Mosteller (1987): BSA (m²) = ([height (cm) × weight (kg)] / 3600)^½.
const mosteller = pow((heightCm * weightKg) / 3600, 0.5);
// DuBois & DuBois (1916): A = W^0.425 × H^0.725 × 71.84, A in cm².
const duBois = (pow(weightKg, 0.425) * pow(heightCm, 0.725) * 71.84) / 10000;
return { mosteller: roundFloat(mosteller, 2), duBois: roundFloat(duBois, 2) };
}