bitvector mantissa implemented

This commit is contained in:
Jiri Pittner 2022-06-24 06:42:32 +02:00
parent 6c22365a48
commit b63373fe7b
2 changed files with 26 additions and 1 deletions

View File

@ -93,6 +93,24 @@ r.clear();
for(int i=0; i<n; ++i) if(v[i]) r[i]=1;
}
//mantissa of a floating number between 0 and 1
template <typename T>
bitvector mantissa(const T &x, int nbits)
{
if(x<0||x>=1) laerror("number not normalized in bitvector mantissa");
bitvector b(nbits);
b.clear();
T y= x+x;
for(int i=0; i<nbits; ++i)
{
int n= (int) y;
if(n&1) b.set(i);
y += y;
}
return b;
}
template <typename T>
void bitvector_compress(bitvector &r, const NRVec<T> &v)
{

9
t.cc
View File

@ -2574,7 +2574,7 @@ cout <<test;
cout <<"Error = "<<(expitszsz-test).norm()<<endl;
}
if(1)
if(0)
{
NRVec<double> x({1,2,3});
NRVec<double> y({4,5,6});
@ -2585,4 +2585,11 @@ x.concatme(y);
cout <<x;
}
if(1)
{
double x;
cin>>x;
cout <<mantissa(x,20)<<endl;
}
}