From ddeae250bc6661daafb25ae07f8c2e01b53b0d44 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Sat, 8 Oct 2016 11:58:59 +0200 Subject: Improve bigint division depth estimate --- bigint.cpp | 15 +++++++++------ bigint.h | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/bigint.cpp b/bigint.cpp index 72a882b..3a36f12 100644 --- a/bigint.cpp +++ b/bigint.cpp @@ -325,7 +325,10 @@ Bigint Bigint::operator>>(int sh) const { int depthrecord; pair Bigint::divmod(const Bigint &div) const { - pair res=divmod(div,1); + // cerr<<"divmod("< res=divmod(div,1,bitcdiff/29+10); //cerr< "< Bigint::divmod(const Bigint &div,int depth) const { - if(depth>100)assert(false); - //cerr<<"divmod("< Bigint::divmod(const Bigint &div,int depth) const { }*/ Bigint rest(*this); rest-=guess; //also correct for *this and guess negative - pair dm=rest.divmod(div,depth+1); + pair dm=rest.divmod(div,depth+1,maxdepth); dm.first+=quotient; return dm; } @@ -454,7 +457,7 @@ pair Bigint::divmod(const Bigint &div,int depth) const { if(cmp==0){record(depth); return make_pair(quotient,Bigint::zero);} Bigint rest(*this); rest-=guess; - pair dm=rest.divmod(div,depth+1); + pair dm=rest.divmod(div,depth+1,maxdepth); dm.first+=quotient; return dm; } diff --git a/bigint.h b/bigint.h index 4d6c980..02f3da3 100644 --- a/bigint.h +++ b/bigint.h @@ -26,7 +26,7 @@ private: void normalise(); void checkconsistent(); - std::pair divmod(const Bigint&,int depth) const; + std::pair divmod(const Bigint&,int depth,int maxdepth) const; public: Bigint(); -- cgit v1.2.3-54-g00ecf