39 const std::map<utils::Equation, double>& variables) {
41 std::vector<utils::Equation> eq;
52 static_cast<int>(wholeEq.size()) + 1);
55 for (
size_t i = 0; i < symbols.size(); ++i) {
56 int idx =
static_cast<int>(wholeEq.find(symbols[i]));
66 if (toStop == symbols.size()) {
67 eq.push_back(wholeEq);
70 if (wholeEq.size() == 1) {
71 eq.push_back(wholeEq(0));
74 if (firstIdx + 1 ==
static_cast<int>(wholeEq.size())) {
75 eq.push_back(wholeEq.substr(0,
static_cast<size_t>(firstIdx)));
76 eq.push_back(wholeEq(
static_cast<size_t>(firstIdx)));
78 }
else if (firstIdx == 0) {
79 if (!wholeEq(0).compare(
"-")) {
81 std::vector<utils::Equation> tp(
83 if (eq.size() != 0 && !eq[eq.size() - 1].compare(
"e")) {
85 eq.push_back(wholeEq(0));
86 wholeEq = wholeEq.substr(1);
87 }
else if (!tp[0].compare(
"(")) {
89 size_t idx = wholeEq.find_first_of(
")");
93 wholeEq =
to_string(res) + wholeEq.substr(idx + 1);
96 eq.insert(eq.end(), tp.begin(), tp.end());
99 }
else if (!wholeEq(0).compare(
"+")) {
101 std::vector<utils::Equation> tp(
107 eq.insert(eq.end(), tp.begin(), tp.end());
110 eq.push_back(wholeEq(0));
111 wholeEq = wholeEq.substr(1);
114 eq.push_back(wholeEq.substr(
115 0,
static_cast<size_t>(firstIdx)));
116 eq.push_back(wholeEq(
static_cast<size_t>(firstIdx)));
117 wholeEq = wholeEq.substr(
118 static_cast<size_t>(firstIdx) +
154 std::vector<Equation> eq,
157 if (eq.size() == 1) {
163 std::vector<utils::Equation> eq2;
164 bool continuer(
true);
166 for (
size_t j = 0; j < eq.size(); ++j) {
167 if (!eq[j].compare(symbols[math]) && continuer) {
169 (!symbols[math].compare(
"+") || !symbols[math].compare(
"-"))) {
171 if (!symbols[math].compare(
"+")) {
172 eq2[j - 1] =
to_string(0.0 + stod(eq[j + 1]));
173 }
else if (!symbols[math].compare(
"-")) {
174 eq2[j - 1] =
to_string(0.0 - stod(eq[j + 1]));
178 if (!symbols[math].compare(
"(")) {
179 std::vector<utils::Equation> eq_tp;
180 bool foundIdx(
false);
183 for (
size_t k = j + 1; k < eq.size(); ++k) {
184 if (!eq[k].compare(
"(")) {
186 }
else if (!eq[k].compare(
")")) {
195 eq_tp.push_back(eq[k]);
201 j +=
static_cast<size_t>(cmpValues);
202 }
else if (!symbols[math].compare(
"/")) {
203 eq2[j - 1] =
to_string(stod(eq[j - 1]) / stod(eq[j + 1]));
204 }
else if (!symbols[math].compare(
"*")) {
205 eq2[j - 1] =
to_string(stod(eq[j - 1]) * stod(eq[j + 1]));
206 }
else if (!symbols[math].compare(
"+")) {
207 eq2[j - 1] =
to_string(stod(eq[j - 1]) + stod(eq[j + 1]));
208 }
else if (!symbols[math].compare(
"-")) {
209 eq2[j - 1] =
to_string(stod(eq[j - 1]) - stod(eq[j + 1]));
210 }
else if (!symbols[math].compare(
"e")) {
211 if (!eq[j + 1].compare(
"-")) {
213 to_string(stod(eq[j - 1]) * pow(10, -1 * stod(eq[j + 2])));
215 }
else if (!eq[j + 1].compare(
"+")) {
216 eq2[j - 1] =
to_string(stod(eq[j - 1]) * pow(10, stod(eq[j + 2])));
219 eq2[j - 1] =
to_string(stod(eq[j - 1]) * pow(10, stod(eq[j + 1])));
228 eq2.push_back(eq[j]);
static std::vector< Equation > splitIntoEquation(Equation wholeEq, const std::map< Equation, double > &variables)
Split equation into smaller parts, down to number or math symbols.