home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 3 / Meeting_Pearls_III.iso / Pearls / texmf / inputs / latex / contrib / other / fp.lha / fp / fp-pas.sty < prev    next >
Text File  |  1995-04-03  |  3KB  |  119 lines

  1. \NeedsTeXFormat{LaTeX2e}
  2. \ProvidesPackage{fp-pas}[1994/08/29]
  3.  
  4. %version information
  5. \def\FP@pasversion{1.0}
  6. \message{%
  7.   `Fixed Point Pascal Triangle',%
  8.   \space\space\space%
  9.   Version \FP@pasversion\space%
  10.   \space(C) Michael Mehlich%
  11.   \space\space\space\space\space\space\space%
  12.   \space\space\space\space\space\space%
  13. }
  14.  
  15. %resolve dependencies
  16. \RequirePackage{fp-basic}
  17.  
  18. %%%public area (macros which may be used)%%%
  19.  
  20. \def\FPpascal#1#2{\FP@pascal{#1}{#2}}%pascal triangle for lines 0,...,63
  21.  
  22. %%%private fp-area (don't use these macros)%%%
  23.  
  24. %allocation of registers
  25. \countdef\FP@pas=50
  26. \countdef\FP@pasc=51
  27.  
  28. %addition of two natural numbers
  29. \def\FP@pasadd#1#2#3{%
  30.   % #1 macro, which gets the result
  31.   % #2 1st value
  32.   % #3 2nd value
  33.   {\FP@removeleadingzeros#2\relax%
  34.    \expandafter\FP@setintcounter\FP@tmp000000000000000000\relax%
  35.    \FP@xia=\FP@rega%
  36.    \FP@xib=\FP@regb%
  37.    %
  38.    \FP@removeleadingzeros#3\relax%
  39.    \expandafter\FP@setintcounter\FP@tmp000000000000000000\relax%
  40.    \FP@yia=\FP@rega%
  41.    \FP@yib=\FP@regb%
  42.    %
  43.    \advance\FP@xia\FP@yia%
  44.    \advance\FP@xib\FP@yib%
  45.    \ifnum\FP@xib<1000000000\relax\else%
  46.      \advance\FP@xia1\relax%
  47.      \advance\FP@xib-1000000000\relax%
  48.    \fi%
  49.    \ifnum\FP@xia<1000000000\relax\else%
  50.      \FP@errmessage{Overflow}%
  51.    \fi%
  52.    %
  53.    \ifnum\FP@xia=0\relax%
  54.      \edef\FP@tmpa{\the\FP@xib}%
  55.    \else%
  56.      \advance\FP@xib1000000000%
  57.      \edef\FP@tmpa{\the\FP@xia\expandafter\FP@ignorenext\the\FP@xib}%
  58.    \fi%
  59.    %
  60.    \global\let\FP@tmpa\FP@tmpa%
  61.   }%
  62.   %
  63.   \let#1\FP@tmpa%
  64. }
  65.  
  66. %the first two entries of the pascal-triangle
  67. \expandafter\edef\csname FP@pas0\endcsname{[1]}
  68. \expandafter\edef\csname FP@pas1\endcsname{[1,1]}
  69.  
  70. %which is the highest line of the pascal-triangle we have already computed?
  71. \expandafter\edef\csname FP@pascount\endcsname{1}
  72.  
  73. %compute next line of pascal-triangle
  74. \def\FP@pasdouble[#1]{%
  75.   % #1 previous line of pascal-triangle
  76.   \edef\FP@old{}%
  77.   \edef\FP@tmpb{}%
  78.   \@for\FP@new:=#1\do{%
  79.     \expandafter\if!\FP@old!\relax%
  80.       \edef\FP@old{\FP@new}%
  81.     \else%
  82.       \FP@pasadd{\FP@tmpa}{\FP@old}{\FP@new}%
  83.       \edef\FP@tmpb{\FP@tmpb,\FP@tmpa}%
  84.       \edef\FP@old{\FP@new}%
  85.     \fi%
  86.   }%
  87.   \global\edef\FP@tmpb{[1\FP@tmpb,1]}%
  88. }
  89.  
  90. %compute n-th line of pascal-triangle
  91. \def\FP@pascomp#1{%
  92.   % #1 which line to compute
  93.   \expandafter\FP@pasc\FP@pascount\relax%
  94.   \ifnum\FP@pasc<#1\relax%
  95.     \loop%
  96.       \ifnum\FP@pasc<#1\relax%
  97.         \expandafter\expandafter\expandafter\FP@pasdouble\csname FP@pas\the\FP@pasc\endcsname%
  98.         \advance\FP@pasc1\relax%
  99.     \edef\next{\noexpand\global\noexpand\let\csname FP@pas\the\FP@pasc\endcsname\noexpand\FP@tmpb}%
  100.     \next%
  101.       \repeat%
  102.   \fi%
  103.   \global\edef\FP@pascount{\the\FP@pasc}%
  104. }
  105.  
  106. \def\FP@pascal#1#2{%
  107.   % #1 macro, which gets the result
  108.   % #2 which line of the pascal-triangle to compute
  109.   {\FP@beginmessage{PASCAL}%
  110.    %
  111.    \FP@pas#2\relax%
  112.    \FP@pascomp\FP@pas%
  113.    \global\edef\FP@tmp{\csname FP@pas\the\FP@pas\endcsname}%
  114.    %
  115.    \FP@endmessage{}%
  116.   }%
  117.   \let#1\FP@tmp%
  118. }
  119.