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(); } \
31 ITK_MACROEND_NOOP_STATEMENT
41template <
typename TValue,
unsigned int VLength>
92 static const T ITKCommon_EXPORT
Zero;
95 static const T ITKCommon_EXPORT
One;
101 return TraitsType::lowest();
171 return TraitsType::max();
176 return TraitsType::min();
191 itkGenericExceptionMacro(
"Cannot set the size of a scalar to " << s);
201 static constexpr unsigned int
208 static constexpr unsigned int
242 template <
typename TArray>
260class 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
315 static constexpr bool
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);
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);
488class 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);
610class 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
647 static constexpr bool
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);
713class 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);
816class 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
852 static constexpr bool
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);
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);
1021class 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
1076 static constexpr bool
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);
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);
1246class 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);
1349class 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);
1453class 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);
1556class NumericTraits<long double> :
public std::numeric_limits<long double>
1568 static constexpr long double ITKCommon_EXPORT
Zero = 0.0;
1569 static constexpr long double ITKCommon_EXPORT
One = 1.0;
1572 static constexpr long double
1575 return std::numeric_limits<ValueType>::lowest();
1577 static constexpr bool
1582 static constexpr bool
1587 static constexpr bool
1592 static constexpr bool
1597 static constexpr bool IsSigned =
true;
1598 static constexpr bool IsInteger =
false;
1599 static constexpr bool IsComplex =
false;
1600 static constexpr long double
1605 static constexpr long double
1610 static constexpr unsigned int
1615 static constexpr unsigned int
1636 template <
typename TArray>
1647 itkGenericExceptionMacro(
"Cannot set the size of a scalar to " << s);
1660class NumericTraits<long long> :
public std::numeric_limits<long long>
1679 return std::numeric_limits<ValueType>::lowest();
1681 static constexpr bool
1686 static constexpr bool
1691 static constexpr bool
1696 static constexpr bool
1701 static constexpr bool IsSigned =
true;
1703 static constexpr bool IsComplex =
false;
1714 static constexpr unsigned int
1719 static constexpr unsigned int
1740 template <
typename TArray>
1751 itkGenericExceptionMacro(
"Cannot set the size of a scalar to " << s);
1763class NumericTraits<unsigned long long> :
public std::numeric_limits<unsigned long long>
1768 using AbsType =
unsigned long long;
1776 static constexpr ValueType ITKCommon_EXPORT
One = 1ULL;
1782 return std::numeric_limits<ValueType>::lowest();
1784 static constexpr bool
1789 static constexpr bool
1794 static constexpr bool
1799 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);
1866template <
typename 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();
1895 static constexpr Self
1900 static constexpr Self
1908 return std::numeric_limits<ValueType>::epsilon();
1910 static constexpr Self
1916 static constexpr bool
1919 return val.real() > 0;
1921 static constexpr bool
1924 return val.real() <= 0;
1926 static constexpr bool
1929 return val.real() < 0;
1931 static constexpr bool
1934 return val.real() >= 0;
1937 static constexpr bool IsSigned = std::is_signed_v<ValueType>;
1938 static constexpr bool IsInteger =
false;
1950 static constexpr unsigned int
1955 static constexpr unsigned int
1960 static constexpr Self
1976 template <
typename TArray>
1984 SetLength(Self & m,
const unsigned int s)
1988 itkGenericExceptionMacro(
"Cannot set the size of a complex to " << s);
1993#if defined(ITK_LEGACY_REMOVE)
1994 static_assert(std::is_floating_point_v<TComponent>,
1995 "As per https://en.cppreference.com/w/cpp/numeric/complex the behavior is unspecified and may fail to "
1996 "compile if TComponent is not float, double, or long double and undefined if T is not NumericType.");
Simulate a standard C array with copy semantics.
Define additional traits for native types such as int or float.
static constexpr bool IsInteger
static constexpr bool IsSigned
static bool IsNegative(T val)
static T OneValue(const T &)
static constexpr T NonpositiveMin()
static constexpr T max(const T &)
static T ZeroValue(const T &)
std::numeric_limits< T > TraitsType
static bool IsPositive(T val)
static constexpr T min(const T &)
static void AssignToArray(const T &v, TArray &mv)
static const AbsoluteFrequencyType ITKCommon_EXPORT Zero
static bool IsNonpositive(T val)
static constexpr unsigned int GetLength()
static T NonpositiveMin(const T &)
static const AbsoluteFrequencyType ITKCommon_EXPORT One
static constexpr unsigned int GetLength(const T &)
static void SetLength(T &m, const unsigned int s)
static bool IsNonnegative(T val)
FixedArray< ValueType, 1 > MeasurementVectorType
static constexpr bool IsComplex
#define itkNUMERIC_TRAITS_MIN_MAX_MACRO()
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....