Added negative zero preprocessor constants
[alexxy/gromacs.git] / src / gromacs / legacyheaders / types / simple.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5  * Copyright (c) 2001-2004, The GROMACS development team.
6  * Copyright (c) 2013,2014, by the GROMACS development team, led by
7  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8  * and including many others, as listed in the AUTHORS file in the
9  * top-level source directory and at http://www.gromacs.org.
10  *
11  * GROMACS is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public License
13  * as published by the Free Software Foundation; either version 2.1
14  * of the License, or (at your option) any later version.
15  *
16  * GROMACS is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with GROMACS; if not, see
23  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
25  *
26  * If you want to redistribute modifications to GROMACS, please
27  * consider that scientific software is very special. Version
28  * control is crucial - bugs must be traceable. We will be happy to
29  * consider code for inclusion in the official distribution, but
30  * derived work must not be called official GROMACS. Details are found
31  * in the README & COPYING files - if they are missing, get the
32  * official version at http://www.gromacs.org.
33  *
34  * To help us fund GROMACS development, we humbly ask that you cite
35  * the research papers on the package. Check out http://www.gromacs.org.
36  */
37
38 #ifndef _simple_h
39 #define _simple_h
40
41 /* Information about integer data type sizes */
42 #include <limits.h>
43 #define __STDC_LIMIT_MACROS
44 #include <stdint.h>
45 #ifndef _MSC_VER
46 #define __STDC_FORMAT_MACROS
47 #include <inttypes.h>
48 #endif
49
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 #if 0
54 }
55 #endif
56
57
58 #define XX      0           /* Defines for indexing in  */
59 #define YY      1           /* vectors                  */
60 #define ZZ      2
61 #define DIM     3           /* Dimension of vectors             */
62 #define XXXX    0           /* defines to index matrices */
63 #define XXYY    1
64 #define XXZZ    2
65 #define YYXX    3
66 #define YYYY    4
67 #define YYZZ    5
68 #define ZZXX    6
69 #define ZZYY    7
70 #define ZZZZ    8
71
72 /* There is no standard size for 'bool' in C++, so when
73  * we previously defined it to int for C code the data types
74  * (and structs) would have different size depending on your compiler,
75  * both at gromacs build time and when you use the library.
76  * The only way around this is to NOT assume anything about the C++ type,
77  * so we cannot use the name 'bool' in our C code anymore.
78  */
79
80 typedef int gmx_bool;
81
82 #ifndef FALSE
83 #  define FALSE   0
84 #endif
85 #ifndef TRUE
86 #  define TRUE    1
87 #endif
88 #define BOOL_NR 2
89
90
91 typedef int         atom_id;      /* To indicate an atoms id         */
92 #define NO_ATID     (atom_id)(~0) /* Use this to indicate invalid atid */
93
94 /*! \brief Double precision accuracy */
95 #define GMX_DOUBLE_EPS   2.2204460492503131e-16
96
97 /*! \brief Maximum double precision value - reduced 1 unit in last digit for MSVC */
98 #define GMX_DOUBLE_MAX   1.7976931348623157e+308
99
100 /*! \brief Minimum double precision value */
101 #define GMX_DOUBLE_MIN   2.2250738585072014e-308
102
103 /*! \brief Single precision accuracy */
104 #define GMX_FLOAT_EPS    1.19209290e-07F
105
106 /*! \brief Maximum single precision value - reduced 1 unit in last digit for MSVC */
107 #define GMX_FLOAT_MAX    3.40282346E+38F
108
109 /*! \brief Minimum single precision value */
110 #define GMX_FLOAT_MIN    1.175494351E-38F
111
112 #ifdef __PGI
113 /* The portland group x86 C/C++ compilers do not treat negative zero initializers
114  * correctly, but "optimizes" them to positive zero, so we implement it explicitly.
115  * These constructs are optimized to simple loads at compile time. If you want to
116  * use them on other compilers those have to support gcc preprocessor extensions.
117  * Note: These initializers might be sensitive to the endianness (which can
118  * be different for byte and word order), so check that it works for your platform
119  * and add a separate section if necessary before adding to the ifdef above.
120  */
121 #    define GMX_DOUBLE_NEGZERO  ({ const union { int  di[2]; double d; } _gmx_dzero = {0, -2147483648}; _gmx_dzero.d; })
122 #    define GMX_FLOAT_NEGZERO   ({ const union { int  fi; float f; } _gmx_fzero = {-2147483648}; _gmx_fzero.f; })
123 #else
124 /*! \brief Negative zero in double */
125 #    define GMX_DOUBLE_NEGZERO  (-0.0)
126
127 /*! \brief Negative zero in float */
128 #    define GMX_FLOAT_NEGZERO   (-0.0f)
129 #endif
130
131
132 /* Check whether we already have a real type! */
133 #ifdef GMX_DOUBLE
134
135 #ifndef HAVE_REAL
136 typedef double      real;
137 #define HAVE_REAL
138 #endif
139
140 #define GMX_MPI_REAL      MPI_DOUBLE
141 #define GMX_REAL_EPS      GMX_DOUBLE_EPS
142 #define GMX_REAL_MIN      GMX_DOUBLE_MIN
143 #define GMX_REAL_MAX      GMX_DOUBLE_MAX
144 #define GMX_REAL_NEGZERO  GMX_DOUBLE_NEGZERO
145 #define gmx_real_fullprecision_pfmt "%21.14e"
146 #else
147
148 #ifndef HAVE_REAL
149 typedef float           real;
150 #define HAVE_REAL
151 #endif
152
153 #define GMX_MPI_REAL      MPI_FLOAT
154 #define GMX_REAL_EPS      GMX_FLOAT_EPS
155 #define GMX_REAL_MIN      GMX_FLOAT_MIN
156 #define GMX_REAL_MAX      GMX_FLOAT_MAX
157 #define GMX_REAL_NEGZERO  GMX_FLOAT_NEGZERO
158 #define gmx_real_fullprecision_pfmt "%14.7e"
159 #endif
160
161 typedef real            rvec[DIM];
162
163 typedef double          dvec[DIM];
164
165 typedef real            matrix[DIM][DIM];
166
167 typedef real            tensor[DIM][DIM];
168
169 typedef int             ivec[DIM];
170
171 typedef int             imatrix[DIM][DIM];
172
173 #ifdef _MSC_VER
174 typedef __int32 gmx_int32_t;
175 #define GMX_PRId32 "I32d"
176 #define GMX_SCNd32 "I32d"
177
178 typedef __int64 gmx_int64_t;
179 #define GMX_PRId64 "I64d"
180 #define GMX_SCNd64 "I64d"
181
182 typedef unsigned __int32 gmx_uint32_t;
183 #define GMX_PRIu32 "I32u"
184 #define GMX_SCNu32 "I32u"
185
186 typedef unsigned __int64 gmx_uint64_t;
187 #define GMX_PRIu64 "I64u"
188 #define GMX_SCNu64 "I64u"
189 #else
190 typedef int32_t gmx_int32_t;
191 #define GMX_PRId32 PRId32
192 #define GMX_SCNd32 SCNd32
193
194 typedef int64_t gmx_int64_t;
195 #define GMX_PRId64 PRId64
196 #define GMX_SCNd64 SCNd64
197
198 typedef uint32_t gmx_uint32_t;
199 #define GMX_PRIu32 PRIu32
200 #define GMX_SCNu32 SCNu32
201
202 typedef uint64_t gmx_uint64_t;
203 #define GMX_PRIu64 PRIu64
204 #define GMX_SCNu64 SCNu64
205 #endif
206
207 #define GMX_INT32_MAX INT32_MAX
208 #define GMX_INT32_MIN INT32_MIN
209
210 #define GMX_INT64_MAX INT64_MAX
211 #define GMX_INT64_MIN INT64_MIN
212
213 #define GMX_UINT32_MAX UINT32_MAX
214 #define GMX_UINT32_MIN UINT32_MIN
215
216 #define GMX_UINT64_MAX UINT64_MAX
217 #define GMX_UINT64_MIN UINT64_MIN
218
219 #if !defined __cplusplus && _MSC_VER
220 #define gmx_inline __inline
221 #else
222 /* C++ or C99 */
223 #define gmx_inline inline
224 #endif
225
226 /* ICC, GCC, MSVC, Pathscale, PGI, XLC support __restrict.
227  * Any other compiler can be added here. We cannot
228  * use restrict because it is in C99 but not in C++ */
229 #define gmx_restrict __restrict
230
231 /*
232  * These attributes suppress compiler warnings about unused function arguments
233  * by marking them as possibly unused. Some arguments are unused but
234  * have to be retained to preserve a function signature
235  * that must match that of another function.
236  * Some arguments are only used in *some* code paths (e.g. MPI)
237  */
238
239 #ifndef gmx_unused
240 #ifdef __GNUC__
241 /* GCC, clang, and some ICC pretending to be GCC */
242 #  define gmx_unused __attribute__ ((unused))
243 #elif (defined(__INTEL_COMPILER) || defined(__ECC)) && !defined(_MSC_VER)
244 /* ICC on *nix */
245 #  define gmx_unused __attribute__ ((unused))
246 #elif defined(__PGI)
247 /* Portland group compilers */
248 #  define gmx_unused __attribute__ ((unused))
249 #elif defined _MSC_VER
250 /* MSVC */
251 #  define gmx_unused /*@unused@*/
252 #elif defined(__xlC__)
253 /* IBM */
254 #  define gmx_unused __attribute__ ((unused))
255 #else
256 #  define gmx_unused
257 #endif
258 #endif
259
260 /* Standard sizes for char* string buffers */
261 #define STRLEN 4096
262 #define BIG_STRLEN 1048576
263
264
265 #ifdef __cplusplus
266 }
267 #endif
268
269 #endif