Is there a good way to obtain the type that would result from dividing two numbers of different types? promote_type
basically gives you this for addition, but not so much for division since promote_type(Int64, Int64) == Int64
but dividing two ints gives a float.
typeof(x/x)
I suppose would work, but seems inelegant, and Base.return_type
returns an array of types, which also seems inelegant
One option is
julia> Base.promote_op(/, Int, Int)
Float64
(This uses Core.Compiler.return_type
under the hood)
That looks perfect, thanks!
Last updated: Oct 02 2023 at 04:34 UTC