@@ -264,6 +264,8 @@ function map_dimensions(op::O, l::SymbolicDimensions{L}, r::SymbolicDimensions{R
264264 return SymbolicDimensions (I, V)
265265end
266266
267+ const DEFAULT_SYMBOLIC_QUANTITY_TYPE = with_type_parameters (DEFAULT_QUANTITY_TYPE, DEFAULT_VALUE_TYPE, SymbolicDimensions{DEFAULT_DIM_BASE_TYPE})
268+
267269"""
268270 SymbolicUnitsParse
269271
@@ -277,7 +279,8 @@ module SymbolicUnitsParse
277279 import .. SYMBOL_CONFLICTS
278280 import .. SymbolicDimensions
279281
280- import ... RealQuantity
282+ import ... constructorof
283+ import ... DEFAULT_SYMBOLIC_QUANTITY_TYPE
281284 import ... DEFAULT_VALUE_TYPE
282285 import ... DEFAULT_DIM_BASE_TYPE
283286
@@ -287,7 +290,8 @@ module SymbolicUnitsParse
287290 import .. SYMBOL_CONFLICTS
288291 import .. SymbolicDimensions
289292
290- import .. RealQuantity
293+ import .. constructorof
294+ import .. DEFAULT_SYMBOLIC_QUANTITY_TYPE
291295 import .. DEFAULT_VALUE_TYPE
292296 import .. DEFAULT_DIM_BASE_TYPE
293297
@@ -299,11 +303,11 @@ module SymbolicUnitsParse
299303 CONSTANT_SYMBOLS_EXIST[] || lock (CONSTANT_SYMBOLS_LOCK) do
300304 CONSTANT_SYMBOLS_EXIST[] && return nothing
301305 for unit in setdiff (CONSTANT_SYMBOLS, SYMBOL_CONFLICTS)
302- @eval const $ unit = RealQuantity (DEFAULT_VALUE_TYPE (1.0 ), SymbolicDimensions{DEFAULT_DIM_BASE_TYPE}; $ (unit)= 1 )
306+ @eval const $ unit = constructorof (DEFAULT_SYMBOLIC_QUANTITY_TYPE) (DEFAULT_VALUE_TYPE (1.0 ), SymbolicDimensions{DEFAULT_DIM_BASE_TYPE}; $ (unit)= 1 )
303307 end
304308 # Evaluate conflicting symbols to non-symbolic form:
305309 for unit in SYMBOL_CONFLICTS
306- @eval const $ unit = convert (RealQuantity{DEFAULT_VALUE_TYPE,SymbolicDimensions} , EagerConstants.$ unit)
310+ @eval const $ unit = convert (DEFAULT_SYMBOLIC_QUANTITY_TYPE , EagerConstants.$ unit)
307311 end
308312 CONSTANT_SYMBOLS_EXIST[] = true
309313 end
@@ -318,7 +322,7 @@ module SymbolicUnitsParse
318322 UNIT_SYMBOLS_EXIST[] || lock (UNIT_SYMBOLS_LOCK) do
319323 UNIT_SYMBOLS_EXIST[] && return nothing
320324 for unit in UNIT_SYMBOLS
321- @eval const $ unit = RealQuantity (DEFAULT_VALUE_TYPE (1.0 ), SymbolicDimensions{DEFAULT_DIM_BASE_TYPE}; $ (unit)= 1 )
325+ @eval const $ unit = constructorof (DEFAULT_SYMBOLIC_QUANTITY_TYPE) (DEFAULT_VALUE_TYPE (1.0 ), SymbolicDimensions{DEFAULT_DIM_BASE_TYPE}; $ (unit)= 1 )
322326 end
323327 UNIT_SYMBOLS_EXIST[] = true
324328 end
@@ -329,27 +333,27 @@ module SymbolicUnitsParse
329333 sym_uparse(raw_string::AbstractString)
330334
331335 Parse a string containing an expression of units and return the
332- corresponding `RealQuantity ` object with `Float64` value.
336+ corresponding `Quantity ` object with `Float64` value.
333337 However, that unlike the regular `u"..."` macro, this macro uses
334338 `SymbolicDimensions` for the dimension type, which means that all units and
335339 constants are stored symbolically and will not automatically expand to SI
336340 units. For example, `sym_uparse("km/s^2")` would be parsed to
337- `RealQuantity (1.0, SymbolicDimensions, km=1, s=-2)`.
341+ `Quantity (1.0, SymbolicDimensions, km=1, s=-2)`.
338342
339343 Note that inside this expression, you also have access to the `Constants`
340344 module. So, for example, `sym_uparse("Constants.c^2 * Hz^2")` would evaluate to
341- `RealQuantity (1.0, SymbolicDimensions, c=2, Hz=2)`. However, note that due to
345+ `Quantity (1.0, SymbolicDimensions, c=2, Hz=2)`. However, note that due to
342346 namespace collisions, a few physical constants are automatically converted.
343347 """
344348 function sym_uparse (raw_string:: AbstractString )
345349 _generate_unit_symbols ()
346350 Constants. _generate_unit_symbols ()
347351 raw_result = eval (Meta. parse (raw_string))
348- return copy (as_quantity (raw_result)):: RealQuantity{DEFAULT_VALUE_TYPE,SymbolicDimensions{DEFAULT_DIM_BASE_TYPE}}
352+ return copy (as_quantity (raw_result)):: DEFAULT_SYMBOLIC_QUANTITY_TYPE
349353 end
350354
351- as_quantity (q:: RealQuantity ) = q
352- as_quantity (x:: Number ) = RealQuantity ( convert (DEFAULT_VALUE_TYPE , x), SymbolicDimensions{DEFAULT_DIM_BASE_TYPE} )
355+ as_quantity (q:: DEFAULT_SYMBOLIC_QUANTITY_TYPE ) = q
356+ as_quantity (x:: Number ) = convert (DEFAULT_SYMBOLIC_QUANTITY_TYPE , x)
353357 as_quantity (x) = error (" Unexpected type evaluated: $(typeof (x)) " )
354358end
355359
@@ -359,15 +363,15 @@ import .SymbolicUnitsParse: sym_uparse
359363 us"[unit expression]"
360364
361365Parse a string containing an expression of units and return the
362- corresponding `RealQuantity ` object with `Float64` value. However,
366+ corresponding `Quantity ` object with `Float64` value. However,
363367unlike the regular `u"..."` macro, this macro uses `SymbolicDimensions`
364368for the dimension type, which means that all units and constants
365369are stored symbolically and will not automatically expand to SI units.
366- For example, `us"km/s^2"` would be parsed to `RealQuantity (1.0, SymbolicDimensions, km=1, s=-2)`.
370+ For example, `us"km/s^2"` would be parsed to `Quantity (1.0, SymbolicDimensions, km=1, s=-2)`.
367371
368372Note that inside this expression, you also have access to the `Constants`
369373module. So, for example, `us"Constants.c^2 * Hz^2"` would evaluate to
370- `RealQuantity (1.0, SymbolicDimensions, c=2, Hz=2)`. However, note that due to
374+ `Quantity (1.0, SymbolicDimensions, c=2, Hz=2)`. However, note that due to
371375namespace collisions, a few physical constants are automatically converted.
372376"""
373377macro us_str (s)
0 commit comments