From d24ab714b958b9fece4631076e240739ad0dd23f Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Mon, 3 Oct 2016 22:15:25 +0200 Subject: Progress --- bigint.cpp | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 89 insertions(+), 17 deletions(-) (limited to 'bigint.cpp') diff --git a/bigint.cpp b/bigint.cpp index 5182d07..644ffb3 100644 --- a/bigint.cpp +++ b/bigint.cpp @@ -7,6 +7,10 @@ using namespace std; +Bigint Bigint::zero(0); +Bigint Bigint::one(1); +Bigint Bigint::mone(-1); + Bigint::Bigint() :sign(1){} @@ -163,6 +167,11 @@ Bigint& Bigint::operator*=(const Bigint &o){ return *this; } +//TODO: optimise these functions +Bigint& Bigint::operator+=(slongdigit_t n){return *this+=Bigint(n);} +Bigint& Bigint::operator-=(slongdigit_t n){return *this-=Bigint(n);} +Bigint& Bigint::operator*=(slongdigit_t n){return *this*=Bigint(n);} + Bigint& Bigint::operator<<=(int sh){ if(sh==0)return *this; if(digits.size()==0)return *this; @@ -233,12 +242,26 @@ Bigint Bigint::operator*(const Bigint &o) const { return product(*this,o); } +//TODO: optimise these functions +Bigint Bigint::operator+(slongdigit_t n) const {return *this+Bigint(n);} +Bigint Bigint::operator-(slongdigit_t n) const {return *this-Bigint(n);} +Bigint Bigint::operator*(slongdigit_t n) const {return *this*Bigint(n);} + +Bigint Bigint::operator<<(int sh) const { + return Bigint(*this)<<=sh; +} + +Bigint Bigint::operator>>(int sh) const { + return Bigint(*this)>>=sh; +} + int depthrecord; pair Bigint::divmod(const Bigint &div) const { pair res=divmod(div,1); //cerr< "< Bigint::divmod(const Bigint &div,int depth) const { - //cerr<<"divmod("<100)assert(false); + //cerr<<"divmod("< Bigint::divmod(const Bigint &div,int depth) const { //cerr<<"guess="< Bigint::divmod(const Bigint &div,int depth) const { longdigit_t factor=((longdigit_t)1<