Replace rounding using int(x+0.5) with roundToInt
authorRoland Schulz <roland.schulz@intel.com>
Sat, 8 Sep 2018 16:57:12 +0000 (09:57 -0700)
committerMark Abraham <mark.j.abraham@gmail.com>
Mon, 10 Sep 2018 07:41:44 +0000 (09:41 +0200)
Enable clang-tidy misc-incorrect-roundings

Change-Id: If448e37ad86c01a38e7a4951f3cb42a3b4cd1f12

46 files changed:
src/.clang-tidy
src/gromacs/analysisdata/modules/histogram.cpp
src/gromacs/awh/bias.cpp
src/gromacs/awh/grid.cpp
src/gromacs/domdec/cellsizes.cpp
src/gromacs/domdec/distribute.cpp
src/gromacs/domdec/domdec.cpp
src/gromacs/domdec/domdec_box.cpp
src/gromacs/domdec/domdec_setup.cpp
src/gromacs/ewald/pme.cpp
src/gromacs/fileio/trxio.cpp
src/gromacs/gmxana/anadih.cpp
src/gromacs/gmxana/cmat.cpp
src/gromacs/gmxana/gmx_anaeig.cpp
src/gromacs/gmxana/gmx_analyze.cpp
src/gromacs/gmxana/gmx_angle.cpp
src/gromacs/gmxana/gmx_densmap.cpp
src/gromacs/gmxana/gmx_dipoles.cpp
src/gromacs/gmxana/gmx_editconf.cpp
src/gromacs/gmxana/gmx_msd.cpp
src/gromacs/gmxana/gmx_rms.cpp
src/gromacs/gmxana/gmx_rmsdist.cpp
src/gromacs/gmxana/gmx_sorient.cpp
src/gromacs/gmxana/gmx_tcaf.cpp
src/gromacs/gmxana/gmx_vanhove.cpp
src/gromacs/gmxana/gmx_wham.cpp
src/gromacs/gmxana/sfactor.cpp
src/gromacs/gmxpreprocess/convparm.cpp
src/gromacs/gmxpreprocess/genconf.cpp
src/gromacs/gmxpreprocess/grompp.cpp
src/gromacs/gmxpreprocess/readir.cpp
src/gromacs/gmxpreprocess/toppush.cpp
src/gromacs/mdlib/coupling.cpp
src/gromacs/mdlib/nbnxn_search.cpp
src/gromacs/mdlib/nsgrid.cpp
src/gromacs/mdlib/shellfc.cpp
src/gromacs/mdlib/stat.cpp
src/gromacs/mdlib/update.cpp
src/gromacs/mdrun/minimize.cpp
src/gromacs/mdrun/tpi.cpp
src/gromacs/pulling/pull_rotation.cpp
src/gromacs/statistics/statistics.cpp
src/gromacs/tables/forcetable.cpp
src/gromacs/timing/wallcycle.cpp
src/gromacs/tools/convert_tpr.cpp
src/programs/mdrun/mdrun.cpp

index 56ffbb29ff48d40a5a75b5926c149498918aa8d4..21b88ea02602a8f3b7c23137fe0b748e8aab08f0 100644 (file)
@@ -1,5 +1,5 @@
 Checks:  clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-security.insecureAPI.strcpy,
-         bugprone-*,misc-*,readability-*,performance-*,mpi-*,-misc-incorrect-roundings,
+         bugprone-*,misc-*,readability-*,performance-*,mpi-*,
          -readability-inconsistent-declaration-parameter-name,
          -readability-function-size,-readability-else-after-return,
          modernize-use-nullptr,modernize-use-emplace,
index 092b0009b1efdbbfe69215618f960da69bd19095..f77f96e9c76c83ef3358e7f411079baeb78142af 100644 (file)
@@ -51,6 +51,7 @@
 #include "gromacs/analysisdata/dataframe.h"
 #include "gromacs/analysisdata/datastorage.h"
 #include "gromacs/analysisdata/framelocaldata.h"
+#include "gromacs/math/functions.h"
 #include "gromacs/utility/basedefinitions.h"
 #include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/gmxassert.h"
