home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / kmpl9803.zip / 0_sqrt.cmd < prev    next >
OS/2 REXX Batch file  |  1998-02-14  |  652b  |  46 lines

  1. /* REXX-Programm sqrt.CMD */
  2.  
  3.    arg x,ND
  4.    Numeric Digits ND+30
  5.              
  6.    if x<1.0E-10000 | x>1.0E+10000 | x<0 then signal VW 
  7.    if (x=0) then return(0)
  8.    if (x=1) then return(1)
  9.  
  10.    if x<1 then SIGNAL A
  11.    else
  12.    do
  13.      n=0
  14.      do while x>100
  15.        x=x/100
  16.        n=n+1
  17.      end
  18.    end
  19.    SIGNAL B
  20.  
  21.    A:
  22.      n=0
  23.      do while x<(0.01)
  24.        x=x*100
  25.        n=n-1
  26.      end
  27.      SIGNAL B
  28.  
  29.    B:
  30.      y=1
  31.      t=x/y
  32.      do while abs(y-t) > y*10**(-ND-20)  
  33.        y=(y+t)/2
  34.        t=x/y
  35.      end
  36.  
  37.    u=y*10**n
  38.    numeric digits ND+5
  39.    return(Format(u)) 
  40.  
  41. EXIT
  42.  
  43. vW:
  44.    return(NULL)
  45.    EXIT
  46.