quanta 0.1.0
Type-safe units for temperature, frequency, electrical and spatial quantities, modeled after std::chrono
Loading...
Searching...
No Matches
quanta::electro Namespace Reference

Electrical unit types and utilities. More...

Classes

struct  ampere_unit
 Electric current, measured in amperes. More...
 
struct  coulomb_unit
 Electric charge, measured in coulombs. More...
 
struct  decibel_unit
 A dimensionless logarithmic ratio, measured in decibels. More...
 
struct  farad_unit
 Capacitance, measured in farads. More...
 
struct  henry_unit
 Inductance, measured in henries. More...
 
struct  is_level
 Trait to detect level specializations. More...
 
struct  is_level< level< Reference, Rep, Precision > >
 
struct  is_quantity
 Trait to detect quantity specializations. More...
 
struct  is_quantity< quantity< Unit, Rep, Precision > >
 
struct  joule_unit
 Energy, measured in joules. More...
 
class  level
 An absolute point on a logarithmic scale, relative to a reference. More...
 
struct  microvolt_reference
 Reference of 1 µV, for dBµV. More...
 
struct  millivolt_reference
 Reference of 1 mV, for dBmV. More...
 
struct  milliwatt_reference
 Reference of 1 mW, for dBm. More...
 
struct  ohm_unit
 Electrical resistance, measured in ohms. More...
 
class  quantity
 A quantity of an electrical unit with a representation and precision. More...
 
struct  quantity_suffix
 Trait giving the display suffix for a (unit, precision) pair. More...
 
struct  quantity_suffix< decibel_unit, Precision >
 Decibels opt out of the generic SI-prefix suffix machinery. More...
 
struct  quantity_values
 Provides special values for quantity representations. More...
 
struct  si_prefix
 Trait giving the display symbol for an SI precision prefix. More...
 
struct  volt_reference
 Reference of 1 V, for dBV. More...
 
struct  volt_unit
 Voltage, measured in volts. More...
 
struct  watt_reference
 Reference of 1 W, for dBW. More...
 
struct  watt_unit
 Power, measured in watts. More...
 

Concepts

concept  decibel_reference
 Concept for decibel reference tags.
 

Typedefs

template<typename Rep , typename Precision = std::ratio<1>>
using gain = quantity< decibel_unit, Rep, Precision >
 A logarithmic ratio with configurable representation and precision.
 
using decibels = gain< int64_t >
 Gain with 1 dB precision.
 
using centidecibels = gain< int64_t, std::centi >
 Gain with 0.01 dB precision.
 
using millidecibels = gain< int64_t, std::milli >
 Gain with 0.001 dB precision.
 
template<typename Rep , typename Precision = std::ratio<1>>
using dbm_level = level< milliwatt_reference, Rep, Precision >
 A level referenced to 1 mW.
 
template<typename Rep , typename Precision = std::ratio<1>>
using dbw_level = level< watt_reference, Rep, Precision >
 A level referenced to 1 W.
 
template<typename Rep , typename Precision = std::ratio<1>>
using dbv_level = level< volt_reference, Rep, Precision >
 A level referenced to 1 V.
 
template<typename Rep , typename Precision = std::ratio<1>>
using dbmv_level = level< millivolt_reference, Rep, Precision >
 A level referenced to 1 mV.
 
template<typename Rep , typename Precision = std::ratio<1>>
using dbuv_level = level< microvolt_reference, Rep, Precision >
 A level referenced to 1 µV.
 
using dbm = dbm_level< int64_t >
 Power level in dBm, with 1 dB precision.
 
using centi_dbm = dbm_level< int64_t, std::centi >
 Power level in dBm, with 0.01 dB precision.
 
using dbw = dbw_level< int64_t >
 Power level in dBW, with 1 dB precision.
 
using dbv = dbv_level< int64_t >
 Voltage level in dBV, with 1 dB precision.
 
using dbmv = dbmv_level< int64_t >
 Voltage level in dBmV, with 1 dB precision.
 
using dbuv = dbuv_level< int64_t >
 Voltage level in dBµV, with 1 dB precision.
 
using centi_dbuv = dbuv_level< int64_t, std::centi >
 Voltage level in dBµV, with 0.01 dB precision.
 
template<typename Rep , typename Precision = std::ratio<1>>
using voltage = quantity< volt_unit, Rep, Precision >
 Voltage quantity with configurable representation and precision.
 
template<typename Rep , typename Precision = std::ratio<1>>
using current = quantity< ampere_unit, Rep, Precision >
 Current quantity with configurable representation and precision.
 
template<typename Rep , typename Precision = std::ratio<1>>
using resistance = quantity< ohm_unit, Rep, Precision >
 Resistance quantity with configurable representation and precision.
 
template<typename Rep , typename Precision = std::ratio<1>>
using power = quantity< watt_unit, Rep, Precision >
 Power quantity with configurable representation and precision.
 
template<typename Rep , typename Precision = std::ratio<1>>
using charge = quantity< coulomb_unit, Rep, Precision >
 Charge quantity with configurable representation and precision.
 
template<typename Rep , typename Precision = std::ratio<1>>
using energy = quantity< joule_unit, Rep, Precision >
 Energy quantity with configurable representation and precision.
 
template<typename Rep , typename Precision = std::ratio<1>>
using capacitance = quantity< farad_unit, Rep, Precision >
 Capacitance quantity with configurable representation and precision.
 
template<typename Rep , typename Precision = std::ratio<1>>
using inductance = quantity< henry_unit, Rep, Precision >
 Inductance quantity with configurable representation and precision.
 
using microvolts = voltage< int64_t, std::micro >
 Voltage with 1 µV precision.
 
using millivolts = voltage< int64_t, std::milli >
 Voltage with 1 mV precision.
 
using volts = voltage< int64_t >
 Voltage with 1 V precision.
 
using kilovolts = voltage< int64_t, std::kilo >
 Voltage with 1 kV precision.
 
using microamperes = current< int64_t, std::micro >
 Current with 1 µA precision.
 
using milliamperes = current< int64_t, std::milli >
 Current with 1 mA precision.
 
using amperes = current< int64_t >
 Current with 1 A precision.
 
using microamps = microamperes
 Shorthand for microamperes.
 
using milliamps = milliamperes
 Shorthand for milliamperes.
 
using amps = amperes
 Shorthand for amperes.
 
using milliohms = resistance< int64_t, std::milli >
 Resistance with 1 mΩ precision.
 
using ohms = resistance< int64_t >
 Resistance with 1 Ω precision.
 
using kiloohms = resistance< int64_t, std::kilo >
 Resistance with 1 kΩ precision.
 
using megaohms = resistance< int64_t, std::mega >
 Resistance with 1 MΩ precision.
 
using gigaohms = resistance< int64_t, std::giga >
 Resistance with 1 GΩ precision.
 
using microwatts = power< int64_t, std::micro >
 Power with 1 µW precision.
 
using milliwatts = power< int64_t, std::milli >
 Power with 1 mW precision.
 
using watts = power< int64_t >
 Power with 1 W precision.
 
using kilowatts = power< int64_t, std::kilo >
 Power with 1 kW precision.
 
using megawatts = power< int64_t, std::mega >
 Power with 1 MW precision.
 
