summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/apnum
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2015-01-04 23:05:16 +0000
committerKarl Berry <karl@freefriends.org>2015-01-04 23:05:16 +0000
commit90561dbec0fcb33dc7607338973c174774a32aba (patch)
treec30a0b0c035d2e8a62f14f0dd372ed7461f4b71c /Master/texmf-dist/tex/generic/apnum
parenta720b5b8835a3527a1454d218a856e45643611d5 (diff)
apnum (4jan15)
git-svn-id: svn://tug.org/texlive/trunk@35958 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/generic/apnum')
-rw-r--r--Master/texmf-dist/tex/generic/apnum/apnum.tex139
1 files changed, 65 insertions, 74 deletions
diff --git a/Master/texmf-dist/tex/generic/apnum/apnum.tex b/Master/texmf-dist/tex/generic/apnum/apnum.tex
index cb891d55bcc..28f1dea9557 100644
--- a/Master/texmf-dist/tex/generic/apnum/apnum.tex
+++ b/Master/texmf-dist/tex/generic/apnum/apnum.tex
@@ -1,10 +1,10 @@
% Arbitrary precision numbers
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% 2014 Petr Olsak
+% 2014, 2015 Petr Olsak
% See the documentation apnum.pdf or apnum.d for more information
-\def\apnumversion{1.0 <Nov. 2014>}
+\def\apnumversion{1.1 <Jan. 2015>}
\message{The Arbitrary Precision Numbers, \apnumversion}
%%%%%%%%%%%% Internal registers:
@@ -55,17 +55,17 @@
\apTESTdigit#1\iftrue
\ifx E#1\let\tmpb=\tmpa \expandafter\apEVALd\expandafter\apEVALk
\else \edef\tmpb{\tmpa#1}\expandafter\apEVALd\expandafter\apEVALn\fi\fi
- \edef\tmpb{\tmpa\noexpand#1}\futurelet\next\apEVALg
+ \edef\tmpb{\tmpa\noexpand#1}\futurelet\apNext\apEVALg
}
-\def\apEVALd#1\fi#2\next\apEVALg{\fi#1}
+\def\apEVALd#1\fi#2\apNext\apEVALg{\fi#1}
\def\apEVALe{%
\ifx\tmpa\empty \else \ifnum\tmpa1<0 \def\tmpb{-1}\apEVALp \MUL 4\fi\fi
\advance\apnumA by4
\apEVALb
}
\def\apEVALf#1#2{\expandafter\def\expandafter\tmpb\expandafter{\tmpa#1#2}\apEVALo}
-\def\apEVALg{\ifx\next \bgroup \expandafter\apEVALh \else \expandafter\apEVALo \fi}
-\def\apEVALh#1{\expandafter\def\expandafter\tmpb\expandafter{\tmpb{#1}}\futurelet\next\apEVALg}
+\def\apEVALg{\ifx\apNext \bgroup \expandafter\apEVALh \else \expandafter\apEVALo \fi}
+\def\apEVALh#1{\expandafter\def\expandafter\tmpb\expandafter{\tmpb{#1}}\futurelet\apNext\apEVALg}
\def\apEVALk{\afterassignment\apEVALm\apE=}
\def\apEVALm{\edef\tmpb{\tmpb E\the\apE}\apEVALo}
\def\apEVALn#1{\apTESTdigit#1%
@@ -73,22 +73,22 @@
\else\edef\tmpb{\tmpb#1}\expandafter\expandafter\expandafter\apEVALn\fi
\else \expandafter\apEVALo\expandafter#1\fi
}
-\def\apEVALo#1{\let\next=\apEVALb
+\def\apEVALo#1{\let\apNext=\apEVALb
\ifx+#1\apEVALp \apEPLUS 1\fi
\ifx-#1\apEVALp \apEMINUS 1\fi
\ifx*#1\apEVALp \apEMUL 2\fi
\ifx/#1\apEVALp \apEDIV 2\fi
\ifx^#1\apEVALp \apEPOW 3\fi
- \ifx)#1\advance\apnumA by-4 \let\next=\apEVALo \let\tmpa=\relax
+ \ifx)#1\advance\apnumA by-4 \let\apNext=\apEVALo \let\tmpa=\relax
\ifnum\apnumA<0 \apEVALerror{many brackets ")"}\fi
\fi
\ifx\end#1%
\ifnum\apnumA>0 \apEVALerror{missing bracket ")"}%
\else \apEVALp\END 0\fi
- \let\next=\relax
+ \let\apNext=\relax
\fi
\ifx\tmpa\relax \else \apEVALerror{unknown operator "\string#1"}\fi
- \apnumE=0 \next
+ \apnumE=0 \apNext
}
\def\apEVALp#1#2{%
\apnumB=#2 \advance\apnumB by\apnumA
@@ -112,7 +112,7 @@
\fi\fi
}
\def\apEVALerror#1{\message{\noexpand\evaldef ERROR: #1.}%
- \def\tmpb{\def\OUT{??}}\def\next##1\end{}%
+ \def\tmpb{\def\OUT{??}}\def\apNext##1\end{}%
}
\def\apTESTdigit#1#2{%
\ifx E#1\apXtrue \else
@@ -166,12 +166,12 @@
}
\def\apPPs#1#2#3{\def\tmpc{#3}\expandafter\apPPt\expandafter#1#2.@#2}
\def\apPPt#1#2{%
- \ifx-#2\apnumG=-1 \def\next{#1}%
- \else \ifx0#2\apnumG=0 \def\next{\apPPu#1}\else \apnumG=1 \def\next{#1#2}\fi\fi
- \next
+ \ifx-#2\apnumG=-1 \def\apNext{#1}%
+ \else \ifx0#2\apnumG=0 \def\apNext{\apPPu#1}\else \apnumG=1 \def\apNext{#1#2}\fi\fi
+ \apNext
}
\def\apPPu#1#2.@#3{\ifx@#2@\apnumG=0 \ifx#1\apROUNDa\def\XOUT{}\fi
- \else\def\next{\apPPt#1#2.@#3}\expandafter\next\fi
+ \else\def\apNext{\apPPt#1#2.@#3}\expandafter\apNext\fi
}
\def\apEVALone#1#2{\evaldef\OUT{#2}\ifnum\apSIGN<0 \expandafter\apNOminus\OUT@\OUT\fi #1}
\def\apEVALtwo#1#2#3{%
@@ -201,8 +201,8 @@
\else \apnumC=-\apnumC \apPLUSb \tmpa\apnumE \tmpb\apnumF \apnumA
\fi
\ifnum\apnumG=0 \def\OUT{0}\apSIGN=0 \apE=0 \else
- \ifnum\apSIGN=0 \apSIGN=\apnumG \let\next=\apPLUSm \else \let\next=\apPLUSp \fi
- \apnumX=0 \edef\OUT{\expandafter}\expandafter \next \OUT@% second pass
+ \ifnum\apSIGN=0 \apSIGN=\apnumG \let\apNext=\apPLUSm \else \let\apNext=\apPLUSp \fi
+ \apnumX=0 \edef\OUT{\expandafter}\expandafter \apNext \OUT@% second pass
\ifnum\apnumD<1 % result in the form .000123
\apnumZ=-\apnumD
\def\tmpa{.}%
@@ -215,11 +215,11 @@
\def\apPLUSb#1#2#3#4#5{%
\edef\tmpd{\ifcase#4\or{}{}{}\or{}{}\or{}\fi#3}%
\edef\tmpc{\ifcase#2\or{}{}{}\or{}{}\or{}\fi}%
- \let\next=\apPLUSc \apnumD=#5\advance\apnumD by4 \apnumG=0 \apnumZ=0 \def\OUT{}%
+ \let\apNext=\apPLUSc \apnumD=#5\advance\apnumD by4 \apnumG=0 \apnumZ=0 \def\OUT{}%
\expandafter\expandafter\expandafter\apPLUSc\expandafter\tmpc#1\apNL\apNL\apNL\apNL@%
}
\def\apPLUSc#1#2#3#4{\apnumY=\apPLUSxA#1#2#3#4\relax
- \ifx\apNL#4\let\next=\apPLUSd\fi
+ \ifx\apNL#4\let\apNext=\apPLUSd\fi
\ifx\apNL#1\relax \ifx\tmpd\empty \expandafter\expandafter\expandafter\apPLUSf \fi\fi
\apPLUSe
}
@@ -230,7 +230,7 @@
\ifnum\apnumZ=0 \apPLUSh \fi
\edef\OUT{{\the\apnumY}\OUT}%
\advance\apnumD by-4
- \next
+ \apNext
}
\def\apPLUSf#1@{}
\def\apPLUSg{\let\tmpc=\apPLUSxA \let\apPLUSxA=\apPLUSxB \let\apPLUSxB=\tmpc}
@@ -371,7 +371,7 @@
\edef\OUT{\ifnum\apSIGN<0-\fi}%
\ifnum\apnumD<0 \edef\OUT{\OUT.}\apnumZ=-\apnumD \apADDzeros\OUT \fi
\apnumE=1 \apnumZ=0
- \let\next=\apDIVg \next % <--- the main calculation loop is here
+ \let\apNext=\apDIVg \apNext % <--- the main calculation loop is here
\ifnum\apnumD>0 \apnumZ=\apnumD \apADDzeros\OUT \fi
\ifnum\apnumE=0 \def\XOUT{0}\else % extracting remainder from \XOUT
\edef\XOUT{\expandafter}\expandafter\apDIVv\XOUT
@@ -383,8 +383,8 @@
\def\apDIVcomp#1#2{%
\expandafter\def\expandafter\tmpc\expandafter{#1\apNL\apNL\apNL\apNL\apNL\apNL\apNL\apNL@}%
\expandafter\def\expandafter\tmpd\expandafter{#2\apNL\apNL\apNL\apNL\apNL\apNL\apNL\apNL@}%
- \def\next{\expandafter\expandafter\expandafter\apDIVcompA\expandafter\tmpc\tmpd}%
- \apXtrue \next
+ \def\apNext{\expandafter\expandafter\expandafter\apDIVcompA\expandafter\tmpc\tmpd}%
+ \apXtrue \apNext
}
\def\apDIVcompA#1#2#3#4#5#6#7#8#9@{%
\ifx#8\apNL \def\tmpc{0000000\apNL@}\else\def\tmpc{#9@}\fi
@@ -392,28 +392,29 @@
\apDIVcompB
}
\def\apDIVcompB#1#2#3#4#5#6#7#8#9@{%
- \ifnum\apnumX<#1#2#3#4#5#6#7#8 \let\next=\relax \apXfalse \else
- \ifnum\apnumX>#1#2#3#4#5#6#7#8 \let\next=\relax \apXtrue
+ \ifnum\apnumX<#1#2#3#4#5#6#7#8 \let\apNext=\relax \apXfalse \else
+ \ifnum\apnumX>#1#2#3#4#5#6#7#8 \let\apNext=\relax \apXtrue
\fi\fi
- \ifx\next\relax\else
- \ifx#8\apNL \def\tmpd{0000000\apNL@}\ifx\tmpc\tmpd\let\next=\relax\fi \else\def\tmpd{#9@}\fi
+ \ifx\apNext\relax\else
+ \ifx#8\apNL \def\tmpd{0000000\apNL@}\ifx\tmpc\tmpd\let\apNext=\relax\fi
+ \else\def\tmpd{#9@}\fi
\fi
- \next
+ \apNext
}
\def\apDIVg{%
\ifx\tmpb\empty
- \ifx\tmpa\empty \def\next{\apDIVi!}\let\nexti=\apDIVi
- \else \def\next{\expandafter\apDIVh\tmpa\apNL\apNL\apNL\apNL!}\let\nexti=\apDIVh
+ \ifx\tmpa\empty \def\apNext{\apDIVi!}\let\apNexti=\apDIVi
+ \else \def\apNext{\expandafter\apDIVh\tmpa\apNL\apNL\apNL\apNL!}\let\apNexti=\apDIVh
\fi\fi
- \ifx\next\apDIVg
+ \ifx\apNext\apDIVg
\apIVread\tmpa \apnumA=\apnumX
\apIVread\tmpb
\edef\XOUT{{\the\apnumX}{\the\apnumA}\XOUT}%
\fi
- \next
+ \apNext
}
\def\apDIVh#1#2#3#4{\apnumZ=#1#2#3#4
- \ifx\apNL#4\let\nexti=\apDIVi\fi
+ \ifx\apNL#4\let\apNexti=\apDIVi\fi
\apDIVi
}
\def\apDIVi{%
@@ -422,7 +423,7 @@
\expandafter\apDIVp\XOUT
\advance\apnumC by-4
\apnumZ=0
- \expandafter\nexti
+ \expandafter\apNexti
\else
\expandafter\apDIVj
\fi
@@ -432,7 +433,7 @@
\apnumA=\apDIVxA \divide\apnumA by\apDIVxB
\def\apOUTl{}\apnumO=1 \apnumL=0
\apnumX=0 \apnumB=0 \apnumE=0
- \let\next=\apDIVq \next 0\apnumZ
+ \let\apNext=\apDIVq \apNext 0\apnumZ
}
\def\apDIVq#1#2#3{% B A B
\advance\apnumO by-1 \ifnum\apnumO=0 \apOUTx \fi
@@ -446,15 +447,15 @@
\expandafter
\edef\csname apOUT:\apOUTn\endcsname{\csname apOUT:\apOUTn\endcsname{#3}{\the\apnumB}}%
\ifnum\apnumE<\apnumB \apnumE=\apnumB \fi
- \ifx@#3\let\next=\apDIVr \fi
- \next{#3}%
+ \ifx@#3\let\apNext=\apDIVr \fi
+ \apNext{#3}%
}
\def\apDIVr#1#2{%
\ifnum\apnumX=#2 % the calculated Digit is OK, we save it
\edef\XOUT{\expandafter\apOUTs\apOUTl.,}%
\edef\tmpa{\ifnum\apnumF=4 \expandafter\apIVwrite\else \expandafter\the\fi\apnumA}%
\ifnum\apnumD<\apnumF \ifnum\apnumD>-1 \apDIVt \fi\fi %adding dot
- \ifx\nexti\apDIVh \apnumE=1 \fi
+ \ifx\apNexti\apDIVh \apnumE=1 \fi
\ifnum\apnumE=0 \apDIVu % removing zeros
\advance\apnumD by-\apNUMdigits\tmpa \relax
\else \advance\apnumD by-\apnumF \apnumF=4 \fi
@@ -463,9 +464,9 @@
\else % we need do correction and run the remainder calculation again
\advance\apnumA by-1 \apnumX=0 \apnumB=0 \apnumE=0
\def\apOUTl{}\apnumO=1 \apnumL=0
- \def\next{\let\next=\apDIVq
- \expandafter\next\expandafter0\expandafter\apnumZ\XOUT}%
- \expandafter\next
+ \def\apNext{\let\apNext=\apDIVq
+ \expandafter\apNext\expandafter0\expandafter\apnumZ\XOUT}%
+ \expandafter\apNext
\fi
}
\def\apDIVt{\edef\tmpa{\apIVdot\apnumD\tmpa}\edef\tmpa{\tmpa}}
@@ -499,11 +500,8 @@
\edef\tmpc{\ifcase\apnumA\or{}{}{}\or{}{}\or{}\fi}\def\OUT{}%
\expandafter\expandafter\expandafter \apMULb \expandafter \tmpc \tmpa @@@@%
\edef\OUT{*.\OUT}% \OUT := \tmpa in interleaved format
- \let\tmpd=\tmpa \def\tmpa{}%
- \expandafter\expandafter\expandafter \apMULc \expandafter \tmpc \tmpd @@@@%
- \def\tmpc{*.1*}\apnumE=10
- \edef\tmpb{\apREV\tmpb}%
- \expandafter\apPOWb\tmpb@% do multiplications
+ \def\tmpc{*.1*}%
+ \apnumE=\tmpb\relax \apPOWb
\expandafter\apPOWg \tmpc % \OUT := \tmpc in human raedable form
\ifnum\apnumD=0 \ifnum \apSIGN<0 \edef\OUT{-\OUT}\fi
\else \def\tmpc{-\apnumD}\apnumG=\apSIGN \expandafter\apROLLa\OUT.@\OUT\fi
@@ -511,26 +509,17 @@
\relax
\fi\fi
}
-\def\apPOWb#1{%
- \ifx@#1\else
- \ifnum\apnumE<10
- \expandafter\apPOWc\ifcase\apnumE
- ppmp.\or ppmp.\or pmp.\or mmp.\or mp.\or p.\or mmmm.\or mmm.\or mm.\or m.\or .\fi
- \def\tmpb{}\expandafter\apPOWd\OUT \let\tmpa=\tmpb
- \fi
- \apnumE=#1
- \ifnum\apnumE=0 \else
- \expandafter\apPOWc\ifcase\apnumE
- \or .\or p.\or pm.\or pp.\or ppm.\or pmp.\or pmpm.\or ppp.\or pppm.\fi
- \def\tmpb{}\expandafter\apPOWd\OUT
- \let\tmpd=\OUT \let\OUT=\tmpc
- \expandafter\apMULd \tmpb@\expandafter\apPOWn\OUT@%
- \let\tmpc=\OUT \let\OUT=\tmpd
- \fi
- \expandafter\apPOWb
+\def\apPOWb{%
+ \ifodd\apnumE \def\tmpb{}\expandafter\apPOWd\OUT
+ \let\tmpd=\OUT \let\OUT=\tmpc
+ \expandafter\apMULd \tmpb@\expandafter\apPOWn\OUT@%
+ \let\tmpc=\OUT \let\OUT=\tmpd
\fi
-}
-\def\apPOWc#1{\ifx.#1\else \csname apPOW#1\endcsname \expandafter\apPOWc\fi}
+ \divide\apnumE by2
+ \ifnum\apnumE>0 \expandafter\apPOWt\OUT \expandafter\apPOWn\OUT@%
+ \expandafter\apPOWb
+ \fi
+}
\def\apPOWd#1#2{% \apPOWd <spec format> => \tmpb (in simple reverse format)
\ifx*#1\expandafter\apPOWd \else
\edef\tmpb{\tmpb{#1}}%
@@ -542,8 +531,6 @@
\def\apPOWh#1#2{\apnumA=#1
\ifx*#2\edef\OUT{\the\apnumA\OUT}\else \edef\OUT{\apIVwrite\apnumA\OUT}\expandafter\apPOWh\fi
}
-\def\apPOWm{\expandafter\apMULd\tmpa@\expandafter\apPOWn\OUT@}
-\def\apPOWp{\expandafter\apPOWt\OUT \expandafter\apPOWn\OUT@}
\def\apPOWn#1{\def\OUT{*}\apPOWna}
\def\apPOWna#1{\ifx*#1\expandafter\apPOWnn\else \edef\OUT{\OUT0{#1}}\expandafter\apPOWna\fi}
\def\apPOWnn#1#2{\ifx*#1\edef\OUT{\OUT*}\else\edef\OUT{\OUT0{#1}}\expandafter\apPOWnn\fi}
@@ -608,13 +595,13 @@
\else \expandafter\apROUNDb
\fi
}
-\def\apROUNDb#1.{\edef\tmpc{#1}\apnumX=0 \def\tmpd{}\let\next=\apROUNDc \next}
-\def\apROUNDc#1{\ifx@#1\def\next{\apROUNDd.@}%
+\def\apROUNDb#1.{\edef\tmpc{#1}\apnumX=0 \def\tmpd{}\let\apNext=\apROUNDc \apNext}
+\def\apROUNDc#1{\ifx@#1\def\apNext{\apROUNDd.@}%
\else \advance\apnumD by-1
- \ifnum\apnumD<0 \def\next{\apROUNDd#1}%
+ \ifnum\apnumD<0 \def\apNext{\apROUNDd#1}%
\else \ifx.#1\else \advance\apnumX by#1 \edef\tmpd{\tmpd#1}\fi
\fi
- \fi \next
+ \fi \apNext
}
\def\apROUNDd#1.@#2{\def\XOUT{#1}%
\ifnum\apnumX=0 \def\tmpd{}\fi
@@ -667,9 +654,9 @@
\else \expandafter\apDIGc \expandafter#1\fi
}
\def\apDIGc#1.{\def\tmpd{#1}%
- \ifx\tmpc\empty \let\next=\apDIGe
- \else \def\next{\expandafter\apDIGd\tmpd@}%
- \fi \next
+ \ifx\tmpc\empty \let\apNext=\apDIGe
+ \else \def\apNext{\expandafter\apDIGd\tmpd@}%
+ \fi \apNext
}
\def\apDIGd#1{\ifx@#1\expandafter\apDIGe \else \tmpc \expandafter\apDIGd \fi}
\def\apDIGe#1@#2{%
@@ -728,3 +715,7 @@
\catcode`\@=\apnumZ
\endinput
+1.0 <Nov. 2014> - First version released
+1.1 <Jan. 2015>
+ - POW implemented more simple (by base 2 of exponent)
+ - \next renamed in order to avoid name conflict