@@ -50,10 +50,10 @@ convfact(s::Units{S}, t::Units{S}) where {S} = 1
5050 convfact(T::Type, s::Units, t::Units)
5151Returns the appropriate conversion factor from unit `t` to unit `s` for the number type `T`.
5252"""
53- @generated function convfact (:: Type{T} , s:: Units , t:: Units ) where T
54- cf = convfact (s () , t () )
53+ function convfact (:: Type{T} , s:: Units , t:: Units ) where T
54+ cf = convfact (s, t)
5555 if cf isa AbstractFloat
56- F = floattype (T)
56+ F = convfact_floattype (T)
5757 # Since conversion factors only have Float64 precision,
5858 # there is no point in converting to BigFloat
5959 convert (F == BigFloat ? Float64 : F, cf)
@@ -62,17 +62,20 @@ Returns the appropriate conversion factor from unit `t` to unit `s` for the numb
6262 end
6363end
6464
65- function floattype (:: Type{T} ) where T
65+ function convfact_floattype (:: Type{T} ) where T
6666 # Use try-catch instead of hasmethod because a
6767 # fallback method might exist but throw an error
6868 try
69- F = float (real (T))
70- F <: AbstractFloat ? F : Float64
69+ _convfact_floattype (float (real (T)))
7170 catch
7271 Float64
7372 end
7473end
7574
75+ _convfact_floattype (:: Type ) = Float64
76+ _convfact_floattype (:: Type{Float16} ) = Float16
77+ _convfact_floattype (:: Type{Float32} ) = Float32
78+
7679"""
7780 uconvert(a::Units, x::Quantity{T,D,U}) where {T,D,U}
7881Convert a [`Unitful.Quantity`](@ref) to different units. The conversion will
0 commit comments