"use strict"; function round2(x) { return Math.round(x * 100) / 100; } module.exports = { slug: "circle-measures", title: "Circle circumference and area", deck_category: "geometry", description: "Computes a circle's circumference and area from its radius or diameter.", inputs: [ { name: "which_given", type: "string", required: true, description: "Whether value is a radius or a diameter.", enum: ["radius", "diameter"] }, { name: "value", type: "number", unit: "length units", required: true, description: "The radius or diameter, per which_given.", min: 0 } ], outputs: [ { name: "circumference", unit: "length units", description: "Circle circumference." }, { name: "area", unit: "square length units", description: "Circle area." } ], steps: [ "If which_given is diameter, radius = value / 2; otherwise radius = value.", "circumference = 2 * pi * radius.", "area = pi * radius^2.", "Round both to 2 decimals." ], constants: [ { name: "pi", value: 3.14159265358979, unit: "dimensionless", source: 0 } ], sources: [ { kind: "edition_page", value: "Standard geometry reference (e.g. Coxeter, H.S.M. Introduction to Geometry, 2nd ed., Wiley, 1969).", title: "Circle circumference and area formulas", publisher: "Wiley", retrieved_utc: "2026-09-30T19:48:00Z", note: "Standard formulas C=2*pi*r and A=pi*r^2." } ], disclaimer: null, questionText(inputs) { return `What are the circumference and area of a circle with ${inputs.which_given} ${inputs.value}?`; }, run(inputs) { const { which_given, value } = inputs || {}; if (which_given !== "radius" && which_given !== "diameter") throw new Error("which_given must be radius or diameter"); if (typeof value !== "number" || value <= 0) throw new Error("value must be a positive number"); const r = which_given === "diameter" ? value / 2 : value; const circumference = round2(2 * Math.PI * r); const area = round2(Math.PI * r * r); return { answer: `circumference ${circumference.toFixed(2)}, area ${area.toFixed(2)}`, values: { circumference, area } }; }, examples: [ { name: "worked example", inputs: { which_given: "radius", value: 7 }, expected: { answer: "circumference 43.98, area 153.94" }, check: "By hand: circumference=2*3.14159265*7=43.9823 rounds to 43.98; area=3.14159265*49=153.9380 rounds to 153.94." }, { name: "test vector: given diameter", inputs: { which_given: "diameter", value: 10 }, expected: { answer: "circumference 31.42, area 78.54" }, check: "By hand: radius=5; circumference=2*3.14159265*5=31.4159 rounds to 31.42; area=3.14159265*25=78.5398 rounds to 78.54; matches the well known fact that a circle of diameter 10 has circumference pi*10=31.4159." } ] };