lumen

SI derived units.

Examples

auto work(Quantity!newton force, Quantity!metre displacement)
{
    return force * displacement;
}

Quantity!(mole, V) idealGasAmount(V)(Quantity!(pascal, V) pressure,
    Quantity!(pow!3(meter), V) volume, Quantity!(kelvin, V) temperature)
{
    enum R = 8.314471 * joule / (kelvin * mole);
    return (pressure * volume) / (temperature * R);
}

enum forcef = 1.0f * newton;
enum force = 1.0 * newton;

// compare quantities with different value types
assert(forcef == force);
static assert(forcef == force);

enum displacement = 1.0 * metre;
enum Quantity!joule e = work(force, displacement);
static assert(e == 1.0 * joule);

enum T = (273. + 37.) * kelvin;
enum p = 1.01325e5 * pascal;
enum r = 0.5e-6 * meter;
enum V = (4.0 / 3.0) * 3.141592 * r.pow!3;
enum n = idealGasAmount!double(p, V, T); // Need to explicitly specify double due to @@BUG5801@@.
// TODO is this needed: static assert(n == 0xb.dd95ef4ddcb82f7p-59 * mole);

static assert((2 * kilogram).convert!gram == 2000 * gram);
static assert((2000 * gram).convert!kilogram == 2 * kilogram);
static assert((1000 * newton).convert!(milli!newton) == 1000000 * milli!newton);
static assert((2000000 * gram * meter / second.pow!2).convert!(kilo!newton) == 2 * kilo!newton);
static assert((1234.0 * micro!newton / milli!metre.pow!2).convert!pascal == 1234.0 * pascal);

Meta