File indexing completed on 2024-04-06 12:04:42
0001 #ifndef DataFormats_Math_Rounding_h
0002 #define DataFormats_Math_Rounding_h
0003
0004
0005
0006 #include <cmath>
0007
0008 namespace cms_rounding {
0009
0010 template <class valType>
0011 inline constexpr valType roundIfNear0(valType value, double tolerance = 1.e-7) {
0012 if (std::abs(value) < tolerance)
0013 return (0.0);
0014 return (value);
0015 }
0016
0017 template <class valType>
0018 inline constexpr valType roundVecIfNear0(valType value, double tolerance = 1.e-7) {
0019 auto xVal{roundIfNear0(value.x(), tolerance)};
0020 auto yVal{roundIfNear0(value.y(), tolerance)};
0021 auto zVal{roundIfNear0(value.z(), tolerance)};
0022 return (valType{xVal, yVal, zVal});
0023 }
0024
0025 }
0026
0027 #endif