From 039d0d6757925f368158bf3e5026d4dd4106130b Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 29 May 2022 14:55:16 +0300 Subject: Autocommit at 29.05.2022 @ 14:55 --- src/Models/CellFormula.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/Models/CellFormula.cpp') 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 #include +#include 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>* tableCells) : #include double CellFormula::getNumeralValue() { - return calculate(); + try { + return calculate(); + } + catch (std::logic_error) { + return 0; + } } String CellFormula::getValueForPrint() { -- cgit v1.3.1-23-gd82d