Date: prev next · Thread: first prev next last
2012 Archives by date, by thread · List index


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

Attachment: pgpYNZAZXfH4u.pgp
Description: PGP signature


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.