openMSX
Namespaces | Macros | Functions
Math.hh File Reference
#include "likely.hh"
#include <cmath>
#include <cstdint>
Include dependency graph for Math.hh:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

 Math
 

Macros

#define M_E   2.7182818284590452354
 
#define M_LN2   0.69314718055994530942
 
#define M_LN10   2.30258509299404568402
 
#define M_PI   3.14159265358979323846
 

Functions

template<typename T >
constexpr T Math::log2p1 (T x) noexcept
 Returns the number of bits needed to store the value 'x', that is: for x==0 : 0 for x!=0 : 1 + floor(log2(x)) This will be part of c++20: https://en.cppreference.com/w/cpp/numeric/log2p1. More...
 
template<typename T >
constexpr bool Math::ispow2 (T x) noexcept
 Is the given number an integral power of two? That is, does it have exactly one 1-bit in binary representation. More...
 
template<typename T >
constexpr T Math::floodRight (T x) noexcept
 Returns the smallest number of the form 2^n-1 that is greater or equal to the given number. More...
 
template<typename T >
constexpr T Math::ceil2 (T x) noexcept
 Returns the smallest number that is both >=a and a power of two. More...
 
template<int LO, int HI>
int Math::clip (int x)
 Clips x to the range [LO,HI]. More...
 
int16_t Math::clipIntToShort (int x)
 Clip x to range [-32768,32767]. More...
 
uint8_t Math::clipIntToByte (int x)
 Clip x to range [0,255]. More...
 
unsigned Math::gcd (unsigned a, unsigned b)
 Calculate greatest common divider of two strictly positive integers. More...
 
unsigned Math::reverseNBits (unsigned x, unsigned bits)
 Reverse the lower N bits of a given value. More...
 
uint8_t Math::reverseByte (uint8_t a)
 Reverse the bits in a byte. More...
 
unsigned Math::countLeadingZeros (unsigned x)
 Count the number of leading zero-bits in the given word. More...
 
unsigned Math::findFirstSet (unsigned x)
 Find the least significant bit that is set. More...
 

Macro Definition Documentation

◆ M_E

#define M_E   2.7182818284590452354

Definition at line 17 of file Math.hh.

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

◆ M_LN10

#define M_LN10   2.30258509299404568402

Definition at line 23 of file Math.hh.

◆ M_LN2

#define M_LN2   0.69314718055994530942

Definition at line 20 of file Math.hh.

Referenced by cstd::exp2().

◆ M_PI

#define M_PI   3.14159265358979323846

Definition at line 26 of file Math.hh.

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