Merge pull request #332 from influxdata/flux/new-math-operators
New Flux math operatorspull/335/head
commit
98fbe153c1
|
@ -42,7 +42,7 @@ Object literals construct a value with the object type.
|
||||||
```js
|
```js
|
||||||
ObjectLiteral = "{" ObjectBody "}" .
|
ObjectLiteral = "{" ObjectBody "}" .
|
||||||
ObjectBody = WithProperties | PropertyList .
|
ObjectBody = WithProperties | PropertyList .
|
||||||
WithProperties = identifier "with" PropertyList .
|
WithProperties = identifier "with" PropertyList .
|
||||||
PropertyList = [ Property { "," Property } ] .
|
PropertyList = [ Property { "," Property } ] .
|
||||||
Property = identifier [ ":" Expression ]
|
Property = identifier [ ":" Expression ]
|
||||||
| string_lit ":" Expression .
|
| string_lit ":" Expression .
|
||||||
|
@ -198,22 +198,23 @@ Operators combine operands into expressions.
|
||||||
The precedence of the operators is given in the table below.
|
The precedence of the operators is given in the table below.
|
||||||
Operators with a lower number have higher precedence.
|
Operators with a lower number have higher precedence.
|
||||||
|
|
||||||
| Precedence | Operator | Description |
|
| Precedence | Operator | Description |
|
||||||
|:----------:|:--------: |:--------------------------|
|
|:----------:|:--------: |:-------------------------- |
|
||||||
| 1 | `a()` | Function call |
|
| 1 | `a()` | Function call |
|
||||||
| | `a[]` | Member or index access |
|
| | `a[]` | Member or index access |
|
||||||
| | `.` | Member access |
|
| | `.` | Member access |
|
||||||
| 2 | `*` `/` |Multiplication and division|
|
| 2 | `^` | Exponentiation |
|
||||||
| 3 | `+` `-` | Addition and subtraction |
|
| 3 | `*` `/` `%` | Multiplication, division, and modulo |
|
||||||
| 4 |`==` `!=` | Comparison operators |
|
| 4 | `+` `-` | Addition and subtraction |
|
||||||
| | `<` `<=` | |
|
| 5 |`==` `!=` | Comparison operators |
|
||||||
| | `>` `>=` | |
|
| | `<` `<=` | |
|
||||||
| |`=~` `!~` | |
|
| | `>` `>=` | |
|
||||||
| 5 | `not` | Unary logical operator |
|
| |`=~` `!~` | |
|
||||||
| | `exists` | Null check operator |
|
| 6 | `not` | Unary logical operator |
|
||||||
| 6 | `and` | Logical AND |
|
| | `exists` | Null check operator |
|
||||||
| 7 | `or` | Logical OR |
|
| 7 | `and` | Logical AND |
|
||||||
| 8 | `if` `then` `else` | Conditional |
|
| 8 | `or` | Logical OR |
|
||||||
|
| 9 | `if` `then` `else` | Conditional |
|
||||||
|
|
||||||
The operator precedence is encoded directly into the grammar as the following.
|
The operator precedence is encoded directly into the grammar as the following.
|
||||||
|
|
||||||
|
@ -235,7 +236,7 @@ AdditiveExpression = MultiplicativeExpression
|
||||||
AdditiveOperator = "+" | "-" .
|
AdditiveOperator = "+" | "-" .
|
||||||
MultiplicativeExpression = PipeExpression
|
MultiplicativeExpression = PipeExpression
|
||||||
| MultiplicativeExpression MultiplicativeOperator PipeExpression .
|
| MultiplicativeExpression MultiplicativeOperator PipeExpression .
|
||||||
MultiplicativeOperator = "*" | "/" .
|
MultiplicativeOperator = "*" | "/" | "%" | "^".
|
||||||
PipeExpression = PostfixExpression
|
PipeExpression = PostfixExpression
|
||||||
| PipeExpression PipeOperator UnaryExpression .
|
| PipeExpression PipeOperator UnaryExpression .
|
||||||
PipeOperator = "|>" .
|
PipeOperator = "|>" .
|
||||||
|
|
|
@ -34,7 +34,8 @@ perform a calculation that returns a single numerical value.
|
||||||
| `-` | Subtraction | `3 - 2` | `1` |
|
| `-` | Subtraction | `3 - 2` | `1` |
|
||||||
| `*` | Multiplication | `2 * 3` | `6` |
|
| `*` | Multiplication | `2 * 3` | `6` |
|
||||||
| `/` | Division | `9 / 3` | `3` |
|
| `/` | Division | `9 / 3` | `3` |
|
||||||
| `%` | Modulus | `10 % 5` | `0` |
|
| `^` | Exponentiation | `2 ^ 3` | `8` |
|
||||||
|
| `%` | Modulo | `10 % 5` | `0` |
|
||||||
|
|
||||||
{{% note %}}
|
{{% note %}}
|
||||||
In the current version of Flux, values used in arithmetic operations must
|
In the current version of Flux, values used in arithmetic operations must
|
||||||
|
|
Loading…
Reference in New Issue