From 9c63880efba8e11da72739f8abe46e61a76b155e Mon Sep 17 00:00:00 2001 From: Jiri Pittner Date: Fri, 8 Jul 2022 10:58:30 +0200 Subject: [PATCH] implemented optional shift in bitvector mantissa --- bitvector.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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;} }