modulo
Calculates the remainder of dividing a by b. Returns an error if b is zero.
Instructions
Remainder of a / b. Errors on zero divisor.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| a | Yes | ||
| b | Yes |
Implementation Reference
- cruncher.js:864-880 (schema)Schema/definition for the 'modulo' tool, including its name, description ('Remainder of a / b. Errors on zero divisor.'), and input schema requiring two number parameters (a and b).
{ name: "modulo", annotations: { title: "Modulo", readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false, }, description: "Remainder of a / b. Errors on zero divisor.", inputSchema: { type: "object", properties: { a: { type: "number" }, b: { type: "number" } }, required: ["a", "b"], }, }, - cruncher.js:1720-1729 (handler)Handler for the 'modulo' tool. Delegates to safeMath.modulo(a, b) to compute the remainder of a divided by b.
/** Additional Math Handlers */ /** * Calculates the remainder (modulo) of dividing two numbers. * @param {Object} args - The arguments object. * @param {number} args.a - The dividend. * @param {number} args.b - The divisor. * @returns {number} The remainder of a divided by b. * @throws {Error} If b is zero. */ modulo: ({ a, b }) => safeMath.modulo(a, b), - cruncher.js:1283-1294 (helper)safeMath.modulo implementation: provides safe floating-point modulo using integer-scaling to avoid precision errors. Throws on zero divisor.
modulo: (a, b) => { if (b === 0) throw new Error("Modulo 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)) / multiplier ); }, }; - cruncher.js:76-86 (registration)Registration of 'modulo' in the 'standard' tool tier list, controlling which tools are exposed based on the CRUNCHER_TOOL_SET environment variable.
"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", ],