using gigawatts = power< int64_t, std::giga >
 Power with 1 GW precision.
 
using microcoulombs = charge< int64_t, std::micro >
 Charge with 1 µC precision.
 
using millicoulombs = charge< int64_t, std::milli >
 Charge with 1 mC precision.
 
using coulombs = charge< int64_t >
 Charge with 1 C precision.
 
using milliampere_hours = charge< int64_t, std::ratio< 18, 5 > >
 Charge with 1 mAh (3.6 C) precision.
 
using ampere_hours = charge< int64_t, std::ratio< 3600 > >
 Charge with 1 Ah (3600 C) precision.
 
using millijoules = energy< int64_t, std::milli >
 Energy with 1 mJ precision.
 
using joules = energy< int64_t >
 Energy with 1 J precision.
 
using kilojoules = energy< int64_t, std::kilo >
 Energy with 1 kJ precision.
 
using megajoules = energy< int64_t, std::mega >
 Energy with 1 MJ precision.
 
using watt_hours = energy< int64_t, std::ratio< 3600 > >
 Energy with 1 Wh (3600 J) precision.
 
using kilowatt_hours = energy< int64_t, std::ratio< 3600000 > >
 Energy with 1 kWh (3,600,000 J) precision.
 
using picofarads = capacitance< int64_t, std::pico >
 Capacitance with 1 pF precision.
 
using nanofarads = capacitance< int64_t, std::nano >
 Capacitance with 1 nF precision.
 
using microfarads = capacitance< int64_t, std::micro >
 Capacitance with 1 µF precision.
 
using millifarads = capacitance< int64_t, std::milli >
 Capacitance with 1 mF precision.
 
using farads = capacitance< int64_t >
 Capacitance with 1 F precision.
 
using nanohenries = inductance< int64_t, std::nano >
 Inductance with 1 nH precision.
 
using microhenries = inductance< int64_t, std::micro >
 Inductance with 1 µH precision.
 
using millihenries = inductance< int64_t, std::milli >
 Inductance with 1 mH precision.
 
using henries = inductance< int64_t >
 Inductance with 1 H precision.
 

Functions

template<typename ToLevel , typename Reference , typename Rep , typename Precision >
requires (!std::is_same_v<typename ToLevel::reference, Reference>) || detail::_quantity_cast_requirements<gain<Rep, Precision>, typename ToLevel::offset>
constexpr ToLevel level_cast (const level< Reference, Rep, Precision > &l)
 Converts a level to a different precision or representation.
 
template<typename ToLevel , typename Reference , typename Rep , typename Precision >
constexpr ToLevel floor (const level< Reference, Rep, Precision > &l)
 Converts a level to the target type, rounding toward negative infinity.
 
template<typename ToLevel , typename Reference , typename Rep , typename Precision >
constexpr ToLevel ceil (const level< Reference, Rep, Precision > &l)
 Converts a level to the target type, rounding toward positive infinity.
 
template<typename ToLevel , typename Reference , typename Rep , typename Precision >
constexpr ToLevel trunc (const level< Reference, Rep, Precision > &l)
 Converts a level to the target type, rounding toward zero (as level_cast does).
 
template<typename ToLevel , typename Reference , typename Rep , typename Precision >
constexpr ToLevel round (const level< Reference, Rep, Precision > &l)
 Converts a level to the target type, rounding to nearest (ties to even).
 
template<typename Reference , typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 >
constexpr auto operator+ (const level< Reference, Rep1, Precision1 > &l, const quantity< decibel_unit, Rep2, Precision2 > &g)
 Applies a gain to a level.
 
template<typename Reference , typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 >
constexpr auto operator+ (const quantity< decibel_unit, Rep2, Precision2 > &g, const level< Reference, Rep1, Precision1 > &l)
 Applies a gain to a level.
 
template<typename Reference , typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 >
constexpr auto operator- (const level< Reference, Rep1, Precision1 > &l, const quantity< decibel_unit, Rep2, Precision2 > &g)
 Applies a loss to a level.
 
template<typename Reference , typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 >
constexpr auto operator- (const level< Reference, Rep1, Precision1 > &a, const level< Reference, Rep2, Precision2 > &b)
 The difference between two levels is a gain.
 
template<typename Reference , typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 >
constexpr bool operator== (const level< Reference, Rep1, Precision1 > &a, const level< Reference, Rep2, Precision2 > &b)
 
template<typename Reference , typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 >
requires std::three_way_comparable<std::common_type_t<Rep1, Rep2>>
constexpr auto operator<=> (const level< Reference, Rep1, Precision1 > &a, const level< Reference, Rep2, Precision2 > &b)
 
template<typename Reference , typename Rep , typename Precision >
auto to_linear (const level< Reference, Rep, Precision > &l)
 Converts a level to the equivalent linear quantity.
 
template<typename ToLevel , typename Unit , typename Rep , typename Precision >
ToLevel to_level (const quantity< Unit, Rep, Precision > &q)
 Converts a linear quantity to a level.
 
template<typename Rep , typename Precision >
double power_ratio (const quantity< decibel_unit, Rep, Precision > &g)
 The linear power ratio a gain represents (10^(dB/10)).
 
template<typename Rep , typename Precision >
double amplitude_ratio (const quantity< decibel_unit, Rep, Precision > &g)
 The linear amplitude ratio a gain represents (10^(dB/20)).
 
gain< double > power_gain (double ratio)
 The gain corresponding to a linear power ratio (10*log10(ratio)).
 
gain< double > amplitude_gain (double ratio)
 The gain corresponding to a linear amplitude ratio (20*log10(ratio)).
 
template<typename Reference , typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 >
requires is_power_reference_v<Reference>
auto add_powers (const level< Reference, Rep1, Precision1 > &a, const level< Reference, Rep2, Precision2 > &b)
 Combines the powers of two uncorrelated signals.
 
template<typename Rep , typename Precision >
requires _is_decimal_precision<typename Precision::type>
std::string to_string (const quantity< decibel_unit, Rep, Precision > &g)
 Converts a gain to a string, e.g.
 
template<typename Rep , typename Precision >
requires _is_decimal_precision<typename Precision::type>
std::string to_string (const quantity< decibel_unit, Rep, Precision > &g, base_unit_t)
 Converts a gain to a string in decibels, e.g.
 
template<typename Rep , typename Precision >
requires _is_decimal_precision<typename Precision::type>
std::string to_string (const quantity< decibel_unit, Rep, Precision > &g, scaled_t)
 Converts a gain to a string in decibels, e.g.
 
template<typename Reference , typename Rep , typename Precision >
requires _is_decimal_precision<typename Precision::type>
std::string to_string (const level< Reference, Rep, Precision > &l)
 Converts a level to a string, e.g.
 
template<typename Reference , typename Rep , typename Precision >
requires _is_decimal_precision<typename Precision::type>
std::string to_string (const level< Reference, Rep, Precision > &l, base_unit_t)
 Converts a level to a string against its reference, e.g.
 
template<typename Reference , typename Rep , typename Precision >
requires _is_decimal_precision<typename Precision::type>
std::string to_string (const level< Reference, Rep, Precision > &l, scaled_t)
 Converts a level to a string against its reference, e.g.
 
