Skip to content

Commit

Permalink
Add electric charge quantity and associated units.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aehmlo committed May 23, 2018
1 parent 4b10223 commit 86f87e3
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
97 changes: 97 additions & 0 deletions src/si/electric_charge.rs
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())));
}
}
}
}
1 change: 1 addition & 0 deletions src/si/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ system! {
density::Density,
electrical_resistance::ElectricalResistance,
electrical_conductance::ElectricalConductance,
electric_charge::ElectricCharge,
electric_current::ElectricCurrent,
electric_potential::ElectricPotential,
energy::Energy,
Expand Down

0 comments on commit 86f87e3

Please sign in to comment.