Utilities
The two main general utilities for working with quantities are ustrip and dimension:
DynamicQuantities.ustrip — Function
ustrip(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.
ustrip(unit::UnionAbstractQuantity, q::UnionAbstractQuantity)Convert quantity q to the units specified by unit, then strip the units. This is equivalent to ustrip(q / unit), but also verifies the dimensions are compatible.
Examples
julia> ustrip(u"km", 1000u"m")
1.0
julia> ustrip(u"s", 1u"minute")
60.0
julia> ustrip.(u"km", [1000u"m", 2000u"m"])
2-element Vector{Float64}:
1.0
2.0sourceustrip(unit::AffineUnit, q::UnionAbstractQuantity)Convert a quantity q to the numerical value in terms of affine units specified by unit, then strip the units. This allows getting the numerical value in terms of degrees Celsius or Fahrenheit.
Examples
julia> ustrip(ua"degC", 27ua"degC")
27.0
julia> ustrip(ua"degF", 300u"K")
80.33000000000003sourceDynamicQuantities.dimension — Function
dimension(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 — Function
ulength(q::AbstractQuantity)
ulength(q::AbstractGenericQuantity)
ulength(d::AbstractDimensions)Get the length dimension of a quantity (e.g., meters^(ulength)).
sourceDynamicQuantities.umass — Function
umass(q::AbstractQuantity)
umass(q::AbstractGenericQuantity)
umass(d::AbstractDimensions)Get the mass dimension of a quantity (e.g., kg^(umass)).
sourceDynamicQuantities.utime — Function
utime(q::AbstractQuantity)
utime(q::AbstractGenericQuantity)
utime(d::AbstractDimensions)Get the time dimension of a quantity (e.g., s^(utime))
sourceDynamicQuantities.ucurrent — Function
ucurrent(q::AbstractQuantity)
ucurrent(q::AbstractGenericQuantity)
ucurrent(d::AbstractDimensions)Get the current dimension of a quantity (e.g., A^(ucurrent)).
sourceDynamicQuantities.utemperature — Function
utemperature(q::AbstractQuantity)
utemperature(q::AbstractGenericQuantity)
utemperature(d::AbstractDimensions)Get the temperature dimension of a quantity (e.g., K^(utemperature)).
sourceDynamicQuantities.uluminosity — Function
uluminosity(q::AbstractQuantity)
uluminosity(q::AbstractGenericQuantity)
uluminosity(d::AbstractDimensions)Get the luminosity dimension of a quantity (e.g., cd^(uluminosity)).
sourceDynamicQuantities.uamount — Function
uamount(q::AbstractQuantity)
uamount(q::AbstractGenericQuantity)
uamount(d::AbstractDimensions)Get the amount dimension of a quantity (e.g., mol^(uamount)).
sourceDynamicQuantities.promote_except_value — Method
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.
sourceDynamicQuantities.promote_quantity_on_quantity — Method
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.
DynamicQuantities.promote_quantity_on_value — Method
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.
Internals
FixedRational
DynamicQuantities.FixedRational — Type
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 typeT. The denominator is fixed to the type parameterden.
DynamicQuantities.FRInt32 — Type
DynamicQuantities.FRInt8 — Type
DynamicQuantities.denom — Function
denom(F::FixedRational)Since den can be a different type than T, this function is used to get the denominator as a T.