BPU

A rational (usually integral) power of a single basis unit

Context

_images/ditaa-7e93663a62d3e6f5a75b008c04ff95ad0895c4eb.png

Introduction

#include <xo/unit/bpu.hpp>

A xo::qty::bpu (aka “basis power unit”) represents a rational (usually integer) power of a Basis Unit.

For example:

object mm3<<bpu>>
mm3 : native_dim = dim::distance
mm3 : scalefactor = 1/1000
mm3 : power = 3/1

representation for cubic millimeters

object vol<<bpu>>
vol : native_dim = dim::time
vol : scalefactor = 365*24*3600
vol : power = -1/2

representation for annual (365-day) volatility

bpu is intended as an implementation-level abstraction. Application code will normally interact with the more-general scaled_unit instead of bpu.

Class

template<typename Int>
class bpu

represent product of a compile-time scale-factor with a rational power of a native unit

Member Variables

group Bpu-instance-vars

Variables

struct basis_unit bu_

this bpu represent a power of basis unit bu.

Public to avoid disqualifying bpu as a ‘structural type’.

power_ratio_type power_ = {}

this unit represents basis dimension (bu) taken to this power

Public to avoid disqualifying bpu as a ‘structural type’.

Constructors

group bpu constructors

Functions

constexpr bpu() = default

default constructor. creates dimensionless bpu, representing zero’th power of sentinel basis unit

inline constexpr bpu(const basis_unit &bu, const power_ratio_type &power)

construct bpu representing exponent power of basis unit bu

inline constexpr bpu(dim native_dim, const scalefactor_ratio_type &scalefactor, const power_ratio_type &power)

construct bpu representing exponent power of basis_unit(native_dim,scalefactor)

static inline bpu<Int> unit_power(const basis_unit &bu)

construct bpu representing basis unit bu, i.e. with unit exponent

Access Methods

group bpu access methods

Functions

inline const basis_unit &bu() const

report this bpu’s basis_unit, e.g. detail::bu::minute

inline dimension native_dim() const

report this bpu’s dimension, e.g. dimension::time

inline const scalefactor_ratio_type &scalefactor() const

report this bpu’s scale factor, e.g. 60/1 for detail::bu::minute

inline const power_ratio_type &power() const

report this bpu’s exponent, e.g. 3/1 for bpu representing cubic meters

Other Methods

group Bpu-methods

Functions

inline bpu_abbrev_type abbrev() const

abbreviation for this dimension

bpu<int64_t>(dim::time,
             scalefactor_ratio_type(60,1),
             power_ratio_type(-2,1)).abbrev() => "min^-2"
inline bpu<Int> reciprocal() const

for bpu x, x.reciprocal() represents dimension of 1/x

Example:

constexpr auto x = bpu<int64_t>(dim::time,
                                scalefactor_ratio_type(60,1),
                                power_ratio_type(1));
x.abbrev() => "min"
x.reciprocal().abbrev() => "min^-1"

template<typename Int2>
inline bpu<Int2> to_repr() const

construct bpu representing the same unit, but using Int2 to represent exponenct

Comparison

group Bpu-comparison

Functions

template<typename Int>
inline bool operator==(const bpu<Int> &x, const bpu<Int> &y)

compare bpus x and y for equality

Equality requires that both basis unit and power are equal

template<typename Int>
inline bool operator!=(const bpu<Int> &x, const bpu<Int> &y)

compare bpus x and y for inequality

Details

group bpu abbrev helpers

Functions

power_abbrev_type flatstring_from_exponent(const power_ratio_type &power)

construct prefix string for unit exponent

Auxiliary function for bpu_abbrev

static bpu_abbrev_type bpu_abbrev(dim native_dim, const scalefactor_ratio_type &scalefactor, const power_ratio_type &power)

construct suffix abbreviation for a basis-power-unit