File indexing completed on 2024-04-06 12:24:21
0001 #ifndef PhysicsTools_Utilities_Sgn_h
0002 #define PhysicsTools_Utilities_Sgn_h
0003
0004 namespace funct {
0005
0006 template <typename T>
0007 struct SgnStruct {
0008 SgnStruct(const T& t) : _(t) {}
0009 inline double operator()() const { return _() >= 0 ? 1 : -1; }
0010 inline operator double() const { return _() >= 0 ? 1 : -1; }
0011 T _;
0012 };
0013
0014 template <typename T>
0015 struct Sgn {
0016 typedef SgnStruct<T> type;
0017 inline static type compose(const T& t) { return type(t); }
0018 };
0019
0020 template <typename T>
0021 inline typename Sgn<T>::type sgn(const T& t) {
0022 return Sgn<T>::compose(t);
0023 }
0024
0025 }
0026
0027 #endif