[Jama] Fwd: Hello question about Jama and code-styling

13 views
Skip to first unread message

Ronald Boisvert

unread,
Jul 28, 2018, 3:41:01 PM7/28/18
to ja...@list.nist.gov


-------- Forwarded Message --------
Subject: Hello question about Jama and code-styling
Date: Mon, 23 Jul 2018 13:57:23 -0700
From: moe <mo.mu.wss at gmail.com>
To: ronald.boisvert at nist.gov

Hello,

in many places you have a way to handle simple tasks, it's like defying simple logic, maybe too much of copy paste transforms to java (You could remove a bunch of useless extra memory)

One of the most comical one:

in LU decomposition line 107

if (j < m & LU[j][j] != 0.0) { why using a bitwise operation when you want to express a logical `and`, surely 1 & 1 will always give 1 and the rest will be always 0,

but if I may there is a reason why level 2 and 3 languages introduced this difference.

Best.

Wishmaster

unread,
Jul 28, 2018, 4:37:38 PM7/28/18
to ja...@list.nist.gov
Well,
That's not quite correct, as "&" works for conditional boolean arguments as
well as for int and others, and there may be some really rare use cases
where you have to use & instead of &&. In general use && unless you have a
good reason not to use it. :)

It is not a bitwise operation - if you try to use smth like int bla = j < m
& LU[j][j] != 0.0; the compiler will give an error, as bla must be boolean
here. That's the only reason why && was introduced.

However, the ONLY difference between "&" and "&&" is that "&" is
NOT short-circuiting but && is.

In that case, "j < m & LU[j][j] != 0.0" it looks suspicious because if j >=
m, it will still evaluate the next LU[j][j] != 0.0 term.
Assuming that m is the length of LU, it will lead to
IndexOutOfBoundsExceptuon.

I didn't check the code if that can actually happen, but I suggest to use
&& here, just to be careful - apart from that it just looks a bit cleaner.


Ronald Boisvert <ronald.boisvert at nist.gov> schrieb am Sa., 28. Juli 2018,
21:41:

> _______________________________________________
> Jama mailing list
> Ja...@list.nist.gov
> https://list.nist.gov/jama
>

Reply all
Reply to author
Forward
0 new messages