|
units
Use physical dimensions at compile-time or run-time.
|
Rational exponent for each basis-element of dimension. More...
#include <dim.hpp>
Classes | |
| struct | divd |
| Function object used for dividing every exponent by a single factor. More... | |
| struct | mult |
| Function object used for multiplying every exponent by a single factor. More... | |
Public Types | |
| enum | { NUM_BASES = DBO::num_offs, NUM_BITS = NUM_BASES * rat::BITS } |
| using | rat = rational< 4, 2 > |
| Type of rational for dimensioned values. More... | |
| using | off = DBO |
| Type of offset for each base-element. More... | |
| using | word = typename int_types< NUM_BITS >::US |
| Type of unsigned word in which dimensions are encoded. More... | |
Public Member Functions | |
| constexpr | basic_dim () |
| constexpr | basic_dim (word u) |
| Initialize from dim that has been encoded into a word. More... | |
| template<typename... T> | |
| constexpr | basic_dim (T...ts) |
| Initialize exponents, one for each base quantity. More... | |
| constexpr | basic_dim (std::array< rat, NUM_BASES > const &a) |
| constexpr word | encode () const |
| Encode data for this dim into a word. More... | |
| constexpr rat | exp (DBO off) const |
| Rational exponent at specified offset. More... | |
| constexpr rat | operator[] (DBO off) const |
| Rational exponent at specified offset. More... | |
| constexpr void | set (DBO off, rat r) |
| Set rational exponent at specified offset. More... | |
| template<typename F > | |
| constexpr basic_dim | combine (basic_dim const &d, F f) const |
| Combine each exponent with corresponding other exponent via function. More... | |
| template<typename F > | |
| constexpr basic_dim | transform (F f) const |
| Transform each exponent according to a function. More... | |
| constexpr basic_dim | operator+ (basic_dim const &a) const |
| Add corresponding exponents. More... | |
| constexpr basic_dim | operator- (basic_dim const &s) const |
| Subtract corresponding exponents. More... | |
| constexpr basic_dim | operator* (rat f) const |
| Multiply exponents by rational factor. More... | |
| constexpr basic_dim | operator/ (rat f) const |
| Divide exponents by rational factor. More... | |
| constexpr basic_dim | operator/ (rat::stype f) const |
| Divide exponents by rational factor. More... | |
| constexpr bool | operator== (basic_dim const &d) const |
| constexpr bool | operator!= (basic_dim const &d) const |
Static Public Member Functions | |
| static constexpr rat | add (rat x, rat y) |
| Function used to add corresponding exponents. More... | |
| static constexpr rat | sbtrct (rat x, rat y) |
| Function used to subtract corresponding exponents. More... | |
| static std::ostream & | print_unit (std::ostream &s, char const *u, rat e) |
| Print to output stream the symbolic contribution from a given unit. More... | |
Private Types | |
| enum | { MAX_SHIFT = (NUM_BASES - 1) * rat::BITS } |
Static Private Member Functions | |
| template<typename T > | |
| static constexpr word | encode (T t) |
| Encode exponent associated with highest DBO at highest bit-offsets. More... | |
| template<typename T , typename... U> | |
| static constexpr word | encode (T t, U...us) |
| Encode exponents, with higher DBO at higher bit-offsets. More... | |
| static constexpr word | encode (std::array< rat, NUM_BASES > const &a) |
Private Attributes | |
| word | e_ |
| Storage for exponents. More... | |
Friends | |
| std::ostream & | operator<< (std::ostream &s, basic_dim d) |
| Print to to output stream. More... | |
Rational exponent for each basis-element of dimension.
The template-type parameter DBO is of type dim_base_offset, which is automatically generated from YAML and ERB before the header-only library is installed.
| DBO | Type of offset of basis-element of dimension. |
| using vnix::units::basic_dim< DBO >::off = DBO |
| using vnix::units::basic_dim< DBO >::rat = rational<4, 2> |
| using vnix::units::basic_dim< DBO >::word = typename int_types<NUM_BITS>::US |
| anonymous enum |
|
private |
| Enumerator | |
|---|---|
| MAX_SHIFT |
Maximum number of bits to shift an encoding of a rational exponent. |
Definition at line 41 of file dim.hpp.
|
inline |
|
inlineexplicit |
|
inline |
Initialize exponents, one for each base quantity.
| T | List of types, one for each initializer in list for rat_array. Each type should be rat. |
| ts | List of initializers for rat_array. |
Definition at line 96 of file dim.hpp.
|
inline |
Definition at line 101 of file dim.hpp.
|
inlinestatic |
|
inline |
Combine each exponent with corresponding other exponent via function.
| F | Type of function for combining two rationals to make third. |
| d | Other rational exponents. |
| f | Function operating on pair of rationals. |
Definition at line 133 of file dim.hpp.
|
inlinestaticprivate |
Encode exponent associated with highest DBO at highest bit-offsets.
| T | Type that is convertible rat. |
| t | Exponent to be encoded. |
Definition at line 49 of file dim.hpp.
|
inlinestaticprivate |
Encode exponents, with higher DBO at higher bit-offsets.
| T | Type that is convertible to rat. |
| U | List of types, each convertible to rat. |
| t | Exponent to be encoded at lowest bit-offsets. |
| us | Exponents to be encoded at higher bit-offsets. |
Definition at line 60 of file dim.hpp.
|
inlinestaticprivate |
Definition at line 70 of file dim.hpp.
|
inline |
|
inline |
Rational exponent at specified offset.
| off | Offset of exponent. |
Definition at line 108 of file dim.hpp.
|
inline |
|
inline |
Multiply exponents by rational factor.
This is called when a physical quantity is raised to a power.
| f | Factor. |
Definition at line 211 of file dim.hpp.
|
inline |
Add corresponding exponents.
This is called when two physical quantities are multiplied. Passing lambda in constexpr function requires C++17.
| a | Addends. |
Definition at line 194 of file dim.hpp.
|
inline |
Subtract corresponding exponents.
This is called when one physical quantity is divided by another. Passing lambda in constexpr function requires C++17.
| s | Subtrahends. |
Definition at line 203 of file dim.hpp.
|
inline |
Divide exponents by rational factor.
This is called when a physical quantity is raised to a power.
| f | Factor. |
Definition at line 217 of file dim.hpp.
|
inline |
Divide exponents by rational factor.
This is called when a physical quantity is raised to a power.
| f | Factor. |
Definition at line 223 of file dim.hpp.
|
inline |
|
inline |
Rational exponent at specified offset.
| off | Offset of exponent. |
Definition at line 115 of file dim.hpp.
|
inlinestatic |
Print to output stream the symbolic contribution from a given unit.
| s | Output stream. |
| u | Abbreviation for unit. |
| e | Exponent of unit. |
Definition at line 235 of file dim.hpp.
|
inlinestatic |
|
inline |
Set rational exponent at specified offset.
| off | Offset of exponent. |
| r | Rational exponent. |
Definition at line 120 of file dim.hpp.
|
inline |
Transform each exponent according to a function.
| F | Type of function. |
| f | Unary function operating on rational. |
Definition at line 146 of file dim.hpp.
|
friend |
Print to to output stream.
| s | Reference to stream. |
| d | Dimension to print. |
Definition at line 251 of file dim.hpp.
|
private |
1.8.11