openMSX

Functions  
unsigned  powerOfTwo (unsigned a) 
Returns the smallest number that is both >=a and a power of two. More...  
constexpr 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...  
int16_t  clipIntToShort (int x) 
Clip x to range [32768,32767]. More...  
uint8_t  clipIntToByte (int x) 
Clip x to range [0,255]. 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...  
uint8_t  reverseByte (uint8_t a) 
Reverse the bits in a byte. More...  
template<typename T >  
T  floodRight (T x) 
Returns the smallest number of the form 2^n1 that is greater or equal to the given number. More...  
unsigned  countLeadingZeros (unsigned x) 
Count the number of leading zerobits in the given word. More...  
unsigned  findFirstSet (unsigned x) 
Find the least significant bit that is set. More...  

inline 
Clips x to the range [LO,HI].
Slightly faster than std::min(HI, std::max(LO, x)) especially when no clipping is required.
Definition at line 48 of file Math.hh.
Referenced by openmsx::GLPostProcessor::update(), openmsx::Mouse::~Mouse(), and openmsx::Trackball::~Trackball().

inline 
Clip x to range [0,255].
Optimized for the case when no clipping is needed.
Definition at line 66 of file Math.hh.
Referenced by openmsx::VDP::getMSX1Palette(), and TEST_CASE().

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 57 of file Math.hh.
Referenced by openmsx::Y8950Adpcm::calcSample(), openmsx::DCFilter::operator()(), TEST_CASE(), openmsx::Wav16Writer::write(), and openmsx::Y8950::writeReg().

inline 
Count the number of leading zerobits in the given word.
The result is undefined when the input is zero (all bits are zero).
Definition at line 199 of file Math.hh.
Referenced by openmsx::SpriteChecker::reset(), and TEST_CASE().

inline 

inline 
Returns the smallest number of the form 2^n1 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 1bit in the input all bits more to the right are also 1.
Definition at line 185 of file Math.hh.
Referenced by openmsx::VRAMWindow::getReadAreaPlanar(), openmsx::VRAMWindow::isContinuous(), openmsx::TigerTree::notifyChange(), powerOfTwo(), and TEST_CASE().

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 81 of file Math.hh.
Referenced by openmsx::FBPostProcessor< Pixel >::paint(), and openmsx::GLPostProcessor::~GLPostProcessor().
constexpr bool Math::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).
Definition at line 34 of file Math.hh.
References powerOfTwo().
Referenced by openmsx::AmdFlash::AmdFlash(), openmsx::MemoryOps::mallocAligned(), openmsx::MSXMusicBase::MSXMusicBase(), openmsx::RomBlocks< BANK_SIZE_ >::RomBlocks(), and TEST_CASE().
unsigned Math::powerOfTwo  (  unsigned  a  ) 
Returns the smallest number that is both >=a and a power of two.
Definition at line 5 of file Math.cc.
References floodRight().
Referenced by openmsx::SDLGLOutputSurface::init(), isPowerOfTwo(), openmsx::MSXMemoryMapper::peekIO(), openmsx::SDLSoundDriver::SDLSoundDriver(), TEST_CASE(), openmsx::VDPVRAM::updateSpritesEnabled(), and openmsx::MSXMemoryMapper::writeIO().

inline 
Reverse the bits in a byte.
This is equivalent to (but faster than) reverseNBits(x, 8);
Definition at line 159 of file Math.hh.
Referenced by openmsx::ImagePrinter::printGraphicByte(), openmsx::LaserdiscPlayer::serialize(), and openmsx::SunriseIDE::writeMem().

inline 
Reverse the lower N bits of a given value.
The upper 32N bits from the input are ignored and will be returned as 0. For example reverseNBits('xxxabcde', 5) returns '000edcba' (binary notation).
Definition at line 109 of file Math.hh.
Referenced by openmsx::LaserdiscPlayer::serialize().