MathFunctions

Mixin template that introduces math functions operating on a quantity of value type N in the current scope. Each function imports module_ internally. This module should contain the math primitives that can operate on the variables of type N, such as sqrt, cbrt, pow and fabs.

Members

Functions

abs
Q abs(Q quantity)
cbrt
auto cbrt(Q quantity)
cubic
auto cubic(U unit)
nthRoot
auto nthRoot(Q quantity)
pow
auto pow(U unit)
sqrt
auto sqrt(Q quantity)

ditto

square
auto square(U unit)
Undocumented in source. Be warned that the author may not have intended to support it.

Examples

t
{
    enum meter = unit!("L");
    enum liter = 0.001 * meter * meter * meter;

    mixin MathFunctions!(real, "std.math");

    auto surface = 25 * square(meter);
    auto side = sqrt(surface);
    assert(side.value(meter).approxEqual(5));

    auto volume = 27 * liter;
    side = cbrt(volume);
    assert(side.value(meter).approxEqual(0.3));

    auto delta = -10 * meter;
    assert(abs(delta) == 10 * meter

Meta