在元组 Julia 中推动一个大浮点数

问题描述

我试图将一个大浮点数“推”到一个元组中。但得到以下错误

# where test() is a function with big floats as values

store = Tuple{Any,Any}][]
for i in 1:10
    push!(store,test(i))
end
store

enter image description here

错误消息提到 convert() 作为解决方案,但我不确定如何转换 test()

解决方法

您不能将 BigFloat 推送到仅接受 Tuples 的容器中。您的容器必须接受 BigFloat,因此请使用以下命令对其进行初始化:

store = BigFloat[]

另请注意,您可以只写:

store = test.(1:10)