Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easy conversions between Signed and Unsigned #46

Closed
clarfonthey opened this issue Mar 4, 2018 · 1 comment
Closed

Easy conversions between Signed and Unsigned #46

clarfonthey opened this issue Mar 4, 2018 · 1 comment

Comments

@clarfonthey
Copy link
Contributor

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.

@cuviper
Copy link
Member

cuviper commented Mar 5, 2018

I've decided to limit the clutter of breaking change issues, so they will now be tracked collectively in #47. I'm closing this issue for now as postponed but we can still discuss its merits here as needed.

@cuviper cuviper closed this as completed Mar 5, 2018
@cuviper cuviper modified the milestone: num-traits-0.x Mar 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants