big int
This commit is contained in:
49
include/BigInt.h
Normal file
49
include/BigInt.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <gmp.h>
|
||||
|
||||
/**
|
||||
* \class BigInt
|
||||
* \brief Représente un entier d'une taille quelconque
|
||||
* \warning Prend énormément de place en mémoire. À utiliser avec précaution !
|
||||
*/
|
||||
class BigInt {
|
||||
private:
|
||||
mpz_t m_Data;
|
||||
|
||||
public:
|
||||
BigInt(std::string&& a_Number);
|
||||
|
||||
BigInt(long a_Number = 0);
|
||||
|
||||
BigInt(const BigInt& a_Copy);
|
||||
|
||||
BigInt(BigInt&& a_Move);
|
||||
|
||||
~BigInt();
|
||||
|
||||
BigInt operator+(const BigInt& a_Other);
|
||||
|
||||
BigInt operator-(const BigInt& a_Other);
|
||||
|
||||
BigInt operator*(const BigInt& a_Other);
|
||||
|
||||
BigInt operator/(const BigInt& a_Other);
|
||||
|
||||
BigInt operator+=(const BigInt& a_Other);
|
||||
|
||||
BigInt operator-=(const BigInt& a_Other);
|
||||
|
||||
BigInt operator*=(const BigInt& a_Other);
|
||||
|
||||
BigInt operator/=(const BigInt& a_Other);
|
||||
|
||||
bool operator==(const BigInt& a_Other);
|
||||
|
||||
void operator=(const BigInt& a_Other);
|
||||
|
||||
const std::string ToString() const;
|
||||
|
||||
bool IsEqualZero() const;
|
||||
};
|
||||
@@ -10,10 +10,14 @@
|
||||
class Matrix;
|
||||
class Vect;
|
||||
class VectAffine;
|
||||
class BigInt;
|
||||
|
||||
std::ostream& operator<<(std::ostream& stream, const Matrix& mat);
|
||||
std::istream& operator>>(std::istream& stream, Matrix& mat);
|
||||
|
||||
std::ostream& operator<<(std::ostream& stream, const BigInt& nbre);
|
||||
std::istream& operator>>(std::istream& stream, BigInt& nbre);
|
||||
|
||||
/**
|
||||
* \brief Charge une matrice à partir d'un fichier
|
||||
* \param fileName Le chemin du fichier à charger
|
||||
|
||||
@@ -10,13 +10,15 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "BigInt.h"
|
||||
|
||||
/**
|
||||
* \class Matrix
|
||||
* \brief Représente une matrice d'éléments
|
||||
*/
|
||||
class Matrix {
|
||||
public:
|
||||
typedef long double Element;
|
||||
typedef BigInt Element;
|
||||
typedef std::vector<Element>::iterator iterator;
|
||||
|
||||
private:
|
||||
@@ -154,6 +156,21 @@ class Matrix {
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
bool IsEqualZero(T var) {
|
||||
bool IsEqualZero(const T& var) {
|
||||
return std::abs(var) < std::pow(10, -5);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool IsEqualZero(const int& var) {
|
||||
return var == 0;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool IsEqualZero(const long& var) {
|
||||
return var == 0;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool IsEqualZero(const BigInt& var) {
|
||||
return var.IsEqualZero();
|
||||
}
|
||||
Reference in New Issue
Block a user