diff options
author | Karl Berry <karl@freefriends.org> | 2007-10-05 23:13:42 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2007-10-05 23:13:42 +0000 |
commit | 4c911ff5ebf103e651707635abf2064ddf149c96 (patch) | |
tree | d3550a7008c8851c3df0746c7e9800df307a0699 /Master/texmf-dist/source/latex/oberdiek/intcalc.dtx | |
parent | f020fc73ad0b6e33f65d5f0b84646131e0340f2f (diff) |
oberdiek update/new: bigintcalc bitset grfext
git-svn-id: svn://tug.org/texlive/trunk@5118 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/oberdiek/intcalc.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/oberdiek/intcalc.dtx | 1475 |
1 files changed, 963 insertions, 512 deletions
diff --git a/Master/texmf-dist/source/latex/oberdiek/intcalc.dtx b/Master/texmf-dist/source/latex/oberdiek/intcalc.dtx index 2cef807d937..30cee2ecbee 100644 --- a/Master/texmf-dist/source/latex/oberdiek/intcalc.dtx +++ b/Master/texmf-dist/source/latex/oberdiek/intcalc.dtx @@ -72,7 +72,7 @@ \input docstrip.tex \Msg{************************************************************************} \Msg{* Installation} -\Msg{* Package: intcalc 2007/09/09 v1.0 Expandable integer calculations (HO)} +\Msg{* Package: intcalc 2007/09/27 v1.1 Expandable integer calculations (HO)} \Msg{************************************************************************} \keepsilent @@ -112,7 +112,7 @@ and the derived files \usedir{doc/latex/oberdiek}% \file{intcalc-test1.tex}{\from{intcalc.dtx}{test1}}% \file{intcalc-test2.tex}{\from{intcalc.dtx}{test2,etex}}% - \file{intcalc-test3.tex}{\from{intcalc.dtx}{test3,noetex}}% + \file{intcalc-test3.tex}{\from{intcalc.dtx}{test2,noetex}}% \file{intcalc-test4.tex}{\from{intcalc.dtx}{test4,etex}}% } @@ -139,7 +139,7 @@ and the derived files %<*driver> \NeedsTeXFormat{LaTeX2e} \ProvidesFile{intcalc.drv}% - [2007/09/09 v1.0 Expandable integer calculations (HO)]% + [2007/09/27 v1.1 Expandable integer calculations (HO)]% \documentclass{ltxdoc} \usepackage{holtxdoc} \usepackage{wasysym} @@ -182,7 +182,7 @@ and the derived files %</driver> % \fi % -% \CheckSum{2665} +% \CheckSum{3045} % % \CharacterTable % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z @@ -203,7 +203,7 @@ and the derived files % \GetFileInfo{intcalc.drv} % % \title{The \xpackage{intcalc} package} -% \date{2007/09/09 v1.0} +% \date{2007/09/27 v1.1} % \author{Heiko Oberdiek\\\xemail{oberdiek@uni-freiburg.de}} % % \maketitle @@ -227,7 +227,7 @@ and the derived files % The operations have the form of macros that take one or % two integers as parameter and return the integer result. % The macro name is a three letter operation name prefixed -% by the package name, e.g. \cs{intcalcAdd}{10}{43} returns +% by the package name, e.g. \cs{intcalcAdd}|{10}{43}| returns % |53|. % % The macros are fully expandable, exactly two expansion @@ -324,6 +324,19 @@ and the derived files % \end{cases} % \end{gather*} % +% \subsubsection{\op{Num}} +% +% \begin{declcs}{intcalcNum} \M{x} +% \end{declcs} +% Macro \cs{intcalcNum} converts its argument to a normalized integer +% number without unnecessary leading zeros or signs. +% The result matches the regular expression: +%\begin{quote} +%\begin{verbatim} +%0|-?[1-9][0-9]* +%\end{verbatim} +%\end{quote} +% % \subsubsection{\op{Inv}, \op{Abs}, \op{Sgn}} % % \begin{declcs}{intcalcInv} \M{x} @@ -449,18 +462,18 @@ and the derived files % \end{declcs} % Macro \cs{intcalcShl} implements shifting to the left that % means the number is multiplied by two. Overflow is possible. -% Negative values are not permitted. +% The sign is preserved. % \begin{gather*} -% \opShl(x) \Def x*2\qquad\text{for $x\geq0$} +% \opShl(x) \Def x*2 % \end{gather*} % % \begin{declcs}{intcalcShr} \M{x} % \end{declcs} % Macro \cs{intcalcShr} implements shifting to the right. % That is equivalent to an integer division by two. -% Negative values are not permitted. +% The sign is preserved. % \begin{gather*} -% \opShr(x) \Def \opInt(x/2)\qquad\text{for $x\geq0$} +% \opShr(x) \Def \opInt(x/2) % \end{gather*} % % \subsubsection{\op{Mul}, \op{Sqr}, \op{Fac}, \op{Pow}} @@ -525,6 +538,59 @@ and the derived files % 0 \leq \opMod(x,y) < y\qquad\text{for $y\geq0$} % \end{gather*} % +% \subsection{Interface for programmer} +% +% If the programmer can ensure some more properties about +% the arguments of the operations, then the following +% macros are a little more efficient. +% +% In general numbers must obey the following constraints: +% \begin{itemize} +% \item Plain number: digit tokens only, no command tokens. +% \item Non-negative. Signs are forbidden. +% \item Arguments and the result must fit in range |0..2147483647|. +% \item Delimited by exclamation mark. Curly braces +% around the number are not allowed and will +% break the code. +% \end{itemize} +% +% \begin{declcs}{IntCalcInc} \meta{number} |!| +% \end{declcs} +% Incrementation, range: |0..2147483646|. +% +% \begin{declcs}{IntCalcDec} \meta{number} |!| +% \end{declcs} +% Decrementation, range: |1..2147483647|. +% +% \begin{declcs}{IntCalcAdd} \meta{number A} |!| \meta{number B} |!| +% \end{declcs} +% Addition, $A\geq B$. +% +% \begin{declcs}{IntCalcSub} \meta{number A} |!| \meta{number B} |!| +% \end{declcs} +% Subtraction, $A\geq B$. +% +% \begin{declcs}{IntCalcShl} \meta{number} |!| +% \end{declcs} +% Left shift (multiplication with two), range: |0..1073741823|. +% +% \begin{declcs}{IntCalcShr} \meta{number} |!| +% \end{declcs} +% Right shift (integer division by two). +% +% \begin{declcs}{IntCalcMul} \meta{number A} |!| \meta{number B} |!| +% \end{declcs} +% Multiplication, $A\geq B$. +% +% \begin{declcs}{IntCalcDiv} \meta{number A} |!| \meta{number B} |!| +% \end{declcs} +% Division operation. +% +% \begin{declcs}{IntCalcMod} \meta{number A} |!| \meta{number B} |!| +% \end{declcs} +% Modulo operation. +% +% % \StopEventually{ % } % @@ -592,19 +658,19 @@ and the derived files \fi \expandafter\x\csname ver@intcalc.sty\endcsname \ProvidesPackage{intcalc}% - [2007/09/09 v1.0 Expandable integer calculations (HO)] + [2007/09/27 v1.1 Expandable integer calculations (HO)] % \end{macrocode} % % \subsection{Catcodes} % % \begin{macrocode} -\expandafter\edef\csname IntCalc@AtEnd\endcsname{% +\expandafter\edef\csname InCa@AtEnd\endcsname{% \catcode64 \the\catcode64\relax } \catcode64 11 % @ \def\TMP@EnsureCode#1#2{% - \edef\IntCalc@AtEnd{% - \IntCalc@AtEnd + \edef\InCa@AtEnd{% + \InCa@AtEnd \catcode#1 \the\catcode#1\relax }% \catcode#1 #2\relax @@ -622,26 +688,20 @@ and the derived files \TMP@EnsureCode{62}{12}% > \TMP@EnsureCode{63}{14}% ? (comment!) \begingroup\expandafter\expandafter\expandafter\endgroup -\expandafter\ifx\csname IntCalc@TestMode\endcsname\relax +\expandafter\ifx\csname InCa@TestMode\endcsname\relax \else \catcode63=9 % ? (ignore) \fi -? \let\IntCalc@@TestMode\IntCalc@TestMode +? \let\InCa@@TestMode\InCa@TestMode % \end{macrocode} % % \subsection{Macros independent of \eTeX} % -% \begin{macro}{\IntCalc@Space} -% \begin{macrocode} -\def\IntCalc@Space{ } -% \end{macrocode} -% \end{macro} -% % \subsubsection{\op{Abs}, \op{Sgn}} % -% \begin{macro}{\IntCalc@Abs} +% \begin{macro}{\InCa@Abs} % \begin{macrocode} -\def\IntCalc@Abs#1#2!{% +\def\InCa@Abs#1#2!{% \ifx#1-% #2% \else @@ -651,9 +711,9 @@ and the derived files % \end{macrocode} % \end{macro} % -% \begin{macro}{\IntCalc@Sgn} +% \begin{macro}{\InCa@Sgn} % \begin{macrocode} -\def\IntCalc@Sgn#1#2!{% +\def\InCa@Sgn#1#2!{% \ifx#1-% -1% \else @@ -669,9 +729,9 @@ and the derived files % % \subsubsection{\op{Min}, \op{Max}, \op{Cmp}} % -% \begin{macro}{\IntCalc@Min} +% \begin{macro}{\InCa@Min} % \begin{macrocode} -\def\IntCalc@Min#1!#2!{% +\def\InCa@Min#1!#2!{% \ifnum#1<#2 % #1% \else @@ -681,9 +741,9 @@ and the derived files % \end{macrocode} % \end{macro} % -% \begin{macro}{\IntCalc@Max} +% \begin{macro}{\InCa@Max} % \begin{macrocode} -\def\IntCalc@Max#1!#2!{% +\def\InCa@Max#1!#2!{% \ifnum#1>#2 % #1% \else @@ -693,9 +753,9 @@ and the derived files % \end{macrocode} % \end{macro} % -% \begin{macro}{\IntCalc@Cmp} +% \begin{macro}{\InCa@Cmp} % \begin{macrocode} -\def\IntCalc@Cmp#1!#2!{% +\def\InCa@Cmp#1!#2!{% \ifnum#1=#2 % 0% \else @@ -710,13 +770,13 @@ and the derived files % % \subsubsection{\op{Fac}} % -% \begin{macro}{\IntCalc@Fac} +% \begin{macro}{\InCa@Fac} % It does not make much sense to calculate the % faculty by an general algorithm. The allowed % range of arguments is too low because of the % limited integer domain. % \begin{macrocode} -\def\IntCalc@Fac#1!{% +\def\InCa@Fac#1!{% \ifcase#1 1% 0! \or 1% 1! \or 2% 2! @@ -750,12 +810,22 @@ and the derived files \else % \end{macrocode} % +% \subsubsection{\op{Num}} +% +% \begin{macro}{\intcalcNum} +% \begin{macrocode} + \def\intcalcNum#1{% + \the\numexpr#1\relax + }% +% \end{macrocode} +% \end{macro} +% % \subsubsection{\op{Inv}, \op{Abs}, \op{Sgn}} % % \begin{macro}{\intcalcInv} % \begin{macrocode} \def\intcalcInv#1{% - \number-\the\numexpr#1\relax\IntCalc@Space + \number-\intcalcNum{#1} % }% % \end{macrocode} % \end{macro} @@ -763,7 +833,7 @@ and the derived files % \begin{macro}{\intcalcAbs} % \begin{macrocode} \def\intcalcAbs#1{% - \number\expandafter\IntCalc@Abs\the\numexpr#1! % + \number\expandafter\InCa@Abs\the\numexpr#1! % }% % \end{macrocode} % \end{macro} @@ -771,7 +841,7 @@ and the derived files % \begin{macro}{\intcalcSgn} % \begin{macrocode} \def\intcalcSgn#1{% - \number\expandafter\IntCalc@Sgn\the\numexpr#1! % + \number\expandafter\InCa@Sgn\the\numexpr#1! % }% % \end{macrocode} % \end{macro} @@ -781,7 +851,7 @@ and the derived files % \begin{macro}{\intcalcMin} % \begin{macrocode} \def\intcalcMin#1#2{% - \number\expandafter\IntCalc@Min + \number\expandafter\InCa@Min \the\numexpr#1\expandafter!% \the\numexpr#2! % }% @@ -791,7 +861,7 @@ and the derived files % \begin{macro}{\intcalcMax} % \begin{macrocode} \def\intcalcMax#1#2{% - \number\expandafter\IntCalc@Max + \number\expandafter\InCa@Max \the\numexpr#1\expandafter!% \the\numexpr#2! % }% @@ -801,7 +871,7 @@ and the derived files % \begin{macro}{\intcalcCmp} % \begin{macrocode} \def\intcalcCmp#1#2{% - \number\expandafter\IntCalc@Cmp + \number\expandafter\InCa@Cmp \the\numexpr#1\expandafter!\the\numexpr#2! % }% % \end{macrocode} @@ -825,6 +895,21 @@ and the derived files % \end{macrocode} % \end{macro} % +% \begin{macro}{\IntCalcInc} +% \begin{macrocode} + \def\IntCalcInc#1!{% + \the\numexpr#1+1\relax + }% +% \end{macrocode} +% \end{macro} +% \begin{macro}{\IntCalcDec} +% \begin{macrocode} + \def\IntCalcDec#1!{% + \the\numexpr#1-1\relax + }% +% \end{macrocode} +% \end{macro} +% % \subsubsection{\op{Add}, \op{Sub}} % % \begin{macro}{\intcalcAdd} @@ -842,40 +927,60 @@ and the derived files }% % \end{macrocode} % \end{macro} + +% \begin{macro}{\IntCalcAdd} +% \begin{macrocode} + \def\IntCalcAdd#1!#2!{% + \the\numexpr#1+#2\relax + }% +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\IntCalcSub} +% \begin{macrocode} + \def\IntCalcSub#1!#2!{% + \the\numexpr#1-#2\relax + }% +% \end{macrocode} +% \end{macro} % % \subsubsection{\op{Shl}, \op{Shr}} % % \begin{macro}{\intcalcShl} % \begin{macrocode} \def\intcalcShl#1{% - \number\expandafter\IntCalc@Shl\the\numexpr#1! % + \the\numexpr(#1)*2\relax + }% +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\intcalcShr} +% \begin{macrocode} + \def\intcalcShr#1{% + \number\expandafter\InCa@Shr\the\numexpr#1! % }% % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@Shl} +% \begin{macro}{\IntCalcShl} % \begin{macrocode} - \def\IntCalc@Shl#1#2!{% - \ifx#1-% - 0\IntCalcError:ShlNegativeNumber% - \else - \the\numexpr#1#2*2\relax - \fi + \def\IntCalcShl#1!{% + \the\numexpr#1*2\relax }% % \end{macrocode} % \end{macro} % -% \begin{macro}{\intcalcShr} +% \begin{macro}{\IntCalcShr} % \begin{macrocode} - \def\intcalcShr#1{% - \number\expandafter\IntCalc@Shr\the\numexpr#1! % + \def\IntCalcShr#1!{% + \the\numexpr\ifodd#1 (#1-1)\else#1\fi/2\relax }% % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@Shr} +% \begin{macro}{\InCa@Shr} % \begin{macrocode} - \def\IntCalc@Shr#1#2!{% + \def\InCa@Shr#1#2!{% \ifx#1-% - 0\IntCalcError:ShrNegativeNumber% + -\InCa@Shr#2!% \else \ifodd#1#2 % \the\numexpr(#1#2-1)/2\relax @@ -896,17 +1001,24 @@ and the derived files }% % \end{macrocode} % \end{macro} +% \begin{macro}{\IntCalcMul} +% \begin{macrocode} + \def\IntCalcMul#1!#2!{% + \the\numexpr#1*#2\relax + }% +% \end{macrocode} +% \end{macro} % % \begin{macro}{\intcalcSqr} % \begin{macrocode} \def\intcalcSqr#1{% - \number\expandafter\IntCalc@Sqr\the\numexpr#1! % + \number\expandafter\InCa@Sqr\the\numexpr#1! % }% % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@Sqr} +% \begin{macro}{\InCa@Sqr} % \begin{macrocode} - \def\IntCalc@Sqr#1!{% + \def\InCa@Sqr#1!{% \the\numexpr#1*#1\relax }% % \end{macrocode} @@ -915,7 +1027,7 @@ and the derived files % \begin{macro}{\intcalcFac} % \begin{macrocode} \def\intcalcFac#1{% - \number\expandafter\IntCalc@Fac\the\numexpr#1! % + \number\expandafter\InCa@Fac\the\numexpr#1! % }% % \end{macrocode} % \end{macro} @@ -925,15 +1037,15 @@ and the derived files % \begin{macro}{\intcalcPow} % \begin{macrocode} \def\intcalcPow#1#2{% - \number\expandafter\IntCalc@Pow + \number\expandafter\InCa@Pow \the\numexpr#1\expandafter!% \the\numexpr#2! % }% % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@Pow} +% \begin{macro}{\InCa@Pow} % \begin{macrocode} - \def\IntCalc@Pow#1#2!#3#4!{% + \def\InCa@Pow#1#2!#3#4!{% \ifcase#3#4 % power = 0 1% \or % power = 1 @@ -958,7 +1070,7 @@ and the derived files \ifx#3-% power < 0 0% \else % power > 2 - \IntCalc@PowRec#1#2!#3#4!1!% + \InCa@PowRec#1#2!#3#4!1!% \fi \fi \fi @@ -966,7 +1078,7 @@ and the derived files }% % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@PowRec} +% \begin{macro}{\InCa@PowRec} %\begin{quote} %\begin{verbatim} %Pow(b, p) { @@ -974,7 +1086,7 @@ and the derived files %} %PowRec(b, p, r) { % if p == 1 then -% return r +% return r*b % else % ifodd p then % return PowRec(b*b, (p-1)/2, r*b) % p div 2 = (p-1)/2 @@ -986,17 +1098,17 @@ and the derived files %\end{verbatim} %\end{quote} % \begin{macrocode} - \def\IntCalc@PowRec#1!#2!#3!{% + \def\InCa@PowRec#1!#2!#3!{% \ifnum#2=\@ne \the\numexpr#1*#3\relax \else \ifodd#2 % - \expandafter\IntCalc@PowRec + \expandafter\InCa@PowRec \the\numexpr#1*#1\expandafter!% \the\numexpr(#2-1)/2\expandafter!% \the\numexpr#1*#3\expandafter\expandafter\expandafter!% \else - \expandafter\IntCalc@PowRec + \expandafter\InCa@PowRec \the\numexpr#1*#1\expandafter!% \the\numexpr(#2-1)/2\expandafter!% \number#3\expandafter\expandafter\expandafter!% @@ -1025,22 +1137,22 @@ and the derived files % \begin{macro}{\intcalcDiv} % \begin{macrocode} \def\intcalcDiv#1#2{% - \number\expandafter\IntCalc@Div + \number\expandafter\InCa@Div \the\numexpr#1\expandafter!% \the\numexpr#2! % }% % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@Div} +% \begin{macro}{\InCa@Div} % \begin{macrocode} - \def\IntCalc@Div#1!#2!{% + \def\InCa@Div#1!#2!{% \ifcase#2 % 0\IntCalcError:DivisionByZero% \else \ifcase#1 % 0% \else - \expandafter\IntCalc@@Div + \expandafter\InCa@@Div \romannumeral 0% \ifnum#1<\z@ \expandafter-\number-#1% @@ -1060,9 +1172,29 @@ and the derived files }% % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@@Div} +% \begin{macro}{\IntCalcDiv} % \begin{macrocode} - \def\IntCalc@@Div#1#2!#3#4!{% + \def\InCa@Temp#1{% + \def\IntCalcDiv##1!##2!{% + \number + \ifcase##2 % + 0\IntCalcError:DivisionByZero% + \else + \ifcase##1 % + 0% + \else + \the\numexpr(##1-(##2-1)/2)/##2\relax + \fi + \fi + #1% + }% + }% + \InCa@Temp{ }% +% \end{macrocode} +% \end{macro} +% \begin{macro}{\InCa@@Div} +% \begin{macrocode} + \def\InCa@@Div#1#2!#3#4!{% #1#3% \the\numexpr(#2-(#4-1)/2)/#4\relax }% @@ -1072,22 +1204,22 @@ and the derived files % \begin{macro}{\intcalcMod} % \begin{macrocode} \def\intcalcMod#1#2{% - \number\expandafter\IntCalc@Mod + \number\expandafter\InCa@Mod \the\numexpr#1\expandafter!% \the\numexpr#2! % }% % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@Mod} +% \begin{macro}{\InCa@Mod} % \begin{macrocode} - \def\IntCalc@Mod#1!#2!{% + \def\InCa@Mod#1!#2!{% \ifcase#2 % 0\IntCalcError:DivisionByZero% \else \ifcase#1 % 0% \else - \expandafter\IntCalc@@Mod + \expandafter\InCa@@Mod \romannumeral 0% \ifnum#1<\z@ \expandafter-\number-#1% @@ -1107,31 +1239,51 @@ and the derived files }% % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@@Mod} +% \begin{macro}{\IntCalcMod} % \begin{macrocode} - \def\IntCalc@@Mod#1#2!#3#4!{% + \def\InCa@Temp#1{% + \def\IntCalcMod##1!##2!{% + \number + \ifcase##2 % + 0\IntCalcError:DivisionByZero% + \else + \ifcase##1 % + 0% + \else + \the\numexpr##1-(##1-(##2-1)/2)/##2*##2\relax + \fi + \fi + #1% + }% + }% + \InCa@Temp{ }% +% \end{macrocode} +% \end{macro} +% \begin{macro}{\InCa@@Mod} +% \begin{macrocode} + \def\InCa@@Mod#1#2!#3#4!{% \if#3+% \if#1+% - \the\numexpr#2-\IntCalc@@Div+#2!+#4!*#4\relax + \the\numexpr#2-\InCa@@Div+#2!+#4!*#4\relax \else - \expandafter\IntCalc@ModX - \the\numexpr-#2+\IntCalc@@Div+#2!+#4!*#4!#4!% + \expandafter\InCa@ModX + \the\numexpr-#2+\InCa@@Div+#2!+#4!*#4!#4!% \fi \else -% \if#1+% - \expandafter\IntCalc@ModX - \the\numexpr-#2+\IntCalc@@Div+#2!+#4!*#4!#4!% + \expandafter\InCa@ModX + \the\numexpr-#2+\InCa@@Div+#2!+#4!*#4!#4!% \else - \the\numexpr#2-\IntCalc@@Div+#2!+#4!*#4\relax + \the\numexpr#2-\InCa@@Div+#2!+#4!*#4\relax \fi \fi }% % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@ModX} +% \begin{macro}{\InCa@ModX} % \begin{macrocode} - \def\IntCalc@ModX#1!#2!{% + \def\InCa@ModX#1!#2!{% \ifcase#1 % 0% \else @@ -1142,32 +1294,42 @@ and the derived files % \end{macro} % % \begin{macrocode} - \IntCalc@AtEnd + \InCa@AtEnd \expandafter\endinput \fi % \end{macrocode} % % \subsection{Implementation without \eTeX} % +% \subsubsection{\op{Num}} +% +% \begin{macro}{\intcalcNum} +% \begin{macrocode} +\def\intcalcNum#1{% + \number\expandafter\InCa@FirstOfOne\number#1! % +} +% \end{macrocode} +% \end{macro} +% % \subsubsection{\op{Inv}, \op{Abs}, \op{Sgn}} % % \begin{macro}{\intcalcInv} % \begin{macrocode} \def\intcalcInv#1{% - \number\expandafter\IntCalc@Inv\number-#1! % + \number\expandafter\InCa@FirstOfOne\number-#1! % } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@Inv} +% \begin{macro}{\InCa@FirstOfOne} % \begin{macrocode} -\def\IntCalc@Inv#1!{#1} +\def\InCa@FirstOfOne#1!{#1} % \end{macrocode} % \end{macro} % % \begin{macro}{\intcalcAbs} % \begin{macrocode} \def\intcalcAbs#1{% - \number\expandafter\IntCalc@Abs\number#1! % + \number\expandafter\InCa@Abs\number#1! % } % \end{macrocode} % \end{macro} @@ -1175,7 +1337,7 @@ and the derived files % \begin{macro}{\intcalcSgn} % \begin{macrocode} \def\intcalcSgn#1{% - \number\expandafter\IntCalc@Sgn\number#1! % + \number\expandafter\InCa@Sgn\number#1! % } % \end{macrocode} % \end{macro} @@ -1185,7 +1347,7 @@ and the derived files % \begin{macro}{\intcalcMin} % \begin{macrocode} \def\intcalcMin#1#2{% - \number\expandafter\IntCalc@Min + \number\expandafter\InCa@Min \number\number#1\expandafter!\number#2! % } % \end{macrocode} @@ -1194,7 +1356,7 @@ and the derived files % \begin{macro}{\intcalcMax} % \begin{macrocode} \def\intcalcMax#1#2{% - \number\expandafter\IntCalc@Max + \number\expandafter\InCa@Max \number\number#1\expandafter!\number#2! % } % \end{macrocode} @@ -1203,7 +1365,7 @@ and the derived files % \begin{macro}{\intcalcCmp} % \begin{macrocode} \def\intcalcCmp#1#2{% - \number\expandafter\IntCalc@Cmp + \number\expandafter\InCa@Cmp \number\number#1\expandafter!\number#2! % }% % \end{macrocode} @@ -1214,20 +1376,20 @@ and the derived files % \begin{macro}{\intcalcInc} % \begin{macrocode} \def\intcalcInc#1{% - \number\expandafter\IntCalc@IncSwitch\number#1! % + \number\expandafter\InCa@IncSwitch\number#1! % } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@IncSwitch} +% \begin{macro}{\InCa@IncSwitch} % \begin{macrocode} -\def\IntCalc@IncSwitch#1#2!{% +\def\InCa@IncSwitch#1#2!{% \ifx#1-% -% - \csname IntCalc@Empty% - \IntCalc@Dec#2!% + \csname InCa@Empty% + \InCa@Dec#2!% \else - \csname IntCalc@Empty% - \IntCalc@Inc#1#2!% + \csname InCa@Empty% + \InCa@Inc#1#2!% \fi } % \end{macrocode} @@ -1235,45 +1397,60 @@ and the derived files % \begin{macro}{\intcalcDec} % \begin{macrocode} \def\intcalcDec#1{% - \number\expandafter\IntCalc@DecSwitch\number#1! % + \number\expandafter\InCa@DecSwitch\number#1! % } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@DecSwitch} +% \begin{macro}{\InCa@DecSwitch} % \begin{macrocode} -\def\IntCalc@DecSwitch#1#2!{% +\def\InCa@DecSwitch#1#2!{% \ifx#1-% -% - \csname IntCalc@Empty% - \expandafter\IntCalc@Inc#2!% + \csname InCa@Empty% + \expandafter\InCa@Inc#2!% \else \ifx#10% -1% \else - \csname IntCalc@Empty% - \IntCalc@Dec#1#2!% + \csname InCa@Empty% + \InCa@Dec#1#2!% \fi \fi } % \end{macrocode} % \end{macro} % -% \begin{macro}{\IntCalc@Inc} +% \begin{macro}{\IntCalcInc} % \begin{macrocode} -\def\IntCalc@Inc#1#2{% +\def\IntCalcInc#1!{% + \number\csname InCa@Empty\InCa@Inc#1! % +} +% \end{macrocode} +% \end{macro} +% \begin{macro}{\IntCalcDec} +% \begin{macrocode} +\def\IntCalcDec#1!{% + \number\csname InCa@Empty\InCa@Dec#1! % +} +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\InCa@Inc} +% \begin{macrocode} +\def\InCa@Inc#1#2{% \ifx#2!% - \csname IntCalc@IncDigit#1\endcsname1% + \csname InCa@IncDigit#1\endcsname1% \else - \csname IntCalc@IncDigit#1% - \expandafter\IntCalc@Inc\expandafter#2% + \csname InCa@IncDigit#1% + \expandafter\InCa@Inc\expandafter#2% \fi } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@IncDigit[0-8]} +% \begin{macro}{\InCa@IncDigit[0-8]} % \begin{macrocode} -\def\IntCalc@Temp#1#2{% - \expandafter\def\csname IntCalc@IncDigit#1\endcsname##1{% +\def\InCa@Temp#1#2{% + \expandafter\def\csname InCa@IncDigit#1\endcsname##1{% \endcsname 0% \ifcase##1 % @@ -1283,20 +1460,20 @@ and the derived files \fi }% } -\IntCalc@Temp 01 -\IntCalc@Temp 12 -\IntCalc@Temp 23 -\IntCalc@Temp 34 -\IntCalc@Temp 45 -\IntCalc@Temp 56 -\IntCalc@Temp 67 -\IntCalc@Temp 78 -\IntCalc@Temp 89 +\InCa@Temp 01 +\InCa@Temp 12 +\InCa@Temp 23 +\InCa@Temp 34 +\InCa@Temp 45 +\InCa@Temp 56 +\InCa@Temp 67 +\InCa@Temp 78 +\InCa@Temp 89 % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@IncDigit9} +% \begin{macro}{\InCa@IncDigit9} % \begin{macrocode} -\expandafter\def\csname IntCalc@IncDigit9\endcsname#1{% +\expandafter\def\csname InCa@IncDigit9\endcsname#1{% \expandafter\endcsname \ifcase#1 % 09% @@ -1307,22 +1484,22 @@ and the derived files % \end{macrocode} % \end{macro} % -% \begin{macro}{\IntCalc@Dec} +% \begin{macro}{\InCa@Dec} % \begin{macrocode} -\def\IntCalc@Dec#1#2{% +\def\InCa@Dec#1#2{% \ifx#2!% - \csname IntCalc@DecDigit#1\endcsname1% + \csname InCa@DecDigit#1\endcsname1% \else - \csname IntCalc@DecDigit#1% - \expandafter\IntCalc@Dec\expandafter#2% + \csname InCa@DecDigit#1% + \expandafter\InCa@Dec\expandafter#2% \fi } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@DecDigit[1-9]} +% \begin{macro}{\InCa@DecDigit[1-9]} % \begin{macrocode} -\def\IntCalc@Temp#1#2{% - \expandafter\def\csname IntCalc@DecDigit#1\endcsname##1{% +\def\InCa@Temp#1#2{% + \expandafter\def\csname InCa@DecDigit#1\endcsname##1{% \endcsname 0% \ifcase##1 % @@ -1332,20 +1509,20 @@ and the derived files \fi }% } -\IntCalc@Temp 98 -\IntCalc@Temp 87 -\IntCalc@Temp 76 -\IntCalc@Temp 65 -\IntCalc@Temp 54 -\IntCalc@Temp 43 -\IntCalc@Temp 32 -\IntCalc@Temp 21 -\IntCalc@Temp 10 +\InCa@Temp 98 +\InCa@Temp 87 +\InCa@Temp 76 +\InCa@Temp 65 +\InCa@Temp 54 +\InCa@Temp 43 +\InCa@Temp 32 +\InCa@Temp 21 +\InCa@Temp 10 % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@DecDigit0} +% \begin{macro}{\InCa@DecDigit0} % \begin{macrocode} -\expandafter\def\csname IntCalc@DecDigit0\endcsname#1{% +\expandafter\def\csname InCa@DecDigit0\endcsname#1{% \expandafter\endcsname \ifcase#1 % 00% @@ -1362,10 +1539,9 @@ and the derived files % \begin{macrocode} \def\intcalcAdd#1#2{% \number - \expandafter\IntCalc@AddSwitch + \expandafter\InCa@AddSwitch \number\number#1\expandafter!% - \number#2!% - \IntCalc@Space + \number#2! % } % \end{macrocode} % \end{macro} @@ -1373,18 +1549,17 @@ and the derived files % \begin{macrocode} \def\intcalcSub#1#2{% \number - \expandafter\IntCalc@AddSwitch + \expandafter\InCa@AddSwitch \number\number#1\expandafter!% - \number-\number#2!% - \IntCalc@Space + \number-\number#2! % } % \end{macrocode} % \end{macro} % -% \begin{macro}{\IntCalc@AddSwitch} -% Decision table for \cs{IntCalc@AddSwitch}. -% By using less than zero operations, the sign -% of negative numbers can be removed by a simple \cs{IntCalc@Gobble} +% \begin{macro}{\InCa@AddSwitch} +% Decision table for \cs{InCa@AddSwitch}. +% The sign of negative numbers can be removed +% by a simple \cs{@gobble} % instead of the more expensive |\number-|. % \begin{quote} % \begin{tabular}[t]{@{}|l|l|l|l|l|@{}} @@ -1408,166 +1583,189 @@ and the derived files % \end{tabular} % \end{quote} % \begin{macrocode} -\def\IntCalc@AddSwitch#1!#2!{% +\def\InCa@AddSwitch#1!#2!{% \ifnum#1<\z@ \ifnum#2<\z@ -% \ifnum#1<#2 % - \expandafter\IntCalc@Add\number-#1\expandafter!% - \IntCalc@Gobble#2!% + \expandafter\InCa@Add\number-#1\expandafter!% + \@gobble#2!% \else - \expandafter\IntCalc@Add\number-#2\expandafter!% - \IntCalc@Gobble#1!% + \expandafter\InCa@Add\number-#2\expandafter!% + \@gobble#1!% \fi \else \ifnum-#1>#2 % -% - \expandafter\IntCalc@Sub\IntCalc@Gobble#1!#2!% + \expandafter\InCa@Sub\@gobble#1!#2!% \else - \expandafter\IntCalc@Sub\number#2\expandafter!% - \IntCalc@Gobble#1!% + \expandafter\InCa@Sub\number#2\expandafter!% + \@gobble#1!% \fi \fi \else \ifnum#2<\z@ \ifnum#1>-#2 % - \expandafter\IntCalc@Sub\number#1\expandafter!% - \IntCalc@Gobble#2!% + \expandafter\InCa@Sub\number#1\expandafter!% + \@gobble#2!% \else -% - \expandafter\IntCalc@Sub\IntCalc@Gobble#2!#1!% + \expandafter\InCa@Sub\@gobble#2!#1!% \fi \else \ifnum#1>#2 % - \IntCalc@Add#1!#2!% + \InCa@Add#1!#2!% \else - \IntCalc@Add#2!#1!% + \InCa@Add#2!#1!% \fi \fi \fi } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@Add} +% \begin{macro}{\IntCalcAdd} +% \begin{macrocode} +\def\IntCalcAdd#1!#2!{% + \number\InCa@Add#1!#2! % +} +% \end{macrocode} +% \end{macro} +% \begin{macro}{\IntCalcSub} +% \begin{macrocode} +\def\IntCalcSub#1!#2!{% + \number\InCa@Sub#1!#2! % +} +% \end{macrocode} +% \end{macro} +% \begin{macro}{\InCa@Space} % \begin{macrocode} -\def\IntCalc@Add#1!#2!{% +\begingroup + \def\x#1{\endgroup + \let\InCa@Space= #1% + }% +\x{ } +% \end{macrocode} +% \end{macro} +% \begin{macro}{\InCa@Add} +% \begin{macrocode} +\def\InCa@Add#1!#2!{% \ifcase#2 % #1% \else - \IntCalc@@Add#1!#2!000000000\IntCalc@Space + \InCa@@Add#1!#2!000000000\InCa@Space \fi } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@Sub} +% \begin{macro}{\InCa@Sub} % \begin{macrocode} -\def\IntCalc@Sub#1!#2!{% +\def\InCa@Sub#1!#2!{% \ifnum#1=#2 % 0% \else - \IntCalc@@Sub#1!#2!000000000\IntCalc@Space + \InCa@@Sub#1!#2!000000000\InCa@Space \fi } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@@Add} +% \begin{macro}{\InCa@@Add} % \begin{macrocode} -\def\IntCalc@@Add#1!#2#3!{% - \ifx\IntCalc@Empty#3\IntCalc@Empty +\def\InCa@@Add#1!#2#3!{% + \ifx\InCa@Empty#3\InCa@Empty \@ReturnAfterElseFi{% - \IntCalc@@@Add!!#1!#2% + \InCa@@@Add!!#1!#2% }% \else \@ReturnAfterFi{% - \IntCalc@@Add#1!#3!#2% + \InCa@@Add#1!#3!#2% }% \fi } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@@Sub} +% \begin{macro}{\InCa@@Sub} % \begin{macrocode} -\def\IntCalc@@Sub#1!#2#3!{% - \ifx\IntCalc@Empty#3\IntCalc@Empty +\def\InCa@@Sub#1!#2#3!{% + \ifx\InCa@Empty#3\InCa@Empty \@ReturnAfterElseFi{% - \IntCalc@@@Sub!!#1!#2% + \InCa@@@Sub!!#1!#2% }% \else \@ReturnAfterFi{% - \IntCalc@@Sub#1!#3!#2% + \InCa@@Sub#1!#3!#2% }% \fi } % \end{macrocode} % \end{macro} % -% \begin{macro}{\IntCalc@@@Add} +% \begin{macro}{\InCa@@@Add} % \begin{macrocode} -\def\IntCalc@@@Add#1!#2!#3#4!#5{% - \ifx\IntCalc@Empty#4\IntCalc@Empty - \csname IntCalc@Empty% +\def\InCa@@@Add#1!#2!#3#4!#5{% + \ifx\InCa@Empty#4\InCa@Empty + \csname InCa@Empty% \@ReturnAfterElseFi{% - \IntCalc@ProcessAdd#1#3!#5#2% + \InCa@ProcessAdd#1#3!#5#2% }% \else \@ReturnAfterFi{% - \IntCalc@@@Add#1#3!#5#2!#4!% + \InCa@@@Add#1#3!#5#2!#4!% }% \fi } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@@@Sub} +% \begin{macro}{\InCa@@@Sub} % \begin{macrocode} -\def\IntCalc@@@Sub#1!#2!#3#4!#5{% - \ifx\IntCalc@Empty#4\IntCalc@Empty - \csname IntCalc@Gobble% +\def\InCa@@@Sub#1!#2!#3#4!#5{% + \ifx\InCa@Empty#4\InCa@Empty + \csname @gobble% \@ReturnAfterElseFi{% - \IntCalc@ProcessSub#1#3!#5#2% + \InCa@ProcessSub#1#3!#5#2% }% \else \@ReturnAfterFi{% - \IntCalc@@@Sub#1#3!#5#2!#4!% + \InCa@@@Sub#1#3!#5#2!#4!% }% \fi } % \end{macrocode} % \end{macro} % -% \begin{macro}{\IntCalc@ProcessAdd} +% \begin{macro}{\InCa@ProcessAdd} % \begin{macrocode} -\def\IntCalc@ProcessAdd#1#2!#3#4{% - \ifx\IntCalc@Empty#2\IntCalc@Empty - \csname IntCalc@AddDigit#1\endcsname#3% +\def\InCa@ProcessAdd#1#2!#3#4{% + \ifx\InCa@Empty#2\InCa@Empty + \csname InCa@AddDigit#1\endcsname#3% \romannumeral0#4% \else - \csname IntCalc@AddDigit#1\csname IntCalc@DigitCarry#3% + \csname InCa@AddDigit#1\csname InCa@DigitCarry#3% \@ReturnAfterFi{% - \IntCalc@ProcessAdd#2!#4% + \InCa@ProcessAdd#2!#4% }% \fi } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@ProcessSub} +% \begin{macro}{\InCa@ProcessSub} % \begin{macrocode} -\def\IntCalc@ProcessSub#1#2!#3#4{% - \ifx\IntCalc@Empty#2\IntCalc@Empty - \csname IntCalc@SubDigit#1\endcsname#3% +\def\InCa@ProcessSub#1#2!#3#4{% + \ifx\InCa@Empty#2\InCa@Empty + \csname InCa@SubDigit#1\endcsname#3% \romannumeral0#4% \else - \csname IntCalc@SubDigit#1\csname IntCalc@DigitCarry#3% + \csname InCa@SubDigit#1\csname InCa@DigitCarry#3% \@ReturnAfterFi{% - \IntCalc@ProcessSub#2!#4% + \InCa@ProcessSub#2!#4% }% \fi } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@DigitCarry[0-9]} +% \begin{macro}{\InCa@DigitCarry[0-9]} % \begin{macrocode} -\def\IntCalc@Temp#1#2{% - \expandafter\def\csname IntCalc@DigitCarry#1\endcsname##1{% +\def\InCa@Temp#1#2{% + \expandafter\def\csname InCa@DigitCarry#1\endcsname##1{% \ifcase##1 % \endcsname#1% \else @@ -1575,22 +1773,22 @@ and the derived files \fi }% } -\IntCalc@Temp 01 -\IntCalc@Temp 12 -\IntCalc@Temp 23 -\IntCalc@Temp 34 -\IntCalc@Temp 45 -\IntCalc@Temp 56 -\IntCalc@Temp 67 -\IntCalc@Temp 78 -\IntCalc@Temp 89 -\IntCalc@Temp 9{{10}} +\InCa@Temp 01 +\InCa@Temp 12 +\InCa@Temp 23 +\InCa@Temp 34 +\InCa@Temp 45 +\InCa@Temp 56 +\InCa@Temp 67 +\InCa@Temp 78 +\InCa@Temp 89 +\InCa@Temp 9{{10}} % \end{macrocode} % \end{macro} % -% \begin{macro}{\IntCalc@AddDigit0} +% \begin{macro}{\InCa@AddDigit0} % \begin{macrocode} -\expandafter\def\csname IntCalc@AddDigit0\endcsname#1{% +\expandafter\def\csname InCa@AddDigit0\endcsname#1{% \ifnum#1>9 % \endcsname10% \else @@ -1599,10 +1797,10 @@ and the derived files } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@AddDigit[1-9]} +% \begin{macro}{\InCa@AddDigit[1-9]} % \begin{macrocode} -\def\IntCalc@Temp#1#2#3{% - \expandafter\def\csname IntCalc@AddDigit#1\endcsname##1{% +\def\InCa@Temp#1#2#3{% + \expandafter\def\csname InCa@AddDigit#1\endcsname##1{% \ifnum##1>#2 % \endcsname 1% \else @@ -1614,7 +1812,7 @@ and the derived files \fi }% } -\IntCalc@Temp 18{% +\InCa@Temp 18{% \or 2% 1 \or 3% 2 \or 4% 3 @@ -1625,7 +1823,7 @@ and the derived files \or 9% 8 \or 0% 9 }% -\IntCalc@Temp 27{% +\InCa@Temp 27{% \or 3% 1 \or 4% 2 \or 5% 3 @@ -1636,7 +1834,7 @@ and the derived files \or 0% 8 \or 1% 9 }% -\IntCalc@Temp 36{% +\InCa@Temp 36{% \or 4% 1 \or 5% 2 \or 6% 3 @@ -1647,7 +1845,7 @@ and the derived files \or 1% 8 \or 2% 9 }% -\IntCalc@Temp 45{% +\InCa@Temp 45{% \or 5% 1 \or 6% 2 \or 7% 3 @@ -1658,7 +1856,7 @@ and the derived files \or 2% 8 \or 3% 9 }% -\IntCalc@Temp 54{% +\InCa@Temp 54{% \or 6% 1 \or 7% 2 \or 8% 3 @@ -1669,7 +1867,7 @@ and the derived files \or 3% 8 \or 4% 9 }% -\IntCalc@Temp 63{% +\InCa@Temp 63{% \or 7% 1 \or 8% 2 \or 9% 3 @@ -1680,7 +1878,7 @@ and the derived files \or 4% 8 \or 5% 9 }% -\IntCalc@Temp 72{% +\InCa@Temp 72{% \or 8% 1 \or 9% 2 \or 0% 3 @@ -1691,7 +1889,7 @@ and the derived files \or 5% 8 \or 6% 9 }% -\IntCalc@Temp 81{% +\InCa@Temp 81{% \or 9% 1 \or 0% 2 \or 1% 3 @@ -1702,7 +1900,7 @@ and the derived files \or 6% 8 \or 7% 9 }% -\IntCalc@Temp 90{% +\InCa@Temp 90{% \or 0% 1 \or 1% 2 \or 2% 3 @@ -1716,10 +1914,10 @@ and the derived files % \end{macrocode} % \end{macro} % -% \begin{macro}{\IntCalc@SubDigit[0-9]} +% \begin{macro}{\InCa@SubDigit[0-9]} % \begin{macrocode} -\def\IntCalc@Temp#1#2{% - \expandafter\def\csname IntCalc@SubDigit#1\endcsname##1{% +\def\InCa@Temp#1#2{% + \expandafter\def\csname InCa@SubDigit#1\endcsname##1{% \ifnum##1>#1 % \endcsname 1% \else @@ -1731,7 +1929,7 @@ and the derived files \fi }% } -\IntCalc@Temp 0{% +\InCa@Temp 0{% \or 9% 1 \or 8% 2 \or 7% 3 @@ -1742,7 +1940,7 @@ and the derived files \or 2% 8 \or 1% 9 } -\IntCalc@Temp 1{% +\InCa@Temp 1{% \or 0% 1 \or 9% 2 \or 8% 3 @@ -1753,7 +1951,7 @@ and the derived files \or 3% 8 \or 2% 9 } -\IntCalc@Temp 2{% +\InCa@Temp 2{% \or 1% 1 \or 0% 2 \or 9% 3 @@ -1764,7 +1962,7 @@ and the derived files \or 4% 8 \or 3% 9 } -\IntCalc@Temp 3{% +\InCa@Temp 3{% \or 2% 1 \or 1% 2 \or 0% 3 @@ -1775,7 +1973,7 @@ and the derived files \or 5% 8 \or 4% 9 } -\IntCalc@Temp 4{% +\InCa@Temp 4{% \or 3% 1 \or 2% 2 \or 1% 3 @@ -1786,7 +1984,7 @@ and the derived files \or 6% 8 \or 5% 9 } -\IntCalc@Temp 5{% +\InCa@Temp 5{% \or 4% 1 \or 3% 2 \or 2% 3 @@ -1797,7 +1995,7 @@ and the derived files \or 7% 8 \or 6% 9 } -\IntCalc@Temp 6{% +\InCa@Temp 6{% \or 5% 1 \or 4% 2 \or 3% 3 @@ -1808,7 +2006,7 @@ and the derived files \or 8% 8 \or 7% 9 } -\IntCalc@Temp 7{% +\InCa@Temp 7{% \or 6% 1 \or 5% 2 \or 4% 3 @@ -1819,7 +2017,7 @@ and the derived files \or 9% 8 \or 8% 9 } -\IntCalc@Temp 8{% +\InCa@Temp 8{% \or 7% 1 \or 6% 2 \or 5% 3 @@ -1830,7 +2028,7 @@ and the derived files \or 0% 8 \or 9% 9 } -\IntCalc@Temp 9{% +\InCa@Temp 9{% \or 8% 1 \or 7% 2 \or 6% 3 @@ -1849,47 +2047,57 @@ and the derived files % \begin{macro}{\intcalcShl} % \begin{macrocode} \def\intcalcShl#1{% - \number\expandafter\IntCalc@ShlSwitch\number#1! % + \number\expandafter\InCa@ShlSwitch\number#1! % } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@ShlSwitch} +% \begin{macro}{\InCa@ShlSwitch} % \begin{macrocode} -\def\IntCalc@ShlSwitch#1!{% - \ifnum#1<\z@ - 0\IntCalcError:ShlNegativeNumber% +\def\InCa@ShlSwitch#1#2!{% + \ifx#1-% + -\csname InCa@Empty% + \InCa@Shl#2!% \else - \csname IntCalc@Empty% - \IntCalc@Shl#1!% + \csname InCa@Empty% + \InCa@Shl#1#2!% \fi } % \end{macrocode} % \end{macro} +% \begin{macro}{\IntCalcShl} +% \begin{macrocode} +\def\IntCalcShl#1!{% + \number + \csname InCa@Empty% + \InCa@Shl#1! % +} +% \end{macrocode} +% \end{macro} % \begin{macro}{\IntCal@ShlDigit} % \begin{macrocode} -\def\IntCalc@Shl#1#2{% +\def\InCa@Shl#1#2{% \ifx#2!% - \csname IntCalc@ShlDigit#1\endcsname0% + \csname InCa@ShlDigit#1\endcsname0% \else - \csname IntCalc@ShlDigit#1% + \csname InCa@ShlDigit#1% \@ReturnAfterFi{% - \IntCalc@Shl#2% + \InCa@Shl#2% }% \fi } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@ShlDigit0} +% \begin{macro}{\InCa@ShlDigit0} % \begin{macrocode} -\expandafter\def\csname IntCalc@ShlDigit0\endcsname{% +\expandafter\def\csname InCa@ShlDigit0\endcsname{% \endcsname0% } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@ShlDigit[1-9]} +% \begin{macro}{\InCa@ShlDigit[1-9]} % \begin{macrocode} -\def\IntCalc@Temp#1#2#3#4#5{% - \expandafter\def\csname IntCalc@ShlDigit#1\endcsname##1{% +\def\InCa@Temp#1#2#3#4#5{% + \expandafter\def\csname InCa@ShlDigit#1\endcsname##1{% \expandafter\endcsname \ifcase##1 % #2#3% @@ -1898,49 +2106,56 @@ and the derived files \fi }% } -\IntCalc@Temp 10203 -\IntCalc@Temp 20405 -\IntCalc@Temp 30607 -\IntCalc@Temp 40809 -\IntCalc@Temp 51011 -\IntCalc@Temp 61213 -\IntCalc@Temp 71415 -\IntCalc@Temp 81617 -\IntCalc@Temp 91819 +\InCa@Temp 10203 +\InCa@Temp 20405 +\InCa@Temp 30607 +\InCa@Temp 40809 +\InCa@Temp 51011 +\InCa@Temp 61213 +\InCa@Temp 71415 +\InCa@Temp 81617 +\InCa@Temp 91819 % \end{macrocode} % \end{macro} % % \begin{macro}{\intcalcShr} % \begin{macrocode} \def\intcalcShr#1{% - \number\expandafter\IntCalc@ShrSwitch\number#1! % + \number\expandafter\InCa@ShrSwitch\number#1! % } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@ShrSwitch} +% \begin{macro}{\InCa@ShrSwitch} % \begin{macrocode} -\def\IntCalc@ShrSwitch#1!{% - \ifnum#1<\z@ - 0\IntCalcError:ShrNegativeNumber% +\def\InCa@ShrSwitch#1#2!{% + \ifx#1-% + -\InCa@Shr#2!% \else - \IntCalc@Shr#1!% + \InCa@Shr#1#2!% \fi } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@Shr} +% \begin{macro}{\IntCalcShr} +% \begin{macrocode} +\def\IntCalcShr#1!{% + \number\InCa@Shr#1! % +} +% \end{macrocode} +% \end{macro} +% \begin{macro}{\InCa@Shr} % \begin{macrocode} -\def\IntCalc@Shr#1#2{% - \IntCalc@ShrDigit#1!% +\def\InCa@Shr#1#2{% + \InCa@ShrDigit#1!% \ifx#2!% \else \@ReturnAfterFi{% \ifodd#1 % \@ReturnAfterElseFi{% - \IntCalc@Shr{1#2}% + \InCa@Shr{1#2}% }% \else - \expandafter\IntCalc@Shr\expandafter#2% + \expandafter\InCa@Shr\expandafter#2% \fi }% \fi @@ -1948,7 +2163,7 @@ and the derived files % \end{macrocode} % \end{macro} % \begin{macrocode} -\def\IntCalc@ShrDigit#1!{% +\def\InCa@ShrDigit#1!{% \ifcase#1 0% 0 \or 0% 1 \or 1% 2 @@ -1973,83 +2188,86 @@ and the derived files } % \end{macrocode} % -% \subsubsection{\cs{IntCalc@Tim}} +% \subsubsection{\cs{InCa@Tim}} % -% \begin{macro}{\IntCalc@Tim} -% Macro \cs{IntCalc@Tim} implements +% \begin{macro}{\InCa@Tim} +% Macro \cs{InCa@Tim} implements % ``Number \emph{tim}es digit''. % \begin{macrocode} -\def\IntCalc@Tim#1#2{% - \number - \ifcase#2 % 0 - 0% - \or % 1 - #1% - \else % 2-9 - \csname IntCalc@Empty% - \IntCalc@ProcessTim#2#1!% - \fi - \IntCalc@Space +\def\InCa@Temp#1{% + \def\InCa@Tim##1##2{% + \number + \ifcase##2 % 0 + 0% + \or % 1 + ##1% + \else % 2-9 + \csname InCa@Empty% + \InCa@ProcessTim##2##1!% + \fi + #1% + }% } +\InCa@Temp{ } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@ProcessTim} +% \begin{macro}{\InCa@ProcessTim} % \begin{macrocode} -\def\IntCalc@ProcessTim#1#2#3{% +\def\InCa@ProcessTim#1#2#3{% \ifx#3!% - \csname IntCalc@TimDigit#2\endcsname#10% + \csname InCa@TimDigit#2\endcsname#10% \else - \csname IntCalc@TimDigit#2\csname IntCalc@Param#1% + \csname InCa@TimDigit#2\csname InCa@Param#1% \@ReturnAfterFi{% - \IntCalc@ProcessTim#1#3% + \InCa@ProcessTim#1#3% }% \fi } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@Param[0-9]} +% \begin{macro}{\InCa@Param[0-9]} % \begin{macrocode} -\def\IntCalc@Temp#1{% - \expandafter\def\csname IntCalc@Param#1\endcsname{% +\def\InCa@Temp#1{% + \expandafter\def\csname InCa@Param#1\endcsname{% \endcsname#1% }% } -\IntCalc@Temp 0% -\IntCalc@Temp 1% -\IntCalc@Temp 2% -\IntCalc@Temp 3% -\IntCalc@Temp 4% -\IntCalc@Temp 5% -\IntCalc@Temp 6% -\IntCalc@Temp 7% -\IntCalc@Temp 8% -\IntCalc@Temp 9% +\InCa@Temp 0% +\InCa@Temp 1% +\InCa@Temp 2% +\InCa@Temp 3% +\InCa@Temp 4% +\InCa@Temp 5% +\InCa@Temp 6% +\InCa@Temp 7% +\InCa@Temp 8% +\InCa@Temp 9% % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@TimDigit0} +% \begin{macro}{\InCa@TimDigit0} % \begin{macrocode} -\expandafter\def\csname IntCalc@TimDigit0\endcsname#1#2{% +\expandafter\def\csname InCa@TimDigit0\endcsname#1#2{% \endcsname 0#2% } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@TimDigit1} +% \begin{macro}{\InCa@TimDigit1} % \begin{macrocode} -\expandafter\def\csname IntCalc@TimDigit1\endcsname#1#2{% +\expandafter\def\csname InCa@TimDigit1\endcsname#1#2{% \ifcase#2 % \endcsname 0#1% \else - \csname IntCalc@AddDigit#1\endcsname #2% + \csname InCa@AddDigit#1\endcsname #2% \fi } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@TimDigit[2-9]} +% \begin{macro}{\InCa@TimDigit[2-9]} % \begin{macrocode} -\def\IntCalc@Temp#1#2{% - \expandafter\def\csname IntCalc@TimDigit#1\endcsname##1{% - \expandafter\IntCalc@TimDigitCarry +\def\InCa@Temp#1#2{% + \expandafter\def\csname InCa@TimDigit#1\endcsname##1{% + \expandafter\InCa@TimDigitCarry \number \ifcase##1 0% 0 #2% @@ -2057,7 +2275,7 @@ and the derived files !% }% } -\IntCalc@Temp 2{% +\InCa@Temp 2{% \or 2% 1 \or 4% 2 \or 6% 3 @@ -2068,7 +2286,7 @@ and the derived files \or 16% 8 \or 18% 9 } -\IntCalc@Temp 3{% +\InCa@Temp 3{% \or 3% 1 \or 6% 2 \or 9% 3 @@ -2079,7 +2297,7 @@ and the derived files \or 24% 8 \or 27% 9 } -\IntCalc@Temp 4{% +\InCa@Temp 4{% \or 4% 1 \or 8% 2 \or 12% 3 @@ -2090,7 +2308,7 @@ and the derived files \or 32% 8 \or 36% 9 } -\IntCalc@Temp 5{% +\InCa@Temp 5{% \or 5% 1 \or 10% 2 \or 15% 3 @@ -2101,7 +2319,7 @@ and the derived files \or 40% 8 \or 45% 9 } -\IntCalc@Temp 6{% +\InCa@Temp 6{% \or 6% 1 \or 12% 2 \or 18% 3 @@ -2112,7 +2330,7 @@ and the derived files \or 48% 8 \or 54% 9 } -\IntCalc@Temp 7{% +\InCa@Temp 7{% \or 7% 1 \or 14% 2 \or 21% 3 @@ -2123,7 +2341,7 @@ and the derived files \or 56% 8 \or 63% 9 } -\IntCalc@Temp 8{% +\InCa@Temp 8{% \or 8% 1 \or 16% 2 \or 24% 3 @@ -2134,7 +2352,7 @@ and the derived files \or 64% 8 \or 72% 9 } -\IntCalc@Temp 9{% +\InCa@Temp 9{% \or 9% 1 \or 18% 2 \or 27% 3 @@ -2147,24 +2365,24 @@ and the derived files } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@TimDigitCarry} +% \begin{macro}{\InCa@TimDigitCarry} % \begin{macrocode} -\def\IntCalc@TimDigitCarry#1!{% +\def\InCa@TimDigitCarry#1!{% \ifnum#1<10 % - \csname IntCalc@AddDigit#1\expandafter\endcsname + \csname InCa@AddDigit#1\expandafter\endcsname \else \@ReturnAfterFi{% - \IntCalc@@TimDigitCarry#1!% + \InCa@@TimDigitCarry#1!% }% \fi } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@@TimDigitCarry} +% \begin{macro}{\InCa@@TimDigitCarry} % \begin{macrocode} -\def\IntCalc@@TimDigitCarry#1#2!#3{% - \csname IntCalc@DigitCarry#1% - \csname IntCalc@AddDigit#2\endcsname #3% +\def\InCa@@TimDigitCarry#1#2!#3{% + \csname InCa@DigitCarry#1% + \csname InCa@AddDigit#2\endcsname #3% } % \end{macrocode} % \end{macro} @@ -2175,16 +2393,15 @@ and the derived files % \begin{macrocode} \def\intcalcMul#1#2{% \number - \expandafter\IntCalc@MulSwitch + \expandafter\InCa@MulSwitch \number\number#1\expandafter!% - \number#2!% - \IntCalc@Space + \number#2! % } % \end{macrocode} % \end{macro} % -% \begin{macro}{\IntCalc@MulSwitch} -% Decision table for \cs{IntCalc@MulSwitch}. +% \begin{macro}{\InCa@MulSwitch} +% Decision table for \cs{InCa@MulSwitch}. % \begin{quote} % \begin{tabular}[t]{@{}|l|l|l|l|l|@{}} % \hline @@ -2207,82 +2424,89 @@ and the derived files % \end{tabular} % \end{quote} % \begin{macrocode} -\def\IntCalc@MulSwitch#1!#2!{% +\def\InCa@MulSwitch#1!#2!{% \ifnum#1<\z@ \ifnum#2<\z@ \ifnum#1<#2 % - \expandafter\IntCalc@Mul\number-#1\expandafter!% - \IntCalc@Gobble#2!% + \expandafter\InCa@Mul\number-#1\expandafter!% + \@gobble#2!% \else - \expandafter\IntCalc@Mul\number-#2\expandafter!% - \IntCalc@Gobble#1!% + \expandafter\InCa@Mul\number-#2\expandafter!% + \@gobble#1!% \fi \else -% \ifnum-#1>#2 % - \expandafter\IntCalc@Mul\IntCalc@Gobble#1!#2!% + \expandafter\InCa@Mul\@gobble#1!#2!% \else - \expandafter\IntCalc@Mul\number#2\expandafter!% - \IntCalc@Gobble#1!% + \expandafter\InCa@Mul\number#2\expandafter!% + \@gobble#1!% \fi \fi \else \ifnum#2<\z@ -% \ifnum#1>-#2 % - \expandafter\IntCalc@Mul\number#1\expandafter!% - \IntCalc@Gobble#2!% + \expandafter\InCa@Mul\number#1\expandafter!% + \@gobble#2!% \else - \expandafter\IntCalc@Mul\IntCalc@Gobble#2!#1!% + \expandafter\InCa@Mul\@gobble#2!#1!% \fi \else \ifnum#1>#2 % - \IntCalc@Mul#1!#2!% + \InCa@Mul#1!#2!% \else - \IntCalc@Mul#2!#1!% + \InCa@Mul#2!#1!% \fi \fi \fi } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@Mul} +% \begin{macro}{\IntCalcMul} % \begin{macrocode} -\def\IntCalc@Mul#1!#2!{% +\def\IntCalcMul#1!#2!{% + \number\InCa@Mul#1!#2! % +} +% \end{macrocode} +% \end{macro} +% \begin{macro}{\InCa@Mul} +% \begin{macrocode} +\def\InCa@Mul#1!#2!{% \ifcase#2 % 0% \or #1% \or - \csname IntCalc@Empty% - \expandafter\IntCalc@Shl#1!% + \csname InCa@Empty% + \expandafter\InCa@Shl#1!% \else \ifnum#2<10 % - \IntCalc@Tim{#1}#2% + \InCa@Tim{#1}#2% \else - \IntCalc@ProcessMul!#2!#1!% + \InCa@ProcessMul!#2!#1!% \fi \fi } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@Mul} +% \begin{macro}{\InCa@Mul} % \begin{macrocode} -\def\IntCalc@ProcessMul#1!#2#3!#4!{% - \ifx\IntCalc@Empty#3\IntCalc@Empty - \expandafter\IntCalc@Add\number +\def\InCa@ProcessMul#1!#2#3!#4!{% + \ifx\InCa@Empty#3\InCa@Empty + \expandafter\InCa@Add\number #10\expandafter\expandafter\expandafter!% - \IntCalc@Tim{#4}#2!% + \InCa@Tim{#4}#2!% \else - \ifx\IntCalc@Empty#1\IntCalc@Empty - \expandafter\expandafter\expandafter\IntCalc@ProcessMul - \IntCalc@Tim{#4}#2!% + \ifx\InCa@Empty#1\InCa@Empty + \expandafter\expandafter\expandafter\InCa@ProcessMul + \InCa@Tim{#4}#2!% #3!#4!% \else - \expandafter\IntCalc@ProcessMul\number - \expandafter\IntCalc@Add\number% + \expandafter\InCa@ProcessMul\number + \expandafter\InCa@Add\number% #10\expandafter\expandafter\expandafter!% - \IntCalc@Tim{#4}#2!!% + \InCa@Tim{#4}#2!!% #3!#4!% \fi \fi @@ -2295,17 +2519,17 @@ and the derived files % \begin{macro}{\intcalcSqr} % \begin{macrocode} \def\intcalcSqr#1{% - \number\expandafter\IntCalc@Sqr\number#1! % + \number\expandafter\InCa@Sqr\number#1! % } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@Sqr} +% \begin{macro}{\InCa@Sqr} % \begin{macrocode} -\def\IntCalc@Sqr#1#2!{% +\def\InCa@Sqr#1#2!{% \ifx#1-% - \IntCalc@Mul#2!#2!% + \InCa@Mul#2!#2!% \else - \IntCalc@Mul#1#2!#1#2!% + \InCa@Mul#1#2!#1#2!% \fi } % \end{macrocode} @@ -2314,7 +2538,7 @@ and the derived files % \begin{macro}{\intcalcFac} % \begin{macrocode} \def\intcalcFac#1{% - \number\expandafter\IntCalc@Fac\number#1! % + \number\expandafter\InCa@Fac\number#1! % } % \end{macrocode} % \end{macro} @@ -2324,24 +2548,24 @@ and the derived files % \begin{macro}{\intcalcPow} % \begin{macrocode} \def\intcalcPow#1#2{% - \number\expandafter\IntCalc@Pow + \number\expandafter\InCa@Pow \number\number#1\expandafter!% \number#2! % } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@Pow} +% \begin{macro}{\InCa@Pow} % \begin{macrocode} -\def\IntCalc@Pow#1#2!#3#4!{% +\def\InCa@Pow#1#2!#3#4!{% \ifcase#3#4 % power = 0 1% \or % power = 1 #1#2% \or % power = 2 \ifx#1-% - \IntCalc@Mul#2!#2!% + \InCa@Mul#2!#2!% \else - \IntCalc@Mul#1#2!#1#2!% + \InCa@Mul#1#2!#1#2!% \fi \else \ifcase#1#2 % basis = 0, power <> 0 @@ -2365,9 +2589,9 @@ and the derived files \ifodd#3#4 % -% \fi - \IntCalc@PowRec#2!#3#4!1!% + \InCa@PowRec#2!#3#4!1!% \else - \IntCalc@PowRec#1#2!#3#4!1!% + \InCa@PowRec#1#2!#3#4!1!% \fi \fi \fi @@ -2376,7 +2600,7 @@ and the derived files } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@PowRec} +% \begin{macro}{\InCa@PowRec} %\begin{quote} %\begin{verbatim} %Pow(b, p) { @@ -2396,23 +2620,23 @@ and the derived files %\end{verbatim} %\end{quote} % \begin{macrocode} -\def\IntCalc@PowRec#1!#2!#3!{% +\def\InCa@PowRec#1!#2!#3!{% \ifnum#2=\@ne \ifnum#1>#3 % - \IntCalc@Mul#1!#3!% + \InCa@Mul#1!#3!% \else - \IntCalc@Mul#3!#1!% + \InCa@Mul#3!#1!% \fi \else - \expandafter\IntCalc@PowRec - \number\IntCalc@Mul#1!#1!\expandafter!% + \expandafter\InCa@PowRec + \number\InCa@Mul#1!#1!\expandafter!% \number\intcalcShr{#2}\expandafter!% \number \ifodd#2 % \ifnum#1>#3 % - \IntCalc@Mul#1!#3!% + \InCa@Mul#1!#3!% \else - \IntCalc@Mul#3!#1!% + \InCa@Mul#3!#1!% \fi \else #3% @@ -2428,22 +2652,22 @@ and the derived files % \begin{macro}{\intcalcDiv} % \begin{macrocode} \def\intcalcDiv#1#2{% - \number\expandafter\IntCalc@Div + \number\expandafter\InCa@Div \number\number#1\expandafter!% \number#2! % } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@Div} +% \begin{macro}{\InCa@Div} % \begin{macrocode} -\def\IntCalc@Div#1!#2!{% +\def\InCa@Div#1!#2!{% \ifcase#2 % 0\IntCalcError:DivisionByZero% \else \ifcase#1 % 0% \else - \expandafter\IntCalc@DivSwitch + \expandafter\InCa@DivSwitch \number#1\expandafter!% \number#2!% \fi @@ -2451,63 +2675,75 @@ and the derived files } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@DivSwitch} -% Decision table for \cs{IntCalc@DivSwitch}. +% \begin{macro}{\IntCalcDiv} +% \begin{macrocode} +\def\InCa@Temp#1{% + \def\IntCalcDiv##1!##2!{% + \number + \ifcase##2 % + 0\IntCalcError:DivisionByZero% + \else + \ifcase##1 % + 0% + \else + \InCa@@Div##1!##2!% + \fi + \fi + #1% + }% +} +\InCa@Temp{ }% +% \end{macrocode} +% \end{macro} +% \begin{macro}{\InCa@DivSwitch} +% Decision table for \cs{InCa@DivSwitch}. % \begin{quote} -% \begin{tabular}[t]{@{}|l|l|l|l|l|@{}} +% \begin{tabular}[t]{@{}|l|l|l|l|@{}} % \hline -% $x<0$ & $y<0$ & $ x< y$ & $+$ & $\opDiv(-x,-y)$\\ -% \cline{3-3}\cline{5-5} -% & & else & & $\opDiv(-y,-x)$\\ -% \cline{2-5} -% & else & $-x> y$ & $-$ & $\opDiv(-x, y)$\\ -% \cline{3-3}\cline{5-5} -% & & else & & $\opDiv( y,-x)$\\ +% $x<0$ & $y<0$ & $+$ & $\opDiv(-x,-y)$\\ +% \cline{2-4} +% & else & $-$ & $\opDiv(-x, y)$\\ % \hline -% else & $y<0$ & $ x>-y$ & $-$ & $\opDiv( x,-y)$\\ -% \cline{3-3}\cline{5-5} -% & & else & & $\opDiv(-y, x)$\\ -% \cline{2-5} -% & else & $ x> y$ & $+$ & $\opDiv( x, y)$\\ -% \cline{3-3}\cline{5-5} -% & & else & & $\opDiv( y, x)$\\ +% else & $y<0$ & $-$ & $\opDiv( x,-y)$\\ +% \cline{2-4} +% & else & $+$ & $\opDiv( x, y)$\\ % \hline % \end{tabular} % \end{quote} % \begin{macrocode} -\def\IntCalc@DivSwitch#1!#2!{% +\def\InCa@DivSwitch#1!#2!{% \ifnum#1<\z@ \ifnum#2<\z@ - \expandafter\IntCalc@@Div\number-#1\expandafter!% - \IntCalc@Gobble#2!% + \expandafter\InCa@@Div\number-#1\expandafter!% + \@gobble#2!% \else -% - \expandafter\IntCalc@@Div\IntCalc@Gobble#1!#2!% + \expandafter\InCa@@Div\@gobble#1!#2!% \fi \else \ifnum#2<\z@ -% - \expandafter\IntCalc@@Div\number#1\expandafter!% - \IntCalc@Gobble#2!% + \expandafter\InCa@@Div\number#1\expandafter!% + \@gobble#2!% \else - \IntCalc@@Div#1!#2!% + \InCa@@Div#1!#2!% \fi \fi } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@@Div} +% \begin{macro}{\InCa@@Div} % \begin{macrocode} -\def\IntCalc@@Div#1!#2!{% +\def\InCa@@Div#1!#2!{% \ifnum#1>#2 % \ifcase#2 % 0 already catched ? \IntCalcError:ThisCannotHappen% \or % 1 #1% \or % 2 - \IntCalc@Shr#1!% + \InCa@Shr#1!% \else - \IntCalc@DivStart!#1!#2!#2!% + \InCa@DivStart!#1!#2!#2!% \fi \else \ifnum#1=#2 % @@ -2519,77 +2755,77 @@ and the derived files } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@DivStart} +% \begin{macro}{\InCa@DivStart} % \begin{macrocode} -\def\IntCalc@DivStart#1!#2#3!#4#5{% +\def\InCa@DivStart#1!#2#3!#4#5{% \ifx#5!% \@ReturnAfterElseFi{% - \IntCalc@DivStartI{#1#2}#3=!% + \InCa@DivStartI{#1#2}#3=!% }% \else \@ReturnAfterFi{% - \IntCalc@DivStart{#1#2}!#3!#5% + \InCa@DivStart{#1#2}!#3!#5% }% \fi } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@StartI} +% \begin{macro}{\InCa@StartI} % \begin{macrocode} -\def\IntCalc@DivStartI#1!#2!{% - \expandafter\IntCalc@DivStartII +\def\InCa@DivStartI#1!#2!{% + \expandafter\InCa@DivStartII \number#2\expandafter\expandafter\expandafter!% \intcalcShl{#2}!% #1!% } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@StartII} +% \begin{macro}{\InCa@StartII} % \begin{macrocode} -\def\IntCalc@DivStartII#1!#2!{% - \expandafter\IntCalc@DivStartIII +\def\InCa@DivStartII#1!#2!{% + \expandafter\InCa@DivStartIII \number#1\expandafter!% \number#2\expandafter\expandafter\expandafter!% \intcalcShl{#2}!% } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@StartIII} +% \begin{macro}{\InCa@StartIII} % \begin{macrocode} -\def\IntCalc@DivStartIII#1!#2!#3!{% - \expandafter\IntCalc@DivStartIV +\def\InCa@DivStartIII#1!#2!#3!{% + \expandafter\InCa@DivStartIV \number#1\expandafter!% \number#2\expandafter!% \number#3\expandafter!% - \number\IntCalc@Add#3!#2!\expandafter\expandafter\expandafter!% + \number\InCa@Add#3!#2!\expandafter\expandafter\expandafter!% \intcalcShl{#3}!% } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@StartIV} +% \begin{macro}{\InCa@StartIV} % \begin{macrocode} -\def\IntCalc@DivStartIV#1!#2!#3!#4!#5!#6!{% - \IntCalc@ProcessDiv#6!#1!#2!#3!#4!#5!/% +\def\InCa@DivStartIV#1!#2!#3!#4!#5!#6!{% + \InCa@ProcessDiv#6!#1!#2!#3!#4!#5!/% } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@ProcessDiv} +% \begin{macro}{\InCa@ProcessDiv} % \begin{macrocode} -\def\IntCalc@ProcessDiv#1#2#3!#4!#5!#6!#7!#8!#9/{% +\def\InCa@ProcessDiv#1#2#3!#4!#5!#6!#7!#8!#9/{% #9% \ifnum#1<#4 % 0 0% \ifx#2=% \else - \IntCalc@ProcessDiv{#1#2}#3!#4!#5!#6!#7!#8!% + \InCa@ProcessDiv{#1#2}#3!#4!#5!#6!#7!#8!% \fi \else % 1-9 \ifnum#1<#5 % 1 1% \ifx#2=% \else - \expandafter\IntCalc@ProcessDiv\expandafter{% - \number\IntCalc@Sub#1!#4!% + \expandafter\InCa@ProcessDiv\expandafter{% + \number\InCa@Sub#1!#4!% #2% }#3!#4!#5!#6!#7!#8!% \fi @@ -2597,14 +2833,14 @@ and the derived files \ifnum#1<#7 % 2 3 4 5 \ifnum#1<#6 % 2 3 \@ReturnAfterElseFi{% - \expandafter\IntCalc@@ProcessDiv - \number\IntCalc@Sub#1!#5!!% + \expandafter\InCa@@ProcessDiv + \number\InCa@Sub#1!#5!!% 23% }% \else % 4 5 \@ReturnAfterFi{% - \expandafter\IntCalc@@ProcessDiv - \number\IntCalc@Sub#1!#6!!% + \expandafter\InCa@@ProcessDiv + \number\InCa@Sub#1!#6!!% 45% }% \fi @@ -2612,14 +2848,14 @@ and the derived files \else % 6 7 8 9 \ifnum#1<#8 % 6 7 \@ReturnAfterElseFi{% - \expandafter\IntCalc@@ProcessDiv - \number\IntCalc@Sub#1!#7!!% + \expandafter\InCa@@ProcessDiv + \number\InCa@Sub#1!#7!!% 67% }% \else % 8 9 \@ReturnAfterFi{% - \expandafter\IntCalc@@ProcessDiv - \number\IntCalc@Sub#1!#8!!% + \expandafter\InCa@@ProcessDiv + \number\InCa@Sub#1!#8!!% 89% }% \fi @@ -2628,23 +2864,23 @@ and the derived files \fi \fi \ifx#2=% - \expandafter\IntCalc@Gobble + \expandafter\@gobble \fi /% } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@@ProcessDiv} +% \begin{macro}{\InCa@@ProcessDiv} % \begin{macrocode} -\def\IntCalc@@ProcessDiv#1!#2#3#4#5!#6!{% +\def\InCa@@ProcessDiv#1!#2#3#4#5!#6!{% \ifnum#1<#6 % #2% \@ReturnAfterElseFi{% \ifx#4=% - \expandafter\IntCalc@CleanupIV + \expandafter\InCa@CleanupIV \else \@ReturnAfterFi{% - \IntCalc@ProcessDiv{#1#4}#5!#6!% + \InCa@ProcessDiv{#1#4}#5!#6!% }% \fi }% @@ -2652,11 +2888,11 @@ and the derived files #3% \@ReturnAfterFi{% \ifx#4=% - \expandafter\IntCalc@CleanupIV + \expandafter\InCa@CleanupIV \else \@ReturnAfterFi{% - \expandafter\IntCalc@ProcessDiv\expandafter{% - \number\IntCalc@Sub#1!#6!\IntCalc@Space + \expandafter\InCa@ProcessDiv\expandafter{% + \number\InCa@Sub#1!#6! % #4% }#5!#6!% }% @@ -2666,9 +2902,9 @@ and the derived files } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@CleanupIV} +% \begin{macro}{\InCa@CleanupIV} % \begin{macrocode} -\def\IntCalc@CleanupIV#1!#2!#3!#4!{} +\def\InCa@CleanupIV#1!#2!#3!#4!{} % \end{macrocode} % \end{macro} % @@ -2677,7 +2913,7 @@ and the derived files % \begin{macro}{\intcalcMod} % \begin{macrocode} \def\intcalcMod#1#2{% - \number\expandafter\IntCalc@Mod + \number\expandafter\InCa@Mod \number\number#1\expandafter!% \number#2! % } @@ -2693,19 +2929,19 @@ and the derived files % elsif & $y=1$ & 0\\ % elsif & $y=2$ & $\opOdd(x)\mathbin{?}1\mathbin{:}0$\\ % elsif & $x<0$ & -% $z\leftarrow x+(x/y)*x;\quad (z<0)\mathbin{?}z+x\mathbin{:}z$\\ -% else & & $x-(x/y)*x$\\ +% $z\leftarrow x-(x/y)*y;\quad (z<0)\mathbin{?}z+y\mathbin{:}z$\\ +% else & & $x-(x/y)*y$\\ % \\ % \end{tabular} % \end{quote} % \begin{macrocode} -\def\IntCalc@Mod#1!#2!{% +\def\InCa@Mod#1!#2!{% \ifcase#2 % 0\IntCalcError:DivisionByZero% \else \ifnum#2<\z@ -% - \expandafter\IntCalc@Mod + \expandafter\InCa@Mod \number-#1\expandafter!% \number-#2!% \else @@ -2717,24 +2953,20 @@ and the derived files \or % 1 0% \or % 2 - \ifodd#1 % - 1% - \else - 0% - \fi + \ifodd#1 1\else 0\fi \else \ifnum#1<\z@ - \expandafter\IntCalc@ModShift + \expandafter\InCa@ModShift \number-% - \expandafter\IntCalc@Sub - \number\IntCalc@Gobble#1\expandafter!% + \expandafter\InCa@Sub + \number\@gobble#1\expandafter!% \number\intcalcMul{#2}{% - \expandafter\IntCalc@Div\IntCalc@Gobble#1!#2!% + \expandafter\InCa@Div\@gobble#1!#2!% }!% !#2!% \else - \expandafter\IntCalc@Sub\number#1\expandafter!% - \number\intcalcMul{#2}{\IntCalc@Div#1!#2!}!% + \expandafter\InCa@Sub\number#1\expandafter!% + \number\intcalcMul{#2}{\InCa@Div#1!#2!}!% \fi \fi \fi @@ -2743,12 +2975,41 @@ and the derived files } % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@ModShift} +% \begin{macro}{\IntCalcMod} % \begin{macrocode} -\def\IntCalc@ModShift#1!#2!{% +\def\InCa@Temp#1{% + \def\IntCalcMod##1!##2!{% + \number + \ifcase##2 % + 0\IntCalcError:DivisionByZero% + \else + \ifcase##1 % + 0% + \else + \ifcase##2 % 0 already catched +? \IntCalcError:ThisCannotHappen + \or % 1 + 0% + \or % 2 + \ifodd ##1 1\else 0\fi + \else + \expandafter\InCa@Sub\number##1\expandafter!% + \number\intcalcMul{##2}{\InCa@Div##1!##2!}!% + \fi + \fi + \fi + #1% + }% +} +\InCa@Temp{ }% +% \end{macrocode} +% \end{macro} +% \begin{macro}{\InCa@ModShift} +% \begin{macrocode} +\def\InCa@ModShift#1!#2!{% \ifnum#1<\z@ - \expandafter\IntCalc@Sub\number#2\expandafter!% - \IntCalc@Gobble#1!% + \expandafter\InCa@Sub\number#2\expandafter!% + \@gobble#1!% \else #1% \fi @@ -2758,14 +3019,16 @@ and the derived files % % \subsubsection{Help macros} % -% \begin{macro}{\IntCalc@Empty} +% \begin{macro}{\InCa@Empty} % \begin{macrocode} -\def\IntCalc@Empty{} +\def\InCa@Empty{} % \end{macrocode} % \end{macro} -% \begin{macro}{\IntCalc@Gobble} +% \begin{macro}{\@gobble} % \begin{macrocode} -\def\IntCalc@Gobble#1{} +\expandafter\ifx\csname @gobble\endcsname\relax + \long\def\@gobble#1{}% +\fi % \end{macrocode} % \end{macro} % \begin{macro}{\@ReturnAfterFi} @@ -2780,7 +3043,7 @@ and the derived files % \end{macro} % % \begin{macrocode} -\IntCalc@AtEnd +\InCa@AtEnd % \end{macrocode} % % \begin{macrocode} @@ -2846,22 +3109,22 @@ and the derived files % \subsubsection{Preamble with test macro definitions} % % \begin{macrocode} -%<*test2|test3|test4> +%<*test2|test4> \NeedsTeXFormat{LaTeX2e} \nofiles \documentclass{article} %<noetex>\let\SavedNumexpr\numexpr %<noetex>\let\numexpr\UNDEFINED \makeatletter -\chardef\IntCalc@TestMode=1 % +\chardef\InCa@TestMode=1 % \makeatother -\usepackage{intcalc}[2007/09/09] +\usepackage{intcalc}[2007/09/27] %<noetex>\let\numexpr\SavedNumexpr \usepackage{qstest} \IncludeTests{*} \LogTests{log}{*}{*} -%</test2|test3|test4> -%<*test2|test3> +%</test2|test4> +%<*test2> \newcommand*{\TestSpaceAtEnd}[1]{% %<noetex> \let\SavedNumexpr\numexpr %<noetex> \let\numexpr\UNDEFINED @@ -2904,6 +3167,9 @@ and the derived files \newcommand*{\TestInv}[2]{% \Test{\intcalcInv{#1}}{#2}% } +\newcommand*{\TestNum}[2]{% + \Test{\intcalcNum{#1}}{#2}% +} \newcommand*{\TestAbs}[2]{% \Test{\intcalcAbs{#1}}{#2}% } @@ -2921,24 +3187,92 @@ and the derived files } \newcommand*{\TestInc}[2]{% \Test{\intcalcInc{#1}}{#2}% + \ifnum\intcalcNum{#1}>-1 % + \edef\x{% + \noexpand\Test{% + \noexpand\IntCalcInc\intcalcNum{#1}!% + }{#2}% + }% + \x + \fi } \newcommand*{\TestDec}[2]{% \Test{\intcalcDec{#1}}{#2}% + \ifnum\intcalcNum{#1}>0 % + \edef\x{% + \noexpand\Test{% + \noexpand\IntCalcDec\intcalcNum{#1}!% + }{#2}% + }% + \x + \fi } \newcommand*{\TestAdd}[3]{% \Test{\intcalcAdd{#1}{#2}}{#3}% + \ifnum\intcalcNum{#1}>0 % + \ifnum\intcalcNum{#2}> 0 % + \ifnum\intcalcCmp{#1}{#2}>0 % + \edef\x{% + \noexpand\Test{% + \noexpand\IntCalcAdd + \intcalcNum{#1}!\intcalcNum{#2}!% + }{#3}% + }% + \x + \else + \edef\x{% + \noexpand\Test{% + \noexpand\IntCalcAdd + \intcalcNum{#2}!\intcalcNum{#1}!% + }{#3}% + }% + \x + \fi + \fi + \fi } \newcommand*{\TestSub}[3]{% \Test{\intcalcSub{#1}{#2}}{#3}% + \ifnum\intcalcNum{#1}>0 % + \ifnum\intcalcNum{#2}> 0 % + \ifnum\intcalcCmp{#1}{#2}>0 % + \edef\x{% + \noexpand\Test{% + \noexpand\IntCalcSub + \intcalcNum{#1}!\intcalcNum{#2}!% + }{#3}% + }% + \x + \fi + \fi + \fi } \newcommand*{\TestShl}[2]{% \Test{\intcalcShl{#1}}{#2}% + \edef\x{% + \noexpand\Test{% + \noexpand\IntCalcShl\intcalcAbs{#1}!% + }{\intcalcAbs{#2}}% + }% + \x } \newcommand*{\TestShr}[2]{% \Test{\intcalcShr{#1}}{#2}% + \edef\x{% + \noexpand\Test{% + \noexpand\IntCalcShr\intcalcAbs{#1}!% + }{\intcalcAbs{#2}}% + }% + \x } \newcommand*{\TestMul}[3]{% \Test{\intcalcMul{#1}{#2}}{#3}% + \edef\x{% + \noexpand\Test{% + \noexpand\IntCalcMul\intcalcAbs{#1}!\intcalcAbs{#2}!% + }{\intcalcAbs{#3}}% + }% + \x } \newcommand*{\TestSqr}[2]{% \Test{\intcalcSqr{#1}}{#2}% @@ -2952,11 +3286,85 @@ and the derived files \newcommand*{\TestDiv}[3]{% \Test{\intcalcDiv{#1}{#2}}{#3}% \TestTeXDivide{#1}{#2}% + \edef\x{% + \noexpand\Test{% + \noexpand\IntCalcDiv\intcalcAbs{#1}!\intcalcAbs{#2}!% + }{\intcalcAbs{#3}}% + }% } \newcommand*{\TestMod}[3]{% \Test{\intcalcMod{#1}{#2}}{#3}% + \ifcase\ifcase\intcalcSgn{#1} 0% + \or + \ifcase\intcalcSgn{#2} 1% + \or 0% + \else 1% + \fi + \else + \ifcase\intcalcSgn{#2} 1% + \or 1% + \else 0% + \fi + \fi\relax + \edef\x{% + \noexpand\Test{% + \noexpand\IntCalcMod + \intcalcAbs{#1}!\intcalcAbs{#2}!% + }{\intcalcAbs{#3}}% + }% + \x + \fi } -%</test2|test3> +%</test2> +% \end{macrocode} +% +% \subsubsection{Time} +% +% \begin{macrocode} +%<*test2> +\begingroup\expandafter\expandafter\expandafter\endgroup +\expandafter\ifx\csname pdfresettimer\endcsname\relax +\else + \makeatletter + \newcount\SummaryTime + \newcount\TestTime + \SummaryTime=\z@ + \newcommand*{\PrintTime}[2]{% + \typeout{% + [Time #1: \strip@pt\dimexpr\number#2sp\relax\space s]% + }% + }% + \newcommand*{\StartTime}[1]{% + \renewcommand*{\TimeDescription}{#1}% + \pdfresettimer + }% + \newcommand*{\TimeDescription}{}% + \newcommand*{\StopTime}{% + \TestTime=\pdfelapsedtime + \global\advance\SummaryTime\TestTime + \PrintTime\TimeDescription\TestTime + }% + \let\saved@qstest\qstest + \let\saved@endqstest\endqstest + \def\qstest#1#2{% + \saved@qstest{#1}{#2}% + \StartTime{#1}% + }% + \def\endqstest{% + \StopTime + \saved@endqstest + }% + \AtEndDocument{% + \PrintTime{summary}\SummaryTime + }% + \makeatother +\fi +%</test2> +% \end{macrocode} +% +% \subsubsection{Test 4: additional mod/div operations} +% +% \begin{macrocode} %<*test4> \newcommand*{\TestDo}[2]{% \ifcase\numexpr#2\relax @@ -2978,6 +3386,7 @@ and the derived files \TestDo{#1}{#2}% \TestDo{#2}{#1}% } +\let\TestNum\TestOne \let\TestInv\TestOne \let\TestAbs\TestOne \let\TestSgn\TestOne @@ -3002,9 +3411,30 @@ and the derived files % \subsubsection{Test sets} % % \begin{macrocode} -%<*test2|test3|test4> +%<*test2|test4> \makeatletter +\begin{qstest}{num}{num}% + \TestNum{0}{0}% + \TestNum{1}{1}% + \TestNum{-1}{-1}% + \TestNum{10}{10}% + \TestNum{-10}{-10}% + \TestNum{2147483647}{2147483647}% + \TestNum{-2147483647}{-2147483647}% + \TestNum{ 0 }{0}% + \TestNum{ 1 }{1}% + \TestNum{--1}{1}% + \TestNum{ - + - + 4 }{4}% + \TestNum{\z@}{0}% + \TestNum{\@ne}{1}% + \TestNum{\m@ne}{-1}% +%<*etex> + \TestNum{-10+30}{20}% + \TestNum{10-30}{-20}% +%</etex> +\end{qstest} + \begin{qstest}{inv}{inv}% \TestInv{0}{0}% \TestInv{1}{-1}% @@ -3224,6 +3654,8 @@ and the derived files \TestShl{1}{2}% \TestShl{5621}{11242}% \TestShl{1073741823}{2147483646}% + \TestShl{-1}{-2}% + \TestShl{-5621}{-11242}% \end{qstest} \begin{qstest}{shr}{shr} @@ -3253,6 +3685,10 @@ and the derived files \TestShr{11241}{5620}% \TestShr{73054202}{36527101}% \TestShr{2147483646}{1073741823}% + \TestShr{-1}{0}% + \TestShr{-2}{-1}% + \TestShr{-3}{-1}% + \TestShr{-11241}{-5620}% \end{qstest} \begin{qstest}{mul}{mul} @@ -3473,9 +3909,9 @@ and the derived files \TestMod{1+2}{1-5}{-1}% %</etex> \end{qstest} -%</test2|test3|test4> +%</test2|test4> -%<*test2|test3> +%<*test2> \newcommand*{\TestError}[2]{% \begingroup \expandafter\def\csname IntCalcError:#1\endcsname{}% @@ -3489,18 +3925,18 @@ and the derived files \TestError{FacNegative}{\intcalcFac{-2147483647}}% \TestError{FacOverflow}{\intcalcFac{13}}% \TestError{FacOverflow}{\intcalcFac{2147483647}}% - \TestError{ShlNegativeNumber}{\intcalcShl{-1}}% - \TestError{ShrNegativeNumber}{\intcalcShr{-1}}% \TestError{DivisionByZero}{\intcalcPow{0}{-1}}% \TestError{DivisionByZero}{\intcalcDiv{1}{0}}% \TestError{DivisionByZero}{\intcalcMod{1}{0}}% + \TestError{DivisionByZero}{\IntCalcDiv1!0!}% + \TestError{DivisionByZero}{\IntCalcMod1!0!}% \end{qstest} -%</test2|test3> +%</test2> -%<*test2|test3|test4> +%<*test2|test4> \begin{document} \end{document} -%</test2|test3|test4> +%</test2|test4> % \end{macrocode} % % \section{Installation} @@ -3693,6 +4129,21 @@ and the derived files % \item % First version. % \end{Version} +% \begin{Version}{2007/09/27 v1.1} +% \item +% \cs{intcalcNum} added. +% \item +% \cs{intcalcShl} and \cs{intcalcShr} allow negative numbers. +% The sign is preserved. +% \item +% Reuse \cs{@gobble} instead of own macro \cs{IntCalc@Gobble}. +% \item +% Small fixes. +% \item +% Shorter internal prefix. +% \item +% Some programmer's interface. +% \end{Version} % \end{History} % % \PrintIndex |