43 #ifndef UTIL_MATH_MATHLIMITS_H__ 44 #define UTIL_MATH_MATHLIMITS_H__ 121 static bool IsNaN(
const Type
x);
122 static bool IsInf(
const Type
x);
136 #define SIGNED_INT_MAX(Type) \ 137 (((Type(1) << (sizeof(Type)*8 - 2)) - 1) + (Type(1) << (sizeof(Type)*8 - 2))) 139 #define SIGNED_INT_MIN(Type) \ 140 (-(Type(1) << (sizeof(Type)*8 - 2)) - (Type(1) << (sizeof(Type)*8 - 2))) 142 #define UNSIGNED_INT_MAX(Type) \ 143 (((Type(1) << (sizeof(Type)*8 - 1)) - 1) + (Type(1) << (sizeof(Type)*8 - 1))) 146 #define SIGNED_MAX_10_EXP(Type) \ 147 (sizeof(Type) == 1 ? 2 : ( \ 148 sizeof(Type) == 2 ? 4 : ( \ 149 sizeof(Type) == 4 ? 9 : ( \ 150 sizeof(Type) == 8 ? 18 : -1)))) 152 #define UNSIGNED_MAX_10_EXP(Type) \ 153 (sizeof(Type) == 1 ? 2 : ( \ 154 sizeof(Type) == 2 ? 4 : ( \ 155 sizeof(Type) == 4 ? 9 : ( \ 156 sizeof(Type) == 8 ? 19 : -1)))) 158 #define DECL_INT_LIMIT_FUNCS \ 159 static bool IsFinite(const Type ) { return true; } \ 160 static bool IsNaN(const Type ) { return false; } \ 161 static bool IsInf(const Type ) { return false; } \ 162 static bool IsPosInf(const Type ) { return false; } \ 163 static bool IsNegInf(const Type ) { return false; } 165 #define DECL_SIGNED_INT_LIMITS(IntType, UnsignedIntType) \ 167 struct LIBPROTOBUF_EXPORT MathLimits<IntType> { \ 168 typedef IntType Type; \ 169 typedef UnsignedIntType UnsignedType; \ 170 static const bool kIsSigned = true; \ 171 static const bool kIsInteger = true; \ 172 static const Type kPosMin = 1; \ 173 static const Type kPosMax = SIGNED_INT_MAX(Type); \ 174 static const Type kMin = SIGNED_INT_MIN(Type); \ 175 static const Type kMax = kPosMax; \ 176 static const Type kNegMin = -1; \ 177 static const Type kNegMax = kMin; \ 178 static const int kMin10Exp = 0; \ 179 static const int kMax10Exp = SIGNED_MAX_10_EXP(Type); \ 180 static const Type kEpsilon = 1; \ 181 static const Type kStdError = 0; \ 182 DECL_INT_LIMIT_FUNCS \ 185 #define DECL_UNSIGNED_INT_LIMITS(IntType) \ 187 struct LIBPROTOBUF_EXPORT MathLimits<IntType> { \ 188 typedef IntType Type; \ 189 typedef IntType UnsignedType; \ 190 static const bool kIsSigned = false; \ 191 static const bool kIsInteger = true; \ 192 static const Type kPosMin = 1; \ 193 static const Type kPosMax = UNSIGNED_INT_MAX(Type); \ 194 static const Type kMin = 0; \ 195 static const Type kMax = kPosMax; \ 196 static const int kMin10Exp = 0; \ 197 static const int kMax10Exp = UNSIGNED_MAX_10_EXP(Type); \ 198 static const Type kEpsilon = 1; \ 199 static const Type kStdError = 0; \ 200 DECL_INT_LIMIT_FUNCS \ 214 #undef DECL_SIGNED_INT_LIMITS 215 #undef DECL_UNSIGNED_INT_LIMITS 216 #undef SIGNED_INT_MAX 217 #undef SIGNED_INT_MIN 218 #undef UNSIGNED_INT_MAX 219 #undef SIGNED_MAX_10_EXP 220 #undef UNSIGNED_MAX_10_EXP 221 #undef DECL_INT_LIMIT_FUNCS 224 #ifdef WIN32 // Lacks built-in isnan() and isinf() 225 #define DECL_FP_LIMIT_FUNCS \ 226 static bool IsFinite(const Type x) { return _finite(x); } \ 227 static bool IsNaN(const Type x) { return _isnan(x); } \ 228 static bool IsInf(const Type x) { return (_fpclass(x) & (_FPCLASS_NINF | _FPCLASS_PINF)) != 0; } \ 229 static bool IsPosInf(const Type x) { return _fpclass(x) == _FPCLASS_PINF; } \ 230 static bool IsNegInf(const Type x) { return _fpclass(x) == _FPCLASS_NINF; } 232 #define DECL_FP_LIMIT_FUNCS \ 233 static bool IsFinite(const Type x) { return !isinf(x) && !isnan(x); } \ 234 static bool IsNaN(const Type x) { return isnan(x); } \ 235 static bool IsInf(const Type x) { return isinf(x); } \ 236 static bool IsPosInf(const Type x) { return isinf(x) && x > 0; } \ 237 static bool IsNegInf(const Type x) { return isinf(x) && x < 0; } 244 #define DECL_FP_LIMITS(FP_Type, PREFIX) \ 246 struct LIBPROTOBUF_EXPORT MathLimits<FP_Type> { \ 247 typedef FP_Type Type; \ 248 typedef FP_Type UnsignedType; \ 249 static const bool kIsSigned = true; \ 250 static const bool kIsInteger = false; \ 251 static const Type kPosMin; \ 252 static const Type kPosMax; \ 253 static const Type kMin; \ 254 static const Type kMax; \ 255 static const Type kNegMin; \ 256 static const Type kNegMax; \ 257 static const int kMin10Exp = PREFIX##_MIN_10_EXP; \ 258 static const int kMax10Exp = PREFIX##_MAX_10_EXP; \ 259 static const Type kEpsilon; \ 260 static const Type kStdError; \ 261 static const int kPrecisionDigits = PREFIX##_DIG; \ 262 static const Type kNaN; \ 263 static const Type kPosInf; \ 264 static const Type kNegInf; \ 265 DECL_FP_LIMIT_FUNCS \ 272 #undef DECL_FP_LIMITS 273 #undef DECL_FP_LIMIT_FUNCS 279 #endif // UTIL_MATH_MATHLIMITS_H__ #define DECL_SIGNED_INT_LIMITS(IntType, UnsignedIntType)
Definition: mathlimits.h:165
static const Type kNegMax
Definition: mathlimits.h:88
static const Type kNaN
Definition: mathlimits.h:105
static const bool kIsInteger
Definition: mathlimits.h:74
T UnsignedType
Definition: mathlimits.h:70
static const int kMax10Exp
Definition: mathlimits.h:92
static const Type kNegInf
Definition: mathlimits.h:111
static const Type kNegMin
Definition: mathlimits.h:85
static const Type kPosInf
Definition: mathlimits.h:108
TestSubObjConstructor T
Definition: TestTypedefs.idl:84
EGLSurface EGLint x
Definition: eglext.h:950
static bool IsNaN(const Type x)
static const Type kPosMin
Definition: mathlimits.h:76
#define DECL_FP_LIMITS(FP_Type, PREFIX)
Definition: mathlimits.h:244
T Type
Definition: mathlimits.h:67
Definition: __init__.py:1
static const Type kMin
Definition: mathlimits.h:80
Definition: mathlimits.h:65
static bool IsInf(const Type x)
#define DECL_UNSIGNED_INT_LIMITS(IntType)
Definition: mathlimits.h:185
static const bool kIsSigned
Definition: mathlimits.h:72
static const Type kPosMax
Definition: mathlimits.h:78
static const int kPrecisionDigits
Definition: mathlimits.h:102
static const Type kMax
Definition: mathlimits.h:82
LDBL
Definition: mathlimits.cc:136
Definition: gflags_completions.h:115
static const int kMin10Exp
Definition: mathlimits.h:90
static bool IsFinite(const Type x)
static bool IsNegInf(const Type x)
static bool IsPosInf(const Type x)
static const Type kStdError
Definition: mathlimits.h:99
static const Type kEpsilon
Definition: mathlimits.h:94