Thread (69 messages) flat view 69 messages, 4 authors, 2016-06-15

Re: [PATCH v4 40/44] builtin-am: support and auto-detect mercurial patches

From: Paul Tan <hidden>
Date: 2016-06-15 23:05:36

On Tue, Jun 30, 2015 at 4:32 AM, Stefan Beller [off-list ref] wrote:
for calculating the minutes we would only need to take % 3600 (which
you do), but
then we still need to divide by 60 to convert seconds to minutes?
Whoops, yes we do. It should be:

tz = tz / 3600 * 100 + tz % 3600 / 60;
tz = -tz;

However...
What happens if we have a negative input not matching a full hour, say -5400 ?
(would equate to 0130 in git)
Hmm, I assumed that in C, integer division would always truncate to
zero, but turns out that is only so in C99. In C89, it is
implementation defined whether it rounds towards zero or towards
negative infinity.

So, if the compiler rounds towards negative infinity, then the above
will give the incorrect result. The best solution is probably to
ensure that all the integers are positive:

tz2 = labs(tz) / 3600 * 100 + labs(tz) % 3600 / 60;
if (tz > 0) tz2 = -tz2;

Thanks for bringing this up.

Regards,
Paul
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help