2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team,
6 * check out http://www.gromacs.org for more information.
7 * Copyright (c) 2012, by the GROMACS development team, led by
8 * David van der Spoel, Berk Hess, Erik Lindahl, and including many
9 * others, as listed in the AUTHORS file in the top-level source
10 * directory and at http://www.gromacs.org.
12 * GROMACS is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 2.1
15 * of the License, or (at your option) any later version.
17 * GROMACS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with GROMACS; if not, see
24 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
25 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 * If you want to redistribute modifications to GROMACS, please
28 * consider that scientific software is very special. Version
29 * control is crucial - bugs must be traceable. We will be happy to
30 * consider code for inclusion in the official distribution, but
31 * derived work must not be called official GROMACS. Details are found
32 * in the README & COPYING files - if they are missing, get the
33 * official version at http://www.gromacs.org.
35 * To help us fund GROMACS development, we humbly ask that you cite
36 * the research papers on the package. Check out http://www.gromacs.org.
43 #include "visibility.h"
44 #include "types/simple.h"
52 #define M_PI 3.14159265358979323846
56 #define M_PI_2 1.57079632679489661923
60 #define M_2PI 6.28318530717958647692
64 #define M_SQRT2 sqrt(2.0)
68 #define M_1_PI 0.31830988618379067154
71 #ifndef M_FLOAT_1_SQRTPI /* used in CUDA kernels */
72 /* 1.0 / sqrt(M_PI) */
73 #define M_FLOAT_1_SQRTPI 0.564189583547756f
77 /* 1.0 / sqrt(M_PI) */
78 #define M_1_SQRTPI 0.564189583547756
82 /* 2.0 / sqrt(M_PI) */
83 #define M_2_SQRTPI 1.128379167095513
86 /* Suzuki-Yoshida Constants, for n=3 and n=5, for symplectic integration */
88 /* for n=3, w0 = w2 = 1/(2-2^-(1/3)), w1 = 1-2*w0 */
89 /* for n=5, w0 = w1 = w3 = w4 = 1/(4-4^-(1/3)), w1 = 1-4*w0 */
91 #define MAX_SUZUKI_YOSHIDA_NUM 5
92 #define SUZUKI_YOSHIDA_NUM 5
94 static const double sy_const_1
[] = { 1. };
95 static const double sy_const_3
[] = { 0.828981543588751,-0.657963087177502,0.828981543588751 };
96 static const double sy_const_5
[] = { 0.2967324292201065,0.2967324292201065,-0.186929716880426,0.2967324292201065,0.2967324292201065 };
98 static const double* sy_const
[] = {
108 static const double sy_const[MAX_SUZUKI_YOSHIDA_NUM+1][MAX_SUZUKI_YOSHIDA_NUM+1] = {
112 {0.828981543588751,-0.657963087177502,0.828981543588751},
114 {0.2967324292201065,0.2967324292201065,-0.186929716880426,0.2967324292201065,0.2967324292201065}
118 int gmx_nint(real a
);
119 real
sign(real x
,real y
);
121 real
cuberoot (real a
);
123 double gmx_erfd(double x
);
125 double gmx_erfcd(double x
);
127 float gmx_erff(float x
);
129 float gmx_erfcf(float x
);
131 #define gmx_erf(x) gmx_erfd(x)
132 #define gmx_erfc(x) gmx_erfcd(x)
134 #define gmx_erf(x) gmx_erff(x)
135 #define gmx_erfc(x) gmx_erfcf(x)
139 gmx_bool
gmx_isfinite(real x
);
141 /*! \brief Check if two numbers are within a tolerance
143 * This routine checks if the relative difference between two numbers is
144 * approximately within the given tolerance, defined as
145 * fabs(f1-f2)<=tolerance*fabs(f1+f2).
147 * To check if two floating-point numbers are almost identical, use this routine
148 * with the tolerance GMX_REAL_EPS, or GMX_DOUBLE_EPS if the check should be
149 * done in double regardless of Gromacs precision.
151 * To check if two algorithms produce similar results you will normally need
152 * to relax the tolerance significantly since many operations (e.g. summation)
153 * accumulate floating point errors.
155 * \param f1 First number to compare
156 * \param f2 Second number to compare
157 * \param tol Tolerance to use
159 * \return 1 if the relative difference is within tolerance, 0 if not.
162 gmx_within_tol(double f1
,
166 /* The or-equal is important - otherwise we return false if f1==f2==0 */
167 if( fabs(f1
-f2
) <= tol
*0.5*(fabs(f1
)+fabs(f2
)) )
180 * Check if a number is smaller than some preset safe minimum
181 * value, currently defined as GMX_REAL_MIN/GMX_REAL_EPS.
183 * If a number is smaller than this value we risk numerical overflow
184 * if any number larger than 1.0/GMX_REAL_EPS is divided by it.
186 * \return 1 if 'almost' numerically zero, 0 otherwise.
189 gmx_numzero(double a
)
191 return gmx_within_tol(a
,0.0,GMX_REAL_MIN
/GMX_REAL_EPS
);
198 const real iclog2
= 1.0/log( 2.0 );
200 return log( x
) * iclog2
;
203 /*! /brief Multiply two large ints
205 * Returns true when overflow did not occur.
209 check_int_multiply_for_overflow(gmx_large_int_t a
,
211 gmx_large_int_t
*result
);
217 #endif /* _maths_h */