Skip to content

Commit

Permalink
Fix warning: comparing floating point with == or != is unsafe
Browse files Browse the repository at this point in the history
Warning detected on Fedora 25 ci
  • Loading branch information
fspindle committed Jan 3, 2025
1 parent 03c0fb1 commit 73f6846
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
5 changes: 3 additions & 2 deletions modules/core/test/image-with-dataset/testImageFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <visp3/core/vpImageConvert.h>
#include <visp3/core/vpImageFilter.h>
#include <visp3/core/vpIoTools.h>
#include <visp3/core/vpMath.h>
#include <visp3/core/vpRGBa.h>
#include <visp3/io/vpImageIo.h>
#include <visp3/io/vpParseArgv.h>
Expand Down Expand Up @@ -538,7 +539,7 @@ int main(int argc, const char *argv[])
}
double median = vpImageFilter::median(I_median);
double expectedMedian = 4.;
test = (median == expectedMedian);
test = vpMath::equal(median, expectedMedian);
std::cout << "(median (=" << median << ") == expectedMedian(" << expectedMedian << "))? " << test << std::endl;

if (!test) {
Expand All @@ -558,7 +559,7 @@ int main(int argc, const char *argv[])
std::vector<float> median_rgba = vpImageFilter::median(I_median_rgba);
std::vector<float> expected_median_rgba = { 4.f, 8.f, 12.f };
for (unsigned int i = 0; i < 3; i++) {
bool test_local = (median_rgba[i] == expected_median_rgba[i]);
bool test_local = vpMath::equal(median_rgba[i], expected_median_rgba[i]);
test &= test_local;
std::cout << "(median_rgba[" << i << "] (=" << median_rgba[i] << ") == expected_median_rgba[" << i << "] ( " << expected_median_rgba[i] << "))? " << test_local << std::endl;
}
Expand Down
3 changes: 2 additions & 1 deletion modules/core/test/math/catchParticleFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

#include <visp3/core/vpColVector.h>
#include <visp3/core/vpImagePoint.h>
#include <visp3/core/vpMath.h>
#include <visp3/core/vpParticleFilter.h>
#include <visp3/core/vpUniRand.h>

Expand Down Expand Up @@ -386,7 +387,7 @@ class vpAverageFunctor
initPoints.push_back(pt);
}
}
else if (nbPoints == 1.) {
else if (vpMath::equal(nbPoints, 1.)) {
vpParabolaModel curve(particles[i], m_height, m_width);
double u = static_cast<double>(m_width) / 2.;
double v = curve.eval(u);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
// ViSP includes
#include <visp3/core/vpConfig.h>
#include <visp3/core/vpException.h>
#include <visp3/core/vpMath.h>
#include <visp3/core/vpMouseButton.h>
#include <visp3/core/vpTime.h>

Expand Down Expand Up @@ -395,7 +396,7 @@ class vpTutoAverageFunctor
initPoints.push_back(pt);
}
}
else if (nbPoints == 1.) {
else if (vpMath::equal(nbPoints, 1.)) {
// The weight of the particle make it have only one control point
// We sample it at the middle of the image
vpTutoParabolaModel curve(particles[i], m_height, m_width);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include <visp3/core/vpConfig.h>
#include <visp3/core/vpException.h>
#include <visp3/core/vpMath.h>
#include <visp3/core/vpMouseButton.h>
#include <visp3/core/vpTime.h>
#include <visp3/core/vpUniRand.h>
Expand Down Expand Up @@ -391,7 +392,7 @@ class vpTutoAverageFunctor
initPoints.push_back(pt);
}
}
else if (nbPoints == 1.) {
else if (vpMath::equal(nbPoints, 1.)) {
// The weight of the particle make it have only one control point
// We sample it at the middle of the image
vpTutoParabolaModel curve(particles[i], m_height, m_width);
Expand Down
3 changes: 2 additions & 1 deletion tutorial/particle-filter-curve-fitting/vpTutoCommonData.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <visp3/core/vpImage.h>
#include <visp3/core/vpImageFilter.h>
#include <visp3/core/vpIoTools.h>
#include <visp3/core/vpMath.h>
#include <visp3/gui/vpDisplayFactory.h>
#include <visp3/io/vpVideoReader.h>

Expand Down Expand Up @@ -266,7 +267,7 @@ typedef struct vpTutoCommonData
#if defined(VISP_HAVE_DISPLAY)
const int horOffset = 20, vertOffset = 25;
std::string skeletonTitle("Skeletonized image (");
skeletonTitle += (m_ratioSaltPepperNoise == 0 ? "without" : std::to_string(static_cast<unsigned int>(m_ratioSaltPepperNoise * 100.)) + "%");
skeletonTitle += (vpMath::equal(m_ratioSaltPepperNoise, 0.) ? "without" : std::to_string(static_cast<unsigned int>(m_ratioSaltPepperNoise * 100.)) + "%");
skeletonTitle += " noise)";
m_displayOrig = VISP_NAMESPACE_ADDRESSING vpDisplayFactory::createDisplay(m_I_orig, horOffset, vertOffset, "Original image");
m_displaySegmented = VISP_NAMESPACE_ADDRESSING vpDisplayFactory::createDisplay(m_I_segmented, 2 * horOffset + m_I_orig.getWidth(), vertOffset, "Segmented image");
Expand Down

0 comments on commit 73f6846

Please sign in to comment.