Added integer version of log2.

This commit is contained in:
Бранимир Караџић
2019-10-22 19:29:51 -07:00
parent a9e8a24b60
commit 4bcb2c4fb3
3 changed files with 37 additions and 1 deletions

View File

@@ -10,6 +10,7 @@
#endif // BX_MATH_H_HEADER_GUARD
#include <bx/simd_t.h>
#include <bx/uint32_t.h>
namespace bx
{
@@ -191,11 +192,18 @@ namespace bx
return pow(2.0f, _a);
}
template<>
inline BX_CONST_FUNC float log2(float _a)
{
return log(_a) * kInvLogNat2;
}
template<>
inline BX_CONST_FUNC int32_t log2(int32_t _a)
{
return 31 - uint32_cntlz(_a);
}
inline BX_CONST_FUNC float rsqrtRef(float _a)
{
return pow(_a, -0.5f);

View File

@@ -225,7 +225,8 @@ namespace bx
/// Returns the base 2 logarithm of _a.
///
BX_CONST_FUNC float log2(float _a);
template<typename Ty>
BX_CONST_FUNC Ty log2(Ty _a);
/// Returns the square root of _a.
///