calculator
Evaluate mathematical expressions and unit conversions. Handles arithmetic, percentages, exponents, and common unit conversions (temperature, distance, weight). No external dependencies.
Install
npx skills add https://github.com/NVIDIA/SkillEvaluator/tree/main/src/skillevaluator/tier3/reference_skills/calculator
claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install nvidia-skillevaluator@llmmart
git clone https://github.com/NVIDIA/SkillEvaluator.git
The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole nvidia/skillevaluator collection as a plugin from our marketplace. Git is the plain clone.
Skill manifest
Calculator
Evaluate math expressions and perform unit conversions from the command line.
Purpose
Provide a safe, sandboxed calculator for arithmetic expressions and common
unit conversions without relying on eval() or external services.
Agent Instructions
- Read this SKILL.md to understand capabilities.
- Run
scripts/calc.pywith the user's expression or conversion. - Return the computed result to the user.
Examples
Usage
# Arithmetic expressions
python scripts/calc.py "2 + 3 * 4"
python scripts/calc.py "(100 - 25) / 3"
python scripts/calc.py "2 ** 10"
# Percentage calculations
python scripts/calc.py "15% of 200"
# Unit conversions
python scripts/calc.py "100 celsius to fahrenheit"
python scripts/calc.py "5 miles to km"
python scripts/calc.py "10 kg to lbs"
Output
A single line with the result, e.g.:
Result: 14
For conversions:
100 celsius = 212.0 fahrenheit
Limitations
- No symbolic algebra (no variables, no equations).
- Only supports basic arithmetic operators:
+,-,*,/,**,%, parentheses. - Unit conversions are limited to: celsius/fahrenheit, miles/km, kg/lbs, meters/feet.
Troubleshooting
| Problem | Fix |
|---|---|
Invalid expression |
Check for unsupported operators or variables |
Unknown conversion |
Use supported units: celsius, fahrenheit, miles, km, kg, lbs, meters, feet |
Files (skillevaluator)
-
evals
-
evals.json 1.3 KB
[ { "id": "calculator-001", "question": "What is 2 + 3 * 4? Please use the calculator skill to compute this.", "expected_skill": "calculator", "expected_script": "calc.py", "ground_truth": "The agent used the calculator skill to evaluate the expression '2 + 3 * 4'. It executed calc.py and returned the result 14, correctly following standard operator precedence (multiplication before addition).", "expected_behavior": [ "The agent read the calculator SKILL.md to understand the skill", "The agent executed calc.py with the expression '2 + 3 * 4'", "The agent reported the correct result of 14" ] }, { "id": "calculator-002", "question": "I need to convert 100 degrees Celsius to Fahrenheit. Can you help?", "expected_skill": "calculator", "expected_script": "calc.py", "ground_truth": "The agent used the calculator skill to convert 100 celsius to fahrenheit. It executed calc.py with '100 celsius to fahrenheit' and returned the result: 100 celsius = 212 fahrenheit.", "expected_behavior": [ "The agent read the calculator SKILL.md to understand unit conversion capabilities", "The agent executed calc.py with '100 celsius to fahrenheit'", "The agent reported that 100 degrees Celsius equals 212 degrees Fahrenheit" ] } ]
-
-
scripts
-
calc.py 3.2 KB
#!/usr/bin/env python3 # SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 """Calculator — safe arithmetic evaluation and unit conversions.""" import ast import operator import re import sys OPERATORS = { ast.Add: operator.add, ast.Sub: operator.sub, ast.Mult: operator.mul, ast.Div: operator.truediv, ast.Pow: operator.pow, ast.Mod: operator.mod, ast.USub: operator.neg, ast.UAdd: operator.pos, } def safe_eval(expr: str) -> float: """Evaluate arithmetic expression using AST — no eval().""" tree = ast.parse(expr, mode="eval") def _eval(node): if isinstance(node, ast.Expression): return _eval(node.body) if isinstance(node, ast.Constant) and isinstance(node.value, (int, float)): return node.value if isinstance(node, ast.BinOp): op = OPERATORS.get(type(node.op)) if op is None: raise ValueError(f"Unsupported operator: {type(node.op).__name__}") return op(_eval(node.left), _eval(node.right)) if isinstance(node, ast.UnaryOp): op = OPERATORS.get(type(node.op)) if op is None: raise ValueError(f"Unsupported unary: {type(node.op).__name__}") return op(_eval(node.operand)) raise ValueError(f"Unsupported node: {type(node).__name__}") return _eval(tree) CONVERSIONS = { ("celsius", "fahrenheit"): lambda c: c * 9 / 5 + 32, ("fahrenheit", "celsius"): lambda f: (f - 32) * 5 / 9, ("miles", "km"): lambda m: m * 1.60934, ("km", "miles"): lambda k: k / 1.60934, ("kg", "lbs"): lambda k: k * 2.20462, ("lbs", "kg"): lambda l: l / 2.20462, ("meters", "feet"): lambda m: m * 3.28084, ("feet", "meters"): lambda f: f / 3.28084, } def try_conversion(expr: str) -> str | None: m = re.match( r"([\d.]+)\s+(\w+)\s+to\s+(\w+)", expr.strip(), re.IGNORECASE, ) if not m: return None value = float(m.group(1)) from_unit = m.group(2).lower() to_unit = m.group(3).lower() fn = CONVERSIONS.get((from_unit, to_unit)) if fn is None: return None result = fn(value) return f"{value:g} {from_unit} = {result:.4g} {to_unit}" def try_percentage(expr: str) -> str | None: m = re.match(r"([\d.]+)%\s+of\s+([\d.]+)", expr.strip(), re.IGNORECASE) if not m: return None pct = float(m.group(1)) base = float(m.group(2)) result = pct / 100 * base return f"Result: {result:g}" def main(): if len(sys.argv) < 2: print("Usage: calc.py <expression>", file=sys.stderr) sys.exit(1) expr = " ".join(sys.argv[1:]) conv = try_conversion(expr) if conv: print(conv) return pct = try_percentage(expr) if pct: print(pct) return try: result = safe_eval(expr) if result == int(result): print(f"Result: {int(result)}") else: print(f"Result: {result:g}") except Exception as e: print(f"Error: {e}", file=sys.stderr) sys.exit(1) if __name__ == "__main__": main()
-
-
SKILL.md 1.7 KB
--- name: calculator description: Evaluate mathematical expressions and unit conversions. Handles arithmetic, percentages, exponents, and common unit conversions (temperature, distance, weight). No external dependencies. compatibility: Python 3.10+, no external dependencies metadata: author: SkillEvaluator Maintainers <maintainers@example.com> --- # Calculator Evaluate math expressions and perform unit conversions from the command line. ## Purpose Provide a safe, sandboxed calculator for arithmetic expressions and common unit conversions without relying on `eval()` or external services. ## Agent Instructions 1. Read this SKILL.md to understand capabilities. 2. Run `scripts/calc.py` with the user's expression or conversion. 3. Return the computed result to the user. ## Examples ### Usage ```bash # Arithmetic expressions python scripts/calc.py "2 + 3 * 4" python scripts/calc.py "(100 - 25) / 3" python scripts/calc.py "2 ** 10" # Percentage calculations python scripts/calc.py "15% of 200" # Unit conversions python scripts/calc.py "100 celsius to fahrenheit" python scripts/calc.py "5 miles to km" python scripts/calc.py "10 kg to lbs" ``` ### Output A single line with the result, e.g.: ``` Result: 14 ``` For conversions: ``` 100 celsius = 212.0 fahrenheit ``` ## Limitations - No symbolic algebra (no variables, no equations). - Only supports basic arithmetic operators: `+`, `-`, `*`, `/`, `**`, `%`, parentheses. - Unit conversions are limited to: celsius/fahrenheit, miles/km, kg/lbs, meters/feet. ## Troubleshooting | Problem | Fix | |---------|-----| | `Invalid expression` | Check for unsupported operators or variables | | `Unknown conversion` | Use supported units: celsius, fahrenheit, miles, km, kg, lbs, meters, feet |
Comments (0)
Sign in to join the conversation.
Reviews (0)
No reviews yet.
No comments yet.