diff --git a/Makefile b/Makefile index 8a6146d..460a889 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,20 @@ PROJECT= resume SOURCES= src/cheapgmp.cpp src/accessories.cpp MAINSRC= src/main.cpp +CMDSRC= src/cmd.cpp TESTSOURCES= tests/test_cheapgmp.cpp LDFLAGS= TESTLDFLAGS= -laeryn_tests -laeryn_core CFLAGS= -c -Wall -std=c++11 CPLUSPLUS= g++ BINARY=cheapgmp +CMD=gmpcmd TESTBINARY=testrunner OBJECTS=$(SOURCES:.cpp=.o) TESTOBJECTS=$(TESTSOURCES:.cpp=.o) MAINOBJECTS=$(MAINSRC:.cpp=.o) +CMDOBJECTS=$(CMDSRC:.cpp=.o) all: $(SOURCES) $(BINARY) @@ -20,6 +23,9 @@ $(BINARY): $(OBJECTS) $(MAINOBJECTS) app: $(BINARY) +gmpcmd: $(CMDOBJECTS) $(OBJECTS) + $(CPLUSPLUS) $(OBJECTS) $(CMDOBJECTS) $(LDFLAGS) -o $@ + testrunner: $(OBJECTS) $(TESTOBJECTS) $(CPLUSPLUS) $(OBJECTS) $(TESTOBJECTS) $(LDFLAGS) $(TESTLDFLAGS) -o $@ @@ -30,7 +36,7 @@ test: $(BINARY) ./$(BINARY) distclean: clean - rm -f $(BINARY) + rm -f $(BINARY) $(TESTBINARY) $(CMD) clean: - rm -f $(OBJECTS) + rm -f $(OBJECTS) $(TESTOBJECTS) $(MAINOBJECTS) $(CMDOBJECTS) diff --git a/src/cheapgmp.cpp b/src/cheapgmp.cpp index 30e66e6..a4252bb 100644 --- a/src/cheapgmp.cpp +++ b/src/cheapgmp.cpp @@ -11,7 +11,6 @@ namespace cheapgmp { as a carryover to the 10^(n+1) slot */ void multiply(gmrep &multiplicand, ulong multiplier) { - gmrep res(new lmrep()); ulong rem = 0; for_each(multiplicand->rbegin(), multiplicand->rend(), [&rem, multiplier](ulong &i) { ulong t = (i * multiplier) + rem ; @@ -56,7 +55,7 @@ namespace cheapgmp { return makerep(base == 0 ? 0 : 1); } - gmrep res = makerep(base); + auto res = makerep(base); ulong ct = power; while(ct > 1) { multiply(res, base); diff --git a/src/cmd.cpp b/src/cmd.cpp new file mode 100644 index 0000000..b17b9a7 --- /dev/null +++ b/src/cmd.cpp @@ -0,0 +1,30 @@ +#include +#include +#include +#include "cheapgmp.hpp" +#include "accessories.hpp" + +using namespace cheapgmp; +using namespace std; + +ulong reverse(ulong in) { + ulong rev = 0; + for(; in != 0; ) { + rev = (rev * 10) + (in % 10); + in = in / 10; + } + return rev; +} + +int main(int argc, char* argv[]) { + ulong in; + istringstream ss(argv[1]); + if (!(ss >> in)) { + cerr << "Invalid number " << argv[1] << '\n'; + exit(1); + } + + wstring s2 = tostring(makepower(in, (reverse(in)))); + std::wcout << s2 << endl; +} + diff --git a/src/main.cpp b/src/main.cpp index b75f38e..b78fff7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,6 @@ #include #include "cheapgmp.hpp" +#include "accessories.hpp" using namespace cheapgmp; using namespace std;