From 1d145897f1c29c6a66dad51053099d5be76bab86 Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Sun, 19 Nov 2023 23:04:10 +0000 Subject: [PATCH] Fix conversion to base type --- src/utils.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/utils.jl b/src/utils.jl index bb8f87e4..081d6ec3 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -25,7 +25,9 @@ end return output end -Base.convert(::Type{Number}, q::AbstractQuantity) = q +for (type, base_type, _) in ABSTRACT_QUANTITY_TYPES + @eval Base.convert(::Type{$base_type}, q::$type) = q +end function Base.convert(::Type{T}, q::UnionAbstractQuantity) where {T<:Number} @assert iszero(dimension(q)) "$(typeof(q)): $(q) has dimensions! Use `ustrip` instead." return convert(T, ustrip(q))