我可以制作类型的"文字",Int64甚至Uint8在朱莉娅:
julia> typeof(8)
Int64
julia> typeof(0x08)
Uint8
Run Code Online (Sandbox Code Playgroud)
但是我还没有找到如何制作文字的类型Int8.我尝试了一些不同的东西:
julia> 8::Int8
ERROR: type: typeassert: expected Int8, got Int64
julia> 0x08::Int8
ERROR: type: typeassert: expected Int8, got Uint8
julia> convert(Int8, 8)
8
julia> typeof(ans)
Int8
Run Code Online (Sandbox Code Playgroud)
因此该convert功能的应用工作,但这是一个有点罗嗦的表达.我想知道是否有更简洁的东西,也许就像Rust的8i8.
我正在使用Julia 0.3.3,但Julia 0.4.x的答案也不错.
更方便的比 convert(Int8, 8)是Int8(8)各自int8(8)的早期版本.8i8存在少数字面符号的原因是它与并置的乘法相冲突.
julia> i8=8
8
julia> 3i8
24
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
320 次 |
| 最近记录: |