Units.hh
Go to the documentation of this file.
1 
4 #pragma once
5 
6 #include <boost/units/cmath.hpp>
7 
8 #include "boca/units/Prefixes.hh"
9 
13 namespace boost
14 {
18 namespace units
19 {
20 
22 template<class Y>
23 struct root_typeof_helper<quantity<Y>, static_rational<1, 2>> {
24  using type = quantity < typename root_typeof_helper<Y, static_rational<1, 2> >::type
25  >;
26  static type value(const quantity<Y>& x) {
27  return sqrt(x);
28  }
29 };
30 
32 template<>
33 struct root_typeof_helper<double, double> {
34  using type = double;
35  static type value(double x) {
36  return std::sqrt(x);
37  }
38 };
39 
40 }
41 
42 }
43 
44 namespace boca
45 {
46 
52 namespace units
53 {
54 
55 template <typename> struct IsQuantity : std::false_type { };
56 template <typename T> struct IsQuantity<boost::units::quantity<T>> : std::true_type { };
57 
58 template<typename Value>
59 using OnlyIfQuantity = typename std::enable_if <IsQuantity<Value>::value >::type;
60 
61 template<typename Value>
62 using OnlyIfNotQuantity = typename std::enable_if < !IsQuantity<Value>::value >::type;
63 
64 
66 template<class Y>
67 typename boost::units::dimensionless_quantity<boost::units::si::system, Y>::type
68 sinh(const boost::units::quantity<boost::units::si::plane_angle, Y>& theta)
69 {
70  using std::sinh;
71  return sinh(theta.value());
72 }
73 
75 template<class Y>
76 typename boost::units::dimensionless_quantity<boost::units::si::system, Y>::type
77 exp(const boost::units::quantity<boost::units::si::plane_angle, Y>& theta)
78 {
79  using std::exp;
80  return exp(theta.value());
81 }
82 
84 template<class Y>
85 typename boost::units::quantity<boost::units::si::plane_angle, Y>::type
86 log(const boost::units::dimensionless_quantity<boost::units::si::system, Y>& number)
87 {
88  using std::log;
89  return log(number.value()) * rad;
90 }
91 
93 template<class Y>
94 typename boost::units::quantity<boost::units::si::plane_angle, Y>::type
95 log(const boost::units::dimensionless_quantity<electronvolt::System, Y>& number)
96 {
97  using std::log;
98  return log(number.value()) * rad;
99 }
100 
101 // template
102 template<class Y , typename = OnlyIfNotQuantity<Y>>
103 inline Angle log(Y const& number)
104 {
105  using std::log;
106  return log(number) * rad;
107 }
108 
109 template<class Unit, class Y>
110 inline typename boost::units::root_typeof_helper <boost::units::quantity<Unit, Y>, boost::units::static_rational<3>>::type cbrt(const boost::units::quantity<Unit, Y>& q)
111 {
112  using boost::math::cbrt;
113  using quantity_type = typename boost::units::root_typeof_helper <boost::units::quantity<Unit, Y>, boost::units::static_rational<3>>::type;
114  return quantity_type::from_value(cbrt(q.value()));
115 }
116 
117 template<class Unit, class Y>
118 inline boost::units::quantity<Unit, Y> max BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::units::quantity<Unit, Y>& q1, const boost::units::quantity<Unit, Y>& q2)
119 {
120  using std::max;
121  using result_type = boost::units::quantity<Unit, Y>;
122  return result_type::from_value(max BOOST_PREVENT_MACRO_SUBSTITUTION(q1.value(), q2.value()));
123 }
124 
125 template<class Unit, class Y>
126 inline boost::units::quantity<Unit, Y> min BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::units::quantity<Unit, Y>& q1, const boost::units::quantity<Unit, Y>& q2)
127 {
128  using std::min;
129  using quantity_type = boost::units::quantity<Unit, Y>;
130  return quantity_type::from_value(min BOOST_PREVENT_MACRO_SUBSTITUTION(q1.value(), q2.value()));
131 }
132 
133 template<typename Value, typename Value_2>
134 using ValueProduct = typename boost::units::multiply_typeof_helper<Value, Value_2>::type;
135 
136 template<typename Value, typename Value_2>
137 using ValueQuotient = typename boost::units::divide_typeof_helper<Value, Value_2>::type;
138 
139 template<typename Value>
140 using ValueInverse = typename boost::units::divide_typeof_helper<double, Value>::type;
141 
142 template<typename Value>
143 using ValueSquare = typename boost::units::multiply_typeof_helper<Value, Value>::type;
144 
145 template<typename Value>
146 using ValueSqrt = typename boost::units::root_typeof_helper<Value, double>::type;
147 
148 template<typename Value>
149 using ValueCubed = typename boost::units::multiply_typeof_helper<ValueSquare<Value>, Value>::type;
150 
151 template<typename Value>
152 using Value4 = typename boost::units::multiply_typeof_helper<ValueSquare<Value>, ValueSquare<Value>>::type;
153 
159 template<typename Value>
160 ValueSqrt<Value> sqrt(Value const& value)
161 {
162  return sqrt(value, IsQuantity<Value>());
163 }
164 
165 template<typename Value>
166 ValueSqrt<Value> sqrt(Value const& value, std::false_type)
167 {
168  return std::sqrt(value);
169 }
170 
171 template<typename Value>
172 ValueSqrt<Value> sqrt(Value const& value, std::true_type)
173 {
174  return boost::units::sqrt(value);
175 }
176 
178 
184 template<typename Value>
185 Angle atan2(Value const& value_1, Value const& value_2)
186 {
187  return atan2(value_1, value_2, IsQuantity<Value>());
188 }
189 
190 template<typename Value>
191 Angle atan2(Value const& value_1, Value const& value_2, std::false_type)
192 {
193  return std::atan2(value_1, value_2) * rad;
194 }
195 
196 template<typename Value>
197 Angle atan2(Value const& value_1, Value const& value_2, std::true_type)
198 {
199  return Angle(boost::units::atan2(value_1, value_2));
200 }
201 
203 
209 template<typename Value>
210 Angle acos(Value const& value_1)
211 {
212  return acos(value_1, IsQuantity<Value>());
213 }
214 
215 template<typename Value>
216 Angle acos(Value const& value_1, std::false_type)
217 {
218  return std::acos(value_1) * rad;
219 }
220 
221 template<typename Value>
222 Angle acos(Value const& value_1, std::true_type)
223 {
224  return boost::units::acos(value_1);
225 }
226 
228 
234 template<typename Value>
235 Value abs(Value const& value)
236 {
237  return abs(value, IsQuantity<Value>());
238 }
239 
240 template<typename Value>
241 Value abs(Value const& value, std::false_type)
242 {
243  return std::abs(value);
244 }
245 
246 template<typename Value>
247 Value abs(Value const& value, std::true_type)
248 {
249  return boost::units::abs(value);
250 }
251 
253 
259 template<typename Value>
260 Value max(Value const& value_1, Value const& value_2)
261 {
262  return max(value_1, value_2, IsQuantity<Value>());
263 }
264 
265 template<typename Value>
266 Value max(Value const& value_1, Value const& value_2, std::false_type)
267 {
268  return std::max(value_1, value_2);
269 }
270 
271 template<typename Value>
272 Value max(Value const& value_1, Value const& value_2, std::true_type)
273 {
274  return units::max(value_1, value_2);
275 }
276 
278 
279 }
280 
281 using namespace units;
282 
283 }
284 
285 
typename std::enable_if< IsQuantity< Value >::value >::type OnlyIfQuantity
Definition: Units.hh:59
static type value(double x)
Definition: Units.hh:35
typename boost::units::multiply_typeof_helper< ValueSquare< Value >, Value >::type ValueCubed
Definition: Units.hh:149
Boost provides free peer-reviewed portable C++ source libraries.
Definition: LorentzVectorBase.hh:726
boost::units::quantity< boost::units::si::plane_angle > Angle
Angle measured in radian.
Definition: Si.hh:35
boost::units::root_typeof_helper< boost::units::quantity< Unit, Y >, boost::units::static_rational< 3 > >::type cbrt(const boost::units::quantity< Unit, Y > &q)
Definition: Units.hh:110
typename std::enable_if< !IsQuantity< Value >::value >::type OnlyIfNotQuantity
Definition: Units.hh:62
Angle atan2(Value const &value_1, Value const &value_2, std::true_type)
Arctangent2 .
Definition: Units.hh:197
typename boost::units::multiply_typeof_helper< ValueSquare< Value >, ValueSquare< Value >>::type Value4
Definition: Units.hh:152
static type value(const quantity< Y > &x)
Definition: Units.hh:26
typename boost::units::divide_typeof_helper< double, Value >::type ValueInverse
Definition: Units.hh:140
ValueSqrt< Value > sqrt(Value const &value, std::true_type)
Square Root.
Definition: Units.hh:172
boost::units::dimensionless_quantity< boost::units::si::system, Y >::type exp(const boost::units::quantity< boost::units::si::plane_angle, Y > &theta)
exp of theta in radians
Definition: Units.hh:77
typename boost::units::multiply_typeof_helper< Value, Value_2 >::type ValueProduct
Definition: Units.hh:134
boost::units::quantity< Unit, Y > min BOOST_PREVENT_MACRO_SUBSTITUTION(const boost::units::quantity< Unit, Y > &q1, const boost::units::quantity< Unit, Y > &q2)
Definition: Units.hh:126
Boosted Collider Analysis.
Definition: Analysis.hh:15
typename boost::units::multiply_typeof_helper< Value, Value >::type ValueSquare
Definition: Units.hh:143
boost::units::dimensionless_quantity< boost::units::si::system, Y >::type sinh(const boost::units::quantity< boost::units::si::plane_angle, Y > &theta)
sinh of theta in radians
Definition: Units.hh:68
typename boost::units::root_typeof_helper< Value, double >::type ValueSqrt
Definition: Units.hh:146
Value abs(Value const &value, std::true_type)
Absolute value.
Definition: Units.hh:247
Value max(Value const &value_1, Value const &value_2, std::true_type)
Maximal value.
Definition: Units.hh:272
typename boost::units::divide_typeof_helper< Value, Value_2 >::type ValueQuotient
Definition: Units.hh:137
Definition: Units.hh:55
quantity< typename root_typeof_helper< Y, static_rational< 1, 2 > >::type > type
Definition: Units.hh:25
Angle log(Y const &number)
Definition: Units.hh:103
Angle acos(Value const &value_1, std::true_type)
Arccosine.
Definition: Units.hh:222