News for hackers. Stuff that matters.
Re:Python, unlike C, has the mod operator always return a po... by Normal_gaussian on Wednesday December 29, 2021 @05:37PM (#29731024)
That will only work for cases where a >= -b. For the more general case:

> a mod b = ((a % b) + b) % b

The first remainder bounds it to -b < x < b. Then adding b goes to 0 < x < 2b. Then the second remainder gets th desired 0 <= x < b.

This will not work for b > max_int / 2 (solution in that case is much mkre language dependent)

There are no comments on this comment yet.