[Liblas-commits] hg-main-tree: Use epsilon compares instead of ==
for doubles
liblas-commits at liblas.org
liblas-commits at liblas.org
Wed Mar 16 09:58:03 EDT 2011
details: http://hg.libpc.orghg-main-tree/rev/91a079935d63
changeset: 261:91a079935d63
user: Howard Butler <hobu.inc at gmail.com>
date: Wed Mar 16 08:57:57 2011 -0500
description:
Use epsilon compares instead of == for doubles
diffstat:
src/Dimension.cpp | 12 ++++++++----
test/unit/ChipperTest.cpp | 10 ++++++----
test/unit/UtilsTest.cpp | 2 +-
3 files changed, 15 insertions(+), 9 deletions(-)
diffs (69 lines):
diff -r 38ad6c913ea5 -r 91a079935d63 src/Dimension.cpp
--- a/src/Dimension.cpp Wed Mar 16 08:47:42 2011 -0500
+++ b/src/Dimension.cpp Wed Mar 16 08:57:57 2011 -0500
@@ -44,6 +44,7 @@
#include <libpc/Utils.hpp>
#include <iostream>
+#include <limits>
using namespace boost;
@@ -108,11 +109,14 @@
m_field == other.m_field &&
m_byteSize == other.m_byteSize &&
m_description == other.m_description &&
- m_min == other.m_min &&
- m_max == other.m_max &&
+ Utils::compare_approx(m_min, other.m_min, (std::numeric_limits<double>::min)()) &&
+ Utils::compare_approx(m_max, other.m_max, (std::numeric_limits<double>::min)()) &&
m_precise == other.m_precise &&
- m_numericScale == other.m_numericScale &&
- m_numericOffset == other.m_numericOffset)
+
+ Utils::compare_approx(m_numericScale, other.m_numericScale, (std::numeric_limits<double>::min)()) &&
+ Utils::compare_approx(m_numericOffset, other.m_numericOffset, (std::numeric_limits<double>::min)())
+
+ )
{
return true;
}
diff -r 38ad6c913ea5 -r 91a079935d63 test/unit/ChipperTest.cpp
--- a/test/unit/ChipperTest.cpp Wed Mar 16 08:47:42 2011 -0500
+++ b/test/unit/ChipperTest.cpp Wed Mar 16 08:57:57 2011 -0500
@@ -41,6 +41,8 @@
#include "support.hpp"
+#include <limits>
+
using namespace libpc;
BOOST_AUTO_TEST_SUITE(ChipperTest)
@@ -72,10 +74,10 @@
libpc::Range<double> x = ranges[0];
libpc::Range<double> y = ranges[1];
- BOOST_CHECK(Utils::compare_approx(x.getMinimum(), (double)635674, (double) 1) == true);
- BOOST_CHECK(Utils::compare_approx(x.getMaximum(), (double)635994, (double) 1) == true);
- BOOST_CHECK(Utils::compare_approx(y.getMinimum(), (double)848992, (double) 1) == true);
- BOOST_CHECK(Utils::compare_approx(y.getMaximum(), (double)849427, (double) 1) == true);
+ BOOST_CHECK(Utils::compare_approx(x.getMinimum(), (double)635674, (std::numeric_limits<double>::min)()) == true);
+ BOOST_CHECK(Utils::compare_approx(x.getMaximum(), (double)635994, (std::numeric_limits<double>::min)()) == true);
+ BOOST_CHECK(Utils::compare_approx(y.getMinimum(), (double)848992, (std::numeric_limits<double>::min)()) == true);
+ BOOST_CHECK(Utils::compare_approx(y.getMaximum(), (double)849427, (std::numeric_limits<double>::min)()) == true);
std::vector<boost::uint32_t> ids = chipper.GetBlock(70).GetIDs();
diff -r 38ad6c913ea5 -r 91a079935d63 test/unit/UtilsTest.cpp
--- a/test/unit/UtilsTest.cpp Wed Mar 16 08:47:42 2011 -0500
+++ b/test/unit/UtilsTest.cpp Wed Mar 16 08:57:57 2011 -0500
@@ -138,7 +138,7 @@
double y = Utils::read_field<double>(p);
BOOST_CHECK(x==one);
- BOOST_CHECK(Utils::compare_approx(y, two, (double) 0.00001) == true);
+ BOOST_CHECK(Utils::compare_approx(y, two, std::numeric_limits<double>::min()) == true);
return;
}
More information about the Liblas-commits
mailing list