Skip to content
Browse files

Make changes in functionality, originally implemented by Petr to make

maths class suitable for use in grade book, dependent on boolean
switches in constructor which default to having the changes 'on'.
  • Loading branch information...
1 parent c4f7eec commit 94a67b3992bf658e3bc42e944ab919dbddfdcd64 @jamiepratt jamiepratt committed with timhunt Apr 12, 2011
Showing with 14 additions and 3 deletions.
  1. +14 −3 lib/evalmath/evalmath.class.php
View
17 lib/evalmath/evalmath.class.php
@@ -111,7 +111,14 @@ class EvalMath {
'mod'=>array(2), 'pi'=>array(0), 'power'=>array(2),
'round'=>array(1, 2), 'sum'=>array(-1));
- function EvalMath() {
+ var $allowimplicitmultiplication;
+
+ function EvalMath($allowconstants = false, $allowimplicitmultiplication = false) {
+ if ($allowconstants){
+ $this->v['pi'] = pi();
+ $this->v['e'] = exp(1);
+ }
+ $this->allowimplicitmultiplication = $allowimplicitmultiplication;
}
function e($expr) {
@@ -203,8 +210,12 @@ function nfx($expr) {
//===============
} elseif ((in_array($op, $ops) or $ex) and $expecting_op) { // are we putting an operator on the stack?
if ($ex) { // are we expecting an operator but have a number/variable/function/opening parethesis?
- return $this->trigger("expecting operand");
- //$op = '*'; $index--; // it's an implicit multiplication
+ if (!$this->allowimplicitmultiplication){
+ return $this->trigger("expecting operator, implicit multiplication not allowed.");
+ } else {// it's an implicit multiplication
+ $op = '*';
+ $index--;
+ }
}
// heart of the algorithm:
while($stack->count > 0 and ($o2 = $stack->last()) and in_array($o2, $ops) and ($ops_r[$op] ? $ops_p[$op] < $ops_p[$o2] : $ops_p[$op] <= $ops_p[$o2])) {

0 comments on commit 94a67b3

Please sign in to comment.
Something went wrong with that request. Please try again.