electro 0.3.0
Type-safe electrical units library modeled after std::chrono
Loading...
Searching...
No Matches
Cross-Unit Arithmetic

Operators combining quantities of different kinds according to circuit theory. More...

Functions

template<typename R1 , typename P1 , typename R2 , typename P2 >
constexpr auto electro::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 electro::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 electro::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 electro::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 electro::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 electro::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 electro::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 electro::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 electro::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 electro::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 electro::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 electro::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 electro::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 electro::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 electro::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 electro::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 electro::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 electro::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 electro::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 electro::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 electro::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 electro::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 electro::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 electro::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 electro::operator/ (const quantity< henry_unit, R1, P1 > &l, const quantity< ohm_unit, R2, P2 > &r)
 L/R time constant: inductance / resistance = time.
 

Detailed Description

Operators combining quantities of different kinds according to circuit theory.

The result precision is derived from the operand precisions, so results are exact for products (e.g. milliamperes x kiloohms yields volts) while quotients truncate for integer representations (use finer precisions or floating-point representations for fractional results).

Function Documentation

◆ operator*() [1/12]

template<duration_like D, typename R1 , typename P1 >
constexpr auto electro::operator* ( const D t,
const quantity< ampere_unit, R1, P1 > &  i 
)
constexpr

Charge: time x current = charge.

Definition at line 830 of file electro.hpp.

References electro::treat_as_inexact_v.

◆ operator*() [2/12]

template<duration_like D, typename R1 , typename P1 >
constexpr auto electro::operator* ( const D t,
const quantity< watt_unit, R1, P1 > &  p 
)
constexpr

Energy: time x power = energy.

Definition at line 866 of file electro.hpp.

References electro::treat_as_inexact_v.

◆ operator*() [3/12]

template<typename R1 , typename P1 , duration_like D>
constexpr auto electro::operator* ( const quantity< ampere_unit, R1, P1 > &  i,
const D t 
)
constexpr

Charge: current x time = charge.

auto q = milliamperes(100) * std::chrono::hours(2); // 200 mAh
current< int64_t, std::milli > milliamperes
Current with 1 mA precision.
Definition electro.hpp:1013
constexpr bool treat_as_inexact_v
Definition electro.hpp:162

Definition at line 824 of file electro.hpp.

References electro::treat_as_inexact_v.

◆ operator*() [4/12]

Ohm's law: current x resistance = voltage.

Definition at line 770 of file electro.hpp.

References electro::treat_as_inexact_v.

◆ operator*() [5/12]

Power law: current x voltage = power.

Definition at line 800 of file electro.hpp.

References electro::treat_as_inexact_v.

◆ operator*() [6/12]

RC time constant: capacitance x resistance = time.

Definition at line 938 of file electro.hpp.

References electro::treat_as_inexact_v.

◆ operator*() [7/12]

Capacitance: capacitance x voltage = charge.

Definition at line 902 of file electro.hpp.

References electro::treat_as_inexact_v.

◆ operator*() [8/12]

Ohm's law: resistance x current = voltage.

Definition at line 776 of file electro.hpp.

References electro::treat_as_inexact_v.

◆ operator*() [9/12]

RC time constant: resistance x capacitance = time.

auto tau = kiloohms(47) * microfarads(10); // 470 ms
capacitance< int64_t, std::micro > microfarads
Capacitance with 1 µF precision.
Definition electro.hpp:1076
resistance< int64_t, std::kilo > kiloohms
Resistance with 1 kΩ precision.
Definition electro.hpp:1028

Definition at line 932 of file electro.hpp.

References electro::treat_as_inexact_v.

◆ operator*() [10/12]

Power law: voltage x current = power.

Definition at line 794 of file electro.hpp.

References electro::treat_as_inexact_v.

◆ operator*() [11/12]

Capacitance: voltage x capacitance = charge.

Definition at line 908 of file electro.hpp.

References electro::treat_as_inexact_v.

◆ operator*() [12/12]

template<typename R1 , typename P1 , duration_like D>
constexpr auto electro::operator* ( const quantity< watt_unit, R1, P1 > &  p,
const D t 
)
constexpr

Energy: power x time = energy.

auto e = watts(100) * std::chrono::hours(5); // 500 Wh
power< int64_t > watts
Power with 1 W precision.
Definition electro.hpp:1039

Definition at line 860 of file electro.hpp.

References electro::treat_as_inexact_v.

◆ operator/() [1/13]

template<typename R1 , typename P1 , duration_like D>
constexpr auto electro::operator/ ( const quantity< coulomb_unit, R1, P1 > &  q,
const D t 
)
constexpr

Charge: charge / time = current.

Definition at line 836 of file electro.hpp.

References electro::treat_as_inexact_v.

◆ operator/() [2/13]

Charge: charge / current = time.

auto runtime = milliampere_hours(2000) / milliamperes(100); // 20 h
charge< int64_t, std::ratio< 18, 5 > > milliampere_hours
Charge with 1 mAh (3.6 C) precision.
Definition electro.hpp:1054

Definition at line 848 of file electro.hpp.

References electro::treat_as_inexact_v.

◆ operator/() [3/13]

Capacitance: charge / capacitance = voltage.

Definition at line 920 of file electro.hpp.

References electro::treat_as_inexact_v.

◆ operator/() [4/13]

Capacitance: charge / voltage = capacitance.

Definition at line 914 of file electro.hpp.

References electro::treat_as_inexact_v.

◆ operator/() [5/13]

L/R time constant: inductance / resistance = time.

auto tau = millihenries(10) / ohms(2); // 5 ms
inductance< int64_t, std::milli > millihenries
Inductance with 1 mH precision.
Definition electro.hpp:1087
resistance< int64_t > ohms
Resistance with 1 Ω precision.
Definition electro.hpp:1026

Definition at line 950 of file electro.hpp.

References electro::treat_as_inexact_v.

◆ operator/() [6/13]

template<typename R1 , typename P1 , duration_like D>
constexpr auto electro::operator/ ( const quantity< joule_unit, R1, P1 > &  e,
const D t 
)
constexpr

Energy: energy / time = power.

Definition at line 872 of file electro.hpp.

References electro::treat_as_inexact_v.

◆ operator/() [7/13]

Energy: energy / charge = voltage.

Definition at line 896 of file electro.hpp.

References electro::treat_as_inexact_v.

◆ operator/() [8/13]

Energy: energy / voltage = charge.

auto capacity = watt_hours(100) / volts(5); // 20 Ah
voltage< int64_t > volts
Voltage with 1 V precision.
Definition electro.hpp:1006
energy< int64_t, std::ratio< 3600 > > watt_hours
Energy with 1 Wh (3600 J) precision.
Definition electro.hpp:1067

Definition at line 890 of file electro.hpp.

References electro::treat_as_inexact_v.

◆ operator/() [9/13]

Energy: energy / power = time.

Definition at line 878 of file electro.hpp.

References electro::treat_as_inexact_v.

◆ operator/() [10/13]

Ohm's law: voltage / current = resistance.

Definition at line 788 of file electro.hpp.

References electro::treat_as_inexact_v.

◆ operator/() [11/13]

Ohm's law: voltage / resistance = current.

Definition at line 782 of file electro.hpp.

References electro::treat_as_inexact_v.

◆ operator/() [12/13]

Power law: power / current = voltage.

Definition at line 812 of file electro.hpp.

References electro::treat_as_inexact_v.

◆ operator/() [13/13]

Power law: power / voltage = current.

Definition at line 806 of file electro.hpp.

References electro::treat_as_inexact_v.