@@ -140,7 +141,7 @@ AnalysisHistogramSettings::AnalysisHistogramSettings(
             binWidth_  = settings.binWidth_;
             firstEdge_ = binWidth_ * std::floor(settings.min_ / binWidth_);
             lastEdge_  = binWidth_ * std::ceil(settings.max_ / binWidth_);
-            binCount_  = static_cast<int>((lastEdge_ - firstEdge_) / binWidth_ + 0.5);
+            binCount_  = gmx::roundToInt((lastEdge_ - firstEdge_) / binWidth_);
         }
         else
         {
@@ -165,7 +166,7 @@ AnalysisHistogramSettings::AnalysisHistogramSettings(
             else
             {
                 binWidth_ = settings.binWidth_;
-                binCount_ = static_cast<int>((lastEdge_ - firstEdge_) / binWidth_ + 0.5);
+                binCount_ = gmx::roundToInt((lastEdge_ - firstEdge_) / binWidth_);
                 if (settings.bIntegerBins_)
                 {
                     firstEdge_ -= 0.5 * binWidth_;
index 27167183d7aa5a658ba3a4a96a2938b5fb547efe..bde1a68fbeac4416386f3092cc8e74157c42763d 100644 (file)
@@ -57,6 +57,7 @@
 #include "gromacs/compat/make_unique.h"
 #include "gromacs/fileio/gmxfio.h"
 #include "gromacs/gmxlib/network.h"
+#include "gromacs/math/functions.h"
 #include "gromacs/math/utilities.h"
 #include "gromacs/mdtypes/awh-history.h"
 #include "gromacs/mdtypes/awh-params.h"
@@ -222,7 +223,7 @@ static int64_t countSamples(const std::vector<PointState> &pointState)
         numSamples += point.weightSumTot();
     }
 
-    return static_cast<int64_t>(numSamples + 0.5);
+    return gmx::roundToInt64(numSamples);
 }
 
 /*! \brief
index 243c1639c8669af3bcf9434db8c324b24a3befee..7b6492791f0818916958c9d8569a550abc19f90c 100644 (file)
@@ -52,6 +52,7 @@
 
 #include <algorithm>
 
+#include "gromacs/math/functions.h"
 #include "gromacs/math/utilities.h"
 #include "gromacs/mdtypes/awh-params.h"
 #include "gromacs/utility/cstringutil.h"
@@ -497,9 +498,8 @@ static int pointDistanceAlongAxis(const GridAxis &axis, double x, double x0)
         double period = axis.period();
         double dx     = getDeviationPeriodic(x, x0, period);
 
-        /* Transform the distance into a point distance.
-           Shift by +0.5 so we can use floor or integer casting below to get the integer index */
-        distance = static_cast<int>(floor(dx/axis.spacing() + 0.5));
+        /* Transform the distance into a point distance by rounding. */
+        distance = gmx::roundToInt(dx/axis.spacing());
 
         /* If periodic, shift the point distance to be in [0, period) */
         distance = indexWithinPeriod(distance, axis.numPointsInPeriod());
index 1a776ebf384e60ec975f6d55006ec0a472615c5e..1719c7f4e09891f9942daf7c39b6e2076b49d797 100644 (file)
@@ -759,10 +759,10 @@ static void distribute_dd_cell_sizes_dlb(gmx_domdec_t *dd,
         relative_to_absolute_cell_bounds(dd, ddbox, d1);
     }
     /* Convert the communicated shift from float to int */
-    comm.ddpme[0].maxshift = static_cast<int>(cellFracRow[pos++] + 0.5);
+    comm.ddpme[0].maxshift = gmx::roundToInt(cellFracRow[pos++]);
     if (d >= 1)
     {
-        comm.ddpme[1].maxshift = static_cast<int>(cellFracRow[pos++] + 0.5);
+        comm.ddpme[1].maxshift = gmx::roundToInt(cellFracRow[pos++]);
     }
 }
 
index 040d75626e13307082bd72d46153ff939263a3fe..1b4520f425aae261474fea0e7b8420d3c6d888b3 100644 (file)
@@ -422,7 +422,7 @@ getAtomGroupDistribution(FILE *fplog,
         fprintf(fplog, "Atom distribution over %d domains: av %d stddev %d min %d max %d\n",
                 dd->nnodes,
                 nat_sum,
-                static_cast<int>(std::sqrt(nat2_sum - gmx::square(static_cast<double>(nat_sum)) + 0.5)),
+                gmx::roundToInt(std::sqrt(nat2_sum - gmx::square(static_cast<double>(nat_sum)))),
                 nat_min, nat_max);
     }
 
index e8cd6942b35d203fbc98b019bc9c81a871196f6b..dbe8dc1edb543dbc1564d6346978682b94064d67 100644 (file)
@@ -2223,7 +2223,7 @@ static void get_load_distribution(gmx_domdec_t *dd, gmx_wallcycle_t wcycle)
                         pos++;
                         if (d < dd->ndim-1)
                         {
-                            load->flags = static_cast<int>(load->load[pos++] + 0.5);
+                            load->flags = gmx::roundToInt(load->load[pos++]);
                         }
                         if (d > 0)
                         {
@@ -2366,7 +2366,7 @@ static void print_dd_load_av(FILE *fplog, gmx_domdec_t *dd)
         msg += " " + dlbStateStr + "\n";
         msg += gmx::formatString(" Average load imbalance: %.1f%%.\n", imbalance*100);
         msg += gmx::formatString(" The balanceable part of the MD step is %d%%, load imbalance is computed from this.\n",
-                                 static_cast<int>(dd_force_load_fraction(dd)*100 + 0.5));
+                                 gmx::roundToInt(dd_force_load_fraction(dd)*100));
         msg += gmx::formatString(" Part of the total run time spent waiting due to load imbalance: %.1f%%.\n",
                                  lossFraction*100);
         fprintf(fplog, "%s", msg.c_str());
@@ -2532,7 +2532,7 @@ static void dd_print_load_verbose(gmx_domdec_t *dd)
     }
     if (dd->nnodes > 1)
     {
-        fprintf(stderr, "imb F %2d%% ", static_cast<int>(dd_f_imbal(dd)*100+0.5));
+        fprintf(stderr, "imb F %2d%% ", gmx::roundToInt(dd_f_imbal(dd)*100));
     }
     if (dd->comm->cycl_n[ddCyclPME])
     {
index ebd4de8d1b8f10ecb1120e2d42b0f7a03bd29f26..7f6822fba35ecd9da87f4cb46eb9766d6517d594 100644 (file)
@@ -103,7 +103,7 @@ static void calc_pos_av_stddev(int n, const rvec *x,
             s1[d] = receiveBuffer[d];
             s2[d] = receiveBuffer[DIM + d];
         }
-        n = static_cast<int>(receiveBuffer[6] + 0.5);
+        n = gmx::roundToInt(receiveBuffer[6]);
     }
 #else  // GMX_MPI
     GMX_UNUSED_VALUE(mpiCommunicator);
index e6766d9c8a5dc9a420b19085aa5209e1665a2586..1ff9e88c37033d41e715be96c0aa4075b12e1916 100644 (file)
@@ -143,8 +143,8 @@ static gmx_bool fits_pp_pme_perf(int ntot, int npme, float ratio)
     std::vector<int> mdiv;
     factorize(ntot - npme, &div, &mdiv);
 
-    int npp_root3  = static_cast<int>(std::cbrt(ntot - npme) + 0.5);
-    int npme_root2 = static_cast<int>(std::sqrt(static_cast<double>(npme)) + 0.5);
+    int npp_root3  = gmx::roundToInt(std::cbrt(ntot - npme));
+    int npme_root2 = gmx::roundToInt(std::sqrt(static_cast<double>(npme)));
 
     /* The check below gives a reasonable division:
      * factor 5 allowed at 5 or more PP ranks,
@@ -237,7 +237,7 @@ static int guess_npme(FILE *fplog, const gmx_mtop_t *mtop, const t_inputrec *ir,
     {
         gmx_fatal(FARGS, "Could not find an appropriate number of separate PME ranks. i.e. >= %5f*#ranks (%d) and <= #ranks/2 (%d) and reasonable performance wise (grid_x=%d, grid_y=%d).\n"
                   "Use the -npme option of mdrun or change the number of ranks or the PME grid dimensions, see the manual for details.",
-                  ratio, static_cast<int>(0.95*ratio*nrank_tot + 0.5), nrank_tot/2, ir->nkx, ir->nky);
+                  ratio, gmx::roundToInt(0.95*ratio*nrank_tot), nrank_tot/2, ir->nkx, ir->nky);
     }
     else
     {
index 2d2f04484a5cd0a858d0cf339410f7bacbb55699..46411815da26cf4d28aafaa21173650aea8cd105 100644 (file)
@@ -803,7 +803,7 @@ gmx_pme_t *gmx_pme_init(const t_commrec     *cr,
                     "      PME grid_x (%d) and grid_y (%d) should be divisible by #PME_ranks_x (%d)\n"
                     "      and PME grid_y (%d) and grid_z (%d) should be divisible by #PME_ranks_y (%d)\n"
                     "\n",
-                    static_cast<int>((imbal-1)*100 + 0.5),
+                    gmx::roundToInt((imbal-1)*100),
                     pme->nkx, pme->nky, pme->nnodes_major,
                     pme->nky, pme->nkz, pme->nnodes_minor);
         }
index f69f6dbc2e5d6446f99f0919de3cc411b70f0690..73a036433c842fe88a7f678022767bb033ea8980 100644 (file)
@@ -226,7 +226,7 @@ int prec2ndec(real prec)
         gmx_fatal(FARGS, "DEATH HORROR prec (%g) <= 0 in prec2ndec", prec);
     }
 
-    return static_cast<int>(log(prec)/log(10.0)+0.5);
+    return gmx::roundToInt(log(prec)/log(10.0));
 }
 
 real ndec2prec(int ndec)
index bc524a5890d8955a4492e729f2a065012b60cbf5..cf7869ced0ee85cec290c293dfa34323cc697dc8 100644 (file)
@@ -961,7 +961,7 @@ void read_ang_dih(const char *trj_fn,
             }
 
             /* Update the distribution histogram */
