From ffcf33bd49ab7e9fc33309475f4f582a9a976d78 Mon Sep 17 00:00:00 2001
From: Sebastien Ponce <sebastien.ponce@cern.ch>
Date: Tue, 5 Sep 2023 16:51:19 +0200
Subject: [PATCH] Fixed float comparisons in CPUCrunchSvc.cpp

---
 GaudiSvc/src/CPUCrunchSvc/CPUCrunchSvc.cpp | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/GaudiSvc/src/CPUCrunchSvc/CPUCrunchSvc.cpp b/GaudiSvc/src/CPUCrunchSvc/CPUCrunchSvc.cpp
index 2f18932190..6012aa7a70 100644
--- a/GaudiSvc/src/CPUCrunchSvc/CPUCrunchSvc.cpp
+++ b/GaudiSvc/src/CPUCrunchSvc/CPUCrunchSvc.cpp
@@ -23,6 +23,13 @@ DECLARE_COMPONENT( CPUCrunchSvc )
 #define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) )
 #define VERBOSE_MSG ON_VERBOSE verbose()
 
+namespace {
+  // idea coming from The art of computer programming by Knuth
+  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();
+  }
+} // namespace
+
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 
 CPUCrunchSvc::CPUCrunchSvc( const std::string& name, ISvcLocator* svc ) : base_class( name, svc ) {}
@@ -101,7 +108,7 @@ void CPUCrunchSvc::calibrate() {
       }
     }
   }
-  if ( m_corrFact != 1. ) {
+  if ( essentiallyEqual( m_corrFact, 1. ) ) {
     debug() << "Adjusting times with correction factor " << m_corrFact.value() << endmsg;
     for ( auto& t : m_times_vect ) { t = t * m_corrFact; }
   }
-- 
GitLab