Open
Graph Drawing
Framework

 v. 2022.02 (Dogwood)
 

ogdf::Math Namespace Reference

Namespaces

 internal
 

Functions

int binomial (int n, int k)
 Returns \(n \choose k\). More...
 
double binomial_d (int n, int k)
 Returns \(n \choose k\). More...
 
double degreesToRadians (const double &angleInDegrees)
 Converts an angle from degrees to radians. More...
 
int factorial (int n)
 Returns n!. More...
 
double factorial_d (int n)
 Returns n!. More...
 
int floorLog2 (int v)
 A method to obtain the rounded down binary logarithm of v. More...
 
template<class T , class INDEX = int>
gcd (const Array< T, INDEX > &numbers)
 Returns the greatest common divisor of a list of numbers. More...
 
template<typename T >
gcd (T a, T b)
 Returns the greatest common divisor of two numbers. More...
 
void getFraction (double d, int &num, int &denom, const double epsilon=5e-10, const int count=10)
 Converts a double to a fraction. More...
 
double harmonic (unsigned n)
 Returns the n-th harmonic number or 1.0 if n < 1. More...
 
template<typename T >
lcm (T a, T b)
 Returns the least common multipler of two numbers. More...
 
template<typename T >
log2 (T x)
 Returns the logarithm of x to the base 2. More...
 
double log4 (double x)
 Returns the logarithm of x to the base 4. More...
 
template<class Container >
Container::value_type maxValue (const Container &values)
 Returns the maximum of an iterable container of given values. More...
 
template<class Container >
double mean (const Container &values)
 Returns the mean of an iterable container of given values. More...
 
template<class Container >
Container::value_type minValue (const Container &values)
 Returns the minimum of an iterable container of given values. More...
 
template<typename T , typename... Args>
static T nextPower2 (T arg1, T arg2, Args... args)
 Returns the smallest power of 2 that is no less than the given (integral) arguments. More...
 
template<typename T >
nextPower2 (T x)
 Returns the smallest power of 2 that is no less than the given (integral) argument. More...
 
double radiansToDegrees (const double &angleInRadians)
 Converts an angle from radians to degrees. More...
 
template<typename T >
int sgn (T val)
 Returns +1 for val > 0, 0 for val = 0, and -1 for val < 0. More...
 
template<class Container >
double standardDeviation (const Container &values)
 Returns the standard deviation of an iterable container of given values. More...
 
template<class Container >
double standardDeviation (const Container &values, double mean)
 Returns the standard deviation of an iterable container of given values. More...
 
template<class Container >
Container::value_type sum (const Container &values)
 Returns the sum of an iterable container of given values. More...
 
template<typename T >
void updateMax (T &max, const T &newValue)
 Stores the maximum of max and newValue in max. More...
 
template<typename T >
void updateMin (T &min, const T &newValue)
 Stores the minimum of min and newValue in min. More...
 

Variables

constexpr double gamma = 0.57721566490153286061
 The Euler-Mascheroni constant gamma. More...
 
const double log_of_4 = log(4.0)
 The constant log(4.0). More...
 
constexpr double one_rad = 57.29577951308232087679
 The constant \(\frac{180}{\pi}\). More...
 
constexpr double pi = 3.14159265358979323846
 The constant \(\pi\). More...
 
constexpr double pi_180 = 0.01745329251994329576
 The constant \(\frac{\pi}{180}\). More...
 
constexpr double pi_2 = 1.57079632679489661923
 The constant \(\frac{\pi}{2}\). More...
 

Function Documentation

◆ binomial()

int ogdf::Math::binomial ( int  n,
int  k 
)

Returns \(n \choose k\).

◆ binomial_d()

double ogdf::Math::binomial_d ( int  n,
int  k 
)

Returns \(n \choose k\).

◆ degreesToRadians()

double ogdf::Math::degreesToRadians ( const double &  angleInDegrees)
inline

Converts an angle from degrees to radians.

Definition at line 128 of file Math.h.

◆ factorial()

int ogdf::Math::factorial ( int  n)
inline

Returns n!.

Deprecated:
"Use std::tgamma(n+1)."

Definition at line 145 of file Math.h.

◆ factorial_d()

double ogdf::Math::factorial_d ( int  n)
inline

Returns n!.

Deprecated:
"Use std::tgamma(n+1)."

Definition at line 151 of file Math.h.

◆ floorLog2()

int ogdf::Math::floorLog2 ( int  v)
inline

A method to obtain the rounded down binary logarithm of v.

Parameters
vThe number of which the binary logarithm is to be determined
Returns
The rounded down logarithm base 2 if v is positive, -1 otherwise
Deprecated:
"Use std::ilogb(v)."

Definition at line 165 of file Math.h.

◆ gcd() [1/2]

template<class T , class INDEX = int>
T ogdf::Math::gcd ( const Array< T, INDEX > &  numbers)
inline

Returns the greatest common divisor of a list of numbers.

