6 ms·
It is in fact covered in the page, as the heading for that formula specifically calls out “languages with signed "%", eg. C/C++”. That is why there is a formul
by masklinn 27d ago
It is in fact covered in the page, as the heading for that formula specifically calls out “languages with signed "%", eg. C/C++”.
That is why there is a formula without that adjustment with a “posmod” aka any modulo where a positive divisor yields a positive value (Euclidean division as in rust’s `rem_euclid`, but also floored division as in Python or Ruby, langages with both mod and rem functions / operators generally have a floored division on mod and a truncated division on rem but that’s not a guarantee so check).
- gblargg 26d agoJust saying, a little clarification would have helped. The details are there, but putting it together would have laid out the base algorithm that's being optimized, which I see as a basic point of an article like this, give everyone a clear understanding of the algorithm so they can follow along. "rd is number of days offset from 1970-01-01, positive or negative. In some languages the mod 7 can yield a negative in the range -6 to 0, so an extra +7 and mod is used in the basic implementation."