Oh geez, well then I rest my case that this code is too clever to be maintainable. The next programmer might not be any smarter than I.
(I'm not a PL/I expert -- I guess "fixed" means packed? I had guessed binary.) If i is fairly large and there are a good number of a(i) == 0 then my point is still valid -- this has to be an expensive way of doing this. What is the statement of the problem? What is the snippet supposed to accomplish? "For a table of packed values a[whatever], print the sum of all of the positive values, unless that sum is zero?" Do I have that right? I would be stunned if the code below performs better than -- and not worse than, assuming a fair number of zero values -- the most obvious logic for i = 1 to whatever; if a(i) > 0 then sum = sum + a(i); end; if sum > 0 then put data(sum); Charles -----Original Message----- From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU] On Behalf Of Robert Prins Sent: Friday, August 4, 2017 2:58 AM To: IBM-MAIN@LISTSERV.UA.EDU Subject: Re: Someone just too smart for his or her own good? On 2017-08-04 00:31, Charles Mills wrote: > Certainly if one is looking to save a cycle or two then > > if a(i) >= 0 then > sum = sum + a(i); > > should be > > if a(i) > 0 then > sum = sum + a(i); > > because adding a(i) to sum when a(i) == 0 is a waste of a cycle or two. Yes, but in this case it *IS* significant, because the initialization of a PL/I "FIXED (7)" with -1.0 < init-value < 0 will set it to MINUS zero (zero with a D-sign) and by adding zero to this will normalize the value to have a C-sign. As I already write in the title, the gal or guy who wrote this code is just a trifle too smart for her or his own good, I've been using PL/I for nearly 32 years, and until I used UNSPEC() on "sum", the code didn't make any sense to me. FWIW, my original post contained a type, if substr(unspec(sum), 25, 8) ^= '0d'bx then should have been if substr(unspec(sum), 29, 4) ^= 'd'bx then or, like in the original code, if substr(unspec(sum), 8*stg(sum)-3, 4) ^= 'd'bx then Mea culpa, too much Intel assembler where hex constants must start with a zero... Robert > > -----Original Message----- > From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU] > On Behalf Of Robert Prins > Sent: Thursday, August 3, 2017 12:11 PM > To: IBM-MAIN@LISTSERV.UA.EDU > Subject: Someone just too smart for his or her own good? > > Just came across the following, and please don't come back with pedantic > remarks about undeclared variables, the code is just to show what's there: > > dcl sum fixed (7) init (-0.1); > > for i = 1 to whatever; > if a(i) >= 0 then > sum = sum + a(i); > end; > > if substr(unspec(sum), 25, 8) ^= '0d'bx then > put data(sum); > > In other words if all a(i) are negative, nothing is printed. A comment in the > code suggests that this is faster code, on modern OoO z/OS systems, than the > more logical: > > dcl sum fixed (7) init (-1); > > for i = 1 to whatever; > if a(i) >= 0 then > if sum ^= -1 then > sum = sum + a(i); > else > sum = a(i); > end; > > It probably is if the value of whatever is in the order of 42 gazillion, but > any other thoughts about this? > > Robert > -- > Robert AH Prins > robert.ah.pr...@gmail.com > Some programming @ <https://prino.neocities.org/zOS/zOS%20Tools.html> > > ---------------------------------------------------------------------- > For IBM-MAIN subscribe / signoff / archive access instructions, send > email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN > > ---------------------------------------------------------------------- > For IBM-MAIN subscribe / signoff / archive access instructions, send > email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN > -- Robert AH Prins robert(a)prino(d)org ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN