diff --git a/Makefile b/Makefile index aaba07b49..ac199be58 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,7 @@ OBJECTS = src/checkautovariables.o \ src/errorlogger.o \ src/filelister.o \ src/main.o \ + src/mathlib.o \ src/preprocessor.o \ src/settings.o \ src/threadexecutor.o \ @@ -65,6 +66,7 @@ TESTOBJ = test/testautovariables.o \ src/cppcheckexecutor.o \ src/errorlogger.o \ src/filelister.o \ + src/mathlib.o \ src/preprocessor.o \ src/settings.o \ src/threadexecutor.o \ @@ -148,7 +150,10 @@ src/filelister.o: src/filelister.cpp src/filelister.h src/main.o: src/main.cpp src/cppcheckexecutor.h src/errorlogger.h src/settings.h $(CXX) $(CXXFLAGS) -c -o src/main.o src/main.cpp -src/preprocessor.o: src/preprocessor.cpp src/preprocessor.h src/tokenize.h src/settings.h src/errorlogger.h src/token.h +src/mathlib.o: src/mathlib.cpp + $(CXX) $(CXXFLAGS) -c -o src/mathlib.o src/mathlib.cpp + +src/preprocessor.o: src/preprocessor.cpp src/preprocessor.h src/errorlogger.h src/settings.h src/tokenize.h src/token.h $(CXX) $(CXXFLAGS) -c -o src/preprocessor.o src/preprocessor.cpp src/settings.o: src/settings.cpp src/settings.h diff --git a/src/mathlib.cpp b/src/mathlib.cpp new file mode 100644 index 000000000..27decadc6 --- /dev/null +++ b/src/mathlib.cpp @@ -0,0 +1,90 @@ +#include "mathLib.h" + + +#include +#include +#include +#include +#include +#include +#include + +double MathLib::ToNumber(const std::string &str) +{ + return atof(str.c_str()); +} + +std::string MathLib::ToString(double d) +{ + std::ostringstream result; + result< ToNumber(second); +} + +bool MathLib::IsEqual(const std::string &first, const std::string &second) +{ + return ToNumber(first) == ToNumber(second); +} + +bool MathLib::IsLess(const std::string &first, const std::string &second) +{ + return ToNumber(first) < ToNumber(second); +} + +int MathLib::compare(const std::string &first, const std::string &second) +{ + if(ToNumber(first) < ToNumber(second)) + return -1; + if(ToNumber(first) == ToNumber(second)) + return 0; + return 1; +} + diff --git a/src/mathlib.h b/src/mathlib.h new file mode 100644 index 000000000..bfa74d0e8 --- /dev/null +++ b/src/mathlib.h @@ -0,0 +1,20 @@ +#include "token.h" +class MathLib +{ +private: + static double ToNumber(const std::string & str); + static std::string ToString(double d); +public: + static std::string add(const std::string & first, const std::string & second); + static std::string substract(const std::string & first, const std::string & second); + static std::string multiply(const std::string & first, const std::string & second); + static std::string divide(const std::string & first, const std::string & second); + static std::string sin(const std::string & tok); + static std::string cos(const std::string & tok); + static std::string tan(const std::string & tok); + static std::string abs(const std::string & tok); + static bool IsGreater (const std::string & first, const std::string & second); + static bool IsEqual (const std::string & first, const std::string & second); + static bool IsLess (const std::string & first, const std::string & second); + static int compare(const std::string & first, const std::string & second); +}; \ No newline at end of file