BOSS 7.0.4
BESIII Offline Software System
Loading...
Searching...
No Matches
ComPackExpFloat Class Reference

#include <ComPackExpFloat.h>

+ Inheritance diagram for ComPackExpFloat:

Public Member Functions

 ComPackExpFloat (unsigned nbits, unsigned maxexponent, double start, double stop, bool center=false)
 
virtual ~ComPackExpFloat ()
 
virtual StatusCode pack (const double, d_ULong &) const
 
virtual StatusCode unpack (const d_ULong, double &) const
 
void print (std::ostream &os) const
 
 ComPackExpFloat (unsigned nbits, unsigned maxexponent, double start, double stop, bool center=false)
 
virtual ~ComPackExpFloat ()
 
virtual StatusCode pack (const double, d_ULong &) const
 
virtual StatusCode unpack (const d_ULong, double &) const
 
void print (std::ostream &os) const
 
- Public Member Functions inherited from ComPackBase< double >
 ComPackBase ()
 
 ComPackBase (double minval, double maxval, d_ULong bitrange)
 
 ComPackBase (const ComPackBase &)
 
 ComPackBase ()
 
 ComPackBase (double minval, double maxval, d_ULong bitrange)
 
 ComPackBase (const ComPackBase &)
 
virtual ~ComPackBase ()
 
virtual ~ComPackBase ()
 
virtual StatusCode pack (const double, d_ULong &) const=0
 
virtual StatusCode pack (const double, d_ULong &) const=0
 
virtual StatusCode unpack (const d_ULong, double &) const=0
 
virtual StatusCode unpack (const d_ULong, double &) const=0
 
virtual const double & getMinVal () const
 
virtual const double & getMinVal () const
 
virtual const double & getMaxVal () const
 
virtual const double & getMaxVal () const
 
virtual const double & getRange () const
 
virtual const double & getRange () const
 
d_ULong bitRange () const
 
d_ULong bitRange () const
 
d_ULong bitMask () const
 
d_ULong bitMask () const
 
ComPackBaseoperator= (const ComPackBase &)
 
ComPackBaseoperator= (const ComPackBase &)
 

Additional Inherited Members

- Public Types inherited from ComPackBaseBase
enum  StatusCode {
  TAG_OK , TAG_BAD , TAG_RANGE_ERROR , TAG_VAL_ROUND_DOWN ,
  TAG_VAL_ROUND_UP , TAG_OK , TAG_BAD , TAG_RANGE_ERROR ,
  TAG_VAL_ROUND_DOWN , TAG_VAL_ROUND_UP
}
 
enum  StatusCode {
  TAG_OK , TAG_BAD , TAG_RANGE_ERROR , TAG_VAL_ROUND_DOWN ,
  TAG_VAL_ROUND_UP , TAG_OK , TAG_BAD , TAG_RANGE_ERROR ,
  TAG_VAL_ROUND_DOWN , TAG_VAL_ROUND_UP
}
 
- Protected Types inherited from ComPackBase< double >
enum  
 
enum  
 
- Protected Attributes inherited from ComPackBase< double >
double _minVal
 
double _maxVal
 
double _valRange
 
d_ULong _bitRange
 
d_ULong _bitMask
 

Detailed Description

Constructor & Destructor Documentation

◆ ComPackExpFloat() [1/2]

ComPackExpFloat::ComPackExpFloat ( unsigned  nbits,
unsigned  maxexponent,
double  start,
double  stop,
bool  center = false 
)

Definition at line 31 of file ComPackExpFloat.cxx.

