$$math
Evaluate a mathematical expression
Usage​
{
"$$math": /* `op1` / `op` / `array` (`[op1, op, op2]` / `[op, op1, op2]`) */,
"op1": /* BigDecimal */,
"op": /* Math operation (operator) */,
"op2": 0 /* BigDecimal */
}
"$$math(<op1>,<op>,[op2]):{input}"
note
Concrete values in the usage example are default values.
OR
{
"$$math": [/* operator */, /* operand 1 */, /* operand 2 ? */]
}
OR
{
"$$math": [/* operand 1 */, /* operator */, /* operand 2 ? */]
}
OR
"$$math(<operand1>,<operator>,[operand2])"
"$$math(<operator>,<operand1>,[operand2])"
"$$math(<operator>,[operand2]):{operand1}"
Returns​
number
(BigDecimal
)
Arguments​
Argument | Type | Values | Required / Default Value | Description |
---|---|---|---|---|
Primary | BigDecimal | Yes | op1 / op / array ([op1, op, op2] / [op, op1, op2] ) | |
op1 | BigDecimal | Yes | First operand | |
op | enum | + / - /* // /// /% / ^ /& /| /~ /<< / >> /MIN /MAX /SQRT /ROUND / FLOOR /CEIL /ABS /NEG /SIG | Yes | Math operation (operator) |
op2 | BigDecimal | 0 | Second operand or scale for ROUND /FLOOR /CEIL |
Operators​
operator | Action | Example |
---|---|---|
+ , ADD | Addition | "$$math(2,+,3)" = 5 |
- , SUB , SUBTRACT | Subtraction | "$$math(5,-,3)" = 2 |
* , MUL , MULTIPLY | Multiplication | "$$math(2,*,3)" = 6 |
/ , DIV , DIVIDE | Division | "$$math(6,/,3)" = 2 |
// , INTDIV | Integer division | "$$math(7,//,3)" = 2 |
% , MOD , REMAINDER | Modulu | "$$math(7,%,3)" = 1 |
^ , ** , POW , POWER | Power | "$$math(2,^,3)" = 8 |
& , AND | Bit-wise AND | "$$math(6,&,3)" = 2 |
| , OR | Bit-wise OR | "$$math(6,OR,3)" = 7 |
~ , XOR | Bit-wise XOR | "$$math(6,~,3)" = 5 |
<< , SHL | Shift left (bit-wise) | "$$math(6,>>,1)" = 3 |
>> , SHR | Shift right (bit-wise) | "$$math(6,<<,3)" = 48 |
MIN | Minimum | "$$math(MIN,4,2)" = 2 |
MAX | Maximum | "$$math(MAX,4,2)" = 4 |
SQRT | Square root | "$$math(SQRT,81)" = 9 |
ROUND | Round | "$$math(ROUND,4.6)" = 5 |
FLOOR | Floor | "$$math(FLOOR,4.6)" = 4 |
CEIL | Ceil | "$$math(CEIL,4.2)" = 5 |
ABS | Absolute | "$$math(ABS,-10)" = 10 |
NEG , NEGATE | Negation | "$$math(NEG,4)" = -4 |
SIG , SIGNUM | Sign Number | "$$math(SIG,-42)" = -1 |
Examples​
Input
Definition
Output
[
4,
2
]
"$$math(+,$[0],$[1])"
6
[
4,
2
]
"$$math($[0],+,$[1])"
6
[
4,
2
]
"$$math($[0],+)"
4
[
4,
2
]
"$$math($[0],-,$[1])"
2
[
4,
2
]
"$$math($[0],*,$[1])"
8
[
4,
2
]
"$$math($[0],/,$[1])"
2
[
4,
2
]
"$$math($[0],//,3)"
1
[
4,
2
]
"$$math($[0],%,3)"
1
[
4,
2
]
"$$math($[1],^,3)"
8
[
4,
2
]
"$$math(3,&,1)"
1
[
4,
2
]
"$$math(6,AND,3)"
2
[
4,
2
]
"$$math(6,|,3)"
7
[
4,
2
]
"$$math(6,~,3)"
5
[
4,
2
]
"$$math(6,>>,1)"
3
[
4,
2
]
"$$math(6,<<,3)"
48
[
4,
2
]
"$$math(MIN,$[0],$[1])"
2
[
4,
2
]
"$$math(MAX,$[0],$[1])"
4
[
4,
2
]
"$$math(SQRT,81)"
9
[
4,
2
]
"$$math(SQRT):81"
9
[
4,
2
]
"$$math(SQRT):$$math($[0],^,2)"
4
[
4,
2
]
"$$math(ROUND,4.6)"
5
[
4,
2
]
"$$math(ROUND):4.6"
5
[
4,
2
]
"$$math(ROUND,1):4.66"
4.7
[
4,
2
]
"$$math(ROUND,4.66,1)"
4.7
[
4,
2
]
"$$math(4.66,ROUND,1)"
4.7
[
4,
2
]
"$$math(FLOOR,4.6)"
4
[
4,
2
]
"$$math(FLOOR):4.6"
4
[
4,
2
]
"$$math(FLOOR,1):4.66"
4.6
[
4,
2
]
"$$math(CEIL,4.2)"
5
[
4,
2
]
"$$math(CEIL):4.2"
5
[
4,
2
]
"$$math(CEIL,1):4.22"
4.3
[
4,
2
]
"$$math(ABS,-10)"
10
[
4,
2
]
"$$math(ABS):-10"
10
[
4,
2
]
"$$math(NEG,$[0])"
-4
[
4,
2
]
"$$math(NEG):$[0]"
-4
[
4,
2
]
"$$math(SIG):42"
1
[
4,
2
]
"$$math(SIGNUM):-42"
-1
[
4,
2
]
"$$math(SIG):0"
0
[
4,
2
]
{
"$$math": [
"+",
"$[0]",
"$[1]"
]
}
6
[
4,
2
]
{
"$$math": [
"$[0]",
"+",
"$[1]"
]
}
6
[
4,
2
]
{
"$$math": [
"-",
"$[0]",
"$[1]"
]
}
2
[
4,
2
]
{
"$$math": [
"*",
"$[0]",
"$[1]"
]
}
8
[
4,
2
]
{
"$$math": [
"/",
"$[0]",
"$[1]"
]
}
2
[
4,
2
]
{
"$$math": [
"//",
"$[0]",
"3"
]
}
1
[
4,
2
]
{
"$$math": [
"$[0]",
"//",
3
]
}
1
[
4,
2
]
{
"$$math": [
"%",
"$[0]",
"3"
]
}
1
[
4,
2
]
{
"$$math": [
"^",
"$[1]",
"3"
]
}
8
[
4,
2
]
{
"$$math": [
3,
"&",
1
]
}
1
[
4,
2
]
{
"$$math": [
6,
"&",
3
]
}
2
[
4,
2
]
{
"$$math": [
6,
"|",
3
]
}
7
[
4,
2
]
{
"$$math": [
6,
"XOR",
3
]
}
5
[
4,
2
]
{
"$$math": [
6,
">>",
1
]
}
3
[
4,
2
]
{
"$$math": [
6,
"<<",
3
]
}
48
[
4,
2
]
{
"$$math": [
"sqrt",
81
]
}
9
[
4,
2
]
{
"$$math": [
"min",
"$[0]",
"$[1]"
]
}
2
[
4,
2
]
{
"$$math": [
"max",
"$[0]",
"$[1]"
]
}
4
[
4,
2
]
{
"$$math": [
"round",
4.6
]
}
5
[
4,
2
]
{
"$$math": [
"round",
4.66,
1
]
}
4.7
[
4,
2
]
{
"$$math": [
"floor",
4.6
]
}
4
[
4,
2
]
{
"$$math": [
"floor",
4.66,
1
]
}
4.6
[
4,
2
]
{
"$$math": [
"ceil",
4.2
]
}
5
[
4,
2
]
{
"$$math": [
"ceil",
4.22,
1
]
}
4.3
[
4,
2
]
{
"$$math": [
"abs",
-10
]
}
10
[
4,
2
]
{
"$$math": [
"neg",
"$[0]"
]
}
-4
[
"abs",
-10
]
{
"$$math": "$"
}
10
[
4,
2
]
{
"$$math": [
"SIG",
42
]
}
1
[
4,
2
]
{
"$$math": [
"SIGNUM",
-42
]
}
-1
[
4,
2
]
{
"$$math": [
"SIG",
0
]
}
0
null
"$$decimal(2):$$math(1,*,0.987654321)"
0.99
null
"$$decimal(2,FLOOR):$$math(1,*,0.987654321)"
0.98