template<typename ToQuantity , typename Unit , typename Rep , typename Precision >
requires (!std::is_same_v<typename ToQuantity::unit, Unit>) || detail::_quantity_cast_requirements<quantity<Unit, Rep, Precision>, ToQuantity>
constexpr ToQuantity quantity_cast (const quantity< Unit, Rep, Precision > &q)
 Converts a quantity to a different precision or representation.
 
template<typename ToQuantity , typename Unit , typename Rep , typename Precision >
constexpr ToQuantity floor (const quantity< Unit, Rep, Precision > &q)
 Converts a quantity to the target type, rounding toward negative infinity.
 
template<typename ToQuantity , typename Unit , typename Rep , typename Precision >
constexpr ToQuantity ceil (const quantity< Unit, Rep, Precision > &q)
 Converts a quantity to the target type, rounding toward positive infinity.
 
template<typename ToQuantity , typename Unit , typename Rep , typename Precision >
constexpr ToQuantity trunc (const quantity< Unit, Rep, Precision > &q)
 Converts a quantity to the target type, rounding toward zero.
 
template<typename ToQuantity , typename Unit , typename Rep , typename Precision >
constexpr ToQuantity round (const quantity< Unit, Rep, Precision > &q)
 Converts a quantity to the target type, rounding to nearest (ties to even).
 
template<typename Unit , typename Rep , typename Precision >
constexpr quantity< Unit, Rep, Precision > abs (const quantity< Unit, Rep, Precision > &q)
 Returns the absolute value of a quantity.
 
template<typename Unit , typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 >
constexpr auto operator+ (const quantity< Unit, Rep1, Precision1 > &lhs, const quantity< Unit, Rep2, Precision2 > &rhs) -> std::common_type_t< quantity< Unit, Rep1, Precision1 >, quantity< Unit, Rep2, Precision2 > >
 Returns the sum of two quantities of the same unit.
 
template<typename Unit , typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 >
constexpr auto operator- (const quantity< Unit, Rep1, Precision1 > &lhs, const quantity< Unit, Rep2, Precision2 > &rhs) -> std::common_type_t< quantity< Unit, Rep1, Precision1 >, quantity< Unit, Rep2, Precision2 > >
 Returns the difference of two quantities of the same unit.
 
template<typename Unit , typename Rep1 , typename Precision , typename Rep2 >
requires not_quantity<Rep2> && std::convertible_to<const Rep2&, std::common_type_t<Rep1, Rep2>>
constexpr auto operator* (const quantity< Unit, Rep1, Precision > &q, const Rep2 &r) -> quantity< Unit, std::common_type_t< Rep1, Rep2 >, Precision >
 Multiplies a quantity by a scalar.
 
template<typename Unit , typename Rep1 , typename Rep2 , typename Precision >
requires not_quantity<Rep1> && std::convertible_to<const Rep1&, std::common_type_t<Rep1, Rep2>>
constexpr auto operator* (const Rep1 &r, const quantity< Unit, Rep2, Precision > &q) -> quantity< Unit, std::common_type_t< Rep1, Rep2 >, Precision >
 Multiplies a scalar by a quantity.
 
template<typename Unit , typename Rep1 , typename Precision , typename Rep2 >
requires not_quantity<Rep2> && std::convertible_to<const Rep2&, std::common_type_t<Rep1, Rep2>>
constexpr auto operator/ (const quantity< Unit, Rep1, Precision > &q, const Rep2 &s) -> quantity< Unit, std::common_type_t< Rep1, Rep2 >, Precision >
 Divides a quantity by a scalar.
 
template<typename Unit , typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 >
constexpr auto operator/ (const quantity< Unit, Rep1, Precision1 > &lhs, const quantity< Unit, Rep2, Precision2 > &rhs) -> std::common_type_t< Rep1, Rep2 >
 Divides two quantities of the same unit, returning a scalar.
 
template<typename Unit , typename Rep1 , typename Precision , typename Rep2 >
requires not_quantity<Rep2> && std::convertible_to<const Rep2&, std::common_type_t<Rep1, Rep2>> && (!treat_as_inexact_v<Rep1> && !treat_as_inexact_v<Rep2>)
constexpr auto operator% (const quantity< Unit, Rep1, Precision > &q, const Rep2 &s) -> quantity< Unit, std::common_type_t< Rep1, Rep2 >, Precision >
 Returns the remainder of dividing a quantity by a scalar.
 
template<typename Unit , typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 >
requires (!treat_as_inexact_v<Rep1> && !treat_as_inexact_v<Rep2>)
constexpr auto operator% (const quantity< Unit, Rep1, Precision1 > &lhs, const quantity< Unit, Rep2, Precision2 > &rhs) -> std::common_type_t< quantity< Unit, Rep1, Precision1 >, quantity< Unit, Rep2, Precision2 > >
 Returns the remainder of dividing two quantities of the same unit.
 
template<typename Unit , typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 >
constexpr bool operator== (const quantity< Unit, Rep1, Precision1 > &lhs, const quantity< Unit, Rep2, Precision2 > &rhs)
 
template<typename Unit , typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 >
requires std::three_way_comparable<std::common_type_t<Rep1, Rep2>>
constexpr auto operator<=> (const quantity< Unit, Rep1, Precision1 > &lhs, const quantity< Unit, Rep2, Precision2 > &rhs)
 
template<typename R1 , typename P1 , typename R2 , typename P2 >
constexpr auto operator* (const quantity< ampere_unit, R1, P1 > &i, const quantity< ohm_unit, R2, P2 > &r)
 Ohm's law: current x resistance = voltage.
 
template<typename R1 , typename P1 , typename R2 , typename P2 >
constexpr auto operator* (const quantity< ohm_unit, R1, P1 > &r, const quantity< ampere_unit, R2, P2 > &i)
 Ohm's law: resistance x current = voltage.
 
template<typename R1 , typename P1 , typename R2 , typename P2 >
constexpr auto operator/ (const quantity< volt_unit, R1, P1 > &v, const quantity< ohm_unit, R2, P2 > &r)
 Ohm's law: voltage / resistance = current.
 
template<typename R1 , typename P1 , typename R2 , typename P2 >
constexpr auto operator/ (const quantity< volt_unit, R1, P1 > &v, const quantity< ampere_unit, R2, P2 > &i)
 Ohm's law: voltage / current = resistance.
 
template<typename R1 , typename P1 , typename R2 , typename P2 >
constexpr auto operator* (const quantity< volt_unit, R1, P1 > &v, const quantity< ampere_unit, R2, P2 > &i)
 Power law: voltage x current = power.
 
template<typename R1 , typename P1 , typename R2 , typename P2 >
constexpr auto operator* (const quantity< ampere_unit, R1, P1 > &i, const quantity< volt_unit, R2, P2 > &v)
 Power law: current x voltage = power.
 
template<typename R1 , typename P1 , typename R2 , typename P2 >
constexpr auto operator/ (const quantity< watt_unit, R1, P1 > &p, const quantity< volt_unit, R2, P2 > &v)
 Power law: power / voltage = current.
 
