4 ms·
Something that recently caused an interesting amount of problems for me was the simple fact that the modulo operation with negative numbers changes its behaviou
by cstuder 12y ago
Something that recently caused an interesting amount of problems for me was the simple fact that the modulo operation with negative numbers changes its behaviour depending on the programming language: http://rigaux.org/language-study/syntax-across-languages/Mthmt.html#MthmtMdl http://rigaux.org/language-study/syntax-across-languages/Mth...
For a more complete list: http://en.wikipedia.org/wiki/Modulo_operation#Remainder_calculation_for_the_modulo_operation http://en.wikipedia.org/wiki/Modulo_operation#Remainder_calc...
- kuschku 12y agoWhile we had to implement the Modulo operation as part of an assignment in assembler, several other students and me started discussing this topic, ultimately settling on "do whatever you want, just write down what it’s supposed to do", because we couldn’t really agree on which would be the better solution.
- stouset 12y agoActually, if you consider strict nomenclature, modulo should be positive since it's a mathematical concept and that's what it's mathematical definition would require. The fact that it has been (ab)used as a shorthand for the remainder of integer division is unfortunate, but that suggests there ought to be a "remainder" keyword (or operator). We've gotten into a bad habit of calling things by the name of their implementation rather than by what we actually expect of them. This confusion is just a side effect of that problem.
- jarcane 12y agoThis is why Racket has both.