diff options
Diffstat (limited to 'Master/texmf-dist/tex/generic/oberdiek/intcalc.sty')
-rw-r--r-- | Master/texmf-dist/tex/generic/oberdiek/intcalc.sty | 892 |
1 files changed, 506 insertions, 386 deletions
diff --git a/Master/texmf-dist/tex/generic/oberdiek/intcalc.sty b/Master/texmf-dist/tex/generic/oberdiek/intcalc.sty index e92da6bba91..8e1e5d1e860 100644 --- a/Master/texmf-dist/tex/generic/oberdiek/intcalc.sty +++ b/Master/texmf-dist/tex/generic/oberdiek/intcalc.sty @@ -80,14 +80,14 @@ \fi \expandafter\x\csname ver@intcalc.sty\endcsname \ProvidesPackage{intcalc}% - [2007/09/09 v1.0 Expandable integer calculations (HO)] -\expandafter\edef\csname IntCalc@AtEnd\endcsname{% + [2007/09/27 v1.1 Expandable integer calculations (HO)] +\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 @@ -105,20 +105,19 @@ \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 -\def\IntCalc@Space{ } -\def\IntCalc@Abs#1#2!{% +? \let\InCa@@TestMode\InCa@TestMode +\def\InCa@Abs#1#2!{% \ifx#1-% #2% \else #1#2% \fi } -\def\IntCalc@Sgn#1#2!{% +\def\InCa@Sgn#1#2!{% \ifx#1-% -1% \else @@ -129,21 +128,21 @@ \fi \fi } -\def\IntCalc@Min#1!#2!{% +\def\InCa@Min#1!#2!{% \ifnum#1<#2 % #1% \else #2% \fi } -\def\IntCalc@Max#1!#2!{% +\def\InCa@Max#1!#2!{% \ifnum#1>#2 % #1% \else #2% \fi } -\def\IntCalc@Cmp#1!#2!{% +\def\InCa@Cmp#1!#2!{% \ifnum#1=#2 % 0% \else @@ -153,7 +152,7 @@ 1% \fi } -\def\IntCalc@Fac#1!{% +\def\InCa@Fac#1!{% \ifcase#1 1% 0! \or 1% 1! \or 2% 2! @@ -178,27 +177,30 @@ \begingroup\expandafter\expandafter\expandafter\endgroup \expandafter\ifx\csname numexpr\endcsname\relax \else + \def\intcalcNum#1{% + \the\numexpr#1\relax + }% \def\intcalcInv#1{% - \number-\the\numexpr#1\relax\IntCalc@Space + \number-\intcalcNum{#1} % }% \def\intcalcAbs#1{% - \number\expandafter\IntCalc@Abs\the\numexpr#1! % + \number\expandafter\InCa@Abs\the\numexpr#1! % }% \def\intcalcSgn#1{% - \number\expandafter\IntCalc@Sgn\the\numexpr#1! % + \number\expandafter\InCa@Sgn\the\numexpr#1! % }% \def\intcalcMin#1#2{% - \number\expandafter\IntCalc@Min + \number\expandafter\InCa@Min \the\numexpr#1\expandafter!% \the\numexpr#2! % }% \def\intcalcMax#1#2{% - \number\expandafter\IntCalc@Max + \number\expandafter\InCa@Max \the\numexpr#1\expandafter!% \the\numexpr#2! % }% \def\intcalcCmp#1#2{% - \number\expandafter\IntCalc@Cmp + \number\expandafter\InCa@Cmp \the\numexpr#1\expandafter!\the\numexpr#2! % }% \def\intcalcInc#1{% @@ -207,28 +209,40 @@ \def\intcalcDec#1{% \the\numexpr#1-1\relax }% + \def\IntCalcInc#1!{% + \the\numexpr#1+1\relax + }% + \def\IntCalcDec#1!{% + \the\numexpr#1-1\relax + }% \def\intcalcAdd#1#2{% \the\numexpr#1+(#2)\relax }% \def\intcalcSub#1#2{% \the\numexpr#1-(#2)\relax }% - \def\intcalcShl#1{% - \number\expandafter\IntCalc@Shl\the\numexpr#1! % + + \def\IntCalcAdd#1!#2!{% + \the\numexpr#1+#2\relax }% - \def\IntCalc@Shl#1#2!{% - \ifx#1-% - 0\IntCalcError:ShlNegativeNumber% - \else - \the\numexpr#1#2*2\relax - \fi + \def\IntCalcSub#1!#2!{% + \the\numexpr#1-#2\relax + }% + \def\intcalcShl#1{% + \the\numexpr(#1)*2\relax }% \def\intcalcShr#1{% - \number\expandafter\IntCalc@Shr\the\numexpr#1! % + \number\expandafter\InCa@Shr\the\numexpr#1! % + }% + \def\IntCalcShl#1!{% + \the\numexpr#1*2\relax + }% + \def\IntCalcShr#1!{% + \the\numexpr\ifodd#1 (#1-1)\else#1\fi/2\relax }% - \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 @@ -240,21 +254,24 @@ \def\intcalcMul#1#2{% \the\numexpr(#1)*(#2)\relax }% + \def\IntCalcMul#1!#2!{% + \the\numexpr#1*#2\relax + }% \def\intcalcSqr#1{% - \number\expandafter\IntCalc@Sqr\the\numexpr#1! % + \number\expandafter\InCa@Sqr\the\numexpr#1! % }% - \def\IntCalc@Sqr#1!{% + \def\InCa@Sqr#1!{% \the\numexpr#1*#1\relax }% \def\intcalcFac#1{% - \number\expandafter\IntCalc@Fac\the\numexpr#1! % + \number\expandafter\InCa@Fac\the\numexpr#1! % }% \def\intcalcPow#1#2{% - \number\expandafter\IntCalc@Pow + \number\expandafter\InCa@Pow \the\numexpr#1\expandafter!% \the\numexpr#2! % }% - \def\IntCalc@Pow#1#2!#3#4!{% + \def\InCa@Pow#1#2!#3#4!{% \ifcase#3#4 % power = 0 1% \or % power = 1 @@ -279,23 +296,23 @@ \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 \fi }% - \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!% @@ -303,18 +320,18 @@ \fi }% \def\intcalcDiv#1#2{% - \number\expandafter\IntCalc@Div + \number\expandafter\InCa@Div \the\numexpr#1\expandafter!% \the\numexpr#2! % }% - \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% @@ -332,23 +349,39 @@ \fi \fi }% - \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{ }% + \def\InCa@@Div#1#2!#3#4!{% #1#3% \the\numexpr(#2-(#4-1)/2)/#4\relax }% \def\intcalcMod#1#2{% - \number\expandafter\IntCalc@Mod + \number\expandafter\InCa@Mod \the\numexpr#1\expandafter!% \the\numexpr#2! % }% - \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% @@ -366,96 +399,121 @@ \fi \fi }% - \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{ }% + \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 }% - \def\IntCalc@ModX#1!#2!{% + \def\InCa@ModX#1!#2!{% \ifcase#1 % 0% \else \the\numexpr#1+#2\relax \fi }% - \IntCalc@AtEnd + \InCa@AtEnd \expandafter\endinput \fi +\def\intcalcNum#1{% + \number\expandafter\InCa@FirstOfOne\number#1! % +} \def\intcalcInv#1{% - \number\expandafter\IntCalc@Inv\number-#1! % + \number\expandafter\InCa@FirstOfOne\number-#1! % } -\def\IntCalc@Inv#1!{#1} +\def\InCa@FirstOfOne#1!{#1} \def\intcalcAbs#1{% - \number\expandafter\IntCalc@Abs\number#1! % + \number\expandafter\InCa@Abs\number#1! % } \def\intcalcSgn#1{% - \number\expandafter\IntCalc@Sgn\number#1! % + \number\expandafter\InCa@Sgn\number#1! % } \def\intcalcMin#1#2{% - \number\expandafter\IntCalc@Min + \number\expandafter\InCa@Min \number\number#1\expandafter!\number#2! % } \def\intcalcMax#1#2{% - \number\expandafter\IntCalc@Max + \number\expandafter\InCa@Max \number\number#1\expandafter!\number#2! % } \def\intcalcCmp#1#2{% - \number\expandafter\IntCalc@Cmp + \number\expandafter\InCa@Cmp \number\number#1\expandafter!\number#2! % }% \def\intcalcInc#1{% - \number\expandafter\IntCalc@IncSwitch\number#1! % + \number\expandafter\InCa@IncSwitch\number#1! % } -\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 } \def\intcalcDec#1{% - \number\expandafter\IntCalc@DecSwitch\number#1! % + \number\expandafter\InCa@DecSwitch\number#1! % } -\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 } -\def\IntCalc@Inc#1#2{% +\def\IntCalcInc#1!{% + \number\csname InCa@Empty\InCa@Inc#1! % +} +\def\IntCalcDec#1!{% + \number\csname InCa@Empty\InCa@Dec#1! % +} +\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 } -\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 % @@ -465,16 +523,16 @@ \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 -\expandafter\def\csname IntCalc@IncDigit9\endcsname#1{% +\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 +\expandafter\def\csname InCa@IncDigit9\endcsname#1{% \expandafter\endcsname \ifcase#1 % 09% @@ -482,16 +540,16 @@ 10% \fi } -\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 } -\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 % @@ -501,16 +559,16 @@ \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 -\expandafter\def\csname IntCalc@DecDigit0\endcsname#1{% +\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 +\expandafter\def\csname InCa@DecDigit0\endcsname#1{% \expandafter\endcsname \ifcase#1 % 00% @@ -520,140 +578,149 @@ } \def\intcalcAdd#1#2{% \number - \expandafter\IntCalc@AddSwitch + \expandafter\InCa@AddSwitch \number\number#1\expandafter!% - \number#2!% - \IntCalc@Space + \number#2! % } \def\intcalcSub#1#2{% \number - \expandafter\IntCalc@AddSwitch + \expandafter\InCa@AddSwitch \number\number#1\expandafter!% - \number-\number#2!% - \IntCalc@Space + \number-\number#2! % } -\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 } -\def\IntCalc@Add#1!#2!{% +\def\IntCalcAdd#1!#2!{% + \number\InCa@Add#1!#2! % +} +\def\IntCalcSub#1!#2!{% + \number\InCa@Sub#1!#2! % +} +\begingroup + \def\x#1{\endgroup + \let\InCa@Space= #1% + }% +\x{ } +\def\InCa@Add#1!#2!{% \ifcase#2 % #1% \else - \IntCalc@@Add#1!#2!000000000\IntCalc@Space + \InCa@@Add#1!#2!000000000\InCa@Space \fi } -\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 } -\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 } -\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 } -\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 } -\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 } -\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 } -\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 } -\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 @@ -661,25 +728,25 @@ \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}} -\expandafter\def\csname IntCalc@AddDigit0\endcsname#1{% +\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}} +\expandafter\def\csname InCa@AddDigit0\endcsname#1{% \ifnum#1>9 % \endcsname10% \else \endcsname0#1% \fi } -\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 @@ -691,7 +758,7 @@ \fi }% } -\IntCalc@Temp 18{% +\InCa@Temp 18{% \or 2% 1 \or 3% 2 \or 4% 3 @@ -702,7 +769,7 @@ \or 9% 8 \or 0% 9 }% -\IntCalc@Temp 27{% +\InCa@Temp 27{% \or 3% 1 \or 4% 2 \or 5% 3 @@ -713,7 +780,7 @@ \or 0% 8 \or 1% 9 }% -\IntCalc@Temp 36{% +\InCa@Temp 36{% \or 4% 1 \or 5% 2 \or 6% 3 @@ -724,7 +791,7 @@ \or 1% 8 \or 2% 9 }% -\IntCalc@Temp 45{% +\InCa@Temp 45{% \or 5% 1 \or 6% 2 \or 7% 3 @@ -735,7 +802,7 @@ \or 2% 8 \or 3% 9 }% -\IntCalc@Temp 54{% +\InCa@Temp 54{% \or 6% 1 \or 7% 2 \or 8% 3 @@ -746,7 +813,7 @@ \or 3% 8 \or 4% 9 }% -\IntCalc@Temp 63{% +\InCa@Temp 63{% \or 7% 1 \or 8% 2 \or 9% 3 @@ -757,7 +824,7 @@ \or 4% 8 \or 5% 9 }% -\IntCalc@Temp 72{% +\InCa@Temp 72{% \or 8% 1 \or 9% 2 \or 0% 3 @@ -768,7 +835,7 @@ \or 5% 8 \or 6% 9 }% -\IntCalc@Temp 81{% +\InCa@Temp 81{% \or 9% 1 \or 0% 2 \or 1% 3 @@ -779,7 +846,7 @@ \or 6% 8 \or 7% 9 }% -\IntCalc@Temp 90{% +\InCa@Temp 90{% \or 0% 1 \or 1% 2 \or 2% 3 @@ -790,8 +857,8 @@ \or 7% 8 \or 8% 9 }% -\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 @@ -803,7 +870,7 @@ \fi }% } -\IntCalc@Temp 0{% +\InCa@Temp 0{% \or 9% 1 \or 8% 2 \or 7% 3 @@ -814,7 +881,7 @@ \or 2% 8 \or 1% 9 } -\IntCalc@Temp 1{% +\InCa@Temp 1{% \or 0% 1 \or 9% 2 \or 8% 3 @@ -825,7 +892,7 @@ \or 3% 8 \or 2% 9 } -\IntCalc@Temp 2{% +\InCa@Temp 2{% \or 1% 1 \or 0% 2 \or 9% 3 @@ -836,7 +903,7 @@ \or 4% 8 \or 3% 9 } -\IntCalc@Temp 3{% +\InCa@Temp 3{% \or 2% 1 \or 1% 2 \or 0% 3 @@ -847,7 +914,7 @@ \or 5% 8 \or 4% 9 } -\IntCalc@Temp 4{% +\InCa@Temp 4{% \or 3% 1 \or 2% 2 \or 1% 3 @@ -858,7 +925,7 @@ \or 6% 8 \or 5% 9 } -\IntCalc@Temp 5{% +\InCa@Temp 5{% \or 4% 1 \or 3% 2 \or 2% 3 @@ -869,7 +936,7 @@ \or 7% 8 \or 6% 9 } -\IntCalc@Temp 6{% +\InCa@Temp 6{% \or 5% 1 \or 4% 2 \or 3% 3 @@ -880,7 +947,7 @@ \or 8% 8 \or 7% 9 } -\IntCalc@Temp 7{% +\InCa@Temp 7{% \or 6% 1 \or 5% 2 \or 4% 3 @@ -891,7 +958,7 @@ \or 9% 8 \or 8% 9 } -\IntCalc@Temp 8{% +\InCa@Temp 8{% \or 7% 1 \or 6% 2 \or 5% 3 @@ -902,7 +969,7 @@ \or 0% 8 \or 9% 9 } -\IntCalc@Temp 9{% +\InCa@Temp 9{% \or 8% 1 \or 7% 2 \or 6% 3 @@ -914,31 +981,37 @@ \or 0% 9 } \def\intcalcShl#1{% - \number\expandafter\IntCalc@ShlSwitch\number#1! % + \number\expandafter\InCa@ShlSwitch\number#1! % } -\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 } -\def\IntCalc@Shl#1#2{% +\def\IntCalcShl#1!{% + \number + \csname InCa@Empty% + \InCa@Shl#1! % +} +\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 } -\expandafter\def\csname IntCalc@ShlDigit0\endcsname{% +\expandafter\def\csname InCa@ShlDigit0\endcsname{% \endcsname0% } -\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% @@ -947,41 +1020,44 @@ \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 \def\intcalcShr#1{% - \number\expandafter\IntCalc@ShrSwitch\number#1! % + \number\expandafter\InCa@ShrSwitch\number#1! % } -\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 } -\def\IntCalc@Shr#1#2{% - \IntCalc@ShrDigit#1!% +\def\IntCalcShr#1!{% + \number\InCa@Shr#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 } -\def\IntCalc@ShrDigit#1!{% +\def\InCa@ShrDigit#1!{% \ifcase#1 0% 0 \or 0% 1 \or 1% 2 @@ -1004,57 +1080,60 @@ \or 9% 19 \fi } -\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% + }% } -\def\IntCalc@ProcessTim#1#2#3{% +\InCa@Temp{ } +\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 } -\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% -\expandafter\def\csname IntCalc@TimDigit0\endcsname#1#2{% +\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% +\expandafter\def\csname InCa@TimDigit0\endcsname#1#2{% \endcsname 0#2% } -\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 } -\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% @@ -1062,7 +1141,7 @@ !% }% } -\IntCalc@Temp 2{% +\InCa@Temp 2{% \or 2% 1 \or 4% 2 \or 6% 3 @@ -1073,7 +1152,7 @@ \or 16% 8 \or 18% 9 } -\IntCalc@Temp 3{% +\InCa@Temp 3{% \or 3% 1 \or 6% 2 \or 9% 3 @@ -1084,7 +1163,7 @@ \or 24% 8 \or 27% 9 } -\IntCalc@Temp 4{% +\InCa@Temp 4{% \or 4% 1 \or 8% 2 \or 12% 3 @@ -1095,7 +1174,7 @@ \or 32% 8 \or 36% 9 } -\IntCalc@Temp 5{% +\InCa@Temp 5{% \or 5% 1 \or 10% 2 \or 15% 3 @@ -1106,7 +1185,7 @@ \or 40% 8 \or 45% 9 } -\IntCalc@Temp 6{% +\InCa@Temp 6{% \or 6% 1 \or 12% 2 \or 18% 3 @@ -1117,7 +1196,7 @@ \or 48% 8 \or 54% 9 } -\IntCalc@Temp 7{% +\InCa@Temp 7{% \or 7% 1 \or 14% 2 \or 21% 3 @@ -1128,7 +1207,7 @@ \or 56% 8 \or 63% 9 } -\IntCalc@Temp 8{% +\InCa@Temp 8{% \or 8% 1 \or 16% 2 \or 24% 3 @@ -1139,7 +1218,7 @@ \or 64% 8 \or 72% 9 } -\IntCalc@Temp 9{% +\InCa@Temp 9{% \or 9% 1 \or 18% 2 \or 27% 3 @@ -1150,126 +1229,128 @@ \or 72% 8 \or 81% 9 } -\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 } -\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% } \def\intcalcMul#1#2{% \number - \expandafter\IntCalc@MulSwitch + \expandafter\InCa@MulSwitch \number\number#1\expandafter!% - \number#2!% - \IntCalc@Space + \number#2! % } -\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 } -\def\IntCalc@Mul#1!#2!{% +\def\IntCalcMul#1!#2!{% + \number\InCa@Mul#1!#2! % +} +\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 } -\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 } \def\intcalcSqr#1{% - \number\expandafter\IntCalc@Sqr\number#1! % + \number\expandafter\InCa@Sqr\number#1! % } -\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 } \def\intcalcFac#1{% - \number\expandafter\IntCalc@Fac\number#1! % + \number\expandafter\InCa@Fac\number#1! % } \def\intcalcPow#1#2{% - \number\expandafter\IntCalc@Pow + \number\expandafter\InCa@Pow \number\number#1\expandafter!% \number#2! % } -\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 @@ -1293,32 +1374,32 @@ \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 \fi \fi } -\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% @@ -1327,52 +1408,68 @@ \fi } \def\intcalcDiv#1#2{% - \number\expandafter\IntCalc@Div + \number\expandafter\InCa@Div \number\number#1\expandafter!% \number#2! % } -\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 \fi } -\def\IntCalc@DivSwitch#1!#2!{% +\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{ }% +\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 } -\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 % @@ -1382,55 +1479,55 @@ \fi \fi } -\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 } -\def\IntCalc@DivStartI#1!#2!{% - \expandafter\IntCalc@DivStartII +\def\InCa@DivStartI#1!#2!{% + \expandafter\InCa@DivStartII \number#2\expandafter\expandafter\expandafter!% \intcalcShl{#2}!% #1!% } -\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}!% } -\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}!% } -\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!/% } -\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 @@ -1438,14 +1535,14 @@ \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 @@ -1453,14 +1550,14 @@ \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 @@ -1469,19 +1566,19 @@ \fi \fi \ifx#2=% - \expandafter\IntCalc@Gobble + \expandafter\@gobble \fi /% } -\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 }% @@ -1489,11 +1586,11 @@ #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!% }% @@ -1501,19 +1598,19 @@ }% \fi } -\def\IntCalc@CleanupIV#1!#2!#3!#4!{} +\def\InCa@CleanupIV#1!#2!#3!#4!{} \def\intcalcMod#1#2{% - \number\expandafter\IntCalc@Mod + \number\expandafter\InCa@Mod \number\number#1\expandafter!% \number#2! % } -\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 @@ -1525,43 +1622,66 @@ \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 \fi \fi } -\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{ }% +\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 } -\def\IntCalc@Empty{} -\def\IntCalc@Gobble#1{} +\def\InCa@Empty{} +\expandafter\ifx\csname @gobble\endcsname\relax + \long\def\@gobble#1{}% +\fi \long\def\@ReturnAfterFi#1\fi{\fi#1}% \long\def\@ReturnAfterElseFi#1\else#2\fi{\fi#1}% -\IntCalc@AtEnd +\InCa@AtEnd \endinput |