openMSX
Classes | Functions | Variables
Math Namespace Reference

Classes

struct  QuotientRemainder
 Divide one integer by another, rounding towards minus infinity. More...
 

Functions

constexpr auto floodRight (std::unsigned_integral auto x) noexcept
 Returns the smallest number of the form 2^n-1 that is greater or equal to the given number. More...
 
template<std::signed_integral T>
int16_t clipToInt16 (T x)
 Clip x to range [-32768,32767]. More...
 
uint8_t clipIntToByte (int x)
 Clip x to range [0,255]. More...
 
constexpr unsigned reverseNBits (unsigned x, unsigned bits)
 Reverse the lower N bits of a given value. More...
 
constexpr uint8_t reverseByte (uint8_t a)
 Reverse the bits in a byte. More...
 
unsigned findFirstSet (uint32_t x)
 Find the least significant bit that is set. More...
 
constexpr float cubicHermite (std::span< const float, 4 > y, float x)
 
constexpr QuotientRemainder div_mod_floor (int dividend, int divisor)
 
constexpr int div_floor (int dividend, int divisor)
 
constexpr int mod_floor (int dividend, int divisor)
 

Variables

constexpr double e = std::numbers::e_v <double>
 
constexpr double ln2 = std::numbers::ln2_v <double>
 
constexpr double ln10 = std::numbers::ln10_v<double>
 
constexpr double pi = std::numbers::pi_v <double>
 

Function Documentation

◆ clipIntToByte()

uint8_t Math::clipIntToByte ( int  x)
inline

Clip x to range [0,255].

Optimized for the case when no clipping is needed.

Definition at line 60 of file Math.hh.

Referenced by openmsx::VDP::getMSX1Palette(), and TEST_CASE().

◆ clipToInt16()

template<std::signed_integral T>
int16_t Math::clipToInt16 ( x)
inline

Clip x to range [-32768,32767].

Optimized for the case when no clipping is needed.

Definition at line 46 of file Math.hh.

Referenced by openmsx::WavImage::getSampleAt(), openmsx::DCFilter::operator()(), TEST_CASE(), and openmsx::Y8950::writeReg().

◆ cubicHermite()

constexpr float Math::cubicHermite ( std::span< const float, 4 >  y,
float  x 
)
constexpr

Definition at line 166 of file Math.hh.

Referenced by openmsx::WavImage::getSampleAt().

◆ div_floor()

constexpr int Math::div_floor ( int  dividend,
int  divisor 
)
constexpr

Definition at line 196 of file Math.hh.

References div_mod_floor(), and Math::QuotientRemainder::quotient.

◆ div_mod_floor()

constexpr QuotientRemainder Math::div_mod_floor ( int  dividend,
int  divisor 
)
constexpr

Definition at line 187 of file Math.hh.

Referenced by div_floor(), and mod_floor().

◆ findFirstSet()

unsigned Math::findFirstSet ( uint32_t  x)
inline

Find the least significant bit that is set.

Returns
0 if the input is zero (no bits are set), otherwise the index of the first set bit + 1.

Definition at line 148 of file Math.hh.

◆ floodRight()

constexpr auto Math::floodRight ( std::unsigned_integral auto  x)
constexprnoexcept

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 31 of file Math.hh.

Referenced by openmsx::VRAMWindow::getReadAreaPlanar(), openmsx::VRAMWindow::isContinuous(), and TEST_CASE().

◆ mod_floor()

constexpr int Math::mod_floor ( int  dividend,
int  divisor 
)
constexpr

Definition at line 199 of file Math.hh.

References div_mod_floor(), and Math::QuotientRemainder::remainder.

◆ reverseByte()

constexpr uint8_t Math::reverseByte ( uint8_t  a)
constexpr

Reverse the bits in a byte.

This is equivalent to (but faster than) reverseNBits(x, 8);

Definition at line 124 of file Math.hh.

Referenced by openmsx::ImagePrinter::printGraphicByte(), and openmsx::LaserdiscPlayer::serialize().

◆ reverseNBits()

constexpr unsigned Math::reverseNBits ( unsigned  x,
unsigned  bits 
)
constexpr

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 74 of file Math.hh.

Referenced by openmsx::LaserdiscPlayer::serialize().

Variable Documentation

◆ e

constexpr double Math::e = std::numbers::e_v <double>
inlineconstexpr

Definition at line 20 of file Math.hh.

