openMSX
|
Functions | |
unsigned | powerOfTwo (unsigned a) |
Returns the smallest number that is both >=a and a power of two. More... | |
bool | isPowerOfTwo (unsigned a) |
Is the given number an integer power of 2? Not correct for zero (according to this test 0 is a power of 2). More... | |
template<int LO, int HI> | |
int | clip (int x) |
Clips x to the range [LO,HI]. More... | |
short | clipIntToShort (int x) |
Clip x to range [-32768,32767]. More... | |
byte | clipIntToByte (int x) |
Clip x to range [0,255]. More... | |
template<int LO, int HI> | |
int | clip (float r, float factor) |
Clips r * factor to the range [LO,HI]. More... | |
unsigned | gcd (unsigned a, unsigned b) |
Calculate greatest common divider of two strictly positive integers. More... | |
unsigned | reverseNBits (unsigned x, unsigned bits) |
Reverse the lower N bits of a given value. More... | |
byte | reverseByte (byte a) |
Reverse the bits in a byte. More... | |
template<typename T > | |
T | floodRight (T x) |
Returns the smallest number of the form 2^n-1 that is greater or equal to the given number. More... | |
unsigned | countLeadingZeros (unsigned x) |
Count the number of leading zero-bits in the given word. More... | |
|
inline |
|
inline |
|
inline |
|
inline |
Clip x to range [-32768,32767].
Special case of the version above. Optimized for the case when no clipping is needed.
Definition at line 37 of file Math.hh.
References likely.
Referenced by openmsx::WavImage::getSampleAt(), and openmsx::Y8950::Impl::writeReg().
|
inline |
|
inline |
Returns the smallest number of the form 2^n-1 that is greater or equal to the given number.
The resulting number has the same number of leading zeros as the input, but starting from the first 1-bit in the input all bits more to the right are also 1.
Definition at line 174 of file Math.hh.
Referenced by openmsx::VRAMWindow::getReadArea(), openmsx::VRAMWindow::getReadAreaPlanar(), and powerOfTwo().
|
inline |
Calculate greatest common divider of two strictly positive integers.
Classical implementation is like this: while (unsigned t = b % a) { b = a; a = t; } return a; The following implementation avoids the costly modulo operation. It is about 40% faster on my machine.
require: a != 0 && b != 0
Definition at line 70 of file Math.hh.
Referenced by openmsx::FBPostProcessor< Pixel >::paint().
|
inline |
Is the given number an integer power of 2? Not correct for zero (according to this test 0 is a power of 2).
Definition at line 15 of file Math.hh.
Referenced by openmsx::MemoryOps::mallocAligned().
unsigned openmsx::Math::powerOfTwo | ( | unsigned | a | ) |
Returns the smallest number that is both >=a and a power of two.
Definition at line 8 of file Math.cc.
References floodRight().
Referenced by openmsx::SDLGLOutputSurface::init(), and openmsx::SDLSoundDriver::SDLSoundDriver().
|
inline |
Reverse the bits in a byte.
This is equivalent to (but faster than) reverseNBits(x, 8);
Definition at line 148 of file Math.hh.
Referenced by openmsx::ImagePrinter::printGraphicByte(), and openmsx::LaserdiscPlayer::serialize().
|
inline |
Reverse the lower N bits of a given value.
The upper 32-N bits from the input are ignored and will be returned as 0. For example reverseNBits('xxxabcde', 5) returns '000edcba' (binary notation).
Definition at line 98 of file Math.hh.
Referenced by openmsx::LaserdiscPlayer::serialize().