test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
liblogintpack.h
Go to the documentation of this file.
1 #ifndef liblogintpack_h
2 #define liblogintpack_h
3 
4 #include <cmath>
5 
6 namespace logintpack
7 {
9  // note that abs(unpack(smallestNegative)) == unpack(1), i.e. there
10  // is no "x" such that "unpack(x) == -unpack(0)"
12 
13  int8_t pack8logCeil(double x,double lmin, double lmax, uint8_t base=128)
14  {
15  if(base>128) base=128;
16  const double l = std::log(std::abs(x));
17  const double centered = (l-lmin)/(lmax-lmin)*base;
18  int8_t r=std::ceil(centered);
19  if(centered >= base-1) r=base-1;
20  if(centered < 0) r=0;
21  if(x<0) r = r==0 ? -1 : -r;
22  return r;
23  }
24 
25  int8_t pack8log(double x,double lmin, double lmax, uint8_t base=128)
26  {
27  if(base>128) base=128;
28  const double l = std::log(std::abs(x));
29  const double centered = (l-lmin)/(lmax-lmin)*base;
30  int8_t r=centered;
31  if(centered >= base-1) r=base-1;
32  if(centered < 0) r=0;
33  if(x<0) r = r==0 ? -1 : -r;
34  return r;
35  }
36 
39  int8_t pack8logClosed(double x,double lmin, double lmax, uint8_t base=128)
40  {
41  if(base>128) base=128;
42  const double l = std::log(std::abs(x));
43  const double centered = (l-lmin)/(lmax-lmin)*(base-1);
44  int8_t r=round(centered);
45  if(centered >= base-1) r=base-1;
46  if(centered < 0) r=0;
47  if(x<0) r = r==0 ? -1 : -r;
48  return r;
49  }
50 
51 
52  double unpack8log(int8_t i,double lmin, double lmax, uint8_t base=128)
53  {
54  if(base>128) base=128;
55  const double basef=base;
56  const double l=lmin+std::abs(i)/basef*(lmax-lmin);
57  const double val=std::exp(l);
58  if(i<0) return -val; else return val;
59  }
60 
62  double unpack8logClosed(int8_t i,double lmin, double lmax, uint8_t base=128)
63  {
64  if(base>128) base=128;
65  const double basef=base-1;
66  double l=lmin+std::abs(i)/basef*(lmax-lmin);
67  if (std::abs(i) == base-1) l = lmax;
68  const double val=std::exp(l);
69  if(i<0) return -val; else return val;
70  }
71 
72 }
73 #endif
tuple base
Main Program
Definition: newFWLiteAna.py:91
int i
Definition: DBlmapReader.cc:9
double unpack8log(int8_t i, double lmin, double lmax, uint8_t base=128)
Definition: liblogintpack.h:52
int8_t pack8log(double x, double lmin, double lmax, uint8_t base=128)
Definition: liblogintpack.h:25
constexpr int8_t smallestNegative
Definition: liblogintpack.h:11
#define constexpr
int8_t pack8logCeil(double x, double lmin, double lmax, uint8_t base=128)
Definition: liblogintpack.h:13
int8_t pack8logClosed(double x, double lmin, double lmax, uint8_t base=128)
Definition: liblogintpack.h:39
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
constexpr int8_t smallestPositive
Definition: liblogintpack.h:8
double unpack8logClosed(int8_t i, double lmin, double lmax, uint8_t base=128)
reverse of pack8logClosed
Definition: liblogintpack.h:62