Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-06 09:25:33

0001 // This -*- C++ -*- header file contains the definition of the classes
0002 // ZeroFloat and ZeroFloatArray.
0003 //
0004 // ZeroFloat is an empty class which behaves like the floating point
0005 // numer 0.0.  The compiler should be able to automatically set to
0006 // zero some (sub)expressions containing the ZeroFloat type at compile
0007 // time.  It is used for the Masslesss type instantation of the
0008 // Amplitde methods.
0009 //
0010 // ZeroFloatArray is an empty class which behaves like an array of
0011 // ZeroFloat objects.
0012 
0013 
0014 #ifndef NINJA_ZERO_FLOAT_HH
0015 #define NINJA_ZERO_FLOAT_HH
0016 
0017 #include <iostream>
0018 
0019 namespace ninja {
0020 
0021   class ZeroFloat {
0022   public:
0023     ZeroFloat() {}
0024 
0025     // +0 = 0
0026     ZeroFloat operator + () const
0027     {
0028       return ZeroFloat();
0029     }
0030     
0031     // -0 = 0
0032     ZeroFloat operator - () const
0033     {
0034       return ZeroFloat();
0035     }
0036     
0037   private:
0038     // no-data
0039   };
0040 
0041 
0042   // Comparisons with 0
0043   template<typename T>
0044   inline bool operator == (ZeroFloat, const T & x)
0045   {
0046     return (x==T(0));
0047   }
0048   template<typename T>
0049   inline bool operator == (const T & x, ZeroFloat)
0050   {
0051     return (x==T(0));
0052   }
0053   template<typename T>
0054   inline bool operator != (ZeroFloat, const T & x)
0055   {
0056     return (x!=T(0));
0057   }
0058   template<typename T>
0059   inline bool operator != (const T & x, ZeroFloat)
0060   {
0061     return (x!=T(0));
0062   }
0063   template<typename T>
0064   inline bool operator < (ZeroFloat, const T & x)
0065   {
0066     return (x>T(0));
0067   }
0068   template<typename T>
0069   inline bool operator < (const T & x, ZeroFloat)
0070   {
0071     return (x<T(0));
0072   }
0073 
0074 
0075   // Standard output stream
0076   inline std::ostream & operator << (std::ostream & os, ZeroFloat)
0077   {
0078     return os << "(zero)";
0079   }
0080 
0081 
0082   // The following class can be used in order to mimic an array of zeroes
0083   class ZeroFloatArray {
0084 
0085   public:
0086 
0087     ZeroFloatArray() {}
0088 
0089     template<typename T> ZeroFloatArray(const T *) {}
0090 
0091     ZeroFloat operator [] (int)
0092     {
0093       return ZeroFloat();
0094     }
0095 
0096   private:
0097     // no-data
0098   };
0099 
0100 
0101   namespace details {
0102 
0103     // compile-time check: if a type is massless
0104     template <typename MassType>
0105     struct MasslessTypeError {};
0106     template <>
0107     struct MasslessTypeError<ZeroFloat> {
0108       static void MassType_must_be_massless() {}
0109     };
0110 
0111   } // namespace details
0112 
0113 } // namespace ninja
0114 
0115 #endif // NINJA_ZERO_FLOAT_HH