Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:53:33

0001 #ifndef GeometryVector_Geom_Pi_h
0002 #define GeometryVector_Geom_Pi_h
0003 
0004 /** \file 
0005  *  Just pi (the ratio of circle length to diameter).
0006  *  Since the C++ standard seems not to care about PI and the
0007  *  M_PI macro definition in <cmath> is not even in the standard
0008  *  a definition is provided here.
0009  *  <li>
0010  *  The goal of this implementation is to be as efficient as a macro,
0011  *  and transparent to use. Excluding macros, there are four ways
0012  *  to implement a constant for shared use:
0013  *    1) As a global constant (possibly within a namespace), that
0014  *       is initialized by the linker/loader and used as a memory reference
0015  *    2) As a file scope constant (i.e. in the unnamed namespace)
0016  *       with one copy per file
0017  *    3) As an in-line function that returns the value
0018  *    4) As a class with an in-line method that returns the value
0019  *  The first way is probably the most efficient but it requires
0020  *  an additional libraby to link, something you should not need
0021  *  if you just want to use pi.
0022  *  The fourth way is only justified if you need more than one method
0023  *  for the same constant (e.g. return it in different units)
0024  *  The difference between the second and the third is essentially in the
0025  *  parantheses of the function call, which are not needed in the
0026  *  second method.
0027  */
0028 
0029 namespace Geom {
0030 
0031   inline constexpr double pi() { return 3.141592653589793238; }
0032   inline constexpr double twoPi() { return 2. * 3.141592653589793238; }
0033   inline constexpr double halfPi() { return 0.5 * 3.141592653589793238; }
0034 
0035   inline constexpr float fpi() { return 3.141592653589793238f; }
0036   inline constexpr float ftwoPi() { return 2.f * 3.141592653589793238f; }
0037   inline constexpr float fhalfPi() { return 0.5f * 3.141592653589793238f; }
0038 
0039 }  // namespace Geom
0040 
0041 #endif