Utilities

The two main general utilities for working with quantities are ustrip and dimension:

DynamicQuantities.dimensionFunction
dimension(q::AbstractQuantity)
dimension(q::AbstractGenericQuantity)
dimension(x)

Get the dimensions of a quantity, returning an AbstractDimensions object.

source

Accessing dimensions

Utility functions to extract specific dimensions are as follows:

DynamicQuantities.ulengthFunction
ulength(q::AbstractQuantity)
ulength(q::AbstractGenericQuantity)
ulength(d::AbstractDimensions)

Get the length dimension of a quantity (e.g., meters^(ulength)).

source
DynamicQuantities.umassFunction
umass(q::AbstractQuantity)
umass(q::AbstractGenericQuantity)
umass(d::AbstractDimensions)

Get the mass dimension of a quantity (e.g., kg^(umass)).

source
DynamicQuantities.utimeFunction
utime(q::AbstractQuantity)
utime(q::AbstractGenericQuantity)
utime(d::AbstractDimensions)

Get the time dimension of a quantity (e.g., s^(utime))

source
DynamicQuantities.ucurrentFunction
ucurrent(q::AbstractQuantity)
ucurrent(q::AbstractGenericQuantity)
ucurrent(d::AbstractDimensions)

Get the current dimension of a quantity (e.g., A^(ucurrent)).

source
DynamicQuantities.utemperatureFunction
utemperature(q::AbstractQuantity)
utemperature(q::AbstractGenericQuantity)
utemperature(d::AbstractDimensions)

Get the temperature dimension of a quantity (e.g., K^(utemperature)).

source
DynamicQuantities.uluminosityFunction
uluminosity(q::AbstractQuantity)
uluminosity(q::AbstractGenericQuantity)
uluminosity(d::AbstractDimensions)

Get the luminosity dimension of a quantity (e.g., cd^(uluminosity)).

source
DynamicQuantities.uamountFunction
uamount(q::AbstractQuantity)
uamount(q::AbstractGenericQuantity)
uamount(d::AbstractDimensions)

Get the amount dimension of a quantity (e.g., mol^(uamount)).

source
DynamicQuantities.promote_except_valueMethod
promote_except_value(q1::UnionAbstractQuantity, q2::UnionAbstractQuantity)

This applies a promotion to the quantity type, and the dimension type, but not the value type. This is necessary because sometimes we would want to multiply a quantity array with a scalar quantity, and wish to use promotion on the quantity type itself, but don't want to promote to a single value type.

source
DynamicQuantities.promote_quantity_on_quantityMethod
promote_quantity_on_quantity(Q1, Q2)

Defines the type hierarchy for quantities, returning the most specific type that is compatible with both input quantity types. For example, promote_quantity_on_quantity(Quantity, GenericQuantity) would return GenericQuantity, as it can store both Quantity and GenericQuantity values. Similarly, promote_quantity_on_quantity(RealQuantity, RealQuantity) would return RealQuantity, as that is the most specific type.

Also see promote_quantity_on_value.

source
DynamicQuantities.promote_quantity_on_valueMethod
promote_quantity_on_value(Q::Type, T::Type)

Find the next quantity type in the hierarchy that can accommodate the type T. If the current quantity type can already accommodate T, then the current type is returned. For example, promote_quantity_on_value(Quantity, Float64) would return Quantity, and promote_quantity_on_value(RealQuantity, String) would return GenericQuantity. The user should overload this function to define a custom type hierarchy.

Also see promote_quantity_on_quantity.

source

Internals

FixedRational

DynamicQuantities.FixedRationalType
FixedRational{T,den}

A rational number with a fixed denominator. Significantly faster than Rational{T}, as it never needs to compute the gcd apart from when printing. Access the denominator with denom(F) (which converts to T).

Fields

  • num: numerator of type T. The denominator is fixed to the type parameter den.
source
DynamicQuantities.denomFunction
denom(F::FixedRational)

Since den can be a different type than T, this function is used to get the denominator as a T.

source