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

Wrapping neg is not implemented for PrimInt #146

Closed
gnzlbg opened this issue Dec 23, 2015 · 7 comments
Closed

Wrapping neg is not implemented for PrimInt #146

gnzlbg opened this issue Dec 23, 2015 · 7 comments

Comments

@gnzlbg
Copy link

gnzlbg commented Dec 23, 2015

When constraining on PrimInt there is no way of performing wrapping neg in a generic way.

The "generic" way to do this seems to be to call the .wrapping_neg() method which is offered by all primitive integers (but not by PrimInt).

@cuviper
Copy link
Member

cuviper commented Dec 23, 2015

Hmm, it's odd that std::num::Wrapping doesn't implement Neg.

AFAICS .wrapping_neg() was only added in Rust 1.1, but we're still trying to maintain 1.0 compatibility. Bumping that minimum version is a breaking change IMO.

I suppose you could do manual 2's complement, x.not().wrapping_add(1).

@gnzlbg
Copy link
Author

gnzlbg commented Dec 23, 2015

rust-lang/rust#30524 was just oppened, looks like an overlook.

@gnzlbg
Copy link
Author

gnzlbg commented Dec 23, 2015

I suppose you could do manual 2's complement, x.not().wrapping_add(1).

Yes I could, thanks for the tip.

AFAICS .wrapping_neg() was only added in Rust 1.1, but we're still trying to maintain 1.0 compatibility. Bumping that minimum version is a breaking change IMO.

Could we use a cfg macro for that? E.g. if rust version >= 1.1 offer wrapping_neg in PrimInt, otherwise, not offer it?

@cuviper
Copy link
Member

cuviper commented Dec 23, 2015

There's no cfg for the rust version, unfortunately.

@briansmith
Copy link
Contributor

In the interim, you could add a new, off-by-default feature for wrapping_neg. Then people who need it could opt in to it, knowing that it requires Rust 1.1 or later.

@cuviper
Copy link
Member

cuviper commented Jan 8, 2016

That's possible, if there's strong demand. I don't want a combinatorial explosion of features though...

@cuviper
Copy link
Member

cuviper commented Dec 19, 2017

This issue was moved to rust-num/num-traits#10

@cuviper cuviper closed this as completed Dec 19, 2017
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

4 participants