Skip to content
FutureBlitz

    Install

    Import std.math.units

    Quantity

    std.math.units

    struct

    Public Struct Quantity<Const L: Int, Const M: Int, Const T: Int> Implements Comparable, Hashable, Printable, Defaultable

    A value of so many meters, kilograms, and seconds, to the powers L, M, and T: 5 m/s^2 is a Quantity<1, 0, -2> of Value 5.

    Examples

    Local distance = Kilometers(3)
    Local time = Minutes(10)
    Local speed: MetersPerSecond = distance / time
    Expect(IsClose(speed.Value, 5.0))
    Local total: Meters = distance + Meters(500)
    Expect(total.Value == 3500.0)
    // distance + time doesn't compile: they're different units.

    std/math/units.fb, line 38

    • Public Field Value: Double field #

      The value in the base units, and the units they make.

    • Public Static Method Zero(): Quantity<L, M, T> static method #

      A quantity of 0 of these units.

    • Public Static Method DefaultValue(): Quantity<L, M, T> static method #

      Zero, in its units.

    • Public Method ToString(): String method #

      The value and its units, as SI writes them: "9.8 m/s^2", "3 kg m/s^2", "50 1/s", or "4 kg/(m s^2)", and the value alone without any.

    • Operator +(a: Quantity<L, M, T>, b: Quantity<L, M, T>): Quantity<L, M, T> operator #

      a plus b.

    • Operator -(a: Quantity<L, M, T>, b: Quantity<L, M, T>): Quantity<L, M, T> operator #

      a minus b.

    • Operator -(a: Quantity<L, M, T>): Quantity<L, M, T> operator #

      a negated.

    • Operator *(a: Quantity<L, M, T>, scale: Double): Quantity<L, M, T> operator #

      a times scale.

    • Operator *(scale: Double, a: Quantity<L, M, T>): Quantity<L, M, T> operator #

      scale times a.

    • Operator /(a: Quantity<L, M, T>, scale: Double): Quantity<L, M, T> operator #

      a divided by scale.

    • Operator *<Const L2: Int, Const M2: Int, Const T2: Int>(a: Quantity<L, M, T>, b: Quantity<L2, M2, T2>): Quantity<L + L2, M + M2, T + T2> operator #

      a times b, whose exponents are the sum of a's and b's.

    • Operator /<Const L2: Int, Const M2: Int, Const T2: Int>(a: Quantity<L, M, T>, b: Quantity<L2, M2, T2>): Quantity<L - L2, M - M2, T - T2> operator #

      a divided by b, whose exponents are the difference of a's and b's.

    • Operator <(a: Quantity<L, M, T>, b: Quantity<L, M, T>): Bool operator #

      Whether a is less than b, in the same units.

    Report an issue with this page or with FutureBlitz on GitHub.