11 #ifndef L1TopoSimulationUtils_L1TOPODATATYPES_H
12 #define L1TopoSimulationUtils_L1TOPODATATYPES_H
28 if (
n >=
sizeof(
T) * 8)
29 return ~static_cast<T>(0);
30 return (
static_cast<T>(1) <<
n) - 1ull;
35 typedef unsigned long long T;
36 T convert(
const unsigned long long&
v,
const unsigned& in_p,
const unsigned int& in_f,
37 const unsigned int& out_p,
const unsigned int& out_f);
57 for(
auto in =
b.rbegin(); in!=
b.rend(); ++in){
96 operator unsigned long long(){
114 for(
unsigned j=0;j<PREC;++j){
115 res +=
v & (1ull << j) ? 0 : (1ull << j);
135 short int neg = (
m_tvalue >> (PREC-1ull)) ? 1 : 0;
149 template<
unsigned P,
unsigned FF>
friend L1TopoDataTypes<P,FF>
operator*(
const int& factor, L1TopoDataTypes<P,FF>
d);
150 template<
unsigned P,
unsigned FF>
friend L1TopoDataTypes<P,FF>
operator*(L1TopoDataTypes<P,FF>
d,
const int& factor);
153 template<
unsigned P1,
unsigned F1,
unsigned P2,
unsigned F2>
friend L1TopoDataTypes<((P1-F1) > (P2-F2) ? (P1-F1) : (P2-F2)) + ((F1 > F2) ? F1 : F2), (F1 > F2) ? F1 : F2>
operator+(
const L1TopoDataTypes<P1,F1>& lhs,
const L1TopoDataTypes<P2,F2>& rhs);
156 template<
unsigned P1,
unsigned F1,
unsigned P2,
unsigned F2>
friend L1TopoDataTypes<((P1-F1) > (P2-F2) ? (P1-F1) : (P2-F2)) + ((F1 > F2) ? F1 : F2), (F1 > F2) ? F1 : F2>
operator-(
const L1TopoDataTypes<P1,F1> lhs,
const L1TopoDataTypes<P2,F2> rhs);
159 template<
unsigned P1,
unsigned F1> L1TopoDataTypes<P1+1,F1>
friend operator-(
const double& lhs,
const L1TopoDataTypes<P1,F1>& rhs);
161 template<
unsigned P1,
unsigned F1> L1TopoDataTypes<P1+1,F1>
friend operator-(
const L1TopoDataTypes<P1,F1>& lhs,
const double& rhs);
164 template<
unsigned P1,
unsigned F1> L1TopoDataTypes<P1+1,F1>
friend operator-(
const int& lhs,
const L1TopoDataTypes<P1,F1>& rhs);
166 template<
unsigned P1,
unsigned F1> L1TopoDataTypes<P1+1,F1>
friend operator-(
const L1TopoDataTypes<P1,F1>& lhs,
const int& rhs);
185 for(
int j=PREC-1;j>=0;--j){
186 out += ((
d.m_tvalue>>j)&1ull) ?
"1" :
"0";
188 os <<
"integer value " <<
d.m_tvalue <<
" binary " <<
out <<
" float " <<
d.to_float();
195 float res = ((
m_tvalue>>(PREC-1ull))&1ull) ? -(1
ll<<(PREC-
F)) : 0.;
202 res +=
static_cast<float>(
frac) / (2ull<<(
F-1ull));
207 unsigned int prec()
const {
return PREC; }
208 unsigned int frac()
const {
return F; }
225 float to_float(
const T& va,
const unsigned int&
p,
const unsigned int&
f);
229 const unsigned int frac = (F1 > F2) ? F1 : F2;
230 const unsigned int digit = ((P1-F1) > (P2-F2)) ? (P1-F1) - 1 : (P2-F2) - 1;
241 const unsigned int frac = (F1 > F2) ? F1 : F2;
242 const unsigned int digit = ((P1-F1) > (P2-F2)) ? (P1-F1) - 1 : (P2-F2) - 1;
286 const unsigned int frac = (P1+P2-1 >
MAXBITS) ? (F2>F1 ? F2 - ((P1+P2-1) -
MAXBITS) : F1 - ((P1+P2-1) -
MAXBITS)) : ((F1 > F2) ? F1 : F2);
289 T lhsconvert = lhs.m_tvalue;
290 T rhsconvert = rhs.m_tvalue;
292 if((lhs.m_tvalue >> (P1-1ull)) & 1ull){
295 if((rhs.m_tvalue >> (P2-1ull)) & 1ull){
299 T lhsconvint =
convert(lhsconvert,P1,F1,P1-F1,0);
300 T rhsconvint =
convert(rhsconvert,P2,F2,P2-F2,0);
301 T lhsconvfrac =
convert(lhsconvert,P1,F1,F1+1,F1);
302 T rhsconvfrac =
convert(rhsconvert,P2,F2,F2+1,F2);
303 T prod_int = lhsconvint*rhsconvint;
304 T prod_frac = lhsconvfrac*rhsconvfrac;
305 T prod_mix1 = lhsconvint*rhsconvfrac;
306 T prod_mix2 = lhsconvfrac*rhsconvint;
311 if(!(((lhs.m_tvalue >> (P1-1ull)) & 1ull) ^ ((rhs.m_tvalue >> (P2-1ull)) & 1ull))){