6868# abstract number packages which may try to do the same thing.
6969# (which would lead to ambiguities)
7070const BASE_NUMERIC_TYPES = Union{
71- Bool, Int8, UInt8, Int16, UInt16, Int32, UInt32,
71+ Int8, UInt8, Int16, UInt16, Int32, UInt32,
7272 Int64, UInt64, Int128, UInt128, Float16, Float32,
73- Float64, BigFloat, BigInt, ComplexF16, ComplexF32,
73+ Float64, BigInt, ComplexF16, ComplexF32,
7474 ComplexF64, Complex{BigFloat}, Rational{Int8}, Rational{UInt8},
7575 Rational{Int16}, Rational{UInt16}, Rational{Int32}, Rational{UInt32},
7676 Rational{Int64}, Rational{UInt64}, Rational{Int128}, Rational{UInt128},
7777 Rational{BigInt},
7878}
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+
7983for (type, _, _) in ABSTRACT_QUANTITY_TYPES
8084 @eval begin
8185 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
8892 return with_type_parameters (promote_quantity (Q, T2), promote_type (T, T2), D)
8993 end
9094 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
91108end
92109
93110"""
0 commit comments