算术
下表显示了可与 JSON 表达式语言一起使用的算术表达式。
| 操作 | Expression | 输入 | 输出 |
|---|---|---|---|
| 加 | ["+", operand1, operand2] |
{ sum: ["+", 2, 4] } |
{ sum: 6 } |
| 减 | ["-", operand1, operand2] |
{ difference: ["-", 10, 3] } |
{ difference: 7 } |
| 乘 | ["*", operand1, operand2] |
{ product: ["*", 5, 6] } |
{ product: 30 } |
| 除 | ["/", operand1, operand2] |
{ quotient: ["/", 20, 4] } |
{ quotient: 5 } |
| 取模 | ["%", operand1, operand2] |
{ remainder: ["%", 15, 4] } |
{ remainder: 3 } |
| 幂 | ["**", base, exponent] |
{ power: ["**", 2, 3] } |
{ power: 8 } |
| 绝对值 | ["abs", operand] |
{ absolute: ["abs", -5] } |
{ absolute: 5 } |
| Square Root | ["sqrt", operand] |
{ sqroot: ["sqrt", 16] } |
{ sqroot: 4 } |
| 对数(以 10 为底) | ["log10", operand] |
{ log: ["log10", 100] } |
{ log: 2 } |
| 自然对数 | ["ln", operand] |
{ ln: ["ln", Math.E] } |
{ ln: 1 } |
| 四舍五入 | ["round", operand] |
{ rounded: ["round", 3.7] } |
{ rounded: 4 } |
| 向下取整 | ["floor", operand] |
{ floor: ["floor", 3.7] } |
{ floor: 3 } |
| 向上取整 | ["ceil", operand] |
{ ceiling: ["ceil", 3.2] } |
{ ceiling: 4 } |
| 正弦 | ["sin", operand] |
{ sine: ["sin", 0] } |
{ sine: 0 } |
| 余弦 | ["cos", operand] |
{ cosine: ["cos", 0] } |
{ cosine: 1 } |
| 正切 | ["tan", operand] |
{ tangent: ["tan", Math.PI] } |
{ tangent: 0 } |