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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c0fe3a04fa2416f1 X-Google-Attributes: gid103376,public From: Roderick Chapman Subject: Re: Ada function sqrt(x) Date: 1996/09/20 Message-ID: <324306A9.9E2@praxis.co.uk>#1/1 X-Deja-AN: 184264768 references: <01bba50c$7c1a2760$dc014dc6@MountainNet> <51o7nh$5vl@cf01> content-type: text/plain; charset=us-ascii organization: Praxis Critical Systems mime-version: 1.0 newsgroups: comp.lang.ada x-mailer: Mozilla 2.0 (Win16; I) Date: 1996-09-20T00:00:00+00:00 List-Id: Keith Thompson wrote: > > In <51o7nh$5vl@cf01> pascal.obry@der.edfgdf.fr (Pascal Obry) writes: > > "zeppelin" wrote: > > > > >I want to find the sqrt of a interger... how can I do this and what package > > >do I need to declare > [...] A simple binary chop search is possible. The algorihtm is not that complex, and can even be proven correct with respect to a formal specification (yes...I've actually done this just recently.) Decide if you want a truncated or rounded answer, and be careful when you want an answer for values near Integer'Last, since it's easy to end up trying to square a number that will overflow. Another algorihtm is detailed at: http://www.best.com/~mxmora/umpg/UMPG_II_Math&Algorithms.html In the article Jamie McCarthy, a fast "bit twiddly" algorithm is given which we've found to be about twice as fast as the binary chop. Interestingly, it can be implemented efficiently in Ada (even in the SPARK subset) without any implementation-dependent support for unsigned integers or bit-wise operations. I wouldn't fancy your chances of proving this algorihtm correct, though. I've run an exhausitve test over our the domain of inetegers we have, and it gives the same result as the binary chop algorithm, so that's good enough for me! - Rod Chapman, Praxis Critical Systems rod@praxis.co.uk