ATLAS Offline Software
Loading...
Searching...
No Matches
FLOATassert.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
6#ifndef TESTTOOLS_FLOATASSERT_H
7#define TESTTOOLS_FLOATASSERT_H
8
9#include <iostream>
10#include <cassert>
11#include <cfloat>
12#include <cmath>
13
14
15namespace Athena_test {
16 inline
17 bool floatEQ(float lhs, float rhs) {
18 return fabs(lhs-rhs)<=FLT_EPSILON;
19 }
20 inline
21 bool floatNEQ(float lhs, float rhs) {
22 return fabs(lhs-rhs)>FLT_EPSILON;
23 }
24
25 inline
26 bool isEqual (double x1, double x2, double thresh = 1e-6)
27 {
28 double den = std::abs(x1+x2);
29 if (den < thresh) return true;
30 double diff = std::abs (x1-x2) / den;
31 if (diff < thresh)
32 return true;
33 std::cout << "Match failure: " << x1 << " " << x2 << " (" << diff << ")\n";
34 return false;
35 }
36
37}
38
39#define FLOAT_NEQassert( LHS, RHS ) assert(Athena_test::floatNEQ(LHS, RHS));
40#define FLOAT_EQassert( LHS, RHS ) assert(Athena_test::floatEQ(LHS, RHS));
41
42#endif
void diff(const Jet &rJet1, const Jet &rJet2, std::map< std::string, double > varDiff)
Difference between jets - Non-Class function required by trigger.
Definition Jet.cxx:631
functions & macros to test the difference between floats
bool floatEQ(float lhs, float rhs)
Definition FLOATassert.h:17
bool floatNEQ(float lhs, float rhs)
Definition FLOATassert.h:21
bool isEqual(double x1, double x2, double thresh=1e-6)
Definition FLOATassert.h:26