[REVIEWED 3-5-1][PATCH] Fix leap year calculation

Eike Rathke erack at redhat.com
Wed Feb 29 14:02:40 PST 2012


Hi Kevin,

On Wednesday, 2012-02-29 15:38:30 +0100, Kevin André wrote:

> >>      return ((nYear % 4) == 0)
> >> -        && !(((nYear % 100) == 0) || ((nYear % 400) == 0));
> >> +        && (((nYear % 100) != 0) || ((nYear % 400) == 0));
> 
> Why still that many parentheses? Couldn't it be simply:
> 
> return (nYear % 400) == 0 || ((nYear % 4) == 0 && (nYear % 100) != 0);

While giving the correct result this unnecessarily evaluates the
expression  ((nYear % 400) == 0) in 3/4 of all cases and then continues
with evaluation of ((nYear % 4) == 0) just to return then if false,
whereas starting with ((nYear % 4) == 0) does not need any further
evaluation in 3/4 of all cases.

Apart from that, parentheses IMHO increase readability of logical
expressions. With more complicated expressions they also help if the
editor supports highlighting / jumping matching parentheses.

  Eike

-- 
LibreOffice Calc developer. Number formatter stricken i18n transpositionizer.
GnuPG key 0x293C05FD : 997A 4C60 CE41 0149 0DB3  9E96 2F1A D073 293C 05FD
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/libreoffice/attachments/20120229/880b23a2/attachment.pgp>


More information about the LibreOffice mailing list