CMS 3D CMS Logo

approx_math.h
Go to the documentation of this file.
1 #ifndef DataFormatsMathApproxMath_H
2 #define DataFormatsMathApproxMath_H
3 
4 
5 #include <cstdint>
6 #include <cmath>
7 #include <limits>
8 #include <algorithm>
9 
10 namespace approx_math {
11  // not c++ compliant (only C compliant)
12  // to be c++ compliaint one must use memcpy...
13  union binary32 {
14  constexpr binary32() : ui32(0) {};
15  constexpr binary32(float ff) : f(ff) {};
16  constexpr binary32(int32_t ii) : i32(ii){}
17  constexpr binary32(uint32_t ui) : ui32(ui){}
18 
19  uint32_t ui32; /* unsigned int */
20  int32_t i32; /* Signed int */
21  float f;
22  };
23 #ifdef __SSE4_1__
24  constexpr float fpfloor(float x) {
25  return std::floor(x);
26  }
27 #else
28  constexpr float fpfloor(float x) {
29  int32_t ret = x;
30  binary32 xx(x);
31  ret-=(xx.ui32>>31);
32  return ret;
33  }
34 #endif
35 }
36 
37 #endif
constexpr binary32(int32_t ii)
Definition: approx_math.h:16
constexpr float fpfloor(float x)
Definition: approx_math.h:28
constexpr binary32()
Definition: approx_math.h:14
#define constexpr
ii
Definition: cuy.py:590
constexpr binary32(float ff)
Definition: approx_math.h:15
constexpr binary32(uint32_t ui)
Definition: approx_math.h:17