Commit a965ca09 authored by snuverink_j's avatar snuverink_j

Use std::round(x) instead of std::floor(x+0.5)

parent 80ed400a
......@@ -15,6 +15,7 @@
#include <boost/filesystem.hpp>
#include <cmath>
#include <iostream>
#include <limits>
......@@ -72,7 +73,7 @@ OrbitThreader::OrbitThreader(const PartData &ref,
logger_m.open(fileName, std::ios_base::app);
}
loggingFrequency_m = std::max(1.0, floor(1e-11 / std::abs(dt_m) + 0.5));
loggingFrequency_m = std::max(1.0, std::round(1e-11 / std::abs(dt_m)));
} else {
loggingFrequency_m = std::numeric_limits<size_t>::max();
}
......@@ -455,4 +456,4 @@ double OrbitThreader::computeMaximalImplicitDrift() {
maxDrift = std::min(maxIntegSteps_m * std::abs(dt_m) * Physics::c, maxDrift);
return maxDrift;
}
\ No newline at end of file
}
......@@ -28,6 +28,8 @@
#include "gsl/gsl_interp.h"
#include "gsl/gsl_spline.h"
#include <cmath>
#include <iostream>
#include <fstream>
......@@ -616,7 +618,7 @@ double RFCavity::getAutoPhaseEstimateFallback(double E0, double t0, double q, do
dphi = dphi / 17.5;
}
phimax = phimax - floor(phimax / Physics::two_pi + 0.5) * Physics::two_pi;
phimax = phimax - std::round(phimax / Physics::two_pi) * Physics::two_pi;
phimax = fmod(phimax, Physics::two_pi);
const int prevPrecision = Ippl::Info->precision(8);
......@@ -711,7 +713,7 @@ double RFCavity::getAutoPhaseEstimate(const double &E0, const double &t0, const
return tmp_phi;
}
phi = tmp_phi - floor(tmp_phi / Physics::two_pi + 0.5) * Physics::two_pi;
phi = tmp_phi - std::round(tmp_phi / Physics::two_pi) * Physics::two_pi;
for(unsigned int i = 1; i < N; ++ i) {
E[i] = E[i - 1];
......
This diff is collapsed.
......@@ -3,6 +3,7 @@
#include "H5hut.h"
#include "Physics/Physics.h"
#include <cmath>
#include <fstream>
#include <ios>
......@@ -97,7 +98,7 @@ void FM3DH5Block_nonscale::readMap() {
long field_size = 0;
int Nnodes = Ippl::getNodes();//min(20, Ippl::getNodes());
int Nz_avrg = static_cast<int>(floor(0.5 + num_gridpz_m / Nnodes));
int Nz_avrg = static_cast<int>(std::round((double)num_gridpz_m / Nnodes));
int Nz_diff = Nz_avrg * Nnodes - num_gridpz_m;
int signNz = Nz_diff > 0 ? 1 : -1;
int *Nz_read_start = new int[Ippl::getNodes() + 1];
......
......@@ -127,8 +127,8 @@ void FM3DMagnetoStatic::readMap() {
if (normalize_m) {
double Bymax = 0.0;
// find maximum field
unsigned int centerX = static_cast<unsigned int>(std::floor(-xbegin_m / hx_m + 0.5));
unsigned int centerY = static_cast<unsigned int>(std::floor(-ybegin_m / hy_m + 0.5));
unsigned int centerX = static_cast<unsigned int>(std::round(-xbegin_m / hx_m));
unsigned int centerY = static_cast<unsigned int>(std::round(-ybegin_m / hy_m));
for(unsigned int k = 0; k < num_gridpz_m; ++ k) {
double By = FieldstrengthBy_m[getIndex(centerX, centerY, k)];
if(std::abs(By) > Bymax) {
......
......@@ -3,6 +3,7 @@
#include "Utilities/GeneralClassicException.h"
#include "Utilities/Util.h"
#include <cmath>
#include <fstream>
#include <ios>
#include <algorithm>
......@@ -121,7 +122,7 @@ void FM3DMagnetoStaticExtended::readMap() {
double Bymax = 0.0;
// find maximum field
unsigned int centerX = static_cast<unsigned int>(std::floor(-xbegin_m / hx_m + 0.5));
unsigned int centerX = static_cast<unsigned int>(std::round(-xbegin_m / hx_m));
for(unsigned int k = 0; k < num_gridpz_m; ++ k) {
double By = FieldstrengthBy_m[getIndex(centerX, 0, k)];
if(std::abs(By) > std::abs(Bymax)) {
......
......@@ -3,6 +3,7 @@
#include "H5hut.h"
#include "Physics/Physics.h"
#include <cmath>
#include <fstream>
#include <ios>
......@@ -100,7 +101,7 @@ void FM3DMagnetoStaticH5Block::readMap() {
long field_size = 0;
int Nnodes = Ippl::getNodes();//min(20, Ippl::getNodes());
int Nz_avrg = static_cast<int>(floor(0.5 + num_gridpz_m / Nnodes));
int Nz_avrg = static_cast<int>(std::round((double)num_gridpz_m / Nnodes));
int Nz_diff = Nz_avrg * Nnodes - num_gridpz_m;
int signNz = Nz_diff > 0 ? 1 : -1;
int *Nz_read_start = new int[Ippl::getNodes() + 1];
......
......@@ -32,6 +32,7 @@
#include <boost/filesystem.hpp>
#include <cmath>
#include <iostream>
#include <fstream>
#include <ios>
......@@ -447,7 +448,7 @@ void Fieldmap::checkMap(unsigned int accuracy,
gsl_spline *splineCoefficients,
gsl_interp_accel *splineAccelerator) {
double length = fieldDimensions.second - fieldDimensions.first;
unsigned int sizeSampling = std::floor(length / deltaZ + 0.5);
unsigned int sizeSampling = std::round(length / deltaZ);
std::vector<double> zSampling(sizeSampling);
zSampling[0] = fieldDimensions.first;
for (unsigned int i = 1; i < sizeSampling; ++ i) {
......
......@@ -10,6 +10,7 @@
#include "OPALconfig.h"
#include <cassert>
#include <cmath>
#define ADD_ATTACHMENT( fname ) { \
h5_int64_t h5err = H5AddAttachment (H5file_m, fname); \
......@@ -644,7 +645,7 @@ SetStatistics LossDataSink::computeSetStatistics(unsigned int setIdx) {
stat.refTime_m = refTime_m[setIdx];
stat.RefPartR_m = RefPartR_m[setIdx];
stat.RefPartP_m = RefPartP_m[setIdx];
stat.nTotal_m = (unsigned long)floor(plainData[0] + 0.5);
stat.nTotal_m = (unsigned long)std::round(plainData[0]);
for(unsigned int i = 0 ; i < 3u; i++) {
stat.rmean_m(i) = centroid[2 * i] / stat.nTotal_m;
......
......@@ -2051,7 +2051,7 @@ void Distribution::generateAstraFlattopT(size_t numberOfParticles) {
}
loc_fraction -= distributionTable[numberOfSampleBins * (k + 1)]
* (5. - weight) / tot;
numParticlesInBin[k] = static_cast<int>(std::floor(loc_fraction * numberOfParticles + 0.5));
numParticlesInBin[k] = static_cast<int>(std::round(loc_fraction * numberOfParticles));
effectiveNumParticles += numParticlesInBin[k];
if (numParticlesInBin[k] > numParticlesInBin[largestBin]) largestBin = k;
}
......@@ -4467,4 +4467,4 @@ void Distribution::adjustPhaseSpace(double massIneV) {
// c-basic-offset: 4
// indent-tabs-mode: nil
// require-final-newline: nil
// End:
\ No newline at end of file
// End:
......@@ -249,7 +249,7 @@ void LaserProfile::normalizeProfileData(double intensityCut, unsigned short *ima
double val = (double(image[pixel]) / profileMax - intensityCut) / (1.0 - intensityCut);
val = std::max(0.0, val);
image[pixel] = std::floor(val * profileMax + 0.5);
image[pixel] = std::round(val * profileMax);
}
}
}
......@@ -382,4 +382,4 @@ unsigned short LaserProfile::getProfileMax(unsigned short *image) {
}
return maxIntensity;
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment