68
68
# abstract number packages which may try to do the same thing.
69
69
# (which would lead to ambiguities)
70
70
const BASE_NUMERIC_TYPES = Union{
71
- Bool, Int8, UInt8, Int16, UInt16, Int32, UInt32,
71
+ Int8, UInt8, Int16, UInt16, Int32, UInt32,
72
72
Int64, UInt64, Int128, UInt128, Float16, Float32,
73
- Float64, BigFloat, BigInt, ComplexF16, ComplexF32,
73
+ Float64, BigInt, ComplexF16, ComplexF32,
74
74
ComplexF64, Complex{BigFloat}, Rational{Int8}, Rational{UInt8},
75
75
Rational{Int16}, Rational{UInt16}, Rational{Int32}, Rational{UInt32},
76
76
Rational{Int64}, Rational{UInt64}, Rational{Int128}, Rational{UInt128},
77
77
Rational{BigInt},
78
78
}
79
+ # The following types require explicit promotion,
80
+ # as putting them in a union type creates different ambiguities
81
+ const AMBIGUOUS_NUMERIC_TYPES = (Bool, BigFloat)
82
+
79
83
for (type, _, _) in ABSTRACT_QUANTITY_TYPES
80
84
@eval begin
81
85
function Base. convert (:: Type{Q} , x:: BASE_NUMERIC_TYPES ) where {T,D,Q<: $type{T,D} }
@@ -88,6 +92,19 @@ for (type, _, _) in ABSTRACT_QUANTITY_TYPES
88
92
return with_type_parameters (promote_quantity (Q, T2), promote_type (T, T2), D)
89
93
end
90
94
end
95
+ for numeric_type in AMBIGUOUS_NUMERIC_TYPES
96
+ @eval begin
97
+ function Base. convert (:: Type{Q} , x:: $numeric_type ) where {T,D,Q<: $type{T,D} }
98
+ return new_quantity (Q, convert (T, x), D ())
99
+ end
100
+ function Base. promote_rule (:: Type{Q} , :: Type{$numeric_type} ) where {T,D,Q<: $type{T,D} }
101
+ return with_type_parameters (promote_quantity (Q, $ numeric_type), promote_type (T, $ numeric_type), D)
102
+ end
103
+ function Base. promote_rule (:: Type{$numeric_type} , :: Type{Q} ) where {T,D,Q<: $type{T,D} }
104
+ return with_type_parameters (promote_quantity (Q, $ numeric_type), promote_type (T, $ numeric_type), D)
105
+ end
106
+ end
107
+ end
91
108
end
92
109
93
110
"""
0 commit comments