template<typename R1 , typename P1 , typename R2 , typename P2 >
constexpr auto operator/ (const quantity< watt_unit, R1, P1 > &p, const quantity< ampere_unit, R2, P2 > &i)
 Power law: power / current = voltage.
 
template<typename R1 , typename P1 , duration_like D>
constexpr auto operator* (const quantity< ampere_unit, R1, P1 > &i, const D &t)
 Charge: current x time = charge.
 
template<duration_like D, typename R1 , typename P1 >
constexpr auto operator* (const D &t, const quantity< ampere_unit, R1, P1 > &i)
 Charge: time x current = charge.
 
template<typename R1 , typename P1 , duration_like D>
constexpr auto operator/ (const quantity< coulomb_unit, R1, P1 > &q, const D &t)
 Charge: charge / time = current.
 
template<typename R1 , typename P1 , typename R2 , typename P2 >
constexpr auto operator/ (const quantity< coulomb_unit, R1, P1 > &q, const quantity< ampere_unit, R2, P2 > &i)
 Charge: charge / current = time.
 
template<typename R1 , typename P1 , duration_like D>
constexpr auto operator* (const quantity< watt_unit, R1, P1 > &p, const D &t)
 Energy: power x time = energy.
 
template<duration_like D, typename R1 , typename P1 >
constexpr auto operator* (const D &t, const quantity< watt_unit, R1, P1 > &p)
 Energy: time x power = energy.
 
template<typename R1 , typename P1 , duration_like D>
constexpr auto operator/ (const quantity< joule_unit, R1, P1 > &e, const D &t)
 Energy: energy / time = power.
 
template<typename R1 , typename P1 , typename R2 , typename P2 >
constexpr auto operator/ (const quantity< joule_unit, R1, P1 > &e, const quantity< watt_unit, R2, P2 > &p)
 Energy: energy / power = time.
 
template<typename R1 , typename P1 , typename R2 , typename P2 >
constexpr auto operator/ (const quantity< joule_unit, R1, P1 > &e, const quantity< volt_unit, R2, P2 > &v)
 Energy: energy / voltage = charge.
 
template<typename R1 , typename P1 , typename R2 , typename P2 >
constexpr auto operator/ (const quantity< joule_unit, R1, P1 > &e, const quantity< coulomb_unit, R2, P2 > &q)
 Energy: energy / charge = voltage.
 
template<typename R1 , typename P1 , typename R2 , typename P2 >
constexpr auto operator* (const quantity< farad_unit, R1, P1 > &c, const quantity< volt_unit, R2, P2 > &v)
 Capacitance: capacitance x voltage = charge.
 
template<typename R1 , typename P1 , typename R2 , typename P2 >
constexpr auto operator* (const quantity< volt_unit, R1, P1 > &v, const quantity< farad_unit, R2, P2 > &c)
 Capacitance: voltage x capacitance = charge.
 
template<typename R1 , typename P1 , typename R2 , typename P2 >
constexpr auto operator/ (const quantity< coulomb_unit, R1, P1 > &q, const quantity< volt_unit, R2, P2 > &v)
 Capacitance: charge / voltage = capacitance.
 
template<typename R1 , typename P1 , typename R2 , typename P2 >
constexpr auto operator/ (const quantity< coulomb_unit, R1, P1 > &q, const quantity< farad_unit, R2, P2 > &c)
 Capacitance: charge / capacitance = voltage.
 
template<typename R1 , typename P1 , typename R2 , typename P2 >
constexpr auto operator* (const quantity< ohm_unit, R1, P1 > &r, const quantity< farad_unit, R2, P2 > &c)
 RC time constant: resistance x capacitance = time.
 
template<typename R1 , typename P1 , typename R2 , typename P2 >
constexpr auto operator* (const quantity< farad_unit, R1, P1 > &c, const quantity< ohm_unit, R2, P2 > &r)
 RC time constant: capacitance x resistance = time.
 
template<typename R1 , typename P1 , typename R2 , typename P2 >
constexpr auto operator/ (const quantity< henry_unit, R1, P1 > &l, const quantity< ohm_unit, R2, P2 > &r)
 L/R time constant: inductance / resistance = time.
 
template<typename Unit , typename Rep , typename Precision >
requires _has_suffix<Unit, typename Precision::type>
std::string to_string (const quantity< Unit, Rep, Precision > &q)
 Converts a quantity to a string with its unit suffix.
 
template<typename Unit , typename Rep , typename Precision >
requires _has_suffix<Unit, typename Precision::type>
std::string to_string (const quantity< Unit, Rep, Precision > &q, base_unit_t)
 Converts a quantity to a string in its base unit.
 
template<typename Unit , typename Rep , typename Precision >
requires _has_suffix<Unit, typename Precision::type>
std::string to_string (const quantity< Unit, Rep, Precision > &q, scaled_t)
 Converts a quantity to a string with an SI prefix suited to its magnitude.
 

Variables

template<typename Reference >
constexpr bool is_power_reference_v = false
 True if the reference measures a power quantity (10*log10).
 
template<decibel_reference Reference>
constexpr bool is_power_reference_v< Reference > = Reference::factor == 10
 
template<typename Reference >
constexpr bool is_field_reference_v = false
 True if the reference measures a field quantity (20*log10).
 
template<decibel_reference Reference>
constexpr bool is_field_reference_v< Reference > = Reference::factor == 20
 
template<typename T >
constexpr bool is_level_v = is_level<T>::value
 
template<typename T >
constexpr bool is_quantity_v = is_quantity<T>::value
 

Detailed Description

Electrical unit types and utilities.

This library provides type-safe handling of the principal electrical quantities - voltage, current, resistance, power, charge, energy, capacitance and inductance - with support for multiple precisions (e.g. millivolts, microamperes, kiloohms), following the design of std::chrono::duration.

Basic Usage

The library provides standard integer-based types for each quantity:

using namespace quanta::electro;
using namespace quanta::electro_literals;
millivolts vbat{3300};
milliamperes load{150};
kiloohms pullup{10};
auto usb = 5_V;
auto shunt = 50_mOhm;
current< int64_t, std::milli > milliamperes
Current with 1 mA precision.
Definition electro.hpp:930
voltage< int64_t, std::milli > millivolts
Voltage with 1 mV precision.
Definition electro.hpp:921
resistance< int64_t, std::kilo > kiloohms
Resistance with 1 kΩ precision.
Definition electro.hpp:945
Electrical unit types and utilities.
Definition decibel.hpp:61

Cross-Quantity Arithmetic

Quantities of different kinds combine according to the laws of circuit theory, producing results in the correct unit with the correct precision:

