News for hackers. Stuff that matters.
Re:Microfeatures I'd like to see in more languages by feoren on Friday January 06, 2023 @02:49AM (#34272076)
It's a little verbose and can probably be reduced, but "((x % m) + m) % m" always works. Although it's probably not better than a check if x < 0 since branch prediction will get that right almost always.

I do think it's quite odd and frustrating that modulo can return negative numbers and I don't really get the reasoning there, but there's probably a good reason I don't know about.

Re:Microfeatures I'd like to see in more languages by xigoi on Friday January 06, 2023 @05:03AM (#34272960)
The only reason is that C does it that way. And C does it that way because machine code does it that way.