Add IntLog2 and use it
Replace uses of floating point log2 when we want an integer result from an integer operand. This avoids concerns about accuracy of floating point library functions.
This commit is contained in:
parent
5c4f421121
commit
fa6e3c2737
4 changed files with 179 additions and 8 deletions
|
|
@ -286,6 +286,18 @@ template <class T> bool IsMultipleOfPow2(T number, int powerOf2)
|
|||
return ! (number & (powerOf2 - 1));
|
||||
}
|
||||
|
||||
// Returns log2 of an integer power of 2.
|
||||
// T should be integral.
|
||||
template <class T> int IntLog2(T n)
|
||||
{
|
||||
assert(IsPow2(n));
|
||||
int result = 0;
|
||||
while ((T(1) << result) != n) {
|
||||
result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // end namespace glslang
|
||||
|
||||
#endif // _COMMON_INCLUDED_
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue