std_dev
Calculate standard deviation for a list of numbers. Choose sample (n-1) or population (n) via population parameter.
Instructions
Sample standard deviation (n-1). Set population: true for population (n).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| numbers | Yes | ||
| population | No |
Implementation Reference
- cruncher.js:1698-1698 (handler)The std_dev handler function. Computes the standard deviation by taking the square root of the variance (computed via computeVariance helper). Accepts 'numbers' array and optional 'population' boolean (default sample n-1).
std_dev: ({ numbers, population }) => Math.sqrt(computeVariance(numbers, !!population)), - cruncher.js:1328-1336 (helper)The computeVariance helper function used by std_dev. Computes sample variance (n-1) by default, or population variance (n) when population=true.
function computeVariance(numbers, population) { if (numbers.length === 0) throw new Error("Cannot calculate the variance of an empty list."); if (numbers.length === 1 && !population) throw new Error("Sample variance needs ≥2 values. Use population: true."); const mean = numbers.reduce((a, b) => a + b, 0) / numbers.length; const ss = numbers.reduce((a, b) => a + (b - mean) ** 2, 0); return ss / (population ? numbers.length : numbers.length - 1); } - cruncher.js:782-801 (schema)The schema definition for std_dev tool. Defines input: 'numbers' array (required) and 'population' boolean (optional).
{ name: "std_dev", annotations: { title: "Standard Deviation", readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false, }, description: "Sample standard deviation (n-1). Set population: true for population (n).", inputSchema: { type: "object", properties: { numbers: { type: "array", items: { type: "number" } }, population: { type: "boolean" }, }, required: ["numbers"], }, }, - cruncher.js:82-84 (registration)std_dev is registered in the 'standard' tool set tier, making it available in standard and full modes.
"sum", "avg", "min", "max", "count", "variance", "std_dev", "percentage_of", "percentage_change", "percentage_reverse", "median", "range", - cruncher.js:144-145 (registration)std_dev is listed as a MAIN_THREAD_TOOLS, meaning it executes directly on the main thread (no worker overhead) for fast execution.
"count", "min", "max", "variance", "std_dev", // Percentage