home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
viscobv6.zip
/
vac22os2
/
ibmcobol
/
samples
/
toolkit
/
rexx
/
api
/
rexxcalc
/
program2.cal
< prev
next >
Wrap
Text File
|
1996-11-19
|
1KB
|
27 lines
/* Rexx Calculator program 2 key - square root */
parse arg num, right /* get the two operands */
numeric digits CalcPrecision() /* set current precision */
numeric form value CalcForm() /* set current form */
/* Function to calculate the square root of a number using */
/* the Newton-Raphson method */
if num < 0 /* check for negative */
then return 'Error'
else if num = 0 then return 0 /* check for 0 */
xnew = num /* initialize answer */
/* calculate maximum */
eps = 0.5 * 10**(1+fuzz()-digits()) /* accuracy */
/* Loop until a sufficiently accurate answer is obtained. */
do until abs(xold-xnew) < (eps*xnew)
xold = xnew /* save the old value */
xnew = 0.5 * (xold + num / xold) /* calculate the new */
end
xnew = xnew / 1 /* make it pretty */
return xnew