Referenced by openmsx::Clock< FREQ_NUM, FREQ_DENOM >::advance(), openmsx::DynamicClock::advance(), openmsx::Clock< FREQ_NUM, FREQ_DENOM >::advance_fast(), openmsx::XMLDocument::allocateString(), openmsx::Clock< FREQ_NUM, FREQ_DENOM >::before(), openmsx::DynamicClock::before(), openmsx::XmlInputArchive::beginTag(), openmsx::BreakPointBase::checkAndExecute(), openmsx::CliServer::CliServer(), openmsx::IPSPatch::copyBlock(), openmsx::OSDImageBasedWidget::createImage(), openmsx::SDLVisibleSurfaceBase::createSurface(), openmsx::EventDistributor::deliverEvents(), dynarray< T >::dynarray(), openmsx::Sha1Sum::empty(), openmsx::EmuDurationCompactStorage< T >::EmuDurationCompactStorage(), openmsx::AfterCmd::execute(), openmsx::MachineExtensionInfo::execute(), openmsx::ConfigInfo::execute(), openmsx::DiskCommand::execute(), openmsx::ListExtCmd::execute(), openmsx::MachineCommand::execute(), openmsx::TestMachineCommand::execute(), openmsx::RestoreMachineCommand::execute(), openmsx::HDCommand::execute(), openmsx::CDXCommand::execute(), openmsx::LSXCommand::execute(), openmsx::RemoveExtCmd::execute(), openmsx::ExtCmd::execute(), ranges::find(), openmsx::FirmwareSwitch::FirmwareSwitch(), openmsx::EventDelay::flush(), openmsx::ImagePrinter::flushEmulatedPrinter(), openmsx::EnumSettingBase::getPossibleValues(), openmsx::Clock< FREQ_NUM, FREQ_DENOM >::getTicksTill(), openmsx::DynamicClock::getTicksTill(), openmsx::Clock< FREQ_NUM, FREQ_DENOM >::getTicksTill_fast(), openmsx::DynamicClock::getTicksTillAsIntFloat(), openmsx::DynamicClock::getTicksTillDouble(), openmsx::Clock< FREQ_NUM, FREQ_DENOM >::getTicksTillUp(), openmsx::DynamicClock::getTicksTillUp(), openmsx::MSXMotherBoard::insertExtension(), openmsx::isRepeatStopper(), openmsx::PNG::load(), openmsx::XMLDocument::load(), openmsx::MSXMotherBoard::loadExtension(), openmsx::MSXMotherBoard::loadMachine(), openmsx::SettingsConfig::loadSetting(), openmsx::matches(), openmsx::MsxChar2Unicode::MsxChar2Unicode(), openmsx::MSXtar::MSXtar(), openmsx::VariantSerializer< V >::Saver::operator()(), openmsx::VariantSerializer< V >::Loader::operator()(), openmsx::EqualEvent::operator()(), openmsx::CommandLineParser::parse(), openmsx::CliExtension::parseOption(), openmsx::PrinterPortLogger::plugHelper(), openmsx::WavAudioInput::plugHelper(), circular_buffer< T >::push_back(), cb_queue< T >::push_back(), openmsx::SectorAccessibleDisk::readSectors(), openmsx::MSXCPUInterface::removeCondition(), openmsx::MSXMotherBoard::removeExtension(), openmsx::Clock< FREQ_NUM, FREQ_DENOM >::reset(), openmsx::DynamicClock::reset(), openmsx::Rom::Rom(), openmsx::RomDatabase::RomDatabase(), openmsx::PostProcessor::rotateFrames(), openmsx::Reactor::run(), openmsx::Connector::serialize(), openmsx::DiskChanger::serialize(), openmsx::Paper::setDotSize(), openmsx::EnumSetting< T >::setEnum(), openmsx::SN76489::SN76489(), openmsx::GlobalCommandController::source(), StringOp::stringToBase(), utf8::unchecked::substr(), openmsx::EventDelay::sync(), openmsx::RemoveExtCmd::tabCompletion(), openmsx::MachineExtensionInfo::tabCompletion(), test(), TEST_CASE(), openmsx::DBParser::text(), ProfileCounters< ENABLED, ENUM >::tick(), openmsx::toTclList(), openmsx::Touchpad::Touchpad(), openmsx::SectorAccessibleDisk::writeSector(), xrange(), openmsx::YM2151::YM2151(), openmsx::YM2413Burczynski::YM2413::YM2413(), openmsx::YM2413Okazaki::YM2413::YM2413(), openmsx::YMF262::YMF262(), openmsx::FirmwareSwitch::~FirmwareSwitch(), openmsx::HardwareConfig::~HardwareConfig(), and openmsx::SettingsConfig::~SettingsConfig().

◆ ln10

constexpr double Math::ln10 = std::numbers::ln10_v<double>
inlineconstexpr

Definition at line 22 of file Math.hh.

◆ ln2

constexpr double Math::ln2 = std::numbers::ln2_v <double>
inlineconstexpr

Definition at line 21 of file Math.hh.

◆ pi

constexpr double Math::pi = std::numbers::pi_v <double>
inlineconstexpr

Definition at line 23 of file Math.hh.

Referenced by gl::degrees(), openmsx::DCFilter::setFreq(), and TEST_CASE().