1 /* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
11 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
12 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
13 * Copyright (c) 2001-2004, The GROMACS development team,
14 * check out http://www.gromacs.org for more information.
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * If you want to redistribute modifications, please consider that
22 * scientific software is very special. Version control is crucial -
23 * bugs must be traceable. We will be happy to consider code for
24 * inclusion in the official distribution, but derived work must not
25 * be called official GROMACS. Details are found in the README & COPYING
26 * files - if they are missing, get the official version at www.gromacs.org.
28 * To help us fund GROMACS development, we humbly ask that you cite
29 * the papers on the package - you can find them in the top README file.
31 * For more info, check our website at http://www.gromacs.org
34 * Gromacs Runs On Most of All Computer Systems
45 #include "types/simple.h"
53 #define M_PI 3.14159265358979323846
57 #define M_PI_2 1.57079632679489661923
61 #define M_2PI 6.28318530718
65 #define M_SQRT2 sqrt(2.0)
68 extern int gmx_nint(real a
);
69 extern real
sign(real x
,real y
);
71 extern real
gmx_erf(real x
);
72 extern real
gmx_erfc(real x
);
74 /*! \brief Check if two numbers are within a tolerance
76 * This routine checks if the relative difference between two numbers is
77 * approximately within the given tolerance, defined as
78 * fabs(f1-f2)<=tolerance*fabs(f1+f2+1.0).
80 * This expression is somewhat based on trial-and-error; the fabs() term on
81 * the right hand side avoids a division (important if f1==f2==0), and adding
82 * 1.0 is necessary when comparing a single number vs. 0.0.
84 * To check if two floating-point numbers are almost identical, use this routine
85 * with the tolerance GMX_REAL_EPS, or GMX_DOUBLE_EPS if the check should be
86 * done in double regardless of Gromacs precision.
88 * To check if two algorithms produce similar results you will normally need
89 * to relax the tolerance significantly since many operations (e.g. summation)
90 * accumulate floating point errors.
92 * \param f1 First number to compare
93 * \param f2 Second number to compare
94 * \param tol Tolerance to use
96 * \return 1 if the relative difference is within tolerance, 0 if not.
99 gmx_within_tol(double f1
,
103 /* The or-equal is important - otherwise we return false if f1==f2==0 */
104 if( fabs(f1
-f2
) <= tol
*0.5*(fabs(f1
)+fabs(f2
)) )
117 * Check if a number is smaller than some preset safe minimum
118 * value, currently defined as GMX_REAL_MIN/GMX_REAL_EPS.
120 * If a number is smaller than this value we risk numerical overflow
121 * if any number larger than 1.0/GMX_REAL_EPS is divided by it.
123 * \return 1 if 'almost' numerically zero, 0 otherwise.
126 gmx_numzero(double a
)
128 return gmx_within_tol(a
,0.0,GMX_REAL_MIN
/GMX_REAL_EPS
);
135 const real iclog2
= 1.0/log( 2.0 );
137 return log( x
) * iclog2
;
145 #endif /* _maths_h */