File indexing completed on 2024-09-07 04:35:55
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
0011
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;
0019 int32_t i32;
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 }
0033
0034 #endif