Getting the square root
Author Message
Getting the square root

This is off topic, but does anyone know how to program a square root
fuction?  any language will be fine.. even an algorithm would be good if
that was all you could get.  Thanks ahead of time,

Tyler Prete

Tue, 30 Jul 2002 03:00:00 GMT
Getting the square root

Quote:
>     This is off topic, but does anyone know how to program a square root
> fuction?  any language will be fine.. even an algorithm would be good if
> that was all you could get.  Thanks ahead of time,

The only function that I had performed on a computer to get a square root
of a number was on a
6502 computer, when I was doing a course at school, and was a superficial
one at that.
I don't have the source, so I will give you the algorithm. Only works on
numbers which have
square roots, such as 64.

64 -1 -3 -5 -7 -9 -11 -13 -15 = 0

1  2  3  4  5   6     7    8.... If you understand that 8)...

Take away each odd number from the particular number until you get 0... at
which point the
number of subtractions will equal the square root. 8)... wasn't too hard to
program.

Another method I have found on the internet after speculation that a
squareroot could be
found by hand is one which may be located at:

http://forum.swarthmore.edu/dr.math/problems/tim3.30.98.html

I have difficulty explaining the method to others... Then of course there
is always the guess
and times the number by itself until it works properly.

Steven Cooke

Wed, 31 Jul 2002 03:00:00 GMT
Getting the square root
On Fri, 11 Feb 2000 22:59:02 -0000, "Tyler Prete"

Quote:

>    This is off topic, but does anyone know how to program a square root
>fuction?  any language will be fine.. even an algorithm would be good if
>that was all you could get.  Thanks ahead of time,

I've got an algorithm , you shouldn't have any problem to program it
since it is a very simple one :

a = your number
a -> x

the algorithm :

(x*x+a) / (2*x)

Do this about 10 times ( well i don't really know how many times : i
found this not long ago and  i haven't programed it yet ) , and you
should get a number very close of the real one .

P.S : Well , if you don't like this one , i've found two other's but
they are a lot more difficult .

Gandalf

Wed, 31 Jul 2002 03:00:00 GMT
Getting the square root
Quote:
>This is off topic, but does anyone know how to program a square root

fuction?

The Square Root function is actually very nice.  It only uses DIV, MUL and
ADD functions to compute.  It works on any number whether it has an integer
root or not.  It can compute decimals out as far as you want to take them.
The further out you go the larger the long division becomes. :)

I have a small paper on it, but it uses some high ASCII characters and
graphics to visualize exactly how it works.  If you are interested in it,
then e-mail me and I'll send a PDF file with that info.

- Rick C. Hodgin

Wed, 31 Jul 2002 03:00:00 GMT
Getting the square root
Hi

I'm really sorry , i made a mistake in this message :

Quote:
>I've got an algorithm , you shouldn't have any problem to program it
>since it is a very simple one :

>a = your number
>a -> x

>the algorithm :

>(x*x+a) / (2*x)

Well , this is true but you must also do this :

x*x -> c

Quote:
>Do this about 10 times ( well i don't really know how many times : i
>found this not long ago and  i haven't programed it yet )

Actually , you must do it while  c > a .

( I hope i did not make you waste your time )

Gandalf

Thu, 01 Aug 2002 03:00:00 GMT
Getting the square root
I wonder.
Why don't you use the Math Coprocessor?

--

Eric P. van Westendorp  Tel: +31(0252)210579
Reigerslaan 22  2215NN Voorhout  Netherlands

Quote:

> Hi

> I'm really sorry , i made a mistake in this message :

> >I've got an algorithm , you shouldn't have any problem to program it
> >since it is a very simple one :

> >a = your number
> >a -> x

> >the algorithm :

> >(x*x+a) / (2*x)

> Well , this is true but you must also do this :

> x*x -> c

> >Do this about 10 times ( well i don't really know how many times : i
> >found this not long ago and  i haven't programed it yet )

> Actually , you must do it while  c > a .

>  ( I hope i did not make you waste your time )

> Gandalf

Fri, 02 Aug 2002 03:00:00 GMT
Getting the square root
ASM:
FLD [value]
FSQRT ST(0)
FST [value]

TP:
Var value:Real;
value:=SQRT(value);

QB:
[LET] value=SQRT(value)

Math:
value-->c1
loop:
value/c1-->c2
(c1+c2)/2-->c1
until c1=c2
c1-->result

Fri, 02 Aug 2002 03:00:00 GMT
Getting the square root
On Mon, 14 Feb 2000 09:30:51 +0100, "E.P. van Westendorp"

Quote:

>I wonder.
>Why don't you use the Math Coprocessor?

Math Coprocessor doesn't exist on several processor :-( , for example
i program for a 68k which has no Math Coprocessor , that's why i have
to find such methode if i need square root , sin , cos ...

Gandalf

Fri, 02 Aug 2002 03:00:00 GMT
Getting the square root
Do you need 68K floating point math routines?  Or are you working in fixed
point or integers?

Paul R. Santa-Maria
Ann Arbor, Michigan  USA

Quote:
> On Mon, 14 Feb 2000 09:30:51 +0100, "E.P. van Westendorp"

> >I wonder.
> >Why don't you use the Math Coprocessor?

> Math Coprocessor doesn't exist on several processor :-( , for example
> i program for a 68k which has no Math Coprocessor , that's why i have
> to find such methode if i need square root , sin , cos ...

> Gandalf

Sat, 03 Aug 2002 03:00:00 GMT
Getting the square root
Hi

Quote:
>Do you need 68K floating point math routines?  Or are you working in fixed
>point or integers?

I need 68K floating point math routines , any information about that
would greatly appreciated .

Gandalf

Sat, 03 Aug 2002 03:00:00 GMT
Getting the square root
You may be better off in comp.sys.m68k.

See my DTACK Grounded archive at
http://people.delphi.com/paulrsm/68k/dg/dg.htm, especially issue 16, for
some background on writing a floating point package.

See 68343FFP.ARC and FFP.ARC in the Motorola 68K archive files.  These are
a complete set of IEEE floating point routines written in 68K assembly
language.

Paul R. Santa-Maria
Ann Arbor, Michigan  USA

Quote:
> >Do you need 68K floating point math routines?  Or are you working in
fixed
> >point or integers?

> I need 68K floating point math routines , any information about that
> would greatly appreciated .

Sun, 04 Aug 2002 03:00:00 GMT
Getting the square root
::Math:
::   value-->c1
::   loop:
::   value/c1-->c2
::   (c1+c2)/2-->c1
::   until c1=c2
::   c1-->result

very nice!

Thu, 08 Aug 2002 03:00:00 GMT

 Page 1 of 1 [ 12 post ]

Relevant Pages
 11. Square Root