From 5f866c4a4b44d39b827a99d82006fa2d375c0ba9 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Sun, 11 Aug 2013 08:02:17 +0200 Subject: Adding BigInts, based off libtomcrypto / libtommath. --- includes/BigInt.h | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 includes/BigInt.h (limited to 'includes/BigInt.h') diff --git a/includes/BigInt.h b/includes/BigInt.h new file mode 100644 index 0000000..a74df6e --- /dev/null +++ b/includes/BigInt.h @@ -0,0 +1,80 @@ +#pragma once + +#include +#include +#include + +namespace Balau { + +class BigInt { + public: + BigInt() throw(GeneralException); + BigInt(const BigInt &) throw (GeneralException); + BigInt(BigInt &&); + ~BigInt(); + + BigInt & operator=(const BigInt &) throw (GeneralException); + + void set(uint64_t) throw (GeneralException); + void set(int64_t); + void set(uint32_t) throw (GeneralException); + void set(int32_t); + void set(double) throw (GeneralException); + void set(const String &, int radix = 10) throw (GeneralException); + void set2expt(int i) throw (GeneralException); + + BigInt operator+(unsigned int) const throw (GeneralException); + BigInt operator+(const BigInt &) const throw (GeneralException); + BigInt operator-(unsigned int) const throw (GeneralException); + BigInt operator-(const BigInt &) const throw (GeneralException); + BigInt operator*(unsigned int) const throw (GeneralException); + BigInt operator*(const BigInt &) const throw (GeneralException); + BigInt operator/(const BigInt &) const throw (GeneralException); + BigInt operator%(const BigInt &) const throw (GeneralException); + BigInt operator<<(unsigned int) const throw (GeneralException); + BigInt operator>>(unsigned int) const; + + BigInt & operator+=(unsigned int) throw (GeneralException); + BigInt & operator+=(const BigInt &) throw (GeneralException); + BigInt & operator-=(unsigned int) throw (GeneralException); + BigInt & operator-=(const BigInt &) throw (GeneralException); + BigInt & operator*=(unsigned int) throw (GeneralException); + BigInt & operator*=(const BigInt &) throw (GeneralException); + BigInt & operator/=(const BigInt &) throw (GeneralException); + BigInt & operator%=(const BigInt &) throw (GeneralException); + BigInt & operator<<=(unsigned int) throw (GeneralException); + BigInt & operator>>=(unsigned int); + + BigInt operator-() const throw (GeneralException); + + BigInt & operator++(); + BigInt operator++(int); + BigInt & operator--(); + BigInt operator--(int); + + enum comp_t { LT, GT, EQ }; + comp_t comp(const BigInt &) const throw (GeneralException); + + BigInt & neg() throw (GeneralException); + + BigInt sqrt() const throw (GeneralException); + BigInt & do_sqrt() throw (GeneralException); + + BigInt gcd(const BigInt &) const throw (GeneralException); + BigInt lcm(const BigInt &) const throw (GeneralException); + + bool operator==(const BigInt &) const; + bool operator!=(const BigInt &) const; + bool operator<=(const BigInt &) const; + bool operator>=(const BigInt &) const; + bool operator<(const BigInt &) const; + bool operator>(const BigInt &) const; + + String toString(int radix = 10) const; + char * makeString(int radix = 10) const; + + private: + void * m_bi = NULL; +}; + +}; -- cgit v1.2.3