mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-18 04:53:06 +01:00
Added integer version of log2.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user