Skip to content

Commit

Permalink
Update Types documentation (#591)
Browse files Browse the repository at this point in the history
* Update `Types` documentation

Fixes #590

* Update conversion.md

* Update conversion.md

* Update docs/src/conversion.md

Co-authored-by: Sebastian Stock <[email protected]>

Co-authored-by: Sebastian Stock <[email protected]>
  • Loading branch information
cmichelenstrofer and sostock authored Nov 30, 2022
1 parent 49e6dde commit c799b0a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
14 changes: 7 additions & 7 deletions docs/src/conversion.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ ERROR: MethodError: no method matching f(::Vector{Quantity{Float64}})
## Advanced promotion mechanisms

There are some new types as of Unitful.jl v0.2.0 that enable some fairly sophisticated
promotion logic. Three concrete subtypes of [`Unitful.Units{N,D}`](@ref) are defined:
[`Unitful.FreeUnits{N,D}`](@ref), [`Unitful.ContextUnits{N,D,P}`](@ref), and
[`Unitful.FixedUnits{N,D}`](@ref).
promotion logic. Three concrete subtypes of [`Unitful.Units{N,D,A}`](@ref) are defined:
[`Unitful.FreeUnits{N,D,A}`](@ref), [`Unitful.ContextUnits{N,D,P,A}`](@ref), and
[`Unitful.FixedUnits{N,D,A}`](@ref).

Units defined in the Unitful.jl package itself are all `Unitful.FreeUnits{N,D}` objects.
Units defined in the Unitful.jl package itself are all `Unitful.FreeUnits{N,D,A}` objects.
The "free" in `FreeUnits` indicates that the object carries no information on its own about
how it should respond during promotion. Other code in Unitful dictates that by default,
quantities should promote to SI units. `FreeUnits` use the promotion mechanisms described
Expand All @@ -189,8 +189,8 @@ in prior versions of Unitful.
Sometimes, a package may want to default to a particular behavior for promotion, in the
presence of other packages that may require differing default behaviors. An example would be
a CAD package for nanoscale device design: it makes more sense to promote to nanometers or
microns than to meters. For this purpose we define `Unitful.ContextUnits{N,D,P}`. The `P` in
this type signature should be some type `Unitful.FreeUnits{M,D}` (the dimensions must be the
microns than to meters. For this purpose we define `Unitful.ContextUnits{N,D,P,A}`. The `P` in
this type signature should be some type `Unitful.FreeUnits{M,D,B}` (the dimensions must be the
same). We refer to this as the "context." `ContextUnits` may be easily instantiated by e.g.
`ContextUnits(nm, μm)` for a `nm` unit that will promote to `μm`. Here's an example:

Expand Down Expand Up @@ -245,7 +245,7 @@ kg μm
### FixedUnits

Sometimes, there may be times where it is required to disable automatic conversion between
quantities with different units. For this purpose there are `Unitful.FixedUnits{N,D}`.
quantities with different units. For this purpose there are `Unitful.FixedUnits{N,D,A}`.
Trying to add or compare two quantities with `FixedUnits` will throw an error, provided the
units are not the same. Note that you can still add/compare a quantity with `FixedUnits` to
a quantity with another kind of units; in that case, the result units (if applicable) are
Expand Down
16 changes: 8 additions & 8 deletions docs/src/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ to avoid overflow issues and general ugliness.

Usually, the user interacts only with `Units` objects, not `Unit` objects.
This is because generically, more than one unit is needed to describe a quantity.
An abstract type [`Unitful.Units{N,D}`](@ref) is defined, where `N` is always a tuple
of `Unit` objects, and `D` is a [`Unitful.Dimensions{N}`](@ref) object such as `𝐋`, the
object representing the length dimension.
An abstract type [`Unitful.Units{N,D,A}`](@ref) is defined, where `N` is always a tuple
of `Unit` objects, `D` is a [`Unitful.Dimensions{N}`](@ref) object such as `𝐋`, the
object representing the length dimension, and `A` is a translation for affine quantities.

Subtypes of `Unitful.Units{N,D}` are used to implement different behaviors
Subtypes of `Unitful.Units{N,D,A}` are used to implement different behaviors
for how to promote dimensioned quantities. The concrete subtypes have no fields and
are therefore immutable singletons. Currently implemented subtypes of `Unitful.Units{N,D}`
include [`Unitful.FreeUnits{N,D}`](@ref), [`Unitful.ContextUnits{N,D,P}`](@ref), and
[`Unitful.FixedUnits{N,D}`](@ref). Units defined in the Unitful.jl package itself are all
`Unitful.FreeUnits{N,D}` objects.
are therefore immutable singletons. Currently implemented subtypes of `Unitful.Units{N,D,A}`
include [`Unitful.FreeUnits{N,D,A}`](@ref), [`Unitful.ContextUnits{N,D,P,A}`](@ref), and
[`Unitful.FixedUnits{N,D,A}`](@ref). Units defined in the Unitful.jl package itself are all
`Unitful.FreeUnits{N,D,A}` objects.

Finally, we define physical quantity types as [`Quantity{T<:Number, D, U}`](@ref), where
`D :: Dimensions` and `U <: Units`. By putting units in the type signature of a
Expand Down

0 comments on commit c799b0a

Please sign in to comment.