3 ms·
The difference between flooring and euclidean modulo is quite irrelevant in practice for the most part. Either way resolve the main issue with truncating modul
by the_mitsuhiko 5y ago
The difference between flooring and euclidean modulo is quite irrelevant in practice for the most part. Either way resolve the main issue with truncating modulo that is the issue outlined in the tweet.
- masklinn 5y ago> The difference between flooring and euclidean modulo is quite irrelevant in practice for the most part. It seems quite relevant as it diverges significantly from the assertion put forth in the tweet: Python's remainder takes the sign of the divisor. So flooring division fixes the more common issue but leaves an other one present.
- the_mitsuhiko 5y agoThe tweet we're discussing: > python, unlike C, had the mod operator always return a positive number, even if the first argument is negative That is true for Rust's rem_euclid as well: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=59080e23e6c7dcf60e5ef766b52e1d20 https://play.rust-lang.org/?version=stable&mode=debug&editio...
- housecarpenter 5y agoIn practice, when you use a modulo operator the second operand is usually some kind of length or size, which is inherently non-negative, while the first operand is an index or offset, which could easily be negative if there's no natural origin point. So it's much rarer that you have to deal with a potentially negative second operand, compared to having to deal with a potentially negative first operand.