I can make "literals" of type Int64
and even Uint8
in Julia:
julia> typeof(8)
Int64
julia> typeof(0x08)
Uint8
But I haven't been able to find out how to make a literal of type Int8
. I have tried a few 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
So the application of the convert
function worked, but that's a somewhat wordy expression. I was wondering if there was something a little more concise, perhaps like Rust's 8i8.
I am using Julia 0.3.3, but answers for Julia 0.4.x would be fine too.
More convenient than convert(Int8, 8)
is Int8(8)
respective int8(8)
on earlier versions. The reason that few number literal notations like 8i8
exist is that it conflicts with multiplication by juxtaposition.
julia> i8=8
8
julia> 3i8
24
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With