Skip to content

Plugin Calculator

Jon edited this page Sep 5, 2026 · 2 revisions

calculator Plugin

calculator is a reference TypeScript plugin for Ash. It evaluates complex mathematical formulas and expressions without relying on unsafe eval().

Capabilities and Supported Mathematics

  • Arithmetic: +, -, *, /, %, ^ (exponentiation)
  • Functions: sin, cos, tan, sqrt, log, ln, exp, abs, floor, ceil, round, min, max
  • Constants: pi, e
  • Parentheses: arbitrary nested expressions

Capabilities and Arguments

Discovery & Documentation

calculator --ai-docs

Returns structured JSON:

{
  "Capabilities": [
    "Safely evaluate mathematical expressions and formulas.",
    "Support arithmetic (+, -, *, /, %, ^), parentheses, constants (pi, e), and standard math functions (sin, cos, tan, sqrt, log, ln, exp, abs, floor, ceil, round)."
  ],
  "Arguments": {
    "--expr": "Mathematical expression string to evaluate (e.g. '2 + 2 * 3', 'sin(pi / 4)', 'sqrt(144) + 10^2')",
    "--format": "Output format: 'json' (default) or 'text'",
    "--ai-docs": "Print AI documentation and exit",
    "--version": "Print version and exit",
    "--help": "Print help and exit"
  },
  "Return format": {
    "status": "success or error",
    "expression": "the evaluated input expression",
    "result": "calculated numerical result as a float or integer",
    "error_message": "description of syntax or evaluation error when status is error"
  },
  "Usage guidance for the AI": "Use calculator for precise mathematical computations instead of performing mental math. A single call evaluates the expression. Directly parse and use the numerical result from the JSON response."
}

CLI Usage Examples

  • Direct evaluation (JSON default):
    calculator --expr "2 + 2 * 3"
    # Output: {"status":"success","expression":"2 + 2 * 3","result":8}
  • Text format:
    calculator --expr "sin(pi / 2) + 2^4" --format text
    # Output: 17

Clone this wiki locally