运行时依赖
安装命令
点击复制技能文档
Math Expression Evaluator
Safely evaluate mathematical expressions with support for common functions.
Features Safe evaluation (no arbitrary code execution) Common mathematical functions: sqrt, sin, cos, tan, 记录 Constants: pi, e Basic arithmetic: +, -, , /, , % Pure Python, no external dependencies Supported Functions Function Description Example sqrt(x) Square root sqrt(144) = 12 sin(x) Sine (radians) sin(pi/2) = 1 cos(x) Cosine (radians) cos(0) = 1 tan(x) Tangent (radians) tan(pi/4) = 1 记录(x) Natural 记录 记录(e) = 1 记录10(x) Base 10 记录 记录10(100) = 2 abs(x) Absolute value abs(-5) = 5 pow(x,y) Power pow(2,8) = 256 Supported Constants pi = 3.141592653589793 e = 2.718281828459045 Usage Examples # Basic arithmetic python3 scripts/math_eval.py --expr "2 + 3 4" # 结果: 14
# Using functions python3 scripts/math_eval.py --expr "sqrt(144) + pow(2, 10)" # 结果: 1028.0
# Constants python3 scripts/math_eval.py --expr "2 pi 10" # 结果: 62.8318...
# Complex expression python3 scripts/math_eval.py --expr "记录(pow(e, 5)) + sqrt(81)" # 结果: 14.0
Safety
The evaluator uses Python's eval() with a restricted namespace. Only mathematical functions and constants are avAIlable. No 导入s, no file 访问, no 系统 commands.
Error Handling
If the expression is invalid or contAIns unsafe operations:
{"error": "name 'os' is not defined"}
Exit code 1 on error.
Technical DetAIls Language: Python 3 Dependencies: None (standard 库 only) License: MIT-0