Replace rounding using int(x+0.5) with roundToInt
[alexxy/gromacs.git] / src / gromacs / awh / grid.cpp
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());