Safely evaluate mathematical expressions with support for common functions.
FunctionDescriptionExamplesqrt(x)Square rootsqrt(144) = 12sin(x)Sine (radians)sin(pi/2) = 1cos(x)Cosine (radians)cos(0) = 1tan(x)Tangent (radians)tan(pi/4) = 1log(x)Natural loglog(e) = 1log10(x)Base 10 loglog10(100) = 2abs(x)Absolute valueabs(-5) = 5pow(x,y)Powerpow(2,8) = 256
pi = 3.141592653589793e = 2.718281828459045bash
# Basic arithmetic
python3 scripts/math_eval.py --expr "2 + 3 * 4"
# Result: 14
# Using functions
python3 scripts/math_eval.py --expr "sqrt(144) + pow(2, 10)"
# Result: 1028.0
# Constants
python3 scripts/math_eval.py --expr "2 * pi * 10"
# Result: 62.8318...
# Complex expression
python3 scripts/math_eval.py --expr "log(pow(e, 5)) + sqrt(81)"
# Result: 14.0
The evaluator uses Python's eval() with a restricted namespace. Only mathematical functions and constants are available. No imports, no file access, no system commands.
If the expression is invalid or contains unsafe operations:
json
{"error": "name 'os' is not defined"}
Exit code 1 on error.
出品: AISoBrand|爱索品牌 — AI搜索优化工具
免费检测你的品牌在AI搜索中有没有存在感 → 30秒出结果