Added floorLog2 function (#314)

This commit is contained in:
Jamil Halabi
2023-12-11 18:38:56 +03:00
committed by GitHub
parent 89ba00e6cd
commit 3e5d611007
2 changed files with 12 additions and 0 deletions

View File

@@ -376,6 +376,13 @@ namespace bx
return Ty(_a) < Ty(1) ? Ty(0) : sizeof(Ty)*8 - countLeadingZeros<Ty>(_a - 1);
}
template<typename Ty>
inline BX_CONSTEXPR_FUNC uint8_t floorLog2(Ty _a)
{
BX_STATIC_ASSERT(isInteger<Ty>(), "Type Ty must be of integer type!");
return Ty(_a) < Ty(1) ? Ty(0) : sizeof(Ty)*8 - 1 - countLeadingZeros<Ty>(_a);
}
template<typename Ty>
inline BX_CONSTEXPR_FUNC Ty nextPow2(Ty _a)
{

View File

@@ -297,6 +297,11 @@ namespace bx
template<typename Ty>
BX_CONSTEXPR_FUNC uint8_t ceilLog2(Ty _a);
/// Returns the next biggest integer base 2 logarithm of _a.
///
template<typename Ty>
BX_CONSTEXPR_FUNC uint8_t floorLog2(Ty _a);
/// Returns the next smallest power of two value.
///
template<typename Ty>