How to create an Int8 literal in Julia?

I can make literals like Int64and even Uint8in Julia:

julia> typeof(8)
Int64

julia> typeof(0x08)
Uint8

But I was not able to figure out how to make a type literal Int8. I tried several different things:

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

Thus, working with a function convertworked, but it is a somewhat verbal expression. I was wondering if something was a bit more concise, maybe like Rust 8i8.

I am using Julia 0.3.3, but the answers for Julia 0.4.x will be good too.

+4
source share
1 answer

, convert(Int8, 8), Int8(8) Int8(8) . , 8i8, , .

julia> i8=8
8

julia> 3i8
24
+7

Source: https://habr.com/ru/post/1606352/


All Articles