openMSX
Functions | Variables
Math Namespace Reference

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...
 
int16_t clipIntToShort (int 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 (const float *y, float x)
 

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

References openmsx::x.

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

◆ clipIntToShort()

int16_t Math::clipIntToShort ( int  x)
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 43 of file Math.hh.

References openmsx::x.

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

◆ cubicHermite()

constexpr float Math::cubicHermite ( const float *  y,
float  x 
)
constexpr

Definition at line 162 of file Math.hh.

References openmsx::x.

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

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

References openmsx::x.

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

References openmsx::x.

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

◆ 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 120 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 70 of file Math.hh.

References openmsx::x.

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

Variable Documentation

◆ e

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

Definition at line 18 of file Math.hh.

Referenced by openmsx::Clock< FREQ_NUM, FREQ_DENOM >::advance(), openmsx::DynamicClock::advance(), openmsx::Clock< FREQ_NUM, FREQ_DENOM >::advance_fast(), detail::append(), openmsx::Clock< FREQ_NUM, FREQ_DENOM >::before(), openmsx::DynamicClock::before(), openmsx::XmlInputArchive::beginTag(), openmsx::BreakPointBase::checkAndExecute(), openmsx::V9990VRAM::clear(), openmsx::CliServer::CliServer(), openmsx::IPSPatch::copyBlock(), openmsx::DiskFactory::createDisk(), openmsx::OSDImageBasedWidget::createImage(), openmsx::SDLVisibleSurfaceBase::createSurface(), openmsx::EventDistributor::deliverEvents(), 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(), cstd::exp(), 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(), cstd::log(), 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::Y8950::Y8950(), openmsx::YM2151::YM2151(), openmsx::YM2413Burczynski::YM2413::YM2413(), openmsx::YM2413Okazaki::YM2413::YM2413(), openmsx::FirmwareSwitch::~FirmwareSwitch(), openmsx::HardwareConfig::~HardwareConfig(), and openmsx::SettingsConfig::~SettingsConfig().

◆ ln10

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

Definition at line 20 of file Math.hh.

Referenced by cstd::log10().

◆ ln2

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

Definition at line 19 of file Math.hh.

Referenced by cstd::exp2(), and cstd::log2().

◆ pi

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

Definition at line 21 of file Math.hh.

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