units
Use physical dimensions at compile-time or run-time.
dimval.hpp
Go to the documentation of this file.
1 /// @file vnix/units/dimval.hpp
2 /// @brief Definition of vnix::units::dimval, descendants, and typedefs.
3 /// @copyright 2019 Thomas E. Vaughan; all rights reserved.
4 /// @license BSD Three-Clause; see LICENSE.
5 
6 #ifndef VNIX_UNITS_DIMVAL_HPP
7 #define VNIX_UNITS_DIMVAL_HPP
8 
9 #include <cmath> // for sqrt, pow
10 #include <vnix/units/dim.hpp> // for dim
11 #include <vnix/units/dyndim-base.hpp> // for dyndim_base
12 #include <vnix/units/number.hpp> // for number
13 #include <vnix/units/statdim-base.hpp> // for statdim_base
14 
15 namespace vnix {
16 
17 /// Classes and functions supporting a model of physically dimensioned
18 /// quantities.
19 namespace units {
20 
21 
22 template <typename T, typename B> class dimval;
23 template <typename T> class basic_dyndim;
24 template <dim::word D, typename T> class basic_statdim;
25 
26 
27 /// Return the reciprocal of an instance of type T.
28 /// Specialize this as necessary for matrix, etc.
29 /// @tparam T Numeric type of dimensioned quantity.
30 /// @param v Numeric value stored in dimensioned quantity.
31 template <typename T> constexpr auto invert(T v) { return T(1) / v; }
32 
33 /// Specialization of invert() for Eigen::Matrix.
34 template <typename S, int R, int C, int OPT, int MR, int MC>
35 constexpr auto invert(Eigen::Matrix<S, R, C, OPT, MR, MC> const &m) {
36  return m.inverse();
37 }
38 
39 
40 /// Integer typedef defined by number<OT> only if OT be an acceptable
41 /// scalar-type.
42 ///
43 /// This typedef is used to support SFINAE, which limits the scope of some of
44 /// the template member functions defined here in dimval.
45 ///
46 /// @tparam OT Type of scalar.
47 template <typename OT> using otest = typename number<OT>::test;
48 
49 
50 /// Model of a physically dimensioned quantity.
51 /// @tparam T Type of storage (e.g., float or double) for numerical quantity.
52 /// @tparam B Base-class (statdim_base or dyndim_base) for dimension.
53 template <typename T, typename B>
54 class dimval : protected number<T>, public B {
55  /// Allow access to every kind of dimval.
56  /// @tparam OT Type of other dimval's numeric value.
57  /// @tparam OB Type of other dimval's base-class for dimension.
58  template <typename OT, typename OB> friend class dimval;
59 
60  /// Allow access to each kind (float or double) of dyndim.
61  /// @tparam OT Type of dyndim's numeric value.
62  template <typename OT> friend class basic_dyndim;
63 
64  /// Allow access to every kind of statdim.
65  /// @tparam D Encoding of dimension in dim::word.
66  /// @tparam OT Type of statdim's numeric value.
67  template <dim::word D, typename OT> friend class basic_statdim;
68 
69 protected:
70  /// Initialize dimension, but leave number undefined.
71  /// @param d Dimension.
72  dimval(dim const &d) : B(d) {}
73 
74  using number<T>::v_; ///< Allow access to numeric value.
75 
76 public:
77  using B::d; ///< Allow access to dimension.
78  dimval() : B(d()) {} ///< By default, do not initialize.
79 
80  /// Initialize from numeric value and from dimension.
81  ///
82  /// NOTE: This is public not because it ought to be called by the user but
83  /// because there is no easy way to allow every friend operator access to
84  /// every kind of dimval.
85  ///
86  /// @param v Numeric value.
87  /// @param d Dimension.
88  constexpr dimval(T const &v, dim const &d) : number<T>(v), B(d) {}
89 
90  /// Initialize from other dimensioned value.
91  /// @tparam OT Numeric type of other dimensioned value.
92  /// @tparam OB Base-dimension type of other dimensioned value.
93  /// @param v Reference to other dimensioned value.
94  template <typename OT, typename OB>
95  constexpr dimval(dimval<OT, OB> const &v) : number<T>(v.v_), B(v.d()) {}
96 
97  /// Initialize from dimensionless number.
98  /// @param n Number.
99  constexpr dimval(T const &n) : number<T>(n), B(dim()) {}
100 
101  /// Convert to dimensionless number.
102  constexpr T to_number() const {
103  B::number();
104  return v_;
105  }
106 
107  /// Exponent for base at specified offset.
108  /// @param off Offset.
109  constexpr dim::rat d(dim::off off) const { return B::d()[off]; }
110 
111  /// Equality-comparison of two dimensioned values.
112  /// This will throw an exception if the dimensions are different.
113  /// @tparam OT Numeric type of other dimensioned value.
114  /// @tparam OB Base-dimension type of other dimensioned value.
115  /// @param v Reference to other dimensioned value.
116  /// @return True only if this and the other be equal.
117  template <typename OT, typename OB>
118  constexpr auto operator==(dimval<OT, OB> const &v) const {
119  B::comparison(v); // Check for compatibility of units.
120  return v_ == v.v_;
121  }
122 
123  /// Inequality-comparison of two dimensioned values.
124  /// This will throw an exception if the dimensions are different.
125  /// @tparam OT Numeric type of other dimensioned value.
126  /// @tparam OB Base-dimension type of other dimensioned value.
127  /// @param v Reference to other dimensioned value.
128  /// @return True only if this and the other be unequal.
129  template <typename OT, typename OB>
130  constexpr auto operator!=(dimval<OT, OB> const &v) const {
131  return !(*this == v);
132  }
133 
134  /// Less-than comparison of two dimensioned values.
135  /// This will throw an exception if the dimensions are different.
136  /// @tparam OT Numeric type of other dimensioned value.
137  /// @tparam OB Base-dimension type of other dimensioned value.
138  /// @param v Reference to other dimensioned value.
139  /// @return True only if this be less than the other.
140  template <typename OT, typename OB>
141  constexpr auto operator<(dimval<OT, OB> const &v) const {
142  B::comparison(v); // Check for compatibility of units.
143  return v_ < v.v_;
144  }
145 
146  /// Less-than-or-equal comparison of two dimensioned values.
147  /// This will throw an exception if the dimensions are different.
148  /// @tparam OT Numeric type of other dimensioned value.
149  /// @tparam OB Base-dimension type of other dimensioned value.
150  /// @param v Reference to other dimensioned value.
151  /// @return True only if this be less than or equal to the other.
152  template <typename OT, typename OB>
153  constexpr auto operator<=(dimval<OT, OB> const &v) const {
154  B::comparison(v); // Check for compatibility of units.
155  return v_ <= v.v_;
156  }
157 
158  /// Greater-than comparison of two dimensioned values.
159  /// This will throw an exception if the dimensions are different.
160  /// @tparam OT Numeric type of other dimensioned value.
161  /// @tparam OB Base-dimension type of other dimensioned value.
162  /// @param v Reference to other dimensioned value.
163  /// @return True only if this be greater than the other.
164  template <typename OT, typename OB>
165  constexpr auto operator>(dimval<OT, OB> const &v) const {
166  return !(*this <= v);
167  }
168 
169  /// Greater-than-or-equal comparison of two dimensioned values.
170  /// This will throw an exception if the dimensions are different.
171  /// @tparam OT Numeric type of other dimensioned value.
172  /// @tparam OB Base-dimension type of other dimensioned value.
173  /// @param v Reference to other dimensioned value.
174  /// @return True only if this be greater than or equal to the other.
175  template <typename OT, typename OB>
176  constexpr auto operator>=(dimval<OT, OB> const &v) const {
177  return !(*this < v);
178  }
179 
180  /// Sum of two dimensioned values.
181  /// @tparam OT Numeric type of addend.
182  /// @tparam OB Base-dimension type of addend.
183  /// @param v Addend.
184  /// @return Sum.
185  template <typename OT, typename OB>
186  constexpr auto operator+(dimval<OT, OB> const &v) const {
187  auto const sdim = B::sum(v); // Check for compatibility of units.
188  auto sum = v_ + v.v_;
189  return dimval<decltype(sum), B>(sum, sdim.d());
190  }
191 
192  /// Difference between two dimensioned values.
193  /// @tparam OT Numeric type of subtractor.
194  /// @tparam OB Base-dimension type of subtractor.
195  /// @param v Subractor.
196  /// @return Difference.
197  template <typename OT, typename OB>
198  constexpr auto operator-(dimval<OT, OB> const &v) const {
199  auto const ddim = B::diff(v); // Check for compatibility of units.
200  auto diff = v_ - v.v_;
201  return dimval<decltype(diff), B>(diff, ddim.d());
202  }
203 
204  /// Modify present instance by adding in a dimensioned value.
205  /// @tparam OT Numeric type of addend.
206  /// @tparam OB Base-dimension type of addend.
207  /// @param v Addend.
208  /// @return Sum.
209  template <typename OT, typename OB>
210  constexpr dimval &operator+=(dimval<OT, OB> const &v) {
211  B::sum(v); // Check for compatibility of units.
212  v_ += v.v_;
213  return *this;
214  }
215 
216  /// Modify present instance by subtracting out a dimensioned value.
217  /// @tparam OT Numeric type of subtractor.
218  /// @tparam OB Base-dimension type of subtractor.
219  /// @param v Subtractor.
220  /// @return Difference.
221  template <typename OT, typename OB>
222  constexpr dimval &operator-=(dimval<OT, OB> const &v) {
223  B::diff(v); // Check for compatibility of units.
224  v_ -= v.v_;
225  return *this;
226  }
227 
228  /// Scale dimensioned value.
229  ///
230  /// This function's scope for matching the template-type parameter is limited
231  /// by SFINAE.
232  ///
233  /// @tparam OT Type of scale-factor.
234  /// @param n Scale-factor.
235  /// @return Scaled value.
236  template <typename OT, otest<OT> = 0>
237  constexpr auto operator*(OT const &n) const {
238  auto prod = v_ * n;
239  return dimval<decltype(prod), B>(prod, d());
240  }
241 
242  /// Scale dimensioned value.
243  ///
244  /// This function's scope for matching the template-type parameter is limited
245  /// by SFINAE.
246  ///
247  /// @tparam OT Type of scale-factor.
248  /// @param n Scale-factor.
249  /// @param v Original value.
250  /// @return Scaled value.
251  template <typename OT, otest<OT> = 0>
252  friend constexpr auto operator*(OT const &n, dimval const &v) {
253  auto prod = n * v.v_;
254  return dimval<decltype(prod), B>(prod, v.d());
255  }
256 
257  /// Multiply two dimensioned values.
258  /// @tparam OT Numeric type of factor.
259  /// @tparam OB Base-dimension type of factor.
260  /// @param v Factor.
261  /// @return Product.
262  template <typename OT, typename OB>
263  constexpr auto operator*(dimval<OT, OB> const &v) const {
264  auto const pdim = B::prod(v);
265  auto prod = v_ * v.v_;
266  return dimval<decltype(prod), decltype(pdim)>(prod, pdim.d());
267  }
268 
269  /// Support element-access in case it be supported by numeric type.
270  /// @param off Offset of element.
271  constexpr auto operator[](size_t off) const {
272  auto e = v_[off];
273  return dimval<decltype(e), B>(e, d());
274  }
275 
276  /// Support dot-product in case it be supported by numeric type.
277  /// @tparam OT Numeric type of factor.
278  /// @param n Factor.
279  /// @return Dot-product.
280  template <typename OT, otest<OT> = 0> constexpr auto dot(OT const &n) const {
281  auto prod = v_.dot(n);
282  return dimval<decltype(prod), B>(prod, d());
283  }
284 
285  /// Support dot-product in case it be supported by numeric type.
286  /// @tparam OT Numeric type of factor.
287  /// @tparam OB Base-dimension type of factor.
288  /// @param v Factor.
289  /// @return Dot-product.
290  template <typename OT, typename OB>
291  constexpr auto dot(dimval<OT, OB> const &v) const {
292  auto const pdim = B::prod(v);
293  auto prod = v_.dot(v.v_);
294  return dimval<decltype(prod), decltype(pdim)>(prod, pdim.d());
295  }
296 
297  /// Support cross-product in case it be supported by numeric type.
298  /// @tparam OT Numeric type of factor.
299  /// @param n Factor.
300  /// @return Cross-product.
301  template <typename OT, otest<OT> = 0>
302  constexpr auto cross(OT const &n) const {
303  auto prod = v_.cross(n);
304  return dimval<decltype(prod), B>(prod, d());
305  }
306 
307  /// Support cross-product in case it be supported by numeric type.
308  /// @tparam OT Numeric type of factor.
309  /// @tparam OB Base-dimension type of factor.
310  /// @param v Factor.
311  /// @return Dot-product.
312  template <typename OT, typename OB>
313  constexpr auto cross(dimval<OT, OB> const &v) const {
314  auto const pdim = B::prod(v);
315  auto prod = v_.cross(v.v_);
316  return dimval<decltype(prod), decltype(pdim)>(prod, pdim.d());
317  }
318 
319  /// Scale dimensioned quantity by dividing by number.
320  ///
321  /// This function's scope for matching the template-type parameter is limited
322  /// by SFINAE.
323  ///
324  /// @tparam OT Type of scale-factor.
325  /// @param n Scale-divisor.
326  /// @return Scaled value.
327  template <typename OT, otest<OT> = 0>
328  constexpr auto operator/(OT const &n) const {
329  auto quot = v_ / n;
330  return dimval<decltype(quot), B>(quot, d());
331  }
332 
333  /// Invert dimensioned value.
334  /// @return Reciprocal of dimval.
335  constexpr dimval<T, typename B::recip_basedim> inverse() const {
336  auto const br = this->recip();
337  return dimval<T, typename B::recip_basedim>(invert(v_), br.d());
338  }
339 
340  /// Divide two dimensioned values.
341  /// @tparam OT Numeric type of divisor.
342  /// @tparam OB Base-dimension type of divisor.
343  /// @param v Divisor.
344  /// @return Quotient.
345  template <typename OT, typename OB>
346  constexpr auto operator/(dimval<OT, OB> const &v) const {
347  auto const qdim = B::quot(v);
348  auto quot = v_ / v.v_;
349  return dimval<decltype(quot), decltype(qdim)>(v_ / v.v_, qdim.d());
350  }
351 
352  /// Modify present instance by multiplying in a dimensionless value.
353  ///
354  /// This function's scope for matching the template-type parameter is limited
355  /// by SFINAE.
356  ///
357  /// @tparam OT Type of scale-factor.
358  /// @param v Dimensionless scale-factor.
359  /// @return Scaled value.
360  template <typename OT, otest<OT> = 0>
361  constexpr dimval &operator*=(OT const &v) {
362  v_ *= v;
363  return *this;
364  }
365 
366  /// Modify present instance by dividing it by a dimensionless value.
367  ///
368  /// This function's scope for matching the template-type parameter is limited
369  /// by SFINAE.
370  ///
371  /// @tparam OT Type of scale-factor.
372  /// @param v Dimensionless scale-divisor.
373  /// @return Scaled value.
374  template <typename OT, otest<OT> = 0>
375  constexpr dimval &operator/=(OT const &v) {
376  v_ /= v;
377  return *this;
378  }
379 
380  /// Raise dimensioned value to rational power.
381  /// @tparam PN Numerator of power.
382  /// @tparam PD Denominator of power (by default, 1).
383  /// @return Transformed value of different dimension.
384  template <int64_t PN, int64_t PD = 1> constexpr auto power() const {
385  auto const pdim = B::template pow<PN, PD>();
386  auto const powr = pow(v_, PN * 1.0 / PD);
387  return dimval<T, decltype(pdim)>(powr, pdim.d());
388  }
389 
390  /// Raise dimensioned value to rational power.
391  /// @param p Rational power.
392  /// @return Transformed value of different dimension.
393  constexpr auto power(dim::rat p) const {
394  auto const pdim = B::pow(p);
395  auto const powr = pow(v_, p.to_double());
396  return dimval<T, decltype(pdim)>(powr, pdim.d());
397  }
398 
399  /// Square-root of a dimensioned quantity.
400  constexpr auto square_root() const {
401  auto const rdim = B::sqrt();
402  T const root = sqrt(v_);
403  return dimval<T, decltype(rdim)>(root, rdim.d());
404  }
405 
406  /// Print to to output stream.
407  friend std::ostream &operator<<(std::ostream &s, dimval const &v) {
408  return s << v.v_ << v.d();
409  }
410 };
411 
412 
413 /// Invert dimensioned value by dividing it into number.
414 ///
415 /// This function's scope for matching the template-type parameter is limited
416 /// by SFINAE.
417 ///
418 /// @tparam OT Type of scale-factor.
419 /// @tparam T Type of numeric storage in dimval.
420 /// @tparam B Type of base-class for dimension.
421 /// @param d Number as dividend.
422 /// @param v Dimensioned quantitity as divisor.
423 /// @return Inverted value.
424 template <typename OT, typename T, typename B, otest<OT> = 0>
425 constexpr auto operator/(OT const &d, dimval<T, B> const &v) {
426  return d * v.inverse();
427 }
428 
429 
430 /// Take the squre root of a dimensioned quantity.
431 /// @tparam T Type for numeric storage.
432 /// @tparam B Type of base-class for dimension.
433 /// @param v Original dimensioned value.
434 /// @return Transformed value of different dimension.
435 template <typename T, typename B, otest<T> = 0>
436 constexpr auto sqrt(dimval<T, B> const &v) {
437  return v.square_root();
438 }
439 
440 /// Raise dimensioned value to rational power.
441 /// @tparam PN Numerator of power.
442 /// @tparam PD Denominator of power (by default, 1).
443 /// @tparam T Type for numeric storage.
444 /// @tparam B Type of base-class for dimension.
445 /// @param v Original dimensioned value.
446 /// @return Transformed value of different dimension.
447 template <int64_t PN, int64_t PD = 1, typename T, typename B>
448 constexpr auto pow(dimval<T, B> const &v) {
449  return v.template power<PN, PD>();
450 }
451 
452 
453 /// Raise dimensioned value to rational power.
454 /// @tparam T Type for numeric storage.
455 /// @tparam B Type of base-class for dimension.
456 /// @param v Original dimensioned value.
457 /// @param p Rational power.
458 /// @return Transformed value of different dimension.
459 template <typename T, typename B>
460 constexpr auto pow(dimval<T, B> const &v, dim::rat p) {
461  return v.power(p);
462 }
463 
464 
465 /// Model of a dynamically dimensioned physical quantity.
466 /// @tparam T Type of numeric value.
467 template <typename T> class basic_dyndim : public dimval<T, dyndim_base> {
468  using dimval<T, dyndim_base>::v_; ///< Allow access to number.
469 
470 public:
471  /// Initialize from other dimensioned value.
472  /// @tparam OT Numeric type of other dimensioned value.
473  /// @tparam OB Dimension-base of other dimensioned value.
474  /// @param v Reference to other dimensioned value.
475  template <typename OT, typename OB>
476  constexpr basic_dyndim(dimval<OT, OB> const &v)
477  : dimval<T, dyndim_base>(v) {}
478 
479  /// Convert from number.
480  /// @param v Number.
481  constexpr basic_dyndim(T v) : dimval<T, dyndim_base>(v, dim()) {}
482 
483  // TBD: dyndim should have a constructor from std::string.
484 };
485 
486 
487 /// Model of a statically dimensioned physical quantity.
488 /// @tparam D Encoding of dimension in dim::word.
489 /// @tparam T Type numeric value.
490 template <dim::word D, typename T>
491 class basic_statdim : public dimval<T, statdim_base<D>> {
492  /// Type of compatible statdim.
493  /// @tparam OT Type of numeric value.
494  template <typename OT> using stat = dimval<OT, statdim_base<D>>;
495 
496 protected:
497  /// Inherit all of parent's constructors as protected so that descendants
498  /// such as length, time, etc., may call ancestor's constructor from number
499  /// and dimension.
500  using dimval<T, statdim_base<D>>::dimval;
501 
502 public:
503  /// By default, initialize dimension, but leave number uninitialized.
504  basic_statdim() : stat<T>(this->d()) {}
505 
506  /// Initialize from compatible statdim.
507  /// @tparam OT Type of numeric value.
508  /// @param dv Compatible statdim.
509  template <typename OT>
510  constexpr basic_statdim(stat<OT> dv) : stat<T>(dv.v_, dv.d()) {}
511 
512  /// Initialize from dyndim.
513  /// @tparam OT Numeric type of other dimensioned value.
514  /// @param v Reference to other dimensioned value.
515  template <typename OT>
516  constexpr basic_statdim(dimval<OT, dyndim_base> const &v) : stat<T>(v) {}
517 };
518 
519 
520 constexpr auto nul_code = nul_dim.encode();
521 
522 
523 /// Specialization of basic_statdim for dimensionless quantity.
524 template <typename T>
525 class basic_statdim<nul_code, T> : public dimval<T, statdim_base<nul_code>> {
526  /// Type of compatible statdim.
527  /// @tparam OT Type of numeric value.
528  template <typename OT> using stat = dimval<OT, statdim_base<nul_code>>;
529 
530  using dimval<T, statdim_base<nul_code>>::v_; ///< Allow access to number.
531 
532 public:
533  /// Initialize from compatible (dimensionless) statdim.
534  /// @tparam OT Type of numeric value.
535  /// @param dv Compatible statdim.
536  template <typename OT>
537  constexpr basic_statdim(stat<OT> dv) : stat<T>(dv.v_, dv.d()) {}
538 
539  /// Initialize from dyndim.
540  /// @tparam OT Numeric type of other dimensioned value.
541  /// @param v Reference to other dimensioned value.
542  template <typename OT>
543  constexpr basic_statdim(dimval<OT, dyndim_base> const &v) : stat<T>(v) {}
544 
545  /// Initialize from number.
546  /// @param v Number.
547  constexpr basic_statdim(T v) : stat<T>(v, nul_dim) {}
548 
549  constexpr operator T() const { return v_; } ///< Convert to number.
550 };
551 
552 
553 } // namespace units
554 } // namespace vnix
555 
556 #endif // ndef VNIX_UNITS_DIMVAL_HPP
constexpr auto operator[](size_t off) const
Support element-access in case it be supported by numeric type.
Definition: dimval.hpp:271
constexpr word encode() const
Encode data for this dim into a word.
Definition: dim.hpp:104
constexpr basic_statdim(T v)
Initialize from number.
Definition: dimval.hpp:547
constexpr auto invert(Eigen::Matrix< S, R, C, OPT, MR, MC > const &m)
Specialization of invert() for Eigen::Matrix.
Definition: dimval.hpp:35
constexpr auto dot(OT const &n) const
Support dot-product in case it be supported by numeric type.
Definition: dimval.hpp:280
constexpr auto operator/(OT const &n) const
Scale dimensioned quantity by dividing by number.
Definition: dimval.hpp:328
constexpr dimval(T const &n)
Initialize from dimensionless number.
Definition: dimval.hpp:99
constexpr basic_statdim(dimval< OT, dyndim_base > const &v)
Initialize from dyndim.
Definition: dimval.hpp:516
constexpr auto pow(dimval< T, B > const &v)
Raise dimensioned value to rational power.
Definition: dimval.hpp:448
constexpr auto operator<(dimval< OT, OB > const &v) const
Less-than comparison of two dimensioned values.
Definition: dimval.hpp:141
constexpr dimval & operator+=(dimval< OT, OB > const &v)
Modify present instance by adding in a dimensioned value.
Definition: dimval.hpp:210
constexpr auto sqrt(dimval< T, B > const &v)
Take the squre root of a dimensioned quantity.
Definition: dimval.hpp:436
Base-type for a dimensioned value whose dimension is specified, perhaps dynamically at run-time...
Definition: dyndim-base.hpp:24
constexpr auto square_root() const
Square-root of a dimensioned quantity.
Definition: dimval.hpp:400
Definition: number.hpp:11
constexpr dimval & operator/=(OT const &v)
Modify present instance by dividing it by a dimensionless value.
Definition: dimval.hpp:375
constexpr auto power(dim::rat p) const
Raise dimensioned value to rational power.
Definition: dimval.hpp:393
constexpr auto operator*(OT const &n) const
Scale dimensioned value.
Definition: dimval.hpp:237
constexpr dimval(T const &v, dim const &d)
Initialize from numeric value and from dimension.
Definition: dimval.hpp:88
constexpr basic_statdim(stat< OT > dv)
Initialize from compatible statdim.
Definition: dimval.hpp:510
constexpr basic_statdim(dimval< OT, dyndim_base > const &v)
Initialize from dyndim.
Definition: dimval.hpp:543
dimval()
< Allow access to dimension.
Definition: dimval.hpp:78
constexpr auto operator*(dimval< OT, OB > const &v) const
Multiply two dimensioned values.
Definition: dimval.hpp:263
constexpr double to_double() const
Convert to double.
Definition: rational.hpp:71
constexpr auto operator==(dimval< OT, OB > const &v) const
Equality-comparison of two dimensioned values.
Definition: dimval.hpp:118
constexpr auto operator/(OT const &d, dimval< T, B > const &v)
Invert dimensioned value by dividing it into number.
Definition: dimval.hpp:425
constexpr dimval & operator-=(dimval< OT, OB > const &v)
Modify present instance by subtracting out a dimensioned value.
Definition: dimval.hpp:222
constexpr dimval(dimval< OT, OB > const &v)
Initialize from other dimensioned value.
Definition: dimval.hpp:95
constexpr auto operator/(dimval< OT, OB > const &v) const
Divide two dimensioned values.
Definition: dimval.hpp:346
constexpr dimval< T, typename B::recip_basedim > inverse() const
Invert dimensioned value.
Definition: dimval.hpp:335
constexpr auto cross(OT const &n) const
Support cross-product in case it be supported by numeric type.
Definition: dimval.hpp:302
static constexpr dim nul_dim
Null dimension.
Definition: dim.hpp:263
constexpr auto operator-(dimval< OT, OB > const &v) const
Difference between two dimensioned values.
Definition: dimval.hpp:198
constexpr auto operator!=(dimval< OT, OB > const &v) const
Inequality-comparison of two dimensioned values.
Definition: dimval.hpp:130
friend std::ostream & operator<<(std::ostream &s, basic_dim d)
Print to to output stream.
Definition: dim.hpp:251
constexpr T to_number() const
Convert to dimensionless number.
Definition: dimval.hpp:102
constexpr auto nul_code
Definition: dimval.hpp:520
constexpr auto operator+(dimval< OT, OB > const &v) const
Sum of two dimensioned values.
Definition: dimval.hpp:186
dimval(dim const &d)
Initialize dimension, but leave number undefined.
Definition: dimval.hpp:72
constexpr basic_statdim(stat< OT > dv)
< Allow access to number.
Definition: dimval.hpp:537
constexpr auto operator>=(dimval< OT, OB > const &v) const
Greater-than-or-equal comparison of two dimensioned values.
Definition: dimval.hpp:176
constexpr dim::rat d(dim::off off) const
Exponent for base at specified offset.
Definition: dimval.hpp:109
constexpr auto dot(dimval< OT, OB > const &v) const
Support dot-product in case it be supported by numeric type.
Definition: dimval.hpp:291
constexpr auto invert(T v)
Return the reciprocal of an instance of type T.
Definition: dimval.hpp:31
constexpr auto cross(dimval< OT, OB > const &v) const
Support cross-product in case it be supported by numeric type.
Definition: dimval.hpp:313
basic_statdim()
By default, initialize dimension, but leave number uninitialized.
Definition: dimval.hpp:504
constexpr basic_dyndim(dimval< OT, OB > const &v)
< Allow access to number.
Definition: dimval.hpp:476
constexpr operator T() const
Convert to number.
Definition: dimval.hpp:549
constexpr auto operator>(dimval< OT, OB > const &v) const
Greater-than comparison of two dimensioned values.
Definition: dimval.hpp:165
Base-type for a dimensioned value whose dimension is specified statically at compile-time by way of a...
constexpr auto pow(dimval< T, B > const &v, dim::rat p)
Raise dimensioned value to rational power.
Definition: dimval.hpp:460
constexpr dimval & operator*=(OT const &v)
Modify present instance by multiplying in a dimensionless value.
Definition: dimval.hpp:361
Thomas E. Vaughan&#39;s public software.
Definition: rational.hpp:13
Classes and functions supporting a model of physically dimensioned quantities.
Generic template for wrapper to disambiguate scalar from dimval and protected storage for numeric val...
Definition: number.hpp:58
constexpr auto operator<=(dimval< OT, OB > const &v) const
Less-than-or-equal comparison of two dimensioned values.
Definition: dimval.hpp:153
constexpr basic_dim()
Definition: dim.hpp:82
constexpr basic_dyndim(T v)
Convert from number.
Definition: dimval.hpp:481
constexpr auto power() const
Raise dimensioned value to rational power.
Definition: dimval.hpp:384