|
49 | 49 | # or even <:AbstractFloat, as it could conflict with other
|
50 | 50 | # abstract number packages which may try to do the same thing.
|
51 | 51 | # (which would lead to ambiguities)
|
52 |
| -for (type, _, _) in ABSTRACT_QUANTITY_TYPES, numeric_type in ( |
| 52 | +const BASE_NUMERIC_TYPES = Union{ |
53 | 53 | Bool, Int8, UInt8, Int16, UInt16, Int32, UInt32,
|
54 | 54 | Int64, UInt64, Int128, UInt128, Float16, Float32,
|
55 | 55 | Float64, BigFloat, BigInt, ComplexF16, ComplexF32,
|
56 | 56 | ComplexF64, Complex{BigFloat}, Rational{Int8}, Rational{UInt8},
|
57 | 57 | Rational{Int16}, Rational{UInt16}, Rational{Int32}, Rational{UInt32},
|
58 | 58 | Rational{Int64}, Rational{UInt64}, Rational{Int128}, Rational{UInt128},
|
59 | 59 | Rational{BigInt},
|
60 |
| -) |
61 |
| - @eval begin |
62 |
| - function Base.promote_rule(::Type{Q}, ::Type{$numeric_type}) where {T,D,Q<:$type{T,D}} |
63 |
| - return with_type_parameters(Q, promote_type(T,$numeric_type), D) |
64 |
| - end |
65 |
| - function Base.convert(::Type{Q}, x::$numeric_type) where {T,D,Q<:$type{T,D}} |
66 |
| - return new_quantity(Q, convert(T, x), D()) |
67 |
| - end |
| 60 | +} |
| 61 | +for (type, _, _) in ABSTRACT_QUANTITY_TYPES |
| 62 | + @eval function Base.promote_rule(::Type{Q}, ::Type{T2}) where {T,D,Q<:$type{T,D},T2<:BASE_NUMERIC_TYPES} |
| 63 | + return with_type_parameters(Q, promote_type(T, T2), D) |
| 64 | + end |
| 65 | + @eval function Base.convert(::Type{Q}, x::BASE_NUMERIC_TYPES) where {T,D,Q<:$type{T,D}} |
| 66 | + return new_quantity(Q, convert(T, x), D()) |
68 | 67 | end
|
69 | 68 | end
|
70 | 69 | function Base.promote_rule(::Type{<:AbstractQuantity}, ::Type{<:Number})
|
|
0 commit comments