![]() |
|
|||
File indexing completed on 2025-04-19 09:13:37
0001 // -*- C++ -*- 0002 // 0003 // This file is part of YODA -- Yet more Objects for Data Analysis 0004 // Copyright (C) 2008-2024 The YODA collaboration (see AUTHORS for details) 0005 // 0006 #ifndef YODA_PREDICATES_H 0007 #define YODA_PREDICATES_H 0008 0009 #include <iostream> 0010 0011 namespace YODA { 0012 0013 0014 /// @brief Functor to compare two floating point numbers and return whether they are fuzzily equivalent 0015 /// 0016 /// The equivalence comparison is of the form dev = |b-a|/refscale. The @a 0017 /// refscale argument may used to force the reference scale in this, otherwise 0018 /// (or if explicitly set to zero) it will default to (|a| + |b|)/2. The 0019 /// returned boolean is determined by the comparison |dev| < tol. 0020 struct CmpFloats { 0021 CmpFloats(double tol=1e-3, double refscale=0.0) : _tol(tol), _refscale(refscale) {} 0022 bool operator () (const double& a, const double& b) { 0023 const double div = (_refscale == 0) ? 0.5*(std::abs(a)+std::abs(b)) : _refscale; 0024 const double dev = (b-a)/div; 0025 // std::cout << "CmpFloats: " << a << " vs. " << b << " -> dev = " << dev << std::endl; 0026 return std::abs(dev) < _tol; 0027 } 0028 double _tol, _refscale; 0029 }; 0030 0031 0032 } 0033 0034 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |