1 #ifndef CORELIB___NCBI_LIMITS__H
2 #define CORELIB___NCBI_LIMITS__H
3 
4 /*  $Id: ncbi_limits.h 472658 2015-07-13 16:12:40Z vakatov $
5  * ===========================================================================
6  *
7  *                            PUBLIC DOMAIN NOTICE
8  *               National Center for Biotechnology Information
9  *
10  *  This software/database is a "United States Government Work" under the
11  *  terms of the United States Copyright Act.  It was written as part of
12  *  the author's official duties as a United States Government employee and
13  *  thus cannot be copyrighted.  This software/database is freely available
14  *  to the public for use. The National Library of Medicine and the U.S.
15  *  Government have not placed any restriction on its use or reproduction.
16  *
17  *  Although all reasonable efforts have been taken to ensure the accuracy
18  *  and reliability of the software and data, the NLM and the U.S.
19  *  Government do not and cannot warrant the performance or results that
20  *  may be obtained by using this software or data. The NLM and the U.S.
21  *  Government disclaim all warranties, express or implied, including
22  *  warranties of performance, merchantability or fitness for any particular
23  *  purpose.
24  *
25  *  Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Author:  Denis Vakatov
30  *
31  *
32  */
33 
34 /**
35  * @file ncbitype.h
36  *
37  * Defines Limits for the types used in NCBI C/C++ toolkit.
38  *
39  *   Limits for the NCBI C/C++ fixed-size types:
40  *      Char, Uchar
41  *      Int1, Uint1  --  kMin_I1,       kMax_I1,       kMax_UI1
42  *      Int2, Uint2  --  kMin_I2,       kMax_I2,       kMax_UI2
43  *      Int4, Uint4  --  kMin_I4,       kMax_I4,       kMax_UI4
44  *      Int8, Uint8  --  kMin_I8,       kMax_I8,       kMax_UI8
45  *
46  *   Limits for the built-in integer types:
47  *      "char"       --  kMin_Char,     kMax_Char,     kMax_UChar
48  *      "short"      --  kMin_Short,    kMax_Short,    kMax_UShort
49  *      "int"        --  kMin_Int,      kMax_Int,      kMax_UInt
50  *      "long"       --  kMin_Long,     kMax_Long,     kMax_ULong
51  *      "long long"  --  kMin_LongLong, kMax_LongLong, kMax_ULongLong
52  *      "__int64"    --  kMin_Int64,    kMax_Int64,    kMax_UInt64
53  *
54  *   Limits for the built-in floating-point types:
55  *      "float"      --  kMin_Float,    kMax_Float
56  *      "double"     --  kMin_Double,   kMax_Double
57  *
58  */
59 
60 #include <corelib/ncbitype.h>
61 #include <limits.h>
62 #include <float.h>
63 #ifdef HAVE_WCHAR_H
64 #include <wchar.h>
65 #endif
66 
67 
68 /** @addtogroup Portability
69  *
70  * @{
71  */
72 
73 
74 /* Int8, Uint8
75  *   NOTE:  "NCBI_MIN/MAX_***8" are temporary preprocessor definitions, so
76  *          do not use them... always use "kMax_*" and "kMin_*" instead!
77  */
78 #if   (SIZEOF_LONG == 8)
79 #  define NCBI_MIN_I8  LONG_MIN
80 #  define NCBI_MAX_I8  LONG_MAX
81 #  define NCBI_MAX_UI8 ULONG_MAX
82 #elif (SIZEOF_LONG_LONG == 8)
83 #  define NCBI_MIN_I8  0x8000000000000000LL
84 #  define NCBI_MAX_I8  0x7FFFFFFFFFFFFFFFLL
85 #  define NCBI_MAX_UI8 0xFFFFFFFFFFFFFFFFULL
86 #elif defined(NCBI_INT8_IS_INT64)
87 #  define NCBI_MIN_I8  0x8000000000000000i64
88 #  define NCBI_MAX_I8  0x7FFFFFFFFFFFFFFFi64
89 #  define NCBI_MAX_UI8 0xFFFFFFFFFFFFFFFFui64
90 #endif
91 
92 
93 /*  Limits:  C++ and C interfaces
94  */
95 
96 #ifdef __cplusplus
97 /* (BEGIN C++ interface) */
98 
99 /* [C++]  built-in integer types */
100 const          char   kMin_Char   = CHAR_MIN;
101 const          char   kMax_Char   = CHAR_MAX;
102 const signed   char   kMin_SChar  = SCHAR_MIN;
103 const signed   char   kMax_SChar  = SCHAR_MAX;
104 const unsigned char   kMax_UChar  = UCHAR_MAX;
105 
106 #if defined(HAVE_WCHAR_H)  &&  defined(WCHAR_MIN)
107 const wchar_t kMin_WChar = WCHAR_MIN;
108 const wchar_t kMax_WChar = WCHAR_MAX;
109 #endif
110 
111 const signed   short  kMin_Short  = SHRT_MIN;
112 const signed   short  kMax_Short  = SHRT_MAX;
113 const unsigned short  kMax_UShort = USHRT_MAX;
114 
115 const signed   int    kMin_Int    = INT_MIN;
116 const signed   int    kMax_Int    = INT_MAX;
117 const unsigned int    kMax_UInt   = UINT_MAX;
118 
119 const signed   long   kMin_Long   = LONG_MIN;
120 const signed   long   kMax_Long   = LONG_MAX;
121 const unsigned long   kMax_ULong  = ULONG_MAX;
122 
123 #  if (SIZEOF_LONG_LONG == 8)
124 const signed   long long  kMin_LongLong   = 0x8000000000000000LL;
125 const signed   long long  kMax_LongLong   = 0x7FFFFFFFFFFFFFFFLL;
126 const unsigned long long  kMax_ULongLong  = 0xFFFFFFFFFFFFFFFFULL;
127 #  elif (SIZEOF_LONG_LONG == 4)
128 const signed   long long  kMin_LongLong   = 0x80000000LL;
129 const signed   long long  kMax_LongLong   = 0x7FFFFFFFLL;
130 const unsigned long long  kMax_ULongLong  = 0xFFFFFFFFULL;
131 #  endif
132 
133 #  if defined(NCBI_INT8_IS_INT64)
134 const signed   __int64 kMin_Int64  = NCBI_MIN_I8;
135 const signed   __int64 kMax_Int64  = NCBI_MAX_I8;
136 const unsigned __int64 kMax_UInt64 = NCBI_MAX_UI8;
137 #  endif
138 
139 /* [C++]  built-in floating-point types */
140 const float kMin_Float = FLT_MIN;
141 const float kMax_Float = FLT_MAX;
142 
143 const double kMin_Double = DBL_MIN;
144 const double kMax_Double = DBL_MAX;
145 
146 /* [C++]  NCBI fixed-size types */
147 const Int1  kMin_I1  = SCHAR_MIN;
148 const Int1  kMax_I1  = SCHAR_MAX;
149 const Uint1 kMax_UI1 = UCHAR_MAX;
150 
151 const Int2  kMin_I2  = SHRT_MIN;
152 const Int2  kMax_I2  = SHRT_MAX;
153 const Uint2 kMax_UI2 = USHRT_MAX;
154 
155 const Int4  kMin_I4  = INT_MIN;
156 const Int4  kMax_I4  = INT_MAX;
157 const Uint4 kMax_UI4 = UINT_MAX;
158 
159 const Int8  kMin_I8  = NCBI_MIN_I8;
160 const Int8  kMax_I8  = NCBI_MAX_I8;
161 const Uint8 kMax_UI8 = NCBI_MAX_UI8;
162 #  undef NCBI_MIN_I8
163 #  undef NCBI_MAX_I8
164 #  undef NCBI_MAX_UI8
165 
166 
167 /* (END of C++ interface) */
168 #else
169 /* (BEGIN C interface) */
170 
171 
172 /* [ C ]  built-in integer types */
173 #  define kMin_Char   CHAR_MIN
174 #  define kMax_Char   CHAR_MAX
175 #  define kMin_SChar  SCHAR_MIN
176 #  define kMax_SChar  SCHAR_MAX
177 #  define kMax_UChar  UCHAR_MAX
178 
179 #  define kMin_Short  SHRT_MIN
180 #  define kMax_Short  SHRT_MAX
181 #  define kMax_UShort USHRT_MAX
182 
183 #  define kMin_Int    INT_MIN
184 #  define kMax_Int    INT_MAX
185 #  define kMax_UInt   UINT_MAX
186 
187 #  if (SIZEOF_LONG_LONG == 8)
188 #    define kMin_LongLong   0x8000000000000000LL
189 #    define kMax_LongLong   0x7FFFFFFFFFFFFFFFLL
190 #    define kMax_ULongLong  0xFFFFFFFFFFFFFFFFULL
191 #  elif (SIZEOF_LONG_LONG == 4)
192 #    define kMin_LongLong   0x80000000LL
193 #    define kMax_LongLong   0x7FFFFFFFLL
194 #    define kMax_ULongLong  0xFFFFFFFFULL
195 #  endif
196 
197 #  if (SIZEOF___INT64 == 8)
198 #    define kMin_Int64  NCBI_CONST_INT8(0x8000000000000000)
199 #    define kMax_Int64  NCBI_CONST_INT8(0x7FFFFFFFFFFFFFFF)
200 #    define kMax_UInt64 NCBI_CONST_UINT8(0xFFFFFFFFFFFFFFFF)
201 #  endif
202 
203 /* [ C ]  built-in floating-point types */
204 #  define kMin_Float  FLT_MIN;
205 #  define kMax_Float  FLT_MAX;
206 
207 #  define kMin_Double DBL_MIN;
208 #  define kMax_Double DBL_MAX;
209 
210 /* [ C ]  NCBI fixed-size types */
211 #  define kMin_I1   SCHAR_MIN
212 #  define kMax_I1   SCHAR_MAX
213 #  define kMax_UI1  UCHAR_MAX
214 #  define kMin_I2   SHRT_MIN
215 #  define kMax_I2   SHRT_MAX
216 #  define kMax_UI2  USHRT_MAX
217 #  define kMin_I4   INT_MIN
218 #  define kMax_I4   INT_MAX
219 #  define kMax_UI4  UINT_MAX
220 #  define kMin_I8   NCBI_MIN_I8
221 #  define kMax_I8   NCBI_MAX_I8
222 #  define kMax_UI8  NCBI_MAX_UI8
223 
224 
225 /* (END of C interface) */
226 #endif  /* __cplusplus */
227 
228 
229 #endif /* CORELIB___NCBI_LIMITS__H */
230 
231 
232 /* @} */
233