|
Go to the documentation of this file.
34template < class T> struct is_complex : public std::false_type {};
38template < class T> struct is_complex< std::complex<T> > : public std::true_type{};
45std::enable_if_t<std::is_unsigned<T>::value, bool>
46is_zero(T a, T prec = std::numeric_limits<T>::epsilon()) noexcept
54std::enable_if_t<!std::is_unsigned<T>::value &&
55 !detail::is_complex<T>::value, bool>
56is_zero(T a, T prec = std::numeric_limits<T>::epsilon()) noexcept
58 return std::abs(a) <= prec;
64std::enable_if_t<detail::is_complex<T>::value, bool>
66 typename T::value_type prec
67 = std::numeric_limits<typename T::value_type>::epsilon()) noexcept
75bool is_equal(T a, T b, T prec = std::numeric_limits<T>::epsilon()) noexcept
83bool is_equal(std::complex<T> a, std::complex<T> b,
84 T prec = std::numeric_limits<T>::epsilon()) noexcept
86 return is_equal(a.real(), b.real(), prec) &&
93std::enable_if_t<!std::is_unsigned<T>::value, bool>
96 const T max = std::max(std::abs(a), std::abs(b));
97 return is_zero(a - b, max*prec);
104std::enable_if_t<!std::is_unsigned<T>::value, bool>
105is_equal_rel(T a, T b, T prec = std::numeric_limits<T>::epsilon()) noexcept
107 if ( is_equal(a, b, std::numeric_limits<T>::epsilon())) {
111 const T min = std::min(std::abs(a), std::abs(b));
113 if (min < std::numeric_limits<T>::epsilon()) {
117 const T max = std::max(std::abs(a), std::abs(b));
126std::enable_if_t<std::is_unsigned<T>::value, bool>
127is_equal_rel(T a, T b, T prec = std::numeric_limits<T>::epsilon()) noexcept
129 using ST = typename std::make_signed<T>::type;
130 const auto sa = static_cast<ST >(a);
131 const auto sb = static_cast<ST >(b);
132 const auto sprec = static_cast<ST >(prec);
139bool is_finite( const double*, long) noexcept;
143template < typename T, std:: size_t N>
151template < typename T, std:: size_t N>
160std::complex<T> fast_log( const std::complex<T>& z) noexcept
162 const T rz = std::real(z);
163 const T iz = std::imag(z);
165 return std::complex<T>(0.5*std::log(rz*rz + iz*iz), std::atan2(iz, rz));
bool is_equal(T a, T b, T prec=std::numeric_limits< T >::epsilon()) noexcept compares two numbers for (absolute) equality
std::enable_if_t< std::is_unsigned< T >::value, bool > is_zero(T a, T prec=std::numeric_limits< T >::epsilon()) noexcept compares a number for being close to zero
bool is_finite(const gsl_vector *x) Returns true if GSL vector contains only finite elements, false otherwise.
std::complex< T > fast_log(const std::complex< T > &z) noexcept fast implementation of complex logarithm
bool is_equal_rel(const Eigen::PlainObjectBase< Derived > &a, const Eigen::PlainObjectBase< Derived > &b, double eps)
std::enable_if_t<!std::is_unsigned< T >::value, bool > is_equal_fraction(T a, T b, T prec=std::numeric_limits< T >::epsilon()) noexcept compares two numbers for relative equality
|