Hacker News new | past | comments | ask | show | jobs | submit login

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.



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.


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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: