top | item 42707989 (no title) notfish | 1 year ago In what languages is n % 2 -1 for negative odd numbers?Edit: apparently JS, java, and C all do this. That’s horrifying discuss order hn newest jagged-chisel|1 year ago Horrifying? It’s mathematically correct. seritools|1 year ago it's a semantics problem, not a maths problem - modulus and remainder are not the same operation. This easily trips up people since `%` is often called "modulo", yet is implemented as remainder operation in many languageshttps://stackoverflow.com/questions/13683563/whats-the-diffe... michael1999|1 year ago It's actually really awkward. Math usually considers (-7 mod 5) === (2 mod 5). But in C, (-7 % 5 != 2 % 5). load replies (1) affinepplan|1 year ago wrong. it's not any more correct than 1. that's the key part of an "equivalence" class is that the elements are "equivalent"
jagged-chisel|1 year ago Horrifying? It’s mathematically correct. seritools|1 year ago it's a semantics problem, not a maths problem - modulus and remainder are not the same operation. This easily trips up people since `%` is often called "modulo", yet is implemented as remainder operation in many languageshttps://stackoverflow.com/questions/13683563/whats-the-diffe... michael1999|1 year ago It's actually really awkward. Math usually considers (-7 mod 5) === (2 mod 5). But in C, (-7 % 5 != 2 % 5). load replies (1) affinepplan|1 year ago wrong. it's not any more correct than 1. that's the key part of an "equivalence" class is that the elements are "equivalent"
seritools|1 year ago it's a semantics problem, not a maths problem - modulus and remainder are not the same operation. This easily trips up people since `%` is often called "modulo", yet is implemented as remainder operation in many languageshttps://stackoverflow.com/questions/13683563/whats-the-diffe...
michael1999|1 year ago It's actually really awkward. Math usually considers (-7 mod 5) === (2 mod 5). But in C, (-7 % 5 != 2 % 5). load replies (1)
affinepplan|1 year ago wrong. it's not any more correct than 1. that's the key part of an "equivalence" class is that the elements are "equivalent"
jagged-chisel|1 year ago
seritools|1 year ago
https://stackoverflow.com/questions/13683563/whats-the-diffe...
michael1999|1 year ago
affinepplan|1 year ago