sum
Calculate the sum of a list of numbers. Provide an array of numbers to get their total.
Instructions
Sum of numbers.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| numbers | Yes |
Implementation Reference
- cruncher.js:549-566 (schema)Schema definition for the 'sum' tool. Defines name, description, and inputSchema expecting an array of numbers.
{ name: "sum", annotations: { title: "Sum", readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false, }, description: "Sum of numbers.", inputSchema: { type: "object", properties: { numbers: { type: "array", items: { type: "number" } }, }, required: ["numbers"], }, }, - cruncher.js:76-76 (registration)The tool name 'sum' is listed in the standard tool tier, registering it as an available tool.
"sum", "avg", "min", "max", "count", "variance", "std_dev", - cruncher.js:1497-1498 (handler)Handler function for the 'sum' tool. Uses reduce with safeMath.add to sum an array of numbers.
sum: ({ numbers }) => numbers.reduce((acc, val) => safeMath.add(acc, val), 0), - cruncher.js:1239-1248 (helper)safeMath.add helper used by the sum handler to perform floating-point-safe addition.
add: (a, b) => { const d1 = countDecimals(a); const d2 = countDecimals(b); const maxDecimals = Math.max(d1, d2); const multiplier = Math.pow(10, maxDecimals); return ( (Math.round(a * multiplier) + Math.round(b * multiplier)) / multiplier ); },