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

jagged-chisel|1 year ago

Horrifying? It’s mathematically correct.

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).

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"