Julia: How to avoid changes like automatic advertising?

For instance:

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 not defined, so n automatically rises to Uint64 . Is there a better way to handle this than to drop everything back to it with a preliminary raise after each operation? Isn't that what the interpreter should be able to process automatically (i.e. if it was told x after adding add Uint8 )?

+5
source share
1 answer

I don't think Julia 0.3 has a better way than

 julia> typeof(uint8(0x00 + 0x10)) UInt8 

but in Julia 0.4 you don’t have to worry, as this no longer makes auto-promotion:

 julia> typeof(0x00 + 0x10) UInt8 
+7
source

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


All Articles