divide
Divides two numbers. Returns an error if the divisor is zero.
Instructions
Divides two numbers. Errors on zero divisor.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| a | Yes | ||
| b | Yes |
Implementation Reference
- cruncher.js:280-296 (schema)Schema definition for the 'divide' tool: specifies input parameters 'a' (number) and 'b' (number), both required. Description: 'Divides two numbers. Errors on zero divisor.'
{ name: "divide", annotations: { title: "Divide", readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false, }, description: "Divides two numbers. Errors on zero divisor.", inputSchema: { type: "object", properties: { a: { type: "number" }, b: { type: "number" } }, required: ["a", "b"], }, }, - cruncher.js:66-67 (registration)Tool registration in the 'minimal' tier list. 'divide' is included in all three tool tiers (minimal, standard, full via null).
"evaluate_expression", "add", "subtract", "multiply", "divide", ], - cruncher.js:1269-1276 (helper)Helper function safeMath.divide: performs safe floating-point division with integer-scaling to avoid precision errors. Throws if divisor is zero.
divide: (a, b) => { if (b === 0) throw new Error("Division by zero is not allowed."); 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); }, - cruncher.js:1344-1352 (handler)Handler for the 'divide' tool in toolHandlers. Takes { a, b } and delegates to safeMath.divide(a, b).
/** * Divides the first number by the second. * @param {Object} args - The arguments object. * @param {number} args.a - The numerator. * @param {number} args.b - The denominator. * @returns {number} The quotient of a and b. * @throws {Error} If b is zero. */ divide: ({ a, b }) => safeMath.divide(a, b), - cruncher.js:69-80 (registration)Tool registration in the 'standard' tier list. 'divide' is included in standard tier as well.
standard: [ "evaluate_expression", "add", "subtract", "multiply", "divide", "sqrt", "power", "absolute", "modulo", "factorial", "logarithm", "natural_log", "get_constant", "sine", "cosine", "tangent", "asin", "acos", "atan", "set_angle_mode", "get_angle_mode", "sum", "avg", "min", "max", "count", "variance", "std_dev", "percentage_of", "percentage_change", "percentage_reverse", "median", "range", "convert_unit", ],