Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Models / CellFormula.cpp
diff options
context:
space:
mode:
Commit039d0d6757925f368158bf3e5026d4dd4106130b (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-05-29 14:55:16 +0300
Committer
 Syndamia <kamen@syndamia.com>
2022-05-29 14:55:16 +0300
Files60e61a8a236f308ab86c71177a85e9de5ac7aedf /src/Models/CellFormula.cpp
FMI-OOP-P2_Tables-039d0d6757925f368158bf3e5026d4dd4106130b.tar
FMI-OOP-P2_Tables-039d0d6757925f368158bf3e5026d4dd4106130b.tar.gz
FMI-OOP-P2_Tables-039d0d6757925f368158bf3e5026d4dd4106130b.zip
Parentcf3abe4c719d08564d06f37933ca984ce72ddc18 (diff)
Autocommit at 29.05.2022 @ 14:55
1 files changed, 9 insertions, 2 deletions
-rw-r--r--src/Models/CellFormula.cpp11
diff --git a/src/Models/CellFormula.cpp b/src/Models/CellFormula.cpp
index 82806eb..20871b8 100644
--- a/src/Models/CellFormula.cpp
+++ b/src/Models/CellFormula.cpp
@@ -2,6 +2,7 @@
#include "CellDouble.h"
#include <cstring>
#include <iostream>
+#include <stdexcept>
double pow(double x, unsigned y) {
if (y == 0) return 1;
@@ -18,7 +19,8 @@ double CellFormula::calculate(unsigned index) {
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 '/' : if (formula[index].left->getNumeralValue() == 0) throw new std::logic_error("");
+ lval /= formula[index].left->getNumeralValue(); break;
case '^' : lval = pow(lval, formula[index].left->getNumeralValue()); break;
}
}
@@ -41,7 +43,12 @@ CellFormula::CellFormula(const char* str, const List<List<Cell*>>* tableCells) :
#include <iostream>
double CellFormula::getNumeralValue() {
- return calculate();
+ try {
+ return calculate();
+ }
+ catch (std::logic_error) {
+ return 0;
+ }
}
String CellFormula::getValueForPrint() {