Skip to content
FutureBlitz

    Install

    Import std.math.units

    std.math.units

    Typed units: a Quantity is a value in SI's base units, meters, kilograms, and seconds, with the exponents of its length, mass, and time as Const type arguments, so the compiler keeps Meters apart from Seconds and works out what Meters / Seconds is. Each unit is an Alias of its Quantity: Meters is Quantity<1, 0, 0>, and MetersPerSecond Quantity<1, 0, -1>. + and - take quantities of the same units, * and / any two, adding or taking away their exponents, and a Double scales one.

    std/math/units.fb

    Types

    Quantity 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.

    std/math/units.fb, line 12

    • 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 #

      The value to start from, like 0 for a number, "" for a String, or an empty collection.

      Doc from std.core.interfaces.Defaultable.DefaultValue.

    • 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 comes before b.

      Doc from std.core.interfaces.Comparable.Operator<.

    Meters alias

    Public Alias Meters = Quantity<1, 0, 0>

    The base units, and those made from them.

    std/math/units.fb, line 98

    Kilograms alias

    Public Alias Kilograms = Quantity<0, 1, 0>

    Kilograms, of mass.

    std/math/units.fb, line 100

    Seconds alias

    Public Alias Seconds = Quantity<0, 0, 1>

    Seconds, of time.

    std/math/units.fb, line 102

    SquareMeters alias

    Public Alias SquareMeters = Quantity<2, 0, 0>

    Square meters, of area.

    std/math/units.fb, line 104

    CubicMeters alias

    Public Alias CubicMeters = Quantity<3, 0, 0>

    Cubic meters, of volume.

    std/math/units.fb, line 106

    MetersPerSecond alias

    Public Alias MetersPerSecond = Quantity<1, 0, -1>

    Meters per second, of speed.

    std/math/units.fb, line 108

    MetersPerSecondSquared alias

    Public Alias MetersPerSecondSquared = Quantity<1, 0, -2>

    Meters per second squared, of acceleration.

    std/math/units.fb, line 110

    Hertz alias

    Public Alias Hertz = Quantity<0, 0, -1>

    Hertz, a time each second, of frequency.

    std/math/units.fb, line 112

    Newtons alias

    Public Alias Newtons = Quantity<1, 1, -2>

    Newtons, of force.

    std/math/units.fb, line 114

    NewtonSeconds alias

    Public Alias NewtonSeconds = Quantity<1, 1, -1>

    Newton seconds, of momentum.

    std/math/units.fb, line 116

    Joules alias

    Public Alias Joules = Quantity<2, 1, -2>

    Joules, of energy.

    std/math/units.fb, line 118

    Watts alias

    Public Alias Watts = Quantity<2, 1, -3>

    Watts, of power.

    std/math/units.fb, line 120

    Pascals alias

    Public Alias Pascals = Quantity<-1, 1, -2>

    Pascals, of pressure.

    std/math/units.fb, line 122

    KilogramsPerCubicMeter alias

    Public Alias KilogramsPerCubicMeter = Quantity<-3, 1, 0>

    Kilograms per cubic meter, of density.

    std/math/units.fb, line 124

    Functions

    Abs function

    Public Function Abs<Const L: Int, Const M: Int, Const T: Int>(q: Quantity<L, M, T>): Quantity<L, M, T>

    How big a quantity is, of the same units, as the scalar Abs has it: 0 for -0.

    std/math/units.fb, line 92

    Kilometers function

    Public Function Kilometers(value: Double): Meters

    Other units, as the base units' quantities.

    std/math/units.fb, line 127

    Centimeters function

    Public Function Centimeters(value: Double): Meters

    The meters of value centimeters.

    std/math/units.fb, line 129

    Millimeters function

    Public Function Millimeters(value: Double): Meters

    The meters of value millimeters.

    std/math/units.fb, line 131

    Grams function

    Public Function Grams(value: Double): Kilograms

    The kilograms of value grams.

    std/math/units.fb, line 133

    Tonnes function

    Public Function Tonnes(value: Double): Kilograms

    The kilograms of value tonnes.

    std/math/units.fb, line 135

    Milliseconds function

    Public Function Milliseconds(value: Double): Seconds

    The seconds of value milliseconds.

    std/math/units.fb, line 137

    Minutes function

    Public Function Minutes(value: Double): Seconds

    The seconds of value minutes.

    std/math/units.fb, line 139

    Hours function

    Public Function Hours(value: Double): Seconds

    The seconds of value hours.

    std/math/units.fb, line 141

    KilometersPerHour function

    Public Function KilometersPerHour(value: Double): MetersPerSecond

    The meters per second of value kilometers per hour.

    std/math/units.fb, line 143

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