18 #ifndef itkNumericTraits_h
19 #define itkNumericTraits_h
26 #define itkNUMERIC_TRAITS_MIN_MAX_MACRO() \
27 static ValueType min() \
29 return std::numeric_limits< ValueType >::min(); \
31 static ValueType max() \
33 return std::numeric_limits< ValueType >::max(); \
35 static ValueType min(ValueType) \
37 return std::numeric_limits< ValueType >::min(); \
39 static ValueType max(ValueType) \
41 return std::numeric_limits< ValueType >::max(); \
45 #include "vcl_limits.h"
52 template<
typename TValue,
unsigned int VLength>
class FixedArray;
69 template<
typename T >
150 static T
max(
const T &) {
return TraitsType::max(); }
151 static T
min(
const T &) {
return TraitsType::min(); }
164 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
211 template<
typename TArray>
229 class NumericTraits< bool > :
public std::numeric_limits< bool >
241 static const bool ITKCommon_EXPORT
Zero;
242 static const bool ITKCommon_EXPORT
One;
244 static bool min() {
return false; }
245 static bool max() {
return true; }
246 static bool min(
bool) {
return min(); }
247 static bool max(
bool) {
return max(); }
249 static bool IsPositive(
bool val) {
return val; }
251 static bool IsNegative(
bool val) {
return val ?
false :
false; }
252 static bool IsNonnegative(
bool val) {
return val ?
true :
true; }
259 static unsigned int GetLength() {
return 1; }
264 template<
typename TArray>
273 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
286 class NumericTraits< char > :
public std::numeric_limits< char >
298 static const char ITKCommon_EXPORT
Zero;
299 static const char ITKCommon_EXPORT
One;
301 static char min() {
return char(255) < char(0) ? char(-128) : char(0); }
302 static char max() {
return char(255) < char(0) ? char(127) : char(255); }
304 static char min(
char) {
return min(); }
305 static char max(
char) {
return max(); }
310 #if VCL_CHAR_IS_SIGNED
315 static bool IsNegative(
char) {
return false; }
324 static unsigned int GetLength() {
return 1; }
329 template<
typename TArray>
338 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
350 class NumericTraits< signed char > :
public std::numeric_limits< signed char >
362 static const signed char ITKCommon_EXPORT
Zero;
363 static const signed char ITKCommon_EXPORT
One;
365 static signed char min() {
return -128; }
366 static signed char max() {
return 127; }
367 static signed char min(
signed char) {
return min(); }
368 static signed char max(
signed char) {
return max(); }
380 static unsigned int GetLength() {
return 1; }
385 template<
typename TArray>
394 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
406 class NumericTraits< unsigned char > :
public std::numeric_limits< unsigned char >
418 static const unsigned char ITKCommon_EXPORT
Zero;
419 static const unsigned char ITKCommon_EXPORT
One;
423 static unsigned char NonpositiveMin() {
return std::numeric_limits< ValueType >::min(); }
426 static bool IsNegative(
unsigned char val) {
return val ?
false :
false; }
427 static bool IsNonnegative(
unsigned char val) {
return val ?
true :
true; }
434 static unsigned int GetLength() {
return 1; }
439 template<
typename TArray>
448 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
459 class NumericTraits< short > :
public std::numeric_limits< short >
464 typedef unsigned short AbsType;
471 static const short ITKCommon_EXPORT
Zero;
472 static const short ITKCommon_EXPORT
One;
475 static short NonpositiveMin() {
return std::numeric_limits< ValueType >::min(); }
486 static unsigned int GetLength() {
return 1; }
491 template<
typename TArray>
500 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
512 class NumericTraits< unsigned short > :
public std::numeric_limits< unsigned short >
517 typedef unsigned short AbsType;
524 static const unsigned short ITKCommon_EXPORT
Zero;
525 static const unsigned short ITKCommon_EXPORT
One;
528 static unsigned short NonpositiveMin() {
return std::numeric_limits< ValueType >::min(); }
529 static bool IsPositive(
unsigned short val) {
return val !=
Zero; }
531 static bool IsNegative(
unsigned short val) {
return val ?
false :
false; }
532 static bool IsNonnegative(
unsigned short val) {
return val ?
true :
true; }
539 static unsigned int GetLength() {
return 1; }
544 template<
typename TArray>
553 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
564 class NumericTraits< int > :
public std::numeric_limits< int >
576 static const int ITKCommon_EXPORT
Zero;
577 static const int ITKCommon_EXPORT
One;
580 static int NonpositiveMin() {
return std::numeric_limits< ValueType >::min(); }
591 static unsigned int GetLength() {
return 1; }
596 template<
typename TArray>
605 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
617 class NumericTraits< unsigned int > :
public std::numeric_limits< unsigned int >
629 static const unsigned int ITKCommon_EXPORT
Zero;
630 static const unsigned int ITKCommon_EXPORT
One;
632 static unsigned int min(
void) {
return 0; }
633 static unsigned int max(
void) {
return static_cast< unsigned int >( -1 ); }
634 static unsigned int min(
unsigned int) {
return std::numeric_limits< ValueType >::min(); }
635 static unsigned int max(
unsigned int) {
return std::numeric_limits< ValueType >::max(); }
639 static bool IsNegative(
unsigned int val) {
return val ?
false :
false; }
640 static bool IsNonnegative(
unsigned int val) {
return val ?
true :
true; }
647 static unsigned int GetLength() {
return 1; }
652 template<
typename TArray>
661 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
673 class NumericTraits< long > :
public std::numeric_limits< long >
685 static const long ITKCommon_EXPORT
Zero;
686 static const long ITKCommon_EXPORT
One;
689 static long NonpositiveMin() {
return std::numeric_limits< ValueType >::min(); }
700 static unsigned int GetLength() {
return 1; }
705 template<
typename TArray>
714 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
726 class NumericTraits< unsigned long > :
public std::numeric_limits< unsigned long >
738 static const unsigned long ITKCommon_EXPORT
Zero;
739 static const unsigned long ITKCommon_EXPORT
One;
742 static unsigned long NonpositiveMin() {
return std::numeric_limits< ValueType >::min(); }
745 static bool IsNegative(
unsigned long) {
return false; }
753 static unsigned int GetLength() {
return 1; }
758 template<
typename TArray>
767 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
779 class NumericTraits< float > :
public std::numeric_limits< float >
791 static const float ITKCommon_EXPORT
Zero;
792 static const float ITKCommon_EXPORT
One;
795 static float NonpositiveMin() {
return -std::numeric_limits< ValueType >::max(); }
806 static unsigned int GetLength() {
return 1; }
811 template<
typename TArray>
820 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
832 class NumericTraits< double > :
public std::numeric_limits< double >
844 static const double ITKCommon_EXPORT
Zero;
845 static const double ITKCommon_EXPORT
One;
848 static double NonpositiveMin() {
return -std::numeric_limits< ValueType >::max(); }
859 static unsigned int GetLength() {
return 1; }
864 template<
typename TArray>
873 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
885 class NumericTraits< long double > :
public std::numeric_limits< long double >
889 #if defined( __SUNPRO_CC ) && defined( _ILP32 )
905 static const long double ITKCommon_EXPORT
Zero;
906 static const long double ITKCommon_EXPORT
One;
909 static long double NonpositiveMin() {
return -std::numeric_limits< ValueType >::max(); }
920 static unsigned int GetLength() {
return 1; }
925 template<
typename TArray>
934 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
946 class NumericTraits< std::complex< char > >
949 typedef std::complex< char > Self;
951 typedef Self TheType;
956 typedef std::complex< double >
RealType;
961 static const Self ITKCommon_EXPORT
Zero;
962 static const Self ITKCommon_EXPORT
One;
964 static Self
min() {
return std::numeric_limits< Self >::min(); }
965 static Self
max() {
return std::numeric_limits< Self >::max(); }
966 static Self
min(Self) {
return min(); }
967 static Self
max(Self) {
return max(); }
970 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
973 static bool IsPositive(Self val) {
return val.real() > 0; }
974 static bool IsNonpositive(Self val) {
return val.real() <= 0; }
976 #if VCL_CHAR_IS_SIGNED
977 static bool IsNegative(Self val) {
return val.real() < 0; }
978 static bool IsNonnegative(Self val) {
return val.real() >= 0; }
980 static bool IsNegative(Self) {
return false; }
983 static const bool IsSigned = NumericTraits< ValueType >::IsSigned;
988 static unsigned int GetLength(
const Self &) {
return 2; }
989 static unsigned int GetLength() {
return 2; }
993 template<
typename TArray>
999 static void SetLength(Self & m,
const unsigned int s)
1003 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1015 class NumericTraits< std::complex< unsigned char > >
1018 typedef std::complex< unsigned char > Self;
1020 typedef Self TheType;
1022 typedef std::complex< unsigned int >
PrintType;
1025 typedef std::complex< double >
RealType;
1027 typedef std::complex< float >
FloatType;
1030 static const Self ITKCommon_EXPORT
Zero;
1031 static const Self ITKCommon_EXPORT
One;
1033 static Self
min() {
return std::numeric_limits< Self >::min(); }
1034 static Self
max() {
return std::numeric_limits< Self >::max(); }
1035 static Self
min(Self) {
return min(); }
1036 static Self
max(Self) {
return max(); }
1039 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1042 static bool IsPositive(Self val) {
return val.real() > 0; }
1043 static bool IsNonpositive(Self val) {
return val.real() == 0; }
1044 static bool IsNegative(Self) {
return false; }
1046 static const bool IsSigned = NumericTraits< ValueType >::IsSigned;
1051 static unsigned int GetLength(
const Self &) {
return 2; }
1052 static unsigned int GetLength() {
return 2; }
1056 template<
typename TArray>
1062 static void SetLength(Self & m,
const unsigned int s)
1066 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1078 class NumericTraits< std::complex< short > >
1081 typedef std::complex< short > Self;
1083 typedef Self TheType;
1088 typedef std::complex< double >
RealType;
1090 typedef std::complex< float >
FloatType;
1093 static const Self ITKCommon_EXPORT
Zero;
1094 static const Self ITKCommon_EXPORT
One;
1096 static Self
min() {
return std::numeric_limits< Self >::min(); }
1097 static Self
max() {
return std::numeric_limits< Self >::max(); }
1098 static Self
min(Self) {
return min(); }
1099 static Self
max(Self) {
return max(); }
1102 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1105 static bool IsPositive(Self val) {
return val.real() > 0; }
1106 static bool IsNonpositive(Self val) {
return val.real() <= 0; }
1107 static bool IsNegative(Self val) {
return val.real() < 0; }
1108 static bool IsNonnegative(Self val) {
return val.real() >= 0; }
1109 static const bool IsSigned = NumericTraits< ValueType >::IsSigned;
1114 static unsigned int GetLength(
const Self &) {
return 2; }
1115 static unsigned int GetLength() {
return 2; }
1119 template<
typename TArray>
1125 static void SetLength(Self & m,
const unsigned int s)
1129 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1141 class NumericTraits< std::complex< unsigned short > >
1144 typedef std::complex< unsigned short > Self;
1146 typedef Self TheType;
1151 typedef std::complex< double >
RealType;
1153 typedef std::complex< float >
FloatType;
1156 static const Self ITKCommon_EXPORT
Zero;
1157 static const Self ITKCommon_EXPORT
One;
1159 static Self
min() {
return std::numeric_limits< Self >::min(); }
1160 static Self
max() {
return std::numeric_limits< Self >::max(); }
1161 static Self
min(Self) {
return min(); }
1162 static Self
max(Self) {
return max(); }
1165 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1168 static bool IsPositive(Self val) {
return val.real() > 0; }
1169 static bool IsNonpositive(Self val) {
return val.real() == 0; }
1170 static bool IsNegative(Self) {
return false; }
1172 static const bool IsSigned = NumericTraits< ValueType >::IsSigned;
1177 static unsigned int GetLength(
const Self &) {
return 2; }
1178 static unsigned int GetLength() {
return 2; }
1182 template<
typename TArray>
1188 static void SetLength(Self & m,
const unsigned int s)
1192 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1204 class NumericTraits< std::complex< int > >
1207 typedef std::complex< int > Self;
1209 typedef Self TheType;
1214 typedef std::complex< double >
RealType;
1216 typedef std::complex< float >
FloatType;
1219 static const Self ITKCommon_EXPORT
Zero;
1220 static const Self ITKCommon_EXPORT
One;
1222 static Self
min() {
return std::numeric_limits< Self >::min(); }
1223 static Self
max() {
return std::numeric_limits< Self >::max(); }
1224 static Self
min(Self) {
return min(); }
1225 static Self
max(Self) {
return max(); }
1228 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1231 static bool IsPositive(Self val) {
return val.real() > 0; }
1232 static bool IsNonpositive(Self val) {
return val.real() <= 0; }
1233 static bool IsNegative(Self val) {
return val.real() < 0; }
1234 static bool IsNonnegative(Self val) {
return val.real() >= 0; }
1235 static const bool IsSigned = NumericTraits< ValueType >::IsSigned;
1240 static unsigned int GetLength(
const Self &) {
return 2; }
1241 static unsigned int GetLength() {
return 2; }
1245 template<
typename TArray>
1251 static void SetLength(Self & m,
const unsigned int s)
1255 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1267 class NumericTraits< std::complex< unsigned int > >
1270 typedef std::complex< unsigned int > Self;
1272 typedef Self TheType;
1277 typedef std::complex< double >
RealType;
1279 typedef std::complex< float >
FloatType;
1282 static const Self ITKCommon_EXPORT
Zero;
1283 static const Self ITKCommon_EXPORT
One;
1285 static Self
min() {
return std::numeric_limits< Self >::min(); }
1286 static Self
max() {
return std::numeric_limits< Self >::max(); }
1287 static Self
min(Self) {
return min(); }
1288 static Self
max(Self) {
return max(); }
1291 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1294 static bool IsPositive(Self val) {
return val.real() > 0; }
1295 static bool IsNonpositive(Self val) {
return val.real() == 0; }
1296 static bool IsNegative(Self) {
return false; }
1298 static const bool IsSigned = NumericTraits< ValueType >::IsSigned;
1303 static unsigned int GetLength(
const Self &) {
return 2; }
1304 static unsigned int GetLength() {
return 2; }
1308 template<
typename TArray>
1314 static void SetLength(Self & m,
const unsigned int s)
1318 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1330 class NumericTraits< std::complex< long > >
1333 typedef std::complex< long > Self;
1335 typedef Self TheType;
1340 typedef std::complex< double >
RealType;
1342 typedef std::complex< float >
FloatType;
1345 static const Self ITKCommon_EXPORT
Zero;
1346 static const Self ITKCommon_EXPORT
One;
1348 static Self
min() {
return std::numeric_limits< Self >::min(); }
1349 static Self
max() {
return std::numeric_limits< Self >::max(); }
1350 static Self
min(Self) {
return min(); }
1351 static Self
max(Self) {
return max(); }
1354 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1357 static bool IsPositive(Self val) {
return val.real() > 0; }
1358 static bool IsNonpositive(Self val) {
return val.real() <= 0; }
1359 static bool IsNegative(Self val) {
return val.real() < 0; }
1360 static bool IsNonnegative(Self val) {
return val.real() >= 0; }
1361 static const bool IsSigned = NumericTraits< ValueType >::IsSigned;
1366 static unsigned int GetLength(
const Self &) {
return 2; }
1367 static unsigned int GetLength() {
return 2; }
1371 template<
typename TArray>
1377 static void SetLength(Self & m,
const unsigned int s)
1381 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1393 class NumericTraits< std::complex< unsigned long > >
1396 typedef std::complex< unsigned long > Self;
1398 typedef Self TheType;
1403 typedef std::complex< double >
RealType;
1405 typedef std::complex< float >
FloatType;
1408 static const Self ITKCommon_EXPORT
Zero;
1409 static const Self ITKCommon_EXPORT
One;
1411 static Self
min() {
return std::numeric_limits< Self >::min(); }
1412 static Self
max() {
return std::numeric_limits< Self >::max(); }
1413 static Self
min(Self) {
return min(); }
1414 static Self
max(Self) {
return max(); }
1417 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1420 static bool IsPositive(Self val) {
return val.real() > 0; }
1421 static bool IsNonpositive(Self val) {
return val.real() == 0; }
1422 static bool IsNegative(Self) {
return false; }
1424 static const bool IsSigned = NumericTraits< ValueType >::IsSigned;
1429 static unsigned int GetLength(
const Self &) {
return 2; }
1430 static unsigned int GetLength() {
return 2; }
1434 template<
typename TArray>
1440 static void SetLength(Self & m,
const unsigned int s)
1444 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1456 class NumericTraits< std::complex< float > >
1459 typedef std::complex< float > Self;
1461 typedef Self TheType;
1466 typedef std::complex< double >
RealType;
1468 typedef std::complex< float >
FloatType;
1471 static const Self ITKCommon_EXPORT
Zero;
1472 static const Self ITKCommon_EXPORT
One;
1474 static Self
min() {
return std::numeric_limits< Self >::min(); }
1475 static Self
max() {
return std::numeric_limits< Self >::max(); }
1476 static Self
min(Self) {
return min(); }
1477 static Self
max(Self) {
return max(); }
1480 return Self(NumericTraits< float >::NonpositiveMin(), 0.0f);
1483 static bool IsPositive(Self val) {
return val.real() > 0.0; }
1484 static bool IsNonpositive(Self val) {
return val.real() <= 0.0; }
1485 static bool IsNegative(Self val) {
return val.real() < 0.0; }
1486 static bool IsNonnegative(Self val) {
return val.real() >= 0.0; }
1487 static const bool IsSigned = NumericTraits< ValueType >::IsSigned;
1492 static unsigned int GetLength(
const Self &) {
return 2; }
1493 static unsigned int GetLength() {
return 2; }
1497 template<
typename TArray>
1503 static void SetLength(Self & m,
const unsigned int s)
1507 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1519 class NumericTraits< std::complex< double > >
1522 typedef std::complex< double > Self;
1524 typedef Self TheType;
1529 typedef std::complex< double >
RealType;
1531 typedef std::complex< float >
FloatType;
1534 static const Self ITKCommon_EXPORT
Zero;
1535 static const Self ITKCommon_EXPORT
One;
1537 static Self
min() {
return std::numeric_limits< ValueType >::min(); }
1538 static Self
max() {
return std::numeric_limits< ValueType >::max(); }
1539 static Self
min(Self) {
return min(); }
1540 static Self
max(Self) {
return max(); }
1543 return Self(NumericTraits< double >::NonpositiveMin(), 0.0);
1546 static bool IsPositive(Self val) {
return val.real() > 0.0; }
1547 static bool IsNonpositive(Self val) {
return val.real() <= 0.0; }
1548 static bool IsNegative(Self val) {
return val.real() < 0.0; }
1549 static bool IsNonnegative(Self val) {
return val.real() >= 0.0; }
1550 static const bool IsSigned = NumericTraits< ValueType >::IsSigned;
1555 static unsigned int GetLength(
const Self &) {
return 2; }
1556 static unsigned int GetLength() {
return 2; }
1560 template<
typename TArray>
1566 static void SetLength(Self & m,
const unsigned int s)
1570 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1582 class NumericTraits< std::complex< long double > >
1585 typedef std::complex< long double > Self;
1587 typedef Self TheType;
1592 typedef std::complex< long double >
RealType;
1594 typedef std::complex< float >
FloatType;
1597 static const Self ITKCommon_EXPORT
Zero;
1598 static const Self ITKCommon_EXPORT
One;
1600 static Self
min() {
return std::numeric_limits< ValueType >::min(); }
1601 static Self
max() {
return std::numeric_limits< ValueType >::max(); }
1602 static Self
min(Self) {
return min(); }
1603 static Self
max(Self) {
return max(); }
1606 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0.0);
1609 static bool IsPositive(Self val) {
return val.real() > 0.0; }
1610 static bool IsNonpositive(Self val) {
return val.real() <= 0.0; }
1611 static bool IsNegative(Self val) {
return val.real() < 0.0; }
1612 static bool IsNonnegative(Self val) {
return val.real() >= 0.0; }
1613 static const bool IsSigned = NumericTraits< ValueType >::IsSigned;
1618 static unsigned int GetLength(
const Self &) {
return 2; }
1619 static unsigned int GetLength() {
return 2; }
1623 template<
typename TArray>
1629 static void SetLength(Self & m,
const unsigned int s)
1633 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1645 class NumericTraits< long long > :
1646 public std::numeric_limits< long long >
1673 static unsigned int GetLength() {
return 1; }
1678 template<
typename TArray>
1687 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
1699 class NumericTraits< unsigned long long > :
1700 public std::numeric_limits< unsigned long long >
1705 typedef unsigned long long AbsType;
1721 static const bool IsSigned =
false;
1727 static unsigned int GetLength() {
return 1; }
1732 template<
typename TArray>
1741 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
1753 #endif // itkNumericTraits_h
#define itkNUMERIC_TRAITS_MIN_MAX_MACRO()
static T OneValue(const T &)
static void AssignToArray(const T &v, TArray &mv)
static const bool IsSigned
static bool IsPositive(T val)
Simulate a standard C array with copy semnatics.
static bool IsNonnegative(T val)
static T NonpositiveMin(const T &)
std::numeric_limits< T > TraitsType
static unsigned int GetLength()
static void SetLength(T &m, const unsigned int s)
static bool IsNegative(T val)
static T ZeroValue(const T &)
static bool IsNonpositive(T val)
FixedArray< ValueType, 1 > MeasurementVectorType
static const bool IsInteger
static T NonpositiveMin()
static const bool IsComplex
Define additional traits for native types such as int or float.
static unsigned int GetLength(const T &)