Wanted: Efficient Algorithm to Square an Integer Number

03072019, 02:52 PM
(This post was last modified: 03082019 12:21 PM by Martin Hepperle.)
Post: #7




RE: Wanted: Efficient Algorithm to Square an Integer Number
(03062019 08:10 PM)ijabbott Wrote: I'm not aware of clever tricks for squaring an integer (and most modern CPUs have fast multiply instructions), but this seems like another opportunity to recommend the book Hacker's Delight (2nd Edition) by Henry S. Warren, Jr. Thank you, this is very interesting and surely comes in handy for future coding problems. My CPUs of interest are older and do not offer multiplication (e.g. 6800 and HPSeries80 Capricorn). I finally found this explanation for the existance of the Sqr() function in "FreePascal from Square One" (http://www.copperwood.com/pub/FreePascal...areOne.pdf): "11.2. Sqr and Sqrt Nothing complicated here. Sqr(X) squares X. It is completely equivalent to X * X, and Pascal includes it because squaring is done so frequently in mathematics, and also because (as we will discuss later) there is no exponentiation operator in Standard Pascal and hence no clean notation for X raised to a power of two. FreePascal does have an exponentiation operator, as I’ll explain shortly, and so with FreePascal, Sqr is unnecessary." So the Sqr() function in Pascal seems to be unrelated to speed, contrary to what I had thought. Thank you all for your help, Martin 

« Next Oldest  Next Newest »

Messages In This Thread 
Wanted: Efficient Algorithm to Square an Integer Number  Martin Hepperle  03062019, 03:54 PM
RE: Wanted: Efficient Algorithm to Square an Integer Number  ijabbott  03062019, 08:10 PM
RE: Wanted: Efficient Algorithm to Square an Integer Number  Martin Hepperle  03072019 02:52 PM
RE: Wanted: Efficient Algorithm to Square an Integer Number  David Hayden  03062019, 08:16 PM
RE: Wanted: Efficient Algorithm to Square an Integer Number  Thomas Okken  03062019, 11:24 PM
RE: Wanted: Efficient Algorithm to Square an Integer Number  Jim Horn  03082019, 12:26 AM
RE: Wanted: Efficient Algorithm to Square an Integer Number  Gerson W. Barbosa  03062019, 11:47 PM
RE: Wanted: Efficient Algorithm to Square an Integer Number  Druzyek  03072019, 12:10 AM

User(s) browsing this thread: 1 Guest(s)