AutoPas  3.0.0
Loading...
Searching...
No Matches
Namespaces | Functions | Variables
Math.h File Reference
#include <Eigen/Core>
#include <cmath>
#include <vector>
Include dependency graph for Math.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  autopas
 This is the main namespace of AutoPas.
 
namespace  autopas::utils
 In this namespace some helper classes and functions can be found used inside of AutoPas.
 

Functions

template<class Int_t , std::enable_if_t< std::is_integral_v< Int_t >, bool > = true>
Int_t autopas::utils::Math::safeAdd (const Int_t &a, const Int_t &b, const Int_t &valUnderflow=std::numeric_limits< Int_t >::min(), const Int_t &valOverflow=std::numeric_limits< Int_t >::max())
 Addition function for integer types that is safe against over and underflow.
 
template<class Float_t , std::enable_if_t< std::is_floating_point_v< Float_t >, bool > = true>
Float_t autopas::utils::Math::safeAdd (const Float_t &a, const Float_t &b, const Float_t &valUnderflow=-std::numeric_limits< Float_t >::max(), const Float_t &valOverflow=std::numeric_limits< Float_t >::max())
 Addition function for floating point types that is safe against over and underflow.
 
template<class Int_t , std::enable_if_t< std::is_integral_v< Int_t >, bool > = true>
Int_t autopas::utils::Math::safeSub (const Int_t &a, const Int_t &b, const Int_t &valUnderflow=std::numeric_limits< Int_t >::min(), const Int_t &valOverflow=std::numeric_limits< Int_t >::max())
 Subtraction function for integer types that is safe against over and underflow.
 
template<class Float_t , std::enable_if_t< std::is_floating_point_v< Float_t >, bool > = true>
Float_t autopas::utils::Math::safeSub (const Float_t &a, const Float_t &b, const Float_t &valUnderflow=-std::numeric_limits< Float_t >::max(), const Float_t &valOverflow=std::numeric_limits< Float_t >::max())
 Addition function for floating point types that is safe against over and underflow.
 
template<class Int_t , std::enable_if_t< std::is_integral_v< Int_t >, bool > = true>
Int_t autopas::utils::Math::safeMul (const Int_t &a, const Int_t &b, const Int_t &valUnderflow=std::numeric_limits< Int_t >::min(), const Int_t &valOverflow=std::numeric_limits< Int_t >::max())
 Multiplication function for integer types that is safe against over and underflow.
 
template<class Float_t , std::enable_if_t< std::is_floating_point_v< Float_t >, bool > = true>
Float_t autopas::utils::Math::safeMul (const Float_t &a, const Float_t &b, const Float_t &valUnderflow=-std::numeric_limits< Float_t >::max(), const Float_t &valOverflow=std::numeric_limits< Float_t >::max())
 Multiplication function for floating point types that is safe against over and underflow.
 
template<size_t exponent, class T >
autopas::utils::Math::pow (const T &base)
 No-overhead power function with exponent known at compile time.
 
double autopas::utils::Math::normalPDF (double x)
 Probability density function PDF of the standard normal distribution.
 
double autopas::utils::Math::normalCDF (double x)
 Cumulative distribution function CDF of the standard normal distribution.
 
double autopas::utils::Math::sigmoid (double x)
 Sigmoid logistic function.
 
bool autopas::utils::Math::isNearRel (double a, double b, double maxRelativeDifference=1e-9)
 Determines if two doubles are near each other.
 
bool autopas::utils::Math::isNearAbs (double a, double b, double maxAbsoluteDifference)
 Determines if two doubles are near each other.
 
double autopas::utils::Math::roundFixed (double d, int fixedPrecision)
 Round a floating point number to a given number of decimal digits.
 
double autopas::utils::Math::roundFloating (double d, int floatingPrecision)
 Round a floating point number to a given floating precision.
 
Eigen::VectorXd autopas::utils::Math::makeVectorXd (const std::vector< double > &elements)
 Create a vector of doubles from given elements.
 
Eigen::VectorXi autopas::utils::Math::makeVectorXi (const std::vector< int > &elements)
 Create a vector of ints from given elements.
 

Variables

const double autopas::utils::Math::normalScale = 1. / std::sqrt(2 * M_PI)
 Factor of PDF of standard normal distribution.
 

Detailed Description

Author
Jan Nguyen
Date
18.08.19

Function Documentation

◆ isNearAbs()

bool autopas::utils::Math::isNearAbs ( double  a,
double  b,
double  maxAbsoluteDifference 
)

Determines if two doubles are near each other.

This function should be preferred to comparing with ==.

Parameters
a
b
maxAbsoluteDifferenceinclusive
Returns

◆ isNearRel()

bool autopas::utils::Math::isNearRel ( double  a,
double  b,
double  maxRelativeDifference = 1e-9 
)

Determines if two doubles are near each other.

This function should be preferred to comparing with ==.

Parameters
a
b
maxRelativeDifferenceinclusive, relative to max(|a|, |b|).
Returns

◆ makeVectorXd()

Eigen::VectorXd autopas::utils::Math::makeVectorXd ( const std::vector< double > &  elements)

Create a vector of doubles from given elements.

Parameters
elements
Returns

◆ makeVectorXi()

Eigen::VectorXi autopas::utils::Math::makeVectorXi ( const std::vector< int > &  elements)

Create a vector of ints from given elements.

Parameters
elements
Returns

◆ normalCDF()

double autopas::utils::Math::normalCDF ( double  x)

Cumulative distribution function CDF of the standard normal distribution.

Parameters
x
Returns
CDF(x)

◆ normalPDF()

