#include <math.h>
ArithmeticEvaluator::ArithmeticEvaluator() {
- opMarkers = "+-*/";
+ opMarkers = "+-*/|%"; // | is for euclidan division
varMarkers = "$";
expression = QStringList();
/* CAUTION : function are mandatory using ( ) to encapsulate the operand
}
ArithmeticEvaluator::ArithmeticEvaluator(const QString& _expression) throw(int) {
- opMarkers = "+-*/";
+ opMarkers = "+-*/|%"; // | is for euclidan division
varMarkers = "$";
expression = QStringList();
/* CAUTION : function are mandatory using ( ) to encapsulate the operand
else if (c == '/') {
stack.push(value1/value2);
}
+ else if (c == '|') {
+ int val1 = (int)value1;
+ int val2 = (int)value2;
+ stack.push(val1/val2);
+ }
+ else if (c == '%') {
+ int val1 = (int)value1;
+ int val2 = (int)value2;
+ stack.push(val1%val2);
+ }
}
else {
value1 = elt.toDouble(&ok);
*offset += 1;
}
}
- else if (expr[*offset] == '/') {
+ else if ((expr[*offset] == '/')||(expr[*offset] == '|')||(expr[*offset] == '%')) {
if (!checkAfterOp(expr,*offset)) throw(*offset);
c = '1';
while ( (pile.isEmpty() == false) && (c != '(') && (c != '+') && (c != '-')) {
c = pile.pop();
- if ( (c=='*') || (c == '/')) {
+ if ( (c=='*') || (c == '/') || (c == '|') || (c=='%')) {
result.append(c).append(",");
}
else {
else if (_expression[offset+1] == '-') return true;
else if (_expression[offset+1] == '*') return true;
else if (_expression[offset+1] == '/') return true;
+ else if (_expression[offset+1] == '|') return true;
+ else if (_expression[offset+1] == '%') return true;
return false;
}