                    Calculating Square Roots
        (PC Magazine Vol 4 No 23 Nov 12, 1985 Power User)

     The following is an old Pascal routine for calculating square
roots converted into dBASE.  Simply STORE the number you would like
to a memory variable "number" and execute the procedure with DO SQRT.
The result will be returned in the variable "sqrt."  This result will
be accurate to at least eight decimal places, perhaps more, depending
on the precision of the initial number.
     Editor's Note:  Converting Pascal routines into dBASE sounds like
an avenue with all sorts of possible applications.  There are thousands
of Pascal routines to solve many of the problems dBASE programmers
face, making this one to avoid rediscovering the wheel.  The syntax
of each of the two languages is similar enough to make Pascal an
attractive source of ideas for .PRG files.  Expect a lot of debugging
though.  The program below is modified slightly to add both an INPUT
line at the top and a "?" line at the end.  These lines make the
program usable as a standalone method for obtaining square roots.
To use the routine within a more complex application, you can drop
these lines if the preceding code creates a memory variable called
"number".

* SQRT.PRG -- finds square roots [dBASE III]
* ENTER WITH number = NUMBER
* RETURNS WITH sqr = SQUARE ROOT

SET HEADING OFF
SET SAFETY OFF
SET TALK OFF
INPUT "NUMBER? " TO NUMBER
STORE NUMBER * 1.00000000 TO LQnum
STORE (1 + LQnum) / 2 TO LQs
STORE LQnum * .00000001 TO LQtest
STORE .N. TO LQdone
DO WHILE .NOT. LQdone
  STORE LQs * LQs - LQnum TO lqHOLD
  IF LQhold < 0
    STORE 0 - LQhold TO LQhold
  ENDIF
  IF LQhold < LQtest
    STORE .Y. TO LQdone
    LOOP
  ENDIF
  STORE (LQs + (LQnum / LQs)) / 2 TO LQs
ENDDO
STORE LQs TO SQR
? "ANSWER: "
?? SQR
RELEASE ALL LIKE LQ*
SET TALK ON
RETURN
