CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
libminifloat.h
Go to the documentation of this file.
1 #ifndef libminifloat_h
2 #define libminifloat_h
3 #include <cstdint>
4 
5 // ftp://ftp.fox-toolkit.org/pub/fasthalffloatconversion.pdf
7  public:
9  inline static float float16to32(uint16_t h) {
10  union { float flt; uint32_t i32; } conv;
11  conv.i32 = mantissatable[offsettable[h>>10]+(h&0x3ff)]+exponenttable[h>>10];
12  return conv.flt;
13  }
14  inline static uint16_t float32to16(float x) {
15  return float32to16round(x);
16  }
18  inline static uint16_t float32to16crop(float x) {
19  union { float flt; uint32_t i32; } conv;
20  conv.flt = x;
21  return basetable[(conv.i32>>23)&0x1ff]+((conv.i32&0x007fffff)>>shifttable[(conv.i32>>23)&0x1ff]);
22  }
24  inline static uint16_t float32to16round(float x) {
25  union { float flt; uint32_t i32; } conv;
26  conv.flt = x;
27  uint8_t shift = shifttable[(conv.i32>>23)&0x1ff];
28  if (shift == 13) {
29  uint16_t base2 = (conv.i32&0x007fffff)>>12;
30  uint16_t base = base2 >> 1;
31  if (((base2 & 1) != 0) && (base < 1023)) base++;
32  return basetable[(conv.i32>>23)&0x1ff]+base;
33  } else {
34  return basetable[(conv.i32>>23)&0x1ff]+((conv.i32&0x007fffff)>>shifttable[(conv.i32>>23)&0x1ff]);
35  }
36  }
37  private:
38  static uint32_t mantissatable[2048];
39  static uint32_t exponenttable[64];
40  static uint16_t offsettable[64];
41  static uint16_t basetable[512];
42  static uint8_t shifttable[512];
43  static void filltables() ;
44 };
45 #endif
static uint16_t float32to16crop(float x)
Fast implementation, but it crops the number so it biases low.
Definition: libminifloat.h:18
tuple base
Main Program
Definition: newFWLiteAna.py:92
static uint16_t offsettable[64]
Definition: libminifloat.h:40
static HepMC::IO_HEPEVT conv
static float float16to32(uint16_t h)
Definition: libminifloat.h:9
static uint16_t basetable[512]
Definition: libminifloat.h:41
static uint8_t shifttable[512]
Definition: libminifloat.h:42
static uint16_t float32to16(float x)
Definition: libminifloat.h:14
static uint32_t mantissatable[2048]
Definition: libminifloat.h:38
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
static unsigned int const shift
static void filltables()
Definition: libminifloat.cc:18
Definition: DDAxes.h:10
static uint16_t float32to16round(float x)
Slower implementation, but it rounds to avoid biases.
Definition: libminifloat.h:24
static uint32_t exponenttable[64]
Definition: libminifloat.h:39