That's obfuscation.
If it's in a loop,  I'd expect the compiler to move the constant part outside 
of the loop,
or to evaluate the constant part at compilation time.

In any case, the more efficient form eliminates the division 4/3,
avoiding the avaluation in fixed-point form (and the conversion
to floating-point).

----- Original Message ----- From: "Bob Bridges" <robhbrid...@gmail.com>
Newsgroups: bit.listserv.ibm-main
To: <IBM-MAIN@LISTSERV.UA.EDU>
Sent: Sunday, September 06, 2020 6:18 AM
Subject: Re: Constant Identifiers


When you care about efficiency, I'd think this would be better:

 const=4/3*3.14159E0 /* in the initialization */
 volume=const*radius**3 /* inside the loop */

---
Bob Bridges, robhbrid...@gmail.com, cell 336 382-7313

/* Things may come to those who wait, but only those things left behind by
those who hustle.  -attributed (probably falsely) to Abraham Lincoln, lawyer
*/

-----Original Message-----
From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU] On
Behalf Of Robin Vowels
Sent: Friday, September 4, 2020 18:14

As for writing formulas, I prefer to follow a well-known formula, thus:

  volume = 4/3 * 3.14159 * radius**3

However, if I'm interested in efficiency, I'd prefer

  volume = 4 * 3.14159E0 / 3 * radius**3

---
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

Reply via email to