Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upArithmetic operator precedence doesn't work as documented #1446
Comments
brian-brazil
added
the
bug
label
Mar 2, 2016
This comment has been minimized.
This comment has been minimized.
|
A question for Mr Parser AKA @fabxc . :) |
beorn7
assigned
fabxc
Mar 2, 2016
This comment has been minimized.
This comment has been minimized.
|
Here's a test that demonstrates the issue:
Result:
...this is indeed parsed wrong. It's parsed as (1) < ((2-1) * 2). I believe the problem is that the "rebalance" step is not recursive, and it needs to be. Currently for L op R, where L itself is L_L L_op L_R, if L_op precedence is less than op precedence, then the expression is rewritten from L_L L_op L_R op R to L_L L_op [L_r op R]. Hopefully that's not too confusing. The problem occurs when L_R is itself an expression; LR_L LR_op LR_R; this expression is not checked for precedence and it should be. |
fabxc
closed this
in
#1451
Mar 3, 2016
This comment has been minimized.
This comment has been minimized.
lock
bot
commented
Mar 24, 2019
|
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
korfuri commentedMar 2, 2016
Consider the following expressions:
(1)
1 < 2evaluates to 1(2)
1 < 2 - 1evaluates to 0(3)
1 < 2 - 1 * 2evaluates to 1(4)
1 < 2 - (1 * 2)evaluates to 0Operator precedence (http://prometheus.io/docs/querying/operators/#binary-operator-precedence) suggests (3) and (4) should both evaluate to 0. However (3) doesn't, and I don't understand why. I've solved it in my rules by parenthesizing more, but the behavior is certainly surprising.
I'm running Prometheus version:
branch debian/sid
date 20150806-01:11:22
go_version go1.4.2
revision 0.14.0+ds-1
version 0.14.0+ds