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 #10

Closed
cuviper opened this issue Dec 19, 2017 · 7 comments · Fixed by #153
Closed

Wrapping neg is not implemented for PrimInt #10

cuviper opened this issue Dec 19, 2017 · 7 comments · Fixed by #153

Comments

@cuviper
Copy link
Member

cuviper commented Dec 19, 2017

From @gnzlbg on December 23, 2015 18:40

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).

Copied from original issue: rust-num/num#146

@cuviper
Copy link
Member Author

cuviper commented Dec 19, 2017

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).

@cuviper
Copy link
Member Author

cuviper commented Dec 19, 2017

From @gnzlbg on December 23, 2015 19:2

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

@cuviper
Copy link
Member Author

cuviper commented Dec 19, 2017

From @gnzlbg on December 23, 2015 19:3

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 Author

cuviper commented Dec 19, 2017

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

@cuviper
Copy link
Member Author

cuviper commented Dec 19, 2017

From @briansmith on January 8, 2016 22:48

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 Author

cuviper commented Dec 19, 2017

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

@cuviper
Copy link
Member Author

cuviper commented Dec 19, 2017

AFAICS .wrapping_neg() was only added in Rust 1.1, but we're still trying to maintain 1.0 compatibility.

We were later forced to 1.8 (rust-num/num#257), so I think we can do this now without breaking.

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

Successfully merging a pull request may close this issue.

1 participant