summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/fp/fp-pas.sty
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /macros/latex/contrib/fp/fp-pas.sty
Initial commit
Diffstat (limited to 'macros/latex/contrib/fp/fp-pas.sty')
-rw-r--r--macros/latex/contrib/fp/fp-pas.sty118
1 files changed, 118 insertions, 0 deletions
diff --git a/macros/latex/contrib/fp/fp-pas.sty b/macros/latex/contrib/fp/fp-pas.sty
new file mode 100644
index 0000000000..8cef34d97a
--- /dev/null
+++ b/macros/latex/contrib/fp/fp-pas.sty
@@ -0,0 +1,118 @@
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesPackage{fp-pas}[1994/08/29]
+
+%version information
+\def\FP@pasversion{1.0}
+\message{%
+ `Fixed Point Pascal Triangle',%
+ \space\space\space%
+ Version \FP@pasversion\space%
+ \space(C) Michael Mehlich%
+ \space\space\space\space\space\space\space%
+ \space\space\space\space\space\space%
+}
+
+%resolve dependencies
+\RequirePackage{fp-basic}
+
+%%%public area (macros which may be used)%%%
+
+\def\FPpascal#1#2{\FP@pascal{#1}{#2}}%pascal triangle for lines 0,...,63
+
+%%%private fp-area (don't use these macros)%%%
+
+%allocation of registers
+\countdef\FP@pas=50
+\countdef\FP@pasc=51
+
+%addition of two natural numbers
+\def\FP@pasadd#1#2#3{%
+ % #1 macro, which gets the result
+ % #2 1st value
+ % #3 2nd value
+ {\FP@removeleadingzeros#2\relax%
+ \expandafter\FP@setintcounter\FP@tmp000000000000000000\relax%
+ \FP@xia=\FP@rega%
+ \FP@xib=\FP@regb%
+ %
+ \FP@removeleadingzeros#3\relax%
+ \expandafter\FP@setintcounter\FP@tmp000000000000000000\relax%
+ \FP@yia=\FP@rega%
+ \FP@yib=\FP@regb%
+ %
+ \advance\FP@xia\FP@yia%
+ \advance\FP@xib\FP@yib%
+ \ifnum\FP@xib<1000000000\relax\else%
+ \advance\FP@xia1\relax%
+ \advance\FP@xib-1000000000\relax%
+ \fi%
+ \ifnum\FP@xia<1000000000\relax\else%
+ \FP@errmessage{Overflow}%
+ \fi%
+ %
+ \ifnum\FP@xia=0\relax%
+ \edef\FP@tmpa{\the\FP@xib}%
+ \else%
+ \advance\FP@xib1000000000%
+ \edef\FP@tmpa{\the\FP@xia\expandafter\FP@ignorenext\the\FP@xib}%
+ \fi%
+ %
+ \global\let\FP@tmpa\FP@tmpa%
+ }%
+ %
+ \let#1\FP@tmpa%
+}
+
+%the first two entries of the pascal-triangle
+\expandafter\edef\csname FP@pas0\endcsname{[1]}
+\expandafter\edef\csname FP@pas1\endcsname{[1,1]}
+
+%which is the highest line of the pascal-triangle we have already computed?
+\expandafter\edef\csname FP@pascount\endcsname{1}
+
+%compute next line of pascal-triangle
+\def\FP@pasdouble[#1]{%
+ % #1 previous line of pascal-triangle
+ \edef\FP@old{}%
+ \edef\FP@tmpb{}%
+ \@for\FP@new:=#1\do{%
+ \expandafter\if!\FP@old!\relax%
+ \edef\FP@old{\FP@new}%
+ \else%
+ \FP@pasadd{\FP@tmpa}{\FP@old}{\FP@new}%
+ \edef\FP@tmpb{\FP@tmpb,\FP@tmpa}%
+ \edef\FP@old{\FP@new}%
+ \fi%
+ }%
+ \global\edef\FP@tmpb{[1\FP@tmpb,1]}%
+}
+
+%compute n-th line of pascal-triangle
+\def\FP@pascomp#1{%
+ % #1 which line to compute
+ \expandafter\FP@pasc\FP@pascount\relax%
+ \ifnum\FP@pasc<#1\relax%
+ \loop%
+ \ifnum\FP@pasc<#1\relax%
+ \expandafter\expandafter\expandafter\FP@pasdouble\csname FP@pas\the\FP@pasc\endcsname%
+ \advance\FP@pasc1\relax%
+ \edef\next{\noexpand\global\noexpand\let\csname FP@pas\the\FP@pasc\endcsname\noexpand\FP@tmpb}%
+ \next%
+ \repeat%
+ \fi%
+ \global\edef\FP@pascount{\the\FP@pasc}%
+}
+
+\def\FP@pascal#1#2{%
+ % #1 macro, which gets the result
+ % #2 which line of the pascal-triangle to compute
+ {\FP@beginmessage{PASCAL}%
+ %
+ \FP@pas#2\relax%
+ \FP@pascomp\FP@pas%
+ \global\edef\FP@tmp{\csname FP@pas\the\FP@pas\endcsname}%
+ %
+ \FP@endmessage{}%
+ }%
+ \let#1\FP@tmp%
+}