fio: support modulus for the arithmetic parser
Signed-off-by: Jens Axboe <axboe@fb.com>
diff --git a/exp/expression-parser.l b/exp/expression-parser.l
index a0c6b24..bb80553 100644
--- a/exp/expression-parser.l
+++ b/exp/expression-parser.l
@@ -158,7 +158,7 @@
}
}
\n return 0;
-[+-/*()^] return yytext[0];
+[+-/*()^%] return yytext[0];
. {
yylval.v.has_error = 1;
diff --git a/exp/expression-parser.y b/exp/expression-parser.y
index f5a7981..fa19a51 100644
--- a/exp/expression-parser.y
+++ b/exp/expression-parser.y
@@ -59,6 +59,7 @@
%left '-' '+'
%left '*' '/'
%right '^'
+%left '%'
%nonassoc UMINUS
%parse-param { long long *result }
%parse-param { double *dresult }
@@ -132,6 +133,15 @@
$$.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) {
diff --git a/fio.1 b/fio.1
index 66c9cb0..01c7cec 100644
--- a/fio.1
+++ b/fio.1
@@ -119,7 +119,7 @@
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).