11#ifndef NDARRAY_types_h_INCLUDED
12#define NDARRAY_types_h_INCLUDED
19#include <boost/type_traits/is_complex.hpp>
33template <typename T, typename U=typename boost::remove_const<T>::type,
34 typename is_complex=
typename boost::is_complex<U>::type,
35 typename is_arithmetic=
typename boost::is_arithmetic<U>::type>
39template <
typename T,
typename U>
42 typedef boost::true_type IsReal;
44 typedef std::complex<U> ComplexType;
47 static const int PRIORITY =
sizeof(U) + (
sizeof(
long long) * (!std::numeric_limits<U>::is_integer));
50template <
typename T,
typename U>
51struct NumericTraits<T,U,boost::true_type,boost::false_type> {
53 typedef boost::false_type IsReal;
54 typedef typename U::value_type RealType;
55 typedef U ComplexType;
56 typedef U
const & ParamType;
58 static const int PRIORITY = NumericTraits<RealType>::PRIORITY;
66template <
typename T1,
typename T2,
67 bool winner=(NumericTraits<T1>::PRIORITY > NumericTraits<T2>::PRIORITY),
68 bool is_complex=(NumericTraits<T1>::IsReal::value && NumericTraits<T2>::IsReal::value)
76template <
typename T1,
typename T2>
77struct Promote<T1,T2,false,true> {
82template <
typename T1,
typename T2>
83struct Promote<T1,T2,true,true> {
84 typedef typename NumericTraits<T1>::Type Type;
88template <
typename T1,
typename T2>
89struct Promote<T1,T2,false,false> {
90 typedef typename NumericTraits<T2>::ComplexType Type;
94template <
typename T1,
typename T2>
95struct Promote<T1,T2,true,false> {
96 typedef typename NumericTraits<T1>::ComplexType Type;
114 static inline T divide(T a, T b) {
115 if (b <
static_cast<T
>(1) && a > b*std::numeric_limits<T>::max())
116 return std::numeric_limits<T>::max();
117 if (a ==
static_cast<T
>(0) || (b >
static_cast<T
>(1) && a < b*std::numeric_limits<T>::min()))
118 return static_cast<T
>(0);
122 static inline T abs(T a) {
123 return (a <
static_cast<T
>(0)) ? -a : a;
136template <
typename T1,
typename T2=T1>
138 typedef T1 first_argument_type;
139 typedef T2 second_argument_type;
140 typedef bool result_type;
145 result_type operator()(T1 a, T2 b)
const {
146 Promoted diff = Ops::abs(a - b);
147 Promoted da = Ops::divide(diff,Ops::abs(a));
148 Promoted db = Ops::divide(diff,Ops::abs(b));
149 return db <= _tolerance && da <= _tolerance;
164template <
typename U1,
typename U2>
166 typedef std::complex<U1> first_argument_type;
167 typedef std::complex<U2> second_argument_type;
168 typedef bool result_type;
172 result_type operator()(std::complex<U1>
const & a, std::complex<U2>
const & b)
const {
173 return _real(a.real(),b.real()) && _real(a.imag(),b.imag());
Binary predicate for floating point equality comparison with tolerance.
Definition types.h:137
Numeric type traits.
Definition types.h:36