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