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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham 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!postnews.google.com!64g2000cwx.googlegroups.com!not-for-mail From: "Adam Beneschan" Newsgroups: comp.lang.ada Subject: Re: Unsigned Integer Restraint Errors Date: 13 Mar 2007 09:04:14 -0700 Organization: http://groups.google.com Message-ID: <1173801854.505211.245650@64g2000cwx.googlegroups.com> 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> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: posting.google.com 1173801860 31301 127.0.0.1 (13 Mar 2007 16:04:20 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 13 Mar 2007 16:04:20 +0000 (UTC) In-Reply-To: <1173797935.875023.7590@p10g2000cwp.googlegroups.com> User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: 64g2000cwx.googlegroups.com; posting-host=66.126.103.122; posting-account=cw1zeQwAAABOY2vF_g6V_9cdsyY_wV9w Xref: g2news1.google.com comp.lang.ada:14513 Date: 2007-03-13T09:04:14-07:00 List-Id: On Mar 13, 7:58 am, "frikk" wrote: > I have a bit of an unrelated (but kind of related) question: > > Are there any builtin square root functions? I thought this was > working, but I don't think it is anymore: > m := Integer(100**(0.5)+1); This couldn't have worked as written, since there is no predefined "**" that accepts a floating-point number on the right side. > This always coming out to 2. I;m using this to computer a maximum loop > value for finding primes. I'd like to loop from 2 to sqrt(n)/2 + 1. > > Any suggestions? See Section A.5.1. Ada.Numerics.Elementary_Functions (A.5.1(9)) defines Sqrt as well as a "**" that accepts floating-point exponents. By the way, if I were going to write a loop that goes from 2 to sqrt(n)/2 + 1, I wouldn't use Sqrt like this: for I in 2 .. Integer(Float'Floor(Sqrt(Float(N))/2.0)) + 1 loop... but rather, I'd just write it something like this: I := 2; while (2 * I - 1) * (2 * I - 1) <= N loop -- I think I got this right ... I := I + 1; end loop; 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 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. -- Adam