18 #ifndef itkNumericTraits_h
19 #define itkNumericTraits_h
26 #define itkNUMERIC_TRAITS_MIN_MAX_MACRO() \
27 static constexpr ValueType min(ValueType) { return std::numeric_limits<ValueType>::min(); } \
28 static constexpr ValueType max(ValueType) { return std::numeric_limits<ValueType>::max(); } \
29 static constexpr ValueType min() { return std::numeric_limits<ValueType>::min(); } \
30 static constexpr ValueType max() { return std::numeric_limits<ValueType>::max(); }
39 template <
typename TValue,
unsigned int VLength>
90 static const T ITKCommon_EXPORT
Zero;
93 static const T ITKCommon_EXPORT
One;
99 return TraitsType::lowest();
169 return TraitsType::max();
174 return TraitsType::min();
189 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
241 template <
typename TArray>
259 class NumericTraits<bool> :
public std::numeric_limits<bool>
271 static constexpr
bool ITKCommon_EXPORT
Zero =
false;
272 static constexpr
bool ITKCommon_EXPORT
One =
true;
274 static constexpr
bool
279 static constexpr
bool
284 static constexpr
bool
289 static constexpr
bool
294 static constexpr
bool
299 static constexpr
bool
304 static constexpr
bool
309 static constexpr
bool
312 return val ? false :
false;
314 static constexpr
bool
317 return val ? true :
true;
319 static constexpr
bool IsSigned =
false;
322 static constexpr
bool
327 static constexpr
bool
332 static constexpr
unsigned int
337 static constexpr
unsigned int
358 template <
typename TArray>
369 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
381 class NumericTraits<char> :
public std::numeric_limits<char>
393 static constexpr
char ITKCommon_EXPORT
Zero = 0;
394 static constexpr
char ITKCommon_EXPORT
One = 1;
398 static constexpr
char
403 static constexpr
bool
408 static constexpr
bool
414 static constexpr
bool
419 static constexpr
bool
424 static constexpr
bool IsSigned = std::numeric_limits<char>::is_signed;
426 static constexpr
bool IsInteger = std::numeric_limits<char>::is_integer;
428 static constexpr
char
433 static constexpr
char
438 static constexpr
unsigned int
443 static constexpr
unsigned int
464 template <
typename TArray>
475 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
487 class NumericTraits<signed char> :
public std::numeric_limits<signed char>
499 static constexpr
signed char ITKCommon_EXPORT
Zero = 0;
500 static constexpr
signed char ITKCommon_EXPORT
One = 1;
502 static constexpr
signed char
507 static constexpr
signed char
512 static constexpr
signed char
517 static constexpr
signed char
522 static constexpr
signed char
527 static constexpr
bool
532 static constexpr
bool
537 static constexpr
bool
542 static constexpr
bool
547 static constexpr
bool IsSigned =
true;
550 static constexpr
signed char
555 static constexpr
signed char
560 static constexpr
unsigned int
565 static constexpr
unsigned int
586 template <
typename TArray>
597 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
609 class NumericTraits<unsigned char> :
public std::numeric_limits<unsigned char>
621 static constexpr
unsigned char ITKCommon_EXPORT
Zero = 0;
622 static constexpr
unsigned char ITKCommon_EXPORT
One = 1;
626 static constexpr
unsigned char
629 return std::numeric_limits<ValueType>::lowest();
631 static constexpr
bool
636 static constexpr
bool
641 static constexpr
bool
644 return val ? false :
false;
646 static constexpr
bool
649 return val ? true :
true;
651 static constexpr
bool IsSigned =
false;
654 static constexpr
unsigned char
659 static constexpr
unsigned char
664 static constexpr
unsigned int
669 static constexpr
unsigned int
690 template <
typename TArray>
701 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
712 class NumericTraits<short> :
public std::numeric_limits<short>
717 using AbsType =
unsigned short;
724 static constexpr
short ITKCommon_EXPORT
Zero = 0;
725 static constexpr
short ITKCommon_EXPORT
One = 1;
728 static constexpr
short
731 return std::numeric_limits<ValueType>::lowest();
733 static constexpr
bool
738 static constexpr
bool
743 static constexpr
bool
748 static constexpr
bool
753 static constexpr
bool IsSigned =
true;
756 static constexpr
short
761 static constexpr
short
766 static constexpr
unsigned int
771 static constexpr
unsigned int
792 template <
typename TArray>
803 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
815 class NumericTraits<unsigned short> :
public std::numeric_limits<unsigned short>
820 using AbsType =
unsigned short;
827 static constexpr
unsigned short ITKCommon_EXPORT
Zero = 0;
828 static constexpr
unsigned short ITKCommon_EXPORT
One = 1;
831 static constexpr
unsigned short
834 return std::numeric_limits<ValueType>::lowest();
836 static constexpr
bool
841 static constexpr
bool
846 static constexpr
bool
849 return val ? false :
false;
851 static constexpr
bool
854 return val ? true :
true;
856 static constexpr
bool IsSigned =
false;
859 static constexpr
unsigned short
864 static constexpr
unsigned short
869 static constexpr
unsigned int
874 static constexpr
unsigned int
895 template <
typename TArray>
906 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
917 class NumericTraits<int> :
public std::numeric_limits<int>
929 static constexpr
int ITKCommon_EXPORT
Zero = 0;
930 static constexpr
int ITKCommon_EXPORT
One = 1;
936 return std::numeric_limits<ValueType>::lowest();
938 static constexpr
bool
943 static constexpr
bool
948 static constexpr
bool
953 static constexpr
bool
958 static constexpr
bool IsSigned =
true;
971 static constexpr
unsigned int
976 static constexpr
unsigned int
997 template <
typename TArray>
1008 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
1020 class NumericTraits<unsigned int> :
public std::numeric_limits<unsigned int>
1032 static constexpr
unsigned int ITKCommon_EXPORT
Zero = 0;
1033 static constexpr
unsigned int ITKCommon_EXPORT
One = 1;
1035 static constexpr
unsigned int
1040 static constexpr
unsigned int
1043 return static_cast<unsigned int>(-1);
1045 static constexpr
unsigned int
1048 return std::numeric_limits<ValueType>::min();
1050 static constexpr
unsigned int
1053 return std::numeric_limits<ValueType>::max();
1055 static constexpr
unsigned int
1060 static constexpr
bool
1065 static constexpr
bool
1070 static constexpr
bool
1073 return val ? false :
false;
1075 static constexpr
bool
1078 return val ? true :
true;
1080 static constexpr
bool IsSigned =
false;
1082 static constexpr
bool IsComplex =
false;
1083 static constexpr
unsigned int
1088 static constexpr
unsigned int
1093 static constexpr
unsigned int
1098 static constexpr
unsigned int
1119 template <
typename TArray>
1130 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
1142 class NumericTraits<long> :
public std::numeric_limits<long>
1147 using AbsType =
unsigned long;
1154 static constexpr
long ITKCommon_EXPORT
Zero = 0L;
1155 static constexpr
long ITKCommon_EXPORT
One = 1L;
1158 static constexpr
long
1161 return std::numeric_limits<ValueType>::lowest();
1163 static constexpr
bool
1168 static constexpr
bool
1173 static constexpr
bool
1178 static constexpr
bool
1183 static constexpr
bool IsSigned =
true;
1185 static constexpr
bool IsComplex =
false;
1186 static constexpr
long
1191 static constexpr
long
1196 static constexpr
unsigned int
1201 static constexpr
unsigned int
1222 template <
typename TArray>
1233 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
1245 class NumericTraits<unsigned long> :
public std::numeric_limits<unsigned long>
1250 using AbsType =
unsigned long;
1257 static constexpr
unsigned long ITKCommon_EXPORT
Zero = 0UL;
1258 static constexpr
unsigned long ITKCommon_EXPORT
One = 1UL;
1261 static constexpr
unsigned long
1264 return std::numeric_limits<ValueType>::lowest();
1266 static constexpr
bool
1271 static constexpr
bool
1276 static constexpr
bool
1281 static constexpr
bool
1286 static constexpr
bool IsSigned =
false;
1288 static constexpr
bool IsComplex =
false;
1289 static constexpr
unsigned long
1294 static constexpr
unsigned long
1299 static constexpr
unsigned int
1304 static constexpr
unsigned int
1325 template <
typename TArray>
1336 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
1348 class NumericTraits<float> :
public std::numeric_limits<float>
1361 static constexpr
float ITKCommon_EXPORT
Zero = 0.0f;
1362 static constexpr
float ITKCommon_EXPORT
One = 1.0f;
1365 static constexpr
float
1368 return std::numeric_limits<ValueType>::lowest();
1370 static constexpr
bool
1375 static constexpr
bool
1380 static constexpr
bool
1385 static constexpr
bool
1390 static constexpr
bool IsSigned =
true;
1391 static constexpr
bool IsInteger =
false;
1392 static constexpr
bool IsComplex =
false;
1393 static constexpr
float
1398 static constexpr
float
1403 static constexpr
unsigned int
1408 static constexpr
unsigned int
1429 template <
typename TArray>
1440 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
1452 class NumericTraits<double> :
public std::numeric_limits<double>
1464 static constexpr
double ITKCommon_EXPORT
Zero = 0.0;
1465 static constexpr
double ITKCommon_EXPORT
One = 1.0;
1468 static constexpr
double
1471 return std::numeric_limits<ValueType>::lowest();
1473 static constexpr
bool
1478 static constexpr
bool
1483 static constexpr
bool
1488 static constexpr
bool
1493 static constexpr
bool IsSigned =
true;
1494 static constexpr
bool IsInteger =
false;
1495 static constexpr
bool IsComplex =
false;
1496 static constexpr
double
1501 static constexpr
double
1506 static constexpr
unsigned int
1511 static constexpr
unsigned int
1532 template <
typename TArray>
1543 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
1555 class NumericTraits<long double> :
public std::numeric_limits<long double>
1559 #if defined(__SUNPRO_CC) && defined(_ILP32)
1575 static constexpr
long double ITKCommon_EXPORT
Zero = 0.0;
1576 static constexpr
long double ITKCommon_EXPORT
One = 1.0;
1579 static constexpr
long double
1582 return std::numeric_limits<ValueType>::lowest();
1584 static constexpr
bool
1589 static constexpr
bool
1594 static constexpr
bool
1599 static constexpr
bool
1604 static constexpr
bool IsSigned =
true;
1605 static constexpr
bool IsInteger =
false;
1606 static constexpr
bool IsComplex =
false;
1607 static constexpr
long double
1612 static constexpr
long double
1617 static constexpr
unsigned int
1622 static constexpr
unsigned int
1643 template <
typename TArray>
1654 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
1667 class NumericTraits<long long> :
public std::numeric_limits<long long>
1686 return std::numeric_limits<ValueType>::lowest();
1688 static constexpr
bool
1693 static constexpr
bool
1698 static constexpr
bool
1703 static constexpr
bool
1708 static constexpr
bool IsSigned =
true;
1710 static constexpr
bool IsComplex =
false;
1721 static constexpr
unsigned int
1726 static constexpr
unsigned int
1747 template <
typename TArray>
1758 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
1770 class NumericTraits<unsigned long long> :
public std::numeric_limits<unsigned long long>
1775 using AbsType =
unsigned long long;
1783 static constexpr
ValueType ITKCommon_EXPORT
One = 1ULL;
1789 return std::numeric_limits<ValueType>::lowest();
1791 static constexpr
bool
1796 static constexpr
bool
1803 static constexpr
bool IsSigned =
false;
1805 static constexpr
bool IsComplex =
false;
1816 static constexpr
unsigned int
1821 static constexpr
unsigned int
1842 template <
typename TArray>
1853 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
1865 template <
typename TComponent>
1866 class NumericTraits<std::complex<TComponent>>
1869 using Self = std::complex<TComponent>;
1871 using TheType = Self;
1876 using RealType = std::complex<double>;
1881 static const Self ITKCommon_EXPORT
Zero;
1882 static const Self ITKCommon_EXPORT
One;
1884 static constexpr Self
1887 return std::numeric_limits<ValueType>::min();
1889 static constexpr Self
1892 return std::numeric_limits<ValueType>::max();
1894 static constexpr Self
min(Self) {
return min(); }
1895 static constexpr Self
max(Self) {
return max(); }
1899 return std::numeric_limits<ValueType>::epsilon();
1901 static constexpr Self
1907 static constexpr
bool
1910 return val.real() > 0;
1912 static constexpr
bool
1915 return val.real() <= 0;
1917 static constexpr
bool
1920 return val.real() < 0;
1922 static constexpr
bool
1925 return val.real() >= 0;
1929 static constexpr
bool IsInteger =
false;
1941 static constexpr
unsigned int
1946 static constexpr
unsigned int
1951 static constexpr Self
1967 template <
typename TArray>
1975 SetLength(Self & m,
const unsigned int s)
1979 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1989 #endif // itkNumericTraits_h