// Ohm's law: V = I x R
auto v = milliamperes(100) * kiloohms(2); // 200 V
auto i = millivolts(5000) / ohms(100); // 50 mA
auto r = volts(12) / amperes(3); // 4 Ω
// Power: P = V x I
auto p = volts(12) * amperes(2); // 24 W
auto i2 = watts(60) / volts(12); // 5 A
// Charge and energy via std::chrono durations
auto q = milliamperes(100) * std::chrono::hours(2); // 200 mAh
auto e = watts(100) * std::chrono::hours(5); // 500 Wh
auto runtime = ampere_hours(2) / amperes(1); // 2 h
// RC and L/R time constants
auto tau = kiloohms(47) * microfarads(10); // 470 ms
auto lr = millihenries(10) / ohms(2); // 5 ms
voltage< int64_t > volts
Voltage with 1 V precision.
Definition electro.hpp:923
power< int64_t > watts
Power with 1 W precision.
Definition electro.hpp:956
capacitance< int64_t, std::micro > microfarads
Capacitance with 1 µF precision.
Definition electro.hpp:993
inductance< int64_t, std::milli > millihenries
Inductance with 1 mH precision.
Definition electro.hpp:1004
charge< int64_t, std::ratio< 3600 > > ampere_hours
Charge with 1 Ah (3600 C) precision.
Definition electro.hpp:973
current< int64_t > amperes
Current with 1 A precision.
Definition electro.hpp:932
resistance< int64_t > ohms
Resistance with 1 Ω precision.
Definition electro.hpp:943

Formatting

to_string() and std::format show a quantity in its own unit by default, whatever the format spec: {} prints the exact count and {:.1f} the count as a double, each followed by the precision's suffix. A single leading marker letter in the spec, or a tag argument to to_string(), opts into a different unit:

std::format("{}", millivolts(3300)); // "3300mV" own unit
std::format("{:.1f}", millivolts(3300)); // "3300.0mV" own unit
std::format("{:b}", millivolts(3300)); // "3.3V" base unit
std::format("{:s.2f}", ohms(4700)); // "4.70kΩ" scaled
to_string(milliampere_hours(200), base_unit); // "0.2Ah"
to_string(ohms(4700), scaled); // "4.7kΩ"
charge< int64_t, std::ratio< 18, 5 > > milliampere_hours
Charge with 1 mAh (3.6 C) precision.
Definition electro.hpp:971
std::string to_string(const quantity< decibel_unit, Rep, Precision > &g)
Converts a gain to a string, e.g.
Definition decibel.hpp:733

Integer vs Floating-Point

  • Integer types (default): Exact arithmetic, support modulo operations, preferred for embedded and digital systems. Note that cross-quantity division truncates (volts(5) / ohms(3) is 1 A); use a finer precision (millivolts(5000) / ohms(3) is 1666 mA) or a floating-point representation when the quotient may be fractional.
  • Floating-point types: Fractional precision, e.g. voltage<double> or current<double, std::milli>.

Conversions between precisions are implicit when lossless and require an explicit cast when lossy, exactly as with std::chrono::duration.

Typedef Documentation

◆ centidecibels

using quanta::electro::centidecibels = typedef gain<int64_t, std::centi>

Gain with 0.01 dB precision.

Definition at line 85 of file decibel.hpp.

◆ decibels

using quanta::electro::decibels = typedef gain<int64_t>

Gain with 1 dB precision.

Definition at line 83 of file decibel.hpp.

◆ gain

template<typename Rep , typename Precision = std::ratio<1>>
using quanta::electro::gain = typedef quantity<decibel_unit, Rep, Precision>

A logarithmic ratio with configurable representation and precision.

Definition at line 80 of file decibel.hpp.

◆ millidecibels

using quanta::electro::millidecibels = typedef gain<int64_t, std::milli>

Gain with 0.001 dB precision.

Definition at line 87 of file decibel.hpp.

Function Documentation

◆ abs()

template<typename Unit , typename Rep , typename Precision >
constexpr quantity< Unit, Rep, Precision > quanta::electro::abs ( const quantity< Unit, Rep, Precision > &  q)
constexpr

Returns the absolute value of a quantity.

Template Parameters
UnitThe unit tag type.
RepRepresentation type.
PrecisionPrecision type.
Parameters
qThe quantity.
Returns
The absolute value of the quantity.

Definition at line 527 of file electro.hpp.

◆ add_powers()

template<typename Reference , typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 >
requires is_power_reference_v<Reference>
auto quanta::electro::add_powers ( const level< Reference, Rep1, Precision1 > &  a,
const level< Reference, Rep2, Precision2 > &  b 
)
inline

Combines the powers of two uncorrelated signals.

This is what "adding" two levels physically means, and it is deliberately not operator+: 10 dBm combined with 10 dBm is 13.01 dBm, not 20 dBm.

Only available for power references. For a field reference such as dBµV, summing the linear amplitudes would model coherent, in-phase addition instead, which is a different operation with a different answer.

add_powers(centi_dbm(1000), centi_dbm(1000)); // 13.01 dBm
dbm_level< int64_t, std::centi > centi_dbm
Power level in dBm, with 0.01 dB precision.
Definition decibel.hpp:627
auto add_powers(const level< Reference, Rep1, Precision1 > &a, const level< Reference, Rep2, Precision2 > &b)
Combines the powers of two uncorrelated signals.
Definition decibel.hpp:589
Note
Not constexpr: requires std::pow and std::log10.

Definition at line 589 of file decibel.hpp.

References to_linear().

◆ amplitude_gain()

gain< double > quanta::electro::amplitude_gain ( double  ratio)
inline

The gain corresponding to a linear amplitude ratio (20*log10(ratio)).

Definition at line 566 of file decibel.hpp.

◆ amplitude_ratio()

template<typename Rep , typename Precision >
double quanta::electro::amplitude_ratio ( const quantity< decibel_unit, Rep, Precision > &  g)
inline

The linear amplitude ratio a gain represents (10^(dB/20)).

amplitude_ratio(6_dB); // ~1.995 (a doubling of voltage)
double amplitude_ratio(const quantity< decibel_unit, Rep, Precision > &g)
The linear amplitude ratio a gain represents (10^(dB/20)).
Definition decibel.hpp:555
Note
Not constexpr: requires std::pow.

Definition at line 555 of file decibel.hpp.

◆ ceil() [1/2]

template<typename ToLevel , typename Reference , typename Rep , typename Precision >
constexpr ToLevel quanta::electro::ceil ( const level< Reference, Rep, Precision > &  l)
constexpr

Converts a level to the target type, rounding toward positive infinity.

As with the cast, the result is undefined if it does not fit the target rep.

Definition at line 340 of file decibel.hpp.

References quanta::electro::level< Reference, Rep, Precision >::offset_from_reference().

◆ ceil() [2/2]

template<typename ToQuantity , typename Unit , typename Rep , typename Precision >
constexpr ToQuantity quanta::electro::ceil ( const quantity< Unit, Rep, Precision > &  q)
constexpr

Converts a quantity to the target type, rounding toward positive infinity.

As with the cast, the result is undefined if it does not fit the target rep.

Template Parameters
ToQuantityThe target quantity type.
UnitThe unit tag type.
RepSource representation type.
PrecisionSource precision.
Parameters
qThe quantity to convert.
Returns
The converted quantity, rounded toward positive infinity.
using namespace quanta::electro;
millivolts mv{1500};
auto v = ceil<volts>(mv); // 2 V (rounded up from 1.5)

Definition at line 465 of file electro.hpp.

◆ floor() [1/2]

template<typename ToLevel , typename Reference , typename Rep , typename Precision >
constexpr ToLevel quanta::electro::floor ( const level< Reference, Rep, Precision > &  l)
constexpr

Converts a level to the target type, rounding toward negative infinity.

As with the cast, the result is undefined if it does not fit the target rep.

