comp.lang.ada
 help / color / mirror / Atom feed
From: Roderick Chapman <rod@praxis.co.uk>
Subject: Re: Ada function sqrt(x)
Date: 1996/09/20
Date: 1996-09-20T00:00:00+00:00	[thread overview]
Message-ID: <324306A9.9E2@praxis.co.uk> (raw)
In-Reply-To: Dy0xBw.A1u@thomsoft.com


Keith Thompson wrote:
> 
> In <51o7nh$5vl@cf01> pascal.obry@der.edfgdf.fr (Pascal Obry) writes:
> > "zeppelin" <zeppelin@access.mountain.net> 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




  reply	other threads:[~1996-09-20  0:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <01bba50c$7c1a2760$dc014dc6@MountainNet>
1996-09-18  0:00 ` Ada function sqrt(x) Pascal Obry
1996-09-20  0:00   ` Keith Thompson
1996-09-20  0:00     ` Roderick Chapman [this message]
1996-09-21  0:00     ` Robert Dewar
1996-09-26  0:00       ` Keith Thompson
1996-09-21  0:00     ` Robert Dewar
1996-09-22  0:00     ` Matthew Heaney
1996-09-22  0:00       ` Matthew Heaney
1996-09-24  0:00 W. Wesley Groleau (Wes)
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox