For any subtype of Number
, zero(T)
is just a shorthand for convert(T, 0)
. See: https://github.com/JuliaLang/julia/blob/6a23e234e6cc5b4361b5f88614a9ed423dc2c12a/base/number.jl#L238
And for any type T, if you haven’t defined a constructor T(x)
, then it will also fall back to convert(T, x)
. See: https://github.com/JuliaLang/julia/blob/6a23e234e6cc5b4361b5f88614a9ed423dc2c12a/base/sysimg.jl#L114