Re: PL/I Integer arithmetic
- Original Message - From: "Seymour J Metz" Sent: Thursday, September 10, 2020 1:02 AM You did, in the comment. No I didn't. You misread it. From: IBM Mainframe Discussion List on behalf of Robin Vowels Sent: Wednesday, September 9, 2020 11:00 AM On 2020-09-10 00:33, Seymour J Metz wrote: Since when is 1.33... an integer? Who said it was? A/B (both integers with values 4 and 3 respectively), yield exactly 1. From: IBM Mainframe Discussion List on behalf of Robin Vowels Sent: Wednesday, September 9, 2020 10:08 AM From: "Seymour J Metz" Sent: Monday, September 07, 2020 4:13 PM PL/I has never had integers. It always has had integers. The arithmetic rules for scaled fixed point are different from those for integers. In integer arithmetic, (4/3)*6 is 6 That's not the result you get in PL/I. Yes it is, with declarations as shown, as I said before, . Under IBM rules: %PROCESS RULES(IBM); INTEGER_DIVISION: PROCEDURE OPTIONS (MAIN); DECLARE (A, B) FIXED DECIMAL (15); A = 4; B = 3; PUT (4/3); PUT (A/B); PUT ( (A/B) * 6 ); END INTEGER_DIVISION; /* RESULTS: 1.33 1 6 */ -- 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 --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN
Re: PL/I Integer arithmetic
You did, in the comment. -- Shmuel (Seymour J.) Metz http://mason.gmu.edu/~smetz3 From: IBM Mainframe Discussion List on behalf of Robin Vowels Sent: Wednesday, September 9, 2020 11:00 AM To: IBM-MAIN@LISTSERV.UA.EDU Subject: Re: PL/I Integer arithmetic On 2020-09-10 00:33, Seymour J Metz wrote: > Since when is 1.33... an integer? Who said it was? A/B (both integers with values 4 and 3 respectively), yield exactly 1. > > From: IBM Mainframe Discussion List on > behalf of Robin Vowels > Sent: Wednesday, September 9, 2020 10:08 AM > Subject: Re: PL/I Integer arithmetic (was: Constant Identifiers) > > From: "Seymour J Metz" > Sent: Monday, September 07, 2020 4:13 PM > > >> PL/I has never had integers. > > It always has had integers. > >> The arithmetic rules for scaled fixed point are different from those >> for integers. >> In integer arithmetic, (4/3)*6 is 6 That's not the result you get in >> PL/I. > > Yes it is, with declarations as shown, as I said before, . > > Under IBM rules: > > %PROCESS RULES(IBM); > INTEGER_DIVISION: >PROCEDURE OPTIONS (MAIN); >DECLARE (A, B) FIXED DECIMAL (15); > >A = 4; B = 3; > >PUT (4/3); >PUT (A/B); >PUT ( (A/B) * 6 ); > > END INTEGER_DIVISION; > /* RESULTS: > 1.33 1 6 > */ -- 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
Re: PL/I Integer arithmetic
On 2020-09-10 00:33, Seymour J Metz wrote: Since when is 1.33... an integer? Who said it was? A/B (both integers with values 4 and 3 respectively), yield exactly 1. From: IBM Mainframe Discussion List on behalf of Robin Vowels Sent: Wednesday, September 9, 2020 10:08 AM Subject: Re: PL/I Integer arithmetic (was: Constant Identifiers) From: "Seymour J Metz" Sent: Monday, September 07, 2020 4:13 PM PL/I has never had integers. It always has had integers. The arithmetic rules for scaled fixed point are different from those for integers. In integer arithmetic, (4/3)*6 is 6 That's not the result you get in PL/I. Yes it is, with declarations as shown, as I said before, . Under IBM rules: %PROCESS RULES(IBM); INTEGER_DIVISION: PROCEDURE OPTIONS (MAIN); DECLARE (A, B) FIXED DECIMAL (15); A = 4; B = 3; PUT (4/3); PUT (A/B); PUT ( (A/B) * 6 ); END INTEGER_DIVISION; /* RESULTS: 1.33 1 6 */ -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN
Re: PL/I Integer arithmetic.
On 2020-09-10 00:32, Seymour J Metz wrote: The results that you have described are not integer arithmetic. In integer arithmetic, 4/3 is 1. Look at the second result following the program. You will see that A/B == 4/3 yields 1. From: IBM Mainframe Discussion List on behalf of Robin Vowels Sent: Wednesday, September 9, 2020 10:14 AM - Original Message - From: "Seymour J Metz" Sent: Monday, September 07, 2020 3:02 PM Subject: Re: Constant Identifiers 4/3 yields 1.3, 04/3 yields 1332, ... Rubbish. 4/3 yields 1.33 INTEGER_DIVISION: PROCEDURE OPTIONS (MAIN); DECLARE (A, B) FIXED DECIMAL (15); A = 4; B = 3; PUT (4/3); PUT (A/B); PUT ( (A/B) * 6 ); END INTEGER_DIVISION; /* RESULTS: 1.33 1 6 */ However, DIVIDE(4,3,16,15) yields 1.3...2 to 15 digits No, it yields 1.33 -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN
Re: PL/I Integer arithmetic (was: Constant Identifiers)
Since when is 1.33... an integer? -- Shmuel (Seymour J.) Metz http://mason.gmu.edu/~smetz3 From: IBM Mainframe Discussion List on behalf of Robin Vowels Sent: Wednesday, September 9, 2020 10:08 AM To: IBM-MAIN@LISTSERV.UA.EDU Subject: Re: PL/I Integer arithmetic (was: Constant Identifiers) From: "Seymour J Metz" Sent: Monday, September 07, 2020 4:13 PM > PL/I has never had integers. It always has had integers. > The arithmetic rules for scaled fixed point are different from those for > integers. > In integer arithmetic, (4/3)*6 is 6 That's not the result you get in PL/I. Yes it is, with declarations as shown, as I said before, . Under IBM rules: %PROCESS RULES(IBM); INTEGER_DIVISION: PROCEDURE OPTIONS (MAIN); DECLARE (A, B) FIXED DECIMAL (15); A = 4; B = 3; PUT (4/3); PUT (A/B); PUT ( (A/B) * 6 ); END INTEGER_DIVISION; /* RESULTS: 1.33 1 6 */ And under Rules (ans): %PROCESS RULES(ANS); INTEGER_DIVISION: PROCEDURE OPTIONS (MAIN); DECLARE (A, B) FIXED DECIMAL (15); A = 4; B = 3; PUT (4/3); PUT (A/B); PUT ( (A/B) * 6 ); END INTEGER_DIVISION; /* RESULTS: 1.33 1 6 */ As you can see, the results are the same under IBM and ANS rules. From: IBM Mainframe Discussion List on behalf of Robin Vowels Sent: Sunday, September 6, 2020 7:06 PM Subject: Re: Constant Identifiers - Original Message - From: "Seymour J Metz" Sent: Monday, September 07, 2020 5:33 AM > PL/I doesn't have integers. PL/I has always had integers. > The ratiio 4/3 is FIXED BIN, No it not. It is FIXED DECIMAL -- as I said a few days ago. And it hasn't changed since. > with some number of bits after the binary point. DECIMAL digits after the decimal point, because the reault is FIXED DECIMAL, not binary. --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus -- 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 -- 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
Re: PL/I Integer arithmetic. (was: Constant Identifiers)
The results that you have described are not integer arithmetic. In integer arithmetic, 4/3 is 1. -- Shmuel (Seymour J.) Metz http://mason.gmu.edu/~smetz3 From: IBM Mainframe Discussion List on behalf of Robin Vowels Sent: Wednesday, September 9, 2020 10:14 AM To: IBM-MAIN@LISTSERV.UA.EDU Subject: Re: PL/I Integer arithmetic. (was: Constant Identifiers) - Original Message - From: "Seymour J Metz" Sent: Monday, September 07, 2020 3:02 PM Subject: Re: Constant Identifiers 4/3 yields 1.3, 04/3 yields 1332, ... Rubbish. 4/3 yields 1.33 INTEGER_DIVISION: PROCEDURE OPTIONS (MAIN); DECLARE (A, B) FIXED DECIMAL (15); A = 4; B = 3; PUT (4/3); PUT (A/B); PUT ( (A/B) * 6 ); END INTEGER_DIVISION; /* RESULTS: 1.33 1 6 */ However, DIVIDE(4,3,16,15) yields 1.3...2 to 15 digits No, it yields 1.33 From: IBM Mainframe Discussion List on behalf of Robin Vowels Sent: Sunday, September 6, 2020 7:58 PM Subject: Re: Constant Identifiers From: "Paul Gilmartin" <000433f07816-dmarc-requ...@listserv.ua.edu> Sent: Sunday, September 06, 2020 1:33 PM On Sat, 5 Sep 2020 08:13:42 +1000, Robin Vowels wrote: > >As for writing formulas, I prefer to follow a well-known formula, thus: > >volume = 4/3 * 3.14159 * radius**3 > Beware! Than might left-associate as: volume = ( 4/3 ) * 3.14159 * radius**3 "might"? Evaluation MUST proceed left to right. So, whether it is written as 4/3 or (4/3), the division will be done first. > ... and the quotient of integers, 4/3, is 1. As I indicaed before, 4/3 yields 1.333.to 15 digits. >However, if I'm interested in efficiency, I'd prefer > >volume = 4 * 3.14159E0 / 3 * radius**3 > ... (and correct.) Yes, it's correct, but I wrote it that way in order to avoid unnecessary conversions and arithmetic in fixed-point. --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus -- 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 -- 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
Re: PL/I Integer arithmetic. (was: Constant Identifiers)
- Original Message - From: "Seymour J Metz" Sent: Monday, September 07, 2020 3:02 PM Subject: Re: Constant Identifiers 4/3 yields 1.3, 04/3 yields 1332, ... Rubbish. 4/3 yields 1.33 INTEGER_DIVISION: PROCEDURE OPTIONS (MAIN); DECLARE (A, B) FIXED DECIMAL (15); A = 4; B = 3; PUT (4/3); PUT (A/B); PUT ( (A/B) * 6 ); END INTEGER_DIVISION; /* RESULTS: 1.33 1 6 */ However, DIVIDE(4,3,16,15) yields 1.3...2 to 15 digits No, it yields 1.33 From: IBM Mainframe Discussion List on behalf of Robin Vowels Sent: Sunday, September 6, 2020 7:58 PM Subject: Re: Constant Identifiers From: "Paul Gilmartin" <000433f07816-dmarc-requ...@listserv.ua.edu> Sent: Sunday, September 06, 2020 1:33 PM On Sat, 5 Sep 2020 08:13:42 +1000, Robin Vowels wrote: As for writing formulas, I prefer to follow a well-known formula, thus: volume = 4/3 * 3.14159 * radius**3 Beware! Than might left-associate as: volume = ( 4/3 ) * 3.14159 * radius**3 "might"? Evaluation MUST proceed left to right. So, whether it is written as 4/3 or (4/3), the division will be done first. ... and the quotient of integers, 4/3, is 1. As I indicaed before, 4/3 yields 1.333.to 15 digits. However, if I'm interested in efficiency, I'd prefer volume = 4 * 3.14159E0 / 3 * radius**3 ... (and correct.) Yes, it's correct, but I wrote it that way in order to avoid unnecessary conversions and arithmetic in fixed-point. --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus -- 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 -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN
Re: PL/I Integer arithmetic (was: Constant Identifiers)
From: "Seymour J Metz" Sent: Monday, September 07, 2020 4:13 PM PL/I has never had integers. It always has had integers. The arithmetic rules for scaled fixed point are different from those for integers. In integer arithmetic, (4/3)*6 is 6 That's not the result you get in PL/I. Yes it is, with declarations as shown, as I said before, . Under IBM rules: %PROCESS RULES(IBM); INTEGER_DIVISION: PROCEDURE OPTIONS (MAIN); DECLARE (A, B) FIXED DECIMAL (15); A = 4; B = 3; PUT (4/3); PUT (A/B); PUT ( (A/B) * 6 ); END INTEGER_DIVISION; /* RESULTS: 1.33 1 6 */ And under Rules (ans): %PROCESS RULES(ANS); INTEGER_DIVISION: PROCEDURE OPTIONS (MAIN); DECLARE (A, B) FIXED DECIMAL (15); A = 4; B = 3; PUT (4/3); PUT (A/B); PUT ( (A/B) * 6 ); END INTEGER_DIVISION; /* RESULTS: 1.33 1 6 */ As you can see, the results are the same under IBM and ANS rules. From: IBM Mainframe Discussion List on behalf of Robin Vowels Sent: Sunday, September 6, 2020 7:06 PM Subject: Re: Constant Identifiers - Original Message - From: "Seymour J Metz" Sent: Monday, September 07, 2020 5:33 AM PL/I doesn't have integers. PL/I has always had integers. The ratiio 4/3 is FIXED BIN, No it not. It is FIXED DECIMAL -- as I said a few days ago. And it hasn't changed since. with some number of bits after the binary point. DECIMAL digits after the decimal point, because the reault is FIXED DECIMAL, not binary. --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus -- 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 -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN
Re: PL/I integer arithmetic
"The maximum number of decimal digits allowed is 15. Default precision, assumed when no specification is made, is (5,0). The internal coded arithmetic form of decimal fixed-point data is packed decimal. Packed decimal is stored two digits to the byte, with a sign indication in the rightmost four bits of the rightmost byte. Consequently, a decimal fixed-point data item is always stored as an odd number of digits, even though the declaration of the variable may specify the number of digits (p) as an even number." Page 17 http://www.bitsavers.org/pdf/ibm/370/pli/GC33-0009-3_OS_PLI_Language_Reference_Jul74.pdf Joe On Mon, Sep 7, 2020 at 8:43 AM Robin Vowels wrote: > You think that I am not looking at IBM's PL/I LRM? > > On 2020-09-07 23:25, Joe Monk wrote: > > The answer is here: > > > > > https://www.ibm.com/support/knowledgecenter/SSY2V3_5.2.0/com.ibm.ent.pl1.zos.doc/lr/resarithoprt.html > > > > Joe > > -- > 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
Re: PL/I integer arithmetic
You think that I am not looking at IBM's PL/I LRM? On 2020-09-07 23:25, Joe Monk wrote: The answer is here: https://www.ibm.com/support/knowledgecenter/SSY2V3_5.2.0/com.ibm.ent.pl1.zos.doc/lr/resarithoprt.html Joe -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN
Re: PL/I integer arithmetic
The answer is here: https://www.ibm.com/support/knowledgecenter/SSY2V3_5.2.0/com.ibm.ent.pl1.zos.doc/lr/resarithoprt.html Joe On Mon, Sep 7, 2020 at 8:12 AM Robin Vowels wrote: > You are looking at the wrong part of the table. > This discussion is about DECIMAL operands. > what I wrote is correct for such. > See Table 15 top entry, for ANS rules for division; > Table 16 top entry, for IBM rules. > > On 2020-09-07 22:19, Joe Monk wrote: > > Actually it does... > > > > Under the IBM suboption: > > > > > >- Nonzero scale factors are permitted in FIXED BIN declarations. > > > > > >- If the result of any precision-handling built-in function (ADD, > >BINARY, and so on) has FIXED BIN attributes, the specified or > > implied scale > >factor can be nonzero. > > > > Under the ANS suboption: > > > > > >- Nonzero scale factors are not permitted in FIXED BIN declares. > > > > > >- If the result of any precision-handling built-in function (ADD, > >BINARY, and so on) has FIXED BIN attributes, the specified or > > implied scale > >factor must be zero. > > > > > > > https://www.ibm.com/support/knowledgecenter/SSZHNR_2.0.0/com.ibm.ent.pl1.zos.doc/pg/rules.html > > > > Joe > > > > On Mon, Sep 7, 2020 at 12:23 AM Robin Vowels > > wrote: > > > >> On 2020-09-07 13:05, Joe Monk wrote: > >> > "No it isn't. 4/3 yields 1.33... to 15 digits, > >> > and is of precision (15,14)" > >> > > >> > Depends on RULES(IBM) or RULES(ANS). If its RULES(IBM) it will never > be > >> > integer division. > >> > >> It doesn't depend on whether IBM rules or ANS rules are in force. > >> > >> What I said it correct for IBM rules also. > >> The result is always an integer. > >> See Table 16. > >> When the operands have maximum precision, the result is integer. > >> > >> The formulas for precision and scale factor are exactly the same. > >> > >> > If its RULES(ANS) and the operands are unscaled, then it > >> > will be integer division. > >> > > >> > On Sun, Sep 6, 2020 at 7:34 PM Robin Vowels > >> > wrote: > >> > > >> >> On 2020-09-07 09:35, Joe Monk wrote: > >> >> > "PL/I doesn't have integers." > >> >> > > >> >> > Sorry Shmuel, youre incorrect. > >> >> > > >> >> > FIXED BINARY (15,0) is a 2 byte integer and FIXED BINARY (31,0) is > a 4 > >> >> > byte > >> >> > integer. > >> >> > > >> >> > "The ratiio 4/3 is FIXED BIN," > >> >> > > >> >> > No, its FIXED DECIMAL (1,0)... > >> >> > >> >> No it isn't. 4/3 yields 1.33... to 15 digits, > >> >> and is of precision (15,14) > > -- > 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
Re: PL/I integer arithmetic
You are looking at the wrong part of the table. This discussion is about DECIMAL operands. what I wrote is correct for such. See Table 15 top entry, for ANS rules for division; Table 16 top entry, for IBM rules. On 2020-09-07 22:19, Joe Monk wrote: Actually it does... Under the IBM suboption: - Nonzero scale factors are permitted in FIXED BIN declarations. - If the result of any precision-handling built-in function (ADD, BINARY, and so on) has FIXED BIN attributes, the specified or implied scale factor can be nonzero. Under the ANS suboption: - Nonzero scale factors are not permitted in FIXED BIN declares. - If the result of any precision-handling built-in function (ADD, BINARY, and so on) has FIXED BIN attributes, the specified or implied scale factor must be zero. https://www.ibm.com/support/knowledgecenter/SSZHNR_2.0.0/com.ibm.ent.pl1.zos.doc/pg/rules.html Joe On Mon, Sep 7, 2020 at 12:23 AM Robin Vowels wrote: On 2020-09-07 13:05, Joe Monk wrote: > "No it isn't. 4/3 yields 1.33... to 15 digits, > and is of precision (15,14)" > > Depends on RULES(IBM) or RULES(ANS). If its RULES(IBM) it will never be > integer division. It doesn't depend on whether IBM rules or ANS rules are in force. What I said it correct for IBM rules also. The result is always an integer. See Table 16. When the operands have maximum precision, the result is integer. The formulas for precision and scale factor are exactly the same. > If its RULES(ANS) and the operands are unscaled, then it > will be integer division. > > On Sun, Sep 6, 2020 at 7:34 PM Robin Vowels > wrote: > >> On 2020-09-07 09:35, Joe Monk wrote: >> > "PL/I doesn't have integers." >> > >> > Sorry Shmuel, youre incorrect. >> > >> > FIXED BINARY (15,0) is a 2 byte integer and FIXED BINARY (31,0) is a 4 >> > byte >> > integer. >> > >> > "The ratiio 4/3 is FIXED BIN," >> > >> > No, its FIXED DECIMAL (1,0)... >> >> No it isn't. 4/3 yields 1.33... to 15 digits, >> and is of precision (15,14) -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN