Skip to content

Easy conversions between Signed and Unsigned #46

Closed
@clarfonthey

Description

@clarfonthey

It would be nice if Signed and Unsigned had a way to convert between each other, presumably via:

  • Signed::abs_unsigned, which would losslessly convert the signed version to an unsigned version of the same size (wrapping_abs + as for primitives, and just extracting the inner BigUint for BigInt)
  • Unsigned::try_signed, which would allow casting to the signed version if available.
  • Signed::Unsigned and Unsigned::Signed, two associated types that would do the job.

This would be a breaking change but a useful one. For example, a Pow implementation for Ratio could leverage these methods so that the signed and unsigned versions relied on each others' implementations, instead of duplicating code.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions