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 <IBM-MAIN@LISTSERV.UA.EDU> on behalf of Robin Vowels <robi...@dodo.com.au> 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" <sme...@gmu.edu> 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.33333333333333 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.33333333333333 1 6 */ However, DIVIDE(4,3,16,15) yields 1.3...2 to 15 digits No, it yields 1.33333333333333 ________________________________________ From: IBM Mainframe Discussion List <IBM-MAIN@LISTSERV.UA.EDU> on behalf of Robin Vowels <robi...@dodo.com.au> Sent: Sunday, September 6, 2020 7:58 PM Subject: Re: Constant Identifiers From: "Paul Gilmartin" <0000000433f07816-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.3333333.....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