NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
re: lib/50009: strptime small enhancement
The following reply was made to PR lib/50009; it has been noted by GNATS.
From: matthew green <mrg%eterna.com.au@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: lib-bug-people%netbsd.org@localhost, gnats-admin%netbsd.org@localhost,
netbsd-bugs%netbsd.org@localhost, devnexen%gmail.com@localhost
Subject: re: lib/50009: strptime small enhancement
Date: Mon, 29 Jun 2015 14:42:18 +1000
> 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