4 ms·
I've regularly been annoyed by -1 % n being negative but I've never seen a case where the negative number is on the right. Has anyone seen this before in real c
by Thomashuet 8y ago
I've regularly been annoyed by -1 % n being negative but I've never seen a case where the negative number is on the right.
Has anyone seen this before in real code?
- userbinator 8y agoI suspect this is why the topic is relatively obscure; situations where you have a negative divisor and need the remainder/mod are not common.
- chii 8y ago> situations where you have a negative divisor and need the remainder/mod are not common. yep. But sometimes, when you have numbers that come from some external system, and you didn't check them or expect that the % operator will make it positive, you end up with this sort of problem. Such as having negative positions with CSS, or a game where you end up with negative values for coordinates.