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);
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>
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);
1668class 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);
1771class 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
1802 static constexpr bool
1807 static constexpr bool
1812 static constexpr bool IsSigned =
false;
1814 static constexpr bool IsComplex =
false;
1825 static constexpr unsigned int
1830 static constexpr unsigned int
1851 template <
typename TArray>
1862 itkGenericExceptionMacro(
"Cannot set the size of a scalar to " << s);
1874template <
typename TComponent>
1878 using Self = std::complex<TComponent>;
1880 using TheType = Self;
1885 using RealType = std::complex<double>;
1890 static const Self ITKCommon_EXPORT
Zero;
1891 static const Self ITKCommon_EXPORT
One;
1893 static constexpr Self
1896 return std::numeric_limits<ValueType>::min();
1898 static constexpr Self
1901 return std::numeric_limits<ValueType>::max();
1903 static constexpr Self
1908 static constexpr Self
1916 return std::numeric_limits<ValueType>::epsilon();
1918 static constexpr Self
1924 static constexpr bool
1927 return val.real() > 0;
1929 static constexpr bool
1932 return val.real() <= 0;
1934 static constexpr bool
1937 return val.real() < 0;
1939 static constexpr bool
1942 return val.real() >= 0;
1945 static constexpr bool IsSigned = std::is_signed_v<ValueType>;
1946 static constexpr bool IsInteger =
false;
1958 static constexpr unsigned int
1963 static constexpr unsigned int
1968 static constexpr Self
1984 template <
typename TArray>
1992 SetLength(Self & m,
const unsigned int s)
1996 itkGenericExceptionMacro(
"Cannot set the size of a complex to " << s);
2001#if defined(ITK_LEGACY_REMOVE)
2002 static_assert(std::is_floating_point_v<TComponent>,
2003 "As per https://en.cppreference.com/w/cpp/numeric/complex the behavior is unspecified and may fail to "
2004 "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 unsigned int GetLength()
static const AbsoluteFrequencyType ITKCommon_EXPORT Zero
static bool IsNonpositive(T val)
static T NonpositiveMin(const T &)
static const AbsoluteFrequencyType ITKCommon_EXPORT One
static void SetLength(T &m, const unsigned int s)
static bool IsNonnegative(T val)
FixedArray< ValueType, 1 > MeasurementVectorType
static constexpr bool IsComplex
static unsigned int GetLength(const T &)
#define itkNUMERIC_TRAITS_MIN_MAX_MACRO()
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....