#pragma once #include #include #include #include #include #include #include namespace AMDiS { namespace Math { /// Implementation of the absolute value \f\$|a|\f\$ of arithmetic types. template constexpr T abs(T const& a) { return a >= 0 ? a : -a; } /// Implementation of the square \f\$ a^2 \f\$ of arithmetic types. template constexpr auto sqr(T const& a) { return a*a; } /// Implementation of the power \f\$ v^p \f\$ of arithmetic types `T`. template constexpr auto pow(T const& v) { static_assert( p >= 0, "Exponent p in `pow

(v)` should be >= 0," ); return Dune::Power

::eval(v); } /// Implementation of the minimum of two values \f\$ min(a,b)\f\$ of any type /// supporting the `<` relation. /// @{ template constexpr auto min(T0 a, T1 b) { return a < b ? a : b; } template constexpr T0 min(T0 a) { return a; } template constexpr auto min(T0 a, Ts... ts) { return min(a, min(ts...)); } /// @} /// Implementation of the maximum of two values \f\$ max(a,b)\f\$ of any type /// supporting the `>` relation. /// @{ template constexpr auto max(T0 a, T1 b) { return a < b ? b : a; } template constexpr T0 max(T0 a) { return a; } template constexpr auto max(T0 a, Ts... ts) { return max(a, max(ts...)); } /// @} } // end namespace Math template inline void nullify(T& a) { a = 0; } inline void nullify(std::string& s) { s = ""; } template constexpr T threshold = std::numeric_limits::epsilon(); /// Calculates factorial of i constexpr std::uint64_t factorial(std::uint64_t i) { return i <= 1 ? 1 : i * factorial(i - 1); } /// check for inf and nan values inline bool isNumber(double val) { return !std::isnan(val) && !std::isinf(val); } } // end namespace AMDiS