difftime
Paul Eggert
eggert at CS.UCLA.EDU
Mon Nov 1 17:47:13 UTC 2004
"Olson, Arthur David (NIH/NCI)" <olsona at dc37a.nci.nih.gov> writes:
> ** If (sizeof (double) > sizeof (time_t)) simply convert and subtract
> ** (assuming that the wider type has more precision).
This should say "larger" rather than "wider". In C99 standardese,
"larger" talks about sizeof, "wider" talks about useful bits
(ie. precision).
> if (time1 >= 0 && time0 >= 0 || time1 < 0 && time0 < 0)
It'd be nicer, shorter, and often faster to say this:
if ((time1 < 0) == (time0 < 0))
and then, for symmetry (and more likelihood for compiler optimization) replace
"time1 >= 0 /* && time0 < 0 */" with
"time0 < 0 /* && time1 >= 0 */" later on.
> ** Punt if unsigned long is too narrow.
Why not use uintmax_t if 199901 <= __STDC_VERSION__? That will work
on all hosts except the weird ones where unsigned values have holes.
The implementation is still a bit slow for the common case where
time_t is a signed integer type and fits in double (e.g., x86) or long
double (e.g., x86-64). This case should be doable without any tests
or branches. It's not a correctness issue; just a performance issue.
I sense that you didn't like the version that I sent in, because of
its complexity. What part of the complexity turned you off the most?
Perhaps I could simplify that part.
More information about the tz
mailing list