NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
re: lib/50009: strptime small enhancement
> On Sun, Jun 28, 2015 at 07:50:00PM +0000, devnexen%gmail.com@localhost wrote:
> > +#ifndef ISLEAPYEAR
> > +#define ISLEAPYEAR(y) ((y % 400) == 0 && (y % 4) == 0 && (y % 100) != 0)
> > +#endif
>
> ...this is wrong...
indeed, sys/clock.h has this:
63 /*
64 * This inline avoids some unnecessary modulo operations
65 * as compared with the usual macro:
66 * ( ((year % 4) == 0 &&
67 * (year % 100) != 0) ||
68 * ((year % 400) == 0) )
69 * It is otherwise equivalent.
70 */
71 static inline int
72 is_leap_year(uint64_t year)
73 {
74 if ((year & 3) != 0)
75 return 0;
76
77 if (__predict_false((year % 100) != 0))
78 return 1;
79
80 return __predict_false((year % 400) == 0);
81 }
which should probably be used instead, for netbsd, or at
least the same expression in the comment.
(the macro above also doesn't work properly for various
inputs, like a good macro should.)
.mrg.
Home |
Main Index |
Thread Index |
Old Index