-            angind = static_cast<int>((angle*maxangstat)/pifac + 0.5);
+            angind = gmx::roundToInt((angle*maxangstat)/pifac);
             if (angind == maxangstat)
             {
                 angind = 0;
index d19601cff21322e98c5ca760475383d989e0414c..ec67259db610917994cf06e6bb0ec676283829d0 100644 (file)
@@ -3,7 +3,7 @@
  *
  * 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.
@@ -220,7 +220,7 @@ void low_rmsd_dist(const char *fn, real maxrms, int nn, real **mat,
     {
         for (j = i+1; j < nn; j++)
         {
-            x = static_cast<int>(fac*mat[i][j]+0.5);
+            x = gmx::roundToInt(fac*mat[i][j]);
             if (x <= 100)
             {
                 histo[x]++;
index 1d213722f7ae3fd115895e54cf846a58da120a9c..b9e1e7d1d0c645e0aa6e7516e1557fe3c3ae0f24 100644 (file)
@@ -273,7 +273,7 @@ compare(int natoms, int n1, rvec **eigvec1, int n2, rvec **eigvec2,
     if (neig1 != n || neig2 != n)
     {
         fprintf(stdout, "this is %d%% and %d%% of the total trace\n",
-                static_cast<int>(100*sum1/trace1+0.5), static_cast<int>(100*sum2/trace2+0.5));
+                gmx::roundToInt(100*sum1/trace1), gmx::roundToInt(100*sum2/trace2));
     }
     fprintf(stdout, "Square root of the traces: %g and %g\n",
             std::sqrt(sum1), std::sqrt(sum2));
index d76bc83f6c37eb42e6d8e13d0fd23c5b21e233ac..4e98ff3d98b57c353ed4e8de60eae11f4599ee0b 100644 (file)
@@ -271,7 +271,7 @@ static void histogram(const char *distfile, real binwidth, int n, int nset, real
     }
     maxval += binwidth;
 
-    nbin = static_cast<int>(((maxval - minval)/binwidth + 0.5) + 1);
+    nbin = gmx::roundToInt(((maxval - minval)/binwidth) + 1);
     fprintf(stderr, "Making distributions with %d bins\n", nbin);
     snew(histo, nbin);
     fp = xvgropen(distfile, "Distribution", "", "", oenv);
@@ -283,7 +283,7 @@ static void histogram(const char *distfile, real binwidth, int n, int nset, real
         }
         for (i = 0; i < n; i++)
         {
-            histo[static_cast<int>((val[s][i] - minval)/binwidth + 0.5)]++;
+            histo[gmx::roundToInt((val[s][i] - minval)/binwidth)]++;
         }
         for (i = 0; i < nbin; i++)
         {
@@ -334,9 +334,9 @@ static void average(const char *avfile, int avbar_opt,
         {
             snew(tmp, nset);
             fprintf(fp, "@TYPE xydydy\n");
-            edge = static_cast<int>(nset*0.05+0.5);
+            edge = gmx::roundToInt(nset*0.05);
             fprintf(stdout, "Errorbars: discarding %d points on both sides: %d%%"
-                    " interval\n", edge, static_cast<int>(100.*(nset-2*edge)/nset+0.5));
+                    " interval\n", edge, gmx::roundToInt(100.*(nset-2*edge)/nset));
         }
         else
         {
index c1f2370c1b2ff342f7ae6072552c4e5d32208d50..1b56598e0fd06351050efc0a969f86d1e73d6302 100644 (file)
@@ -229,7 +229,7 @@ int gmx_g_angle(int argc, char *argv[])
     }
 
     /* Calculate bin size */
-    maxangstat = static_cast<int>(maxang/binwidth+0.5);
+    maxangstat = gmx::roundToInt(maxang/binwidth);
     binwidth   = maxang/maxangstat;
 
     rd_index(ftp2fn(efNDX, NFILE, fnm), 1, &isize, &index, &grpname);
index de5e182276f201911bfd38ad8e00a6a7dc5a5142..8ba35939442b61c6e2e43aed0fef95ec97db34a1 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,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.
@@ -241,17 +241,17 @@ int gmx_densmap(int argc, char *argv[])
     {
         if (n1 == 0)
         {
-            n1 = static_cast<int>(box[c1][c1]/bin + 0.5);
+            n1 = gmx::roundToInt(box[c1][c1]/bin);
         }
         if (n2 == 0)
         {
-            n2 = static_cast<int>(box[c2][c2]/bin + 0.5);
+            n2 = gmx::roundToInt(box[c2][c2]/bin);
         }
     }
     else
     {
-        n1      = static_cast<int>(2*amax/bin + 0.5);
-        nradial = static_cast<int>(rmax/bin + 0.5);
+        n1      = gmx::roundToInt(2*amax/bin);
+        nradial = gmx::roundToInt(rmax/bin);
         invspa  = n1/(2*amax);
         invspz  = nradial/rmax;
         if (bMirror)
index 302818b18ee0db7d26e34bc81e09114497ec77bc..5fe85b58a243989c9fe8c4818ff249beb3d91ab5 100644 (file)
@@ -1120,7 +1120,7 @@ static void do_dip(const t_topology *top, int ePBC, real volume,
                     mu_ave += mu_mol;                         /* calc. the average mu */
 
                     /* Update the dipole distribution */
-                    ibin = static_cast<int>(ndipbin*mu_mol/mu_max + 0.5);
+                    ibin = gmx::roundToInt(ndipbin*mu_mol/mu_max);
                     if (ibin < ndipbin)
                     {
                         dipole_bin[ibin]++;
index 9d012ec3ee674ce08370d01a7f92f9a651ca0253..5b249260b0a67ad914ebfe312c490852fe54a31f 100644 (file)
@@ -381,9 +381,9 @@ static void visualize_box(FILE *out, int a0, int r0, matrix box, const rvec grid
     a0++;
     r0++;
 
-    nx   = static_cast<int>(gridsize[XX] + 0.5);
-    ny   = static_cast<int>(gridsize[YY] + 0.5);
-    nz   = static_cast<int>(gridsize[ZZ] + 0.5);
+    nx   = gmx::roundToInt(gridsize[XX]);
+    ny   = gmx::roundToInt(gridsize[YY]);
+    nz   = gmx::roundToInt(gridsize[ZZ]);
     nbox = nx * ny * nz;
     if (TRICLINIC(box))
     {
index 3d4e240a2f77977eac6bdcc73f60310f9ee51faf..8c54f617e68da123a37431f6648c58a38deb5a72 100644 (file)
@@ -957,7 +957,7 @@ static void do_corr(const char *trx_file, const char *ndx_file, const char *msd_
 
     if (beginfit == -1)
     {
-        i0       = static_cast<int>(0.1*(msd->nframes - 1) + 0.5);
+        i0       = gmx::roundToInt(0.1*(msd->nframes - 1));
         beginfit = msd->time[i0];
     }
     else
@@ -970,7 +970,7 @@ static void do_corr(const char *trx_file, const char *ndx_file, const char *msd_
 
     if (endfit == -1)
     {
-        i1     = static_cast<int>(0.9*(msd->nframes - 1) + 0.5) + 1;
+        i1     = gmx::roundToInt(0.9*(msd->nframes - 1)) + 1;
         endfit = msd->time[i1-1];
     }
     else
index e981c775e69607f14d5be76721610ca29d805ec4..1e29cc0fd48b41aa2a621627609fce3ce8a671b2 100644 (file)
@@ -845,7 +845,7 @@ int gmx_rms(int argc, char *argv[])
             if (bDeltaLog)
             {
                 delta_scalex = 8.0/std::log(2.0);
-                delta_xsize  = static_cast<int>(std::log(tel_mat/2.)*delta_scalex+0.5)+1;
+                delta_xsize  = gmx::roundToInt(std::log(tel_mat/2.)*delta_scalex)+1;
             }
             else
             {
@@ -1035,9 +1035,9 @@ int gmx_rms(int argc, char *argv[])
                         {
                             if (bDeltaLog)
                             {
-                                mx = static_cast<int>(std::log(static_cast<real>(mx))*delta_scalex+0.5);
+                                mx = gmx::roundToInt(std::log(static_cast<real>(mx))*delta_scalex);
                             }
-                            my             = static_cast<int>(rmsd_mat[i][j]*delta_scaley*del_lev+0.5);
+                            my             = gmx::roundToInt(rmsd_mat[i][j]*delta_scaley*del_lev);
                             delta_tot[mx] += 1.0;
                             if ((rmsd_mat[i][j] >= 0) && (rmsd_mat[i][j] <= delta_maxy))
                             {
index 6cf2eae1edda8939f375bee485bd5b74b714590c..0e47df8cc6befd27418fe21e2d05af2ec133e780 100644 (file)
@@ -547,7 +547,7 @@ static void write_noe(FILE *fp, int gnr, t_noe **noe, t_noe_gr *noe_gr, real rma
                         "%4d %4d %4s %4s%3d %4d %4d %4s %4s%3d %5s %5s %8d %2d %2s %s\n",
                         gri.ianr+1, gri.anr+1, gri.aname, gri.rname, gri.rnr+1,
                         grj.ianr+1, grj.anr+1, grj.aname, grj.rname, grj.rnr+1,
-                        b3, b6, static_cast<int>(noe[i][j].i_6+0.5), grj.rnr-gri.rnr, buf,
+                        b3, b6, gmx::roundToInt(noe[i][j].i_6), grj.rnr-gri.rnr, buf,
                         noe2scale(r3, r6, rmax));
             }
         }
index 2a88186f8bf92ebb64f1e82af4600e18de705e28..837c234828841ec2685eb7739a7e58b3284fd8c0 100644 (file)
@@ -255,8 +255,8 @@ int gmx_sorient(int argc, char *argv[])
     rcut2 = gmx::square(rcut);
 
     invbw = 1/binwidth;
-    nbin1 = 1+static_cast<int>(2*invbw + 0.5);
-    nbin2 = 1+static_cast<int>(invbw + 0.5);
+    nbin1 = 1+gmx::roundToInt(2*invbw);
+    nbin2 = 1+gmx::roundToInt(invbw);
 
     invrbw = 1/rbinw;
 
index 6cb1ed63fc178fbcea7a1839f97a33104cd83945..7e1553e18e45cf397bbced9dc9c4e99b2897d937 100644 (file)
@@ -107,9 +107,9 @@ static void process_tcaf(int nframes, real dt, int nkc, real **tc, rvec *kfac,
     }
 
     ncorr = (nframes+1)/2;
-    if (ncorr > static_cast<int>(5*wt/dt+0.5))
+    if (ncorr > gmx::roundToInt(5*wt/dt))
     {
-        ncorr = static_cast<int>(5*wt/dt+0.5)+1;
+        ncorr = gmx::roundToInt(5*wt/dt)+1;
     }
     snew(tcaf, nk);
     for (k = 0; k < nk; k++)
index 7d2ca2c17018b1a0ef1542cda0a049599af069b4..53e57368ef4116ee5d8104de43b6317c8f32a0e4 100644 (file)
@@ -240,7 +240,7 @@ int gmx_vanhove(int argc, char *argv[])
             fmmax = nfr - 1;
         }
         snew(mcount, fmmax);
-        nbin = static_cast<int>(rmax*invbin + 0.5);
+        nbin = gmx::roundToInt(rmax*invbin);
         if (sbin == 0)
         {
             mat_nx = fmmax + 1;
@@ -334,14 +334,14 @@ int gmx_vanhove(int argc, char *argv[])
                 }
                 else
                 {
-                    mbin = static_cast<int>(std::sqrt(fbin*dt)*invsbin + 0.5);
+                    mbin = gmx::roundToInt(std::sqrt(fbin*dt)*invsbin);
                 }
                 for (i = 0; i < isize; i++)
                 {
                     d2 = distance2(sx[f][i], sx[ff][i]);
                     if (mbin < mat_nx && d2 < rmax2)
                     {
-                        bin = static_cast<int>(std::sqrt(d2)*invbin + 0.5);
+                        bin = gmx::roundToInt(std::sqrt(d2)*invbin);
                         if (bin < nbin)
                         {
                             mat[mbin][bin] += 1;
@@ -372,7 +372,7 @@ int gmx_vanhove(int argc, char *argv[])
                     for (i = 0; i < isize; i++)
                     {
                         d2  = distance2(sx[f][i], sx[ff][i]);
-                        bin = static_cast<int>(std::sqrt(d2)*invbin + 0.5);
+                        bin = gmx::roundToInt(std::sqrt(d2)*invbin);
                         if (bin >= nalloc)
                         {
                             nallocn = 10*(bin/10) + 11;
index 1b8929506f901cc3aacb8bad77b08bc15c55e14b..395d9e96deb51234b9e9de12af56ffc91858d46a 100644 (file)
@@ -659,7 +659,7 @@ static void read_pdo_data(FILE * file, t_UmbrellaHeader * header,
 
         sscanf(ptr, fmtlf, &time); /* printf("Time %f\n",time); */
         /* Round time to fs */
-        time = 1.0/1000*( static_cast<int64_t> (time*1000+0.5) );
+        time = 1.0/1000*( gmx::roundToInt64(time*1000) );
 
         /* get time step of pdo file */
         if (count == 0)
@@ -671,7 +671,7 @@ static void read_pdo_data(FILE * file, t_UmbrellaHeader * header,
             dt = time-time0;
             if (opt->dt > 0.0)
             {
-                dstep = static_cast<int>(opt->dt/dt+0.5);
+                dstep = gmx::roundToInt(opt->dt/dt);
                 if (dstep == 0)
                 {
                     dstep = 1;
@@ -799,7 +799,7 @@ static void enforceEqualWeights(t_UmbrellaWindow * window, int nWindows)
             {
                 window[j].Histo[k][i] *= ratio;
             }
-            window[j].N[k] = static_cast<int>(ratio*window[j].N[k] + 0.5);
+            window[j].N[k] = gmx::roundToInt(ratio*window[j].N[k]);
         }
     }
 }
@@ -1114,7 +1114,7 @@ static void symmetrizeProfile(double* profile, t_UmbrellaOptions *opt)
         z    = min+(i+0.5)*dz;
         zsym = -z;
         /* bin left of zsym */
-        j = static_cast<int> (std::floor((zsym-min)/dz-0.5));
+        j = gmx::roundToInt((zsym-min)/dz)-1;
         if (j >= 0 && (j+1) < bins)
         {
             /* interpolate profile linearly between bins j and j+1 */
@@ -2352,7 +2352,7 @@ static void read_pull_xf(const char *fn, t_UmbrellaHeader * header,
     for (i = 0; i < nt; i++)
     {
         /* Do you want that time frame? */
-        t = 1.0/1000*( static_cast<int64_t> ((y[0][i]*1000) + 0.5)); /* round time to fs */
+        t = 1.0/1000*( gmx::roundToInt64((y[0][i]*1000))); /* round time to fs */
 
         /* get time step of pdo file and get dstep from opt->dt */
         if (i == 0)
@@ -2364,7 +2364,7 @@ static void read_pull_xf(const char *fn, t_UmbrellaHeader * header,
             dt = t-time0;
             if (opt->dt > 0.0)
             {
-                dstep = static_cast<int>(opt->dt/dt+0.5);
+                dstep = gmx::roundToInt(opt->dt/dt);
                 if (dstep == 0)
                 {
                     dstep = 1;
@@ -2719,7 +2719,7 @@ static void calcIntegratedAutocorrelationTimes(t_UmbrellaWindow *window, int nwi
         snew(count, ncorr);
         dt = window[i].dt;
         snew(window[i].tau, window[i].nPull);
-        restart = static_cast<int>(opt->acTrestart/dt+0.5);
+        restart = gmx::roundToInt(opt->acTrestart/dt);
         if (restart == 0)
         {
             restart = 1;
index 4432f906065b5303735197c2f12fa214ba68d91b..603f45860281f5123400a19ed6c5df72565ed149 100644 (file)
@@ -176,9 +176,9 @@ extern void compute_structure_factor (structure_factor_t * sft, matrix box,
     k_factor[YY] = 2 * M_PI / box[YY][YY];
     k_factor[ZZ] = 2 * M_PI / box[ZZ][ZZ];
 
-    maxkx = static_cast<int>(end_q / k_factor[XX] + 0.5);
-    maxky = static_cast<int>(end_q / k_factor[YY] + 0.5);
-    maxkz = static_cast<int>(end_q / k_factor[ZZ] + 0.5);
+    maxkx = gmx::roundToInt(end_q / k_factor[XX]);
+    maxky = gmx::roundToInt(end_q / k_factor[YY]);
+    maxkz = gmx::roundToInt(end_q / k_factor[ZZ]);
 
     snew (counter, sf->n_angles);
 
@@ -205,7 +205,7 @@ extern void compute_structure_factor (structure_factor_t * sft, matrix box,
                     krr = std::sqrt (gmx::square(kx) + gmx::square(ky) + gmx::square(kz));
                     if (krr >= start_q && krr <= end_q)
                     {
-                        kr = static_cast<int>(krr/sf->ref_k + 0.5);
+                        kr = gmx::roundToInt(krr/sf->ref_k);
                         if (kr < sf->n_angles)
                         {
                             counter[kr]++; /* will be used for the copmutation
@@ -241,7 +241,7 @@ extern void compute_structure_factor (structure_factor_t * sft, matrix box,
                 kz = k * k_factor[ZZ]; krr = std::sqrt (gmx::square(kx) + gmx::square(ky)
                                                         + gmx::square(kz)); if (krr >= start_q && krr <= end_q)
                 {
-                    kr = static_cast<int>(krr / sf->ref_k + 0.5);
+                    kr = gmx::roundToInt(krr / sf->ref_k);
                     if (kr < sf->n_angles && counter[kr] != 0)
                     {
                         sf->F[group][kr] +=
@@ -505,7 +505,7 @@ extern int do_scattering_intensity (const char* fnTPS, const char* fnNDX,
 
     sf->ref_k = (2.0 * M_PI) / (r_tmp);
     /* ref_k will be the reference momentum unit */
-    sf->n_angles = static_cast<int>(end_q / sf->ref_k + 0.5);
+    sf->n_angles = gmx::roundToInt(end_q / sf->ref_k);
 
     snew (sf->F, ng);
     for (i = 0; i < ng; i++)
index aaea388177ab2b9bbb999e4adae5f9839a439b6b..525aa064e6fe044b258d501360cf2bdade447fa0 100644 (file)
 
 static int round_check(real r, int limit, int ftype, const char *name)
 {
-    int i;
-
-    if (r >= 0)
-    {
-        i = static_cast<int>(r + 0.5);
-    }
-    else
-    {
-        i = static_cast<int>(r - 0.5);
-    }
+    const int i = gmx::roundToInt(r);
 
     if (r-i > 0.01 || r-i < -0.01)
     {
index 70849f1e643eca7d062675211595ceee7d948493..d3665adacf2661303992f686a63c1a837f759b99 100644 (file)
@@ -169,9 +169,9 @@ int gmx_genconf(int argc, char *argv[])
     gmx::DefaultRandomEngine rng(seed);
 
     bTRX = ftp2bSet(efTRX, NFILE, fnm);
-    nx   = static_cast<int>(nrbox[XX]+0.5);
-    ny   = static_cast<int>(nrbox[YY]+0.5);
-    nz   = static_cast<int>(nrbox[ZZ]+0.5);
+    nx   = gmx::roundToInt(nrbox[XX]);
+    ny   = gmx::roundToInt(nrbox[YY]);
+    nz   = gmx::roundToInt(nrbox[ZZ]);
 
     if ((nx <= 0) || (ny <= 0) || (nz <= 0))
     {
index cbf86d9e301781b4602fbcdf6e2d3706aae793ac..338de9a82b2b4e61442b5b95589b193a1936a4c7 100644 (file)
@@ -2061,7 +2061,7 @@ int gmx_grompp(int argc, char *argv[])
                 else
                 {
                     sprintf(warn_buf, "NVE simulation with an initial temperature of zero: will use a Verlet buffer of %d%%. Check your energy drift!",
-                            static_cast<int>(verlet_buffer_ratio_NVE_T0*100 + 0.5));
+                            gmx::roundToInt(verlet_buffer_ratio_NVE_T0*100));
                     warning_note(wi, warn_buf);
                 }
             }
@@ -2099,8 +2099,8 @@ int gmx_grompp(int argc, char *argv[])
                     {
                         sprintf(warn_buf, "You are using a Verlet buffer tolerance of %g kJ/mol/ps for an NVE simulation of length %g ps, which can give a final drift of %d%%. For conserving energy to %d%% when using constraints, you might need to set verlet-buffer-tolerance to %.1e.",
                                 ir->verletbuf_tol, ir->nsteps*ir->delta_t,
-                                static_cast<int>(ir->verletbuf_tol/totalEnergyDriftPerAtomPerPicosecond*100 + 0.5),
-                                static_cast<int>(100*driftTolerance + 0.5),
+                                gmx::roundToInt(ir->verletbuf_tol/totalEnergyDriftPerAtomPerPicosecond*100),
+                                gmx::roundToInt(100*driftTolerance),
                                 driftTolerance*totalEnergyDriftPerAtomPerPicosecond);
                         warning_note(wi, warn_buf);
                     }
index 3425f9884e16d953f831250522603e56d71cca67..62885e2ebdd00b77f2f59ae4c4fa2bb70f2e7407 100644 (file)
@@ -4012,7 +4012,7 @@ void triple_check(const char *mdparin, t_inputrec *ir, gmx_mtop_t *sys,
         {
             for (i = 0; i < ir->opts.ngtc; i++)
             {
-                int nsteps = static_cast<int>(ir->opts.tau_t[i]/ir->delta_t + 0.5);
+                int nsteps = gmx::roundToInt(ir->opts.tau_t[i]/ir->delta_t);
                 sprintf(err_buf, "tau_t/delta_t for group %d for temperature control method %s must be a multiple of nstcomm (%d), as velocities of atoms in coupled groups are randomized every time step. The input tau_t (%8.3f) leads to %d steps per randomization", i, etcoupl_names[ir->etc], ir->nstcomm, ir->opts.tau_t[i], nsteps);
                 CHECK(nsteps % ir->nstcomm != 0);
             }
index 46cf9f3bbd164e228ed2bf02bf4c2d4d19cd25bd..8acd507abf4ac2a528c94b2df98cf5852254d3f3 100644 (file)
@@ -52,6 +52,7 @@
 #include "gromacs/gmxpreprocess/readir.h"
 #include "gromacs/gmxpreprocess/topdirs.h"
 #include "gromacs/gmxpreprocess/toputil.h"
+#include "gromacs/math/functions.h"
 #include "gromacs/mdtypes/md_enums.h"
 #include "gromacs/topology/ifunc.h"
 #include "gromacs/topology/symtab.h"
@@ -2070,7 +2071,7 @@ void push_bond(directive d, t_params bondtype[], t_params bond[],
     {
         sprintf(errbuf, "%s table number can not be perturbed %d!=%d",
                 interaction_function[ftype].longname,
-                static_cast<int>(param.c[0]+0.5), static_cast<int>(param.c[2]+0.5));
+                gmx::roundToInt(param.c[0]), gmx::roundToInt(param.c[2]));
         warning_error_and_exit(wi, errbuf, FARGS);
     }
 
index 8d9313a8b3247d53cec06e14da64b0d3ffa2d826..27304afeed903effacc4d46fc1fa46d5c8a11349 100644 (file)
@@ -1448,7 +1448,7 @@ static real vrescale_sumnoises(real                            nn,
         int  nn_int, i;
         real gauss;
 
-        nn_int = static_cast<int>(nn + 0.5);
+        nn_int = gmx::roundToInt(nn);
 
         if (nn - nn_int < -ndeg_tol || nn - nn_int > ndeg_tol)
         {
index bc2ee37f55abc9acbc51118b42de65c57a1f013a..eae0873ae6e909b79e13e30b4567827fb7ed9ccf 100644 (file)
@@ -2773,7 +2773,7 @@ static void get_nsubpair_target(const nbnxn_search   *nbs,
      * (and we can't chop up j-groups) so we use a minimum target size of 36.
      */
     *nsubpair_target  = std::max(nsubpair_target_min,
-                                 static_cast<int>(nsp_est/min_ci_balanced + 0.5));
+                                 roundToInt(nsp_est/min_ci_balanced));
     *nsubpair_tot_est = static_cast<int>(nsp_est);
 
     if (debug)
index 4c8df50a1cac39fdd72de199ac26f41f599ee79c..941fe11c37f4f482a1174e0d504dd0d6f8273502 100644 (file)
@@ -320,7 +320,7 @@ static void set_grid_sizes(matrix box, rvec izones_x0, rvec izones_x1, real rlis
              * we will use the normal grid ns that checks all cells
              * that are within cut-off distance of the i-particle.
              */
-            grid->n[i] = static_cast<int>(size*inv_r_ideal + 0.5);
+            grid->n[i] = gmx::roundToInt(size*inv_r_ideal);
             if (grid->n[i] < 2)
             {
                 grid->n[i] = 2;
@@ -335,7 +335,7 @@ static void set_grid_sizes(matrix box, rvec izones_x0, rvec izones_x1, real rlis
              * We can then beforehand exclude certain ns grid cells
              * for non-home i-particles.
              */
-            grid->ncpddc[i] = static_cast<int>(izones_size[i]*inv_r_ideal + 0.5);
+            grid->ncpddc[i] = gmx::roundToInt(izones_size[i]*inv_r_ideal);
             if (grid->ncpddc[i] < 2)
             {
                 grid->ncpddc[i] = 2;
index e4b54384c5ba642101ca418cc2f3ac543704f45c..667c9581508bfa4e2e382d41f4302d5c0433ee87 100644 (file)
@@ -848,7 +848,7 @@ static real rms_force(const t_commrec *cr, gmx::ArrayRef<const gmx::RVec> force,
         buf[2] = *sf_dir;
         buf[3] = *Epot;
         gmx_sumd(4, buf, cr);
-        ntot    = static_cast<int>(buf[1] + 0.5);
+        ntot    = gmx::roundToInt(buf[1]);
         *sf_dir = buf[2];
         *Epot   = buf[3];
     }
index 4a118743c5397544e47bb2e503247ef5c53553ad..c24ef03006bda8e72df225893e975967f31d84a1 100644 (file)
@@ -371,7 +371,7 @@ void global_stat(gmx_global_stat_t gs,
     if (checkNumberOfBondedInteractions)
     {
         extract_bind(rb, inb, 1, &nb);
-        *totalNumberOfBondedInteractions = static_cast<int>(nb+0.5);
+        *totalNumberOfBondedInteractions = gmx::roundToInt(nb);
     }
 
     if (nsig > 0)
index 67af223fc93cd4444accf5bd795b1622baa5d378..5578853df90bc7dd6c932627ae5ad52463e01e3c 100644 (file)
@@ -1956,7 +1956,7 @@ extern gmx_bool update_randomize_velocities(t_inputrec *ir, int64_t step, const
 
     /* proceed with andersen if 1) it's fixed probability per
        particle andersen or 2) it's massive andersen and it's tau_t/dt */
-    if ((ir->etc == etcANDERSEN) || do_per_step(step, static_cast<int>(1.0/rate + 0.5)))
+    if ((ir->etc == etcANDERSEN) || do_per_step(step, roundToInt(1.0/rate)))
     {
         andersen_tcoupl(ir, step, cr, md, state, rate,
                         upd->sd->randomize_group, upd->sd->boltzfac);
index 8019ffa10bc3f0676e04ec750ee5d2dcc87e1315..d1276689c24059ac7ea6c062721af87b7a9a078f 100644 (file)
@@ -313,7 +313,7 @@ static void get_f_norm_max(const t_commrec *cr,
             if (sum[2*i] > fmax2)
             {
                 fmax2 = sum[2*i];
-                a_max = static_cast<int>(sum[2*i+1] + 0.5);
+                a_max = gmx::roundToInt(sum[2*i+1]);
             }
         }
         sfree(sum);
index 66d8f30ba655378bcddccb3e61da2d96816a5ec3..8e6fd483ee6719b31b387298762c53dbe9c58ecb 100644 (file)
@@ -734,9 +734,8 @@ Integrator::do_tpi()
             }
             else
             {
-                i = static_cast<int>((bU_logV_bin_limit
-                                      - (beta*epot - logV + refvolshift))*invbinw
-                                     + 0.5);
+                i = gmx::roundToInt((bU_logV_bin_limit
+                                     - (beta*epot - logV + refvolshift))*invbinw);
                 if (i < 0)
                 {
                     i = 0;
@@ -848,7 +847,7 @@ Integrator::do_tpi()
             bUlogV = -i/invbinw + bU_logV_bin_limit - refvolshift + log(V_all/frame);
             fprintf(fp_tpi, "%6.2f %10d %12.5e\n",
                     bUlogV,
-                    static_cast<int>(bin[i]+0.5),
+                    roundToInt(bin[i]),
                     bin[i]*exp(-bUlogV)*V_all/VembU_all);
         }
         xvgrclose(fp_tpi);
index 315433b9abc005a3e086beadd648bce68cb9111a..76badaeda53aed597e6b1f703bfdee899870d759 100644 (file)
@@ -1703,7 +1703,6 @@ static inline void shift_single_coord(const matrix box, rvec x, const ivec is)
 
 /* Determine the 'home' slab of this atom which is the
  * slab with the highest Gaussian weight of all */
-#define round(a) int((a)+0.5)
 static inline int get_homeslab(
         rvec       curr_x,   /* The position for which the home slab shall be determined */
         const rvec rotvec,   /* The rotation vector */
@@ -1716,7 +1715,7 @@ static inline int get_homeslab(
      * slab with index 0) is */
     dist = iprod(rotvec, curr_x);
 
-    return round(dist / slabdist);
+    return gmx::roundToInt(dist / slabdist);
 }
 
 
index 709759543018f649822bd369d4b696da29d0fbc1..ee4cecb124a2894a54f597dbf9eb981b4d9bf571 100644 (file)
@@ -48,7 +48,7 @@
 
 static int gmx_dnint(double x)
 {
-    return static_cast<int>(x+0.5);
+    return gmx::roundToInt(x);
 }
 
 typedef struct gmx_stats {
index 1b0ecc2dfd2125b3c4f9233ac10f2d5148d9b445..f3e462e8b68b702dfc8f3d05cacfefbc461874b4 100644 (file)
@@ -708,7 +708,9 @@ static void read_tables(FILE *fp, const char *fn,
             if (ns > 0)
             {
                 ssd /= ns;
-                sprintf(buf, "For the %d non-zero entries for table %d in %s the forces deviate on average %lld%% from minus the numerical derivative of the potential\n", ns, k, libfn, static_cast<long long int>(100*ssd+0.5));
+                sprintf(buf, "For the %d non-zero entries for table %d in %s the forces deviate on average %" PRId64
+                        "%% from minus the numerical derivative of the potential\n",
+                        ns, k, libfn, gmx::roundToInt64(100*ssd));
                 if (debug)
                 {
                     fprintf(debug, "%s", buf);
@@ -1369,7 +1371,7 @@ t_forcetable *make_tables(FILE *out,
                 gmx_fatal(FARGS, "Tables in file %s not long enough for cut-off:\n"
                           "\tshould be at least %f nm\n", fn, rtab);
             }
-            table->n = static_cast<int>(rtab*td[0].tabscale + 0.5);
+            table->n = gmx::roundToInt(rtab*td[0].tabscale);
         }
         table->scale = td[0].tabscale;
         nx0          = td[0].nx0;
index a7eeb6584629454e085d76c55c8ebd254ab81db9..e521c47010a6e27a5a0d15eb4a35e7a18f994596 100644 (file)
@@ -45,6 +45,7 @@
 #include <array>
 #include <vector>
 
+#include "gromacs/math/functions.h"
 #include "gromacs/mdtypes/commrec.h"
 #include "gromacs/timing/cyclecounter.h"
 #include "gromacs/timing/gpu_timing.h"
@@ -575,14 +576,14 @@ WallcycleCounts wallcycle_sum(const t_commrec *cr, gmx_wallcycle_t wc)
                       cr->mpi_comm_mysim);
         for (i = 0; i < ewcNR; i++)
         {
-            wcc[i].n = static_cast<int>(buf[i] + 0.5);
+            wcc[i].n = gmx::roundToInt(buf[i]);
         }
         wc->haveInvalidCount = (buf[nsum] > 0);
         if (wc->wcsc)
         {
             for (i = 0; i < ewcsNR; i++)
             {
-                wc->wcsc[i].n = static_cast<int>(buf[ewcNR+i] + 0.5);
+                wc->wcsc[i].n = gmx::roundToInt(buf[ewcNR+i]);
             }
         }
 
@@ -1054,7 +1055,7 @@ void wallcycle_print(FILE *fplog, const gmx::MDLogger &mdlog, int nnodes, int np
             GMX_LOG(mdlog.warning).asParagraph().appendTextFormatted(
                     "NOTE: %d %% of the run time was spent in pair search,\n"
                     "      you might want to increase nstlist (this has no effect on accuracy)\n",
-                    static_cast<int>(100*cyc_sum[ewcNS]/tot+0.5));
+                    gmx::roundToInt(100*cyc_sum[ewcNS]/tot));
         }
         else
         {
@@ -1062,8 +1063,8 @@ void wallcycle_print(FILE *fplog, const gmx::MDLogger &mdlog, int nnodes, int np
                     "NOTE: %d %% of the run time was spent in domain decomposition,\n"
                     "      %d %% of the run time was spent in pair search,\n"
                     "      you might want to increase nstlist (this has no effect on accuracy)\n",
-                    static_cast<int>(100*cyc_sum[ewcDOMDEC]/tot+0.5),
-                    static_cast<int>(100*cyc_sum[ewcNS]/tot+0.5));
+                    gmx::roundToInt(100*cyc_sum[ewcDOMDEC]/tot),
+                    gmx::roundToInt(100*cyc_sum[ewcNS]/tot));
         }
     }
 
@@ -1072,7 +1073,7 @@ void wallcycle_print(FILE *fplog, const gmx::MDLogger &mdlog, int nnodes, int np
         GMX_LOG(mdlog.warning).asParagraph().appendTextFormatted(
                 "NOTE: %d %% of the run time was spent communicating energies,\n"
                 "      you might want to use the -gcom option of mdrun\n",
-                static_cast<int>(100*cyc_sum[ewcMoveE]/tot+0.5));
+                gmx::roundToInt(100*cyc_sum[ewcMoveE]/tot));
     }
 }
 
index d4fca39d7412845c44fd8cf7bfb44d139026e790..343fa5525b0ac89db629031cb2eeae90a1bb434c 100644 (file)
@@ -404,7 +404,7 @@ int gmx_convert_tpr(int argc, char *argv[])
         /* Determine total number of steps remaining */
         if (bExtend)
         {
-            ir->nsteps = ir->nsteps - (run_step - ir->init_step) + static_cast<int64_t>(extend_t/ir->delta_t + 0.5);
+            ir->nsteps = ir->nsteps - (run_step - ir->init_step) + gmx::roundToInt64(extend_t/ir->delta_t);
             printf("Extending remaining runtime of by %g ps (now %s steps)\n",
                    extend_t, gmx_step_str(ir->nsteps, buf));
         }
@@ -414,7 +414,7 @@ int gmx_convert_tpr(int argc, char *argv[])
                    gmx_step_str(ir->nsteps, buf),
                    gmx_step_str(run_step, buf2),
                    run_t, until_t);
-            ir->nsteps = static_cast<int64_t>((until_t - run_t)/ir->delta_t + 0.5);
+            ir->nsteps = gmx::roundToInt64((until_t - run_t)/ir->delta_t);
             printf("Extending remaining runtime until %g ps (now %s steps)\n",
                    until_t, gmx_step_str(ir->nsteps, buf));
         }
index ae214d59a57995393b4040c9439f9ea2069e2e05..651b97a4c2614638b6f8686679c2da2001e3cafa 100644 (file)
@@ -499,9 +499,9 @@ int Mdrunner::mainFunction(int argc, char *argv[])
 
     domdecOptions.rankOrder    = static_cast<DdRankOrder>(nenum(ddrank_opt_choices));
     domdecOptions.dlbOption    = static_cast<DlbOption>(nenum(dddlb_opt_choices));
-    domdecOptions.numCells[XX] = static_cast<int>(realddxyz[XX] + 0.5);
-    domdecOptions.numCells[YY] = static_cast<int>(realddxyz[YY] + 0.5);
-    domdecOptions.numCells[ZZ] = static_cast<int>(realddxyz[ZZ] + 0.5);
+    domdecOptions.numCells[XX] = roundToInt(realddxyz[XX]);
+    domdecOptions.numCells[YY] = roundToInt(realddxyz[YY]);
+    domdecOptions.numCells[ZZ] = roundToInt(realddxyz[ZZ]);
 
     nbpu_opt    = nbpu_opt_choices[0];
     pme_opt     = pme_opt_choices[0];