Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Models / CellFormula.cpp
diff options
context:
space:
mode:
Commit9d14ce521793ce471e6d8ac10bcdd0663c268e2c (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-05-28 19:59:56 +0300
Committer
 Syndamia <kamen@syndamia.com>
2022-05-28 19:59:56 +0300
Files044478279d1d5ab8547509d1806581f9dd89653d /src/Models/CellFormula.cpp
FMI-OOP-P2_Tables-9d14ce521793ce471e6d8ac10bcdd0663c268e2c.tar
FMI-OOP-P2_Tables-9d14ce521793ce471e6d8ac10bcdd0663c268e2c.tar.gz
FMI-OOP-P2_Tables-9d14ce521793ce471e6d8ac10bcdd0663c268e2c.zip
Parent63a04433aaf4585181598f10398e41dc9801292e (diff)
Autocommit at 28.05.2022 @ 19:59
1 files changed, 13 insertions, 6 deletions
-rw-r--r--src/Models/CellFormula.cpp19
diff --git a/src/Models/CellFormula.cpp b/src/Models/CellFormula.cpp
index 7ff8c9f..1a340e5 100644
--- a/src/Models/CellFormula.cpp
+++ b/src/Models/CellFormula.cpp
@@ -2,21 +2,28 @@
#include "CellDouble.h"
#include <cstring>
-CellFormula::CellFormula(const char* str, const List<List<Cell*>>* tableCells) : referencedCells(), formula(), rawFormula() {
+CellFormula::CellFormula(const char* str, const List<List<Cell*>>* tableCells) : localCells(), formula(), rawFormula() {
this->tableCells = tableCells;
parseAndSetValue(str);
}
+double pow(double x, unsigned y) {
+ double res = x;
+ for (unsigned i = 1; i < y; i++)
+ res *= res;
+ return res;
+}
+
double CellFormula::calculate(unsigned index) {
double lval = formula[index].left->getNumeralValue();
if (formula[index].right < 0) {
switch (-formula[index++].right) {
- case '+' : lval += formula[index].left->getNumeralValue(); break;
- case '-' : lval -= formula[index].left->getNumeralValue(); break;
- case '*' : lval *= formula[index].left->getNumeralValue(); break;
- case '/' : lval /= formula[index].left->getNumeralValue(); break;
- // case pow : lval += formula[index].left->getNumeralValue(); break;
+ case '+' : lval += formula[index].left->getNumeralValue(); break;
+ case '-' : lval -= formula[index].left->getNumeralValue(); break;
+ case '*' : lval *= formula[index].left->getNumeralValue(); break;
+ case '/' : lval /= formula[index].left->getNumeralValue(); break;
+ case '^' : lval = pow(lval, formula[index].left->getNumeralValue()); break;
}
}