ATLAS Offline Software
Control
CxxUtils
CxxUtils
close_to_zero.h
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
11
#ifndef CXXUTILS_CLOSE_TO_ZERO_H
12
#define CXXUTILS_CLOSE_TO_ZERO_H
13
14
#include <limits>
//for epsilon
15
#include <cmath>
//for abs
16
#include <type_traits>
//for std::is_integral_v etc
17
18
19
namespace
CxxUtils
{
47
template
<
typename
T>
48
bool
close_to_zero
(T
value
, T eps =
std::numeric_limits<T>::epsilon
()) {
49
if
constexpr (std::is_integral_v<T>) {
50
// For integers, only exact zero is invalid
51
return
value
== 0;
52
}
else
if
constexpr (std::is_floating_point_v<T>) {
53
return
std::abs(
value
) < eps;
54
}
else
{
55
static_assert(std::is_arithmetic_v<T>,
"close_to_zero: Only arithmetic types supported"
);
56
return
false
;
57
}
58
}
59
}
60
61
#endif
62
CaloClusterMLCalib::epsilon
constexpr float epsilon
Definition:
CaloClusterMLGaussianMixture.h:16
athena.value
value
Definition:
athena.py:124
CxxUtils
Definition:
aligned_vector.h:29
CxxUtils::close_to_zero
bool close_to_zero(T value, T eps=std::numeric_limits< T >::epsilon())
Definition:
close_to_zero.h:48
Generated on Fri Oct 24 2025 21:07:47 for ATLAS Offline Software by
1.8.18