replace static_cast<int>(val + 0.5) with C++11's std::lround()
This commit is contained in:
@ -30,6 +30,8 @@
|
||||
#include "potential_file_reader.h"
|
||||
#include "update.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@ -686,10 +688,9 @@ void PairEAMAPIP::file2array()
|
||||
}
|
||||
|
||||
// set nr,nrho from cutoff and spacings
|
||||
// 0.5 is for round-off in divide
|
||||
|
||||
nr = static_cast<int>(rmax / dr + 0.5);
|
||||
nrho = static_cast<int>(rhomax / drho + 0.5);
|
||||
nr = std::lround(rmax / dr);
|
||||
nrho = std::lround(rhomax / drho);
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// setup frho arrays
|
||||
|
||||
@ -250,7 +250,7 @@ void FixPour::init()
|
||||
delta = yhi - ylo;
|
||||
}
|
||||
double t = (-v_relative - sqrt(v_relative * v_relative - 2.0 * grav * delta)) / grav;
|
||||
nfreq = static_cast<int>(t / update->dt + 0.5);
|
||||
nfreq = std::lround(t / update->dt);
|
||||
|
||||
// 1st insertion on next timestep
|
||||
|
||||
|
||||
@ -636,10 +636,9 @@ void PairEAM::file2array()
|
||||
}
|
||||
|
||||
// set nr,nrho from cutoff and spacings
|
||||
// 0.5 is for round-off in divide
|
||||
|
||||
nr = static_cast<int> (rmax/dr + 0.5);
|
||||
nrho = static_cast<int> (rhomax/drho + 0.5);
|
||||
nr = std::lround(rmax/dr);
|
||||
nrho = std::lround(rhomax/drho);
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// setup frho arrays
|
||||
|
||||
@ -1087,11 +1087,11 @@ int FixChargeRegulation::get_random_particle(int ptype, double charge, double rd
|
||||
double dx, dy, dz, distance_check;
|
||||
for (int i = 0; i < nlocal; i++) {
|
||||
dx = fabs(atom->x[i][0] - target[0]);
|
||||
dx -= static_cast<int>(1.0 * dx / (xhi - xlo) + 0.5) * (xhi - xlo);
|
||||
dx -= std::lround(1.0 * dx / (xhi - xlo)) * (xhi - xlo);
|
||||
dy = fabs(atom->x[i][1] - target[1]);
|
||||
dy -= static_cast<int>(1.0 * dy / (yhi - ylo) + 0.5) * (yhi - ylo);
|
||||
dy -= std::lround(1.0 * dy / (yhi - ylo)) * (yhi - ylo);
|
||||
dz = fabs(atom->x[i][2] - target[2]);
|
||||
dz -= static_cast<int>(1.0 * dz / (zhi - zlo) + 0.5) * (zhi - zlo);
|
||||
dz -= std::lround(1.0 * dz / (zhi - zlo)) * (zhi - zlo);
|
||||
distance_check = dx * dx + dy * dy + dz * dz;
|
||||
if ((distance_check < rd * rd) && atom->type[i] == ptype &&
|
||||
fabs(atom->q[i] - charge) < SMALL && atom->mask[i] != exclusion_group_bit) {
|
||||
@ -1193,11 +1193,11 @@ int FixChargeRegulation::particle_number_xrd(int ptype, double charge, double rd
|
||||
double dx, dy, dz, distance_check;
|
||||
for (int i = 0; i < atom->nlocal; i++) {
|
||||
dx = fabs(atom->x[i][0] - target[0]);
|
||||
dx -= static_cast<int>(1.0 * dx / (xhi - xlo) + 0.5) * (xhi - xlo);
|
||||
dx -= std::lround(1.0 * dx / (xhi - xlo)) * (xhi - xlo);
|
||||
dy = fabs(atom->x[i][1] - target[1]);
|
||||
dy -= static_cast<int>(1.0 * dy / (yhi - ylo) + 0.5) * (yhi - ylo);
|
||||
dy -= std::lround(1.0 * dy / (yhi - ylo)) * (yhi - ylo);
|
||||
dz = fabs(atom->x[i][2] - target[2]);
|
||||
dz -= static_cast<int>(1.0 * dz / (zhi - zlo) + 0.5) * (zhi - zlo);
|
||||
dz -= std::lround(1.0 * dz / (zhi - zlo)) * (zhi - zlo);
|
||||
distance_check = dx * dx + dy * dy + dz * dz;
|
||||
if ((distance_check < rd * rd) && atom->type[i] == ptype &&
|
||||
fabs(atom->q[i] - charge) < SMALL && atom->mask[i] != exclusion_group_bit) {
|
||||
|
||||
@ -1268,7 +1268,7 @@ int ComputeChunkAtom::setup_xyz_bins()
|
||||
if (lo > hi) error->all(FLERR, Error::NOLASTLINE, "Invalid bin bounds in compute chunk/atom");
|
||||
|
||||
offset[m] = lo;
|
||||
nlayers[m] = static_cast<int>((hi - lo) * invdelta[m] + 0.5);
|
||||
nlayers[m] = std::lround((hi - lo) * invdelta[m]);
|
||||
nbins *= nlayers[m];
|
||||
}
|
||||
|
||||
|
||||
@ -469,7 +469,7 @@ void Image::draw_sphere(double *x, double *surfaceColor, double diameter)
|
||||
double pixelWidth = (tanPerPixel > 0) ? tanPerPixel * dist :
|
||||
-tanPerPixel / zoom;
|
||||
double pixelRadiusFull = radius / pixelWidth;
|
||||
int pixelRadius = static_cast<int> (pixelRadiusFull + 0.5) + 1;
|
||||
int pixelRadius = std::lround(pixelRadiusFull) + 1;
|
||||
|
||||
double xf = xmap / pixelWidth;
|
||||
double yf = ymap / pixelWidth;
|
||||
@ -531,7 +531,7 @@ void Image::draw_cube(double *x, double *surfaceColor, double diameter)
|
||||
|
||||
double halfWidth = diameter;
|
||||
double pixelHalfWidthFull = halfWidth / pixelWidth;
|
||||
int pixelHalfWidth = static_cast<int> (pixelHalfWidthFull + 0.5);
|
||||
int pixelHalfWidth = std::lround(pixelHalfWidthFull);
|
||||
|
||||
double xf = xmap / pixelWidth;
|
||||
double yf = ymap / pixelWidth;
|
||||
@ -670,8 +670,8 @@ void Image::draw_cylinder(double *x, double *y,
|
||||
|
||||
double pixelHalfWidthFull = (rasterWidth * 0.5) / pixelWidth;
|
||||
double pixelHalfHeightFull = (rasterHeight * 0.5) / pixelWidth;
|
||||
int pixelHalfWidth = static_cast<int> (pixelHalfWidthFull + 0.5);
|
||||
int pixelHalfHeight = static_cast<int> (pixelHalfHeightFull + 0.5);
|
||||
int pixelHalfWidth = std::lround(pixelHalfWidthFull);
|
||||
int pixelHalfHeight = std::lround(pixelHalfHeightFull);
|
||||
|
||||
if (zaxis[0] == camDir[0] && zaxis[1] == camDir[1] && zaxis[2] == camDir[2])
|
||||
return;
|
||||
@ -818,10 +818,10 @@ void Image::draw_triangle(double *x, double *y, double *z, double *surfaceColor)
|
||||
double pixelRightFull = rasterRight / pixelWidth;
|
||||
double pixelDownFull = rasterDown / pixelWidth;
|
||||
double pixelUpFull = rasterUp / pixelWidth;
|
||||
int pixelLeft = static_cast<int> (pixelLeftFull + 0.5);
|
||||
int pixelRight = static_cast<int> (pixelRightFull + 0.5);
|
||||
int pixelDown = static_cast<int> (pixelDownFull + 0.5);
|
||||
int pixelUp = static_cast<int> (pixelUpFull + 0.5);
|
||||
int pixelLeft = std::lround(pixelLeftFull);
|
||||
int pixelRight = std::lround(pixelRightFull);
|
||||
int pixelDown = std::lround(pixelDownFull);
|
||||
int pixelUp = std::lround(pixelUpFull);
|
||||
|
||||
for (int iy = yc - pixelDown; iy <= yc + pixelUp; iy ++) {
|
||||
for (int ix = xc - pixelLeft; ix <= xc + pixelRight; ix ++) {
|
||||
|
||||
Reference in New Issue
Block a user