From 86f87e352b95c3b4ab221f7d4e94118e84740d07 Mon Sep 17 00:00:00 2001 From: Alex Hamilton Date: Tue, 1 May 2018 19:47:32 -0500 Subject: [PATCH] Add electric charge quantity and associated units. --- src/si/electric_charge.rs | 97 +++++++++++++++++++++++++++++++++++++++ src/si/mod.rs | 1 + 2 files changed, 98 insertions(+) create mode 100644 src/si/electric_charge.rs diff --git a/src/si/electric_charge.rs b/src/si/electric_charge.rs new file mode 100644 index 00000000..3ad2e576 --- /dev/null +++ b/src/si/electric_charge.rs @@ -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 = ElectricCurrent::new::(V::one()) + * Time::new::(V::one()); + } + + #[test] + fn check_units() { + test::(); + test::(); + test::(); + test::(); + test::(); + test::(); + test::(); + test::(); + test::(); + test::(); + test::(); + test::(); + test::(); + test::(); + test::(); + test::(); + test::(); + test::(); + test::(); + test::(); + test::(); + + test::(); + test::(); + test::(); + + fn test, T: t::Conversion, Q: q::Conversion>() { + Test::assert_approx_eq(&ElectricCharge::new::(V::one()), + &(ElectricCurrent::new::(V::one()) * Time::new::(V::one()))); + } + } + } +} diff --git a/src/si/mod.rs b/src/si/mod.rs index b8237ad9..2776a4dc 100644 --- a/src/si/mod.rs +++ b/src/si/mod.rs @@ -29,6 +29,7 @@ system! { density::Density, electrical_resistance::ElectricalResistance, electrical_conductance::ElectricalConductance, + electric_charge::ElectricCharge, electric_current::ElectricCurrent, electric_potential::ElectricPotential, energy::Energy,