File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -42,3 +42,11 @@ Units.T
4242Units.L
4343Units.bar
4444```
45+
46+ ## Custom Units
47+
48+ You can define custom units with the ` @register_unit ` macro:
49+
50+ ``` @docs
51+ @register_unit
52+ ```
Original file line number Diff line number Diff line change 2020
2121Register a new unit under the given symbol to have
2222a particular value.
23+
24+ # Example
25+
26+ ```julia
27+ julia> @register_unit MyVolt 1.5u"V"
28+ ```
29+
30+ This will register a new unit `MyVolt` with a value of `1.5u"V"`.
31+ You can then use this unit in your calculations:
32+
33+ ```julia
34+ julia> x = 20us"MyVolt^2"
35+ 20.0 MyVolt²
36+
37+ julia> y = 2.5us"A"
38+ 2.5 A
39+
40+ julia> x * y^2 |> uconvert(us"W^2")
41+ 281.25 W²
42+
43+ julia> x * y^2 |> uconvert(us"W^2") |> sqrt |> uexpand
44+ 16.77050983124842 m² kg s⁻³
45+ ```
46+
2347"""
2448macro register_unit (symbol, value)
2549 return esc (_register_unit (symbol, value))
You can’t perform that action at this time.
0 commit comments