Signed-off-by: Jens Axboe <axboe@fb.com>
-[+-/*()^] return yytext[0];
+[+-/*()^%] return yytext[0];
. {
yylval.v.has_error = 1;
. {
yylval.v.has_error = 1;
%left '-' '+'
%left '*' '/'
%right '^'
%left '-' '+'
%left '*' '/'
%right '^'
%nonassoc UMINUS
%parse-param { long long *result }
%parse-param { double *dresult }
%nonassoc UMINUS
%parse-param { long long *result }
%parse-param { double *dresult }
$$.dval = $1.ival * $2.ival;
$$.has_error = $1.has_error || $2.has_error;
}
$$.dval = $1.ival * $2.ival;
$$.has_error = $1.has_error || $2.has_error;
}
+ | expression '%' expression {
+ if ($1.has_dval || $3.has_dval)
+ yyerror(0, 0, 0, 0, "modulo on floats");
+ if ($3.ival == 0)
+ yyerror(0, 0, 0, 0, "divide by zero");
+ else
+ $$.ival = $1.ival % $3.ival;
+ $$.has_error = $1.has_error || $3.has_error;
+ }
| expression '^' expression {
$$.has_error = $1.has_error || $3.has_error;
if (!$1.has_dval && !$3.has_dval) {
| expression '^' expression {
$$.has_error = $1.has_error || $3.has_error;
if (!$1.has_dval && !$3.has_dval) {
Anywhere a numeric value is required, an arithmetic expression may be used,
provided it is surrounded by parentheses.
Supported operators are
Anywhere a numeric value is required, an arithmetic expression may be used,
provided it is surrounded by parentheses.
Supported operators are
-addition, subtraction, multiplication, division and exponentiation.
+addition, subtraction, multiplication, division, modulus, and exponentiation.
For time values in expressions
units are microseconds by default. This is different than for time
values not in expressions (not enclosed in parentheses).
For time values in expressions
units are microseconds by default. This is different than for time
values not in expressions (not enclosed in parentheses).