EvalSpinBox evaluator operators priority backported from PIP

This commit is contained in:
2020-09-07 00:52:51 +03:00
parent 5ed8d8114a
commit 146863a533
2 changed files with 23 additions and 7 deletions

View File

@@ -715,14 +715,13 @@ int QPIEvaluator::parse(const QString & string, int offset) {
if (args.size() > 0) return args.back();
else return -666;
}
for (int i = 0; i < QPIEvaluatorTypes::operationCount; i++) {
coper = operationInOrder(i);
int oprior = -1;
QVector<QPIEvaluatorTypes::Operation> opv;
while(1) {
operationsByPriority(++oprior, opv);
if (opv.isEmpty()) break;
for (int j = 0; j < opers.size(); j++) {
if (coper == QPIEvaluatorTypes::oDivide || coper == QPIEvaluatorTypes::oMultiply) {
if (opers[j] != QPIEvaluatorTypes::oDivide && opers[j] != QPIEvaluatorTypes::oMultiply) continue;
} else {
if (opers[j] != coper) continue;
}
if (!opv.contains(opers[j])) continue;
atmp.clear();
if (j < args.size() && j >= 0) atmp.push_back(args[j]);
else atmp.push_back(-666);
@@ -834,6 +833,22 @@ QString QPIEvaluator::operationChar(const QPIEvaluatorTypes::Operation & operati
}
void QPIEvaluator::operationsByPriority(int p, QVector<QPIEvaluatorTypes::Operation> & ret) {
ret.clear();
switch (p) {
case 0: ret << QPIEvaluatorTypes::oPower; break;
case 1: ret << QPIEvaluatorTypes::oMultiply << QPIEvaluatorTypes::oDivide << QPIEvaluatorTypes::oResidue; break;
case 2: ret << QPIEvaluatorTypes::oAdd << QPIEvaluatorTypes::oSubtract; break;
case 3: ret << QPIEvaluatorTypes::oEqual << QPIEvaluatorTypes::oNotEqual
<< QPIEvaluatorTypes::oGreaterEqual << QPIEvaluatorTypes::oSmallerEqual
<< QPIEvaluatorTypes::oGreater << QPIEvaluatorTypes::oSmaller; break;
case 4: ret << QPIEvaluatorTypes::oAnd; break;
case 5: ret << QPIEvaluatorTypes::oOr; break;
default: break;
}
}
inline complexd QPIEvaluator::residue(const complexd & f, const complexd & s) {
complexd ret;
if (s.real() != 0.) ret = complexd(f.real() - ((int)(f.real() / s.real())) * s.real(), 0.);

View File

@@ -186,6 +186,7 @@ private:
bool check();
bool execInstructions();
QString operationChar(const QPIEvaluatorTypes::Operation & operation);
void operationsByPriority(int p, QVector<QPIEvaluatorTypes::Operation> & ret);
QPIEvaluatorTypes::Operation operationInOrder(const int & index);
complexd value(const int & index) {if (index < 0) return tmpvars[-index - 1].value; else return kvars->at(index).value;}
inline complexd residue(const complexd & f, const complexd & s);