home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / math / verylarg / sqrroot.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-10-22  |  2.4 KB  |  90 lines

  1. Program Roots;    { you choose number and precision }
  2.  
  3. uses    vlncls;
  4.  
  5. var  dummy : tWordArray;     { dummy }
  6.      i, nmbr, root,
  7.      CountMax,StdVLNSize,
  8.      precision    : integer;
  9.      a, b, c, d     : pVryLrgNo;
  10.  
  11. begin
  12.     { wksize is initialized to 100 words of storage }
  13.     { but we make it larger before any memory is allocated }
  14.     Setwksize(1000);
  15.     OpenTempRegs;
  16.                             { standard subs need temp storage }
  17.                             { their max count is wksize      }
  18.                             { their needed storage is wksize*2+6 }
  19.  
  20.     CountMax := Getwksize;           { set count to anyvalue <= wksize }
  21.     StdVLNSize := CountMax*2+6; {these variables need this much storage }
  22.  
  23.     getmem(a, StdVLNSize);
  24.     getmem(b, StdVLNSize);
  25.     getmem(c, StdVLNSize);
  26.     getmem(d, StdVLNSize);
  27.  
  28.     dummy[1] := 1;
  29.     dummy[2] := 5;
  30.     dummy[3] := 0;
  31.     a^.init(3,CountMax,1, @dummy);
  32.     a^.Recount;
  33.  
  34.     dummy[1] := $CA00;       { decimal 1,000,000,000 }
  35.     dummy[2] := $3B9A;
  36.     b^.init(2,CountMax,1,@dummy);
  37.     b^.Recount;
  38.  
  39.     c^.init(0,CountMax,1,nil);
  40.     d^.init(0,CountMax,1,nil);
  41.  
  42.     writeln('Max Number size = ',CountMax * 16 div 3,' decimal digits');
  43.  
  44.     repeat
  45.        writeln('--------------------------------');
  46.        write('Enter Number - ');
  47.        Readln(nmbr);
  48.        if nmbr=0 then exit;
  49.        root := 2;
  50.  
  51.        write('Enter Precision  - ');
  52.        Readln(precision);
  53.        c^.SetSmall(10);
  54.        if precision>1 then
  55.           c^.NthPower(2*precision);
  56.  
  57.        c^.MulN(nmbr);
  58.        writeln('Intermediate Number has appx. ',c^.Count * 16 div 3,' decimal digits');
  59.  
  60.        c^.NthRoot(root);
  61.        write('root is - '); c^.writeDecimal(0); writeln;
  62.  
  63.  
  64. (*  Test by multiplying out to get original number
  65.      d^.copy(c);
  66.        for i := 1 to root-1 do
  67.          d^.mulBy(c);
  68.  
  69.        write('answer multiplied out gives - '); d^.writeDecimal(2); writeln;
  70.  
  71.        c^.addN(1);
  72.        d^.copy(c);
  73.        for i := 1 to root-1 do
  74.          d^.mulBy(c);
  75.        write('answer+1 multiplied out gives - '); d^.writeDecimal(2); writeln;
  76.   *)
  77.     until nmbr=0;
  78.  
  79.     writeln('--------------------------------');
  80.  
  81.  
  82.     writeln('Done!');
  83.  
  84.     freemem(a, StdVLNSize);         { user variables }
  85.     freemem(b, StdVLNSize);
  86.     freemem(c, StdVLNSize);
  87.     freemem(d, StdVLNSize);
  88.  
  89.     CloseTempRegs;   { registers used by arithmetic }
  90.     end.