X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/48f48e6a26a54751ecd0ab90b10ab972cc5e89cd..6a0ffdb10d7344d99e04c5518fca2b8295df94be:/ArithmeticEvaluator.cpp?ds=inline diff --git a/ArithmeticEvaluator.cpp b/ArithmeticEvaluator.cpp index 54a9596..2898f13 100644 --- a/ArithmeticEvaluator.cpp +++ b/ArithmeticEvaluator.cpp @@ -15,7 +15,7 @@ supp. infos : saved in UTF-8 [éè] #include ArithmeticEvaluator::ArithmeticEvaluator() { - opMarkers = "+-*/"; + opMarkers = "+-*/|%"; // | is for euclidan division varMarkers = "$"; expression = QStringList(); /* CAUTION : function are mandatory using ( ) to encapsulate the operand @@ -26,7 +26,7 @@ ArithmeticEvaluator::ArithmeticEvaluator() { } 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 @@ -156,6 +156,16 @@ double ArithmeticEvaluator::evaluate() throw(int) { 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); @@ -303,7 +313,7 @@ QString ArithmeticEvaluator::convertRecur(const QString& _expression, int *offse *offset += 1; } } - else if (expr[*offset] == '/') { + else if ((expr[*offset] == '/')||(expr[*offset] == '|')||(expr[*offset] == '%')) { if (!checkAfterOp(expr,*offset)) throw(*offset); @@ -311,7 +321,7 @@ QString ArithmeticEvaluator::convertRecur(const QString& _expression, int *offse 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 { @@ -469,6 +479,8 @@ bool ArithmeticEvaluator::checkAfterPar(const QString& _expression, int offset) 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; }