Added more operations and install statements
This commit is contained in:
parent
95282f7d1a
commit
97125eaf07
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,5 +1,7 @@
|
|||
.vs
|
||||
.vscode
|
||||
out
|
||||
build
|
||||
3rdparty
|
||||
|
||||
*.json
|
|
@ -1,6 +1,6 @@
|
|||
cmake_minimum_required (VERSION 3.8)
|
||||
|
||||
project ("GM3p")
|
||||
project ("gm3p" CXX)
|
||||
|
||||
set(GMP_INCLUDE_DIR "" CACHE PATH "Path to the directory containing 'gmp.h'")
|
||||
|
||||
|
@ -28,4 +28,7 @@ target_link_libraries(gm3p PUBLIC
|
|||
# Include sub-projects.
|
||||
if(ENABLE_TEST_PROJ)
|
||||
add_subdirectory(testapp)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
install(TARGETS gm3p DESTINATION lib)
|
||||
install(DIRECTORY include DESTINATION .)
|
|
@ -1,4 +1,3 @@
|
|||
#pragma once
|
||||
#include <iostream>
|
||||
|
||||
#include "gm3p_int.hpp"
|
|
@ -1,5 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "gmp.h"
|
||||
|
||||
namespace gm3p
|
||||
|
@ -7,19 +9,28 @@ namespace gm3p
|
|||
class gInt
|
||||
{
|
||||
public:
|
||||
// CONSTRUCTORS
|
||||
gInt();
|
||||
gInt(mpz_t init);
|
||||
gInt(unsigned long int init);
|
||||
gInt(long int init);
|
||||
gInt(const char* init, int base);
|
||||
~gInt();
|
||||
|
||||
// ASSIGNMENT OPERATORS
|
||||
gInt& operator=(const gInt& other);
|
||||
|
||||
// ARITHMETIC OPERATORS
|
||||
friend gInt operator+(const gInt& left, const gInt& right);
|
||||
friend gInt operator-(const gInt& left, const gInt& right);
|
||||
friend gInt operator*(const gInt& left, const gInt& right);
|
||||
friend gInt operator/(const gInt& left, const gInt& right);
|
||||
|
||||
gInt& operator+=(const gInt& right);
|
||||
gInt& operator-=(const gInt& right);
|
||||
gInt& operator*=(const gInt& right);
|
||||
gInt& operator/=(const gInt& right);
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& os, const gInt& value);
|
||||
|
||||
private:
|
||||
|
|
|
@ -13,6 +13,12 @@ namespace gm3p
|
|||
mpz_set(value, init);
|
||||
}
|
||||
|
||||
gInt::gInt(unsigned long int init) :
|
||||
gInt::gInt()
|
||||
{
|
||||
mpz_set_ui(value, init);
|
||||
}
|
||||
|
||||
gInt::gInt(long int init) :
|
||||
gInt::gInt()
|
||||
{
|
||||
|
@ -30,11 +36,16 @@ namespace gm3p
|
|||
mpz_clear(value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
gInt& gInt::operator=(const gInt& other)
|
||||
{
|
||||
mpz_set(this->value, other.value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
gInt operator+(const gInt& left, const gInt& right)
|
||||
{
|
||||
gInt ret;
|
||||
|
@ -62,6 +73,34 @@ namespace gm3p
|
|||
mpz_div(ret.value, left.value, right.value);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
gInt& gInt::operator+=(const gInt& right)
|
||||
{
|
||||
mpz_add(value, value, right.value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
gInt& gInt::operator-=(const gInt& right)
|
||||
{
|
||||
mpz_sub(value, value, right.value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
gInt& gInt::operator*=(const gInt& right)
|
||||
{
|
||||
mpz_mul(value, value, right.value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
gInt& gInt::operator/=(const gInt& right)
|
||||
{
|
||||
mpz_div(value, value, right.value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const gInt& value)
|
||||
{
|
||||
static char* buf;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "gm3p.hpp"
|
||||
|
||||
#include <iostream>
|
||||
//#include <iostream>
|
||||
|
||||
using namespace gm3p;
|
||||
|
||||
|
|
Loading…
Reference in a new issue