File indexing completed on 2025-10-31 09:15:38
0001 
0002 
0003 
0004 #ifndef  ROOT_Math_UnaryOperators
0005 #define  ROOT_Math_UnaryOperators
0006 
0007 
0008 
0009 
0010 
0011 
0012 
0013 
0014 
0015 
0016 
0017 
0018 
0019 
0020 
0021 #include <cmath>
0022 
0023 #include "Math/Expression.h"
0024 
0025 namespace ROOT {
0026 
0027   namespace Math {
0028 
0029 
0030 
0031 template <class T, unsigned int D> class SVector;
0032 template <class T, unsigned int D1, unsigned int D2, class R> class SMatrix;
0033 
0034 
0035 
0036 
0037 
0038 
0039 
0040 
0041 
0042 
0043 template <class T>
0044 class Minus {
0045 public:
0046   static inline T apply(const T& rhs) {
0047     return -(rhs);
0048   }
0049 };
0050 
0051 
0052 
0053 
0054 template <class A, class T, unsigned int D>
0055 inline VecExpr<UnaryOp<Minus<T>, VecExpr<A,T,D>, T>, T, D>
0056  operator-(const VecExpr<A,T,D>& rhs) {
0057   typedef UnaryOp<Minus<T>, VecExpr<A,T,D>, T> MinusUnaryOp;
0058 
0059   return VecExpr<MinusUnaryOp,T,D>(MinusUnaryOp(Minus<T>(),rhs));
0060 }
0061 
0062 
0063 
0064 
0065 
0066 
0067 
0068 
0069 
0070 
0071 
0072 template <class T, unsigned int D>
0073 inline VecExpr<UnaryOp<Minus<T>, SVector<T,D>, T>, T, D>
0074  operator-(const SVector<T,D>& rhs) {
0075   typedef UnaryOp<Minus<T>, SVector<T,D>, T> MinusUnaryOp;
0076 
0077   return VecExpr<MinusUnaryOp,T,D>(MinusUnaryOp(Minus<T>(),rhs));
0078 }
0079 
0080 
0081 
0082 
0083 template <class A, class T, unsigned int D, unsigned int D2, class R>
0084 inline Expr<UnaryOp<Minus<T>, Expr<A,T,D,D2,R>, T>, T, D, D2,R>
0085  operator-(const Expr<A,T,D,D2,R>& rhs) {
0086   typedef UnaryOp<Minus<T>, Expr<A,T,D,D2,R>, T> MinusUnaryOp;
0087 
0088   return Expr<MinusUnaryOp,T,D,D2,R>(MinusUnaryOp(Minus<T>(),rhs));
0089 }
0090 
0091 
0092 
0093 
0094 
0095 
0096 
0097 
0098 
0099 
0100 
0101 template <class T, unsigned int D, unsigned int D2, class R>
0102 inline Expr<UnaryOp<Minus<T>, SMatrix<T,D,D2,R>, T>, T, D, D2,R>
0103  operator-(const SMatrix<T,D,D2,R>& rhs) {
0104   typedef UnaryOp<Minus<T>, SMatrix<T,D,D2,R>, T> MinusUnaryOp;
0105 
0106   return Expr<MinusUnaryOp,T,D,D2,R>(MinusUnaryOp(Minus<T>(),rhs));
0107 }
0108 
0109 
0110 
0111 
0112 
0113 
0114 
0115 
0116 
0117 
0118 template <class T>
0119 class Fabs {
0120 public:
0121   static inline T apply(const T& rhs) {
0122     return std::abs(rhs);
0123   }
0124 };
0125 
0126 
0127 
0128 
0129 template <class A, class T, unsigned int D>
0130 inline VecExpr<UnaryOp<Fabs<T>, VecExpr<A,T,D>, T>, T, D>
0131  fabs(const VecExpr<A,T,D>& rhs) {
0132   typedef UnaryOp<Fabs<T>, VecExpr<A,T,D>, T> FabsUnaryOp;
0133 
0134   return VecExpr<FabsUnaryOp,T,D>(FabsUnaryOp(Fabs<T>(),rhs));
0135 }
0136 
0137 
0138 
0139 
0140 
0141 
0142 
0143 
0144 
0145 
0146 
0147 template <class T, unsigned int D>
0148 inline VecExpr<UnaryOp<Fabs<T>, SVector<T,D>, T>, T, D>
0149  fabs(const SVector<T,D>& rhs) {
0150   typedef UnaryOp<Fabs<T>, SVector<T,D>, T> FabsUnaryOp;
0151 
0152   return VecExpr<FabsUnaryOp,T,D>(FabsUnaryOp(Fabs<T>(),rhs));
0153 }
0154 
0155 
0156 
0157 
0158 template <class A, class T, unsigned int D, unsigned int D2, class R>
0159 inline Expr<UnaryOp<Fabs<T>, Expr<A,T,D,D2,R>, T>, T, D, D2, R>
0160  fabs(const Expr<A,T,D,D2,R>& rhs) {
0161   typedef UnaryOp<Fabs<T>, Expr<A,T,D,D2,R>, T> FabsUnaryOp;
0162 
0163   return Expr<FabsUnaryOp,T,D,D2,R>(FabsUnaryOp(Fabs<T>(),rhs));
0164 }
0165 
0166 
0167 
0168 
0169 
0170 
0171 
0172 
0173 
0174 
0175 
0176 template <class T, unsigned int D, unsigned int D2, class R>
0177 inline Expr<UnaryOp<Fabs<T>, SMatrix<T,D,D2,R>, T>, T, D, D2, R>
0178  fabs(const SMatrix<T,D,D2,R>& rhs) {
0179   typedef UnaryOp<Fabs<T>, SMatrix<T,D,D2,R>, T> FabsUnaryOp;
0180 
0181   return Expr<FabsUnaryOp,T,D,D2,R>(FabsUnaryOp(Fabs<T>(),rhs));
0182 }
0183 
0184 
0185 
0186 
0187 
0188 
0189 
0190 
0191 
0192 
0193 template <class T>
0194 class Sqr {
0195 public:
0196   static inline T apply(const T& rhs) {
0197     return square(rhs);
0198   }
0199 };
0200 
0201 
0202 
0203 
0204 template <class A, class T, unsigned int D>
0205 inline VecExpr<UnaryOp<Sqr<T>, VecExpr<A,T,D>, T>, T, D>
0206  sqr(const VecExpr<A,T,D>& rhs) {
0207   typedef UnaryOp<Sqr<T>, VecExpr<A,T,D>, T> SqrUnaryOp;
0208 
0209   return VecExpr<SqrUnaryOp,T,D>(SqrUnaryOp(Sqr<T>(),rhs));
0210 }
0211 
0212 
0213 
0214 
0215 
0216 
0217 
0218 
0219 
0220 
0221 
0222 template <class T, unsigned int D>
0223 inline VecExpr<UnaryOp<Sqr<T>, SVector<T,D>, T>, T, D>
0224  sqr(const SVector<T,D>& rhs) {
0225   typedef UnaryOp<Sqr<T>, SVector<T,D>, T> SqrUnaryOp;
0226 
0227   return VecExpr<SqrUnaryOp,T,D>(SqrUnaryOp(Sqr<T>(),rhs));
0228 }
0229 
0230 
0231 
0232 
0233 template <class A, class T, unsigned int D, unsigned int D2, class R>
0234 inline Expr<UnaryOp<Sqr<T>, Expr<A,T,D,D2,R>, T>, T, D, D2, R>
0235  sqr(const Expr<A,T,D,D2,R>& rhs) {
0236   typedef UnaryOp<Sqr<T>, Expr<A,T,D,D2,R>, T> SqrUnaryOp;
0237 
0238   return Expr<SqrUnaryOp,T,D,D2,R>(SqrUnaryOp(Sqr<T>(),rhs));
0239 }
0240 
0241 
0242 
0243 
0244 
0245 
0246 
0247 
0248 
0249 
0250 
0251 template <class T, unsigned int D, unsigned int D2, class R>
0252 inline Expr<UnaryOp<Sqr<T>, SMatrix<T,D,D2,R>, T>, T, D, D2, R>
0253  sqr(const SMatrix<T,D,D2,R>& rhs) {
0254   typedef UnaryOp<Sqr<T>, SMatrix<T,D,D2,R>, T> SqrUnaryOp;
0255 
0256   return Expr<SqrUnaryOp,T,D,D2,R>(SqrUnaryOp(Sqr<T>(),rhs));
0257 }
0258 
0259 
0260 
0261 
0262 
0263 
0264 
0265 
0266 
0267 
0268 template <class T>
0269 class Sqrt {
0270 public:
0271   static inline T apply(const T& rhs) {
0272     return std::sqrt(rhs);
0273   }
0274 };
0275 
0276 
0277 
0278 
0279 template <class A, class T, unsigned int D>
0280 inline VecExpr<UnaryOp<Sqrt<T>, VecExpr<A,T,D>, T>, T, D>
0281  sqrt(const VecExpr<A,T,D>& rhs) {
0282   typedef UnaryOp<Sqrt<T>, VecExpr<A,T,D>, T> SqrtUnaryOp;
0283 
0284   return VecExpr<SqrtUnaryOp,T,D>(SqrtUnaryOp(Sqrt<T>(),rhs));
0285 }
0286 
0287 
0288 
0289 
0290 
0291 
0292 
0293 
0294 
0295 
0296 
0297 template <class T, unsigned int D>
0298 inline VecExpr<UnaryOp<Sqrt<T>, SVector<T,D>, T>, T, D>
0299  sqrt(const SVector<T,D>& rhs) {
0300   typedef UnaryOp<Sqrt<T>, SVector<T,D>, T> SqrtUnaryOp;
0301 
0302   return VecExpr<SqrtUnaryOp,T,D>(SqrtUnaryOp(Sqrt<T>(),rhs));
0303 }
0304 
0305 
0306 
0307 
0308 template <class A, class T, unsigned int D, unsigned int D2, class R>
0309 inline Expr<UnaryOp<Sqrt<T>, Expr<A,T,D,D2,R>, T>, T, D, D2, R>
0310  sqrt(const Expr<A,T,D,D2,R>& rhs) {
0311   typedef UnaryOp<Sqrt<T>, Expr<A,T,D,D2,R>, T> SqrtUnaryOp;
0312 
0313   return Expr<SqrtUnaryOp,T,D,D2,R>(SqrtUnaryOp(Sqrt<T>(),rhs));
0314 }
0315 
0316 
0317 
0318 
0319 
0320 
0321 
0322 
0323 
0324 
0325 template <class T, unsigned int D, unsigned int D2, class R>
0326 inline Expr<UnaryOp<Sqrt<T>, SMatrix<T,D,D2,R>, T>, T, D, D2, R>
0327  sqrt(const SMatrix<T,D,D2,R>& rhs) {
0328   typedef UnaryOp<Sqrt<T>, SMatrix<T,D,D2,R>, T> SqrtUnaryOp;
0329 
0330   return Expr<SqrtUnaryOp,T,D,D2,R>(SqrtUnaryOp(Sqrt<T>(),rhs));
0331 }
0332 
0333 
0334   }  
0335 
0336 }  
0337 
0338 
0339 
0340 #endif