Definition at line 329 of file decibel.hpp.

References quanta::electro::level< Reference, Rep, Precision >::offset_from_reference().

◆ floor() [2/2]

template<typename ToQuantity , typename Unit , typename Rep , typename Precision >
constexpr ToQuantity quanta::electro::floor ( const quantity< Unit, Rep, Precision > &  q)
constexpr

Converts a quantity to the target type, rounding toward negative infinity.

As with the cast, the result is undefined if it does not fit the target rep.

Template Parameters
ToQuantityThe target quantity type.
UnitThe unit tag type.
RepSource representation type.
PrecisionSource precision.
Parameters
qThe quantity to convert.
Returns
The converted quantity, rounded toward negative infinity.
using namespace quanta::electro;
millivolts mv{1500};
auto v = floor<volts>(mv); // 1 V (rounded down from 1.5)

Definition at line 441 of file electro.hpp.

◆ level_cast()

template<typename ToLevel , typename Reference , typename Rep , typename Precision >
requires (!std::is_same_v<typename ToLevel::reference, Reference>) || detail::_quantity_cast_requirements<gain<Rep, Precision>, typename ToLevel::offset>
constexpr ToLevel quanta::electro::level_cast ( const level< Reference, Rep, Precision > &  l)
constexpr

Converts a level to a different precision or representation.

Template Parameters
ToLevelThe target level type (must have the same reference).

Definition at line 315 of file decibel.hpp.

References quanta::electro::level< Reference, Rep, Precision >::offset_from_reference().

◆ operator%() [1/2]

template<typename Unit , typename Rep1 , typename Precision , typename Rep2 >
requires not_quantity<Rep2> && std::convertible_to<const Rep2&, std::common_type_t<Rep1, Rep2>> && (!treat_as_inexact_v<Rep1> && !treat_as_inexact_v<Rep2>)
constexpr auto quanta::electro::operator% ( const quantity< Unit, Rep1, Precision > &  q,
const Rep2 &  s 
) -> quantity<Unit, std::common_type_t<Rep1, Rep2>, Precision>
constexpr

Returns the remainder of dividing a quantity by a scalar.

Definition at line 589 of file electro.hpp.

◆ operator%() [2/2]

template<typename Unit , typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 >
requires (!treat_as_inexact_v<Rep1> && !treat_as_inexact_v<Rep2>)
constexpr auto quanta::electro::operator% ( const quantity< Unit, Rep1, Precision1 > &  lhs,
const quantity< Unit, Rep2, Precision2 > &  rhs 
) -> std::common_type_t<quantity<Unit, Rep1, Precision1>, quantity<Unit, Rep2, Precision2>>
constexpr

Returns the remainder of dividing two quantities of the same unit.

Definition at line 598 of file electro.hpp.

◆ operator*() [1/2]

template<typename Unit , typename Rep1 , typename Precision , typename Rep2 >
requires not_quantity<Rep2> && std::convertible_to<const Rep2&, std::common_type_t<Rep1, Rep2>>
constexpr auto quanta::electro::operator* ( const quantity< Unit, Rep1, Precision > &  q,
const Rep2 &  r 
) -> quantity<Unit, std::common_type_t<Rep1, Rep2>, Precision>
constexpr

Multiplies a quantity by a scalar.

Definition at line 554 of file electro.hpp.

◆ operator*() [2/2]

template<typename Unit , typename Rep1 , typename Rep2 , typename Precision >
requires not_quantity<Rep1> && std::convertible_to<const Rep1&, std::common_type_t<Rep1, Rep2>>
constexpr auto quanta::electro::operator* ( const Rep1 &  r,
const quantity< Unit, Rep2, Precision > &  q 
) -> quantity<Unit, std::common_type_t<Rep1, Rep2>, Precision>
constexpr

Multiplies a scalar by a quantity.

Definition at line 563 of file electro.hpp.

◆ operator+() [1/3]

template<typename Reference , typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 >
constexpr auto quanta::electro::operator+ ( const level< Reference, Rep1, Precision1 > &  l,
const quantity< decibel_unit, Rep2, Precision2 > &  g 
)
constexpr

Applies a gain to a level.

Definition at line 375 of file decibel.hpp.

References quanta::electro::level< Reference, Rep, Precision >::offset_from_reference().

◆ operator+() [2/3]

template<typename Reference , typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 >
constexpr auto quanta::electro::operator+ ( const quantity< decibel_unit, Rep2, Precision2 > &  g,
const level< Reference, Rep1, Precision1 > &  l 
)
constexpr

Applies a gain to a level.

Definition at line 384 of file decibel.hpp.

◆ operator+() [3/3]

template<typename Unit , typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 >
constexpr auto quanta::electro::operator+ ( const quantity< Unit, Rep1, Precision1 > &  lhs,
const quantity< Unit, Rep2, Precision2 > &  rhs 
) -> std::common_type_t<quantity<Unit, Rep1, Precision1>, quantity<Unit, Rep2, Precision2>>
constexpr

Returns the sum of two quantities of the same unit.

Definition at line 537 of file electro.hpp.

◆ operator-() [1/3]

template<typename Reference , typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 >
constexpr auto quanta::electro::operator- ( const level< Reference, Rep1, Precision1 > &  a,
const level< Reference, Rep2, Precision2 > &  b 
)
constexpr

The difference between two levels is a gain.

auto margin = -66_dBm - -100_dBm; // 34 dB

Definition at line 405 of file decibel.hpp.

References quanta::electro::level< Reference, Rep, Precision >::offset_from_reference().

◆ operator-() [2/3]

template<typename Reference , typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 >
constexpr auto quanta::electro::operator- ( const level< Reference, Rep1, Precision1 > &  l,
const quantity< decibel_unit, Rep2, Precision2 > &  g 
)
constexpr

Applies a loss to a level.

Definition at line 391 of file decibel.hpp.

References quanta::electro::level< Reference, Rep, Precision >::offset_from_reference().

◆ operator-() [3/3]

template<typename Unit , typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 >
constexpr auto quanta::electro::operator- ( const quantity< Unit, Rep1, Precision1 > &  lhs,
const quantity< Unit, Rep2, Precision2 > &  rhs 
) -> std::common_type_t<quantity<Unit, Rep1, Precision1>, quantity<Unit, Rep2, Precision2>>
constexpr

Returns the difference of two quantities of the same unit.

Definition at line 545 of file electro.hpp.

◆ operator/() [1/2]

template<typename Unit , typename Rep1 , typename Precision , typename Rep2 >
requires not_quantity<Rep2> && std::convertible_to<const Rep2&, std::common_type_t<Rep1, Rep2>>
constexpr auto quanta::electro::operator/ ( const quantity< Unit, Rep1, Precision > &  q,
const Rep2 &  s 
) -> quantity<Unit, std::common_type_t<Rep1, Rep2>, Precision>
constexpr

Divides a quantity by a scalar.

Definition at line 571 of file electro.hpp.

◆ operator/() [2/2]

template<typename Unit , typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 >
constexpr auto quanta::electro::operator/ ( const quantity< Unit, Rep1, Precision1 > &  lhs,
const quantity< Unit, Rep2, Precision2 > &  rhs 
) -> std::common_type_t<Rep1, Rep2>
constexpr

