openMSX
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.

template<std::signed_integral T>
int16_t clipToInt16 (T x)
Clip x to range [-32768,32767].

uint8_t clipIntToByte (int x)
Clip x to range [0,255].

constexpr unsigned reverseNBits (unsigned x, unsigned bits)
Reverse the lower N bits of a given value.

constexpr uint8_t reverseByte (uint8_t a)
Reverse the bits in a byte.

unsigned findFirstSet (uint32_t x)
Find the least significant bit that is set.

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>

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

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

## ◆ clipToInt16()

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

Clip x to range [-32768,32767].

Optimized for the case when no clipping is needed.

Definition at line 47 of file Math.hh.

## ◆ cubicHermite()

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

Definition at line 167 of file Math.hh.

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

## ◆ div_floor()

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

Definition at line 197 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 188 of file Math.hh.

Referenced by div_floor(), mod_floor(), and TEST_CASE().

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

Referenced by openmsx::ColecoJoystickIO::peekIO().

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

## ◆ mod_floor()

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

Definition at line 200 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 125 of file Math.hh.

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

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

## ◆ e

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

Definition at line 21 of file Math.hh.

Referenced by cstd::exp(), and cstd::log().

## ◆ ln10

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

Definition at line 23 of file Math.hh.

Referenced by cstd::log10().

## ◆ ln2

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

Definition at line 22 of file Math.hh.

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

## ◆ pi

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