Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:41

0001 #ifndef DataFormatsMathApproxMath_H
0002 #define DataFormatsMathApproxMath_H
0003 
0004 #include <cstdint>
0005 #include <cmath>
0006 #include <limits>
0007 #include <algorithm>
0008 
0009 namespace approx_math {
0010   // not c++ compliant (only C compliant)
0011   // to be c++ compliaint one must use memcpy...
0012   union binary32 {
0013     constexpr binary32() : ui32(0){};
0014     constexpr binary32(float ff) : f(ff){};
0015     constexpr binary32(int32_t ii) : i32(ii) {}
0016     constexpr binary32(uint32_t ui) : ui32(ui) {}
0017 
0018     uint32_t ui32; /* unsigned int */
0019     int32_t i32;   /* Signed int */
0020     float f;
0021   };
0022 #ifdef __SSE4_1__
0023   constexpr float fpfloor(float x) { return std::floor(x); }
0024 #else
0025   constexpr float fpfloor(float x) {
0026     int32_t ret = x;
0027     binary32 xx(x);
0028     ret -= (xx.ui32 >> 31);
0029     return ret;
0030   }
0031 #endif
0032 }  // namespace approx_math
0033 
0034 #endif