Compare commits
No commits in common. "bd9976fb6fa8f02876d89ca3d6a957bff7d2df48" and "c1b63ea2de8df54f40667fb1383fabcea71237c0" have entirely different histories.
bd9976fb6f
...
c1b63ea2de
3 changed files with 7 additions and 31 deletions
|
@ -23,7 +23,7 @@ enum SymbolType {
|
|||
*/
|
||||
struct Symbol {
|
||||
SymbolType type = SymbolType::number;
|
||||
long double value = 0;
|
||||
double value = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -317,7 +317,7 @@ Symbol calculateUsingStack(std::vector<Symbol>& _stack) {
|
|||
struct parseAndCalculateResult {
|
||||
int unmatchedParanthesis = 0;
|
||||
bool valid = true;
|
||||
long double value = 0;
|
||||
double value = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
11
src/main.cpp
11
src/main.cpp
|
@ -1,12 +1,11 @@
|
|||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include "calculator.cpp"
|
||||
#include "commands.cpp"
|
||||
#include "cursor.cpp"
|
||||
#include "debug.cpp"
|
||||
#include "getch.h"
|
||||
#include "terminal.cpp"
|
||||
#include "utils.cpp"
|
||||
#include "calculator.cpp" //doesn't compile when sorted alphabetically, why??
|
||||
|
||||
/**
|
||||
* @brief Prints entered keys to the console.
|
||||
|
@ -77,7 +76,9 @@ void writeResultLine(
|
|||
* @param inputSize the current input size (used to where display missing paranthesis)
|
||||
*/
|
||||
void writeResultLine(Calculator::parseAndCalculateResult result, const unsigned int inputSize) {
|
||||
writeResultLine(doubleToString(result.value, 10), result.unmatchedParanthesis, result.valid, inputSize);
|
||||
std::stringstream result_string;
|
||||
result_string << result.value;
|
||||
writeResultLine(result_string.str(), result.unmatchedParanthesis, result.valid, inputSize);
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
@ -92,8 +93,6 @@ int main() {
|
|||
}
|
||||
#endif
|
||||
std::setlocale(LC_ALL, "");
|
||||
std::cout << "type your equation to calculate,\n";
|
||||
std::cout << "press enter to enter a new one\n";
|
||||
std::cout << "type :q to exit, type :h for help\n";
|
||||
|
||||
bool exit = false; //should we exit?
|
||||
|
@ -130,7 +129,7 @@ int main() {
|
|||
terminal::key_backspace(keys);
|
||||
break;
|
||||
case 13: // ENTER
|
||||
std::cout << "\n\033[2K" << doubleToString(Calculator::parseAndCaluclate(keys.keys, true).value, -1) << "\n";
|
||||
std::cout << "\n\033[2K" << Calculator::parseAndCaluclate(keys.keys, true).value << "\n";
|
||||
keys.cursorPos = 0;
|
||||
keys.keys.clear();
|
||||
break;
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
#ifndef __UTILS_CPP
|
||||
#define __UTILS_CPP
|
||||
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <limits>
|
||||
|
||||
/**
|
||||
* @brief converts double to string
|
||||
*
|
||||
* @param from the double to convert
|
||||
* @param precision what precision the stringed version should be
|
||||
* @return std::string the converted number
|
||||
*/
|
||||
std::string doubleToString(const long double& from, const int& precision = 10) {
|
||||
std::stringstream theStream;
|
||||
if (precision < 0) theStream << std::setprecision(std::numeric_limits<double>::digits10+1);
|
||||
else theStream << std::setprecision(precision);
|
||||
theStream << from;
|
||||
return theStream.str();
|
||||
}
|
||||
|
||||
#endif
|
Reference in a new issue