From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,b2923d60cb81694b X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!newsfeed-0.progon.net!progon.net!uucp.gnuu.de!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Unsigned Integer Restraint Errors Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1173712032.183064.264340@8g2000cwh.googlegroups.com> <1173726806.656979.305660@8g2000cwh.googlegroups.com> <1173787790.826099.287610@s48g2000cws.googlegroups.com> <1173797935.875023.7590@p10g2000cwp.googlegroups.com> <1173801854.505211.245650@64g2000cwx.googlegroups.com> Date: Tue, 13 Mar 2007 18:23:58 +0100 Message-ID: <10l92gksnkfjl$.1rhbr6sokrtjy.dlg@40tude.net> NNTP-Posting-Date: 13 Mar 2007 18:23:52 CET NNTP-Posting-Host: de95faab.newsspool4.arcor-online.net X-Trace: DXC=aOFDU?g@02:L2C_`koXfC54IUK2mjDUGon<\6oRS:nBYPeb4 X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:14521 Date: 2007-03-13T18:23:52+01:00 List-Id: On 13 Mar 2007 09:04:14 -0700, Adam Beneschan wrote: > on the theory that using Sqrt is just a waste of cycles when you can > just use integer arithmetic. But I've been programming for way too > long---long enough that I remember what a Hollerith card is ... and what was the Hollerith format of strings? (:-)) >---and I'm > sure that doing a square-root doesn't take nearly as long as it used > to, so there are probably some reasonable values of N for which > computing the square-root first makes things more efficient than the > repeated integer multiplications. I don't know. Use Sqrt if you want > to. (for very large number like in infinite arithmetic it could become an issue) BTW, the arithmetic complexity can be further "reduced" by removing multiplication and computing k**2 using binomial decomposition (k+1)*(k+1)=k*k+2*k+1. So it could be: quadratic := 1; -- k*k, k=1 linear := 2; -- 2*k+1, k=1 loop linear := linear + 2; -- 2*k+1 quadratic := quadratic + linear; -- k*k exit when k>=n; ... end loop; Whether this really would be any faster than multiplication or square root computed once, God knows... -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de