double autopas::utils::Math::normalPDF ( double  x)

Probability density function PDF of the standard normal distribution.

Parameters
x
Returns
PDF(x)

◆ pow()

template<size_t exponent, class T >
T autopas::utils::Math::pow ( const T &  base)

No-overhead power function with exponent known at compile time.

Template Parameters
exponent
T
Parameters
base
Returns

◆ roundFixed()

double autopas::utils::Math::roundFixed ( double  d,
int  fixedPrecision 
)

Round a floating point number to a given number of decimal digits.

Parameters
dNumber to round.
fixedPrecisionNumber of decimal digits. Negative values lead to rounding of digits left of the decimal.
Returns
d rounded to the given number of digits.

◆ roundFloating()

double autopas::utils::Math::roundFloating ( double  d,
int  floatingPrecision 
)

Round a floating point number to a given floating precision.

Parameters
dNumber to round.
floatingPrecisionNumber of significant digits. Values <0 will return in 0.
Returns
d rounded to the given number of digits.

◆ safeAdd() [1/2]

template<class Float_t , std::enable_if_t< std::is_floating_point_v< Float_t >, bool > = true>
Float_t autopas::utils::Math::safeAdd ( const Float_t &  a,
const Float_t &  b,
const Float_t &  valUnderflow = -std::numeric_limits<Float_t>::max(),
const Float_t &  valOverflow = std::numeric_limits<Float_t>::max() 
)

Addition function for floating point types that is safe against over and underflow.

If over or underflow is detected, the function returns the specified values.

Note
Underflow here refers to a value more negative than representable and not the underflow gap around zero.
Template Parameters
Float_t
Parameters
a
b
valUnderflowReturn value in case of underflow.
valOverflowReturn value in case of overflow.
Returns
Sum or valUnderflow or valOverflow.

◆ safeAdd() [2/2]

template<class Int_t , std::enable_if_t< std::is_integral_v< Int_t >, bool > = true>
Int_t autopas::utils::Math::safeAdd ( const Int_t &  a,
const Int_t &  b,
const Int_t &  valUnderflow = std::numeric_limits<Int_t>::min(),
const Int_t &  valOverflow = std::numeric_limits<Int_t>::max() 
)

Addition function for integer types that is safe against over and underflow.

If over or underflow is detected, the function returns the specified values.

Template Parameters
Int_t
Parameters
a
b
valUnderflowReturn value in case of underflow.
valOverflowReturn value in case of overflow.
Returns
Sum or valOverflow or valUnderflow.

◆ safeMul() [1/2]

template<class Float_t , std::enable_if_t< std::is_floating_point_v< Float_t >, bool > = true>
Float_t autopas::utils::Math::safeMul ( const Float_t &  a,
const Float_t &  b,
const Float_t &  valUnderflow = -std::numeric_limits<Float_t>::max(),
const Float_t &  valOverflow = std::numeric_limits<Float_t>::max() 
)

Multiplication function for floating point types that is safe against over and underflow.

If over or underflow is detected, the function returns the specified values.

Note
Underflow here refers to a value more negative than representable and not the underflow gap around zero.
Template Parameters
Float_t
Parameters
a
b
valUnderflowReturn value in case of underflow.
valOverflowReturn value in case of overflow.
Returns
Product or valUnderflow or valOverflow.

◆ safeMul() [2/2]

template<class Int_t , std::enable_if_t< std::is_integral_v< Int_t >, bool > = true>
Int_t autopas::utils::Math::safeMul ( const Int_t &  a,
const Int_t &  b,
const Int_t &  valUnderflow = std::numeric_limits<Int_t>::min(),
const Int_t &  valOverflow = std::numeric_limits<Int_t>::max() 
)

Multiplication function for integer types that is safe against over and underflow.

If over or underflow is detected, the function returns the specified values.

Template Parameters
Int_t
Parameters
a
b
valUnderflowReturn value in case of underflow.
valOverflowReturn value in case of overflow.
Returns
Product or valUnderflow or valOverflow.

◆ safeSub() [1/2]

template<class Float_t , std::enable_if_t< std::is_floating_point_v< Float_t >, bool > = true>
Float_t autopas::utils::Math::safeSub ( const Float_t &  a,
const Float_t &  b,
const Float_t &  valUnderflow = -std::numeric_limits<Float_t>::max(),
const Float_t &  valOverflow = std::numeric_limits<Float_t>::max() 
)

Addition function for floating point types that is safe against over and underflow.

If over or underflow is detected, the function returns the specified values.

Note
Underflow here refers to a value more negative than representable and not the underflow gap around zero.
Template Parameters
Float_t
Parameters
a
b
valUnderflowReturn value in case of underflow.
valOverflowReturn value in case of overflow.
Returns
Sum or valUnderflow or valOverflow.

◆ safeSub() [2/2]

template<class Int_t , std::enable_if_t< std::is_integral_v< Int_t >, bool > = true>
Int_t autopas::utils::Math::safeSub ( const Int_t &  a,
const Int_t &  b,
const Int_t &  valUnderflow = std::numeric_limits<Int_t>::min(),
const Int_t &  valOverflow = std::numeric_limits<Int_t>::max() 
)

Subtraction function for integer types that is safe against over and underflow.

If over or underflow is detected, the function returns the specified values.

Template Parameters
Int_t
Parameters
a
b
valUnderflowReturn value in case of underflow.
valOverflowReturn value in case of overflow.
Returns
Difference or valOverflow or valUnderflow.

◆ sigmoid()

double autopas::utils::Math::sigmoid ( double  x)

Sigmoid logistic function.

Parameters
x
Returns
S(x)