Minor fixes

This commit is contained in:
Jérôme Leclercq
2022-02-23 23:48:20 +01:00
parent 74dcb602b8
commit fe16584c8c
7 changed files with 15 additions and 21 deletions

View File

@@ -39,8 +39,8 @@ namespace Nz
unsigned int GetNumberLength(float number, UInt8 precision = NAZARA_CORE_DECIMAL_DIGITS);
unsigned int GetNumberLength(double number, UInt8 precision = NAZARA_CORE_DECIMAL_DIGITS);
unsigned int GetNumberLength(long double number, UInt8 precision = NAZARA_CORE_DECIMAL_DIGITS);
template<typename T> /*constexpr*/ unsigned int IntegralLog2(T number);
template<typename T> /*constexpr*/ unsigned int IntegralLog2Pot(T pot);
template<typename T> constexpr unsigned int IntegralLog2(T number);
template<typename T> constexpr unsigned int IntegralLog2Pot(T pot);
template<typename T> constexpr T IntegralPow(T base, unsigned int exponent);
template<typename T, typename T2> constexpr T Lerp(const T& from, const T& to, const T2& interpolation);
template<typename T> constexpr T MultiplyAdd(T x, T y, T z);

View File

@@ -18,13 +18,13 @@ namespace Nz
namespace
{
// https://graphics.stanford.edu/~seander/bithacks.html#IntegerLogDeBruijn
static const unsigned int MultiplyDeBruijnBitPosition[32] =
static constexpr unsigned int MultiplyDeBruijnBitPosition[32] =
{
0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30,
8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31
};
static const unsigned int MultiplyDeBruijnBitPosition2[32] =
static constexpr unsigned int MultiplyDeBruijnBitPosition2[32] =
{
0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
@@ -32,7 +32,7 @@ namespace Nz
}
template<typename T>
typename std::enable_if<sizeof(T) <= sizeof(UInt32), unsigned int>::type IntegralLog2(T number)
constexpr std::enable_if_t<sizeof(T) <= sizeof(UInt32), unsigned int> IntegralLog2(T number)
{
// https://graphics.stanford.edu/~seander/bithacks.html#IntegerLogDeBruijn
number |= number >> 1; // first round down to one less than a power of 2
@@ -45,8 +45,7 @@ namespace Nz
}
template<typename T>
// The parentheses are needed for GCC
typename std::enable_if<(sizeof(T) > sizeof(UInt32)), unsigned int>::type IntegralLog2(T number)
constexpr std::enable_if_t<(sizeof(T) > sizeof(UInt32)), unsigned int> IntegralLog2(T number)
{
static_assert(sizeof(T) % sizeof(UInt32) == 0, "Assertion failed");
@@ -69,15 +68,14 @@ namespace Nz
}
template<typename T>
typename std::enable_if<sizeof(T) <= sizeof(UInt32), unsigned int>::type IntegralLog2Pot(T number)
constexpr std::enable_if_t<sizeof(T) <= sizeof(UInt32), unsigned int> IntegralLog2Pot(T number)
{
// https://graphics.stanford.edu/~seander/bithacks.html#IntegerLogDeBruijn
return MultiplyDeBruijnBitPosition2[static_cast<UInt32>(number * 0x077CB531U) >> 27];
}
template<typename T>
// The parentheses are needed for GCC
typename std::enable_if<(sizeof(T) > sizeof(UInt32)), unsigned int>::type IntegralLog2Pot(T number)
constexpr std::enable_if_t<(sizeof(T) > sizeof(UInt32)), unsigned int> IntegralLog2Pot(T number)
{
static_assert(sizeof(T) % sizeof(UInt32) == 0, "Assertion failed");
@@ -391,8 +389,7 @@ namespace Nz
* \remark If number is 0, 0 is returned
*/
template<typename T>
//TODO: Mark as constexpr when supported by all major compilers
/*constexpr*/ inline unsigned int IntegralLog2(T number)
constexpr unsigned int IntegralLog2(T number)
{
// Proxy needed to avoid an overload problem
return Detail::IntegralLog2<T>(number);
@@ -409,8 +406,7 @@ namespace Nz
* \remark If number is 0, 0 is returned
*/
template<typename T>
//TODO: Mark as constexpr when supported by all major compilers
/*constexpr*/ inline unsigned int IntegralLog2Pot(T pot)
constexpr unsigned int IntegralLog2Pot(T pot)
{
return Detail::IntegralLog2Pot<T>(pot);
}