Skip to content

Commit e74a296

Browse files
committed
Greatly expand docs
1 parent eb541ed commit e74a296

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

docs/src/api.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ ustrip
1717
dimension
1818
```
1919

20+
### Accessing dimensions
21+
2022
Utility functions to extract specific dimensions are as follows:
2123

2224
```@docs
@@ -44,6 +46,8 @@ The two main functions for working with units are `uparse` and `u_str`:
4446
uparse
4547
```
4648

49+
### Available units
50+
4751
The base SI units are as follows.
4852
Instead of calling directly, it is recommended to access them via
4953
the `@u_str` macro, which evaluates the expression

src/types.jl

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ which is by default a rational number.
1919
- `temperature`: temperature dimension (i.e., K^(temperature))
2020
- `luminosity`: luminosity dimension (i.e., cd^(luminosity))
2121
- `amount`: amount dimension (i.e., mol^(amount))
22+
23+
# Constructors
24+
25+
- `Dimensions(args...)`: Pass all the dimensions as arguments. `R` is set to `DEFAULT_DIM_TYPE`.
26+
- `Dimensions(; kws...)`: Pass a subset of dimensions as keyword arguments. `R` is set to `DEFAULT_DIM_TYPE`.
27+
- `Dimensions(::Type{R}; kws...)` or `Dimensions{R}(; kws...)`: Pass a subset of dimensions as keyword arguments, with the output type set to `Dimensions{R}`.
28+
- `Dimensions{R}(args...)`: Pass all the dimensions as arguments, with the output type set to `Dimensions{R}`.
29+
- `Dimensions{R}(d::Dimensions)`: Copy the dimensions from another `Dimensions` object, with the output type set to `Dimensions{R}`.
30+
2231
"""
2332
struct Dimensions{R <: Real}
2433
length::R
@@ -68,12 +77,21 @@ You can access specific dimensions with `ulength(q)`, `umass(q)`, `utime(q)`,
6877
`ucurrent(q)`, `utemperature(q)`, `uluminosity(q)`, and `uamount(q)`.
6978
7079
Severals operators in `Base` are extended to work with `Quantity` objects,
71-
including `*`, `+`, `-`, `/`, `^`, `sqrt`, and `cbrt`.
80+
including `*`, `+`, `-`, `/`, `abs`, `^`, `sqrt`, and `cbrt`, which manipulate
81+
dimensions according to the operation.
7282
7383
# Fields
7484
75-
- `value::T`: value of the quantity of some type `T`
76-
- `dimensions::Dimensions`: dimensions of the quantity
85+
- `value::T`: value of the quantity of some type `T`. Access with `ustrip(::Quantity)`
86+
- `dimensions::Dimensions{R}`: dimensions of the quantity with dimension type `R`. Access with `dimension(::Quantity)`
87+
88+
# Constructors
89+
90+
- `Quantity(x; kws...)`: Construct a quantity with value `x` and dimensions given by the keyword arguments. The value type is inferred from `x`. `R` is set to `DEFAULT_DIM_TYPE`.
91+
- `Quantity(x, ::Type{R}; kws...)`: Construct a quantity with value `x`. The dimensions parametric type is set to `R`.
92+
- `Quantity(x, d::Dimensions{R})`: Construct a quantity with value `x` and dimensions `d`.
93+
- `Quantity{T}(q::Quantity)`: Construct a quantity with value `q.value` and dimensions `q.dimensions`, but with value type converted to `T`.
94+
- `Quantity{T,R}(q::Quantity)`: Construct a quantity with value `q.value` and dimensions `q.dimensions`, but with value type converted to `T` and dimensions parametric type set to `R`.
7795
"""
7896
struct Quantity{T, R}
7997
value::T

0 commit comments

Comments
 (0)