Divides two quantities of the same unit, returning a scalar.

Definition at line 579 of file electro.hpp.

References quanta::electro::quantity< Unit, Rep, Precision >::count().

◆ operator<=>() [1/2]

template<typename Reference , typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 >
requires std::three_way_comparable<std::common_type_t<Rep1, Rep2>>
constexpr auto quanta::electro::operator<=> ( const level< Reference, Rep1, Precision1 > &  a,
const level< Reference, Rep2, Precision2 > &  b 
)
constexpr

◆ operator<=>() [2/2]

template<typename Unit , typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 >
requires std::three_way_comparable<std::common_type_t<Rep1, Rep2>>
constexpr auto quanta::electro::operator<=> ( const quantity< Unit, Rep1, Precision1 > &  lhs,
const quantity< Unit, Rep2, Precision2 > &  rhs 
)
constexpr

◆ operator==() [1/2]

template<typename Reference , typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 >
constexpr bool quanta::electro::operator== ( const level< Reference, Rep1, Precision1 > &  a,
const level< Reference, Rep2, Precision2 > &  b 
)
constexpr

◆ operator==() [2/2]

template<typename Unit , typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 >
constexpr bool quanta::electro::operator== ( const quantity< Unit, Rep1, Precision1 > &  lhs,
const quantity< Unit, Rep2, Precision2 > &  rhs 
)
constexpr

◆ power_gain()

gain< double > quanta::electro::power_gain ( double  ratio)
inline

The gain corresponding to a linear power ratio (10*log10(ratio)).

Definition at line 560 of file decibel.hpp.

◆ power_ratio()

template<typename Rep , typename Precision >
double quanta::electro::power_ratio ( const quantity< decibel_unit, Rep, Precision > &  g)
inline

The linear power ratio a gain represents (10^(dB/10)).

power_ratio(3_dB); // ~1.995 (a doubling of power)
double power_ratio(const quantity< decibel_unit, Rep, Precision > &g)
The linear power ratio a gain represents (10^(dB/10)).
Definition decibel.hpp:541
Note
Not constexpr: requires std::pow.

Definition at line 541 of file decibel.hpp.

◆ quantity_cast()

template<typename ToQuantity , typename Unit , typename Rep , typename Precision >
requires (!std::is_same_v<typename ToQuantity::unit, Unit>) || detail::_quantity_cast_requirements<quantity<Unit, Rep, Precision>, ToQuantity>
constexpr ToQuantity quanta::electro::quantity_cast ( const quantity< Unit, Rep, Precision > &  q)
constexpr

Converts a quantity to a different precision or representation.

For integer-to-integer conversions, this function uses wider intermediate types (128-bit when available) to minimize overflow risk during ratio arithmetic.

Template Parameters
ToQuantityThe target quantity type (must have the same unit).
UnitThe unit tag type.
RepSource representation type.
PrecisionSource precision.
Parameters
qThe quantity to convert.
Returns
The converted quantity.

Definition at line 413 of file electro.hpp.

◆ round() [1/2]

template<typename ToLevel , typename Reference , typename Rep , typename Precision >
constexpr ToLevel quanta::electro::round ( const level< Reference, Rep, Precision > &  l)
constexpr

Converts a level to the target type, rounding to nearest (ties to even).

As with the cast, the result is undefined if it does not fit the target rep.

Definition at line 358 of file decibel.hpp.

References quanta::electro::level< Reference, Rep, Precision >::offset_from_reference().

◆ round() [2/2]

template<typename ToQuantity , typename Unit , typename Rep , typename Precision >
constexpr ToQuantity quanta::electro::round ( const quantity< Unit, Rep, Precision > &  q)
constexpr

Converts a quantity to the target type, rounding to nearest (ties to even).

As with the cast, the result is undefined if it does not fit the target rep.

Template Parameters
ToQuantityThe target quantity type.
UnitThe unit tag type.
RepSource representation type.
PrecisionSource precision.
Parameters
qThe quantity to convert.
Returns
The converted quantity, rounded to nearest.
using namespace quanta::electro;
millivolts mv{1500};
auto v = round<volts>(mv); // 2 V (rounded to even)

Definition at line 512 of file electro.hpp.

◆ to_level()

template<typename ToLevel , typename Unit , typename Rep , typename Precision >
ToLevel quanta::electro::to_level ( const quantity< Unit, Rep, Precision > &  q)
inline

Converts a linear quantity to a level.

The quantity's unit must match the target level's reference unit. Values are rounded to nearest at the target precision, rather than truncated.

A zero quantity has no finite logarithm. When ToLevel's rep is floating-point it maps to a level of -infinity (e.g. "-infdBm"); otherwise it maps to ToLevel::min(), which is only a sentinel for "no level", not a real one: arithmetic on it (such as adding a gain) overflows. A negative quantity has no logarithm at all; in a debug build this asserts, and otherwise returns the same as for zero. A NaN quantity maps to a NaN level when ToLevel's rep is floating-point; for an integral rep it has no representable level, so it asserts in a debug build and otherwise returns ToLevel::min(). For an integral rep, a level beyond the rep's range (including that of an infinite quantity) saturates at ToLevel::max() or ToLevel::min().

to_level<dbm>(milliwatts(1)); // 0 dBm
to_level<dbm>(watts(1)); // 30 dBm
to_level<dbuv>(volts(1)); // 120 dBµV (field reference: 20*log10)
power< int64_t, std::milli > milliwatts
Power with 1 mW precision.
Definition electro.hpp:954
Note
Not constexpr: requires std::log10.

Definition at line 508 of file decibel.hpp.

References quanta::electro::quantity< Unit, Rep, Precision >::count().

◆ to_linear()

template<typename Reference , typename Rep , typename Precision >
auto quanta::electro::to_linear ( const level< Reference, Rep, Precision > &  l)
inline

Converts a level to the equivalent linear quantity.

The result is expressed at the reference's own precision, so to_linear() of a dBm level yields milliwatts and to_linear() of a dBµV level yields microvolts. Use quantity_cast to retarget:

to_linear(30_dBm); // 1000.0 mW
quantity_cast<watts>(to_linear(30_dBm)); // 1 W
auto to_linear(const level< Reference, Rep, Precision > &l)
Converts a level to the equivalent linear quantity.
Definition decibel.hpp:476
Note
Not constexpr: requires std::pow.

Definition at line 476 of file decibel.hpp.

References quanta::electro::level< Reference, Rep, Precision >::offset_from_reference().

Referenced by add_powers().

◆ to_string() [1/9]

template<typename Reference , typename Rep , typename Precision >
requires _is_decimal_precision<typename Precision::type>
std::string quanta::electro::to_string ( const level< Reference, Rep, Precision > &  l)
inline

Converts a level to a string, e.g.

"-73dBm" or "13.01dBm".

Definition at line 767 of file decibel.hpp.

References quanta::electro::level< Reference, Rep, Precision >::count().

◆ to_string() [2/9]

template<typename Reference , typename Rep , typename Precision >
requires _is_decimal_precision<typename Precision::type>
std::string quanta::electro::to_string ( const level< Reference, Rep, Precision > &  l,
base_unit_t   
)
inline

