Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upImplement RFC #2169 (Euclidean modulo). #49389
Conversation
rust-highfive
assigned
KodrAus
Mar 26, 2018
This comment has been minimized.
This comment has been minimized.
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @KodrAus (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
rust-highfive
added
the
S-waiting-on-review
label
Mar 26, 2018
varkor
requested changes
Mar 26, 2018
|
This is looking good! I've left a few very minor comments, but apart from that and fixing the tidy errors, I can't see any problems! |
| @@ -1318,6 +1460,40 @@ $EndFeature, " | |||
| } | |||
| } | |||
|
|
|||
|
|
|||
| doc_comment! { | |||
| concat!("Calculates the modulo of Euclidean divsion `self.mod_euc(rhs)`. | |||
This comment has been minimized.
This comment has been minimized.
varkor
Mar 26, 2018
Member
Nit: I would call this "the remainder" or "the modulus", as "modulo" is the operation, rather than the result.
This comment has been minimized.
This comment has been minimized.
fanzier
Mar 27, 2018
Author
Contributor
Changing to "remainder" since "modulus" is another word for "divisor".
|
|
||
|
|
||
| doc_comment! { | ||
| concat!("Calculates the modulo `self mod rhs` by Euclidean division. |
This comment has been minimized.
This comment has been minimized.
| doc_comment! { | ||
| concat!("Calculates the quotient of Euclidean division of `self` by `rhs`. | ||
| This computes the integer n such that `self = n * rhs + self.mod_euc(rhs)`. |
This comment has been minimized.
This comment has been minimized.
| #[unstable(feature = "euclidean_division", issue = "49048")] | ||
| #[inline] | ||
| pub fn wrapping_div_euc(self, rhs: Self) -> Self { | ||
| self.div_euc(rhs) |
This comment has been minimized.
This comment has been minimized.
varkor
Mar 26, 2018
Member
This can be the standard self / rhs to avoid the extra branch (like with wrapping_mod_euc).
This comment has been minimized.
This comment has been minimized.
varkor
approved these changes
Mar 27, 2018
|
Looks good to me |
This comment has been minimized.
This comment has been minimized.
|
I was just wondering whether the |
This comment has been minimized.
This comment has been minimized.
|
As far as I'm aware, the
Edit: just realised the floating-point methods are not in |
This comment has been minimized.
This comment has been minimized.
|
@varkor That makes sense. So I should move the float methods to libcore? Edit: Apparently, to move it there, I would have to add the |
This comment has been minimized.
This comment has been minimized.
|
I got a little confused before, sorry! I think it would be better to move the methods to |
This comment has been minimized.
This comment has been minimized.
|
Fair enough, I'll move it into libcore. But since |
This comment has been minimized.
This comment has been minimized.
Ah, I didn't spot that. In that case, let's just leave it in |
This comment has been minimized.
This comment has been minimized.
|
Ping from triage, @KodrAus ! Will you have time to review soon? |
KodrAus
reviewed
Apr 12, 2018
| concat!("Wrapping Euclidean division. Computes `self.div_euc(rhs)`, | ||
| wrapping around at the boundary of the type. | ||
| The only case where such wrapping can occur is when one divides `MIN / -1` on a signed type (where |
This comment has been minimized.
This comment has been minimized.
KodrAus
Apr 12, 2018
The wording here feels a little wonky. How about:
Wrapping will occur in MIN / -1 on a signed type (where MIN is the negative minimal value for the type). This is equivalent to -MIN, a positive value that is too large to represent in the type. In this case, this method returns MIN itself.
This comment has been minimized.
This comment has been minimized.
fanzier
Apr 12, 2018
Author
Contributor
I almost copy-pasted that documentation from wrapping_div. Should I update the documentation there as well or should that be a separate PR?
| concat!("Wrapping Euclidean modulo. Computes `self.mod_euc(rhs)`, wrapping around at the | ||
| boundary of the type. | ||
| Such wrap-around never actually occurs mathematically; implementation artifacts make `x % y` |
This comment has been minimized.
This comment has been minimized.
KodrAus
Apr 12, 2018
Same as above. How about:
Wrapping will occur in MIN % -1 on a signed type (where MIN is the negative minimal value for the type). In this case, this method return 0.
| concat!("Calculates the quotient of Euclidean division `self.div_euc(rhs)`. | ||
| Returns a tuple of the divisor along with a boolean indicating whether an arithmetic overflow would | ||
| occur. If an overflow would occur then self is returned. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
KodrAus
commented
Apr 13, 2018
This comment has been minimized.
This comment has been minimized.
|
|
bors
added
S-waiting-on-bors
and removed
S-waiting-on-review
labels
Apr 13, 2018
KodrAus
referenced this pull request
Apr 13, 2018
Open
Tracking issue for RFC 2169: Euclidean Modulo #49048
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Apr 13, 2018
This comment has been minimized.
This comment has been minimized.
|
|
fanzier commentedMar 26, 2018
Tracking issue: #49048