Definition at line 187 of file Math.h.

◆ gcd() [2/2]

template<typename T >
T ogdf::Math::gcd ( a,
b 
)
inline

Returns the greatest common divisor of two numbers.

Definition at line 175 of file Math.h.

◆ getFraction()

void ogdf::Math::getFraction ( double  d,
int &  num,
int &  denom,
const double  epsilon = 5e-10,
const int  count = 10 
)
inline

Converts a double to a fraction.

Definition at line 204 of file Math.h.

◆ harmonic()

double ogdf::Math::harmonic ( unsigned  n)

Returns the n-th harmonic number or 1.0 if n < 1.

◆ lcm()

template<typename T >
T ogdf::Math::lcm ( a,
b 
)
inline

Returns the least common multipler of two numbers.

Definition at line 197 of file Math.h.

◆ log2()

template<typename T >
T ogdf::Math::log2 ( x)
inline

Returns the logarithm of x to the base 2.

Deprecated:
"Use std::log2(x)."

Definition at line 110 of file Math.h.

◆ log4()

double ogdf::Math::log4 ( double  x)
inline

Returns the logarithm of x to the base 4.

Definition at line 116 of file Math.h.

◆ maxValue()

template<class Container >
Container::value_type ogdf::Math::maxValue ( const Container &  values)
inline

Returns the maximum of an iterable container of given values.

Definition at line 238 of file Math.h.

◆ mean()

template<class Container >
double ogdf::Math::mean ( const Container &  values)
inline

Returns the mean of an iterable container of given values.

Definition at line 251 of file Math.h.

◆ minValue()

template<class Container >
Container::value_type ogdf::Math::minValue ( const Container &  values)
inline

Returns the minimum of an iterable container of given values.

Definition at line 231 of file Math.h.

◆ nextPower2() [1/2]

template<typename T , typename... Args>
static T ogdf::Math::nextPower2 ( arg1,
arg2,
Args...  args 
)
inlinestatic

Returns the smallest power of 2 that is no less than the given (integral) arguments.

Definition at line 87 of file Math.h.

◆ nextPower2() [2/2]

template<typename T >
T ogdf::Math::nextPower2 ( x)
inline

Returns the smallest power of 2 that is no less than the given (integral) argument.

Definition at line 81 of file Math.h.

◆ radiansToDegrees()

double ogdf::Math::radiansToDegrees ( const double &  angleInRadians)
inline

Converts an angle from radians to degrees.

Definition at line 133 of file Math.h.

◆ sgn()

template<typename T >
int ogdf::Math::sgn ( val)
inline

Returns +1 for val > 0, 0 for val = 0, and -1 for val < 0.

Definition at line 123 of file Math.h.

◆ standardDeviation() [1/2]

template<class Container >
double ogdf::Math::standardDeviation ( const Container &  values)
inline

Returns the standard deviation of an iterable container of given values.

Definition at line 271 of file Math.h.

◆ standardDeviation() [2/2]

template<class Container >
double ogdf::Math::standardDeviation ( const Container &  values,
double  mean 
)
inline

Returns the standard deviation of an iterable container of given values.

The given mean is used instead of computing a new one.

Definition at line 259 of file Math.h.

◆ sum()

template<class Container >
Container::value_type ogdf::Math::sum ( const Container &  values)
inline

Returns the sum of an iterable container of given values.

Definition at line 245 of file Math.h.

◆ updateMax()

template<typename T >
void ogdf::Math::updateMax ( T &  max,
const T &  newValue 
)
inline

Stores the maximum of max and newValue in max.

Definition at line 93 of file Math.h.

◆ updateMin()

template<typename T >
void ogdf::Math::updateMin ( T &  min,
const T &  newValue 
)
inline

Stores the minimum of min and newValue in min.

Definition at line 101 of file Math.h.

Variable Documentation

◆ gamma

constexpr double ogdf::Math::gamma = 0.57721566490153286061
constexpr

The Euler-Mascheroni constant gamma.

Definition at line 77 of file Math.h.

◆ log_of_4

const double ogdf::Math::log_of_4 = log(4.0)

The constant log(4.0).

Definition at line 74 of file Math.h.

◆ one_rad

constexpr double ogdf::Math::one_rad = 57.29577951308232087679
constexpr

The constant \(\frac{180}{\pi}\).

Definition at line 71 of file Math.h.

◆ pi

constexpr double ogdf::Math::pi = 3.14159265358979323846
constexpr

The constant \(\pi\).

Definition at line 62 of file Math.h.

◆ pi_180

constexpr double ogdf::Math::pi_180 = 0.01745329251994329576
constexpr

The constant \(\frac{\pi}{180}\).

Definition at line 68 of file Math.h.

◆ pi_2

constexpr double ogdf::Math::pi_2 = 1.57079632679489661923
constexpr

The constant \(\frac{\pi}{2}\).

Definition at line 65 of file Math.h.