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