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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions