thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
PhysicalQtyOps.h
Go to the documentation of this file.
1// -*- C++ -*-
2//
3// PhysicalQtyOps.h is a part of ThePEG - Toolkit for HEP Event Generation
4// Copyright (C) 2006-2019 David Grellscheid, Leif Lonnblad
5//
6// ThePEG is licenced under version 3 of the GPL, see COPYING for details.
7// Please respect the MCnet academic guidelines, see GUIDELINES for details.
8//
9#ifndef Physical_Qty_Ops_H
10#define Physical_Qty_Ops_H
11#include "PhysicalQty.h"
12#include <cmath>
13
18namespace ThePEG {
20
21// qty = qty * qty
22template<typename T, typename U>
23inline constexpr typename BinaryOpTraits<T,U>::MulT
24operator*(T q1, U q2) {
25 typedef typename BinaryOpTraits<T,U>::MulT RetT;
26 return RetT{RetT::baseunit(), q1.rawValue()*q2.rawValue()};
27}
28
29// qty = qty / qty
30template<typename T, typename U>
31inline constexpr typename BinaryOpTraits<T,U>::DivT
32operator/(T q1, U q2) {
33 typedef typename BinaryOpTraits<T,U>::DivT RetT;
34 return RetT{RetT::baseunit(), q1.rawValue()/q2.rawValue()};
35}
36
37// qty = qty + qty
38template<typename T, typename U>
39inline enable_if_same_qty<T,T,U>
40operator+(T q1, U q2) {
41 q1 += q2;
42 return q1;
43}
44
45// qty = qty - qty
46template<typename T, typename U>
47inline enable_if_same_qty<T,T,U>
48operator-(T q1, U q2) {
49 q1 -= q2;
50 return q1;
51}
52
53// qty == qty
54template<typename T, typename U>
55inline constexpr enable_if_same_qty<bool,T,U>
56operator==(T q1, U q2) {
57 return q1.rawValue()==q2.rawValue();
58}
59
60// qty != qty
61template<typename T, typename U>
62inline constexpr enable_if_same_qty<bool,T,U>
63operator!=(T q1, U q2) {
64 return q1.rawValue()!=q2.rawValue();
65}
66
67// qty < qty
68template<typename T, typename U>
69inline constexpr enable_if_same_qty<bool,T,U>
70operator<(T q1, U q2) {
71 return q1.rawValue()<q2.rawValue();
72}
73
74// qty <= qty
75template<typename T, typename U>
76inline constexpr enable_if_same_qty<bool,T,U>
77operator<=(T q1, U q2) {
78 return q1.rawValue()<=q2.rawValue();
79}
80
81// qty > qty
82template<typename T, typename U>
83inline constexpr enable_if_same_qty<bool,T,U>
84operator>(T q1, U q2) {
85 return q1.rawValue()>q2.rawValue();
86}
87
88// qty >= qty
89template<typename T, typename U>
90inline constexpr enable_if_same_qty<bool,T,U>
91operator>=(T q1, U q2) {
92 return q1.rawValue()>=q2.rawValue();
93}
94
95// comparisons with ZERO
96template<typename T>
97inline constexpr enable_if_same_qty<bool, T>
98operator==(T q1, ZeroUnit) {
99 return q1.rawValue() == 0.0;
100}
101template<typename T>
102inline constexpr enable_if_same_qty<bool, T>
103operator!=(T q1, ZeroUnit) {
104 return q1.rawValue() != 0.0;
105}
106template<typename T>
107inline constexpr enable_if_same_qty<bool, T>
108operator<(T q1, ZeroUnit) {
109 return q1.rawValue() < 0.0;
110}
111template<typename T>
112inline constexpr enable_if_same_qty<bool, T>
113operator>(T q1, ZeroUnit) {
114 return q1.rawValue() > 0.0;
115}
116template<typename T>
117inline constexpr enable_if_same_qty<bool, T>
118operator<=(T q1, ZeroUnit) {
119 return q1.rawValue() <= 0.0;
120}
121template<typename T>
122inline constexpr enable_if_same_qty<bool, T>
123operator>=(T q1, ZeroUnit) {
124 return q1.rawValue() >= 0.0;
125}
126
127// qty = qty * double
128template<typename T>
129inline constexpr enable_if_same_qty<T, T>
130operator*(T q,double x) {
131 return T{q,x};
132}
133
134// qty = double * qty
135template<typename T>
136inline constexpr enable_if_same_qty<T, T>
137operator*(double x,T q) {
138 return T{q,x};
139}
140
141// qty = qty / double
142template<typename T>
143inline constexpr enable_if_same_qty<T, T>
144operator/(T q,double x) {
145 return T{q, 1./x};
146}
147
148// qty = double / qty
149template<typename T>
150inline constexpr enable_if_same_qty<typename T::Inverse, T>
151operator/(double x, T q) {
152 typedef typename T::Inverse RetT;
153 return RetT{RetT::baseunit(), x/q.rawValue()};
154}
155
156// qty = -qty
157template<typename T>
158inline constexpr enable_if_same_qty<T, T>
159operator-(T q) {
160 typedef T RetT;
161 return RetT{q, -1.0};
162}
163
164// qty = sqrt(qty) // std::sqrt is not constexpr
165template<typename T>
166inline enable_if_same_qty<typename T::Sqrt, T>
167sqrt(T q) {
168 typedef typename T::Sqrt RetT;
169 return RetT{RetT::baseunit(), std::sqrt(q.rawValue())};
170}
171
172// double = atan2(y,x)
173template<typename T, typename U>
174inline constexpr enable_if_same_qty<double,T,U>
175atan2(T y, U x) {
176 return std::atan2(y.rawValue(), x.rawValue());
177}
178
179// qty = abs(qty)
180template<typename T>
181inline constexpr enable_if_same_qty<T, T>
182abs(T q) {
183 return T{T::baseunit(), std::abs(q.rawValue())};
184}
185
186// qty = pow<P,R>(qty)
187template<long int Num, long int Den, typename T>
188inline constexpr enable_if_same_qty<typename T::template Power<Num,Den>, T>
189pow(T q) {
190 typedef typename T::template Power<Num,Den> RetT;
191 return RetT{RetT::baseunit(), std::pow(q.rawValue(),double(Num)/double(Den))};
192}
193
194// max for T,U types
195template<typename T, typename U>
196inline T max(const T & t, const U & u) {
197 const T & utmp = u;
198 return std::max(t, utmp);
199}
200
201// ZeroUnit in front should take U type
202template<typename U>
203inline U max(const ZeroUnit & t, const U & u) {
204 const U & ttmp = t;
205 return std::max(ttmp, u);
206}
207
208// min for T,U types
209template<typename T, typename U>
210inline T min(const T & t, const U & u) {
211 const T & utmp = u;
212 return std::min(t, utmp);
213}
214
215// ZeroUnit in front should take U type
216template<typename U>
217inline U min(const ZeroUnit & t, const U & u) {
218 const U & ttmp = t;
219 return std::min(ttmp, u);
220}
221
222
224}
225
226#endif
The PhysicalQty class allows compile-time checking of dimensional correctness.
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28