42 constexpr bounded_range(
float min,
float max,
float precision) noexcept :
45 m_Precision(precision),
46 m_BitsRequired(log2(
static_cast<uint32_t
>((m_Max - m_Min) * (1.0f / precision) + 0.5f)) + 1),
47 m_Mask((1U << m_BitsRequired) - 1U) {}
49 constexpr inline float get_min() const noexcept {
return m_Min; }
50 constexpr inline float get_max() const noexcept {
return m_Max; }
51 constexpr inline float get_precision() const noexcept {
return m_Precision; }
54 constexpr inline uint32_t
quantize(
float value)
const noexcept
58 else if (value > m_Max)
61 return static_cast<uint32_t
>(
static_cast<float>((value - m_Min) * (1.0f / m_Precision)) + 0.5f) & m_Mask;
64 constexpr inline float dequantize(uint32_t data)
const noexcept
66 float adjusted = (
static_cast<float>(data) * m_Precision) + m_Min;
70 else if (adjusted > m_Max)
77 constexpr inline static uint32_t log2(uint32_t value)
noexcept
85 return DE_BRUIJN[(value * 0x07C4ACDDU) >> 27];
93 uint32_t m_BitsRequired;
96 constexpr inline static uint32_t DE_BRUIJN[32]
98 0, 9, 1, 10, 13, 21, 2, 29,
99 11, 14, 16, 18, 22, 25, 3, 30,
100 8, 12, 20, 28, 15, 17, 24, 7,
101 19, 27, 23, 6, 26, 5, 4, 31