这是indexloc提供的服务,不要输入任何密码
Skip to content

Consider allowing easy compile time casting between generic signed/unsigned integer types of same byte size #5493

@mgoncerz

Description

@mgoncerz

It is sometimes the case with integers, that you may want to take signed arguments and return unsigned integer of exactly the same byte size. One example is calculating greatest common divisor, if you care about handling the case of GDC(min(T), min(T)).

Consider a dummy casting procedure:

toUnsigned :: proc (A: i32) -> u32

If you care about all byte sizes, then - as far as I'm aware - there is no easy way of expressing it as a generic (if you want to remain explicit about size, rather than using "int" and "uint", possibly with type casting in when statements) and you have to type out all cases manually. Which is fair, as they are two distinct types, but maybe could be resolved at the level of parser with some additional syntax.

For example:
toUnsigned :: proc (A: $T) -> UT where intrinsics.type_is_integer(T) && signed_unsigned_pair(T, UT)
toUnsigned :: proc (A: $int(T)) -> uint(T) where intrinsics.type_is_integer(T)
toUnsigned :: proc (A: $signed(T)) -> unsigned(T) where intrinsics.type_is_integer(T)

Or even more general, with "same_size_int", "same_size_uint", "same_size_float".

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