yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis 2.0.2
Predicates.h
Go to the documentation of this file.
1// -*- C++ -*-
2//
3// This file is part of YODA -- Yet more Objects for Data Analysis
4// Copyright (C) 2008-2024 The YODA collaboration (see AUTHORS for details)
5//
6#ifndef YODA_PREDICATES_H
7#define YODA_PREDICATES_H
8
9#include <iostream>
10
11namespace YODA {
12
13
20 struct CmpFloats {
21 CmpFloats(double tol=1e-3, double refscale=0.0) : _tol(tol), _refscale(refscale) {}
22 bool operator () (const double& a, const double& b) {
23 const double div = (_refscale == 0) ? 0.5*(std::abs(a)+std::abs(b)) : _refscale;
24 const double dev = (b-a)/div;
25 // std::cout << "CmpFloats: " << a << " vs. " << b << " -> dev = " << dev << std::endl;
26 return std::abs(dev) < _tol;
27 }
28 double _tol, _refscale;
29 };
30
31
32}
33
34#endif
Anonymous namespace to limit visibility.
Functor to compare two floating point numbers and return whether they are fuzzily equivalent.
Definition Predicates.h:20
CmpFloats(double tol=1e-3, double refscale=0.0)
Definition Predicates.h:21
bool operator()(const double &a, const double &b)
Definition Predicates.h:22