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 upNo modulo operator? #13909
Comments
This comment has been minimized.
This comment has been minimized.
|
A change to the language like this should be proposed through the RFC process. It's intended to be the remainder operator because it maps to the functionality of hardware, just like in C. It maps directly to the
It's not like |
atg commentedMay 3, 2014
It's rather disappointing to me that Rust has no working modulo operator. I had hoped that, like Ruby and Python,
%would give correct results on negative numbers (e.g. -4 is 2 (mod 3)). Alas it has the same broken behaviour as C.I see
%has been retconned as a "remainder" operator, but realistically, most people expect correctness rather than historical artefacts. Apparently, I'm not the only one bothered by it.If it were me, I would change % to match Ruby and Python, and introduce a "rem" keyword to fulfil the current behaviour. This is a neat solution because it doesn't give up any performance (for all those people doing modulo division in a tight loop, I guess?), but it doesn't give the middle finger to mathematicians either.
2¢.