18 #ifndef __itkNumericTraits_h
19 #define __itkNumericTraits_h
26 #define itkNUMERIC_TRAITS_MIN_MAX_MACRO() \
27 static ValueType min() \
29 return vcl_numeric_limits< ValueType >::min(); \
31 static ValueType max() \
33 return vcl_numeric_limits< ValueType >::max(); \
35 static ValueType min(ValueType) \
37 return vcl_numeric_limits< ValueType >::min(); \
39 static ValueType max(ValueType) \
41 return vcl_numeric_limits< ValueType >::max(); \
45 #include "vcl_limits.h"
52 template<
typename TValueType,
unsigned int VLength>
class FixedArray;
135 static T
max(
const T &) {
return TraitsType::max(); }
136 static T
min(
const T &) {
return TraitsType::min(); }
149 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
195 template<
class TArray>
213 class NumericTraits< bool > :
public vcl_numeric_limits< bool >
225 static const bool ITKCommon_EXPORT
Zero;
226 static const bool ITKCommon_EXPORT
One;
228 static bool min() {
return false; }
229 static bool max() {
return true; }
230 static bool min(
bool) {
return min(); }
231 static bool max(
bool) {
return max(); }
233 static bool IsPositive(
bool val) {
return val; }
235 static bool IsNegative(
bool val) {
return val ?
false :
false; }
236 static bool IsNonnegative(
bool val) {
return val ?
true :
true; }
240 static unsigned int GetLength() {
return 1; }
245 template<
class TArray>
254 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
266 class NumericTraits< char > :
public vcl_numeric_limits< char >
278 static const char ITKCommon_EXPORT
Zero;
279 static const char ITKCommon_EXPORT
One;
281 static char min() {
return char(255) < char(0) ? char(-128) : char(0); }
282 static char max() {
return char(255) < char(0) ? char(127) : char(255); }
284 static char min(
char) {
return min(); }
285 static char max(
char) {
return max(); }
294 static unsigned int GetLength() {
return 1; }
299 template<
class TArray>
308 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
319 class NumericTraits< signed char > :
public vcl_numeric_limits< signed char >
331 static const signed char ITKCommon_EXPORT
Zero;
332 static const signed char ITKCommon_EXPORT
One;
334 static signed char min() {
return -128; }
335 static signed char max() {
return 127; }
336 static signed char min(
signed char) {
return min(); }
337 static signed char max(
signed char) {
return max(); }
346 static unsigned int GetLength() {
return 1; }
351 template<
class TArray>
360 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
371 class NumericTraits< unsigned char > :
public vcl_numeric_limits< unsigned char >
383 static const unsigned char ITKCommon_EXPORT
Zero;
384 static const unsigned char ITKCommon_EXPORT
One;
388 static unsigned char NonpositiveMin() {
return vcl_numeric_limits< ValueType >::min(); }
391 static bool IsNegative(
unsigned char val) {
return val ?
false :
false; }
392 static bool IsNonnegative(
unsigned char val) {
return val ?
true :
true; }
396 static unsigned int GetLength() {
return 1; }
401 template<
class TArray>
410 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
420 class NumericTraits< short > :
public vcl_numeric_limits< short >
425 typedef unsigned short AbsType;
432 static const short ITKCommon_EXPORT
Zero;
433 static const short ITKCommon_EXPORT
One;
436 static short NonpositiveMin() {
return vcl_numeric_limits< ValueType >::min(); }
444 static unsigned int GetLength() {
return 1; }
449 template<
class TArray>
458 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
469 class NumericTraits< unsigned short > :
public vcl_numeric_limits< unsigned short >
474 typedef unsigned short AbsType;
481 static const unsigned short ITKCommon_EXPORT
Zero;
482 static const unsigned short ITKCommon_EXPORT
One;
485 static unsigned short NonpositiveMin() {
return vcl_numeric_limits< ValueType >::min(); }
486 static bool IsPositive(
unsigned short val) {
return val !=
Zero; }
488 static bool IsNegative(
unsigned short val) {
return val ?
false :
false; }
489 static bool IsNonnegative(
unsigned short val) {
return val ?
true :
true; }
493 static unsigned int GetLength() {
return 1; }
498 template<
class TArray>
507 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
517 class NumericTraits< int > :
public vcl_numeric_limits< int >
529 static const int ITKCommon_EXPORT
Zero;
530 static const int ITKCommon_EXPORT
One;
533 static int NonpositiveMin() {
return vcl_numeric_limits< ValueType >::min(); }
541 static unsigned int GetLength() {
return 1; }
546 template<
class TArray>
555 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
566 class NumericTraits< unsigned int > :
public vcl_numeric_limits< unsigned int >
578 static const unsigned int ITKCommon_EXPORT
Zero;
579 static const unsigned int ITKCommon_EXPORT
One;
581 static unsigned int min(
void) {
return 0; }
582 static unsigned int max(
void) {
return static_cast< unsigned int >( -1 ); }
583 static unsigned int min(
unsigned int) {
return vcl_numeric_limits< ValueType >::min(); }
584 static unsigned int max(
unsigned int) {
return vcl_numeric_limits< ValueType >::max(); }
588 static bool IsNegative(
unsigned int val) {
return val ?
false :
false; }
589 static bool IsNonnegative(
unsigned int val) {
return val ?
true :
true; }
593 static unsigned int GetLength() {
return 1; }
598 template<
class TArray>
607 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
618 class NumericTraits< long > :
public vcl_numeric_limits< long >
630 static const long ITKCommon_EXPORT
Zero;
631 static const long ITKCommon_EXPORT
One;
634 static long NonpositiveMin() {
return vcl_numeric_limits< ValueType >::min(); }
642 static unsigned int GetLength() {
return 1; }
647 template<
class TArray>
656 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
667 class NumericTraits< unsigned long > :
public vcl_numeric_limits< unsigned long >
679 static const unsigned long ITKCommon_EXPORT
Zero;
680 static const unsigned long ITKCommon_EXPORT
One;
683 static unsigned long NonpositiveMin() {
return vcl_numeric_limits< ValueType >::min(); }
686 static bool IsNegative(
unsigned long) {
return false; }
691 static unsigned int GetLength() {
return 1; }
696 template<
class TArray>
705 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
716 class NumericTraits< float > :
public vcl_numeric_limits< float >
728 static const float ITKCommon_EXPORT
Zero;
729 static const float ITKCommon_EXPORT
One;
732 static float NonpositiveMin() {
return -vcl_numeric_limits< ValueType >::max(); }
740 static unsigned int GetLength() {
return 1; }
745 template<
class TArray>
754 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
765 class NumericTraits< double > :
public vcl_numeric_limits< double >
777 static const double ITKCommon_EXPORT
Zero;
778 static const double ITKCommon_EXPORT
One;
781 static double NonpositiveMin() {
return -vcl_numeric_limits< ValueType >::max(); }
789 static unsigned int GetLength() {
return 1; }
794 template<
class TArray>
803 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
814 class NumericTraits< long double > :
public vcl_numeric_limits< long double >
818 #if defined( __SUNPRO_CC ) && defined( _ILP32 )
834 static const long double ITKCommon_EXPORT
Zero;
835 static const long double ITKCommon_EXPORT
One;
838 static long double NonpositiveMin() {
return -vcl_numeric_limits< ValueType >::max(); }
846 static unsigned int GetLength() {
return 1; }
851 template<
class TArray>
860 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
871 class NumericTraits< std::complex< char > >
874 typedef std::complex< char > Self;
876 typedef Self TheType;
881 typedef std::complex< double >
RealType;
886 static const Self ITKCommon_EXPORT
Zero;
887 static const Self ITKCommon_EXPORT
One;
889 static Self
min() {
return vcl_numeric_limits< Self >::min(); }
890 static Self
max() {
return vcl_numeric_limits< Self >::max(); }
891 static Self
min(Self) {
return min(); }
892 static Self
max(Self) {
return max(); }
895 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
898 static bool IsPositive(Self val) {
return val.real() > 0; }
899 static bool IsNonpositive(Self val) {
return val.real() <= 0; }
900 static bool IsNegative(Self val) {
return val.real() < 0; }
901 static bool IsNonnegative(Self val) {
return val.real() >= 0; }
904 static unsigned int GetLength(
const Self &) {
return 2; }
905 static unsigned int GetLength() {
return 2; }
909 template<
class TArray>
915 static void SetLength(Self &,
const unsigned int s)
919 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
930 class NumericTraits< std::complex< unsigned char > >
933 typedef std::complex< unsigned char > Self;
935 typedef Self TheType;
937 typedef std::complex< unsigned int >
PrintType;
940 typedef std::complex< double >
RealType;
945 static const Self ITKCommon_EXPORT
Zero;
946 static const Self ITKCommon_EXPORT
One;
948 static Self
min() {
return vcl_numeric_limits< Self >::min(); }
949 static Self
max() {
return vcl_numeric_limits< Self >::max(); }
950 static Self
min(Self) {
return min(); }
951 static Self
max(Self) {
return max(); }
954 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
957 static bool IsPositive(Self val) {
return val.real() > 0; }
958 static bool IsNonpositive(Self val) {
return val.real() == 0; }
959 static bool IsNegative(Self) {
return false; }
963 static unsigned int GetLength(
const Self &) {
return 2; }
964 static unsigned int GetLength() {
return 2; }
968 template<
class TArray>
974 static void SetLength(Self &,
const unsigned int s)
978 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
989 class NumericTraits< std::complex< short > >
992 typedef std::complex< short > Self;
994 typedef Self TheType;
999 typedef std::complex< double >
RealType;
1001 typedef std::complex< float >
FloatType;
1004 static const Self ITKCommon_EXPORT
Zero;
1005 static const Self ITKCommon_EXPORT
One;
1007 static Self
min() {
return vcl_numeric_limits< Self >::min(); }
1008 static Self
max() {
return vcl_numeric_limits< Self >::max(); }
1009 static Self
min(Self) {
return min(); }
1010 static Self
max(Self) {
return max(); }
1013 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1016 static bool IsPositive(Self val) {
return val.real() > 0; }
1017 static bool IsNonpositive(Self val) {
return val.real() <= 0; }
1018 static bool IsNegative(Self val) {
return val.real() < 0; }
1019 static bool IsNonnegative(Self val) {
return val.real() >= 0; }
1022 static unsigned int GetLength(
const Self &) {
return 2; }
1023 static unsigned int GetLength() {
return 2; }
1027 template<
class TArray>
1033 static void SetLength(Self &,
const unsigned int s)
1037 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1048 class NumericTraits< std::complex< unsigned short > >
1051 typedef std::complex< unsigned short > Self;
1053 typedef Self TheType;
1058 typedef std::complex< double >
RealType;
1060 typedef std::complex< float >
FloatType;
1063 static const Self ITKCommon_EXPORT
Zero;
1064 static const Self ITKCommon_EXPORT
One;
1066 static Self
min() {
return vcl_numeric_limits< Self >::min(); }
1067 static Self
max() {
return vcl_numeric_limits< Self >::max(); }
1068 static Self
min(Self) {
return min(); }
1069 static Self
max(Self) {
return max(); }
1072 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1075 static bool IsPositive(Self val) {
return val.real() > 0; }
1076 static bool IsNonpositive(Self val) {
return val.real() == 0; }
1077 static bool IsNegative(Self) {
return false; }
1081 static unsigned int GetLength(
const Self &) {
return 2; }
1082 static unsigned int GetLength() {
return 2; }
1086 template<
class TArray>
1092 static void SetLength(Self &,
const unsigned int s)
1096 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1107 class NumericTraits< std::complex< int > >
1110 typedef std::complex< int > Self;
1112 typedef Self TheType;
1117 typedef std::complex< double >
RealType;
1119 typedef std::complex< float >
FloatType;
1122 static const Self ITKCommon_EXPORT
Zero;
1123 static const Self ITKCommon_EXPORT
One;
1125 static Self
min() {
return vcl_numeric_limits< Self >::min(); }
1126 static Self
max() {
return vcl_numeric_limits< Self >::max(); }
1127 static Self
min(Self) {
return min(); }
1128 static Self
max(Self) {
return max(); }
1131 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1134 static bool IsPositive(Self val) {
return val.real() > 0; }
1135 static bool IsNonpositive(Self val) {
return val.real() <= 0; }
1136 static bool IsNegative(Self val) {
return val.real() < 0; }
1137 static bool IsNonnegative(Self val) {
return val.real() >= 0; }
1140 static unsigned int GetLength(
const Self &) {
return 2; }
1141 static unsigned int GetLength() {
return 2; }
1145 template<
class TArray>
1151 static void SetLength(Self &,
const unsigned int s)
1155 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1166 class NumericTraits< std::complex< unsigned int > >
1169 typedef std::complex< unsigned int > Self;
1171 typedef Self TheType;
1176 typedef std::complex< double >
RealType;
1178 typedef std::complex< float >
FloatType;
1181 static const Self ITKCommon_EXPORT
Zero;
1182 static const Self ITKCommon_EXPORT
One;
1184 static Self
min() {
return vcl_numeric_limits< Self >::min(); }
1185 static Self
max() {
return vcl_numeric_limits< Self >::max(); }
1186 static Self
min(Self) {
return min(); }
1187 static Self
max(Self) {
return max(); }
1190 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1193 static bool IsPositive(Self val) {
return val.real() > 0; }
1194 static bool IsNonpositive(Self val) {
return val.real() == 0; }
1195 static bool IsNegative(Self) {
return false; }
1199 static unsigned int GetLength(
const Self &) {
return 2; }
1200 static unsigned int GetLength() {
return 2; }
1204 template<
class TArray>
1210 static void SetLength(Self &,
const unsigned int s)
1214 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1225 class NumericTraits< std::complex< long > >
1228 typedef std::complex< long > Self;
1230 typedef Self TheType;
1235 typedef std::complex< double >
RealType;
1237 typedef std::complex< float >
FloatType;
1240 static const Self ITKCommon_EXPORT
Zero;
1241 static const Self ITKCommon_EXPORT
One;
1243 static Self
min() {
return vcl_numeric_limits< Self >::min(); }
1244 static Self
max() {
return vcl_numeric_limits< Self >::max(); }
1245 static Self
min(Self) {
return min(); }
1246 static Self
max(Self) {
return max(); }
1249 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1252 static bool IsPositive(Self val) {
return val.real() > 0; }
1253 static bool IsNonpositive(Self val) {
return val.real() <= 0; }
1254 static bool IsNegative(Self val) {
return val.real() < 0; }
1255 static bool IsNonnegative(Self val) {
return val.real() >= 0; }
1258 static unsigned int GetLength(
const Self &) {
return 2; }
1259 static unsigned int GetLength() {
return 2; }
1263 template<
class TArray>
1269 static void SetLength(Self &,
const unsigned int s)
1273 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1284 class NumericTraits< std::complex< unsigned long > >
1287 typedef std::complex< unsigned long > Self;
1289 typedef Self TheType;
1294 typedef std::complex< double >
RealType;
1296 typedef std::complex< float >
FloatType;
1299 static const Self ITKCommon_EXPORT
Zero;
1300 static const Self ITKCommon_EXPORT
One;
1302 static Self
min() {
return vcl_numeric_limits< Self >::min(); }
1303 static Self
max() {
return vcl_numeric_limits< Self >::max(); }
1304 static Self
min(Self) {
return min(); }
1305 static Self
max(Self) {
return max(); }
1308 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1311 static bool IsPositive(Self val) {
return val.real() > 0; }
1312 static bool IsNonpositive(Self val) {
return val.real() == 0; }
1313 static bool IsNegative(Self) {
return false; }
1317 static unsigned int GetLength(
const Self &) {
return 2; }
1318 static unsigned int GetLength() {
return 2; }
1322 template<
class TArray>
1328 static void SetLength(Self &,
const unsigned int s)
1332 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1343 class NumericTraits< std::complex< float > >
1346 typedef std::complex< float > Self;
1348 typedef Self TheType;
1353 typedef std::complex< double >
RealType;
1355 typedef std::complex< float >
FloatType;
1358 static const Self ITKCommon_EXPORT
Zero;
1359 static const Self ITKCommon_EXPORT
One;
1361 static Self
min() {
return vcl_numeric_limits< Self >::min(); }
1362 static Self
max() {
return vcl_numeric_limits< Self >::max(); }
1363 static Self
min(Self) {
return min(); }
1364 static Self
max(Self) {
return max(); }
1367 return Self(NumericTraits< float >::NonpositiveMin(), 0.0f);
1370 static bool IsPositive(Self val) {
return val.real() > 0.0; }
1371 static bool IsNonpositive(Self val) {
return val.real() <= 0.0; }
1372 static bool IsNegative(Self val) {
return val.real() < 0.0; }
1373 static bool IsNonnegative(Self val) {
return val.real() >= 0.0; }
1376 static unsigned int GetLength(
const Self &) {
return 2; }
1377 static unsigned int GetLength() {
return 2; }
1381 template<
class TArray>
1387 static void SetLength(Self &,
const unsigned int s)
1391 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1402 class NumericTraits< std::complex< double > >
1405 typedef std::complex< double > Self;
1407 typedef Self TheType;
1412 typedef std::complex< double >
RealType;
1414 typedef std::complex< float >
FloatType;
1417 static const Self ITKCommon_EXPORT
Zero;
1418 static const Self ITKCommon_EXPORT
One;
1420 static Self
min() {
return vcl_numeric_limits< ValueType >::min(); }
1421 static Self
max() {
return vcl_numeric_limits< ValueType >::max(); }
1422 static Self
min(Self) {
return min(); }
1423 static Self
max(Self) {
return max(); }
1426 return Self(NumericTraits< double >::NonpositiveMin(), 0.0);
1429 static bool IsPositive(Self val) {
return val.real() > 0.0; }
1430 static bool IsNonpositive(Self val) {
return val.real() <= 0.0; }
1431 static bool IsNegative(Self val) {
return val.real() < 0.0; }
1432 static bool IsNonnegative(Self val) {
return val.real() >= 0.0; }
1435 static unsigned int GetLength(
const Self &) {
return 2; }
1436 static unsigned int GetLength() {
return 2; }
1440 template<
class TArray>
1446 static void SetLength(Self &,
const unsigned int s)
1450 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1461 class NumericTraits< std::complex< long double > >
1464 typedef std::complex< long double > Self;
1466 typedef Self TheType;
1471 typedef std::complex< long double >
RealType;
1473 typedef std::complex< float >
FloatType;
1476 static const Self ITKCommon_EXPORT
Zero;
1477 static const Self ITKCommon_EXPORT
One;
1479 static Self
min() {
return vcl_numeric_limits< ValueType >::min(); }
1480 static Self
max() {
return vcl_numeric_limits< ValueType >::max(); }
1481 static Self
min(Self) {
return min(); }
1482 static Self
max(Self) {
return max(); }
1485 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0.0);
1488 static bool IsPositive(Self val) {
return val.real() > 0.0; }
1489 static bool IsNonpositive(Self val) {
return val.real() <= 0.0; }
1490 static bool IsNegative(Self val) {
return val.real() < 0.0; }
1491 static bool IsNonnegative(Self val) {
return val.real() >= 0.0; }
1494 static unsigned int GetLength(
const Self &) {
return 2; }
1495 static unsigned int GetLength() {
return 2; }
1499 template<
class TArray>
1505 static void SetLength(Self &,
const unsigned int s)
1509 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1520 class NumericTraits< long long > :
1521 public vcl_numeric_limits< long long >
1545 static unsigned int GetLength() {
return 1; }
1550 template<
class TArray>
1559 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
1570 class NumericTraits< unsigned long long > :
1571 public vcl_numeric_limits< unsigned long long >
1576 typedef unsigned long long AbsType;
1595 static unsigned int GetLength() {
return 1; }
1600 template<
class TArray>
1609 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
1620 #endif // __itkNumericTraits_h