Natural Unit
A natural unit represents a product of terms, each involving a distinct basis dimension
Context
Introduction
#include <xo/unit/natural_unit.hpp>
Representation for the unit associated with a xquantity
represents a cartesian product of basis units.
constexpr implementation
limited support for fractional dimensions such as time^-1/2
natural unit for a Newton (unit of force)
Class
-
template<typename Int>
class natural_unit an array representing the cartesian product of distinct basis-power-units
Quantities are represented as a multiple of a natural unit
Each bpu in the array represents a power of a basis dimension, e.g. “meter” or “second^2”.
Each bpu in an array has a different dimension id. For example
dim::time, if present, appears once.Basis dimensions can appear in any order. Order used for constructing abbreviations: will get
"kg.m"or"m.kg"depending on the ordering ofdim::distanceanddim::massinbpu_v_
Intsupplies representation for numerator and denominator in basis-unit scale factors.
Member Variables
- group Natural-unit-instance-vars
Type Traits
- group natural unit type traits
Typedefs
-
using ratio_int_type = Int
representation for numerator and denominator of scalefactor ratios
-
using ratio_int_type = Int
Constructors
- group Natural-unit-ctors
Functions
-
inline constexpr natural_unit()
construct dimensionless unit
-
static inline natural_unit from_bu(basis_unit bu, power_ratio_type power = power_ratio_type(1))
construct unit representing basis unit
buwith exponentpower
-
inline constexpr natural_unit()
Access Methods
- group Natural-unit-access-methods
Functions
-
inline bool is_natural() const
always true. Provided for symmetry with
xo::qty::scaled_unit::is_natural
-
inline std::size_t n_bpu() const
get member
n_bpu
-
inline bool is_dimensionless() const
true if this unit has no dimension
-
inline bool is_natural() const
General Methods
- group Natural-unit-methods
Functions
-
inline natural_unit reciprocal() const
construct reciprocal of this unit.
For example reciprocal of a newton (abbreviation
"kg.m.s^-2") is a unit with abbreviation"kg^-1.m^-1.s^2"
-
inline nu_abbrev_type abbrev() const
abbreviation for this unit.
Apply as suffix when printing quantities involving this unit.
For example
"mm"for millimeters, or"ns"for nanoseconds
-
inline void remove_bpu(size_t p)
remove bpu at position
p
-
inline void push_back(const bpu<Int> &bpu)
append
bputo this unit in-placeRequire
bpu.native_dimdoes not match any existing member of bpu_v_
-
inline natural_unit reciprocal() const
Conversion
- group Natural-unit-conversion-methods
Functions
-
template<typename Int2>
inline natural_unit<Int2> to_repr() const convert to equivalent unit using scalefactor representation
Int2instead of ratio_int_type
-
template<typename Int2>
Comparison Functions
- group natural-unit comparison functions
Functions
-
template<typename Int>
bool operator==(const natural_unit<Int> &x, const natural_unit<Int> &y) compare natural units
x,yfor equality.
-
template<typename Int>
bool operator!=(const natural_unit<Int> &x, const natural_unit<Int> &y) compare natural units
x,yfor inequality
-
template<typename Int>