在这里,我期望使用Int类型,但是得到Float:
julia> function test()
i::Int = 3.0
end
test (generic function with 1 method)
julia> typeof(test())
Float64
在这种情况下,返回类型为Int:
julia> function test()
i::Int = 3.0
i
end
test (generic function with 1 method)
julia> typeof(test())
Int64
这是正确的行为还是错误?
这是杰夫的名言:
因此在第一个示例中,等效于直接返回返回的内容,=
即3.0
:
julia> @code_lowered test()
CodeInfo(:(begin
nothing
SSAValue(0) = 3.0
i = (Core.typeassert)((Base.convert)(Main.Int, SSAValue(0)), Main.Int)
return SSAValue(0)
end))
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句