4 ms·
Mathematically speaking if you ask for the modulus of -5 you may as well get a negative number, and I think people may validly have their own interpretations of
by veltas 4y ago
Mathematically speaking if you ask for the modulus of -5 you may as well get a negative number, and I think people may validly have their own interpretations of what's "correct" at this point.
- qsort 4y agoI didn't say it's wrong. You may as well use {white, blue, black, red, green} to represent congruences mod 5, mathematically speaking it's not wrong, as long as they respect the axioms of a field. What's "wat" (in the same sense as the js "wat" talk) is that the answer changes if the argument becomes negative. By all reasonable definitions of modular arithmetic, -8 and 7 are in the same class mod 5. Why is then: > (-8 % 5) == (7 % 5) false in C-like languages? I'm pretty sure it's perfectly consistent with all the relevant language standards, but it's a "wat" nonetheless.
- masklinn 4y ago> What's "wat" (in the same sense as the js "wat" talk) is that the answer changes if the argument becomes negative. It's the same in Python though? you just prefer the way it behaves (though to be fair it's generally more useful and less troublesome): Python's remainder follows the sign of the divisor (because it uses floored division), while C's follows the sign of the dividend (because it uses truncated division). Strictly speaking, neither is an euclidian modulo.
- owl57 4y agoIt's not symmetric. I believe most people with strong mathematical background (like Guido:)) expect lambda x: x % m to be some "computer approximation" to the standard mapping from Z to Z/mZ, while not having deep expectations about lambda m: x % m.