Go to the documentation of this file.
43 #ifndef UTIL_MATH_MATHLIMITS_H__
44 #define UTIL_MATH_MATHLIMITS_H__
48 #if __cplusplus >= 201103L
53 #define GOOGLE_PROTOBUF_USE_STD_CMATH
54 #elif _GLIBCXX_USE_C99_MATH && !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC
58 #define GOOGLE_PROTOBUF_USE_STD_CMATH
67 #include <google/protobuf/stubs/common.h>
69 #include <google/protobuf/port_def.inc>
149 #define SIGNED_INT_MAX(Type) \
150 (((Type(1) << (sizeof(Type)*8 - 2)) - 1) + (Type(1) << (sizeof(Type)*8 - 2)))
152 #define SIGNED_INT_MIN(Type) \
153 (-(Type(1) << (sizeof(Type)*8 - 2)) - (Type(1) << (sizeof(Type)*8 - 2)))
155 #define UNSIGNED_INT_MAX(Type) \
156 (((Type(1) << (sizeof(Type)*8 - 1)) - 1) + (Type(1) << (sizeof(Type)*8 - 1)))
159 #define SIGNED_MAX_10_EXP(Type) \
160 (sizeof(Type) == 1 ? 2 : ( \
161 sizeof(Type) == 2 ? 4 : ( \
162 sizeof(Type) == 4 ? 9 : ( \
163 sizeof(Type) == 8 ? 18 : -1))))
165 #define UNSIGNED_MAX_10_EXP(Type) \
166 (sizeof(Type) == 1 ? 2 : ( \
167 sizeof(Type) == 2 ? 4 : ( \
168 sizeof(Type) == 4 ? 9 : ( \
169 sizeof(Type) == 8 ? 19 : -1))))
171 #define DECL_INT_LIMIT_FUNCS \
172 static bool IsFinite(const Type ) { return true; } \
173 static bool IsNaN(const Type ) { return false; } \
174 static bool IsInf(const Type ) { return false; } \
175 static bool IsPosInf(const Type ) { return false; } \
176 static bool IsNegInf(const Type ) { return false; }
178 #define DECL_SIGNED_INT_LIMITS(IntType, UnsignedIntType) \
180 struct PROTOBUF_EXPORT MathLimits<IntType> { \
181 typedef IntType Type; \
182 typedef UnsignedIntType UnsignedType; \
183 static const bool kIsSigned = true; \
184 static const bool kIsInteger = true; \
185 static const Type kPosMin = 1; \
186 static const Type kPosMax = SIGNED_INT_MAX(Type); \
187 static const Type kMin = SIGNED_INT_MIN(Type); \
188 static const Type kMax = kPosMax; \
189 static const Type kNegMin = -1; \
190 static const Type kNegMax = kMin; \
191 static const int kMin10Exp = 0; \
192 static const int kMax10Exp = SIGNED_MAX_10_EXP(Type); \
193 static const Type kEpsilon = 1; \
194 static const Type kStdError = 0; \
195 DECL_INT_LIMIT_FUNCS \
198 #define DECL_UNSIGNED_INT_LIMITS(IntType) \
200 struct PROTOBUF_EXPORT MathLimits<IntType> { \
201 typedef IntType Type; \
202 typedef IntType UnsignedType; \
203 static const bool kIsSigned = false; \
204 static const bool kIsInteger = true; \
205 static const Type kPosMin = 1; \
206 static const Type kPosMax = UNSIGNED_INT_MAX(Type); \
207 static const Type kMin = 0; \
208 static const Type kMax = kPosMax; \
209 static const int kMin10Exp = 0; \
210 static const int kMax10Exp = UNSIGNED_MAX_10_EXP(Type); \
211 static const Type kEpsilon = 1; \
212 static const Type kStdError = 0; \
213 DECL_INT_LIMIT_FUNCS \
227 #undef DECL_SIGNED_INT_LIMITS
228 #undef DECL_UNSIGNED_INT_LIMITS
229 #undef SIGNED_INT_MAX
230 #undef SIGNED_INT_MIN
231 #undef UNSIGNED_INT_MAX
232 #undef SIGNED_MAX_10_EXP
233 #undef UNSIGNED_MAX_10_EXP
234 #undef DECL_INT_LIMIT_FUNCS
239 #ifdef GOOGLE_PROTOBUF_USE_STD_CMATH
240 #define ISINF std::isinf
241 #define ISNAN std::isnan
248 #if defined(_WIN32) && !defined(__MINGW32__) // Lacks built-in isnan() and isinf()
249 #define DECL_FP_LIMIT_FUNCS \
250 static bool IsFinite(const Type x) { return _finite(x); } \
251 static bool IsNaN(const Type x) { return _isnan(x); } \
252 static bool IsInf(const Type x) { return (_fpclass(x) & (_FPCLASS_NINF | _FPCLASS_PINF)) != 0; } \
253 static bool IsPosInf(const Type x) { return _fpclass(x) == _FPCLASS_PINF; } \
254 static bool IsNegInf(const Type x) { return _fpclass(x) == _FPCLASS_NINF; }
256 #define DECL_FP_LIMIT_FUNCS \
257 static bool IsFinite(const Type x) { return !ISINF(x) && !ISNAN(x); } \
258 static bool IsNaN(const Type x) { return ISNAN(x); } \
259 static bool IsInf(const Type x) { return ISINF(x); } \
260 static bool IsPosInf(const Type x) { return ISINF(x) && x > 0; } \
261 static bool IsNegInf(const Type x) { return ISINF(x) && x < 0; }
268 #define DECL_FP_LIMITS(FP_Type, PREFIX) \
270 struct PROTOBUF_EXPORT MathLimits<FP_Type> { \
271 typedef FP_Type Type; \
272 typedef FP_Type UnsignedType; \
273 static const bool kIsSigned = true; \
274 static const bool kIsInteger = false; \
275 static const Type kPosMin; \
276 static const Type kPosMax; \
277 static const Type kMin; \
278 static const Type kMax; \
279 static const Type kNegMin; \
280 static const Type kNegMax; \
281 static const int kMin10Exp = PREFIX##_MIN_10_EXP; \
282 static const int kMax10Exp = PREFIX##_MAX_10_EXP; \
283 static const Type kEpsilon; \
284 static const Type kStdError; \
285 static const int kPrecisionDigits = PREFIX##_DIG; \
286 static const Type kNaN; \
287 static const Type kPosInf; \
288 static const Type kNegInf; \
289 DECL_FP_LIMIT_FUNCS \
298 #undef DECL_FP_LIMITS
299 #undef DECL_FP_LIMIT_FUNCS
305 #include <google/protobuf/port_undef.inc>
307 #endif // UTIL_MATH_MATHLIMITS_H__
static const Type kNegInf
static const bool kIsSigned
static const int kMin10Exp
#define DECL_UNSIGNED_INT_LIMITS(IntType)
static bool IsNegInf(const Type x)
static bool IsNaN(const Type x)
#define DECL_SIGNED_INT_LIMITS(IntType, UnsignedIntType)
static const bool kIsInteger
#define T(upbtypeconst, upbtype, ctype, default_value)
static const Type kEpsilon
static const Type kPosMin
static const Type kNegMax
static const Type kNegMin
static const int kPrecisionDigits
static const Type kPosMax
static bool IsInf(const Type x)
static const int kMax10Exp
static const Type kStdError
static const Type kPosInf
static bool IsPosInf(const Type x)
#define DECL_FP_LIMITS(FP_Type, PREFIX)
static bool IsFinite(const Type x)
grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:34