gm3p/include/gm3p_int.hpp

63 lines
1.4 KiB
C++
Raw Normal View History

2020-07-18 21:06:17 +02:00
#pragma once
#include <iostream>
2020-07-18 21:06:17 +02:00
#include "gmp.h"
namespace gm3p
{
2020-07-19 17:01:23 +02:00
/**
* A wrapper for mpz_t
*/
2020-07-18 21:06:17 +02:00
class gInt
{
public:
// CONSTRUCTORS
2020-07-18 21:06:17 +02:00
gInt();
gInt(mpz_t init);
2020-07-19 02:06:36 +02:00
gInt(mpq_t init);
gInt(mpf_t init);
2020-07-18 21:06:17 +02:00
gInt(long int init);
2020-07-19 17:01:23 +02:00
gInt(const char* init, int base = 10);
2020-07-19 02:06:36 +02:00
// DESTRUCTOR
2020-07-18 21:06:17 +02:00
~gInt();
2020-07-19 02:06:36 +02:00
// ASSIGNMENT/COPY OPERATORS
2020-07-18 21:06:17 +02:00
gInt& operator=(const gInt& other);
2020-07-19 02:06:36 +02:00
gInt(const gInt& other);
gInt(gInt&& other);
2020-07-18 21:06:17 +02:00
// ARITHMETIC OPERATORS
2020-07-19 17:01:23 +02:00
friend gInt operator-(const gInt& value);
2020-07-18 21:06:17 +02:00
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);
2020-07-19 17:01:23 +02:00
friend gInt Mul2Exp(const gInt& value, const mp_bitcnt_t& exp);
friend gInt Neg(const gInt& value);
friend gInt Abs(const gInt& value);
2020-07-19 02:06:36 +02:00
// CONVERSION OPERATORS
operator long int() const;
2020-07-19 17:01:23 +02:00
operator mpz_t&();
2020-07-19 02:06:36 +02:00
unsigned long int ToUnsigned() const;
char* ToString(char* buf, int base) const;
double ToDouble() const;
double ToDouble(long int* exp) const;
// STDIO OPERATORS
2020-07-18 21:06:17 +02:00
friend std::ostream& operator<<(std::ostream& os, const gInt& value);
private:
mpz_t value;
};
}