Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:39:06

0001 #ifndef GeometryVector_PreciseFloatType_h
0002 #define GeometryVector_PreciseFloatType_h
0003 
0004 /** Defines a typeded corresponding to the more precise of the two 
0005  *  floating point types.
0006  *  This is useful for mixed precision arithmetic, e.g. to determin the 
0007  *  return type. Example of use:
0008  *  template <class T, class U> 
0009  *  typename PreciseFloatType<T,U>::Type operator+( const Vector<T>& a, 
0010  *                                                  const Vector<U>& b) {
0011  *    typename PreciseFloatType<T,U>::Type result(a); // assuming constructability
0012  *    return a+=b;                    // and addition for Vector of different type.
0013  *  }
0014  *
0015  *  This implementation is very simple, it only handles float, double and long double.
0016  *  for all other types PreciseFloatType<T,U>::Type is double if not compared
0017  *  to long double, otherwise it is long double.
0018  */
0019 
0020 ///  default definition is double
0021 
0022 template <typename T, typename U>
0023 struct PreciseFloatType {
0024   typedef double Type;
0025 };
0026 
0027 /// If the two types are identical that is also the precise type
0028 
0029 template <typename T>
0030 struct PreciseFloatType<T, T> {
0031   typedef T Type;
0032 };
0033 
0034 /// long double is more precise by default than other types
0035 
0036 template <typename T>
0037 struct PreciseFloatType<long double, T> {
0038   typedef long double Type;
0039 };
0040 template <typename T>
0041 struct PreciseFloatType<T, long double> {
0042   typedef long double Type;
0043 };
0044 template <>
0045 struct PreciseFloatType<long double, long double> {
0046   typedef long double Type;
0047 };
0048 
0049 #endif