-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from Aehmlo/electromagnetism
Add more electromagnetism-related units.
- Loading branch information
Showing
9 changed files
with
823 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
//! Capacitance (base unit farad, m<sup>-2</sup> · kg<sup>-1</sup> · s<sup>4</sup> · A<sup>2</sup>). | ||
quantity! { | ||
/// Capacitance (base unit farad, m<sup>-2</sup> · kg<sup>-1</sup> · s<sup>4</sup> · | ||
/// A<sup>2</sup>). | ||
quantity: Capacitance; "capacitance"; | ||
/// Capacitance dimension, m<sup>-2</sup> · kg<sup>-1</sup> · s<sup>4</sup> · A<sup>2</sup>. | ||
dimension: ISQ< | ||
N2, // length | ||
N1, // mass | ||
P4, // time | ||
P2, // electric current | ||
Z0, // thermodynamic temperature | ||
Z0, // amount of substance | ||
Z0>; // luminous intensity | ||
units { | ||
@yottafarad: prefix!(yotta); "YF", "yottafarad", "yottafarads"; | ||
@zettafarad: prefix!(zetta); "ZF", "zettafarad", "zettafarads"; | ||
@exafarad: prefix!(exa); "EF", "exafarad", "exafarads"; | ||
@petafarad: prefix!(peta); "PF", "petafarad", "petafarads"; | ||
@terafarad: prefix!(tera); "TF", "terafarad", "terafarads"; | ||
@gigafarad: prefix!(giga); "GF", "gigafarad", "gigafarads"; | ||
@megafarad: prefix!(mega); "MF", "megafarad", "megafarads"; | ||
@kilofarad: prefix!(kilo); "kF", "kilofarad", "kilofarads"; | ||
@hectofarad: prefix!(hecto); "hF", "hectofarad", "hectofarads"; | ||
@decafarad: prefix!(deca); "daF", "decafarad", "decafarads"; | ||
/// Derived unit of capacitance. | ||
@farad: prefix!(none); "F", "farad", "farads"; | ||
@decifarad: prefix!(deci); "dF", "decifarad", "decifarads"; | ||
@centifarad: prefix!(centi); "cF", "centifarad", "centifarads"; | ||
@millifarad: prefix!(milli); "mF", "millifarad", "millifarads"; | ||
@microfarad: prefix!(micro); "µF", "microfarad", "microfarads"; | ||
@nanofarad: prefix!(nano); "nF", "nanofarad", "nanofarads"; | ||
@picofarad: prefix!(pico); "pF", "picofarad", "picofarads"; | ||
@femtofarad: prefix!(femto); "fF", "femtofarad", "femtofarads"; | ||
@attofarad: prefix!(atto); "aF", "attofarad", "attofarads"; | ||
@zeptofarad: prefix!(zepto); "zF", "zeptofarad", "zeptofarads"; | ||
@yoctofarad: prefix!(yocto); "yF", "yoctofarad", "yoctofarads"; | ||
|
||
@abfarad: 1.0_E9; "abF", "abfarad", "abfarads"; | ||
@statfarad: 1.112_650_E-12; "statF", "statfarad", "statfarads"; | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
storage_types! { | ||
use num::One; | ||
use si::quantities::*; | ||
use si::electric_current as i; | ||
use si::time as t; | ||
use si::electric_potential as v; | ||
use si::capacitance as c; | ||
use tests::Test; | ||
|
||
#[test] | ||
fn check_dimension() { | ||
let _: Capacitance<V> = ElectricCurrent::new::<i::ampere>(V::one()) | ||
* Time::new::<t::second>(V::one()) | ||
/ ElectricPotential::new::<v::volt>(V::one()); | ||
} | ||
|
||
#[test] | ||
fn check_units() { | ||
test::<i::yottaampere, v::volt, c::yottafarad>(); | ||
test::<i::zettaampere, v::volt, c::zettafarad>(); | ||
test::<i::exaampere, v::volt, c::exafarad>(); | ||
test::<i::petaampere, v::volt, c::petafarad>(); | ||
test::<i::teraampere, v::volt, c::terafarad>(); | ||
test::<i::gigaampere, v::volt, c::gigafarad>(); | ||
test::<i::megaampere, v::volt, c::megafarad>(); | ||
test::<i::kiloampere, v::volt, c::kilofarad>(); | ||
test::<i::hectoampere, v::volt, c::hectofarad>(); | ||
test::<i::decaampere, v::volt, c::decafarad>(); | ||
test::<i::ampere, v::volt, c::farad>(); | ||
test::<i::deciampere, v::volt, c::decifarad>(); | ||
test::<i::centiampere, v::volt, c::centifarad>(); | ||
test::<i::milliampere, v::volt, c::millifarad>(); | ||
test::<i::microampere, v::volt, c::microfarad>(); | ||
test::<i::nanoampere, v::volt, c::nanofarad>(); | ||
test::<i::picoampere, v::volt, c::picofarad>(); | ||
test::<i::femtoampere, v::volt, c::femtofarad>(); | ||
test::<i::attoampere, v::volt, c::attofarad>(); | ||
test::<i::zeptoampere, v::volt, c::zeptofarad>(); | ||
test::<i::yoctoampere, v::volt, c::yoctofarad>(); | ||
|
||
test::<i::statampere, v::statvolt, c::statfarad>(); | ||
test::<i::abampere, v::abvolt, c::abfarad>(); | ||
|
||
fn test<I: i::Conversion<V>, U: v::Conversion<V>, C: c::Conversion<V>>() { | ||
Test::assert_approx_eq(&Capacitance::new::<C>(V::one()), | ||
&(ElectricCurrent::new::<I>(V::one()) | ||
* Time::new::<t::second>(V::one()) | ||
/ ElectricPotential::new::<U>(V::one()))); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
//! Electric charge (base unit coulomb, A · s). | ||
quantity! { | ||
/// Electric charge (base unit coulomb, A · s). | ||
quantity: ElectricCharge; "electric charge"; | ||
/// Electric charge dimension, A · s. | ||
dimension: ISQ< | ||
Z0, // length | ||
Z0, // mass | ||
P1, // time | ||
P1, // electric current | ||
Z0, // thermodynamic temperature | ||
Z0, // amount of substance | ||
Z0>; // luminous intensity | ||
units { | ||
@yottacoulomb: prefix!(yotta); "YC", "yottacoulomb", "yottacoulombs"; | ||
@zettacoulomb: prefix!(zetta); "ZC", "zettacoulomb", "zettacoulombs"; | ||
@exacoulomb: prefix!(exa); "EC", "exacoulomb", "exacoulombs"; | ||
@petacoulomb: prefix!(peta); "PC", "petacoulomb", "petacoulombs"; | ||
@teracoulomb: prefix!(tera); "TC", "teracoulomb", "teracoulombs"; | ||
@gigacoulomb: prefix!(giga); "GC", "gigacoulomb", "gigacoulombs"; | ||
@megacoulomb: prefix!(mega); "MC", "megacoulomb", "megacoulombs"; | ||
@kilocoulomb: prefix!(kilo); "kC", "kilocoulomb", "kilocoulombs"; | ||
@hectocoulomb: prefix!(hecto); "hC", "hectocoulomb", "hectocoulombs"; | ||
@decacoulomb: prefix!(deca); "daC", "decacoulomb", "decacoulombs"; | ||
/// Derived unit of electric charge. | ||
@coulomb: prefix!(none); "C", "coulomb", "coulombs"; | ||
@decicoulomb: prefix!(deci); "dC", "decicoulomb", "decicoulombs"; | ||
@centicoulomb: prefix!(centi); "cC", "centicoulomb", "centicoulombs"; | ||
@millicoulomb: prefix!(milli); "mC", "millcoulomb", "millcoulombs"; | ||
@microcoulomb: prefix!(micro); "µC", "microcoulomb", "microcoulombs"; | ||
@nanocoulomb: prefix!(nano); "nC", "nanocoulomb", "nanocoulombs"; | ||
@picocoulomb: prefix!(pico); "pC", "picocoulomb", "picocoulombs"; | ||
@femtocoulomb: prefix!(femto); "fC", "femtocoulomb", "femtocoulombs"; | ||
@attocoulomb: prefix!(atto); "aC", "attocoulomb", "attocoulombs"; | ||
@zeptocoulomb: prefix!(zepto); "zC", "zeptocoulomb", "zeptocoulombs"; | ||
@yoctocoulomb: prefix!(yocto); "yC", "yoctocoulomb", "yoctocoulombs"; | ||
|
||
@abcoulomb: 1.0_E1; "abC", "abcoulomb", "abcoulombs"; | ||
@ampere_hour: 3.6_E3; "A · h", "ampere hour", "ampere hours"; | ||
@faraday: 9.648_531_E4; "F", "faraday", "faradays"; | ||
@franklin: 3.335_641_E-10; "Fr", "franklin", "franklins"; | ||
@statcoulomb: 3.335_641_E-10; "statC", "statcoulomb", "statcoulombs"; | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
storage_types! { | ||
use num::One; | ||
use si::quantities::*; | ||
use si::time as t; | ||
use si::electric_current as i; | ||
use si::electric_charge as q; | ||
use tests::Test; | ||
|
||
#[test] | ||
fn check_dimension() { | ||
let _: ElectricCharge<V> = ElectricCurrent::new::<i::ampere>(V::one()) | ||
* Time::new::<t::second>(V::one()); | ||
} | ||
|
||
#[test] | ||
fn check_units() { | ||
test::<i::yottaampere, t::second, q::yottacoulomb>(); | ||
test::<i::zettaampere, t::second, q::zettacoulomb>(); | ||
test::<i::exaampere, t::second, q::exacoulomb>(); | ||
test::<i::petaampere, t::second, q::petacoulomb>(); | ||
test::<i::teraampere, t::second, q::teracoulomb>(); | ||
test::<i::gigaampere, t::second, q::gigacoulomb>(); | ||
test::<i::megaampere, t::second, q::megacoulomb>(); | ||
test::<i::kiloampere, t::second, q::kilocoulomb>(); | ||
test::<i::hectoampere, t::second, q::hectocoulomb>(); | ||
test::<i::decaampere, t::second, q::decacoulomb>(); | ||
test::<i::ampere, t::second, q::coulomb>(); | ||
test::<i::deciampere, t::second, q::decicoulomb>(); | ||
test::<i::centiampere, t::second, q::centicoulomb>(); | ||
test::<i::milliampere, t::second, q::millicoulomb>(); | ||
test::<i::microampere, t::second, q::microcoulomb>(); | ||
test::<i::nanoampere, t::second, q::nanocoulomb>(); | ||
test::<i::picoampere, t::second, q::picocoulomb>(); | ||
test::<i::femtoampere, t::second, q::femtocoulomb>(); | ||
test::<i::attoampere, t::second, q::attocoulomb>(); | ||
test::<i::zeptoampere, t::second, q::zeptocoulomb>(); | ||
test::<i::yoctoampere, t::second, q::yoctocoulomb>(); | ||
|
||
test::<i::ampere, t::hour, q::ampere_hour>(); | ||
test::<i::abampere, t::second, q::abcoulomb>(); | ||
test::<i::statampere, t::second, q::statcoulomb>(); | ||
|
||
fn test<I: i::Conversion<V>, T: t::Conversion<V>, Q: q::Conversion<V>>() { | ||
Test::assert_approx_eq(&ElectricCharge::new::<Q>(V::one()), | ||
&(ElectricCurrent::new::<I>(V::one()) * Time::new::<T>(V::one()))); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
//! Electrical conductance | ||
//! (base unit siemens, m<sup>-2</sup> · kg<sup>-1</sup> · s<sup>3</sup> · A<sup>2</sup>). | ||
quantity! { | ||
/// Electrical conductance (base unit siemens, | ||
/// m<sup>-2</sup> · kg<sup>-1</sup> · s<sup>3</sup> · A<sup>2</sup>). | ||
quantity: ElectricalConductance; "electrical conductance"; | ||
/// Electrical conductance dimension, | ||
/// m<sup>-2</sup> · kg<sup>-1</sup> · s<sup>3</sup> · A<sup>2</sup>. | ||
dimension: ISQ< | ||
N2, // length | ||
N1, // mass | ||
P3, // time | ||
P2, // electric current | ||
Z0, // thermodynamic temperature | ||
Z0, // amount of substance | ||
Z0>; // luminous intensity | ||
units { | ||
@yottasiemens: prefix!(yotta); "YS", "yottasiemens", "yottasiemens"; | ||
@zettasiemens: prefix!(zetta); "ZS", "zettasiemens", "zettasiemens"; | ||
@exasiemens: prefix!(exa); "ES", "exasiemens", "exasiemens"; | ||
@petasiemens: prefix!(peta); "PS", "petasiemens", "petasiemens"; | ||
@terasiemens: prefix!(tera); "TS", "terasiemens", "terasiemens"; | ||
@gigasiemens: prefix!(giga); "GS", "gigasiemens", "gigasiemens"; | ||
@megasiemens: prefix!(mega); "MS", "megasiemens", "megasiemens"; | ||
@kilosiemens: prefix!(kilo); "kS", "kilosiemens", "kilosiemens"; | ||
@hectosiemens: prefix!(hecto); "hS", "hectosiemens", "hectosiemens"; | ||
@decasiemens: prefix!(deca); "daS", "decasiemens", "decasiemens"; | ||
/// Derived unit of electrical conductance. | ||
@siemens: prefix!(none); "S", "siemens", "siemens"; | ||
@mho: prefix!(none); "S", "mho", "mhos"; | ||
@decisiemens: prefix!(deci); "dS", "decisiemens", "decisiemens"; | ||
@centisiemens: prefix!(centi); "cS", "centisiemens", "centisiemens"; | ||
@millisiemens: prefix!(milli); "mS", "millisiemens", "millisiemens"; | ||
@microsiemens: prefix!(micro); "µS", "microsiemens", "microsiemens"; | ||
@nanosiemens: prefix!(nano); "nS", "nanosiemens", "nanosiemens"; | ||
@picosiemens: prefix!(pico); "pS", "picosiemens", "picosiemens"; | ||
@femtosiemens: prefix!(femto); "fS", "femtosiemens", "femtosiemens"; | ||
@attosiemens: prefix!(atto); "aS", "attosiemens", "attosiemens"; | ||
@zeptosiemens: prefix!(zepto); "zS", "zeptosiemens", "zeptosiemens"; | ||
@yoctosiemens: prefix!(yocto); "yS", "yoctosiemens", "yoctosiemens"; | ||
|
||
@abmho: 1.0_E9; "abmho", "abmho", "abmhos"; | ||
@absiemens: 1.0_E9; "abS", "abmsiemens", "abmsiemens"; | ||
@statsiemens: 1.112_650_E-12; "statS", "statsiemens", "statsiemens"; | ||
@statmho: 1.112_650_E-12; "statmho", "statmho", "statmhos"; | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
storage_types! { | ||
use num::One; | ||
use si::quantities::*; | ||
use si::electrical_resistance as r; | ||
use si::electrical_conductance as g; | ||
use tests::Test; | ||
|
||
#[test] | ||
fn check_dimension() { | ||
let _: ElectricalConductance<V> = V::one() | ||
/ ElectricalResistance::new::<r::ohm>(V::one()); | ||
} | ||
|
||
#[test] | ||
fn check_units() { | ||
test::<r::yoctoohm, g::yottasiemens>(); | ||
test::<r::zeptoohm, g::zettasiemens>(); | ||
test::<r::attoohm, g::exasiemens>(); | ||
test::<r::femtoohm, g::petasiemens>(); | ||
test::<r::picoohm, g::terasiemens>(); | ||
test::<r::nanoohm, g::gigasiemens>(); | ||
test::<r::microohm, g::megasiemens>(); | ||
test::<r::milliohm, g::kilosiemens>(); | ||
test::<r::centiohm, g::hectosiemens>(); | ||
test::<r::deciohm, g::decasiemens>(); | ||
test::<r::ohm, g::siemens>(); | ||
test::<r::decaohm, g::decisiemens>(); | ||
test::<r::hectoohm, g::centisiemens>(); | ||
test::<r::kiloohm, g::millisiemens>(); | ||
test::<r::megaohm, g::microsiemens>(); | ||
test::<r::gigaohm, g::nanosiemens>(); | ||
test::<r::teraohm, g::picosiemens>(); | ||
test::<r::petaohm, g::femtosiemens>(); | ||
test::<r::exaohm, g::attosiemens>(); | ||
test::<r::zettaohm, g::zeptosiemens>(); | ||
test::<r::yottaohm, g::yoctosiemens>(); | ||
|
||
test::<r::abohm, g::absiemens>(); | ||
test::<r::statohm, g::statsiemens>(); | ||
test::<r::abohm, g::abmho>(); | ||
test::<r::statohm, g::statmho>(); | ||
|
||
fn test<R: r::Conversion<V>, G: g::Conversion<V>>() { | ||
Test::assert_approx_eq(&ElectricalConductance::new::<G>(V::one()), | ||
&(V::one() / ElectricalResistance::new::<R>(V::one()))); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
//! Electrical resistance (base unit ohm, m<sup>2</sup> · kg · s<sup>-3</sup> · A<sup>-2</sup>). | ||
quantity! { | ||
/// Electrical resistance (base unit ohm, m<sup>2</sup> · kg · s<sup>-3</sup> · A<sup>-2</sup>). | ||
quantity: ElectricalResistance; "electrical resistance"; | ||
/// Electrical resistance dimension, m<sup>2</sup> · kg · s<sup>-3</sup> · A<sup>-2</sup>. | ||
dimension: ISQ< | ||
P2, // length | ||
P1, // mass | ||
N3, // time | ||
N2, // electric current | ||
Z0, // thermodynamic temperature | ||
Z0, // amount of substance | ||
Z0>; // luminous intensity | ||
units { | ||
@yottaohm: prefix!(yotta); "YΩ", "yottaohm", "yottaohms"; | ||
@zettaohm: prefix!(zetta); "ZΩ", "zettaohm", "zettaohms"; | ||
@exaohm: prefix!(exa); "EΩ", "exaohm", "exaohms"; | ||
@petaohm: prefix!(peta); "PΩ", "petaohm", "petaohms"; | ||
@teraohm: prefix!(tera); "TΩ", "teraohm", "teraohms"; | ||
@gigaohm: prefix!(giga); "GΩ", "gigaohm", "gigaohms"; | ||
@megaohm: prefix!(mega); "MΩ", "megaohm", "megaohms"; | ||
@kiloohm: prefix!(kilo); "kΩ", "kiloohm", "kiloohms"; | ||
@hectoohm: prefix!(hecto); "hΩ", "hectoohm", "hectoohms"; | ||
@decaohm: prefix!(deca); "daΩ", "decaohm", "decaohms"; | ||
/// Derived unit of electrical resistance. | ||
@ohm: prefix!(none); "Ω", "ohm", "ohms"; | ||
@deciohm: prefix!(deci); "dΩ", "deciohm", "deciohms"; | ||
@centiohm: prefix!(centi); "cΩ", "centiohm", "centiohms"; | ||
@milliohm: prefix!(milli); "mΩ", "milliohm", "milliohms"; | ||
@microohm: prefix!(micro); "µΩ", "microohm", "microohms"; | ||
@nanoohm: prefix!(nano); "nΩ", "nanoohm", "nanoohms"; | ||
@picoohm: prefix!(pico); "pΩ", "picoohm", "picoohms"; | ||
@femtoohm: prefix!(femto); "fΩ", "femtoohm", "femtoohms"; | ||
@attoohm: prefix!(atto); "aΩ", "attoohm", "attoohms"; | ||
@zeptoohm: prefix!(zepto); "zΩ", "zeptoohm", "zeptoohms"; | ||
@yoctoohm: prefix!(yocto); "yΩ", "yoctoohm", "yoctoohms"; | ||
|
||
@abohm: 1.0_E-9; "abΩ", "abohm", "abohms"; | ||
@statohm: 8.987_552_917_115_481_E11; "statΩ", "statohm", "statohms"; | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
storage_types! { | ||
use num::One; | ||
use si::quantities::*; | ||
use si::electric_current as i; | ||
use si::electric_potential as v; | ||
use si::electrical_resistance as r; | ||
use tests::Test; | ||
|
||
#[test] | ||
fn check_dimension() { | ||
let _: ElectricalResistance<V> = ElectricPotential::new::<v::volt>(V::one()) | ||
/ ElectricCurrent::new::<i::ampere>(V::one()); | ||
} | ||
|
||
#[test] | ||
fn check_units() { | ||
test::<v::yottavolt, i::ampere, r::yottaohm>(); | ||
test::<v::zettavolt, i::ampere, r::zettaohm>(); | ||
test::<v::exavolt, i::ampere, r::exaohm>(); | ||
test::<v::petavolt, i::ampere, r::petaohm>(); | ||
test::<v::teravolt, i::ampere, r::teraohm>(); | ||
test::<v::gigavolt, i::ampere, r::gigaohm>(); | ||
test::<v::megavolt, i::ampere, r::megaohm>(); | ||
test::<v::kilovolt, i::ampere, r::kiloohm>(); | ||
test::<v::hectovolt, i::ampere, r::hectoohm>(); | ||
test::<v::decavolt, i::ampere, r::decaohm>(); | ||
test::<v::volt, i::ampere, r::ohm>(); | ||
test::<v::decivolt, i::ampere, r::deciohm>(); | ||
test::<v::centivolt, i::ampere, r::centiohm>(); | ||
test::<v::millivolt, i::ampere, r::milliohm>(); | ||
test::<v::microvolt, i::ampere, r::microohm>(); | ||
test::<v::nanovolt, i::ampere, r::nanoohm>(); | ||
test::<v::picovolt, i::ampere, r::picoohm>(); | ||
test::<v::femtovolt, i::ampere, r::femtoohm>(); | ||
test::<v::attovolt, i::ampere, r::attoohm>(); | ||
test::<v::zeptovolt, i::ampere, r::zeptoohm>(); | ||
test::<v::yoctovolt, i::ampere, r::yoctoohm>(); | ||
|
||
test::<v::abvolt, i::abampere, r::abohm>(); | ||
test::<v::statvolt, i::statampere, r::statohm>(); | ||
|
||
fn test<U: v::Conversion<V>, I: i::Conversion<V>, R: r::Conversion<V>>() { | ||
Test::assert_approx_eq(&ElectricalResistance::new::<R>(V::one()), | ||
&(ElectricPotential::new::<U>(V::one()) | ||
/ ElectricCurrent::new::<I>(V::one()))); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.