Merge pull request #332 from influxdata/flux/new-math-operators

New Flux math operators
pull/335/head
Scott Anderson 2019-07-16 15:38:47 -06:00 committed by GitHub
commit 98fbe153c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 19 deletions

View File

@ -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 = "|>" .

View File

@ -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