diff options
Diffstat (limited to 'bigint.cpp')
-rw-r--r-- | bigint.cpp | 24 |
1 files changed, 20 insertions, 4 deletions
@@ -16,8 +16,15 @@ Bigint Bigint::two(2); Bigint::Bigint() :sign(1){} +Bigint::Bigint(Bigint &&o) + :digits(move(o.digits)),sign(o.sign){ + o.normalise(); + checkconsistent(); +} + Bigint::Bigint(const string &repr){ stringstream(repr)>>*this; + checkconsistent(); } Bigint::Bigint(slongdigit_t v) @@ -145,6 +152,15 @@ void Bigint::checkconsistent(){ assert(digits.size()!=0||sign==1); } +Bigint& Bigint::operator=(Bigint &&o){ + sign=o.sign; + digits=move(o.digits); + o.normalise(); + normalise(); + checkconsistent(); + return *this; +} + Bigint& Bigint::operator=(slongdigit_t v){ digits.clear(); if(v==0){ @@ -498,21 +514,21 @@ string Bigint::serialiseMantissa() const { int sz=digits.size(); for(int i=0;i<sz;i++){ for(int j=0;j<(int)sizeof(digit_t);j++){ - s[i*sizeof(digit_t)+j]=(digits[i]>>(8*j))&255; + s[i*sizeof(digit_t)+j]=(digits[i]>>(8*j))&0xff; } } return s; } void Bigint::deserialiseMantissa(const string &s){ - assert(s.size()%4==0); + assert(s.size()%sizeof(digit_t)==0); sign=1; - int sz=s.size()/4; + int sz=s.size()/sizeof(digit_t); digits.resize(sz); for(int i=0;i<sz;i++){ digits[i]=0; for(int j=0;j<(int)sizeof(digit_t);j++){ - digits[i]|=s[i*sizeof(digit_t)+j]<<(8*j); + digits[i]|=(uint8_t)s[i*sizeof(digit_t)+j]<<(8*j); } } shrink(); |