Skill: yukin1218/calculator (version 1.0.1)

--- name: calculator description: | Accurate mathematical calculations. Use when user needs to compute: (1) Basic arithmetic (+, -, *, /), (2) Powers and roots (^, sqrt), (3) Percentages, (4) Trigonometry (sin, cos, tan), (5) Logarithms (log, ln), (6) Complex expressions, (7) Unit conversions. --- # Calculator Skill Perform accurate mathematical calculations using the `calc.py` script. ## Usage Run calculations directly with Python: ```bash python3 <skill-path>/scripts/calc.py "<expression>" ``` ## Supported Operations ### Basic Arithmetic - `+` Addition: `2 + 3` → 5 - `-` Subtraction: `10 - 4` → 6 - `*` Multiplication: `6 * 7` → 42 - `/` Division: `15 / 3` → 5 ### Powers & Roots - `^` or `**` Power: `2^10` → 1024 - `sqrt()` Square root: `sqrt(16)` → 4 ### Percentages - `100 * 15%` → 15 (15% of 100) - `50 + 50 * 10%` → 55 (add 10%) ### Trigonometry (radians) - `sin(pi/2)` → 1 - `cos(pi)` → -1 - `tan(pi/4)` → 1 ### Logarithms - `log(100)` → 2 (base 10) - `ln(e)` → 1 (natural log) ### Constants - `pi` → 3.141592653589793 - `e` → 2.718281828459045 ### Other Functions - `abs(-5)` → 5 - `round(3.7)` → 4 - `floor(3.9)` → 3 - `ceil(3.1)` → 4 - `pow(2, 8)` → 256 ## Examples ```bash python3 scripts/calc.py "2 + 3 * 4" # 14 python3 scripts/calc.py "(2 + 3) * 4" # 20 python3 scripts/calc.py "sqrt(144)" # 12 python3 scripts/calc.py "2^8" # 256 python3 scripts/calc.py "1000 * 5%" # 50 python3 scripts/calc.py "sin(0)" # 0 python3 scripts/calc.py "log(1000)" # 3 ``` ## Notes - Implicit multiplication supported: `2(3)` = `2*3` - Use parentheses for grouping - Float results are rounded to 10 decimal places to avoid precision issues

path: scripts/calc.py
content: #!/usr/bin/env python3
"""
Calculator script for accurate mathematical operations.
Supports: basic arithmetic, percentages, powers, roots, trigonometry, logarithms, etc.
"""

import math
import sys
import re

def calculate(expression: str) -> str:
    """Evaluate a mathematical expression and return the result."""
    # Clean up the expression
    expr = expression.strip()
    
    # Define safe operations
    safe_dict = {
        'abs': abs,
        'round': round,
        'min': min,
        'max': max,
        'pow': pow,
        'sqrt': math.sqrt,
        'sin': math.sin,
        'cos': math.cos,
        'tan': math.tan,
        'asin': math.asin,
        'acos': math.acos,
        'atan': math.atan,
        'log': math.log10,
        'ln': math.log,
        'exp': math.exp,
        'pi': math.pi,
        'e': math.e,
        'floor': math.floor,
        'ceil': math.ceil,
    }
    
    # Replace common operators
    expr = expr.replace('^', '**')
    expr = expr.replace('×', '*')
    expr = expr.replace('÷', '/')
    expr = expr.replace('％', '%')
    
    # Handle percentages: "100 * 15%" -> "100 * 0.15"
    # Match patterns like "100 * 15%" or "100*15%"
    expr = re.sub(r'(\d+(?:\.\d+)?)\s*\*\s*(\d+(?:\.\d+)?)\s*%', r'(\1 * \2 / 100)', expr)
    
    # Handle implicit multiplication: 2(3) -> 2*(3)
    expr = re.sub(r'(\d)(\()', r'\1*\2', expr)
    expr = re.sub(r'(\))(\d)', r'\1*\2', expr)
    expr = re.sub(r'(\))(\()', r'\1*\2', expr)
    
    try:
        result = eval(expr, {"__builtins__": {}}, safe_dict)
        
        # Format result nicely
        if isinstance(result, float):
            # Avoid floating point precision issues
            if result.is_integer():
                return str(int(result))
            # Round to reasonable precision
            rounded = round(result, 10)
            return str(rounded).rstrip('0').rstrip('.')
        return str(result)
    except Exception as e:
        return f"Error: {str(e)}"


def main():
    if len(sys.argv) < 2:
        print("Usage: calculator.py '<expression>'")
        print("Examples:")
        print("  calculator.py '2 + 3'           # 5")
        print("  calculator.py '10 * 5'          # 50")
        print("  calculator.py '2^10'             # 1024")
        print("  calculator.py 'sqrt(16)'         # 4")
        print("  calculator.py 'sin(pi/2)'        # 1")
        print("  calculator.py '100 * 15%'         # 15")
        sys.exit(1)
    
    expression = ' '.join(sys.argv[1:])
    result = calculate(expression)
    print(result)


if __name__ == "__main__":
    main()


Security scan verdicts — ClawScan: suspicious | static analysis: suspicious | VirusTotal: clean | SkillSpector: suspicious (MEDIUM)