calculator
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCalculator
计算器
Evaluate arithmetic expressions with arbitrary-precision decimal math using big.js.
使用big.js对算术表达式进行任意精度的十进制数学求值。
When to Use
适用场景
- User asks to calculate or evaluate a math expression
- Precise decimal arithmetic is needed (avoids floating-point errors like )
0.1 + 0.2 = 0.30000000000000004 - Expressions involve parentheses, operator precedence, or exponents
- 用户要求计算或求值数学表达式
- 需要精确的十进制算术(避免类似的浮点错误)
0.1 + 0.2 = 0.30000000000000004 - 表达式包含括号、运算符优先级或幂运算
Supported Operations
支持的运算
| Operator | Description | Precedence |
|---|---|---|
| Addition | 1 |
| Subtraction | 1 |
| Multiplication | 2 |
| Division | 2 |
| Exponent (right-associative) | 3 |
| Parentheses | Highest |
| 运算符 | 描述 | 优先级 |
|---|---|---|
| 加法 | 1 |
| 减法 | 1 |
| 乘法 | 2 |
| 除法 | 2 |
| 幂运算(右结合) | 3 |
| 括号 | 最高 |
Usage
使用方法
bash
cd scripts
npm ci || npm install
npm run build
npm run calculate "<expression>"bash
cd scripts
npm ci || npm install
npm run build
npm run calculate "<expression>"Examples
示例
| Input | Output |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| 输入 | 输出 |
|---|---|
| |
| |
| |
| |
| |
| |
| |
Edge Cases
边缘情况
- Empty expression: Throws "Empty expression" error
- Mismatched parentheses: Throws "Mismatched parentheses" error
- Division by zero: big.js throws an error
- Exponent must be integer: big.js requires integer exponents
.pow()
- 空表达式:抛出"Empty expression"错误
- 括号不匹配:抛出"Mismatched parentheses"错误
- 除以零:big.js抛出错误
- 幂运算指数必须为整数:big.js 要求指数为整数
.pow()
Limitations
局限性
- No trigonometric functions (sin, cos, tan)
- No variables or symbolic math
- Exponents must be integers
- No factorial, modulo, or bitwise operators
- 无三角函数(sin、cos、tan)
- 不支持变量或符号数学
- 幂运算指数必须为整数
- 无阶乘、取模或位运算符