From 4418dfeed78883a9bf6711a5af89f019405af7ae Mon Sep 17 00:00:00 2001 From: Thomas Steinreiter Date: Wed, 16 Nov 2016 17:19:54 +0100 Subject: [PATCH] use std::numeric_limits --- bhtree_mpi/src/datastructures/BarnesHutTree.cpp | 7 +++---- bhtree_mpi/src/datastructures/Body.cpp | 6 ++---- bhtree_mpi/src/datastructures/Box.cpp | 10 +++++----- bhtree_mpi/src/datastructures/Node.cpp | 4 ++-- bhtree_mpi/src/simulation/MpiSimulation.cpp | 1 - 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/bhtree_mpi/src/datastructures/BarnesHutTree.cpp b/bhtree_mpi/src/datastructures/BarnesHutTree.cpp index fadf55d..3d1fe61 100644 --- a/bhtree_mpi/src/datastructures/BarnesHutTree.cpp +++ b/bhtree_mpi/src/datastructures/BarnesHutTree.cpp @@ -2,8 +2,7 @@ #include "Node.hpp" #include "Box.hpp" #include -#include -#include +#include namespace nbody { BarnesHutTree::BarnesHutTree(int parallelId) : Tree(parallelId) { @@ -26,7 +25,7 @@ namespace nbody { //iterate for updating representatives Node* current = this->nodes->prev; while (current != this->nodes) { - current->representative.id = ULONG_MAX; + current->representative.id = std::numeric_limits::max(); current->representative.mass = 0.0; current->representative.position[0] = 0.0; current->representative.position[1] = 0.0; @@ -50,7 +49,7 @@ namespace nbody { } while (child != nullptr); } for (int j = 0; j < 3; j++) { - if (current->representative.mass > FLT_EPSILON) { + if (current->representative.mass > std::numeric_limits::epsilon()) { current->representative.position[j] /= current->representative.mass; } else { current->representative.position[j] = 0.0; diff --git a/bhtree_mpi/src/datastructures/Body.cpp b/bhtree_mpi/src/datastructures/Body.cpp index aedde8a..9aa9ede 100644 --- a/bhtree_mpi/src/datastructures/Body.cpp +++ b/bhtree_mpi/src/datastructures/Body.cpp @@ -4,8 +4,6 @@ #include #include #include -#include -#include #include #include #include @@ -58,8 +56,8 @@ namespace nbody { distance2 += (from.position[0] - to.position[0]) * (from.position[0] - to.position[0]); distance2 += (from.position[1] - to.position[1]) * (from.position[1] - to.position[1]); distance2 += (from.position[2] - to.position[2]) * (from.position[2] - to.position[2]); - if (fabs(distance2) < FLT_EPSILON) { - distance2 = FLT_EPSILON; + if (fabs(distance2) < std::numeric_limits::epsilon()) { //TODO(steinret) max? + distance2 = std::numeric_limits::epsilon(); } double distance = sqrt(distance2); double mdist = -1.0 * ((from.mass * to.mass) / distance2); diff --git a/bhtree_mpi/src/datastructures/Box.cpp b/bhtree_mpi/src/datastructures/Box.cpp index 9a210a4..474a3a0 100644 --- a/bhtree_mpi/src/datastructures/Box.cpp +++ b/bhtree_mpi/src/datastructures/Box.cpp @@ -1,13 +1,13 @@ #include #include -#include +#include #include #include "Box.hpp" namespace nbody { void initBox(Box& box) { - std::fill(std::begin(box.min), std::end(box.min), FLT_MAX); //TODO(steinret) numeric limits - std::fill(std::begin(box.max), std::end(box.max), FLT_MIN); + std::fill(std::begin(box.min), std::end(box.min), std::numeric_limits::max()); + std::fill(std::begin(box.max), std::end(box.max), std::numeric_limits::min()); } //extend box to form cube @@ -179,7 +179,7 @@ namespace nbody { double nextPosition[3] = {position[0], position[1], position[2]}; if (!isValid(box)) { - return DBL_MAX; + return std::numeric_limits::max(); } for (int i = 0; i < 3; i++) { if (nextPosition[i] < box.min[i]) { @@ -207,7 +207,7 @@ namespace nbody { double length = 0.0; if (!isValid(box1) || !isValid(box2)) { - return DBL_MAX; + return std::numeric_limits::max(); } for (int i = 0; i < 3; i++) { double elem; diff --git a/bhtree_mpi/src/datastructures/Node.cpp b/bhtree_mpi/src/datastructures/Node.cpp index f46e24e..ccde996 100644 --- a/bhtree_mpi/src/datastructures/Node.cpp +++ b/bhtree_mpi/src/datastructures/Node.cpp @@ -1,5 +1,5 @@ -#include #include +#include #include #include #include "Node.hpp" @@ -37,7 +37,7 @@ namespace nbody { result = false; } //this is to prevent errors with collocated particles - if (volume(this->bb) <= FLT_EPSILON) { + if (volume(this->bb) <= std::numeric_limits::epsilon()) { result = false; } return result; diff --git a/bhtree_mpi/src/simulation/MpiSimulation.cpp b/bhtree_mpi/src/simulation/MpiSimulation.cpp index 2a63005..9011268 100644 --- a/bhtree_mpi/src/simulation/MpiSimulation.cpp +++ b/bhtree_mpi/src/simulation/MpiSimulation.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include #include -- GitLab