Add `atan2` binary operator

Signed-off-by: Levi Harrison <git@leviharrison.dev>
This commit is contained in:
Levi Harrison 2021-08-24 19:22:14 -04:00
parent d77c985f8c
commit 8547a2bd86
4 changed files with 521 additions and 509 deletions

View File

@ -2116,6 +2116,8 @@ func vectorElemBinop(op parser.ItemType, lhs, rhs float64) (float64, bool) {
return lhs, lhs >= rhs
case parser.LTE:
return lhs, lhs <= rhs
case parser.ATAN2:
return math.Atan2(lhs, rhs), true
}
panic(errors.Errorf("operator %q not allowed for operations between Vectors", op))
}

View File

@ -84,6 +84,7 @@ NEQ_REGEX
POW
SUB
AT
ATAN2
%token operatorsEnd
// Aggregators.
@ -156,7 +157,7 @@ START_METRIC_SELECTOR
%left LAND LUNLESS
%left EQLC GTE GTR LSS LTE NEQ
%left ADD SUB
%left MUL DIV MOD
%left MUL DIV MOD ATAN2
%right POW
// Offset modifiers do not have associativity.
@ -237,6 +238,7 @@ aggregate_modifier:
// Operator precedence only works if each of those is listed separately.
binary_expr : expr ADD bin_modifier expr { $$ = yylex.(*parser).newBinaryExpression($1, $2, $3, $4) }
| expr ATAN2 bin_modifier expr { $$ = yylex.(*parser).newBinaryExpression($1, $2, $3, $4) }
| expr DIV bin_modifier expr { $$ = yylex.(*parser).newBinaryExpression($1, $2, $3, $4) }
| expr EQLC bin_modifier expr { $$ = yylex.(*parser).newBinaryExpression($1, $2, $3, $4) }
| expr GTE bin_modifier expr { $$ = yylex.(*parser).newBinaryExpression($1, $2, $3, $4) }

File diff suppressed because it is too large Load Diff

View File

@ -97,6 +97,7 @@ var key = map[string]ItemType{
"and": LAND,
"or": LOR,
"unless": LUNLESS,
"atan2": ATAN2,
// Aggregators.
"sum": SUM,