37 _maxexp(maxexponent) {
39 std::cout<<
"ErrMsg(fatal) "<<
"Can't pack exponents larger than 62" << endl;
42 static double invln2(1.0/log(2.0));
45 _mansft = _maxexp>0?(unsigned)(log(
double(_maxexp))*invln2+1.01):0;
46 _expmsk = (1<<_mansft)-1;
49 double invmaxman = 1.0/_maxman;
50 long long maxnorm = (
one<<(maxexponent+1))-1;
53 long long norm =
one<<maxexponent;
54 double alpha = 1.0/((double)maxnorm*_maxman*2.0 - (norm + 1.0));
63 double manoff = (0.5 * invmaxman+1.0) * invmaxnorm;
64 double valoff =
_minVal - invmaxnorm;
65 double manfac = invmaxnorm * invmaxman;
67 _expfac =
new double[_maxexp+1];
68 _expoff =
new double[_maxexp+1];
69 for(
unsigned iexp=0;iexp<=_maxexp;iexp++){
70 double expf = (
one<<iexp);
71 _expoff[iexp] = valoff + manoff*expf;
72 _expfac[iexp] = manfac*expf;
84 static double invln2(1.0/log(2.0));
85 static long long one(1);
88 double renorm = 1.0+(value-
_minVal)*_invrange;
93 unsigned iexp = unsigned(log(renorm)*invln2);
96 long long expon =
one<<iexp;
97 iman = (unsigned)( _maxman*(renorm/expon - 1.0) );
112 packdata = (iexp&_expmsk) | (iman&_manmsk)<<_mansft;
118 size_t iman = (packdata>>_mansft)&_manmsk;
119 size_t iexp = packdata&_expmsk;
120 value = _expoff[iexp] + iman * _expfac[iexp];
126 os <<
"Exponential packer for range " <<
_minVal <<
" to " <<
_maxVal << endl;
127 os <<
"Maximum exponent = " << _maxexp << endl;
128 os <<
"Maximum mantissa = " << _maxman << endl;
129 os <<
"Mantissa storage shift, mask = " << _mansft <<
" , " << _manmsk << endl;
double precision pisqo6 one
virtual ~ComPackExpFloat()
ComPackExpFloat(unsigned nbits, unsigned maxexponent, double start, double stop, bool center=false)
virtual StatusCode unpack(const d_ULong, double &) const
virtual StatusCode pack(const double, d_ULong &) const
void print(std::ostream &os) const