@@ -243,7 +243,7 @@ inline int signum(T x)
243243}
244244
245245template <typename T>
246- inline T binLinear (float value, float lo, float hi, float step)
246+ T binLinear (float value, float lo, float hi, float step)
247247{
248248 float v = std::clamp (value, lo, hi);
249249 auto idx = static_cast <int64_t >(std::round ((v - lo) / step));
@@ -253,46 +253,46 @@ inline T binLinear(float value, float lo, float hi, float step)
253253}
254254
255255template <typename T>
256- inline float unBinLinear (T binned, float lo, float step)
256+ float unBinLinear (T binned, float lo, float step)
257257{
258258 auto idx = static_cast <int64_t >(binned) - static_cast <int64_t >(std::numeric_limits<T>::min ());
259259 return lo + static_cast <float >(idx) * step;
260260}
261261
262262template <typename T>
263- inline T binLogSigned (float signedValue, float magMin, float magMax)
263+ T binLogSigned (float signedValue, float magMin, float magMax)
264264{
265265 static_assert (std::is_unsigned_v<T>, " binLogSigned requires an unsigned storage type" );
266- constexpr uint32_t TotalBits = sizeof (T) * 8 ;
267- constexpr uint32_t HalfLevels = 1u << (TotalBits - 1 );
268- uint32_t sign = (signedValue < 0 .f ) ? 1u : 0u ;
269- float mag = std::clamp (std::fabs (signedValue), magMin, magMax);
270- float logLo = std::log (magMin);
271- float logHi = std::log (magMax);
272- float step = (logHi - logLo) / static_cast <float >(HalfLevels - 1 );
273- auto idx = static_cast <uint32_t >(std::round ((std::log (mag) - logLo) / step));
274- idx = std::clamp (idx, 0u , HalfLevels - 1 );
275- return static_cast <T>((sign << (TotalBits - 1 )) | idx);
266+ constexpr uint64_t TotalBits = sizeof (T) * 8 ;
267+ constexpr uint64_t HalfLevels = uint64_t { 1 } << (TotalBits - 1 );
268+ const uint64_t sign = (signedValue < 0 .f ) ? uint64_t { 1 } : uint64_t { 0 } ;
269+ const float mag = std::clamp (std::fabs (signedValue), magMin, magMax);
270+ const float logLo = std::log (magMin);
271+ const float logHi = std::log (magMax);
272+ const float step = (logHi - logLo) / static_cast <float >(HalfLevels - 1 );
273+ auto idx = static_cast <int64_t >(std::round ((std::log (mag) - logLo) / step));
274+ idx = std::clamp (idx, int64_t { 0 }, static_cast < int64_t >( HalfLevels - 1 ) );
275+ return static_cast <T>((sign << (TotalBits - 1 )) | static_cast < uint64_t >( idx) );
276276}
277277
278278template <typename T>
279- inline float unBinLogSigned (T binned, float magMin, float magMax)
279+ float unBinLogSigned (T binned, float magMin, float magMax)
280280{
281- constexpr uint32_t TotalBits = sizeof (T) * 8 ;
282- constexpr uint32_t HalfLevels = 1u << (TotalBits - 1 );
283- constexpr T SignMask = static_cast <T>(1u << (TotalBits - 1 ));
281+ static_assert (std::is_unsigned_v<T>, " unBinLogSigned requires an unsigned storage type" );
282+ constexpr uint64_t TotalBits = sizeof (T) * 8 ;
283+ constexpr uint64_t HalfLevels = uint64_t {1 } << (TotalBits - 1 );
284+ constexpr T SignMask = static_cast <T>(uint64_t {1 } << (TotalBits - 1 ));
284285 constexpr T MagMask = static_cast <T>(SignMask - 1 );
285- float sign = (binned & SignMask) ? -1 .f : 1 .f ;
286- uint32_t idx = binned & MagMask;
287- float logLo = std::log (magMin);
288- float logHi = std::log (magMax);
289- float step = (logHi - logLo) / static_cast <float >(HalfLevels - 1 );
290- float mag = std::exp (logLo + static_cast <float >(idx) * step);
291- return sign * mag;
286+ const float sign = (binned & SignMask) ? -1 .f : 1 .f ;
287+ const auto idx = static_cast <uint64_t >(binned & MagMask);
288+ const float logLo = std::log (magMin);
289+ const float logHi = std::log (magMax);
290+ const float step = (logHi - logLo) / static_cast <float >(HalfLevels - 1 );
291+ return sign * std::exp (logLo + static_cast <float >(idx) * step);
292292}
293293
294294template <typename T>
295- inline int unBinSign (T binned)
295+ int unBinSign (T binned)
296296{
297297 static_assert (std::is_unsigned_v<T>, " unBinSign requires an unsigned storage type" );
298298 constexpr uint64_t TotalBits = sizeof (T) * 8 ;
@@ -301,7 +301,7 @@ inline int unBinSign(T binned)
301301}
302302
303303template <typename T>
304- inline T binLogUnsigned (float value, float magMin, float magMax)
304+ T binLogUnsigned (float value, float magMin, float magMax)
305305{
306306 static_assert (std::is_unsigned_v<T>, " binLogUnsigned requires an unsigned storage type" );
307307 constexpr uint64_t TotalBits = sizeof (T) * 8 ;
@@ -316,7 +316,7 @@ inline T binLogUnsigned(float value, float magMin, float magMax)
316316}
317317
318318template <typename T>
319- inline float unBinLogUnsigned (T binned, float magMin, float magMax)
319+ float unBinLogUnsigned (T binned, float magMin, float magMax)
320320{
321321 constexpr uint64_t TotalBits = sizeof (T) * 8 ;
322322 constexpr uint64_t Levels = uint64_t {1 } << TotalBits;
0 commit comments