Utilities
The two main general utilities for working with quantities are ustrip and dimension:
DynamicQuantities.ustrip — Functionustrip(q::AbstractQuantity)
ustrip(q::AbstractGenericQuantity)Remove the units from a quantity.
If using symbolic dimensions, you might also consider using ustripexpand to first convert to SI base units before stripping.
DynamicQuantities.dimension — Functiondimension(q::AbstractQuantity)
dimension(q::AbstractGenericQuantity)
dimension(x)Get the dimensions of a quantity, returning an AbstractDimensions object.
Accessing dimensions
Utility functions to extract specific dimensions are as follows:
DynamicQuantities.ulength — Functionulength(q::AbstractQuantity)
ulength(q::AbstractGenericQuantity)
ulength(d::AbstractDimensions)Get the length dimension of a quantity (e.g., meters^(ulength)).
DynamicQuantities.umass — Functionumass(q::AbstractQuantity)
umass(q::AbstractGenericQuantity)
umass(d::AbstractDimensions)Get the mass dimension of a quantity (e.g., kg^(umass)).
DynamicQuantities.utime — Functionutime(q::AbstractQuantity)
utime(q::AbstractGenericQuantity)
utime(d::AbstractDimensions)Get the time dimension of a quantity (e.g., s^(utime))
DynamicQuantities.ucurrent — Functionucurrent(q::AbstractQuantity)
ucurrent(q::AbstractGenericQuantity)
ucurrent(d::AbstractDimensions)Get the current dimension of a quantity (e.g., A^(ucurrent)).
DynamicQuantities.utemperature — Functionutemperature(q::AbstractQuantity)
utemperature(q::AbstractGenericQuantity)
utemperature(d::AbstractDimensions)Get the temperature dimension of a quantity (e.g., K^(utemperature)).
DynamicQuantities.uluminosity — Functionuluminosity(q::AbstractQuantity)
uluminosity(q::AbstractGenericQuantity)
uluminosity(d::AbstractDimensions)Get the luminosity dimension of a quantity (e.g., cd^(uluminosity)).
DynamicQuantities.uamount — Functionuamount(q::AbstractQuantity)
uamount(q::AbstractGenericQuantity)
uamount(d::AbstractDimensions)Get the amount dimension of a quantity (e.g., mol^(uamount)).
DynamicQuantities.promote_except_value — Methodpromote_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.
DynamicQuantities.promote_quantity_on_quantity — Methodpromote_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.
DynamicQuantities.promote_quantity_on_value — Methodpromote_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.
Internals
FixedRational
DynamicQuantities.FixedRational — TypeFixedRational{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 typeT. The denominator is fixed to the type parameterden.
DynamicQuantities.denom — Functiondenom(F::FixedRational)Since den can be a different type than T, this function is used to get the denominator as a T.