1 // Copyright 2005 Google Inc. 2 // All Rights Reserved. 3 // 4 // 5 6 #include "util/math/mathlimits.h" 7 #include "base/integral_types.h" 8 9 // MSVC++ 2005 thinks the header declaration was a definition, and 10 // erroneously flags these as a duplicate definition. 11 #ifdef COMPILER_MSVC 12 13 #define DEF_COMMON_LIMITS(Type) 14 #define DEF_UNSIGNED_INT_LIMITS(Type) 15 #define DEF_SIGNED_INT_LIMITS(Type) 16 #define DEF_PRECISION_LIMITS(Type) 17 18 #else 19 20 #define DEF_COMMON_LIMITS(Type) \ 21 const bool MathLimits<Type>::kIsSigned; \ 22 const bool MathLimits<Type>::kIsInteger; \ 23 const int MathLimits<Type>::kMin10Exp; \ 24 const int MathLimits<Type>::kMax10Exp; 25 26 #define DEF_UNSIGNED_INT_LIMITS(Type) \ 27 DEF_COMMON_LIMITS(Type) \ 28 const Type MathLimits<Type>::kPosMin; \ 29 const Type MathLimits<Type>::kPosMax; \ 30 const Type MathLimits<Type>::kMin; \ 31 const Type MathLimits<Type>::kMax; \ 32 const Type MathLimits<Type>::kEpsilon; \ 33 const Type MathLimits<Type>::kStdError; 34 35 #define DEF_SIGNED_INT_LIMITS(Type) \ 36 DEF_UNSIGNED_INT_LIMITS(Type) \ 37 const Type MathLimits<Type>::kNegMin; \ 38 const Type MathLimits<Type>::kNegMax; 39 40 #define DEF_PRECISION_LIMITS(Type) \ 41 const int MathLimits<Type>::kPrecisionDigits; 42 43 #endif // not COMPILER_MSVC 44 45 #define DEF_FP_LIMITS(Type, PREFIX) \ 46 DEF_COMMON_LIMITS(Type) \ 47 const Type MathLimits<Type>::kPosMin = PREFIX##_MIN; \ 48 const Type MathLimits<Type>::kPosMax = PREFIX##_MAX; \ 49 const Type MathLimits<Type>::kMin = -MathLimits<Type>::kPosMax; \ 50 const Type MathLimits<Type>::kMax = MathLimits<Type>::kPosMax; \ 51 const Type MathLimits<Type>::kNegMin = -MathLimits<Type>::kPosMin; \ 52 const Type MathLimits<Type>::kNegMax = -MathLimits<Type>::kPosMax; \ 53 const Type MathLimits<Type>::kEpsilon = PREFIX##_EPSILON; \ 54 /* 32 is 5 bits of mantissa error; should be adequate for common errors */ \ 55 const Type MathLimits<Type>::kStdError = MathLimits<Type>::kEpsilon * 32; \ 56 DEF_PRECISION_LIMITS(Type) \ 57 const Type MathLimits<Type>::kNaN = HUGE_VAL - HUGE_VAL; \ 58 const Type MathLimits<Type>::kPosInf = HUGE_VAL; \ 59 const Type MathLimits<Type>::kNegInf = -HUGE_VAL; 60 61 DEF_SIGNED_INT_LIMITS(int8) 62 DEF_SIGNED_INT_LIMITS(int16) 63 DEF_SIGNED_INT_LIMITS(int32) 64 DEF_SIGNED_INT_LIMITS(int64) 65 DEF_UNSIGNED_INT_LIMITS(uint8) 66 DEF_UNSIGNED_INT_LIMITS(uint16) 67 DEF_UNSIGNED_INT_LIMITS(uint32) 68 DEF_UNSIGNED_INT_LIMITS(uint64) 69 70 DEF_SIGNED_INT_LIMITS(long int) 71 DEF_UNSIGNED_INT_LIMITS(unsigned long int) 72 73 DEF_FP_LIMITS(float, FLT) 74 DEF_FP_LIMITS(double, DBL) 75 DEF_FP_LIMITS(long double, LDBL); 76 77 #undef DEF_COMMON_LIMITS 78 #undef DEF_SIGNED_INT_LIMITS 79 #undef DEF_UNSIGNED_INT_LIMITS 80 #undef DEF_FP_LIMITS 81 #undef DEF_PRECISION_LIMITS 82