MDL-75464 libraries: upgrade EvalMath to 1.0.1
This commit is contained in:
@@ -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 == "_") {
|
||||
|
||||
Reference in New Issue
Block a user