mirror of
https://github.com/g-truc/glm.git
synced 2024-11-23 01:14:34 +00:00
Fixed roundPowerOfTwo and floorPowerOfTwo #503
This commit is contained in:
parent
e0d312ccaf
commit
68ec048b70
@ -276,7 +276,7 @@ namespace detail
|
||||
template <typename genType>
|
||||
GLM_FUNC_QUALIFIER genType floorPowerOfTwo(genType value)
|
||||
{
|
||||
return isPowerOfTwo(value) ? value : findMSB(value);
|
||||
return isPowerOfTwo(value) ? value : static_cast<genType>(1) << findMSB(value);
|
||||
}
|
||||
|
||||
template <typename T, precision P, template <typename, precision> class vecType>
|
||||
@ -294,8 +294,8 @@ namespace detail
|
||||
if(isPowerOfTwo(value))
|
||||
return value;
|
||||
|
||||
genIUType const prev = findMSB(value);
|
||||
genIUType const next = prev << 1;
|
||||
genIUType const prev = static_cast<genIUType>(1) << findMSB(value);
|
||||
genIUType const next = prev << static_cast<genIUType>(1);
|
||||
return (next - value) < (value - prev) ? next : prev;
|
||||
}
|
||||
|
||||
|
@ -303,6 +303,21 @@ namespace roundPowerOfTwo
|
||||
glm::uint32 const A = glm::roundPowerOfTwo(7u);
|
||||
Error += A == 8u ? 0 : 1;
|
||||
|
||||
glm::uint32 const B = glm::roundPowerOfTwo(15u);
|
||||
Error += B == 16u ? 0 : 1;
|
||||
|
||||
glm::uint32 const C = glm::roundPowerOfTwo(31u);
|
||||
Error += C == 32u ? 0 : 1;
|
||||
|
||||
glm::uint32 const D = glm::roundPowerOfTwo(9u);
|
||||
Error += D == 8u ? 0 : 1;
|
||||
|
||||
glm::uint32 const E = glm::roundPowerOfTwo(17u);
|
||||
Error += E == 16u ? 0 : 1;
|
||||
|
||||
glm::uint32 const F = glm::roundPowerOfTwo(33u);
|
||||
Error += F == 32u ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace roundPowerOfTwo
|
||||
@ -316,6 +331,12 @@ namespace floorPowerOfTwo
|
||||
glm::uint32 const A = glm::floorPowerOfTwo(7u);
|
||||
Error += A == 4u ? 0 : 1;
|
||||
|
||||
glm::uint32 const B = glm::floorPowerOfTwo(15u);
|
||||
Error += B == 8u ? 0 : 1;
|
||||
|
||||
glm::uint32 const C = glm::floorPowerOfTwo(31u);
|
||||
Error += C == 16u ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace floorPowerOfTwo
|
||||
|
Loading…
Reference in New Issue
Block a user