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;
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) < 0 ? -128 : 0; }
282 static char max() {
return char(255) < 0 ? 127 : 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;
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;
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;
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;
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 ); }
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;
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;
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;
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;
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;
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< float > >
874 typedef std::complex< float > 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;
891 static Self
min(Self) {
return min(); }
892 static Self
max(Self) {
return max(); }
895 return Self(-NumericTraits< float >::NonpositiveMin(), 0.0f);
898 static bool IsPositive(Self val) {
return val.real() > 0.0; }
899 static bool IsNonpositive(Self val) {
return val.real() <= 0.0; }
900 static bool IsNegative(Self val) {
return val.real() < 0.0; }
901 static bool IsNonnegative(Self val) {
return val.real() >= 0.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< double > >
933 typedef std::complex< double > Self;
935 typedef Self TheType;
940 typedef std::complex< double >
RealType;
945 static const Self ITKCommon_EXPORT
Zero;
946 static const Self ITKCommon_EXPORT
One;
950 static Self
min(Self) {
return min(); }
951 static Self
max(Self) {
return max(); }
954 return Self(-NumericTraits< double >::NonpositiveMin(), 0.0);
957 static bool IsPositive(Self val) {
return val.real() > 0.0; }
958 static bool IsNonpositive(Self val) {
return val.real() <= 0.0; }
959 static bool IsNegative(Self val) {
return val.real() < 0.0; }
960 static bool IsNonnegative(Self val) {
return val.real() >= 0.0; }
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< long long > :
990 public vcl_numeric_limits< long long >
1014 static unsigned int GetLength() {
return 1; }
1019 template<
class TArray>
1028 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
1039 class NumericTraits< unsigned long long > :
1040 public vcl_numeric_limits< unsigned long long >
1045 typedef unsigned long long AbsType;
1064 static unsigned int GetLength() {
return 1; }
1069 template<
class TArray>
1078 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
1089 #endif // __itkNumericTraits_h