35 :
36 ComPackBase<double>(start,stop,nbits),
37 _maxexp(maxexponent) {
38 if(_maxexp > 62 ) {
39 std::cout<<"ErrMsg(fatal) "<< "Can't pack exponents larger than 62" << endl;
40 abort();
41 }
42 static double invln2(1.0/log(2.0));
43 long long one(1);
44// compute how many bits used by exponent
45 _mansft = _maxexp>0?(unsigned)(log(double(_maxexp))*invln2+1.01):0;
46 _expmsk = (1<<_mansft)-1;
47 _maxman = (1<<(_bitRange-_mansft));
48 _manmsk = _maxman-1;
49 double invmaxman = 1.0/_maxman;
50 long long maxnorm = (one<<(maxexponent+1))-1;
51// correct the range if we're centering the bins
52 if(center) {
53 long long norm = one<<maxexponent;
54 double alpha = 1.0/((double)maxnorm*_maxman*2.0 - (norm + 1.0));
56 _maxVal += _valRange*norm*alpha;
58// cout << "alpha = " << alpha << " norm = " << norm << endl;
59 }
60// finish the calculations
61 _invrange = maxnorm/_valRange;
62 double invmaxnorm = _valRange/maxnorm;
63 double manoff = (0.5 * invmaxman+1.0) * invmaxnorm;
64 double valoff = _minVal - invmaxnorm;
65 double manfac = invmaxnorm * invmaxman;
66// pre-compute some factors and store them in an array
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;
73 }
74}
const double alpha
double precision pisqo6 one
Definition: qlconstants.h:4

◆ ~ComPackExpFloat() [1/2]

ComPackExpFloat::~ComPackExpFloat ( )
virtual

Definition at line 76 of file ComPackExpFloat.cxx.

77{
78 delete [] _expfac;
79 delete [] _expoff;
80}

◆ ComPackExpFloat() [2/2]

ComPackExpFloat::ComPackExpFloat ( unsigned  nbits,
unsigned  maxexponent,
double  start,
double  stop,
bool  center = false 
)

◆ ~ComPackExpFloat() [2/2]

virtual ComPackExpFloat::~ComPackExpFloat ( )
virtual

Member Function Documentation

◆ pack() [1/2]

ComPackBase< double >::StatusCode ComPackExpFloat::pack ( const double  value,
d_ULong packdata 
) const
virtual

Definition at line 83 of file ComPackExpFloat.cxx.

83 {
84 static double invln2(1.0/log(2.0));
85 static long long one(1);
87// first, figure out the exponent
88 double renorm = 1.0+(value-_minVal)*_invrange;
89 if(renorm<1.0){
90 renorm=1.0;
91 retval = TAG_VAL_ROUND_UP;
92 }
93 unsigned iexp = unsigned(log(renorm)*invln2);
94 unsigned iman(0);
95 if(iexp<=_maxexp){
96 long long expon = one<<iexp;
97 iman = (unsigned)( _maxman*(renorm/expon - 1.0) );
98// deal with floating-point rounding, which could give a 'non-physical' result
99 if(iman==_maxman){
100 if(iexp==_maxexp)
101 iman=_maxman-1;
102 else {
103 iman=0;
104 iexp++;
105 }
106 }
107 } else {
108 iexp=_maxexp;
109 iman = _maxman-1;
110 retval = TAG_VAL_ROUND_DOWN;
111 }
112 packdata = (iexp&_expmsk) | (iman&_manmsk)<<_mansft;
113 return retval;
114}

Referenced by ComPackSignedExpFloat::pack().

◆ pack() [2/2]

virtual StatusCode ComPackExpFloat::pack ( const double  ,
d_ULong  
) const
virtual

◆ print() [1/2]

void ComPackExpFloat::print ( std::ostream &  os) const

◆ print() [2/2]

void ComPackExpFloat::print ( std::ostream &  os) const

◆ unpack() [1/2]

ComPackBase< double >::StatusCode ComPackExpFloat::unpack ( const d_ULong  packdata,
double &  value 
) const
virtual

Implements ComPackBase< double >.

Definition at line 117 of file ComPackExpFloat.cxx.

117 {
118 size_t iman = (packdata>>_mansft)&_manmsk;
119 size_t iexp = packdata&_expmsk;
120 value = _expoff[iexp] + iman * _expfac[iexp];
121 return TAG_OK;
122}

Referenced by ComPackSignedExpFloat::unpack().

◆ unpack() [2/2]

virtual StatusCode ComPackExpFloat::unpack ( const  d_ULong,
double &   
) const
virtual

Implements ComPackBase< double >.


The documentation for this class was generated from the following files: