Molassembler  3.0.1
Molecule graph and conformer library
Math.h File Reference

constexpr math implementations More...

#include "Molassembler/Temple/Preprocessor.h"
#include <cmath>
#include <limits>
#include <type_traits>
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

 Scine::Molassembler
 Central library namespace.
 
 Scine::Molassembler::Temple
 Template shorthands, optimizers and constexpr data types.
 

Typedefs

template<typename T , typename U >
using Scine::Molassembler::Temple::Math::Traits::enableIfFloatingWithReturn = std::enable_if_t< std::is_floating_point< T >::value, U >
 
template<typename T , typename U >
using Scine::Molassembler::Temple::Math::Traits::enableIfIntegralWithReturn = std::enable_if_t< std::is_integral< T >::value, U >
 
template<typename T , typename U >
using Scine::Molassembler::Temple::Math::Traits::enableIfArithmeticWithReturn = std::enable_if_t< std::is_arithmetic< T >::value, U >
 

Functions

template<typename FloatingPoint >
constexpr PURITY_STRONG std::enable_if_t< std::is_floating_point< FloatingPoint >::value, bool > Scine::Molassembler::Temple::Math::Traits::isnan (const FloatingPoint x)
 
template<typename ... Bools>
constexpr bool Scine::Molassembler::Temple::Math::XOR (Bools ... bools)
 Template parameter-pack exclusive or of booleans.
 
template<typename T >
constexpr Traits::enableIfArithmeticWithReturn< T, T > Scine::Molassembler::Temple::Math::abs (T x) noexcept
 Absolute value.
 
template<typename T >
constexpr Traits::enableIfArithmeticWithReturn< T, T > Scine::Molassembler::Temple::Math::max (T a, T b) noexcept
 Maximum of two values.
 
template<typename T >
constexpr Traits::enableIfArithmeticWithReturn< T, T > Scine::Molassembler::Temple::Math::min (T a, T b) noexcept
 Minimum of two values.
 
template<typename T >
constexpr Traits::enableIfFloatingWithReturn< T, T > Scine::Molassembler::Temple::Math::toRadians (T inDegrees) noexcept
 Convert angular degrees to radians.
 
template<typename T >
constexpr Traits::enableIfFloatingWithReturn< T, T > Scine::Molassembler::Temple::Math::toDegrees (T inRadians) noexcept
 Convert angular radians to degrees.
 
template<typename T , typename U >
constexpr Traits::enableIfFloatingWithReturn< T, T > Scine::Molassembler::Temple::Math::fmod (T value, U divider) noexcept
 module function for arbitrary types
 
template<typename T >
constexpr Traits::enableIfFloatingWithReturn< T, long > Scine::Molassembler::Temple::Math::ceil (T value) noexcept
 Ceiling function, no overflow check.
 
template<typename T >
constexpr Traits::enableIfFloatingWithReturn< T, int > Scine::Molassembler::Temple::Math::floor (T value) noexcept
 Floor function.
 
template<typename T >
constexpr Traits::enableIfArithmeticWithReturn< T, T > Scine::Molassembler::Temple::Math::pow (T base, unsigned exponent) noexcept
 Power of a number.
 
template<typename T >
constexpr Traits::enableIfArithmeticWithReturn< T, double > Scine::Molassembler::Temple::Math::pow (T base, int exponent) noexcept
 Integer version that just calls the unsigned power function and inverts the result. More...
 
template<typename T >
constexpr Traits::enableIfFloatingWithReturn< T, T > Scine::Molassembler::Temple::Math::sqrt (T x)
 Square root.
 
template<typename T >
constexpr Traits::enableIfIntegralWithReturn< T, T > Scine::Molassembler::Temple::Math::factorial (T x)
 Factorial.
 
template<typename T >
constexpr Traits::enableIfFloatingWithReturn< T, T > Scine::Molassembler::Temple::Math::ln (T x)
 Natural logarithm.
 
template<typename T >
constexpr Traits::enableIfFloatingWithReturn< T, T > Scine::Molassembler::Temple::Math::log10 (T x)
 Base-10 logarithm.
 
template<typename T >
constexpr Traits::enableIfFloatingWithReturn< T, T > Scine::Molassembler::Temple::Math::log (T x, T base)
 Arbitrary base logarithm.
 
template<typename T >
constexpr Traits::enableIfFloatingWithReturn< T, T > Scine::Molassembler::Temple::Math::asin (T x)
 
template<typename T >
constexpr Traits::enableIfFloatingWithReturn< T, T > Scine::Molassembler::Temple::Math::acos (T x)
 Inverse cosine.
 
template<typename T >
constexpr Traits::enableIfFloatingWithReturn< T, T > Scine::Molassembler::Temple::Math::atan (T x)
 Inverse tangens.
 
template<typename T >
constexpr PURITY_STRONG Traits::enableIfArithmeticWithReturn< T, T > Scine::Molassembler::Temple::Math::abs (const T x) noexcept
 Absolute value.
 
template<typename T >
constexpr PURITY_STRONG Traits::enableIfArithmeticWithReturn< T, T > Scine::Molassembler::Temple::Math::max (const T a, const T b) noexcept
 Maximum of two values.
 
template<typename T >
constexpr PURITY_STRONG Traits::enableIfArithmeticWithReturn< T, T > Scine::Molassembler::Temple::Math::min (const T a, const T b) noexcept
 Minimum of two values.
 
template<typename T >
constexpr PURITY_STRONG Traits::enableIfFloatingWithReturn< T, T > Scine::Molassembler::Temple::Math::toRadians (const T inDegrees) noexcept
 Convert angular degrees to radians.
 
template<typename T >
constexpr PURITY_STRONG Traits::enableIfFloatingWithReturn< T, T > Scine::Molassembler::Temple::Math::toDegrees (const T inRadians) noexcept
 Convert angular radians to degrees.
 
template<typename T , typename U >
constexpr PURITY_STRONG Traits::enableIfFloatingWithReturn< T, T > Scine::Molassembler::Temple::Math::fmod (const T value, const U divider) noexcept
 module function for arbitrary types
 
template<typename T >
constexpr PURITY_STRONG Traits::enableIfFloatingWithReturn< T, long > Scine::Molassembler::Temple::Math::ceil (const T value) noexcept
 Ceiling function, no overflow check.
 
template<typename T >
constexpr PURITY_STRONG Traits::enableIfFloatingWithReturn< T, int > Scine::Molassembler::Temple::Math::floor (const T value) noexcept
 Floor function.
 
template<typename T >
constexpr PURITY_STRONG Traits::enableIfArithmeticWithReturn< T, T > Scine::Molassembler::Temple::Math::pow (const T base, const unsigned exponent) noexcept
 Power of a number.
 
template<typename T >
constexpr PURITY_STRONGScine::Molassembler::Temple::Math::recPow (const T base, const unsigned exponent) noexcept
 
template<typename T >
constexpr PURITY_STRONG Traits::enableIfArithmeticWithReturn< T, double > Scine::Molassembler::Temple::Math::pow (const T base, const int exponent) noexcept
 Integer version that just calls the unsigned power function and inverts the result. More...
 
template<typename T >
constexpr PURITY_STRONG Traits::enableIfFloatingWithReturn< T, T > Scine::Molassembler::Temple::Math::sqrt (const T x)
 Square root.
 
template<typename T >
constexpr PURITY_STRONG Traits::enableIfIntegralWithReturn< T, T > Scine::Molassembler::Temple::Math::factorial (const T x)
 Factorial.
 
template<typename T >
constexpr PURITY_STRONG Traits::enableIfFloatingWithReturn< T, T > Scine::Molassembler::Temple::Math::ln (const T x)
 Natural logarithm.
 
template<typename T >
constexpr PURITY_STRONG Traits::enableIfFloatingWithReturn< T, T > Scine::Molassembler::Temple::Math::log10 (const T x)
 Base-10 logarithm.
 
template<typename T >
constexpr PURITY_STRONG Traits::enableIfFloatingWithReturn< T, T > Scine::Molassembler::Temple::Math::log (const T x, const T base)
 Arbitrary base logarithm.
 
template<typename T >
constexpr PURITY_STRONG Traits::enableIfFloatingWithReturn< T, T > Scine::Molassembler::Temple::Math::asin (const T x)
 
template<typename T >
constexpr PURITY_STRONG Traits::enableIfFloatingWithReturn< T, T > Scine::Molassembler::Temple::Math::acos (const T x)
 Inverse cosine.
 
template<typename T >
constexpr PURITY_STRONG Traits::enableIfFloatingWithReturn< T, T > Scine::Molassembler::Temple::Math::atan (const T x)
 Inverse tangens.
 

Detailed Description

constexpr math implementations

Provides constexpr basic mathematical function implementations, some logical functions and floating-point comparison helpers.

Warning
Do not use these math functions for anything other than constexpr evaluations. The standard library implementations are most definitely better. In many cases, even though it is not required by the standard, the supplied STL functions are constexpr.

Function Documentation

◆ asin() [1/2]

template<typename T >
constexpr PURITY_STRONG Traits::enableIfFloatingWithReturn<T, T> Scine::Molassembler::Temple::Math::asin ( x)
constexpr

Computes the inverse sine function.

NOTE: Accurate to only ~1e-9 absolute deviation close to domain boundaries

◆ asin() [2/2]

template<typename T >
constexpr Traits::enableIfFloatingWithReturn<T, T> Scine::Molassembler::Temple::Math::asin ( x)
constexpr

Computes the inverse sine function.

NOTE: Accurate to only ~1e-9 absolute deviation close to domain boundaries

◆ pow() [1/2]

template<typename T >
constexpr PURITY_STRONG Traits::enableIfArithmeticWithReturn<T, double> Scine::Molassembler::Temple::Math::pow ( const T  base,
const int  exponent 
)
constexprnoexcept

Integer version that just calls the unsigned power function and inverts the result.

Warning
lots can go wrong here!

◆ pow() [2/2]

template<typename T >
constexpr Traits::enableIfArithmeticWithReturn<T, double> Scine::Molassembler::Temple::Math::pow ( const T  base,
const int  exponent 
)
constexprnoexcept

Integer version that just calls the unsigned power function and inverts the result.

Warning
lots can go wrong here!