@@ -191,7 +191,11 @@ A constant tuple of the existing abstract quantity types,
191
191
each as a tuple with (1) the abstract type,
192
192
(2) the base type, and (3) the default exported concrete type.
193
193
"""
194
- const ABSTRACT_QUANTITY_TYPES = ((AbstractQuantity, Number, Quantity), (AbstractGenericQuantity, Any, GenericQuantity), (AbstractRealQuantity, Real, RealQuantity))
194
+ const ABSTRACT_QUANTITY_TYPES = (
195
+ (AbstractQuantity, Number, Quantity),
196
+ (AbstractGenericQuantity, Any, GenericQuantity),
197
+ (AbstractRealQuantity, Real, RealQuantity)
198
+ )
195
199
196
200
"""
197
201
promote_quantity(::Type{<:UnionAbstractQuantity}, t::Type{<:Any})
@@ -202,7 +206,7 @@ If the current quantity type can already accommodate `t`, then the current type
202
206
promote_quantity (:: Type{<:Union{GenericQuantity,Quantity,RealQuantity}} , :: Type{<:Any} ) = GenericQuantity
203
207
promote_quantity (:: Type{<:Union{Quantity,RealQuantity}} , :: Type{<:Number} ) = Quantity
204
208
promote_quantity (:: Type{<:RealQuantity} , :: Type{<:Real} ) = RealQuantity
205
- promote_quantity (T, _) = t
209
+ promote_quantity (T, _) = T
206
210
207
211
for (type, base_type, _) in ABSTRACT_QUANTITY_TYPES
208
212
@eval begin
222
226
223
227
const DEFAULT_QUANTITY_TYPE = RealQuantity{DEFAULT_VALUE_TYPE, DEFAULT_DIM_TYPE}
224
228
225
- new_dimensions (:: Type{D} , dims... ) where {D<: AbstractDimensions } = constructorof (D)(dims... )
226
- new_quantity (:: Type{Q} , l, r) where {Q<: UnionAbstractQuantity } = constructorof (Q)(l, r)
229
+ @inline function new_dimensions (:: Type{D} , dims... ) where {D<: AbstractDimensions }
230
+ return constructorof (D)(dims... )
231
+ end
232
+ @inline function new_quantity (:: Type{Q} , val, dims) where {Q<: UnionAbstractQuantity }
233
+ Qout = promote_quantity (Q, typeof (val))
234
+ return constructorof (Qout)(val, dims)
235
+ end
227
236
228
237
dim_type (:: Type{Q} ) where {T,D<: AbstractDimensions ,Q<: UnionAbstractQuantity{T,D} } = D
229
238
dim_type (:: Type{<:UnionAbstractQuantity} ) = DEFAULT_DIM_TYPE
0 commit comments