For example:
n::Uint8 = 0x00
x::Uint8 = n + 0x10
ERROR: type: typeassert: expected Uint8, got Uint64
I assume this happens because methods(+)
for a::Uint8, b::Uint8
is not defined so n
is auto-promoted to Uint64
. Is there a better way to deal with this than casting everything back to it's pre-promoted type after every operation? Isn't this something that the interpreter should be able to handle automatically (i.e. if it's told x
should be assigned a Uint8
after the addition)?
I don't think there is a better way in Julia 0.3 than
julia> typeof(uint8(0x00 + 0x10))
UInt8
but in Julia 0.4 you don't need to worry as it doesn't do that automatic promotion anymore:
julia> typeof(0x00 + 0x10)
UInt8
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