Skip to content
Snippets Groups Projects
Commit 44589da6 authored by Stéphane Poirier's avatar Stéphane Poirier
Browse files

[PropertyHelper] Use epsilon for float numbers comparison

parent ee396520
No related branches found
No related tags found
No related merge requests found
......@@ -28,14 +28,12 @@
// DEPENDENCIES
// ============================================================================
#include <iostream>
#include <limits>
#include <yat/threading/Mutex.h>
namespace yat4tango
{
#define FLOAT_PRECISION float(1e-8)
#define DOUBLE_PRECISION double(1e-15)
//-------------------------------------------------------------------------
// Comparison functors specialization for floatting point numbers
//-------------------------------------------------------------------------
......@@ -44,7 +42,7 @@ struct PropertyHelper::ValueComp<float>
{
bool operator()(const float& v1, const float& v2)
{
return yat::fp_is_equal(v1, v2, FLOAT_PRECISION);
return yat::fp_is_equal(v1, v2, std::numeric_limits<float>::epsilon());
}
};
......@@ -53,7 +51,7 @@ struct PropertyHelper::ValueComp<double>
{
bool operator()(const double& v1, const double& v2)
{
return yat::fp_is_equal(v1, v2, DOUBLE_PRECISION);
return yat::fp_is_equal(v1, v2, std::numeric_limits<double>::epsilon());
}
};
......@@ -67,7 +65,7 @@ struct PropertyHelper::ValueComp< std::vector<float> >
for( std::size_t i = 0; i < v1.size(); ++i )
{
if( !yat::fp_is_equal(v1[i], v2[i], FLOAT_PRECISION) )
if( !yat::fp_is_equal(v1[i], v2[i], std::numeric_limits<float>::epsilon()) )
return false;
}
return true;
......@@ -84,7 +82,7 @@ struct PropertyHelper::ValueComp< std::vector<double> >
for( std::size_t i = 0; i < v1.size(); ++i )
{
if( !yat::fp_is_equal(v1[i], v2[i], DOUBLE_PRECISION) )
if( !yat::fp_is_equal(v1[i], v2[i], std::numeric_limits<double>::epsilon()) )
return false;
}
return true;
......@@ -115,11 +113,10 @@ bool PropertyHelper::value_cache(Tango::DeviceImpl* dev_p,
else
{
MapIterator it;
T last_val;
{
yat::AutoMutex<> lock(s_mtx);
it = (*values_cache_p).find(key);
}
T last_val;
if( (*values_cache_p).end() == it )
{
// Value not cached yet
......@@ -127,6 +124,7 @@ bool PropertyHelper::value_cache(Tango::DeviceImpl* dev_p,
}
else
last_val = it->second;
}
if( PropertyHelper::ValueComp<T>()(last_val, val) )
return false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment