Skip to content

better support for signed and unsigned #8

Description

@matthias314

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions