Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make an Int8 literal in Julia?

Tags:

literals

julia

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.

like image 745
Ray Toal Avatar asked Sep 08 '15 06:09

Ray Toal


1 Answers

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
like image 76
mschauer Avatar answered Sep 30 '22 12:09

mschauer