openMSX
utils
Math.cc
Go to the documentation of this file.
1
#include "
Math.hh
"
2
3
namespace
Math
{
4
5
unsigned
powerOfTwo
(
unsigned
a)
6
{
7
// classical implementation:
8
// unsigned res = 1;
9
// while (a > res) res <<= 1;
10
// return res;
11
12
// optimized version
13
a += (a == 0);
// can be removed if argument is never zero
14
return
floodRight
(a - 1) + 1;
15
}
16
17
}
// namespace Math
Math::powerOfTwo
unsigned powerOfTwo(unsigned a)
Returns the smallest number that is both >=a and a power of two.
Definition:
Math.cc:5
Math.hh
Math
Definition:
Math.cc:3
Math::floodRight
T floodRight(T x)
Returns the smallest number of the form 2^n-1 that is greater or equal to the given number...
Definition:
Math.hh:185
Generated on Sun Jul 14 2019 19:02:56 for openMSX by
1.8.13