Unsafe comparison operators in Calo
Some operator== in the Calo code are unsafe, due to internal floating point comparisons. They actually lead to compilation warning when enabling -Wfloat.
Here is the list of such issues :
Some operator== in the Calo code are unsafe, due to internal floating point comparisons. They actually lead to compilation warning when enabling -Wfloat.
Here is the list of such issues :
assigned to @jmarchan
Thanks for pointing this out @sponce do you think that the following is ok ?
std::fabs(lhs.m_energy - rhs.m_energy)<std::numeric_limits::epsilon()
or are there some better options to compare floats ?
You know better what the code does and thus what the best fix is. But yes, what you propose sounds very reasonnable
Note that I've added a second case to the same issue. I believe the same kind of fix will just be fine
Actually, after more careful considerations, things are not that simple. One needs a method like
constexpr bool essentiallyEqual( double const a, double const b ) {
return std::abs(a - b) <= std::min( std::abs( a ), std::abs( b ) ) * std::numeric_limits<double>::epsilon();
}
In other terms the epsilon has to be scaled to the order of magnitude of the values compared.
changed title from Unsafe comparison operate in CaloDigit_v2 to Unsafe comparison operators in Calo
changed the description
mentioned in merge request !4268 (closed)
mentioned in merge request !4291 (merged)
closed with merge request !4291 (merged)
mentioned in commit 038e9cf1