Skip to content

Commit 605f21d

Browse files
committed
docs: mention two-argument ustrip
1 parent 31cb999 commit 605f21d

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,25 @@ julia> ulength(x)
163163
```
164164

165165
Finally, you can strip units with `ustrip`:
166-
166+
167167
```julia
168168
julia> ustrip(x)
169169
0.2
170170
```
171171

172+
You can also convert a quantity to a desired unit and *then* strip the units
173+
using a two-argument version of `ustrip`:
174+
175+
```julia
176+
julia> ustrip(u"km", 1000u"m")
177+
1.0
178+
179+
julia> ustrip(u"minute", 60u"s")
180+
1.0
181+
```
182+
183+
This is equivalent to `ustrip(quantity / unit)` but performs dimension checks first.
184+
172185
### Constants
173186

174187
There are a variety of physical constants accessible
@@ -298,6 +311,16 @@ julia> freezing = 32ua"degF"
298311
273.15 K
299312
```
300313

314+
These are regular `Quantity{Float64,Dimensions{...}}` objects, meaning that you
315+
can use them in the same way as regular quantities, including taking differences.
316+
317+
To convert back, you can use the two-argument `ustrip` with the particular affine unit:
318+
319+
```julia
320+
julia> ustrip(ua"degC", 295.15u"K")
321+
22.0
322+
```
323+
301324
### Arrays
302325

303326
For working with an array of quantities that have the same dimensions,
@@ -439,3 +462,4 @@ julia> @btime f($q8);
439462
julia> @btime f($q32);
440463
1.883 μs (4 allocations: 39.12 KiB)
441464
```
465+

0 commit comments

Comments
 (0)