MDL-75464 libraries: upgrade EvalMath to 1.0.1

This commit is contained in:
Meirza
2023-03-16 17:27:30 +07:00
parent 12a8176926
commit 30a220ec83
4 changed files with 115 additions and 7 deletions
+7 -5
View File
@@ -210,14 +210,14 @@ class EvalMath {
$output = array(); // postfix form of expression, to be passed to pfx()
$expr = trim(strtolower($expr));
// MDL-14274: new operators for comparison added.
$ops = array('+', '-', '*', '/', '^', '_', '>', '<', '<=', '>=', '==');
$ops_r = array('+'=>0,'-'=>0,'*'=>0,'/'=>0,'^'=>1); // right-associative operator?
$ops_p = array('+'=>0,'-'=>0,'*'=>1,'/'=>1,'_'=>1,'^'=>2, '>'=>3, '<'=>3, '<='=>3, '>='=>3, '=='=>3); // operator precedence
$ops = array('+', '-', '*', '/', '^', '_', '>', '<', '<=', '>=', '==', '%');
$ops_r = array('+'=>0,'-'=>0,'*'=>0,'/'=>0,'^'=>1, '%' => 0); // right-associative operator?
$ops_p = array('+'=>0,'-'=>0,'*'=>1,'/'=>1,'_'=>1,'^'=>2, '>'=>3, '<'=>3, '<='=>3, '>='=>3, '=='=>3, '%'=>1); // operator precedence
$expecting_op = false; // we use this in syntax-checking the expression
// and determining when a - is a negation
if (preg_match("/[^\w\s+*^\/()\.,-<>=]/", $expr, $matches)) { // make sure the characters are all good
if (preg_match("/[^\%\w\s+*^\/()\.,-<>=]/", $expr, $matches)) { // make sure the characters are all good
return $this->trigger(get_string('illegalcharactergeneral', 'mathslib', $matches[0]));
}
@@ -433,7 +433,7 @@ class EvalMath {
$stack->push($this->pfx($this->f[$fnn]['func'], $args)); // yay... recursion!!!!
}
// if the token is a binary operator, pop two values off the stack, do the operation, and push the result back on
} elseif (in_array($token, array('+', '-', '*', '/', '^', '>', '<', '==', '<=', '>='), true)) {
} elseif (in_array($token, array('+', '-', '*', '/', '^', '>', '<', '==', '<=', '>=', '%'), true)) {
if (is_null($op2 = $stack->pop())) return $this->trigger(get_string('internalerror', 'mathslib'));
if (is_null($op1 = $stack->pop())) return $this->trigger(get_string('internalerror', 'mathslib'));
switch ($token) {
@@ -458,6 +458,8 @@ class EvalMath {
$stack->push((int)($op1 <= $op2)); break;
case '>=':
$stack->push((int)($op1 >= $op2)); break;
case '%':
$stack->push($op1%$op2); break;
}
// if the token is a unary operator, pop one value off the stack, do the operation, and push it back on
} elseif ($token == "_") {