News for hackers. Stuff that matters.
Re:Python, unlike C, has the mod operator always return a po... by yaur on Thursday December 30, 2021 @05:29AM (#29735505)
What's the case where the C % operator behaves in an unexpected way? I've been wiring software for about 20 years and can count zero hands the number of times someone I've worked with has had to worry about how the modulo operator behaves with negative numbers.
Re:Python, unlike C, has the mod operator always return a po... by housecarpenter on Thursday December 30, 2021 @06:09AM (#29735722)
An example would be if you want to find the month corresponding to a timestamp. The obvious thing to do is to scale the timestamp so that it gives you the number of months after the epoch, take that number % 12, and map 0 to January, 1 to February, etc. (assuming the epoch is in January). But if you try to do that with a timestamp from before the epoch, you'll end up with 0 for January, -11 for February, -10 for March, etc.
Re:Python, unlike C, has the mod operator always return a po... by yaur on Friday December 31, 2021 @02:00AM (#29745702)
No. If your software has to deal with dates from before 1970 "seconds since the epoch" is not a reasonable choice for a time unit.