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

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