File indexing completed on 2024-04-06 12:04:40
0001 #ifndef DataFormats_Math_Angle_Units_h
0002 #define DataFormats_Math_Angle_Units_h
0003
0004 #include <cmath>
0005
0006 namespace angle_units {
0007
0008 constexpr double piRadians(M_PI);
0009 constexpr double degPerRad = 180. / piRadians;
0010
0011 namespace operators {
0012
0013
0014 constexpr double operator"" _pi(long double x) { return double(x) * M_PI; }
0015 constexpr double operator"" _pi(unsigned long long int x) { return double(x) * M_PI; }
0016 constexpr double operator"" _deg(long double deg) { return deg / degPerRad; }
0017 constexpr double operator"" _deg(unsigned long long int deg) { return deg / degPerRad; }
0018 constexpr double operator"" _rad(long double rad) { return rad * 1.; }
0019
0020 template <class NumType>
0021 inline constexpr NumType convertRadToDeg(NumType radians)
0022 {
0023 return (radians * degPerRad);
0024 }
0025
0026 template <class NumType>
0027 inline constexpr double convertDegToRad(NumType degrees)
0028 {
0029 return (degrees / degPerRad);
0030 }
0031
0032 template <class NumType>
0033 typename std::enable_if<!std::numeric_limits<NumType>::is_integer, bool>::type almostEqual(NumType x,
0034 NumType y,
0035 int ulp) {
0036 return std::fabs(x - y) <= std::numeric_limits<NumType>::epsilon() * std::fabs(x + y) * ulp ||
0037 std::fabs(x - y) < std::numeric_limits<NumType>::min();
0038 }
0039
0040
0041
0042
0043 template <class NumType>
0044 inline constexpr NumType convertMmToCm(NumType millimeters)
0045 {
0046 return (millimeters / 10.);
0047 }
0048
0049 template <class NumType>
0050 inline constexpr NumType convertCmToMm(NumType centimeters)
0051 {
0052 return (centimeters * 10.);
0053 }
0054
0055 template <class NumType>
0056 inline constexpr NumType convertCm2ToMm2(NumType centimeters)
0057 {
0058 return (centimeters * 100.);
0059 }
0060
0061 template <class NumType>
0062 inline constexpr NumType convertMm3ToM3(NumType mm3)
0063 {
0064 return (mm3 / 1.e9);
0065 }
0066
0067 template <class NumType>
0068 inline constexpr NumType convertMeVToGeV(NumType mev)
0069 {
0070 return (mev * 0.001);
0071 }
0072
0073 template <class NumType>
0074 inline constexpr NumType convertGeVToMeV(NumType gev)
0075 {
0076 return (gev * 1000.);
0077 }
0078
0079 template <class NumType>
0080 inline constexpr NumType convertGeVToKeV(NumType gev)
0081 {
0082 return (gev * 1.e6);
0083 }
0084
0085 }
0086 }
0087
0088 #endif