9 #ifndef ALPS_NUMERIC_IS_ZERO_HPP 10 #define ALPS_NUMERIC_IS_ZERO_HPP 13 #include <type_traits> 15 namespace alps {
namespace numeric {
19 template<
class T,
unsigned int N = 5>
22 static inline T epsilon() {
return 1e-50; }
24 template<
class T>
struct precision<T, 0>;
25 template<
class T>
struct precision<T, 1>
27 static inline T epsilon() {
return 1e-10; }
29 template<
class T>
struct precision<T, 2>
31 static inline T epsilon() {
return 1e-20; }
33 template<
class T>
struct precision<T, 3>
35 static inline T epsilon() {
return 1e-30; }
37 template<
class T>
struct precision<T, 4>
39 static inline T epsilon() {
return 1e-40; }
53 template<
unsigned int N,
class T>
55 typename std::enable_if<std::is_arithmetic<T>::value >::type* = 0,
56 typename std::enable_if<std::is_float<T>::value >::type* = 0)
57 {
return std::abs(x) < detail::precision<T, N>::epsilon(); }
58 template<
unsigned int N,
class T>
60 typename std::enable_if<std::is_arithmetic<T>::value >::type* = 0,
61 typename std::enable_if<std::is_integral<T>::value >::type* = 0)
66 template<
unsigned int N,
class T>
69 static bool result(
const T& x) {
return x == T(0); }
71 template<
unsigned int N,
class T>
72 struct is_zero_helper<N, std::complex<T> >
74 static bool result(
const std::complex<T>& x)
80 template<
unsigned int N,
class T>
82 typename std::enable_if<!std::is_arithmetic<T>::value >::type* = 0)
87 typename std::enable_if<std::is_arithmetic<T>::value >::type* = 0,
88 typename std::enable_if<std::is_float<T>::value >::type* = 0)
89 {
return std::abs(x) < detail::precision<T>::epsilon(); }
92 typename std::enable_if<std::is_arithmetic<T>::value >::type* = 0,
93 typename std::enable_if<std::is_integral<T>::value >::type* = 0)
97 typename std::enable_if<!std::is_arithmetic<T>::value >::type* = 0)
105 #endif // ALPS_NUMERIC_IS_ZERO_HPP boost::array< T, N > abs(boost::array< T, N > arg)
bool is_zero(T x, typename std::enable_if< std::is_arithmetic< T >::value >::type *=0, typename std::enable_if< std::is_float< T >::value >::type *=0)
checks if a number is zero in case of a floating point number, absolute values less than epsilon (1e-...
traits< Acc >::result_type result(const Acc &acc)