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(); }
34 #include <type_traits>
40 template <
typename TValue,
unsigned int VLength>
91 static const T ITKCommon_EXPORT
Zero;
94 static const T ITKCommon_EXPORT
One;
100 return TraitsType::lowest();
170 return TraitsType::max();
175 return TraitsType::min();
190 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
242 template <
typename TArray>
260 class NumericTraits<bool> :
public std::numeric_limits<bool>
272 static constexpr
bool ITKCommon_EXPORT
Zero =
false;
273 static constexpr
bool ITKCommon_EXPORT
One =
true;
275 static constexpr
bool
280 static constexpr
bool
285 static constexpr
bool
290 static constexpr
bool
295 static constexpr
bool
300 static constexpr
bool
305 static constexpr
bool
310 static constexpr
bool
313 return val ? false :
false;
315 static constexpr
bool
318 return val ? true :
true;
320 static constexpr
bool IsSigned =
false;
323 static constexpr
bool
328 static constexpr
bool
333 static constexpr
unsigned int
338 static constexpr
unsigned int
359 template <
typename TArray>
370 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
382 class NumericTraits<char> :
public std::numeric_limits<char>
394 static constexpr
char ITKCommon_EXPORT
Zero = 0;
395 static constexpr
char ITKCommon_EXPORT
One = 1;
399 static constexpr
char
404 static constexpr
bool
409 static constexpr
bool
415 static constexpr
bool
420 static constexpr
bool
425 static constexpr
bool IsSigned = std::numeric_limits<char>::is_signed;
427 static constexpr
bool IsInteger = std::numeric_limits<char>::is_integer;
429 static constexpr
char
434 static constexpr
char
439 static constexpr
unsigned int
444 static constexpr
unsigned int
465 template <
typename TArray>
476 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
488 class NumericTraits<signed char> :
public std::numeric_limits<signed char>
500 static constexpr
signed char ITKCommon_EXPORT
Zero = 0;
501 static constexpr
signed char ITKCommon_EXPORT
One = 1;
503 static constexpr
signed char
508 static constexpr
signed char
513 static constexpr
signed char
518 static constexpr
signed char
523 static constexpr
signed char
528 static constexpr
bool
533 static constexpr
bool
538 static constexpr
bool
543 static constexpr
bool
548 static constexpr
bool IsSigned =
true;
551 static constexpr
signed char
556 static constexpr
signed char
561 static constexpr
unsigned int
566 static constexpr
unsigned int
587 template <
typename TArray>
598 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
610 class NumericTraits<unsigned char> :
public std::numeric_limits<unsigned char>
622 static constexpr
unsigned char ITKCommon_EXPORT
Zero = 0;
623 static constexpr
unsigned char ITKCommon_EXPORT
One = 1;
627 static constexpr
unsigned char
630 return std::numeric_limits<ValueType>::lowest();
632 static constexpr
bool
637 static constexpr
bool
642 static constexpr
bool
645 return val ? false :
false;
647 static constexpr
bool
650 return val ? true :
true;
652 static constexpr
bool IsSigned =
false;
655 static constexpr
unsigned char
660 static constexpr
unsigned char
665 static constexpr
unsigned int
670 static constexpr
unsigned int
691 template <
typename TArray>
702 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
713 class NumericTraits<short> :
public std::numeric_limits<short>
718 using AbsType =
unsigned short;
725 static constexpr
short ITKCommon_EXPORT
Zero = 0;
726 static constexpr
short ITKCommon_EXPORT
One = 1;
729 static constexpr
short
732 return std::numeric_limits<ValueType>::lowest();
734 static constexpr
bool
739 static constexpr
bool
744 static constexpr
bool
749 static constexpr
bool
754 static constexpr
bool IsSigned =
true;
757 static constexpr
short
762 static constexpr
short
767 static constexpr
unsigned int
772 static constexpr
unsigned int
793 template <
typename TArray>
804 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
816 class NumericTraits<unsigned short> :
public std::numeric_limits<unsigned short>
821 using AbsType =
unsigned short;
828 static constexpr
unsigned short ITKCommon_EXPORT
Zero = 0;
829 static constexpr
unsigned short ITKCommon_EXPORT
One = 1;
832 static constexpr
unsigned short
835 return std::numeric_limits<ValueType>::lowest();
837 static constexpr
bool
842 static constexpr
bool
847 static constexpr
bool
850 return val ? false :
false;
852 static constexpr
bool
855 return val ? true :
true;
857 static constexpr
bool IsSigned =
false;
860 static constexpr
unsigned short
865 static constexpr
unsigned short
870 static constexpr
unsigned int
875 static constexpr
unsigned int
896 template <
typename TArray>
907 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
918 class NumericTraits<int> :
public std::numeric_limits<int>
930 static constexpr
int ITKCommon_EXPORT
Zero = 0;
931 static constexpr
int ITKCommon_EXPORT
One = 1;
937 return std::numeric_limits<ValueType>::lowest();
939 static constexpr
bool
944 static constexpr
bool
949 static constexpr
bool
954 static constexpr
bool
959 static constexpr
bool IsSigned =
true;
972 static constexpr
unsigned int
977 static constexpr
unsigned int
998 template <
typename TArray>
1009 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
1021 class NumericTraits<unsigned int> :
public std::numeric_limits<unsigned int>
1033 static constexpr
unsigned int ITKCommon_EXPORT
Zero = 0;
1034 static constexpr
unsigned int ITKCommon_EXPORT
One = 1;
1036 static constexpr
unsigned int
1041 static constexpr
unsigned int
1044 return static_cast<unsigned int>(-1);
1046 static constexpr
unsigned int
1049 return std::numeric_limits<ValueType>::min();
1051 static constexpr
unsigned int
1054 return std::numeric_limits<ValueType>::max();
1056 static constexpr
unsigned int
1061 static constexpr
bool
1066 static constexpr
bool
1071 static constexpr
bool
1074 return val ? false :
false;
1076 static constexpr
bool
1079 return val ? true :
true;
1081 static constexpr
bool IsSigned =
false;
1083 static constexpr
bool IsComplex =
false;
1084 static constexpr
unsigned int
1089 static constexpr
unsigned int
1094 static constexpr
unsigned int
1099 static constexpr
unsigned int
1120 template <
typename TArray>
1131 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
1143 class NumericTraits<long> :
public std::numeric_limits<long>
1148 using AbsType =
unsigned long;
1155 static constexpr
long ITKCommon_EXPORT
Zero = 0L;
1156 static constexpr
long ITKCommon_EXPORT
One = 1L;
1159 static constexpr
long
1162 return std::numeric_limits<ValueType>::lowest();
1164 static constexpr
bool
1169 static constexpr
bool
1174 static constexpr
bool
1179 static constexpr
bool
1184 static constexpr
bool IsSigned =
true;
1186 static constexpr
bool IsComplex =
false;
1187 static constexpr
long
1192 static constexpr
long
1197 static constexpr
unsigned int
1202 static constexpr
unsigned int
1223 template <
typename TArray>
1234 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
1246 class NumericTraits<unsigned long> :
public std::numeric_limits<unsigned long>
1251 using AbsType =
unsigned long;
1258 static constexpr
unsigned long ITKCommon_EXPORT
Zero = 0UL;
1259 static constexpr
unsigned long ITKCommon_EXPORT
One = 1UL;
1262 static constexpr
unsigned long
1265 return std::numeric_limits<ValueType>::lowest();
1267 static constexpr
bool
1272 static constexpr
bool
1277 static constexpr
bool
1282 static constexpr
bool
1287 static constexpr
bool IsSigned =
false;
1289 static constexpr
bool IsComplex =
false;
1290 static constexpr
unsigned long
1295 static constexpr
unsigned long
1300 static constexpr
unsigned int
1305 static constexpr
unsigned int
1326 template <
typename TArray>
1337 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
1349 class NumericTraits<float> :
public std::numeric_limits<float>
1362 static constexpr
float ITKCommon_EXPORT
Zero = 0.0f;
1363 static constexpr
float ITKCommon_EXPORT
One = 1.0f;
1366 static constexpr
float
1369 return std::numeric_limits<ValueType>::lowest();
1371 static constexpr
bool
1376 static constexpr
bool
1381 static constexpr
bool
1386 static constexpr
bool
1391 static constexpr
bool IsSigned =
true;
1392 static constexpr
bool IsInteger =
false;
1393 static constexpr
bool IsComplex =
false;
1394 static constexpr
float
1399 static constexpr
float
1404 static constexpr
unsigned int
1409 static constexpr
unsigned int
1430 template <
typename TArray>
1441 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
1453 class NumericTraits<double> :
public std::numeric_limits<double>
1465 static constexpr
double ITKCommon_EXPORT
Zero = 0.0;
1466 static constexpr
double ITKCommon_EXPORT
One = 1.0;
1469 static constexpr
double
1472 return std::numeric_limits<ValueType>::lowest();
1474 static constexpr
bool
1479 static constexpr
bool
1484 static constexpr
bool
1489 static constexpr
bool
1494 static constexpr
bool IsSigned =
true;
1495 static constexpr
bool IsInteger =
false;
1496 static constexpr
bool IsComplex =
false;
1497 static constexpr
double
1502 static constexpr
double
1507 static constexpr
unsigned int
1512 static constexpr
unsigned int
1533 template <
typename TArray>
1544 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
1556 class NumericTraits<long double> :
public std::numeric_limits<long double>
1560 #if defined(__SUNPRO_CC) && defined(_ILP32)
1576 static constexpr
long double ITKCommon_EXPORT
Zero = 0.0;
1577 static constexpr
long double ITKCommon_EXPORT
One = 1.0;
1580 static constexpr
long double
1583 return std::numeric_limits<ValueType>::lowest();
1585 static constexpr
bool
1590 static constexpr
bool
1595 static constexpr
bool
1600 static constexpr
bool
1605 static constexpr
bool IsSigned =
true;
1606 static constexpr
bool IsInteger =
false;
1607 static constexpr
bool IsComplex =
false;
1608 static constexpr
long double
1613 static constexpr
long double
1618 static constexpr
unsigned int
1623 static constexpr
unsigned int
1644 template <
typename TArray>
1655 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
1668 class NumericTraits<long long> :
public std::numeric_limits<long long>
1687 return std::numeric_limits<ValueType>::lowest();
1689 static constexpr
bool
1694 static constexpr
bool
1699 static constexpr
bool
1704 static constexpr
bool
1709 static constexpr
bool IsSigned =
true;
1711 static constexpr
bool IsComplex =
false;
1722 static constexpr
unsigned int
1727 static constexpr
unsigned int
1748 template <
typename TArray>
1759 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
1771 class NumericTraits<unsigned long long> :
public std::numeric_limits<unsigned long long>
1776 using AbsType =
unsigned long long;
1784 static constexpr
ValueType ITKCommon_EXPORT
One = 1ULL;
1790 return std::numeric_limits<ValueType>::lowest();
1792 static constexpr
bool
1797 static constexpr
bool
1804 static constexpr
bool IsSigned =
false;
1806 static constexpr
bool IsComplex =
false;
1817 static constexpr
unsigned int
1822 static constexpr
unsigned int
1843 template <
typename TArray>
1854 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
1866 template <
typename TComponent>
1867 class NumericTraits<std::complex<TComponent>>
1870 using Self = std::complex<TComponent>;
1872 using TheType =
Self;
1877 using RealType = std::complex<double>;
1882 static const Self ITKCommon_EXPORT
Zero;
1883 static const Self ITKCommon_EXPORT
One;
1885 static constexpr
Self
1888 return std::numeric_limits<ValueType>::min();
1890 static constexpr
Self
1893 return std::numeric_limits<ValueType>::max();
1900 return std::numeric_limits<ValueType>::epsilon();
1902 static constexpr
Self
1908 static constexpr
bool
1911 return val.real() > 0;
1913 static constexpr
bool
1916 return val.real() <= 0;
1918 static constexpr
bool
1921 return val.real() < 0;
1923 static constexpr
bool
1926 return val.real() >= 0;
1929 static constexpr
bool IsSigned = std::is_signed<ValueType>::value;
1930 static constexpr
bool IsInteger =
false;
1942 static constexpr
unsigned int
1947 static constexpr
unsigned int
1952 static constexpr
Self
1968 template <
typename TArray>
1980 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1985 #if defined(ITK_LEGACY_REMOVE)
1986 static_assert(std::is_floating_point<TComponent>::value,
1987 "As per https://en.cppreference.com/w/cpp/numeric/complex the behavior is unspecified and may fail to "
1988 "compile if TComponent is not float, double, or long double and undefined if T is not NumericType.");
1989 #endif // defined(ITK_LEGACY_REMOVE)
1996 #endif // itkNumericTraits_h