Skip to content

Commit 284586f

Browse files
committed
feat: 2-arg ustrip for affine units
1 parent bbba01e commit 284586f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/affine_dimensions.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,23 @@ function aff_uparse(s::AbstractString)
114114
ex = AffineUnits.map_to_scope(Meta.parse(s))
115115
return eval(ex)::AffineUnit{DEFAULT_DIM_BASE_TYPE}
116116
end
117+
118+
"""
119+
ustrip(unit::AffineUnit, q::UnionAbstractQuantity)
120+
121+
Convert a quantity `q` to the numerical value in terms of affine units specified by `unit`,
122+
then strip the units. This allows getting the numerical value in terms of degrees Celsius or Fahrenheit.
123+
124+
# Examples
125+
```julia
126+
julia> ustrip(ua"degC", 27ua"degC")
127+
27.0
128+
129+
julia> ustrip(ua"degF", 300u"K")
130+
80.33000000000003
131+
```
132+
"""
133+
function ustrip(unit::AffineUnit, q::UnionAbstractQuantity)
134+
unit.basedim == dimension(q) || throw(DimensionError(unit, q))
135+
return (ustrip(q) - unit.offset) / unit.scale
136+
end

0 commit comments

Comments
 (0)