Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:03

0001 #ifndef DataFormats_Math_Rounding_h
0002 #define DataFormats_Math_Rounding_h
0003 
0004 // This file provides utilities for comparing and rounding floating point numbers
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 }  // namespace cms_rounding
0026 
0027 #endif