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