diff --git a/bitvector.h b/bitvector.h index 34e3aa9..e95e0da 100644 --- a/bitvector.h +++ b/bitvector.h @@ -95,8 +95,10 @@ for(int i=0; i -bitvector mantissa(const T &x, int nbits) +bitvector mantissa(T x, int nbits, int shift=0) { +while(shift >0) {x+=x; --shift;} +while(shift <0) {x*=.5; ++shift;} if(x<0||x>=1) laerror("number not normalized in bitvector mantissa"); bitvector b(nbits); b.clear(); @@ -111,10 +113,12 @@ return b; } template -void bitvector_decimal(T &x, const bitvector &b) +void bitvector_decimal(T &x, const bitvector &b, int shift=0) { x=0; -for(int i=0; i=0; --i) if(b[i]) x += 1./(1ULL<0) {x+=x; --shift;} +while(shift <0) {x*=.5; ++shift;} }