|
quanta 0.1.0
Type-safe units for temperature, frequency, electrical and spatial quantities, modeled after std::chrono
|
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 |
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.
The library provides standard integer-based types for each quantity:
Quantities of different kinds combine according to the laws of circuit theory, producing results in the correct unit with the correct precision:
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:
Conversions between precisions are implicit when lossless and require an explicit cast when lossy, exactly as with std::chrono::duration.
| using quanta::electro::centidecibels = typedef gain<int64_t, std::centi> |
Gain with 0.01 dB precision.
Definition at line 85 of file decibel.hpp.
| using quanta::electro::decibels = typedef gain<int64_t> |
Gain with 1 dB precision.
Definition at line 83 of file decibel.hpp.
| 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.
| using quanta::electro::millidecibels = typedef gain<int64_t, std::milli> |
Gain with 0.001 dB precision.
Definition at line 87 of file decibel.hpp.
|
constexpr |
Returns the absolute value of a quantity.
| Unit | The unit tag type. |
| Rep | Representation type. |
| Precision | Precision type. |
| q | The quantity. |
Definition at line 527 of file electro.hpp.
|
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.
Definition at line 589 of file decibel.hpp.
References to_linear().
|
inline |
The gain corresponding to a linear amplitude ratio (20*log10(ratio)).
Definition at line 566 of file decibel.hpp.
|
inline |
The linear amplitude ratio a gain represents (10^(dB/20)).
Definition at line 555 of file decibel.hpp.
|
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().
|
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.
| ToQuantity | The target quantity type. |
| Unit | The unit tag type. |
| Rep | Source representation type. |
| Precision | Source precision. |
| q | The quantity to convert. |
Definition at line 465 of file electro.hpp.
|
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().
|
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.
| ToQuantity | The target quantity type. |
| Unit | The unit tag type. |
| Rep | Source representation type. |
| Precision | Source precision. |
| q | The quantity to convert. |
Definition at line 441 of file electro.hpp.
|
constexpr |
Converts a level to a different precision or representation.
| ToLevel | The 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().
|
constexpr |
Returns the remainder of dividing a quantity by a scalar.
Definition at line 589 of file electro.hpp.
|
constexpr |
Returns the remainder of dividing two quantities of the same unit.
Definition at line 598 of file electro.hpp.
|
constexpr |
Multiplies a quantity by a scalar.
Definition at line 554 of file electro.hpp.
|
constexpr |
Multiplies a scalar by a quantity.
Definition at line 563 of file electro.hpp.
|
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().
|
constexpr |
Applies a gain to a level.
Definition at line 384 of file decibel.hpp.
|
constexpr |
Returns the sum of two quantities of the same unit.
Definition at line 537 of file electro.hpp.
|
constexpr |
The difference between two levels is a gain.
Definition at line 405 of file decibel.hpp.
References quanta::electro::level< Reference, Rep, Precision >::offset_from_reference().
|
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().
|
constexpr |
Returns the difference of two quantities of the same unit.
Definition at line 545 of file electro.hpp.
|
constexpr |
Divides a quantity by a scalar.
Definition at line 571 of file electro.hpp.
|
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().
|
constexpr |
Definition at line 416 of file decibel.hpp.
References quanta::electro::level< Reference, Rep, Precision >::offset_from_reference().
|
constexpr |
Definition at line 612 of file electro.hpp.
References quanta::electro::quantity< Unit, Rep, Precision >::count().
|
constexpr |
Definition at line 410 of file decibel.hpp.
References quanta::electro::level< Reference, Rep, Precision >::offset_from_reference().
|
constexpr |
Definition at line 605 of file electro.hpp.
References quanta::electro::quantity< Unit, Rep, Precision >::count().
|
inline |
The gain corresponding to a linear power ratio (10*log10(ratio)).
Definition at line 560 of file decibel.hpp.
|
inline |
The linear power ratio a gain represents (10^(dB/10)).
Definition at line 541 of file decibel.hpp.
|
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.
| ToQuantity | The target quantity type (must have the same unit). |
| Unit | The unit tag type. |
| Rep | Source representation type. |
| Precision | Source precision. |
| q | The quantity to convert. |
Definition at line 413 of file electro.hpp.
|
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().
|
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.
| ToQuantity | The target quantity type. |
| Unit | The unit tag type. |
| Rep | Source representation type. |
| Precision | Source precision. |
| q | The quantity to convert. |
Definition at line 512 of file electro.hpp.
|
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().
Definition at line 508 of file decibel.hpp.
References quanta::electro::quantity< Unit, Rep, Precision >::count().
|
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:
Definition at line 476 of file decibel.hpp.
References quanta::electro::level< Reference, Rep, Precision >::offset_from_reference().
Referenced by add_powers().
|
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().
|
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().
|
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().
|
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().
|
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.
|
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().
|
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).
Definition at line 1287 of file electro.hpp.
References quanta::electro::quantity< Unit, Rep, Precision >::count(), and quanta::electro::quantity_suffix< Unit, Precision >::value().
|
inline |
Converts a quantity to a string in its base unit.
Available for the same quantities as to_string(q); see base_unit.
Definition at line 1303 of file electro.hpp.
|
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.
Definition at line 1320 of file electro.hpp.
|
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().
|
constexpr |
Converts a quantity to the target type, rounding toward zero.
The same as quantity_cast<ToQuantity>(q).
| ToQuantity | The target quantity type. |
| Unit | The unit tag type. |
| Rep | Source representation type. |
| Precision | Source precision. |
| q | The quantity to convert. |
Definition at line 488 of file electro.hpp.
|
inlineconstexpr |
True if the reference measures a field quantity (20*log10).
Definition at line 169 of file decibel.hpp.
|
inlineconstexpr |
Definition at line 172 of file decibel.hpp.
|
inlineconstexpr |
Definition at line 192 of file decibel.hpp.
|
inlineconstexpr |
True if the reference measures a power quantity (10*log10).
Definition at line 162 of file decibel.hpp.
|
inlineconstexpr |
Definition at line 165 of file decibel.hpp.
|
inlineconstexpr |
Definition at line 121 of file electro.hpp.