File indexing completed on 2025-01-18 10:13:51
0001 #ifndef VECCORE_LIMITS_H
0002 #define VECCORE_LIMITS_H
0003
0004 #include "Backend/Interface.h"
0005
0006 #include <cfloat>
0007 #include <climits>
0008 #include <cmath>
0009
0010 namespace vecCore {
0011
0012 template <typename T>
0013 struct NumericLimits {
0014 using ScalarT = Scalar<T>;
0015
0016 static constexpr T Min() noexcept { return T(NumericLimits<ScalarT>::Min()); }
0017 static constexpr T Max() noexcept { return T(NumericLimits<ScalarT>::Max()); }
0018
0019 static constexpr T Lowest() noexcept { return T(NumericLimits<ScalarT>::Lowest()); }
0020 static constexpr T Highest() noexcept { return T(NumericLimits<ScalarT>::Highest()); }
0021
0022 static constexpr T Epsilon() noexcept { return T(NumericLimits<ScalarT>::Epsilon()); }
0023 static constexpr T Infinity() noexcept { return T(NumericLimits<ScalarT>::Infinity()); }
0024 };
0025
0026 template <>
0027 struct NumericLimits<bool> {
0028 VECCORE_ATT_HOST_DEVICE static constexpr bool Min() noexcept { return false; }
0029 VECCORE_ATT_HOST_DEVICE static constexpr bool Max() noexcept { return true; }
0030 };
0031
0032 template <>
0033 struct NumericLimits<char> {
0034 VECCORE_ATT_HOST_DEVICE static constexpr char Min() noexcept { return CHAR_MIN; }
0035 VECCORE_ATT_HOST_DEVICE static constexpr char Max() noexcept { return CHAR_MAX; }
0036 VECCORE_ATT_HOST_DEVICE static constexpr char Lowest() noexcept { return CHAR_MIN; }
0037 VECCORE_ATT_HOST_DEVICE static constexpr char Highest() noexcept { return CHAR_MAX; }
0038 };
0039
0040 template <>
0041 struct NumericLimits<unsigned char> {
0042 VECCORE_ATT_HOST_DEVICE static constexpr unsigned char Min() noexcept { return 0; }
0043 VECCORE_ATT_HOST_DEVICE static constexpr unsigned char Max() noexcept { return UCHAR_MAX; }
0044 VECCORE_ATT_HOST_DEVICE static constexpr unsigned char Lowest() noexcept { return 0; }
0045 VECCORE_ATT_HOST_DEVICE static constexpr unsigned char Highest() noexcept { return UCHAR_MAX; }
0046 };
0047
0048 template <>
0049 struct NumericLimits<short> {
0050 VECCORE_ATT_HOST_DEVICE static constexpr short Min() noexcept { return SHRT_MIN; }
0051 VECCORE_ATT_HOST_DEVICE static constexpr short Max() noexcept { return SHRT_MAX; }
0052 VECCORE_ATT_HOST_DEVICE static constexpr short Lowest() noexcept { return SHRT_MIN; }
0053 VECCORE_ATT_HOST_DEVICE static constexpr short Highest() noexcept { return SHRT_MAX; }
0054 };
0055
0056 template <>
0057 struct NumericLimits<unsigned short> {
0058 VECCORE_ATT_HOST_DEVICE static constexpr unsigned short Min() noexcept { return 0; }
0059 VECCORE_ATT_HOST_DEVICE static constexpr unsigned short Max() noexcept { return USHRT_MAX; }
0060 VECCORE_ATT_HOST_DEVICE static constexpr unsigned short Lowest() noexcept { return 0; }
0061 VECCORE_ATT_HOST_DEVICE static constexpr unsigned short Highest() noexcept { return USHRT_MAX; }
0062 };
0063
0064 template <>
0065 struct NumericLimits<int> {
0066 VECCORE_ATT_HOST_DEVICE static constexpr int Min() noexcept { return INT_MIN; }
0067 VECCORE_ATT_HOST_DEVICE static constexpr int Max() noexcept { return INT_MAX; }
0068 VECCORE_ATT_HOST_DEVICE static constexpr int Lowest() noexcept { return INT_MIN; }
0069 VECCORE_ATT_HOST_DEVICE static constexpr int Highest() noexcept { return INT_MAX; }
0070 };
0071
0072 template <>
0073 struct NumericLimits<unsigned int> {
0074 VECCORE_ATT_HOST_DEVICE static constexpr unsigned int Min() noexcept { return 0; }
0075 VECCORE_ATT_HOST_DEVICE static constexpr unsigned int Max() noexcept { return UINT_MAX; }
0076 VECCORE_ATT_HOST_DEVICE static constexpr unsigned int Lowest() noexcept { return 0; }
0077 VECCORE_ATT_HOST_DEVICE static constexpr unsigned int Highest() noexcept { return UINT_MAX; }
0078 };
0079
0080 template <>
0081 struct NumericLimits<long> {
0082 VECCORE_ATT_HOST_DEVICE static constexpr long Min() noexcept { return LONG_MIN; }
0083 VECCORE_ATT_HOST_DEVICE static constexpr long Max() noexcept { return LONG_MAX; }
0084 VECCORE_ATT_HOST_DEVICE static constexpr long Lowest() noexcept { return LONG_MIN; }
0085 VECCORE_ATT_HOST_DEVICE static constexpr long Highest() noexcept { return LONG_MAX; }
0086 };
0087
0088 template <>
0089 struct NumericLimits<unsigned long> {
0090 VECCORE_ATT_HOST_DEVICE static constexpr unsigned long Min() noexcept { return 0UL; }
0091 VECCORE_ATT_HOST_DEVICE static constexpr unsigned long Max() noexcept { return ULONG_MAX; }
0092 VECCORE_ATT_HOST_DEVICE static constexpr unsigned long Lowest() noexcept { return 0UL; }
0093 VECCORE_ATT_HOST_DEVICE static constexpr unsigned long Highest() noexcept { return ULONG_MAX; }
0094 };
0095
0096 template <>
0097 struct NumericLimits<long long> {
0098 VECCORE_ATT_HOST_DEVICE static constexpr long long Min() noexcept { return LLONG_MIN; }
0099 VECCORE_ATT_HOST_DEVICE static constexpr long long Max() noexcept { return LLONG_MAX; }
0100 VECCORE_ATT_HOST_DEVICE static constexpr long long Lowest() noexcept { return LLONG_MIN; }
0101 VECCORE_ATT_HOST_DEVICE static constexpr long long Highest() noexcept { return LLONG_MAX; }
0102 };
0103
0104 template <>
0105 struct NumericLimits<unsigned long long> {
0106 VECCORE_ATT_HOST_DEVICE static constexpr unsigned long long Min() noexcept { return 0ULL; }
0107 VECCORE_ATT_HOST_DEVICE static constexpr unsigned long long Max() noexcept { return ULLONG_MAX; }
0108 VECCORE_ATT_HOST_DEVICE static constexpr unsigned long long Lowest() noexcept { return 0ULL; }
0109 VECCORE_ATT_HOST_DEVICE static constexpr unsigned long long Highest() noexcept { return ULLONG_MAX; }
0110 };
0111
0112 template <>
0113 struct NumericLimits<float> {
0114 VECCORE_ATT_HOST_DEVICE static constexpr float Min() noexcept { return FLT_MIN; }
0115 VECCORE_ATT_HOST_DEVICE static constexpr float Max() noexcept { return FLT_MAX; }
0116 VECCORE_ATT_HOST_DEVICE static constexpr float Lowest() noexcept { return -FLT_MAX; }
0117 VECCORE_ATT_HOST_DEVICE static constexpr float Highest() noexcept { return FLT_MAX; }
0118 VECCORE_ATT_HOST_DEVICE static constexpr float Epsilon() noexcept { return FLT_EPSILON; }
0119 VECCORE_ATT_HOST_DEVICE static constexpr float Infinity() noexcept { return HUGE_VALF; }
0120 };
0121
0122 template <>
0123 struct NumericLimits<double> {
0124 VECCORE_ATT_HOST_DEVICE static constexpr double Min() noexcept { return DBL_MIN; }
0125 VECCORE_ATT_HOST_DEVICE static constexpr double Max() noexcept { return DBL_MAX; }
0126 VECCORE_ATT_HOST_DEVICE static constexpr double Lowest() noexcept { return -DBL_MAX; }
0127 VECCORE_ATT_HOST_DEVICE static constexpr double Highest() noexcept { return DBL_MAX; }
0128 VECCORE_ATT_HOST_DEVICE static constexpr double Epsilon() noexcept { return DBL_EPSILON; }
0129 VECCORE_ATT_HOST_DEVICE static constexpr double Infinity() noexcept { return HUGE_VAL; }
0130 };
0131
0132 }
0133
0134 #endif