* Don't use C-style casts; use ``const_cast``, ``static_cast`` or
``reinterpret_cast as appropriate``. See the point on RTTI for
``dynamic_cast``. For emphasizing type (e.g. intentional integer division)
- use constructor syntax.
+ use constructor syntax. For creating real constants use the user-defined literal
+ _real (e.g. 2.5_real instead of static_cast<real>(2.5)).
* Avoid overloading functions unless all variants really do the same
thing, just with different types. Instead, consider making the
function names more descriptive.
{
fprintf(debug, "DR %d, atoms %d, %d, distance %g\n", i, ai, aj, rav);
}
- rviol = std::max(static_cast<real>(0.0), rav-idef->iparams[tp].disres.up1);
+ rviol = std::max(0.0_real, rav-idef->iparams[tp].disres.up1);
matrix[ri][rj] += w_dr[i]*rviol;
matrix[rj][ri] += w_dr[i]*rviol;
hi = std::max(hi, matrix[ri][rj]);
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2017, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2017,2018, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
{
dd = disre_dist;
}
- lo = std::max(static_cast<real>(0.0), d-dd);
+ lo = std::max(0.0_real, d-dd);
hi = d+dd;
fprintf(out, "%5d %5d %1d %5d %10d %10g %10g %10g %10g\n",
ind_grp[i]+1, ind_grp[j]+1, 1, k, 1,
{
mean = dtot[i][j]/nframes;
mean2 = dtot2[i][j]/nframes;
- rms = std::sqrt(std::max(static_cast<real>(0.0), mean2-mean*mean));
+ rms = std::sqrt(std::max(0.0_real, mean2-mean*mean));
rmsc = rms/mean;
if (mean > *meanmax)
{
{
for (f = 0; f < NFACT && bTryAgain; f++)
{
- space = std::pow(static_cast<real>(10.0), static_cast<real>(t)) * major_fact[f];
+ space = std::pow(10.0_real, static_cast<real>(t)) * major_fact[f];
/* count how many ticks we would get: */
i = 0;
for (j = 0; j < n; j++)
void invertMatrix(const matrix src, matrix dest)
{
- const real smallreal = static_cast<real>(1.0e-24);
- const real largereal = static_cast<real>(1.0e24);
+ const real smallreal = 1.0e-24_real;
+ const real largereal = 1.0e24_real;
real determinant = det(src);
- real c = static_cast<real>(1.0)/determinant;
- real fc = static_cast<real>(std::fabs(c));
+ real c = 1.0_real/determinant;
+ real fc = std::fabs(c);
if ((fc <= smallreal) || (fc >= largereal))
{
* groups of atoms we'll anyhow be limited by nsubpair_target_min,
* so this overestimation will not matter.
*/
- nsp_est = std::max(nsp_est, grid->nsubc_tot*static_cast<real>(14));
+ nsp_est = std::max(nsp_est, grid->nsubc_tot*14._real);
if (debug)
{
if (bResAt)
{
- std::fill(resAreaWork->begin(), resAreaWork->end(),
- static_cast<real>(0.0));
+ std::fill(resAreaWork->begin(), resAreaWork->end(), 0.0_real);
}
for (int i = 0; i < sel.posCount(); ++i)
{
if (surfaceSel.isDynamic())
{
std::fill(frameData.atomAreas_.begin(), frameData.atomAreas_.end(),
- static_cast<real>(0.0));
+ 0.0_real);
for (size_t i = 0; i < frameData.index_.size(); ++i)
{
frameData.atomAreas_[frameData.index_[i]] = area[i];
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2017, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2017,2018, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
#endif /* GMX_DOUBLE */
+#ifdef __cplusplus
+/*! \brief User defined literal for real numbers.
+ *
+ * Examples: 2._real, 2.5_real, .5_real. The number is always of type real.
+ *
+ * It is best to use a real constant whenever it is used only with operands which are real.
+ * If a constant is double than the compiler is forced to do operations directly involving the constant
+ * in double even if all variables are real. A constant shouldn't be real when used with double operands,
+ * because then the constant is less accurate with GMX_DOUBLE=no.
+ *
+ * See https://en.cppreference.com/w/cpp/language/user_literal for details on this lanuage feature.
+ */
+constexpr real operator"" _real(long double x) { return real(x); }
+#endif
+
#endif