根据http://julia.readthedocs.org/en/latest/manual/integers-and-floating-point-numbers/,应该可以做到这一点:
julia> Float32(-1.5)
-1.5f0
Run Code Online (Sandbox Code Playgroud)
相反,我得到:
julia> Float32(-1.5)
ERROR: type cannot be constructed
Run Code Online (Sandbox Code Playgroud)
所有其他尝试使用此语法的尝试都会发生这种情况,例如 x = Int16(1)
我在0.3.10。
您使用的是0.3.10,但请阅读0.5的手册。在0.3手册中http://julia.readthedocs.org/en/release-0.3/manual/integers-and-floating-point-numbers/
Values can be converted to Float32 easily:
julia> float32(-1.5)
-1.5f0
julia> typeof(ans)
Float32
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
87 次 |
| 最近记录: |