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

Remainder is not modulus, but int::rem() uses the mod operator. #4565

Closed
wting opened this issue Jan 21, 2013 · 3 comments
Closed

Remainder is not modulus, but int::rem() uses the mod operator. #4565

wting opened this issue Jan 21, 2013 · 3 comments

Comments

@wting
Copy link
Contributor

wting commented Jan 21, 2013

It turns out that Rust's % behavior mimics C99 (adopting the sign of the dividend). However the modulus and remainder are not the same, but Rust's implementation of int::rem() simply uses the % operator:

#[inline(always)]
pub pure fn rem(x: T, y: T) -> T { x % y }

Shouldn't int::rem()'s behavior be different? Why would Rust have two names for the same action?

ping @graydon

@Kimundi
Copy link
Member

Kimundi commented Jan 24, 2013

I think to be consistent with C, rust should keep the % behavior as it is, but explicitly define it as the 'remainder' operation (with documentation pointing out that it's the same as Cs mod, but mathematically correct named).
That means renaming Num::module() to Num::rem(), and defining the actual mod method in a way that doesn't easily get confused with rem.

@graydon
Copy link
Contributor

graydon commented Apr 22, 2013

These bugs make me a bit dizzy. Did #5990 fix this?

@thestinger
Copy link
Contributor

Yeah, this is fixed now. The rem function should be removed and a modulo function as a wrapper around % can be provided.

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

No branches or pull requests

4 participants