CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
angle_units.h
Go to the documentation of this file.
1 #ifndef DataFormats_Math_Angle_Units_h
2 #define DataFormats_Math_Angle_Units_h
3 
4 #include <cmath>
5 
6 namespace angle_units {
7 
8  constexpr double piRadians(M_PI);
9  constexpr double degPerRad = 180. / piRadians; // Degrees per radian
10 
11  namespace operators {
12 
13  // Angle
14  constexpr double operator"" _pi(long double x) { return double(x) * M_PI; }
15  constexpr double operator"" _pi(unsigned long long int x) { return double(x) * M_PI; }
16  constexpr double operator"" _deg(long double deg) { return deg / degPerRad; }
17  constexpr double operator"" _deg(unsigned long long int deg) { return deg / degPerRad; }
18  constexpr double operator"" _rad(long double rad) { return rad * 1.; }
19 
20  template <class NumType>
21  inline constexpr NumType convertRadToDeg(NumType radians) // Radians -> degrees
22  {
23  return (radians * degPerRad);
24  }
25 
26  template <class NumType>
27  inline constexpr double convertDegToRad(NumType degrees) // Degrees -> radians
28  {
29  return (degrees / degPerRad);
30  }
31 
32  template <class NumType>
33  typename std::enable_if<!std::numeric_limits<NumType>::is_integer, bool>::type almostEqual(NumType x,
34  NumType y,
35  int ulp) {
36  return std::fabs(x - y) <= std::numeric_limits<NumType>::epsilon() * std::fabs(x + y) * ulp ||
37  std::fabs(x - y) < std::numeric_limits<NumType>::min();
38  }
39 
40  } // namespace operators
41 } // namespace angle_units
42 
43 #endif
double degrees(double radiants)
def degrees
constexpr double degPerRad
Definition: angle_units.h:9
constexpr double convertDegToRad(NumType degrees)
Definition: angle_units.h:27
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
std::enable_if<!std::numeric_limits< NumType >::is_integer, bool >::type almostEqual(NumType x, NumType y, int ulp)
Definition: angle_units.h:33
T min(T a, T b)
Definition: MathUtil.h:58
#define M_PI
constexpr double piRadians(M_PI)