mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-17 20:52:37 +01:00
Added floorLog2 function (#314)
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user