I have a tuple of numerical types. I am looking for the type that would result after combining these types with +
, *
, sqrt
, log
. Is there a function to do this?
Context: I am writing a function (too complex for an MWE here, generated code) that uses these operations, and I want type stability. Primarily it would be called with Float64
, but other float types and the occasional Integer
should work, too.
I could use promote_type
, except that log(::Int) isa Float64
. I can work around this with something like
julia> function promote_alg(Ts...)
S = promote_type(Ts...)
S <: Integer ? promote_type(S, Float64) : S
end
promote_alg (generic function with 2 methods)
julia> promote_alg(Int, Float64, Float32)
Float64
julia> promote_alg(Float16, Float32, Float32)
Float32
julia> promote_alg(Int, Int, Int8)
Float64
but I wonder if this has a name in Base
.