Currently signed and unsigned work on types only if the target type has been declared, too. Even in that case, unsigned may error on emulated signed integers.
Defining signed integers first:
julia> @emulate Int3
julia> unsigned(Int3)
ERROR: MethodError: no method matching Unsigned(::Int3)
julia> unsigned(Int3(-1))
ERROR: MethodError: no method matching Unsigned(::Int3)
julia> @emulate UInt3
julia> unsigned(Int3)
UInt3
julia> unsigned(Int3(-1))
ERROR: InexactError: convert(UInt8, -1)
Defining unsigned integers first:
julia> @emulate UInt3
julia> signed(UInt3)
ERROR: MethodError: no method matching Signed(::UInt3)
julia> signed(UInt3(7))
ERROR: MethodError: no method matching Signed(::UInt3)
julia> @emulate Int3
julia> signed(UInt3)
Int3
julia> signed(UInt3(7))
-1
To fix the errors on type arguments, it might be necessary to create both the signed and the unsigned version of an emulated integer type at the same time. This is what BitIntegers.jl does.
Currently
signedandunsignedwork on types only if the target type has been declared, too. Even in that case,unsignedmay error on emulated signed integers.Defining signed integers first:
Defining unsigned integers first:
To fix the errors on type arguments, it might be necessary to create both the signed and the unsigned version of an emulated integer type at the same time. This is what BitIntegers.jl does.