Skip to content

Commit 05233d2

Browse files
committed
Support modulo operator '%'
The spec is underspecified in what should happen if the left hand side is a float. This commit decides that the result is undefined (unknown). The spec is also underspecified in what should happen if either the left hand side or the right hand side is negative. This commit decides to use the behaviour of Erlang `rem`.
1 parent b5a5619 commit 05233d2

File tree

6 files changed

+940
-875
lines changed

6 files changed

+940
-875
lines changed

deps/rabbit/src/rabbit_amqp_filter_sql.erl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ eval0({Op, Expr1, Expr2}, Msg)
140140
when Op =:= '+' orelse
141141
Op =:= '-' orelse
142142
Op =:= '*' orelse
143-
Op =:= '/' ->
143+
Op =:= '/' orelse
144+
Op =:= '%' ->
144145
arithmetic(Op, eval0(Expr1, Msg), eval0(Expr2, Msg));
145146

146147
%% Unary operators
@@ -209,6 +210,8 @@ arithmetic('*', Left, Right) when is_number(Left) andalso is_number(Right) ->
209210
Left * Right;
210211
arithmetic('/', Left, Right) when is_number(Left) andalso is_number(Right) andalso Right /= 0 ->
211212
Left / Right;
213+
arithmetic('%', Left, Right) when is_integer(Left) andalso is_integer(Right) andalso Right =/= 0 ->
214+
Left rem Right;
212215
arithmetic(_, _, _) ->
213216
undefined.
214217

0 commit comments

Comments
 (0)