Converts a level to a string against its reference, e.g.

"13.01dBm".

A level has no other unit, so this differs from to_string(l) only in rendering the value in the shortest fixed notation that round-trips, as by the b format marker.

Definition at line 780 of file decibel.hpp.

References quanta::electro::level< Reference, Rep, Precision >::count().

◆ to_string() [3/9]

template<typename Reference , typename Rep , typename Precision >
requires _is_decimal_precision<typename Precision::type>
std::string quanta::electro::to_string ( const level< Reference, Rep, Precision > &  l,
scaled_t   
)
inline

Converts a level to a string against its reference, e.g.

"13.01dBm".

Levels have no SI prefix family, so this is the same as to_string(l, base_unit), as by the s format marker.

Definition at line 792 of file decibel.hpp.

References quanta::base_unit, and to_string().

◆ to_string() [4/9]

template<typename Rep , typename Precision >
requires _is_decimal_precision<typename Precision::type>
std::string quanta::electro::to_string ( const quantity< decibel_unit, Rep, Precision > &  g)
inline

Converts a gain to a string, e.g.

"10dB" or "10.50dB".

Unlike the generic quantity to_string, a gain's precision is rendered as decimal places rather than as an SI prefix: nobody writes "1050cdB".

Definition at line 733 of file decibel.hpp.

References quanta::electro::quantity< Unit, Rep, Precision >::count(), and quanta::electro::decibel_unit::symbol.

Referenced by to_string(), and to_string().

◆ to_string() [5/9]

template<typename Rep , typename Precision >
requires _is_decimal_precision<typename Precision::type>
std::string quanta::electro::to_string ( const quantity< decibel_unit, Rep, Precision > &  g,
base_unit_t   
)
inline

Converts a gain to a string in decibels, e.g.

"10.5dB".

A gain has no other unit, so this differs from to_string(g) only in rendering the value in the shortest fixed notation that round-trips, as by the b format marker.

Definition at line 746 of file decibel.hpp.

References quanta::electro::quantity< Unit, Rep, Precision >::count(), and quanta::electro::decibel_unit::symbol.

◆ to_string() [6/9]

template<typename Rep , typename Precision >
requires _is_decimal_precision<typename Precision::type>
std::string quanta::electro::to_string ( const quantity< decibel_unit, Rep, Precision > &  g,
scaled_t   
)
inline

Converts a gain to a string in decibels, e.g.

"10.5dB".

Decibels have no SI prefix family, so this is the same as to_string(g, base_unit), as by the s format marker.

Definition at line 758 of file decibel.hpp.

References quanta::base_unit, and to_string().

◆ to_string() [7/9]

template<typename Unit , typename Rep , typename Precision >
requires _has_suffix<Unit, typename Precision::type>
std::string quanta::electro::to_string ( const quantity< Unit, Rep, Precision > &  q)
inline

Converts a quantity to a string with its unit suffix.

Available for quantities whose precision has a conventional suffix (standard SI prefixes plus mAh, Ah, Wh and kWh). Integer counts are shown exactly; floating-point counts in the shortest fixed notation that round-trips (never scientific).

to_string(millivolts(3300)); // "3300mV"
to_string(kiloohms(10)); // "10kΩ"
to_string(milliampere_hours(200)); // "200mAh"
to_string(voltage<double>(1e6)); // "1000000V"
quantity< volt_unit, Rep, Precision > voltage
Voltage quantity with configurable representation and precision.
Definition electro.hpp:888

Definition at line 1287 of file electro.hpp.

References quanta::electro::quantity< Unit, Rep, Precision >::count(), and quanta::electro::quantity_suffix< Unit, Precision >::value().

◆ to_string() [8/9]

template<typename Unit , typename Rep , typename Precision >
requires _has_suffix<Unit, typename Precision::type>
std::string quanta::electro::to_string ( const quantity< Unit, Rep, Precision > &  q,
base_unit_t   
)
inline

Converts a quantity to a string in its base unit.

Available for the same quantities as to_string(q); see base_unit.

to_string(millivolts(3300), base_unit); // "3.3V"
to_string(milliampere_hours(200), base_unit); // "0.2Ah"

Definition at line 1303 of file electro.hpp.

◆ to_string() [9/9]

template<typename Unit , typename Rep , typename Precision >
requires _has_suffix<Unit, typename Precision::type>
std::string quanta::electro::to_string ( const quantity< Unit, Rep, Precision > &  q,
scaled_t   
)
inline

Converts a quantity to a string with an SI prefix suited to its magnitude.

Available for the same quantities as to_string(q); see scaled.

to_string(millivolts(3300), scaled); // "3.3V"
to_string(ohms(4700), scaled); // "4.7kΩ"

Definition at line 1320 of file electro.hpp.

◆ trunc() [1/2]

template<typename ToLevel , typename Reference , typename Rep , typename Precision >
constexpr ToLevel quanta::electro::trunc ( const level< Reference, Rep, Precision > &  l)
constexpr

Converts a level to the target type, rounding toward zero (as level_cast does).

Definition at line 347 of file decibel.hpp.

References quanta::electro::level< Reference, Rep, Precision >::offset_from_reference().

◆ trunc() [2/2]

template<typename ToQuantity , typename Unit , typename Rep , typename Precision >
constexpr ToQuantity quanta::electro::trunc ( const quantity< Unit, Rep, Precision > &  q)
constexpr

Converts a quantity to the target type, rounding toward zero.

The same as quantity_cast<ToQuantity>(q).

Template Parameters
ToQuantityThe target quantity type.
UnitThe unit tag type.
RepSource representation type.
PrecisionSource precision.
Parameters
qThe quantity to convert.
Returns
The converted quantity, rounded toward zero.
using namespace quanta::electro;
auto v = trunc<volts>(millivolts(-1500)); // -1 V (rounded toward zero from -1.5)

Definition at line 488 of file electro.hpp.

Variable Documentation

◆ is_field_reference_v

template<typename Reference >
constexpr bool quanta::electro::is_field_reference_v = false
inlineconstexpr

True if the reference measures a field quantity (20*log10).

Definition at line 169 of file decibel.hpp.

◆ is_field_reference_v< Reference >

template<decibel_reference Reference>
constexpr bool quanta::electro::is_field_reference_v< Reference > = Reference::factor == 20
inlineconstexpr

Definition at line 172 of file decibel.hpp.

◆ is_level_v

template<typename T >
constexpr bool quanta::electro::is_level_v = is_level<T>::value
inlineconstexpr

Definition at line 192 of file decibel.hpp.

◆ is_power_reference_v

template<typename Reference >
constexpr bool quanta::electro::is_power_reference_v = false
inlineconstexpr

True if the reference measures a power quantity (10*log10).

Definition at line 162 of file decibel.hpp.

◆ is_power_reference_v< Reference >

template<decibel_reference Reference>
constexpr bool quanta::electro::is_power_reference_v< Reference > = Reference::factor == 10
inlineconstexpr

Definition at line 165 of file decibel.hpp.

◆ is_quantity_v

template<typename T >
constexpr bool quanta::electro::is_quantity_v = is_quantity<T>::value
inlineconstexpr

Definition at line 121 of file electro.hpp.