| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% File: intcalc.dtx |
| 4 |
% Version: 2019/12/15 v1.3 |
| 5 |
% Info: Expandable calculations with integers |
| 6 |
% |
| 7 |
% Copyright (C) |
| 8 |
% 2007 Heiko Oberdiek |
| 9 |
% 2016-2019 Oberdiek Package Support Group |
| 10 |
% https://github.com/ho-tex/intcalc/issues |
| 11 |
% |
| 12 |
% This work may be distributed and/or modified under the |
| 13 |
% conditions of the LaTeX Project Public License, either |
| 14 |
% version 1.3c of this license or (at your option) any later |
| 15 |
% version. This version of this license is in |
| 16 |
% https://www.latex-project.org/lppl/lppl-1-3c.txt |
| 17 |
% and the latest version of this license is in |
| 18 |
% https://www.latex-project.org/lppl.txt |
| 19 |
% and version 1.3 or later is part of all distributions of |
| 20 |
% LaTeX version 2005/12/01 or later. |
| 21 |
% |
| 22 |
% This work has the LPPL maintenance status "maintained". |
| 23 |
% |
| 24 |
% The Current Maintainers of this work are |
| 25 |
% Heiko Oberdiek and the Oberdiek Package Support Group |
| 26 |
% https://github.com/ho-tex/intcalc/issues |
| 27 |
% |
| 28 |
% The Base Interpreter refers to any `TeX-Format', |
| 29 |
% because some files are installed in TDS:tex/generic//. |
| 30 |
% |
| 31 |
% This work consists of the main source file intcalc.dtx |
| 32 |
% and the derived files |
| 33 |
% intcalc.sty, intcalc.pdf, intcalc.ins, intcalc.drv, |
| 34 |
% intcalc-test1.tex, intcalc-test2.tex, intcalc-test3.tex, |
| 35 |
% intcalc-test4.tex. |
| 36 |
% |
| 37 |
% Distribution: |
| 38 |
% CTAN:macros/latex/contrib/intcalc/intcalc.dtx |
| 39 |
% CTAN:macros/latex/contrib/intcalc/intcalc.pdf |
| 40 |
% |
| 41 |
% Unpacking: |
| 42 |
% (a) If intcalc.ins is present: |
| 43 |
% tex intcalc.ins |
| 44 |
% (b) Without intcalc.ins: |
| 45 |
% tex intcalc.dtx |
| 46 |
% (c) If you insist on using LaTeX |
| 47 |
% latex \let\install=y\input{intcalc.dtx} |
| 48 |
% (quote the arguments according to the demands of your shell) |
| 49 |
% |
| 50 |
% Documentation: |
| 51 |
% (a) If intcalc.drv is present: |
| 52 |
% latex intcalc.drv |
| 53 |
% (b) Without intcalc.drv: |
| 54 |
% latex intcalc.dtx; ... |
| 55 |
% The class ltxdoc loads the configuration file ltxdoc.cfg |
| 56 |
% if available. Here you can specify further options, e.g. |
| 57 |
% use A4 as paper format: |
| 58 |
% \PassOptionsToClass{a4paper}{article} |
| 59 |
% |
| 60 |
% Programm calls to get the documentation (example): |
| 61 |
% pdflatex intcalc.dtx |
| 62 |
% makeindex -s gind.ist intcalc.idx |
| 63 |
% pdflatex intcalc.dtx |
| 64 |
% makeindex -s gind.ist intcalc.idx |
| 65 |
% pdflatex intcalc.dtx |
| 66 |
% |
| 67 |
% Installation: |
| 68 |
% TDS:tex/generic/intcalc/intcalc.sty |
| 69 |
% TDS:doc/latex/intcalc/intcalc.pdf |
| 70 |
% TDS:source/latex/intcalc/intcalc.dtx |
| 71 |
% |
| 72 |
%<*ignore> |
| 73 |
\begingroup |
| 74 |
\catcode123=1 % |
| 75 |
\catcode125=2 % |
| 76 |
\def\x{LaTeX2e}% |
| 77 |
\expandafter\endgroup |
| 78 |
\ifcase 0\ifx\install y1\fi\expandafter |
| 79 |
\ifx\csname processbatchFile\endcsname\relax\else1\fi |
| 80 |
\ifx\fmtname\x\else 1\fi\relax |
| 81 |
\else\csname fi\endcsname |
| 82 |
%</ignore> |
| 83 |
%<*install> |
| 84 |
\input docstrip.tex |
| 85 |
\Msg{************************************************************************} |
| 86 |
\Msg{* Installation} |
| 87 |
\Msg{* Package: intcalc 2019/12/15 v1.3 Expandable calculations with integers (HO)} |
| 88 |
\Msg{************************************************************************} |
| 89 |
|
| 90 |
\keepsilent |
| 91 |
\askforoverwritefalse |
| 92 |
|
| 93 |
\let\MetaPrefix\relax |
| 94 |
\preamble |
| 95 |
|
| 96 |
This is a generated file. |
| 97 |
|
| 98 |
Project: intcalc |
| 99 |
Version: 2019/12/15 v1.3 |
| 100 |
|
| 101 |
Copyright (C) |
| 102 |
2007 Heiko Oberdiek |
| 103 |
2016-2019 Oberdiek Package Support Group |
| 104 |
|
| 105 |
This work may be distributed and/or modified under the |
| 106 |
conditions of the LaTeX Project Public License, either |
| 107 |
version 1.3c of this license or (at your option) any later |
| 108 |
version. This version of this license is in |
| 109 |
https://www.latex-project.org/lppl/lppl-1-3c.txt |
| 110 |
and the latest version of this license is in |
| 111 |
https://www.latex-project.org/lppl.txt |
| 112 |
and version 1.3 or later is part of all distributions of |
| 113 |
LaTeX version 2005/12/01 or later. |
| 114 |
|
| 115 |
This work has the LPPL maintenance status "maintained". |
| 116 |
|
| 117 |
The Current Maintainers of this work are |
| 118 |
Heiko Oberdiek and the Oberdiek Package Support Group |
| 119 |
https://github.com/ho-tex/intcalc/issues |
| 120 |
|
| 121 |
|
| 122 |
The Base Interpreter refers to any `TeX-Format', |
| 123 |
because some files are installed in TDS:tex/generic//. |
| 124 |
|
| 125 |
This work consists of the main source file intcalc.dtx |
| 126 |
and the derived files |
| 127 |
intcalc.sty, intcalc.pdf, intcalc.ins, intcalc.drv, |
| 128 |
intcalc-test1.tex, intcalc-test2.tex, intcalc-test3.tex, |
| 129 |
intcalc-test4.tex. |
| 130 |
|
| 131 |
\endpreamble |
| 132 |
\let\MetaPrefix\DoubleperCent |
| 133 |
|
| 134 |
\generate{% |
| 135 |
\file{intcalc.ins}{\from{intcalc.dtx}{install}}% |
| 136 |
\file{intcalc.drv}{\from{intcalc.dtx}{driver}}% |
| 137 |
\usedir{tex/generic/intcalc}% |
| 138 |
\file{intcalc.sty}{\from{intcalc.dtx}{package}}% |
| 139 |
} |
| 140 |
|
| 141 |
\catcode32=13\relax% active space |
| 142 |
\let =\space% |
| 143 |
\Msg{************************************************************************} |
| 144 |
\Msg{*} |
| 145 |
\Msg{* To finish the installation you have to move the following} |
| 146 |
\Msg{* file into a directory searched by TeX:} |
| 147 |
\Msg{*} |
| 148 |
\Msg{* intcalc.sty} |
| 149 |
\Msg{*} |
| 150 |
\Msg{* To produce the documentation run the file `intcalc.drv'} |
| 151 |
\Msg{* through LaTeX.} |
| 152 |
\Msg{*} |
| 153 |
\Msg{* Happy TeXing!} |
| 154 |
\Msg{*} |
| 155 |
\Msg{************************************************************************} |
| 156 |
|
| 157 |
\endbatchfile |
| 158 |
%</install> |
| 159 |
%<*ignore> |
| 160 |
\fi |
| 161 |
%</ignore> |
| 162 |
%<*driver> |
| 163 |
\NeedsTeXFormat{LaTeX2e} |
| 164 |
\ProvidesFile{intcalc.drv}% |
| 165 |
[2019/12/15 v1.3 Expandable calculations with integers (HO)]% |
| 166 |
\documentclass{ltxdoc} |
| 167 |
\usepackage{wasysym} |
| 168 |
\let\iint\relax |
| 169 |
\let\iiint\relax |
| 170 |
\usepackage[fleqn]{amsmath} |
| 171 |
|
| 172 |
\DeclareMathOperator{\opInv}{Inv} |
| 173 |
\DeclareMathOperator{\opAbs}{Abs} |
| 174 |
\DeclareMathOperator{\opSgn}{Sgn} |
| 175 |
\DeclareMathOperator{\opMin}{Min} |
| 176 |
\DeclareMathOperator{\opMax}{Max} |
| 177 |
\DeclareMathOperator{\opCmp}{Cmp} |
| 178 |
\DeclareMathOperator{\opInc}{Inc} |
| 179 |
\DeclareMathOperator{\opDec}{Dec} |
| 180 |
\DeclareMathOperator{\opAdd}{Add} |
| 181 |
\DeclareMathOperator{\opSub}{Sub} |
| 182 |
\DeclareMathOperator{\opShl}{Shl} |
| 183 |
\DeclareMathOperator{\opShr}{Shr} |
| 184 |
\DeclareMathOperator{\opMul}{Mul} |
| 185 |
\DeclareMathOperator{\opSqr}{Sqr} |
| 186 |
\DeclareMathOperator{\opFac}{Fac} |
| 187 |
\DeclareMathOperator{\opPow}{Pow} |
| 188 |
\DeclareMathOperator{\opDiv}{Div} |
| 189 |
\DeclareMathOperator{\opMod}{Mod} |
| 190 |
\DeclareMathOperator{\opInt}{Int} |
| 191 |
\DeclareMathOperator{\opOdd}{ifodd} |
| 192 |
|
| 193 |
\newcommand*{\Def}{% |
| 194 |
\ensuremath{% |
| 195 |
\mathrel{\mathop{:}}=% |
| 196 |
}% |
| 197 |
} |
| 198 |
\newcommand*{\op}[1]{% |
| 199 |
\textsf{#1}% |
| 200 |
} |
| 201 |
\usepackage{holtxdoc}[2011/11/22] |
| 202 |
\begin{document} |
| 203 |
\DocInput{intcalc.dtx}% |
| 204 |
\end{document} |
| 205 |
%</driver> |
| 206 |
% \fi |
| 207 |
% |
| 208 |
% |
| 209 |
% |
| 210 |
% \GetFileInfo{intcalc.drv} |
| 211 |
% |
| 212 |
% \title{The \xpackage{intcalc} package} |
| 213 |
% \date{2019/12/15 v1.3} |
| 214 |
% \author{Heiko Oberdiek\thanks |
| 215 |
% {Please report any issues at \url{https://github.com/ho-tex/intcalc/issues}}} |
| 216 |
% |
| 217 |
% \maketitle |
| 218 |
% |
| 219 |
% \begin{abstract} |
| 220 |
% This package provides expandable arithmetic operations |
| 221 |
% with integers. |
| 222 |
% \end{abstract} |
| 223 |
% |
| 224 |
% \tableofcontents |
| 225 |
% |
| 226 |
% \section{Documentation} |
| 227 |
% |
| 228 |
% \subsection{Introduction} |
| 229 |
% |
| 230 |
% Package \xpackage{intcalc} defines arithmetic operations |
| 231 |
% that deal with integers. Integers mean numbers in \TeX. |
| 232 |
% The same restrictions apply, the range is limited to |
| 233 |
% [-2147483647, 2147483647]. |
| 234 |
% |
| 235 |
% The operations have the form of macros that take one or |
| 236 |
% two integers as parameter and return the integer result. |
| 237 |
% The macro name is a three letter operation name prefixed |
| 238 |
% by the package name, e.g. \cs{intcalcAdd}|{10}{43}| returns |
| 239 |
% |53|. |
| 240 |
% |
| 241 |
% The macros are fully expandable, exactly two expansion |
| 242 |
% steps generate the result. Therefore the operations |
| 243 |
% may be used nearly everywhere in \TeX, even inside |
| 244 |
% \cs{number}, \cs{csname}, file names, or other |
| 245 |
% expandable contexts. |
| 246 |
% |
| 247 |
% The package contains two implementations of the operations. |
| 248 |
% If \eTeX\ is detected then the macros are implemented |
| 249 |
% using its features (\cs{numexpr}). Otherwise the slower |
| 250 |
% implementation without \eTeX's help is choosen. |
| 251 |
% |
| 252 |
% \subsection{Conditions} |
| 253 |
% |
| 254 |
% \subsubsection{Preconditions} |
| 255 |
% |
| 256 |
% \begin{itemize} |
| 257 |
% \item |
| 258 |
% Arguments can be anything that \TeX\ interprets as ``number''. |
| 259 |
% Examples: plain numbers, count or length register, macros |
| 260 |
% that expands to a number. |
| 261 |
% \item |
| 262 |
% The arguments are limited to the range |
| 263 |
% -2147483647 until 2147483647. These numbers belong to the range. |
| 264 |
% Note that some operations |
| 265 |
% have additionals restrictions to the range. |
| 266 |
% \item |
| 267 |
% The argument may be expressions that \cs{numexpr} |
| 268 |
% understands if \eTeX\ is available. |
| 269 |
% \item |
| 270 |
% The resulting number must fit in the allowed range. |
| 271 |
% \end{itemize} |
| 272 |
% |
| 273 |
% \subsubsection{Postconditions} |
| 274 |
% |
| 275 |
% Additional properties of the macros apart from calculating |
| 276 |
% a correct result (of course \smiley): |
| 277 |
% \begin{itemize} |
| 278 |
% \item |
| 279 |
% The macros are fully expandable. Thus they can |
| 280 |
% be used inside \cs{edef}, \cs{csname}, after \cs{number}, |
| 281 |
% for example. |
| 282 |
% \item |
| 283 |
% Furthermore exactly two expansion steps calculate the result. |
| 284 |
% \item |
| 285 |
% The number consists of one optional minus sign and one to |
| 286 |
% ten digits. The first digit is larger than zero for |
| 287 |
% numbers that consists of more than one digit. |
| 288 |
% |
| 289 |
% In short, the number format is exactly the same as |
| 290 |
% \cs{number} generates. And the tokens (minus sign, digits) |
| 291 |
% have catcode 12 (other). |
| 292 |
% \item |
| 293 |
% Call by value is simulated. First the arguments are |
| 294 |
% converted to numbers. Then these numbers are used |
| 295 |
% in the calculations. |
| 296 |
% |
| 297 |
% Remember that arguments |
| 298 |
% may contain expensive macros or \eTeX\ expressions. |
| 299 |
% This strategy avoids multiple evaluations of such |
| 300 |
% arguments. |
| 301 |
% \end{itemize} |
| 302 |
% |
| 303 |
% \subsection{Error handling} |
| 304 |
% |
| 305 |
% There are two kinds of errors if a precondition is violated: |
| 306 |
% Some errors are detected by the macros, example: division by zero. |
| 307 |
% In this cases an undefined control sequence is called and causes |
| 308 |
% a TeX error message, example: \cs{IntCalcError:DivisionByZero}. |
| 309 |
% The name of the control sequence contains |
| 310 |
% the reason for the error. The \TeX\ error may be ignored. |
| 311 |
% Then the operation returns zero as result. |
| 312 |
% Because the macros are supposed to work in expandible contexts. |
| 313 |
% An traditional error message, however, is not expandable and |
| 314 |
% would break these contexts. |
| 315 |
% |
| 316 |
% If a number exceeds the range of -2147483647 until 2147483647, then |
| 317 |
% \TeX\ throws an error ``Number too big'' and recovers by |
| 318 |
% using biggest allowed value. |
| 319 |
% Example for the negative number -3000000000 is replaced |
| 320 |
% by -2147483647. |
| 321 |
% |
| 322 |
% \subsection{Operations} |
| 323 |
% |
| 324 |
% Some definition equations below use the function $\opInt$ |
| 325 |
% that converts a real number to an integer. The number |
| 326 |
% is truncated that means rounding to zero: |
| 327 |
% \begin{gather*} |
| 328 |
% \opInt(x) \Def |
| 329 |
% \begin{cases} |
| 330 |
% \lfloor x\rfloor & \text{if $x\geq0$}\\ |
| 331 |
% \lceil x\rceil & \text{otherwise} |
| 332 |
% \end{cases} |
| 333 |
% \end{gather*} |
| 334 |
% |
| 335 |
% \subsubsection{\op{Num}} |
| 336 |
% |
| 337 |
% \begin{declcs}{intcalcNum} \M{x} |
| 338 |
% \end{declcs} |
| 339 |
% Macro \cs{intcalcNum} converts its argument to a normalized integer |
| 340 |
% number without unnecessary leading zeros or signs. |
| 341 |
% The result matches the regular expression: |
| 342 |
%\begin{quote} |
| 343 |
%\begin{verbatim} |
| 344 |
%0|-?[1-9][0-9]* |
| 345 |
%\end{verbatim} |
| 346 |
%\end{quote} |
| 347 |
% |
| 348 |
% \subsubsection{\op{Inv}, \op{Abs}, \op{Sgn}} |
| 349 |
% |
| 350 |
% \begin{declcs}{intcalcInv} \M{x} |
| 351 |
% \end{declcs} |
| 352 |
% Macro \cs{intcalcInv} switches the sign. |
| 353 |
% \begin{gather*} |
| 354 |
% \opInv(x) \Def -x |
| 355 |
% \end{gather*} |
| 356 |
% |
| 357 |
% \begin{declcs}{intcalcAbs} \M{x} |
| 358 |
% \end{declcs} |
| 359 |
% Macro \cs{intcalcAbs} returns the absolute value |
| 360 |
% of integer \meta{x}. |
| 361 |
% \begin{gather*} |
| 362 |
% \opAbs(x) \Def \vert x\vert |
| 363 |
% \end{gather*} |
| 364 |
% |
| 365 |
% \begin{declcs}{intcalcSgn} \M{x} |
| 366 |
% \end{declcs} |
| 367 |
% Macro \cs{intcalcSgn} encodes the sign of \meta{x} as number. |
| 368 |
% \begin{gather*} |
| 369 |
% \opSgn(x) \Def |
| 370 |
% \begin{cases} |
| 371 |
% -1& \text{if $x<0$}\\ |
| 372 |
% 0& \text{if $x=0$}\\ |
| 373 |
% 1& \text{if $x>0$} |
| 374 |
% \end{cases} |
| 375 |
% \end{gather*} |
| 376 |
% These return values can easily be distinguished by \cs{ifcase}: |
| 377 |
%\begin{quote} |
| 378 |
%\begin{verbatim} |
| 379 |
%\ifcase\intcalcSgn{<x>} |
| 380 |
% $x=0$ |
| 381 |
%\or |
| 382 |
% $x>0$ |
| 383 |
%\else |
| 384 |
% $x<0$ |
| 385 |
%\fi |
| 386 |
%\end{verbatim} |
| 387 |
%\end{quote} |
| 388 |
% |
| 389 |
% \subsubsection{\op{Min}, \op{Max}, \op{Cmp}} |
| 390 |
% |
| 391 |
% \begin{declcs}{intcalcMin} \M{x} \M{y} |
| 392 |
% \end{declcs} |
| 393 |
% Macro \cs{intcalcMin} returns the smaller of the two integers. |
| 394 |
% \begin{gather*} |
| 395 |
% \opMin(x,y) \Def |
| 396 |
% \begin{cases} |
| 397 |
% x & \text{if $x<y$}\\ |
| 398 |
% y & \text{otherwise} |
| 399 |
% \end{cases} |
| 400 |
% \end{gather*} |
| 401 |
% |
| 402 |
% \begin{declcs}{intcalcMax} \M{x} \M{y} |
| 403 |
% \end{declcs} |
| 404 |
% Macro \cs{intcalcMax} returns the larger of the two integers. |
| 405 |
% \begin{gather*} |
| 406 |
% \opMax(x,y) \Def |
| 407 |
% \begin{cases} |
| 408 |
% x & \text{if $x>y$}\\ |
| 409 |
% y & \text{otherwise} |
| 410 |
% \end{cases} |
| 411 |
% \end{gather*} |
| 412 |
% |
| 413 |
% \begin{declcs}{intcalcCmp} \M{x} \M{y} |
| 414 |
% \end{declcs} |
| 415 |
% Macro \cs{intcalcCmp} encodes the comparison result as number: |
| 416 |
% \begin{gather*} |
| 417 |
% \opCmp(x,y) \Def |
| 418 |
% \begin{cases} |
| 419 |
% -1 & \text{if $x<y$}\\ |
| 420 |
% 0 & \text{if $x=y$}\\ |
| 421 |
% 1 & \text{if $x>y$} |
| 422 |
% \end{cases} |
| 423 |
% \end{gather*} |
| 424 |
% These values can be distinguished by \cs{ifcase}: |
| 425 |
%\begin{quote} |
| 426 |
%\begin{verbatim} |
| 427 |
%\ifcase\intcalcCmp{<x>}{<y>} |
| 428 |
% $x=y$ |
| 429 |
%\or |
| 430 |
% $x>y$ |
| 431 |
%\else |
| 432 |
% $x<y$ |
| 433 |
%\fi |
| 434 |
%\end{verbatim} |
| 435 |
%\end{quote} |
| 436 |
% |
| 437 |
% \subsubsection{\op{Inc}, \op{Dec}, \op{Add}, \op{Sub}} |
| 438 |
% |
| 439 |
% \begin{declcs}{intcalcInc} \M{x} |
| 440 |
% \end{declcs} |
| 441 |
% Macro \cs{intcalcInc} increments \meta{x} by one. |
| 442 |
% \begin{gather*} |
| 443 |
% \opInc(x) \Def x + 1 |
| 444 |
% \end{gather*} |
| 445 |
% |
| 446 |
% \begin{declcs}{intcalcDec} \M{x} |
| 447 |
% \end{declcs} |
| 448 |
% Macro \cs{intcalcDec} decrements \meta{x} by one. |
| 449 |
% \begin{gather*} |
| 450 |
% \opDec(x) \Def x - 1 |
| 451 |
% \end{gather*} |
| 452 |
% |
| 453 |
% \begin{declcs}{intcalcAdd} \M{x} \M{y} |
| 454 |
% \end{declcs} |
| 455 |
% Macro \cs{intcalcAdd} adds the two numbers. |
| 456 |
% \begin{gather*} |
| 457 |
% \opAdd(x, y) \Def x + y |
| 458 |
% \end{gather*} |
| 459 |
% |
| 460 |
% \begin{declcs}{intcalcSub} \M{x} \M{y} |
| 461 |
% \end{declcs} |
| 462 |
% Macro \cs{intcalcSub} calculates the difference. |
| 463 |
% \begin{gather*} |
| 464 |
% \opSub(x, y) \Def x - y |
| 465 |
% \end{gather*} |
| 466 |
% |
| 467 |
% \subsubsection{\op{Shl}, \op{Shr}} |
| 468 |
% |
| 469 |
% \begin{declcs}{intcalcShl} \M{x} |
| 470 |
% \end{declcs} |
| 471 |
% Macro \cs{intcalcShl} implements shifting to the left that |
| 472 |
% means the number is multiplied by two. Overflow is possible. |
| 473 |
% The sign is preserved. |
| 474 |
% \begin{gather*} |
| 475 |
% \opShl(x) \Def x*2 |
| 476 |
% \end{gather*} |
| 477 |
% |
| 478 |
% \begin{declcs}{intcalcShr} \M{x} |
| 479 |
% \end{declcs} |
| 480 |
% Macro \cs{intcalcShr} implements shifting to the right. |
| 481 |
% That is equivalent to an integer division by two. |
| 482 |
% The sign is preserved. |
| 483 |
% \begin{gather*} |
| 484 |
% \opShr(x) \Def \opInt(x/2) |
| 485 |
% \end{gather*} |
| 486 |
% |
| 487 |
% \subsubsection{\op{Mul}, \op{Sqr}, \op{Fac}, \op{Pow}} |
| 488 |
% |
| 489 |
% \begin{declcs}{intcalcMul} \M{x} \M{y} |
| 490 |
% \end{declcs} |
| 491 |
% Macro \cs{intcalcMul} calculates the product of |
| 492 |
% \meta{x} and \meta{y}. |
| 493 |
% \begin{gather*} |
| 494 |
% \opMul(x,y) \Def x*y |
| 495 |
% \end{gather*} |
| 496 |
% |
| 497 |
% \begin{declcs}{intcalcSqr} \M{x} |
| 498 |
% \end{declcs} |
| 499 |
% Macro \cs{intcalcSqr} returns the square product. |
| 500 |
% \begin{gather*} |
| 501 |
% \opSqr(x) \Def x^2 |
| 502 |
% \end{gather*} |
| 503 |
% |
| 504 |
% \begin{declcs}{intcalcFac} \M{x} |
| 505 |
% \end{declcs} |
| 506 |
% Macro \cs{intcalcFac} returns the factorial of \meta{x}. |
| 507 |
% Negative numbers are not permitted. |
| 508 |
% \begin{gather*} |
| 509 |
% \opFac(x) \Def x!\qquad\text{for $x\geq0$} |
| 510 |
% \end{gather*} |
| 511 |
% ($0! = 1$) |
| 512 |
% |
| 513 |
% \begin{declcs}{intcalcPow} \M{x} \M{y} |
| 514 |
% \end{declcs} |
| 515 |
% Macro \cs{intcalcPow} calculates the value of \meta{x} to the |
| 516 |
% power of \meta{y}. The error ``division by zero'' is thrown |
| 517 |
% if \meta{x} is zero and \meta{y} is negative. |
| 518 |
% permitted: |
| 519 |
% \begin{gather*} |
| 520 |
% \opPow(x,y) \Def |
| 521 |
% \opInt(x^y)\qquad\text{for $x\neq0$ or $y\geq0$} |
| 522 |
% \end{gather*} |
| 523 |
% ($0^0 = 1$) |
| 524 |
% |
| 525 |
% \subsubsection{\op{Div}, \op{Mod}} |
| 526 |
% |
| 527 |
% \begin{declcs}{intcalcDiv} \M{x} \M{y} |
| 528 |
% \end{declcs} |
| 529 |
% Macro \cs{intcalcDiv} performs an integer division. |
| 530 |
% Argument \meta{y} must not be zero. |
| 531 |
% \begin{gather*} |
| 532 |
% \opDiv(x,y) \Def \opInt(x/y)\qquad\text{for $y\neq0$} |
| 533 |
% \end{gather*} |
| 534 |
% |
| 535 |
% \begin{declcs}{intcalcMod} \M{x} \M{y} |
| 536 |
% \end{declcs} |
| 537 |
% Macro \cs{intcalcMod} gets the remainder of the integer |
| 538 |
% division. The sign follows the divisor \meta{y}. |
| 539 |
% Argument \meta{y} must not be zero. |
| 540 |
% \begin{gather*} |
| 541 |
% \opMod(x,y) \Def x\mathrel{\%}y\qquad\text{for $y\neq0$} |
| 542 |
% \end{gather*} |
| 543 |
% The result ranges: |
| 544 |
% \begin{gather*} |
| 545 |
% -\vert y\vert < \opMod(x,y) \leq 0\qquad\text{for $y<0$}\\ |
| 546 |
% 0 \leq \opMod(x,y) < y\qquad\text{for $y\geq0$} |
| 547 |
% \end{gather*} |
| 548 |
% |
| 549 |
% \subsection{Interface for programmer} |
| 550 |
% |
| 551 |
% If the programmer can ensure some more properties about |
| 552 |
% the arguments of the operations, then the following |
| 553 |
% macros are a little more efficient. |
| 554 |
% |
| 555 |
% In general numbers must obey the following constraints: |
| 556 |
% \begin{itemize} |
| 557 |
% \item Plain number: digit tokens only, no command tokens. |
| 558 |
% \item Non-negative. Signs are forbidden. |
| 559 |
% \item Arguments and the result must fit in range |0..2147483647|. |
| 560 |
% \item Delimited by exclamation mark. Curly braces |
| 561 |
% around the number are not allowed and will |
| 562 |
% break the code. |
| 563 |
% \end{itemize} |
| 564 |
% |
| 565 |
% \begin{declcs}{IntCalcInc} \meta{number} |!| |
| 566 |
% \end{declcs} |
| 567 |
% Incrementation, range: |0..2147483646|. |
| 568 |
% |
| 569 |
% \begin{declcs}{IntCalcDec} \meta{number} |!| |
| 570 |
% \end{declcs} |
| 571 |
% Decrementation, range: |1..2147483647|. |
| 572 |
% |
| 573 |
% \begin{declcs}{IntCalcAdd} \meta{number A} |!| \meta{number B} |!| |
| 574 |
% \end{declcs} |
| 575 |
% Addition, $A\geq B$. |
| 576 |
% |
| 577 |
% \begin{declcs}{IntCalcSub} \meta{number A} |!| \meta{number B} |!| |
| 578 |
% \end{declcs} |
| 579 |
% Subtraction, $A\geq B$. |
| 580 |
% |
| 581 |
% \begin{declcs}{IntCalcShl} \meta{number} |!| |
| 582 |
% \end{declcs} |
| 583 |
% Left shift (multiplication with two), range: |0..1073741823|. |
| 584 |
% |
| 585 |
% \begin{declcs}{IntCalcShr} \meta{number} |!| |
| 586 |
% \end{declcs} |
| 587 |
% Right shift (integer division by two). |
| 588 |
% |
| 589 |
% \begin{declcs}{IntCalcMul} \meta{number A} |!| \meta{number B} |!| |
| 590 |
% \end{declcs} |
| 591 |
% Multiplication, $A\geq B$. |
| 592 |
% |
| 593 |
% \begin{declcs}{IntCalcDiv} \meta{number A} |!| \meta{number B} |!| |
| 594 |
% \end{declcs} |
| 595 |
% Division operation. |
| 596 |
% |
| 597 |
% \begin{declcs}{IntCalcMod} \meta{number A} |!| \meta{number B} |!| |
| 598 |
% \end{declcs} |
| 599 |
% Modulo operation. |
| 600 |
% |
| 601 |
% |
| 602 |
% \StopEventually{ |
| 603 |
% } |
| 604 |
% |
| 605 |
% \section{Implementation} |
| 606 |
% |
| 607 |
% \begin{macrocode} |
| 608 |
%<*package> |
| 609 |
% \end{macrocode} |
| 610 |
% |
| 611 |
% \subsection{Reload check and package identification} |
| 612 |
% Reload check, especially if the package is not used with \LaTeX. |
| 613 |
% \begin{macrocode} |
| 614 |
\begingroup\catcode61\catcode48\catcode32=10\relax% |
| 615 |
\catcode13=5 % ^^M |
| 616 |
\endlinechar=13 % |
| 617 |
\catcode35=6 % # |
| 618 |
\catcode39=12 % ' |
| 619 |
\catcode44=12 % , |
| 620 |
\catcode45=12 % - |
| 621 |
\catcode46=12 % . |
| 622 |
\catcode58=12 % : |
| 623 |
\catcode64=11 % @ |
| 624 |
\catcode123=1 % { |
| 625 |
\catcode125=2 % } |
| 626 |
\expandafter\let\expandafter\x\csname [email protected]\endcsname |
| 627 |
\ifx\x\relax % plain-TeX, first loading |
| 628 |
\else |
| 629 |
\def\empty{}% |
| 630 |
\ifx\x\empty % LaTeX, first loading, |
| 631 |
% variable is initialized, but \ProvidesPackage not yet seen |
| 632 |
\else |
| 633 |
\expandafter\ifx\csname PackageInfo\endcsname\relax |
| 634 |
\def\x#1#2{% |
| 635 |
\immediate\write-1{Package #1 Info: #2.}% |
| 636 |
}% |
| 637 |
\else |
| 638 |
\def\x#1#2{\PackageInfo{#1}{#2, stopped}}% |
| 639 |
\fi |
| 640 |
\x{intcalc}{The package is already loaded}% |
| 641 |
\aftergroup\endinput |
| 642 |
\fi |
| 643 |
\fi |
| 644 |
\endgroup% |
| 645 |
% \end{macrocode} |
| 646 |
% Package identification: |
| 647 |
% \begin{macrocode} |
| 648 |
\begingroup\catcode61\catcode48\catcode32=10\relax% |
| 649 |
\catcode13=5 % ^^M |
| 650 |
\endlinechar=13 % |
| 651 |
\catcode35=6 % # |
| 652 |
\catcode39=12 % ' |
| 653 |
\catcode40=12 % ( |
| 654 |
\catcode41=12 % ) |
| 655 |
\catcode44=12 % , |
| 656 |
\catcode45=12 % - |
| 657 |
\catcode46=12 % . |
| 658 |
\catcode47=12 % / |
| 659 |
\catcode58=12 % : |
| 660 |
\catcode64=11 % @ |
| 661 |
\catcode91=12 % [ |
| 662 |
\catcode93=12 % ] |
| 663 |
\catcode123=1 % { |
| 664 |
\catcode125=2 % } |
| 665 |
\expandafter\ifx\csname ProvidesPackage\endcsname\relax |
| 666 |
\def\x#1#2#3[#4]{\endgroup |
| 667 |
\immediate\write-1{Package: #3 #4}% |
| 668 |
\xdef#1{#4}% |
| 669 |
}% |
| 670 |
\else |
| 671 |
\def\x#1#2[#3]{\endgroup |
| 672 |
#2[{#3}]% |
| 673 |
\ifx#1\@undefined |
| 674 |
\xdef#1{#3}% |
| 675 |
\fi |
| 676 |
\ifx#1\relax |
| 677 |
\xdef#1{#3}% |
| 678 |
\fi |
| 679 |
}% |
| 680 |
\fi |
| 681 |
\expandafter\x\csname [email protected]\endcsname |
| 682 |
\ProvidesPackage{intcalc}% |
| 683 |
[2019/12/15 v1.3 Expandable calculations with integers (HO)]% |
| 684 |
% \end{macrocode} |
| 685 |
% |
| 686 |
% \subsection{Catcodes} |
| 687 |
% |
| 688 |
% \begin{macrocode} |
| 689 |
\begingroup\catcode61\catcode48\catcode32=10\relax% |
| 690 |
\catcode13=5 % ^^M |
| 691 |
\endlinechar=13 % |
| 692 |
\catcode123=1 % { |
| 693 |
\catcode125=2 % } |
| 694 |
\catcode64=11 % @ |
| 695 |
\def\x{\endgroup |
| 696 |
\expandafter\edef\csname InCa@AtEnd\endcsname{% |
| 697 |
\endlinechar=\the\endlinechar\relax |
| 698 |
\catcode13=\the\catcode13\relax |
| 699 |
\catcode32=\the\catcode32\relax |
| 700 |
\catcode35=\the\catcode35\relax |
| 701 |
\catcode61=\the\catcode61\relax |
| 702 |
\catcode64=\the\catcode64\relax |
| 703 |
\catcode123=\the\catcode123\relax |
| 704 |
\catcode125=\the\catcode125\relax |
| 705 |
}% |
| 706 |
}% |
| 707 |
\x\catcode61\catcode48\catcode32=10\relax% |
| 708 |
\catcode13=5 % ^^M |
| 709 |
\endlinechar=13 % |
| 710 |
\catcode35=6 % # |
| 711 |
\catcode64=11 % @ |
| 712 |
\catcode123=1 % { |
| 713 |
\catcode125=2 % } |
| 714 |
\def\TMP@EnsureCode#1#2{% |
| 715 |
\edef\InCa@AtEnd{% |
| 716 |
\InCa@AtEnd |
| 717 |
\catcode#1=\the\catcode#1\relax |
| 718 |
}% |
| 719 |
\catcode#1=#2\relax |
| 720 |
} |
| 721 |
\TMP@EnsureCode{33}{12}% ! |
| 722 |
\TMP@EnsureCode{40}{12}% ( |
| 723 |
\TMP@EnsureCode{41}{12}% ) |
| 724 |
\TMP@EnsureCode{42}{12}% * |
| 725 |
\TMP@EnsureCode{43}{12}% + |
| 726 |
\TMP@EnsureCode{45}{12}% - |
| 727 |
\TMP@EnsureCode{47}{12}% / |
| 728 |
\TMP@EnsureCode{58}{11}% : (letter!) |
| 729 |
\TMP@EnsureCode{60}{12}% < |
| 730 |
\TMP@EnsureCode{62}{12}% > |
| 731 |
\TMP@EnsureCode{63}{14}% ? (comment!) |
| 732 |
\edef\InCa@AtEnd{\InCa@AtEnd\noexpand\endinput} |
| 733 |
\begingroup\expandafter\expandafter\expandafter\endgroup |
| 734 |
\expandafter\ifx\csname InCa@TestMode\endcsname\relax |
| 735 |
\else |
| 736 |
\catcode63=9 % ? (ignore) |
| 737 |
\fi |
| 738 |
? \let\InCa@@TestMode\InCa@TestMode |
| 739 |
% \end{macrocode} |
| 740 |
% |
| 741 |
% \subsection{Macros independent of \eTeX} |
| 742 |
% |
| 743 |
% \subsubsection{\op{Abs}, \op{Sgn}} |
| 744 |
% |
| 745 |
% \begin{macro}{\InCa@Abs} |
| 746 |
% \begin{macrocode} |
| 747 |
\def\InCa@Abs#1#2!{% |
| 748 |
\ifx#1-% |
| 749 |
#2% |
| 750 |
\else |
| 751 |
#1#2% |
| 752 |
\fi |
| 753 |
} |
| 754 |
% \end{macrocode} |
| 755 |
% \end{macro} |
| 756 |
% |
| 757 |
% \begin{macro}{\InCa@Sgn} |
| 758 |
% \begin{macrocode} |
| 759 |
\def\InCa@Sgn#1#2!{% |
| 760 |
\ifx#1-% |
| 761 |
-1% |
| 762 |
\else |
| 763 |
\ifx#10% |
| 764 |
0% |
| 765 |
\else |
| 766 |
1% |
| 767 |
\fi |
| 768 |
\fi |
| 769 |
} |
| 770 |
% \end{macrocode} |
| 771 |
% \end{macro} |
| 772 |
% |
| 773 |
% \subsubsection{\op{Min}, \op{Max}, \op{Cmp}} |
| 774 |
% |
| 775 |
% \begin{macro}{\InCa@Min} |
| 776 |
% \begin{macrocode} |
| 777 |
\def\InCa@Min#1!#2!{% |
| 778 |
\ifnum#1<#2 % |
| 779 |
#1% |
| 780 |
\else |
| 781 |
#2% |
| 782 |
\fi |
| 783 |
} |
| 784 |
% \end{macrocode} |
| 785 |
% \end{macro} |
| 786 |
% |
| 787 |
% \begin{macro}{\InCa@Max} |
| 788 |
% \begin{macrocode} |
| 789 |
\def\InCa@Max#1!#2!{% |
| 790 |
\ifnum#1>#2 % |
| 791 |
#1% |
| 792 |
\else |
| 793 |
#2% |
| 794 |
\fi |
| 795 |
} |
| 796 |
% \end{macrocode} |
| 797 |
% \end{macro} |
| 798 |
% |
| 799 |
% \begin{macro}{\InCa@Cmp} |
| 800 |
% \begin{macrocode} |
| 801 |
\def\InCa@Cmp#1!#2!{% |
| 802 |
\ifnum#1=#2 % |
| 803 |
0% |
| 804 |
\else |
| 805 |
\ifnum#1<#2 % |
| 806 |
-% |
| 807 |
\fi |
| 808 |
1% |
| 809 |
\fi |
| 810 |
} |
| 811 |
% \end{macrocode} |
| 812 |
% \end{macro} |
| 813 |
% |
| 814 |
% \subsubsection{\op{Fac}} |
| 815 |
% |
| 816 |
% \begin{macro}{\InCa@Fac} |
| 817 |
% It does not make much sense to calculate the |
| 818 |
% faculty by an general algorithm. The allowed |
| 819 |
% range of arguments is too low because of the |
| 820 |
% limited integer domain. |
| 821 |
% \begin{macrocode} |
| 822 |
\def\InCa@Fac#1!{% |
| 823 |
\ifcase#1 1% 0! |
| 824 |
\or 1% 1! |
| 825 |
\or 2% 2! |
| 826 |
\or 6% 3! |
| 827 |
\or 24% 4! |
| 828 |
\or 120% 5! |
| 829 |
\or 720% 6! |
| 830 |
\or 5040% 7! |
| 831 |
\or 40320% 8! |
| 832 |
\or 362880% 9! |
| 833 |
\or 3628800% 10! |
| 834 |
\or 39916800% 11! |
| 835 |
\or 479001600% 12! |
| 836 |
\else |
| 837 |
\ifnum#1<\z@ |
| 838 |
0\IntCalcError:FacNegative% |
| 839 |
\else |
| 840 |
0\IntCalcError:FacOverflow% |
| 841 |
\fi |
| 842 |
\fi |
| 843 |
} |
| 844 |
% \end{macrocode} |
| 845 |
% \end{macro} |
| 846 |
% |
| 847 |
% \subsection{Implementation based on \eTeX} |
| 848 |
% |
| 849 |
% Only \cs{numexpr} is used from \eTeX. |
| 850 |
% \begin{macrocode} |
| 851 |
\begingroup\expandafter\expandafter\expandafter\endgroup |
| 852 |
\expandafter\ifx\csname numexpr\endcsname\relax |
| 853 |
\else |
| 854 |
% \end{macrocode} |
| 855 |
% |
| 856 |
% \subsubsection{\op{Num}} |
| 857 |
% |
| 858 |
% \begin{macro}{\intcalcNum} |
| 859 |
% \begin{macrocode} |
| 860 |
\def\intcalcNum#1{% |
| 861 |
\the\numexpr#1\relax |
| 862 |
}% |
| 863 |
% \end{macrocode} |
| 864 |
% \end{macro} |
| 865 |
% |
| 866 |
% \subsubsection{\op{Inv}, \op{Abs}, \op{Sgn}} |
| 867 |
% |
| 868 |
% \begin{macro}{\intcalcInv} |
| 869 |
% \begin{macrocode} |
| 870 |
\def\intcalcInv#1{% |
| 871 |
\number-\intcalcNum{#1} % |
| 872 |
}% |
| 873 |
% \end{macrocode} |
| 874 |
% \end{macro} |
| 875 |
% |
| 876 |
% \begin{macro}{\intcalcAbs} |
| 877 |
% \begin{macrocode} |
| 878 |
\def\intcalcAbs#1{% |
| 879 |
\number\expandafter\InCa@Abs\the\numexpr#1! % |
| 880 |
}% |
| 881 |
% \end{macrocode} |
| 882 |
% \end{macro} |
| 883 |
% |
| 884 |
% \begin{macro}{\intcalcSgn} |
| 885 |
% \begin{macrocode} |
| 886 |
\def\intcalcSgn#1{% |
| 887 |
\number\expandafter\InCa@Sgn\the\numexpr#1! % |
| 888 |
}% |
| 889 |
% \end{macrocode} |
| 890 |
% \end{macro} |
| 891 |
% |
| 892 |
% \subsubsection{\op{Min}, \op{Max}, \op{Cmp}} |
| 893 |
% |
| 894 |
% \begin{macro}{\intcalcMin} |
| 895 |
% \begin{macrocode} |
| 896 |
\def\intcalcMin#1#2{% |
| 897 |
\number\expandafter\InCa@Min |
| 898 |
\the\numexpr#1\expandafter!% |
| 899 |
\the\numexpr#2! % |
| 900 |
}% |
| 901 |
% \end{macrocode} |
| 902 |
% \end{macro} |
| 903 |
% |
| 904 |
% \begin{macro}{\intcalcMax} |
| 905 |
% \begin{macrocode} |
| 906 |
\def\intcalcMax#1#2{% |
| 907 |
\number\expandafter\InCa@Max |
| 908 |
\the\numexpr#1\expandafter!% |
| 909 |
\the\numexpr#2! % |
| 910 |
}% |
| 911 |
% \end{macrocode} |
| 912 |
% \end{macro} |
| 913 |
% |
| 914 |
% \begin{macro}{\intcalcCmp} |
| 915 |
% \begin{macrocode} |
| 916 |
\def\intcalcCmp#1#2{% |
| 917 |
\number\expandafter\InCa@Cmp |
| 918 |
\the\numexpr#1\expandafter!\the\numexpr#2! % |
| 919 |
}% |
| 920 |
% \end{macrocode} |
| 921 |
% \end{macro} |
| 922 |
% |
| 923 |
% \subsubsection{\op{Inc}, \op{Dec}} |
| 924 |
% |
| 925 |
% \begin{macro}{\intcalcInc} |
| 926 |
% \begin{macrocode} |
| 927 |
\def\intcalcInc#1{% |
| 928 |
\the\numexpr#1+1\relax |
| 929 |
}% |
| 930 |
% \end{macrocode} |
| 931 |
% \end{macro} |
| 932 |
% |
| 933 |
% \begin{macro}{\intcalcDec} |
| 934 |
% \begin{macrocode} |
| 935 |
\def\intcalcDec#1{% |
| 936 |
\the\numexpr#1-1\relax |
| 937 |
}% |
| 938 |
% \end{macrocode} |
| 939 |
% \end{macro} |
| 940 |
% |
| 941 |
% \begin{macro}{\IntCalcInc} |
| 942 |
% \begin{macrocode} |
| 943 |
\def\IntCalcInc#1!{% |
| 944 |
\the\numexpr#1+1\relax |
| 945 |
}% |
| 946 |
% \end{macrocode} |
| 947 |
% \end{macro} |
| 948 |
% \begin{macro}{\IntCalcDec} |
| 949 |
% \begin{macrocode} |
| 950 |
\def\IntCalcDec#1!{% |
| 951 |
\the\numexpr#1-1\relax |
| 952 |
}% |
| 953 |
% \end{macrocode} |
| 954 |
% \end{macro} |
| 955 |
% |
| 956 |
% \subsubsection{\op{Add}, \op{Sub}} |
| 957 |
% |
| 958 |
% \begin{macro}{\intcalcAdd} |
| 959 |
% \begin{macrocode} |
| 960 |
\def\intcalcAdd#1#2{% |
| 961 |
\the\numexpr#1+(#2)\relax |
| 962 |
}% |
| 963 |
% \end{macrocode} |
| 964 |
% \end{macro} |
| 965 |
% |
| 966 |
% \begin{macro}{\intcalcSub} |
| 967 |
% \begin{macrocode} |
| 968 |
\def\intcalcSub#1#2{% |
| 969 |
\the\numexpr#1-(#2)\relax |
| 970 |
}% |
| 971 |
% \end{macrocode} |
| 972 |
% \end{macro} |
| 973 |
% |
| 974 |
% \begin{macro}{\IntCalcAdd} |
| 975 |
% \begin{macrocode} |
| 976 |
\def\IntCalcAdd#1!#2!{% |
| 977 |
\the\numexpr#1+#2\relax |
| 978 |
}% |
| 979 |
% \end{macrocode} |
| 980 |
% \end{macro} |
| 981 |
% |
| 982 |
% \begin{macro}{\IntCalcSub} |
| 983 |
% \begin{macrocode} |
| 984 |
\def\IntCalcSub#1!#2!{% |
| 985 |
\the\numexpr#1-#2\relax |
| 986 |
}% |
| 987 |
% \end{macrocode} |
| 988 |
% \end{macro} |
| 989 |
% |
| 990 |
% \subsubsection{\op{Shl}, \op{Shr}} |
| 991 |
% |
| 992 |
% \begin{macro}{\intcalcShl} |
| 993 |
% \begin{macrocode} |
| 994 |
\def\intcalcShl#1{% |
| 995 |
\the\numexpr(#1)*2\relax |
| 996 |
}% |
| 997 |
% \end{macrocode} |
| 998 |
% \end{macro} |
| 999 |
% |
| 1000 |
% \begin{macro}{\intcalcShr} |
| 1001 |
% \begin{macrocode} |
| 1002 |
\def\intcalcShr#1{% |
| 1003 |
\number\expandafter\InCa@Shr\the\numexpr#1! % |
| 1004 |
}% |
| 1005 |
% \end{macrocode} |
| 1006 |
% \end{macro} |
| 1007 |
% \begin{macro}{\IntCalcShl} |
| 1008 |
% \begin{macrocode} |
| 1009 |
\def\IntCalcShl#1!{% |
| 1010 |
\the\numexpr#1*2\relax |
| 1011 |
}% |
| 1012 |
% \end{macrocode} |
| 1013 |
% \end{macro} |
| 1014 |
% |
| 1015 |
% \begin{macro}{\IntCalcShr} |
| 1016 |
% \begin{macrocode} |
| 1017 |
\def\IntCalcShr#1!{% |
| 1018 |
\the\numexpr\ifodd#1 (#1-1)\else#1\fi/2\relax |
| 1019 |
}% |
| 1020 |
% \end{macrocode} |
| 1021 |
% \end{macro} |
| 1022 |
% \begin{macro}{\InCa@Shr} |
| 1023 |
% \begin{macrocode} |
| 1024 |
\def\InCa@Shr#1#2!{% |
| 1025 |
\ifx#1-% |
| 1026 |
-\InCa@Shr#2!% |
| 1027 |
\else |
| 1028 |
\ifodd#1#2 % |
| 1029 |
\the\numexpr(#1#2-1)/2\relax |
| 1030 |
\else |
| 1031 |
\the\numexpr#1#2/2\relax |
| 1032 |
\fi |
| 1033 |
\fi |
| 1034 |
}% |
| 1035 |
% \end{macrocode} |
| 1036 |
% \end{macro} |
| 1037 |
% |
| 1038 |
% \subsubsection{\op{Mul}, \op{Sqr}, \op{Fac}} |
| 1039 |
% |
| 1040 |
% \begin{macro}{\intcalcMul} |
| 1041 |
% \begin{macrocode} |
| 1042 |
\def\intcalcMul#1#2{% |
| 1043 |
\the\numexpr(#1)*(#2)\relax |
| 1044 |
}% |
| 1045 |
% \end{macrocode} |
| 1046 |
% \end{macro} |
| 1047 |
% \begin{macro}{\IntCalcMul} |
| 1048 |
% \begin{macrocode} |
| 1049 |
\def\IntCalcMul#1!#2!{% |
| 1050 |
\the\numexpr#1*#2\relax |
| 1051 |
}% |
| 1052 |
% \end{macrocode} |
| 1053 |
% \end{macro} |
| 1054 |
% |
| 1055 |
% \begin{macro}{\intcalcSqr} |
| 1056 |
% \begin{macrocode} |
| 1057 |
\def\intcalcSqr#1{% |
| 1058 |
\number\expandafter\InCa@Sqr\the\numexpr#1! % |
| 1059 |
}% |
| 1060 |
% \end{macrocode} |
| 1061 |
% \end{macro} |
| 1062 |
% \begin{macro}{\InCa@Sqr} |
| 1063 |
% \begin{macrocode} |
| 1064 |
\def\InCa@Sqr#1!{% |
| 1065 |
\the\numexpr#1*#1\relax |
| 1066 |
}% |
| 1067 |
% \end{macrocode} |
| 1068 |
% \end{macro} |
| 1069 |
% |
| 1070 |
% \begin{macro}{\intcalcFac} |
| 1071 |
% \begin{macrocode} |
| 1072 |
\def\intcalcFac#1{% |
| 1073 |
\number\expandafter\InCa@Fac\the\numexpr#1! % |
| 1074 |
}% |
| 1075 |
% \end{macrocode} |
| 1076 |
% \end{macro} |
| 1077 |
% |
| 1078 |
% \subsubsection{\op{Pow}} |
| 1079 |
% |
| 1080 |
% \begin{macro}{\intcalcPow} |
| 1081 |
% \begin{macrocode} |
| 1082 |
\def\intcalcPow#1#2{% |
| 1083 |
\number\expandafter\InCa@Pow |
| 1084 |
\the\numexpr#1\expandafter!% |
| 1085 |
\the\numexpr#2! % |
| 1086 |
}% |
| 1087 |
% \end{macrocode} |
| 1088 |
% \end{macro} |
| 1089 |
% \begin{macro}{\InCa@Pow} |
| 1090 |
% \begin{macrocode} |
| 1091 |
\def\InCa@Pow#1#2!#3#4!{% |
| 1092 |
\ifcase#3#4 % power = 0 |
| 1093 |
1% |
| 1094 |
\or % power = 1 |
| 1095 |
#1#2% |
| 1096 |
\or % power = 2 |
| 1097 |
\the\numexpr#1#2*#1#2\relax |
| 1098 |
\else |
| 1099 |
\ifcase#1#2 % basis = 0, power <> 0 |
| 1100 |
0% |
| 1101 |
\ifx#3-% power < 0 |
| 1102 |
0\IntCalcError:DivisionByZero% |
| 1103 |
\fi |
| 1104 |
\or |
| 1105 |
1% basis = 1 |
| 1106 |
\else |
| 1107 |
\ifnum#1#2=\m@ne % basis = -1 |
| 1108 |
\ifodd#3#4 % |
| 1109 |
-% |
| 1110 |
\fi |
| 1111 |
1% |
| 1112 |
\else % |basis| > 1 |
| 1113 |
\ifx#3-% power < 0 |
| 1114 |
0% |
| 1115 |
\else % power > 2 |
| 1116 |
\InCa@PowRec#1#2!#3#4!1!% |
| 1117 |
\fi |
| 1118 |
\fi |
| 1119 |
\fi |
| 1120 |
\fi |
| 1121 |
}% |
| 1122 |
% \end{macrocode} |
| 1123 |
% \end{macro} |
| 1124 |
% \begin{macro}{\InCa@PowRec} |
| 1125 |
%\begin{quote} |
| 1126 |
%\begin{verbatim} |
| 1127 |
%Pow(b, p) { |
| 1128 |
% PowRec(b, p, 1) |
| 1129 |
%} |
| 1130 |
%PowRec(b, p, r) { |
| 1131 |
% if p == 1 then |
| 1132 |
% return r*b |
| 1133 |
% else |
| 1134 |
% ifodd p then |
| 1135 |
% return PowRec(b*b, (p-1)/2, r*b) % p div 2 = (p-1)/2 |
| 1136 |
% else |
| 1137 |
% return PowRec(b*b, (p-1)/2, r) |
| 1138 |
% fi |
| 1139 |
% fi |
| 1140 |
%} |
| 1141 |
%\end{verbatim} |
| 1142 |
%\end{quote} |
| 1143 |
% \begin{macrocode} |
| 1144 |
\def\InCa@PowRec#1!#2!#3!{% |
| 1145 |
\ifnum#2=\@ne |
| 1146 |
\the\numexpr#1*#3\relax |
| 1147 |
\else |
| 1148 |
\ifodd#2 % |
| 1149 |
\expandafter\InCa@PowRec |
| 1150 |
\the\numexpr#1*#1\expandafter!% |
| 1151 |
\the\numexpr(#2-1)/2\expandafter!% |
| 1152 |
\the\numexpr#1*#3\expandafter\expandafter\expandafter!% |
| 1153 |
\else |
| 1154 |
\expandafter\InCa@PowRec |
| 1155 |
\the\numexpr#1*#1\expandafter!% |
| 1156 |
\the\numexpr(#2-1)/2\expandafter!% |
| 1157 |
\number#3\expandafter\expandafter\expandafter!% |
| 1158 |
\fi |
| 1159 |
\fi |
| 1160 |
}% |
| 1161 |
% \end{macrocode} |
| 1162 |
% \end{macro} |
| 1163 |
% |
| 1164 |
% \subsubsection{\op{Div}, \op{Mod}} |
| 1165 |
% |
| 1166 |
% \TeX's \cs{divide} truncates, |
| 1167 |
% \eTeX's \cs{numexpr} rounds the result of a division. |
| 1168 |
% The rounding method is called ``Symmetric Arithmetic Rounding'' |
| 1169 |
% or ``Round-Half-Up'' (``Kaufm\"annisches Runden'' in German): |
| 1170 |
% \begin{quote} |
| 1171 |
% | 1 = 3 divide 2 = 1.5 = numexpr 3/2 = 2|\\ |
| 1172 |
% |-1 = -3 divide 2 = -1.5 = numexpr -3/2 = -2| |
| 1173 |
% \end{quote} |
| 1174 |
% Macro \cs{intcalcDiv} follows \TeX\ and truncates. |
| 1175 |
% The calculation is done by the following formula: |
| 1176 |
% \begin{gather} |
| 1177 |
% \opDiv(X,Y) = (X - (Y-1)/2)/Y\qquad\text{for $X, Y > 0$} |
| 1178 |
% \end{gather} |
| 1179 |
% The operator `/' is \cs{numexpr}'s division. |
| 1180 |
% \begin{macro}{\intcalcDiv} |
| 1181 |
% \begin{macrocode} |
| 1182 |
\def\intcalcDiv#1#2{% |
| 1183 |
\number\expandafter\InCa@Div |
| 1184 |
\the\numexpr#1\expandafter!% |
| 1185 |
\the\numexpr#2! % |
| 1186 |
}% |
| 1187 |
% \end{macrocode} |
| 1188 |
% \end{macro} |
| 1189 |
% \begin{macro}{\InCa@Div} |
| 1190 |
% \begin{macrocode} |
| 1191 |
\def\InCa@Div#1!#2!{% |
| 1192 |
\ifcase#2 % |
| 1193 |
0\IntCalcError:DivisionByZero% |
| 1194 |
\else |
| 1195 |
\ifcase#1 % |
| 1196 |
0% |
| 1197 |
\else |
| 1198 |
\expandafter\InCa@@Div |
| 1199 |
\romannumeral 0% |
| 1200 |
\ifnum#1<\z@ |
| 1201 |
\expandafter-\number-#1% |
| 1202 |
\else |
| 1203 |
\expandafter+\number#1% |
| 1204 |
\fi |
| 1205 |
\expandafter!% |
| 1206 |
\romannumeral 0% |
| 1207 |
\ifnum#2<\z@ |
| 1208 |
\expandafter-\number-#2% |
| 1209 |
\else |
| 1210 |
\expandafter+\number#2% |
| 1211 |
\fi |
| 1212 |
!% |
| 1213 |
\fi |
| 1214 |
\fi |
| 1215 |
}% |
| 1216 |
% \end{macrocode} |
| 1217 |
% \end{macro} |
| 1218 |
% \begin{macro}{\IntCalcDiv} |
| 1219 |
% \begin{macrocode} |
| 1220 |
\def\InCa@Temp#1{% |
| 1221 |
\def\IntCalcDiv##1!##2!{% |
| 1222 |
\number |
| 1223 |
\ifcase##2 % |
| 1224 |
0\IntCalcError:DivisionByZero% |
| 1225 |
\else |
| 1226 |
\ifcase##1 % |
| 1227 |
0% |
| 1228 |
\else |
| 1229 |
\the\numexpr(##1-(##2-1)/2)/##2\relax |
| 1230 |
\fi |
| 1231 |
\fi |
| 1232 |
#1% |
| 1233 |
}% |
| 1234 |
}% |
| 1235 |
\InCa@Temp{ }% |
| 1236 |
% \end{macrocode} |
| 1237 |
% \end{macro} |
| 1238 |
% \begin{macro}{\InCa@@Div} |
| 1239 |
% \begin{macrocode} |
| 1240 |
\def\InCa@@Div#1#2!#3#4!{% |
| 1241 |
#1#3% |
| 1242 |
\the\numexpr(#2-(#4-1)/2)/#4\relax |
| 1243 |
}% |
| 1244 |
% \end{macrocode} |
| 1245 |
% \end{macro} |
| 1246 |
% |
| 1247 |
% \begin{macro}{\intcalcMod} |
| 1248 |
% \begin{macrocode} |
| 1249 |
\def\intcalcMod#1#2{% |
| 1250 |
\number\expandafter\InCa@Mod |
| 1251 |
\the\numexpr#1\expandafter!% |
| 1252 |
\the\numexpr#2! % |
| 1253 |
}% |
| 1254 |
% \end{macrocode} |
| 1255 |
% \end{macro} |
| 1256 |
% \begin{macro}{\InCa@Mod} |
| 1257 |
% \begin{macrocode} |
| 1258 |
\def\InCa@Mod#1!#2!{% |
| 1259 |
\ifcase#2 % |
| 1260 |
0\IntCalcError:DivisionByZero% |
| 1261 |
\else |
| 1262 |
\ifcase#1 % |
| 1263 |
0% |
| 1264 |
\else |
| 1265 |
\expandafter\InCa@@Mod |
| 1266 |
\romannumeral 0% |
| 1267 |
\ifnum#1<\z@ |
| 1268 |
\expandafter-\number-#1% |
| 1269 |
\else |
| 1270 |
\expandafter+\number#1% |
| 1271 |
\fi |
| 1272 |
\expandafter!% |
| 1273 |
\romannumeral 0% |
| 1274 |
\ifnum#2<\z@ |
| 1275 |
\expandafter-\number-#2% |
| 1276 |
\else |
| 1277 |
\expandafter+\number#2% |
| 1278 |
\fi |
| 1279 |
!% |
| 1280 |
\fi |
| 1281 |
\fi |
| 1282 |
}% |
| 1283 |
% \end{macrocode} |
| 1284 |
% \end{macro} |
| 1285 |
% \begin{macro}{\IntCalcMod} |
| 1286 |
% \begin{macrocode} |
| 1287 |
\def\InCa@Temp#1{% |
| 1288 |
\def\IntCalcMod##1!##2!{% |
| 1289 |
\number |
| 1290 |
\ifcase##2 % |
| 1291 |
0\IntCalcError:DivisionByZero% |
| 1292 |
\else |
| 1293 |
\ifcase##1 % |
| 1294 |
0% |
| 1295 |
\else |
| 1296 |
\the\numexpr##1-(##1-(##2-1)/2)/##2*##2\relax |
| 1297 |
\fi |
| 1298 |
\fi |
| 1299 |
#1% |
| 1300 |
}% |
| 1301 |
}% |
| 1302 |
\InCa@Temp{ }% |
| 1303 |
% \end{macrocode} |
| 1304 |
% \end{macro} |
| 1305 |
% \begin{macro}{\InCa@@Mod} |
| 1306 |
% \begin{macrocode} |
| 1307 |
\def\InCa@@Mod#1#2!#3#4!{% |
| 1308 |
\if#3+% |
| 1309 |
\if#1+% |
| 1310 |
\the\numexpr#2-\InCa@@Div+#2!+#4!*#4\relax |
| 1311 |
\else |
| 1312 |
\expandafter\InCa@ModX |
| 1313 |
\the\numexpr-#2+\InCa@@Div+#2!+#4!*#4!#4!% |
| 1314 |
\fi |
| 1315 |
\else |
| 1316 |
-% |
| 1317 |
\if#1+% |
| 1318 |
\expandafter\InCa@ModX |
| 1319 |
\the\numexpr-#2+\InCa@@Div+#2!+#4!*#4!#4!% |
| 1320 |
\else |
| 1321 |
\the\numexpr#2-\InCa@@Div+#2!+#4!*#4\relax |
| 1322 |
\fi |
| 1323 |
\fi |
| 1324 |
}% |
| 1325 |
% \end{macrocode} |
| 1326 |
% \end{macro} |
| 1327 |
% \begin{macro}{\InCa@ModX} |
| 1328 |
% \begin{macrocode} |
| 1329 |
\def\InCa@ModX#1!#2!{% |
| 1330 |
\ifcase#1 % |
| 1331 |
0% |
| 1332 |
\else |
| 1333 |
\the\numexpr#1+#2\relax |
| 1334 |
\fi |
| 1335 |
}% |
| 1336 |
% \end{macrocode} |
| 1337 |
% \end{macro} |
| 1338 |
% |
| 1339 |
% \begin{macrocode} |
| 1340 |
\expandafter\InCa@AtEnd |
| 1341 |
\fi% |
| 1342 |
% \end{macrocode} |
| 1343 |
% |
| 1344 |
% \subsection{Implementation without \eTeX} |
| 1345 |
% |
| 1346 |
% \subsubsection{\op{Num}} |
| 1347 |
% |
| 1348 |
% \begin{macro}{\intcalcNum} |
| 1349 |
% \begin{macrocode} |
| 1350 |
\def\intcalcNum#1{% |
| 1351 |
\number\expandafter\InCa@FirstOfOne\number#1! % |
| 1352 |
} |
| 1353 |
% \end{macrocode} |
| 1354 |
% \end{macro} |
| 1355 |
% |
| 1356 |
% \subsubsection{\op{Inv}, \op{Abs}, \op{Sgn}} |
| 1357 |
% |
| 1358 |
% \begin{macro}{\intcalcInv} |
| 1359 |
% \begin{macrocode} |
| 1360 |
\def\intcalcInv#1{% |
| 1361 |
\number\expandafter\InCa@FirstOfOne\number-#1! % |
| 1362 |
} |
| 1363 |
% \end{macrocode} |
| 1364 |
% \end{macro} |
| 1365 |
% \begin{macro}{\InCa@FirstOfOne} |
| 1366 |
% \begin{macrocode} |
| 1367 |
\def\InCa@FirstOfOne#1!{#1} |
| 1368 |
% \end{macrocode} |
| 1369 |
% \end{macro} |
| 1370 |
% |
| 1371 |
% \begin{macro}{\intcalcAbs} |
| 1372 |
% \begin{macrocode} |
| 1373 |
\def\intcalcAbs#1{% |
| 1374 |
\number\expandafter\InCa@Abs\number#1! % |
| 1375 |
} |
| 1376 |
% \end{macrocode} |
| 1377 |
% \end{macro} |
| 1378 |
% |
| 1379 |
% \begin{macro}{\intcalcSgn} |
| 1380 |
% \begin{macrocode} |
| 1381 |
\def\intcalcSgn#1{% |
| 1382 |
\number\expandafter\InCa@Sgn\number#1! % |
| 1383 |
} |
| 1384 |
% \end{macrocode} |
| 1385 |
% \end{macro} |
| 1386 |
% |
| 1387 |
% \subsubsection{\op{Min}, \op{Max}, \op{Cmp}} |
| 1388 |
% |
| 1389 |
% \begin{macro}{\intcalcMin} |
| 1390 |
% \begin{macrocode} |
| 1391 |
\def\intcalcMin#1#2{% |
| 1392 |
\number\expandafter\InCa@Min |
| 1393 |
\number\number#1\expandafter!\number#2! % |
| 1394 |
} |
| 1395 |
% \end{macrocode} |
| 1396 |
% \end{macro} |
| 1397 |
% |
| 1398 |
% \begin{macro}{\intcalcMax} |
| 1399 |
% \begin{macrocode} |
| 1400 |
\def\intcalcMax#1#2{% |
| 1401 |
\number\expandafter\InCa@Max |
| 1402 |
\number\number#1\expandafter!\number#2! % |
| 1403 |
} |
| 1404 |
% \end{macrocode} |
| 1405 |
% \end{macro} |
| 1406 |
% |
| 1407 |
% \begin{macro}{\intcalcCmp} |
| 1408 |
% \begin{macrocode} |
| 1409 |
\def\intcalcCmp#1#2{% |
| 1410 |
\number\expandafter\InCa@Cmp |
| 1411 |
\number\number#1\expandafter!\number#2! % |
| 1412 |
}% |
| 1413 |
% \end{macrocode} |
| 1414 |
% \end{macro} |
| 1415 |
% |
| 1416 |
% \subsubsection{\op{Inc}, \op{Dec}} |
| 1417 |
% |
| 1418 |
% \begin{macro}{\intcalcInc} |
| 1419 |
% \begin{macrocode} |
| 1420 |
\def\intcalcInc#1{% |
| 1421 |
\number\expandafter\InCa@IncSwitch\number#1! % |
| 1422 |
} |
| 1423 |
% \end{macrocode} |
| 1424 |
% \end{macro} |
| 1425 |
% \begin{macro}{\InCa@IncSwitch} |
| 1426 |
% \begin{macrocode} |
| 1427 |
\def\InCa@IncSwitch#1#2!{% |
| 1428 |
\ifx#1-% |
| 1429 |
-% |
| 1430 |
\csname InCa@Empty% |
| 1431 |
\InCa@Dec#2!% |
| 1432 |
\else |
| 1433 |
\csname InCa@Empty% |
| 1434 |
\InCa@Inc#1#2!% |
| 1435 |
\fi |
| 1436 |
} |
| 1437 |
% \end{macrocode} |
| 1438 |
% \end{macro} |
| 1439 |
% \begin{macro}{\intcalcDec} |
| 1440 |
% \begin{macrocode} |
| 1441 |
\def\intcalcDec#1{% |
| 1442 |
\number\expandafter\InCa@DecSwitch\number#1! % |
| 1443 |
} |
| 1444 |
% \end{macrocode} |
| 1445 |
% \end{macro} |
| 1446 |
% \begin{macro}{\InCa@DecSwitch} |
| 1447 |
% \begin{macrocode} |
| 1448 |
\def\InCa@DecSwitch#1#2!{% |
| 1449 |
\ifx#1-% |
| 1450 |
-% |
| 1451 |
\csname InCa@Empty% |
| 1452 |
\expandafter\InCa@Inc#2!% |
| 1453 |
\else |
| 1454 |
\ifx#10% |
| 1455 |
-1% |
| 1456 |
\else |
| 1457 |
\csname InCa@Empty% |
| 1458 |
\InCa@Dec#1#2!% |
| 1459 |
\fi |
| 1460 |
\fi |
| 1461 |
} |
| 1462 |
% \end{macrocode} |
| 1463 |
% \end{macro} |
| 1464 |
% |
| 1465 |
% \begin{macro}{\IntCalcInc} |
| 1466 |
% \begin{macrocode} |
| 1467 |
\def\IntCalcInc#1!{% |
| 1468 |
\number\csname InCa@Empty\InCa@Inc#1! % |
| 1469 |
} |
| 1470 |
% \end{macrocode} |
| 1471 |
% \end{macro} |
| 1472 |
% \begin{macro}{\IntCalcDec} |
| 1473 |
% \begin{macrocode} |
| 1474 |
\def\IntCalcDec#1!{% |
| 1475 |
\number\csname InCa@Empty\InCa@Dec#1! % |
| 1476 |
} |
| 1477 |
% \end{macrocode} |
| 1478 |
% \end{macro} |
| 1479 |
% |
| 1480 |
% \begin{macro}{\InCa@Inc} |
| 1481 |
% \begin{macrocode} |
| 1482 |
\def\InCa@Inc#1#2{% |
| 1483 |
\ifx#2!% |
| 1484 |
\csname InCa@IncDigit#1\endcsname1% |
| 1485 |
\else |
| 1486 |
\csname InCa@IncDigit#1% |
| 1487 |
\expandafter\InCa@Inc\expandafter#2% |
| 1488 |
\fi |
| 1489 |
} |
| 1490 |
% \end{macrocode} |
| 1491 |
% \end{macro} |
| 1492 |
% \begin{macro}{\InCa@IncDigit[0-8]} |
| 1493 |
% \begin{macrocode} |
| 1494 |
\def\InCa@Temp#1#2{% |
| 1495 |
\expandafter\def\csname InCa@IncDigit#1\endcsname##1{% |
| 1496 |
\endcsname |
| 1497 |
0% |
| 1498 |
\ifcase##1 % |
| 1499 |
#1% |
| 1500 |
\else |
| 1501 |
#2% |
| 1502 |
\fi |
| 1503 |
}% |
| 1504 |
} |
| 1505 |
\InCa@Temp 01 |
| 1506 |
\InCa@Temp 12 |
| 1507 |
\InCa@Temp 23 |
| 1508 |
\InCa@Temp 34 |
| 1509 |
\InCa@Temp 45 |
| 1510 |
\InCa@Temp 56 |
| 1511 |
\InCa@Temp 67 |
| 1512 |
\InCa@Temp 78 |
| 1513 |
\InCa@Temp 89 |
| 1514 |
% \end{macrocode} |
| 1515 |
% \end{macro} |
| 1516 |
% \begin{macro}{\InCa@IncDigit9} |
| 1517 |
% \begin{macrocode} |
| 1518 |
\expandafter\def\csname InCa@IncDigit9\endcsname#1{% |
| 1519 |
\expandafter\endcsname |
| 1520 |
\ifcase#1 % |
| 1521 |
09% |
| 1522 |
\else |
| 1523 |
10% |
| 1524 |
\fi |
| 1525 |
} |
| 1526 |
% \end{macrocode} |
| 1527 |
% \end{macro} |
| 1528 |
% |
| 1529 |
% \begin{macro}{\InCa@Dec} |
| 1530 |
% \begin{macrocode} |
| 1531 |
\def\InCa@Dec#1#2{% |
| 1532 |
\ifx#2!% |
| 1533 |
\csname InCa@DecDigit#1\endcsname1% |
| 1534 |
\else |
| 1535 |
\csname InCa@DecDigit#1% |
| 1536 |
\expandafter\InCa@Dec\expandafter#2% |
| 1537 |
\fi |
| 1538 |
} |
| 1539 |
% \end{macrocode} |
| 1540 |
% \end{macro} |
| 1541 |
% \begin{macro}{\InCa@DecDigit[1-9]} |
| 1542 |
% \begin{macrocode} |
| 1543 |
\def\InCa@Temp#1#2{% |
| 1544 |
\expandafter\def\csname InCa@DecDigit#1\endcsname##1{% |
| 1545 |
\endcsname |
| 1546 |
0% |
| 1547 |
\ifcase##1 % |
| 1548 |
#1% |
| 1549 |
\else |
| 1550 |
#2% |
| 1551 |
\fi |
| 1552 |
}% |
| 1553 |
} |
| 1554 |
\InCa@Temp 98 |
| 1555 |
\InCa@Temp 87 |
| 1556 |
\InCa@Temp 76 |
| 1557 |
\InCa@Temp 65 |
| 1558 |
\InCa@Temp 54 |
| 1559 |
\InCa@Temp 43 |
| 1560 |
\InCa@Temp 32 |
| 1561 |
\InCa@Temp 21 |
| 1562 |
\InCa@Temp 10 |
| 1563 |
% \end{macrocode} |
| 1564 |
% \end{macro} |
| 1565 |
% \begin{macro}{\InCa@DecDigit0} |
| 1566 |
% \begin{macrocode} |
| 1567 |
\expandafter\def\csname InCa@DecDigit0\endcsname#1{% |
| 1568 |
\expandafter\endcsname |
| 1569 |
\ifcase#1 % |
| 1570 |
00% |
| 1571 |
\else |
| 1572 |
19% |
| 1573 |
\fi |
| 1574 |
} |
| 1575 |
% \end{macrocode} |
| 1576 |
% \end{macro} |
| 1577 |
% |
| 1578 |
% \subsubsection{\op{Add}, \op{Sub}} |
| 1579 |
% |
| 1580 |
% \begin{macro}{\intcalcAdd} |
| 1581 |
% \begin{macrocode} |
| 1582 |
\def\intcalcAdd#1#2{% |
| 1583 |
\number |
| 1584 |
\expandafter\InCa@AddSwitch |
| 1585 |
\number\number#1\expandafter!% |
| 1586 |
\number#2! % |
| 1587 |
} |
| 1588 |
% \end{macrocode} |
| 1589 |
% \end{macro} |
| 1590 |
% \begin{macro}{\intcalcSub} |
| 1591 |
% \begin{macrocode} |
| 1592 |
\def\intcalcSub#1#2{% |
| 1593 |
\number |
| 1594 |
\expandafter\InCa@AddSwitch |
| 1595 |
\number\number#1\expandafter!% |
| 1596 |
\number-\number#2! % |
| 1597 |
} |
| 1598 |
% \end{macrocode} |
| 1599 |
% \end{macro} |
| 1600 |
% |
| 1601 |
% \begin{macro}{\InCa@AddSwitch} |
| 1602 |
% Decision table for \cs{InCa@AddSwitch}. |
| 1603 |
% The sign of negative numbers can be removed |
| 1604 |
% by a simple \cs{@gobble} |
| 1605 |
% instead of the more expensive |\number-|. |
| 1606 |
% \begin{quote} |
| 1607 |
% \begin{tabular}[t]{@{}|l|l|l|l|l|@{}} |
| 1608 |
% \hline |
| 1609 |
% $x<0$ & $y<0$ & $ x< y$ & $-$ & $\opAdd(-x,-y)$\\ |
| 1610 |
% \cline{3-3}\cline{5-5} |
| 1611 |
% & & else & & $\opAdd(-y,-x)$\\ |
| 1612 |
% \cline{2-5} |
| 1613 |
% & else & $-x> y$ & $-$ & $\opSub(-x, y)$\\ |
| 1614 |
% \cline{3-5} |
| 1615 |
% & & else & $+$ & $\opSub( y,-x)$\\ |
| 1616 |
% \hline |
| 1617 |
% else & $y<0$ & $ x>-y$ & $+$ & $\opSub( x,-y)$\\ |
| 1618 |
% \cline{3-5} |
| 1619 |
% & & else & $-$ & $\opSub(-y, x)$\\ |
| 1620 |
% \cline{2-5} |
| 1621 |
% & else & $ x> y$ & $+$ & $\opAdd( x, y)$\\ |
| 1622 |
% \cline{3-3}\cline{5-5} |
| 1623 |
% & & else & & $\opAdd( y, x)$\\ |
| 1624 |
% \hline |
| 1625 |
% \end{tabular} |
| 1626 |
% \end{quote} |
| 1627 |
% \begin{macrocode} |
| 1628 |
\def\InCa@AddSwitch#1!#2!{% |
| 1629 |
\ifnum#1<\z@ |
| 1630 |
\ifnum#2<\z@ |
| 1631 |
-% |
| 1632 |
\ifnum#1<#2 % |
| 1633 |
\expandafter\InCa@Add\number-#1\expandafter!% |
| 1634 |
\@gobble#2!% |
| 1635 |
\else |
| 1636 |
\expandafter\InCa@Add\number-#2\expandafter!% |
| 1637 |
\@gobble#1!% |
| 1638 |
\fi |
| 1639 |
\else |
| 1640 |
\ifnum-#1>#2 % |
| 1641 |
-% |
| 1642 |
\expandafter\InCa@Sub\@gobble#1!#2!% |
| 1643 |
\else |
| 1644 |
\expandafter\InCa@Sub\number#2\expandafter!% |
| 1645 |
\@gobble#1!% |
| 1646 |
\fi |
| 1647 |
\fi |
| 1648 |
\else |
| 1649 |
\ifnum#2<\z@ |
| 1650 |
\ifnum#1>-#2 % |
| 1651 |
\expandafter\InCa@Sub\number#1\expandafter!% |
| 1652 |
\@gobble#2!% |
| 1653 |
\else |
| 1654 |
-% |
| 1655 |
\expandafter\InCa@Sub\@gobble#2!#1!% |
| 1656 |
\fi |
| 1657 |
\else |
| 1658 |
\ifnum#1>#2 % |
| 1659 |
\InCa@Add#1!#2!% |
| 1660 |
\else |
| 1661 |
\InCa@Add#2!#1!% |
| 1662 |
\fi |
| 1663 |
\fi |
| 1664 |
\fi |
| 1665 |
} |
| 1666 |
% \end{macrocode} |
| 1667 |
% \end{macro} |
| 1668 |
% \begin{macro}{\IntCalcAdd} |
| 1669 |
% \begin{macrocode} |
| 1670 |
\def\IntCalcAdd#1!#2!{% |
| 1671 |
\number\InCa@Add#1!#2! % |
| 1672 |
} |
| 1673 |
% \end{macrocode} |
| 1674 |
% \end{macro} |
| 1675 |
% \begin{macro}{\IntCalcSub} |
| 1676 |
% \begin{macrocode} |
| 1677 |
\def\IntCalcSub#1!#2!{% |
| 1678 |
\number\InCa@Sub#1!#2! % |
| 1679 |
} |
| 1680 |
% \end{macrocode} |
| 1681 |
% \end{macro} |
| 1682 |
% \begin{macro}{\InCa@Space} |
| 1683 |
% \begin{macrocode} |
| 1684 |
\begingroup |
| 1685 |
\def\x#1{\endgroup |
| 1686 |
\let\InCa@Space= #1% |
| 1687 |
}% |
| 1688 |
\x{ } |
| 1689 |
% \end{macrocode} |
| 1690 |
% \end{macro} |
| 1691 |
% \begin{macro}{\InCa@Add} |
| 1692 |
% \begin{macrocode} |
| 1693 |
\def\InCa@Add#1!#2!{% |
| 1694 |
\ifcase#2 % |
| 1695 |
#1% |
| 1696 |
\else |
| 1697 |
\InCa@@Add#1!#2!000000000\InCa@Space |
| 1698 |
\fi |
| 1699 |
} |
| 1700 |
% \end{macrocode} |
| 1701 |
% \end{macro} |
| 1702 |
% \begin{macro}{\InCa@Sub} |
| 1703 |
% \begin{macrocode} |
| 1704 |
\def\InCa@Sub#1!#2!{% |
| 1705 |
\ifnum#1=#2 % |
| 1706 |
0% |
| 1707 |
\else |
| 1708 |
\InCa@@Sub#1!#2!000000000\InCa@Space |
| 1709 |
\fi |
| 1710 |
} |
| 1711 |
% \end{macrocode} |
| 1712 |
% \end{macro} |
| 1713 |
% \begin{macro}{\InCa@@Add} |
| 1714 |
% \begin{macrocode} |
| 1715 |
\def\InCa@@Add#1!#2#3!{% |
| 1716 |
\ifx\InCa@Empty#3\InCa@Empty |
| 1717 |
\@ReturnAfterElseFi{% |
| 1718 |
\InCa@@@Add!!#1!#2% |
| 1719 |
}% |
| 1720 |
\else |
| 1721 |
\@ReturnAfterFi{% |
| 1722 |
\InCa@@Add#1!#3!#2% |
| 1723 |
}% |
| 1724 |
\fi |
| 1725 |
} |
| 1726 |
% \end{macrocode} |
| 1727 |
% \end{macro} |
| 1728 |
% \begin{macro}{\InCa@@Sub} |
| 1729 |
% \begin{macrocode} |
| 1730 |
\def\InCa@@Sub#1!#2#3!{% |
| 1731 |
\ifx\InCa@Empty#3\InCa@Empty |
| 1732 |
\@ReturnAfterElseFi{% |
| 1733 |
\InCa@@@Sub!!#1!#2% |
| 1734 |
}% |
| 1735 |
\else |
| 1736 |
\@ReturnAfterFi{% |
| 1737 |
\InCa@@Sub#1!#3!#2% |
| 1738 |
}% |
| 1739 |
\fi |
| 1740 |
} |
| 1741 |
% \end{macrocode} |
| 1742 |
% \end{macro} |
| 1743 |
% |
| 1744 |
% \begin{macro}{\InCa@@@Add} |
| 1745 |
% \begin{macrocode} |
| 1746 |
\def\InCa@@@Add#1!#2!#3#4!#5{% |
| 1747 |
\ifx\InCa@Empty#4\InCa@Empty |
| 1748 |
\csname InCa@Empty% |
| 1749 |
\@ReturnAfterElseFi{% |
| 1750 |
\InCa@ProcessAdd#1#3!#5#2% |
| 1751 |
}% |
| 1752 |
\else |
| 1753 |
\@ReturnAfterFi{% |
| 1754 |
\InCa@@@Add#1#3!#5#2!#4!% |
| 1755 |
}% |
| 1756 |
\fi |
| 1757 |
} |
| 1758 |
% \end{macrocode} |
| 1759 |
% \end{macro} |
| 1760 |
% \begin{macro}{\InCa@@@Sub} |
| 1761 |
% \begin{macrocode} |
| 1762 |
\def\InCa@@@Sub#1!#2!#3#4!#5{% |
| 1763 |
\ifx\InCa@Empty#4\InCa@Empty |
| 1764 |
\csname @gobble% |
| 1765 |
\@ReturnAfterElseFi{% |
| 1766 |
\InCa@ProcessSub#1#3!#5#2% |
| 1767 |
}% |
| 1768 |
\else |
| 1769 |
\@ReturnAfterFi{% |
| 1770 |
\InCa@@@Sub#1#3!#5#2!#4!% |
| 1771 |
}% |
| 1772 |
\fi |
| 1773 |
} |
| 1774 |
% \end{macrocode} |
| 1775 |
% \end{macro} |
| 1776 |
% |
| 1777 |
% \begin{macro}{\InCa@ProcessAdd} |
| 1778 |
% \begin{macrocode} |
| 1779 |
\def\InCa@ProcessAdd#1#2!#3#4{% |
| 1780 |
\ifx\InCa@Empty#2\InCa@Empty |
| 1781 |
\csname InCa@AddDigit#1\endcsname#3% |
| 1782 |
\romannumeral0#4% |
| 1783 |
\else |
| 1784 |
\csname InCa@AddDigit#1\csname InCa@DigitCarry#3% |
| 1785 |
\@ReturnAfterFi{% |
| 1786 |
\InCa@ProcessAdd#2!#4% |
| 1787 |
}% |
| 1788 |
\fi |
| 1789 |
} |
| 1790 |
% \end{macrocode} |
| 1791 |
% \end{macro} |
| 1792 |
% \begin{macro}{\InCa@ProcessSub} |
| 1793 |
% \begin{macrocode} |
| 1794 |
\def\InCa@ProcessSub#1#2!#3#4{% |
| 1795 |
\ifx\InCa@Empty#2\InCa@Empty |
| 1796 |
\csname InCa@SubDigit#1\endcsname#3% |
| 1797 |
\romannumeral0#4% |
| 1798 |
\else |
| 1799 |
\csname InCa@SubDigit#1\csname InCa@DigitCarry#3% |
| 1800 |
\@ReturnAfterFi{% |
| 1801 |
\InCa@ProcessSub#2!#4% |
| 1802 |
}% |
| 1803 |
\fi |
| 1804 |
} |
| 1805 |
% \end{macrocode} |
| 1806 |
% \end{macro} |
| 1807 |
% \begin{macro}{\InCa@DigitCarry[0-9]} |
| 1808 |
% \begin{macrocode} |
| 1809 |
\def\InCa@Temp#1#2{% |
| 1810 |
\expandafter\def\csname InCa@DigitCarry#1\endcsname##1{% |
| 1811 |
\ifcase##1 % |
| 1812 |
\endcsname#1% |
| 1813 |
\else |
| 1814 |
\endcsname#2% |
| 1815 |
\fi |
| 1816 |
}% |
| 1817 |
} |
| 1818 |
\InCa@Temp 01 |
| 1819 |
\InCa@Temp 12 |
| 1820 |
\InCa@Temp 23 |
| 1821 |
\InCa@Temp 34 |
| 1822 |
\InCa@Temp 45 |
| 1823 |
\InCa@Temp 56 |
| 1824 |
\InCa@Temp 67 |
| 1825 |
\InCa@Temp 78 |
| 1826 |
\InCa@Temp 89 |
| 1827 |
\InCa@Temp 9{{10}} |
| 1828 |
% \end{macrocode} |
| 1829 |
% \end{macro} |
| 1830 |
% |
| 1831 |
% \begin{macro}{\InCa@AddDigit0} |
| 1832 |
% \begin{macrocode} |
| 1833 |
\expandafter\def\csname InCa@AddDigit0\endcsname#1{% |
| 1834 |
\ifnum#1>9 % |
| 1835 |
\endcsname10% |
| 1836 |
\else |
| 1837 |
\endcsname0#1% |
| 1838 |
\fi |
| 1839 |
} |
| 1840 |
% \end{macrocode} |
| 1841 |
% \end{macro} |
| 1842 |
% \begin{macro}{\InCa@AddDigit[1-9]} |
| 1843 |
% \begin{macrocode} |
| 1844 |
\def\InCa@Temp#1#2#3{% |
| 1845 |
\expandafter\def\csname InCa@AddDigit#1\endcsname##1{% |
| 1846 |
\ifnum##1>#2 % |
| 1847 |
\endcsname 1% |
| 1848 |
\else |
| 1849 |
\endcsname 0% |
| 1850 |
\fi |
| 1851 |
\ifcase##1 #1% 0 |
| 1852 |
#3% |
| 1853 |
\else #1% 10 |
| 1854 |
\fi |
| 1855 |
}% |
| 1856 |
} |
| 1857 |
\InCa@Temp 18{% |
| 1858 |
\or 2% 1 |
| 1859 |
\or 3% 2 |
| 1860 |
\or 4% 3 |
| 1861 |
\or 5% 4 |
| 1862 |
\or 6% 5 |
| 1863 |
\or 7% 6 |
| 1864 |
\or 8% 7 |
| 1865 |
\or 9% 8 |
| 1866 |
\or 0% 9 |
| 1867 |
}% |
| 1868 |
\InCa@Temp 27{% |
| 1869 |
\or 3% 1 |
| 1870 |
\or 4% 2 |
| 1871 |
\or 5% 3 |
| 1872 |
\or 6% 4 |
| 1873 |
\or 7% 5 |
| 1874 |
\or 8% 6 |
| 1875 |
\or 9% 7 |
| 1876 |
\or 0% 8 |
| 1877 |
\or 1% 9 |
| 1878 |
}% |
| 1879 |
\InCa@Temp 36{% |
| 1880 |
\or 4% 1 |
| 1881 |
\or 5% 2 |
| 1882 |
\or 6% 3 |
| 1883 |
\or 7% 4 |
| 1884 |
\or 8% 5 |
| 1885 |
\or 9% 6 |
| 1886 |
\or 0% 7 |
| 1887 |
\or 1% 8 |
| 1888 |
\or 2% 9 |
| 1889 |
}% |
| 1890 |
\InCa@Temp 45{% |
| 1891 |
\or 5% 1 |
| 1892 |
\or 6% 2 |
| 1893 |
\or 7% 3 |
| 1894 |
\or 8% 4 |
| 1895 |
\or 9% 5 |
| 1896 |
\or 0% 6 |
| 1897 |
\or 1% 7 |
| 1898 |
\or 2% 8 |
| 1899 |
\or 3% 9 |
| 1900 |
}% |
| 1901 |
\InCa@Temp 54{% |
| 1902 |
\or 6% 1 |
| 1903 |
\or 7% 2 |
| 1904 |
\or 8% 3 |
| 1905 |
\or 9% 4 |
| 1906 |
\or 0% 5 |
| 1907 |
\or 1% 6 |
| 1908 |
\or 2% 7 |
| 1909 |
\or 3% 8 |
| 1910 |
\or 4% 9 |
| 1911 |
}% |
| 1912 |
\InCa@Temp 63{% |
| 1913 |
\or 7% 1 |
| 1914 |
\or 8% 2 |
| 1915 |
\or 9% 3 |
| 1916 |
\or 0% 4 |
| 1917 |
\or 1% 5 |
| 1918 |
\or 2% 6 |
| 1919 |
\or 3% 7 |
| 1920 |
\or 4% 8 |
| 1921 |
\or 5% 9 |
| 1922 |
}% |
| 1923 |
\InCa@Temp 72{% |
| 1924 |
\or 8% 1 |
| 1925 |
\or 9% 2 |
| 1926 |
\or 0% 3 |
| 1927 |
\or 1% 4 |
| 1928 |
\or 2% 5 |
| 1929 |
\or 3% 6 |
| 1930 |
\or 4% 7 |
| 1931 |
\or 5% 8 |
| 1932 |
\or 6% 9 |
| 1933 |
}% |
| 1934 |
\InCa@Temp 81{% |
| 1935 |
\or 9% 1 |
| 1936 |
\or 0% 2 |
| 1937 |
\or 1% 3 |
| 1938 |
\or 2% 4 |
| 1939 |
\or 3% 5 |
| 1940 |
\or 4% 6 |
| 1941 |
\or 5% 7 |
| 1942 |
\or 6% 8 |
| 1943 |
\or 7% 9 |
| 1944 |
}% |
| 1945 |
\InCa@Temp 90{% |
| 1946 |
\or 0% 1 |
| 1947 |
\or 1% 2 |
| 1948 |
\or 2% 3 |
| 1949 |
\or 3% 4 |
| 1950 |
\or 4% 5 |
| 1951 |
\or 5% 6 |
| 1952 |
\or 6% 7 |
| 1953 |
\or 7% 8 |
| 1954 |
\or 8% 9 |
| 1955 |
}% |
| 1956 |
% \end{macrocode} |
| 1957 |
% \end{macro} |
| 1958 |
% |
| 1959 |
% \begin{macro}{\InCa@SubDigit[0-9]} |
| 1960 |
% \begin{macrocode} |
| 1961 |
\def\InCa@Temp#1#2{% |
| 1962 |
\expandafter\def\csname InCa@SubDigit#1\endcsname##1{% |
| 1963 |
\ifnum##1>#1 % |
| 1964 |
\endcsname 1% |
| 1965 |
\else |
| 1966 |
\endcsname 0% |
| 1967 |
\fi |
| 1968 |
\ifcase##1 #1% 0 |
| 1969 |
#2% |
| 1970 |
\else #1% 10 |
| 1971 |
\fi |
| 1972 |
}% |
| 1973 |
} |
| 1974 |
\InCa@Temp 0{% |
| 1975 |
\or 9% 1 |
| 1976 |
\or 8% 2 |
| 1977 |
\or 7% 3 |
| 1978 |
\or 6% 4 |
| 1979 |
\or 5% 5 |
| 1980 |
\or 4% 6 |
| 1981 |
\or 3% 7 |
| 1982 |
\or 2% 8 |
| 1983 |
\or 1% 9 |
| 1984 |
} |
| 1985 |
\InCa@Temp 1{% |
| 1986 |
\or 0% 1 |
| 1987 |
\or 9% 2 |
| 1988 |
\or 8% 3 |
| 1989 |
\or 7% 4 |
| 1990 |
\or 6% 5 |
| 1991 |
\or 5% 6 |
| 1992 |
\or 4% 7 |
| 1993 |
\or 3% 8 |
| 1994 |
\or 2% 9 |
| 1995 |
} |
| 1996 |
\InCa@Temp 2{% |
| 1997 |
\or 1% 1 |
| 1998 |
\or 0% 2 |
| 1999 |
\or 9% 3 |
| 2000 |
\or 8% 4 |
| 2001 |
\or 7% 5 |
| 2002 |
\or 6% 6 |
| 2003 |
\or 5% 7 |
| 2004 |
\or 4% 8 |
| 2005 |
\or 3% 9 |
| 2006 |
} |
| 2007 |
\InCa@Temp 3{% |
| 2008 |
\or 2% 1 |
| 2009 |
\or 1% 2 |
| 2010 |
\or 0% 3 |
| 2011 |
\or 9% 4 |
| 2012 |
\or 8% 5 |
| 2013 |
\or 7% 6 |
| 2014 |
\or 6% 7 |
| 2015 |
\or 5% 8 |
| 2016 |
\or 4% 9 |
| 2017 |
} |
| 2018 |
\InCa@Temp 4{% |
| 2019 |
\or 3% 1 |
| 2020 |
\or 2% 2 |
| 2021 |
\or 1% 3 |
| 2022 |
\or 0% 4 |
| 2023 |
\or 9% 5 |
| 2024 |
\or 8% 6 |
| 2025 |
\or 7% 7 |
| 2026 |
\or 6% 8 |
| 2027 |
\or 5% 9 |
| 2028 |
} |
| 2029 |
\InCa@Temp 5{% |
| 2030 |
\or 4% 1 |
| 2031 |
\or 3% 2 |
| 2032 |
\or 2% 3 |
| 2033 |
\or 1% 4 |
| 2034 |
\or 0% 5 |
| 2035 |
\or 9% 6 |
| 2036 |
\or 8% 7 |
| 2037 |
\or 7% 8 |
| 2038 |
\or 6% 9 |
| 2039 |
} |
| 2040 |
\InCa@Temp 6{% |
| 2041 |
\or 5% 1 |
| 2042 |
\or 4% 2 |
| 2043 |
\or 3% 3 |
| 2044 |
\or 2% 4 |
| 2045 |
\or 1% 5 |
| 2046 |
\or 0% 6 |
| 2047 |
\or 9% 7 |
| 2048 |
\or 8% 8 |
| 2049 |
\or 7% 9 |
| 2050 |
} |
| 2051 |
\InCa@Temp 7{% |
| 2052 |
\or 6% 1 |
| 2053 |
\or 5% 2 |
| 2054 |
\or 4% 3 |
| 2055 |
\or 3% 4 |
| 2056 |
\or 2% 5 |
| 2057 |
\or 1% 6 |
| 2058 |
\or 0% 7 |
| 2059 |
\or 9% 8 |
| 2060 |
\or 8% 9 |
| 2061 |
} |
| 2062 |
\InCa@Temp 8{% |
| 2063 |
\or 7% 1 |
| 2064 |
\or 6% 2 |
| 2065 |
\or 5% 3 |
| 2066 |
\or 4% 4 |
| 2067 |
\or 3% 5 |
| 2068 |
\or 2% 6 |
| 2069 |
\or 1% 7 |
| 2070 |
\or 0% 8 |
| 2071 |
\or 9% 9 |
| 2072 |
} |
| 2073 |
\InCa@Temp 9{% |
| 2074 |
\or 8% 1 |
| 2075 |
\or 7% 2 |
| 2076 |
\or 6% 3 |
| 2077 |
\or 5% 4 |
| 2078 |
\or 4% 5 |
| 2079 |
\or 3% 6 |
| 2080 |
\or 2% 7 |
| 2081 |
\or 1% 8 |
| 2082 |
\or 0% 9 |
| 2083 |
} |
| 2084 |
% \end{macrocode} |
| 2085 |
% \end{macro} |
| 2086 |
% |
| 2087 |
% \subsubsection{\op{Shl}, \op{Shr}} |
| 2088 |
% |
| 2089 |
% \begin{macro}{\intcalcShl} |
| 2090 |
% \begin{macrocode} |
| 2091 |
\def\intcalcShl#1{% |
| 2092 |
\number\expandafter\InCa@ShlSwitch\number#1! % |
| 2093 |
} |
| 2094 |
% \end{macrocode} |
| 2095 |
% \end{macro} |
| 2096 |
% \begin{macro}{\InCa@ShlSwitch} |
| 2097 |
% \begin{macrocode} |
| 2098 |
\def\InCa@ShlSwitch#1#2!{% |
| 2099 |
\ifx#1-% |
| 2100 |
-\csname InCa@Empty% |
| 2101 |
\InCa@Shl#2!% |
| 2102 |
\else |
| 2103 |
\csname InCa@Empty% |
| 2104 |
\InCa@Shl#1#2!% |
| 2105 |
\fi |
| 2106 |
} |
| 2107 |
% \end{macrocode} |
| 2108 |
% \end{macro} |
| 2109 |
% \begin{macro}{\IntCalcShl} |
| 2110 |
% \begin{macrocode} |
| 2111 |
\def\IntCalcShl#1!{% |
| 2112 |
\number |
| 2113 |
\csname InCa@Empty% |
| 2114 |
\InCa@Shl#1! % |
| 2115 |
} |
| 2116 |
% \end{macrocode} |
| 2117 |
% \end{macro} |
| 2118 |
% \begin{macro}{\IntCal@ShlDigit} |
| 2119 |
% \begin{macrocode} |
| 2120 |
\def\InCa@Shl#1#2{% |
| 2121 |
\ifx#2!% |
| 2122 |
\csname InCa@ShlDigit#1\endcsname0% |
| 2123 |
\else |
| 2124 |
\csname InCa@ShlDigit#1% |
| 2125 |
\@ReturnAfterFi{% |
| 2126 |
\InCa@Shl#2% |
| 2127 |
}% |
| 2128 |
\fi |
| 2129 |
} |
| 2130 |
% \end{macrocode} |
| 2131 |
% \end{macro} |
| 2132 |
% \begin{macro}{\InCa@ShlDigit0} |
| 2133 |
% \begin{macrocode} |
| 2134 |
\expandafter\def\csname InCa@ShlDigit0\endcsname{% |
| 2135 |
\endcsname0% |
| 2136 |
} |
| 2137 |
% \end{macrocode} |
| 2138 |
% \end{macro} |
| 2139 |
% \begin{macro}{\InCa@ShlDigit[1-9]} |
| 2140 |
% \begin{macrocode} |
| 2141 |
\def\InCa@Temp#1#2#3#4#5{% |
| 2142 |
\expandafter\def\csname InCa@ShlDigit#1\endcsname##1{% |
| 2143 |
\expandafter\endcsname |
| 2144 |
\ifcase##1 % |
| 2145 |
#2#3% |
| 2146 |
\else |
| 2147 |
#4#5% |
| 2148 |
\fi |
| 2149 |
}% |
| 2150 |
} |
| 2151 |
\InCa@Temp 10203 |
| 2152 |
\InCa@Temp 20405 |
| 2153 |
\InCa@Temp 30607 |
| 2154 |
\InCa@Temp 40809 |
| 2155 |
\InCa@Temp 51011 |
| 2156 |
\InCa@Temp 61213 |
| 2157 |
\InCa@Temp 71415 |
| 2158 |
\InCa@Temp 81617 |
| 2159 |
\InCa@Temp 91819 |
| 2160 |
% \end{macrocode} |
| 2161 |
% \end{macro} |
| 2162 |
% |
| 2163 |
% \begin{macro}{\intcalcShr} |
| 2164 |
% \begin{macrocode} |
| 2165 |
\def\intcalcShr#1{% |
| 2166 |
\number\expandafter\InCa@ShrSwitch\number#1! % |
| 2167 |
} |
| 2168 |
% \end{macrocode} |
| 2169 |
% \end{macro} |
| 2170 |
% \begin{macro}{\InCa@ShrSwitch} |
| 2171 |
% \begin{macrocode} |
| 2172 |
\def\InCa@ShrSwitch#1#2!{% |
| 2173 |
\ifx#1-% |
| 2174 |
-\InCa@Shr#2!% |
| 2175 |
\else |
| 2176 |
\InCa@Shr#1#2!% |
| 2177 |
\fi |
| 2178 |
} |
| 2179 |
% \end{macrocode} |
| 2180 |
% \end{macro} |
| 2181 |
% \begin{macro}{\IntCalcShr} |
| 2182 |
% \begin{macrocode} |
| 2183 |
\def\IntCalcShr#1!{% |
| 2184 |
\number\InCa@Shr#1! % |
| 2185 |
} |
| 2186 |
% \end{macrocode} |
| 2187 |
% \end{macro} |
| 2188 |
% \begin{macro}{\InCa@Shr} |
| 2189 |
% \begin{macrocode} |
| 2190 |
\def\InCa@Shr#1#2{% |
| 2191 |
\InCa@ShrDigit#1!% |
| 2192 |
\ifx#2!% |
| 2193 |
\else |
| 2194 |
\@ReturnAfterFi{% |
| 2195 |
\ifodd#1 % |
| 2196 |
\@ReturnAfterElseFi{% |
| 2197 |
\InCa@Shr{1#2}% |
| 2198 |
}% |
| 2199 |
\else |
| 2200 |
\expandafter\InCa@Shr\expandafter#2% |
| 2201 |
\fi |
| 2202 |
}% |
| 2203 |
\fi |
| 2204 |
} |
| 2205 |
% \end{macrocode} |
| 2206 |
% \end{macro} |
| 2207 |
% \begin{macrocode} |
| 2208 |
\def\InCa@ShrDigit#1!{% |
| 2209 |
\ifcase#1 0% 0 |
| 2210 |
\or 0% 1 |
| 2211 |
\or 1% 2 |
| 2212 |
\or 1% 3 |
| 2213 |
\or 2% 4 |
| 2214 |
\or 2% 5 |
| 2215 |
\or 3% 6 |
| 2216 |
\or 3% 7 |
| 2217 |
\or 4% 8 |
| 2218 |
\or 4% 9 |
| 2219 |
\or 5% 10 |
| 2220 |
\or 5% 11 |
| 2221 |
\or 6% 12 |
| 2222 |
\or 6% 13 |
| 2223 |
\or 7% 14 |
| 2224 |
\or 7% 15 |
| 2225 |
\or 8% 16 |
| 2226 |
\or 8% 17 |
| 2227 |
\or 9% 18 |
| 2228 |
\or 9% 19 |
| 2229 |
\fi |
| 2230 |
} |
| 2231 |
% \end{macrocode} |
| 2232 |
% |
| 2233 |
% \subsubsection{\cs{InCa@Tim}} |
| 2234 |
% |
| 2235 |
% \begin{macro}{\InCa@Tim} |
| 2236 |
% Macro \cs{InCa@Tim} implements |
| 2237 |
% ``Number \emph{tim}es digit''. |
| 2238 |
% \begin{macrocode} |
| 2239 |
\def\InCa@Temp#1{% |
| 2240 |
\def\InCa@Tim##1##2{% |
| 2241 |
\number |
| 2242 |
\ifcase##2 % 0 |
| 2243 |
0% |
| 2244 |
\or % 1 |
| 2245 |
##1% |
| 2246 |
\else % 2-9 |
| 2247 |
\csname InCa@Empty% |
| 2248 |
\InCa@ProcessTim##2##1!% |
| 2249 |
\fi |
| 2250 |
#1% |
| 2251 |
}% |
| 2252 |
} |
| 2253 |
\InCa@Temp{ } |
| 2254 |
% \end{macrocode} |
| 2255 |
% \end{macro} |
| 2256 |
% \begin{macro}{\InCa@ProcessTim} |
| 2257 |
% \begin{macrocode} |
| 2258 |
\def\InCa@ProcessTim#1#2#3{% |
| 2259 |
\ifx#3!% |
| 2260 |
\csname InCa@TimDigit#2\endcsname#10% |
| 2261 |
\else |
| 2262 |
\csname InCa@TimDigit#2\csname InCa@Param#1% |
| 2263 |
\@ReturnAfterFi{% |
| 2264 |
\InCa@ProcessTim#1#3% |
| 2265 |
}% |
| 2266 |
\fi |
| 2267 |
} |
| 2268 |
% \end{macrocode} |
| 2269 |
% \end{macro} |
| 2270 |
% \begin{macro}{\InCa@Param[0-9]} |
| 2271 |
% \begin{macrocode} |
| 2272 |
\def\InCa@Temp#1{% |
| 2273 |
\expandafter\def\csname InCa@Param#1\endcsname{% |
| 2274 |
\endcsname#1% |
| 2275 |
}% |
| 2276 |
} |
| 2277 |
\InCa@Temp 0% |
| 2278 |
\InCa@Temp 1% |
| 2279 |
\InCa@Temp 2% |
| 2280 |
\InCa@Temp 3% |
| 2281 |
\InCa@Temp 4% |
| 2282 |
\InCa@Temp 5% |
| 2283 |
\InCa@Temp 6% |
| 2284 |
\InCa@Temp 7% |
| 2285 |
\InCa@Temp 8% |
| 2286 |
\InCa@Temp 9% |
| 2287 |
% \end{macrocode} |
| 2288 |
% \end{macro} |
| 2289 |
% \begin{macro}{\InCa@TimDigit0} |
| 2290 |
% \begin{macrocode} |
| 2291 |
\expandafter\def\csname InCa@TimDigit0\endcsname#1#2{% |
| 2292 |
\endcsname |
| 2293 |
0#2% |
| 2294 |
} |
| 2295 |
% \end{macrocode} |
| 2296 |
% \end{macro} |
| 2297 |
% \begin{macro}{\InCa@TimDigit1} |
| 2298 |
% \begin{macrocode} |
| 2299 |
\expandafter\def\csname InCa@TimDigit1\endcsname#1#2{% |
| 2300 |
\ifcase#2 % |
| 2301 |
\endcsname 0#1% |
| 2302 |
\else |
| 2303 |
\csname InCa@AddDigit#1\endcsname #2% |
| 2304 |
\fi |
| 2305 |
} |
| 2306 |
% \end{macrocode} |
| 2307 |
% \end{macro} |
| 2308 |
% \begin{macro}{\InCa@TimDigit[2-9]} |
| 2309 |
% \begin{macrocode} |
| 2310 |
\def\InCa@Temp#1#2{% |
| 2311 |
\expandafter\def\csname InCa@TimDigit#1\endcsname##1{% |
| 2312 |
\expandafter\InCa@TimDigitCarry |
| 2313 |
\number |
| 2314 |
\ifcase##1 0% 0 |
| 2315 |
#2% |
| 2316 |
\fi |
| 2317 |
!% |
| 2318 |
}% |
| 2319 |
} |
| 2320 |
\InCa@Temp 2{% |
| 2321 |
\or 2% 1 |
| 2322 |
\or 4% 2 |
| 2323 |
\or 6% 3 |
| 2324 |
\or 8% 4 |
| 2325 |
\or 10% 5 |
| 2326 |
\or 12% 6 |
| 2327 |
\or 14% 7 |
| 2328 |
\or 16% 8 |
| 2329 |
\or 18% 9 |
| 2330 |
} |
| 2331 |
\InCa@Temp 3{% |
| 2332 |
\or 3% 1 |
| 2333 |
\or 6% 2 |
| 2334 |
\or 9% 3 |
| 2335 |
\or 12% 4 |
| 2336 |
\or 15% 5 |
| 2337 |
\or 18% 6 |
| 2338 |
\or 21% 7 |
| 2339 |
\or 24% 8 |
| 2340 |
\or 27% 9 |
| 2341 |
} |
| 2342 |
\InCa@Temp 4{% |
| 2343 |
\or 4% 1 |
| 2344 |
\or 8% 2 |
| 2345 |
\or 12% 3 |
| 2346 |
\or 16% 4 |
| 2347 |
\or 20% 5 |
| 2348 |
\or 24% 6 |
| 2349 |
\or 28% 7 |
| 2350 |
\or 32% 8 |
| 2351 |
\or 36% 9 |
| 2352 |
} |
| 2353 |
\InCa@Temp 5{% |
| 2354 |
\or 5% 1 |
| 2355 |
\or 10% 2 |
| 2356 |
\or 15% 3 |
| 2357 |
\or 20% 4 |
| 2358 |
\or 25% 5 |
| 2359 |
\or 30% 6 |
| 2360 |
\or 35% 7 |
| 2361 |
\or 40% 8 |
| 2362 |
\or 45% 9 |
| 2363 |
} |
| 2364 |
\InCa@Temp 6{% |
| 2365 |
\or 6% 1 |
| 2366 |
\or 12% 2 |
| 2367 |
\or 18% 3 |
| 2368 |
\or 24% 4 |
| 2369 |
\or 30% 5 |
| 2370 |
\or 36% 6 |
| 2371 |
\or 42% 7 |
| 2372 |
\or 48% 8 |
| 2373 |
\or 54% 9 |
| 2374 |
} |
| 2375 |
\InCa@Temp 7{% |
| 2376 |
\or 7% 1 |
| 2377 |
\or 14% 2 |
| 2378 |
\or 21% 3 |
| 2379 |
\or 28% 4 |
| 2380 |
\or 35% 5 |
| 2381 |
\or 42% 6 |
| 2382 |
\or 49% 7 |
| 2383 |
\or 56% 8 |
| 2384 |
\or 63% 9 |
| 2385 |
} |
| 2386 |
\InCa@Temp 8{% |
| 2387 |
\or 8% 1 |
| 2388 |
\or 16% 2 |
| 2389 |
\or 24% 3 |
| 2390 |
\or 32% 4 |
| 2391 |
\or 40% 5 |
| 2392 |
\or 48% 6 |
| 2393 |
\or 56% 7 |
| 2394 |
\or 64% 8 |
| 2395 |
\or 72% 9 |
| 2396 |
} |
| 2397 |
\InCa@Temp 9{% |
| 2398 |
\or 9% 1 |
| 2399 |
\or 18% 2 |
| 2400 |
\or 27% 3 |
| 2401 |
\or 36% 4 |
| 2402 |
\or 45% 5 |
| 2403 |
\or 54% 6 |
| 2404 |
\or 63% 7 |
| 2405 |
\or 72% 8 |
| 2406 |
\or 81% 9 |
| 2407 |
} |
| 2408 |
% \end{macrocode} |
| 2409 |
% \end{macro} |
| 2410 |
% \begin{macro}{\InCa@TimDigitCarry} |
| 2411 |
% \begin{macrocode} |
| 2412 |
\def\InCa@TimDigitCarry#1!{% |
| 2413 |
\ifnum#1<10 % |
| 2414 |
\csname InCa@AddDigit#1\expandafter\endcsname |
| 2415 |
\else |
| 2416 |
\@ReturnAfterFi{% |
| 2417 |
\InCa@@TimDigitCarry#1!% |
| 2418 |
}% |
| 2419 |
\fi |
| 2420 |
} |
| 2421 |
% \end{macrocode} |
| 2422 |
% \end{macro} |
| 2423 |
% \begin{macro}{\InCa@@TimDigitCarry} |
| 2424 |
% \begin{macrocode} |
| 2425 |
\def\InCa@@TimDigitCarry#1#2!#3{% |
| 2426 |
\csname InCa@DigitCarry#1% |
| 2427 |
\csname InCa@AddDigit#2\endcsname #3% |
| 2428 |
} |
| 2429 |
% \end{macrocode} |
| 2430 |
% \end{macro} |
| 2431 |
% |
| 2432 |
% \subsubsection{\op{Mul}} |
| 2433 |
% |
| 2434 |
% \begin{macro}{\intcalcMul} |
| 2435 |
% \begin{macrocode} |
| 2436 |
\def\intcalcMul#1#2{% |
| 2437 |
\number |
| 2438 |
\expandafter\InCa@MulSwitch |
| 2439 |
\number\number#1\expandafter!% |
| 2440 |
\number#2! % |
| 2441 |
} |
| 2442 |
% \end{macrocode} |
| 2443 |
% \end{macro} |
| 2444 |
% |
| 2445 |
% \begin{macro}{\InCa@MulSwitch} |
| 2446 |
% Decision table for \cs{InCa@MulSwitch}. |
| 2447 |
% \begin{quote} |
| 2448 |
% \begin{tabular}[t]{@{}|l|l|l|l|l|@{}} |
| 2449 |
% \hline |
| 2450 |
% $x<0$ & $y<0$ & $ x< y$ & $+$ & $\opMul(-x,-y)$\\ |
| 2451 |
% \cline{3-3}\cline{5-5} |
| 2452 |
% & & else & & $\opMul(-y,-x)$\\ |
| 2453 |
% \cline{2-5} |
| 2454 |
% & else & $-x> y$ & $-$ & $\opMul(-x, y)$\\ |
| 2455 |
% \cline{3-3}\cline{5-5} |
| 2456 |
% & & else & & $\opMul( y,-x)$\\ |
| 2457 |
% \hline |
| 2458 |
% else & $y<0$ & $ x>-y$ & $-$ & $\opMul( x,-y)$\\ |
| 2459 |
% \cline{3-3}\cline{5-5} |
| 2460 |
% & & else & & $\opMul(-y, x)$\\ |
| 2461 |
% \cline{2-5} |
| 2462 |
% & else & $ x> y$ & $+$ & $\opMul( x, y)$\\ |
| 2463 |
% \cline{3-3}\cline{5-5} |
| 2464 |
% & & else & & $\opMul( y, x)$\\ |
| 2465 |
% \hline |
| 2466 |
% \end{tabular} |
| 2467 |
% \end{quote} |
| 2468 |
% \begin{macrocode} |
| 2469 |
\def\InCa@MulSwitch#1!#2!{% |
| 2470 |
\ifnum#1<\z@ |
| 2471 |
\ifnum#2<\z@ |
| 2472 |
\ifnum#1<#2 % |
| 2473 |
\expandafter\InCa@Mul\number-#1\expandafter!% |
| 2474 |
\@gobble#2!% |
| 2475 |
\else |
| 2476 |
\expandafter\InCa@Mul\number-#2\expandafter!% |
| 2477 |
\@gobble#1!% |
| 2478 |
\fi |
| 2479 |
\else |
| 2480 |
-% |
| 2481 |
\ifnum-#1>#2 % |
| 2482 |
\expandafter\InCa@Mul\@gobble#1!#2!% |
| 2483 |
\else |
| 2484 |
\expandafter\InCa@Mul\number#2\expandafter!% |
| 2485 |
\@gobble#1!% |
| 2486 |
\fi |
| 2487 |
\fi |
| 2488 |
\else |
| 2489 |
\ifnum#2<\z@ |
| 2490 |
-% |
| 2491 |
\ifnum#1>-#2 % |
| 2492 |
\expandafter\InCa@Mul\number#1\expandafter!% |
| 2493 |
\@gobble#2!% |
| 2494 |
\else |
| 2495 |
\expandafter\InCa@Mul\@gobble#2!#1!% |
| 2496 |
\fi |
| 2497 |
\else |
| 2498 |
\ifnum#1>#2 % |
| 2499 |
\InCa@Mul#1!#2!% |
| 2500 |
\else |
| 2501 |
\InCa@Mul#2!#1!% |
| 2502 |
\fi |
| 2503 |
\fi |
| 2504 |
\fi |
| 2505 |
} |
| 2506 |
% \end{macrocode} |
| 2507 |
% \end{macro} |
| 2508 |
% \begin{macro}{\IntCalcMul} |
| 2509 |
% \begin{macrocode} |
| 2510 |
\def\IntCalcMul#1!#2!{% |
| 2511 |
\number\InCa@Mul#1!#2! % |
| 2512 |
} |
| 2513 |
% \end{macrocode} |
| 2514 |
% \end{macro} |
| 2515 |
% \begin{macro}{\InCa@Mul} |
| 2516 |
% \begin{macrocode} |
| 2517 |
\def\InCa@Mul#1!#2!{% |
| 2518 |
\ifcase#2 % |
| 2519 |
0% |
| 2520 |
\or |
| 2521 |
#1% |
| 2522 |
\or |
| 2523 |
\csname InCa@Empty% |
| 2524 |
\expandafter\InCa@Shl#1!% |
| 2525 |
\else |
| 2526 |
\ifnum#2<10 % |
| 2527 |
\InCa@Tim{#1}#2% |
| 2528 |
\else |
| 2529 |
\InCa@ProcessMul!#2!#1!% |
| 2530 |
\fi |
| 2531 |
\fi |
| 2532 |
} |
| 2533 |
% \end{macrocode} |
| 2534 |
% \end{macro} |
| 2535 |
% \begin{macro}{\InCa@Mul} |
| 2536 |
% \begin{macrocode} |
| 2537 |
\def\InCa@ProcessMul#1!#2#3!#4!{% |
| 2538 |
\ifx\InCa@Empty#3\InCa@Empty |
| 2539 |
\expandafter\InCa@Add\number |
| 2540 |
#10\expandafter\expandafter\expandafter!% |
| 2541 |
\InCa@Tim{#4}#2!% |
| 2542 |
\else |
| 2543 |
\ifx\InCa@Empty#1\InCa@Empty |
| 2544 |
\expandafter\expandafter\expandafter\InCa@ProcessMul |
| 2545 |
\InCa@Tim{#4}#2!% |
| 2546 |
#3!#4!% |
| 2547 |
\else |
| 2548 |
\expandafter\InCa@ProcessMul\number |
| 2549 |
\expandafter\InCa@Add\number% |
| 2550 |
#10\expandafter\expandafter\expandafter!% |
| 2551 |
\InCa@Tim{#4}#2!!% |
| 2552 |
#3!#4!% |
| 2553 |
\fi |
| 2554 |
\fi |
| 2555 |
} |
| 2556 |
% \end{macrocode} |
| 2557 |
% \end{macro} |
| 2558 |
% |
| 2559 |
% \subsubsection{\op{Sqr}, \op{Fac}} |
| 2560 |
% |
| 2561 |
% \begin{macro}{\intcalcSqr} |
| 2562 |
% \begin{macrocode} |
| 2563 |
\def\intcalcSqr#1{% |
| 2564 |
\number\expandafter\InCa@Sqr\number#1! % |
| 2565 |
} |
| 2566 |
% \end{macrocode} |
| 2567 |
% \end{macro} |
| 2568 |
% \begin{macro}{\InCa@Sqr} |
| 2569 |
% \begin{macrocode} |
| 2570 |
\def\InCa@Sqr#1#2!{% |
| 2571 |
\ifx#1-% |
| 2572 |
\InCa@Mul#2!#2!% |
| 2573 |
\else |
| 2574 |
\InCa@Mul#1#2!#1#2!% |
| 2575 |
\fi |
| 2576 |
} |
| 2577 |
% \end{macrocode} |
| 2578 |
% \end{macro} |
| 2579 |
% |
| 2580 |
% \begin{macro}{\intcalcFac} |
| 2581 |
% \begin{macrocode} |
| 2582 |
\def\intcalcFac#1{% |
| 2583 |
\number\expandafter\InCa@Fac\number#1! % |
| 2584 |
} |
| 2585 |
% \end{macrocode} |
| 2586 |
% \end{macro} |
| 2587 |
% |
| 2588 |
% \subsubsection{\op{Pow}} |
| 2589 |
% |
| 2590 |
% \begin{macro}{\intcalcPow} |
| 2591 |
% \begin{macrocode} |
| 2592 |
\def\intcalcPow#1#2{% |
| 2593 |
\number\expandafter\InCa@Pow |
| 2594 |
\number\number#1\expandafter!% |
| 2595 |
\number#2! % |
| 2596 |
} |
| 2597 |
% \end{macrocode} |
| 2598 |
% \end{macro} |
| 2599 |
% \begin{macro}{\InCa@Pow} |
| 2600 |
% \begin{macrocode} |
| 2601 |
\def\InCa@Pow#1#2!#3#4!{% |
| 2602 |
\ifcase#3#4 % power = 0 |
| 2603 |
1% |
| 2604 |
\or % power = 1 |
| 2605 |
#1#2% |
| 2606 |
\or % power = 2 |
| 2607 |
\ifx#1-% |
| 2608 |
\InCa@Mul#2!#2!% |
| 2609 |
\else |
| 2610 |
\InCa@Mul#1#2!#1#2!% |
| 2611 |
\fi |
| 2612 |
\else |
| 2613 |
\ifcase#1#2 % basis = 0, power <> 0 |
| 2614 |
0% |
| 2615 |
\ifx#3-% power < 0 |
| 2616 |
0\IntCalcError:DivisionByZero% |
| 2617 |
\fi |
| 2618 |
\or |
| 2619 |
1% basis = 1 |
| 2620 |
\else |
| 2621 |
\ifnum#1#2=\m@ne % basis = -1 |
| 2622 |
\ifodd#3#4 % |
| 2623 |
-% |
| 2624 |
\fi |
| 2625 |
1% |
| 2626 |
\else % |basis| > 1 |
| 2627 |
\ifx#3-% power < 0 |
| 2628 |
0% |
| 2629 |
\else % power > 2 |
| 2630 |
\ifx#1-% basis < 0 |
| 2631 |
\ifodd#3#4 % |
| 2632 |
-% |
| 2633 |
\fi |
| 2634 |
\InCa@PowRec#2!#3#4!1!% |
| 2635 |
\else |
| 2636 |
\InCa@PowRec#1#2!#3#4!1!% |
| 2637 |
\fi |
| 2638 |
\fi |
| 2639 |
\fi |
| 2640 |
\fi |
| 2641 |
\fi |
| 2642 |
} |
| 2643 |
% \end{macrocode} |
| 2644 |
% \end{macro} |
| 2645 |
% \begin{macro}{\InCa@PowRec} |
| 2646 |
%\begin{quote} |
| 2647 |
%\begin{verbatim} |
| 2648 |
%Pow(b, p) { |
| 2649 |
% PowRec(b, p, 1) |
| 2650 |
%} |
| 2651 |
%PowRec(b, p, r) { |
| 2652 |
% if p == 1 then |
| 2653 |
% return r |
| 2654 |
% else |
| 2655 |
% ifodd p then |
| 2656 |
% return PowRec(b*b, p div 2, r*b) % p div 2 = (p-1)/2 |
| 2657 |
% else |
| 2658 |
% return PowRec(b*b, p div 2, r) |
| 2659 |
% fi |
| 2660 |
% fi |
| 2661 |
%} |
| 2662 |
%\end{verbatim} |
| 2663 |
%\end{quote} |
| 2664 |
% \begin{macrocode} |
| 2665 |
\def\InCa@PowRec#1!#2!#3!{% |
| 2666 |
\ifnum#2=\@ne |
| 2667 |
\ifnum#1>#3 % |
| 2668 |
\InCa@Mul#1!#3!% |
| 2669 |
\else |
| 2670 |
\InCa@Mul#3!#1!% |
| 2671 |
\fi |
| 2672 |
\else |
| 2673 |
\expandafter\InCa@PowRec |
| 2674 |
\number\InCa@Mul#1!#1!\expandafter!% |
| 2675 |
\number\intcalcShr{#2}\expandafter!% |
| 2676 |
\number |
| 2677 |
\ifodd#2 % |
| 2678 |
\ifnum#1>#3 % |
| 2679 |
\InCa@Mul#1!#3!% |
| 2680 |
\else |
| 2681 |
\InCa@Mul#3!#1!% |
| 2682 |
\fi |
| 2683 |
\else |
| 2684 |
#3% |
| 2685 |
\fi |
| 2686 |
\expandafter!% |
| 2687 |
\fi |
| 2688 |
} |
| 2689 |
% \end{macrocode} |
| 2690 |
% \end{macro} |
| 2691 |
% |
| 2692 |
% \subsubsection{\op{Div}} |
| 2693 |
% |
| 2694 |
% \begin{macro}{\intcalcDiv} |
| 2695 |
% \begin{macrocode} |
| 2696 |
\def\intcalcDiv#1#2{% |
| 2697 |
\number\expandafter\InCa@Div |
| 2698 |
\number\number#1\expandafter!% |
| 2699 |
\number#2! % |
| 2700 |
} |
| 2701 |
% \end{macrocode} |
| 2702 |
% \end{macro} |
| 2703 |
% \begin{macro}{\InCa@Div} |
| 2704 |
% \begin{macrocode} |
| 2705 |
\def\InCa@Div#1!#2!{% |
| 2706 |
\ifcase#2 % |
| 2707 |
0\IntCalcError:DivisionByZero% |
| 2708 |
\else |
| 2709 |
\ifcase#1 % |
| 2710 |
0% |
| 2711 |
\else |
| 2712 |
\expandafter\InCa@DivSwitch |
| 2713 |
\number#1\expandafter!% |
| 2714 |
\number#2!% |
| 2715 |
\fi |
| 2716 |
\fi |
| 2717 |
} |
| 2718 |
% \end{macrocode} |
| 2719 |
% \end{macro} |
| 2720 |
% \begin{macro}{\IntCalcDiv} |
| 2721 |
% \begin{macrocode} |
| 2722 |
\def\InCa@Temp#1{% |
| 2723 |
\def\IntCalcDiv##1!##2!{% |
| 2724 |
\number |
| 2725 |
\ifcase##2 % |
| 2726 |
0\IntCalcError:DivisionByZero% |
| 2727 |
\else |
| 2728 |
\ifcase##1 % |
| 2729 |
0% |
| 2730 |
\else |
| 2731 |
\InCa@@Div##1!##2!% |
| 2732 |
\fi |
| 2733 |
\fi |
| 2734 |
#1% |
| 2735 |
}% |
| 2736 |
} |
| 2737 |
\InCa@Temp{ }% |
| 2738 |
% \end{macrocode} |
| 2739 |
% \end{macro} |
| 2740 |
% \begin{macro}{\InCa@DivSwitch} |
| 2741 |
% Decision table for \cs{InCa@DivSwitch}. |
| 2742 |
% \begin{quote} |
| 2743 |
% \begin{tabular}[t]{@{}|l|l|l|l|@{}} |
| 2744 |
% \hline |
| 2745 |
% $x<0$ & $y<0$ & $+$ & $\opDiv(-x,-y)$\\ |
| 2746 |
% \cline{2-4} |
| 2747 |
% & else & $-$ & $\opDiv(-x, y)$\\ |
| 2748 |
% \hline |
| 2749 |
% else & $y<0$ & $-$ & $\opDiv( x,-y)$\\ |
| 2750 |
% \cline{2-4} |
| 2751 |
% & else & $+$ & $\opDiv( x, y)$\\ |
| 2752 |
% \hline |
| 2753 |
% \end{tabular} |
| 2754 |
% \end{quote} |
| 2755 |
% \begin{macrocode} |
| 2756 |
\def\InCa@DivSwitch#1!#2!{% |
| 2757 |
\ifnum#1<\z@ |
| 2758 |
\ifnum#2<\z@ |
| 2759 |
\expandafter\InCa@@Div\number-#1\expandafter!% |
| 2760 |
\@gobble#2!% |
| 2761 |
\else |
| 2762 |
-% |
| 2763 |
\expandafter\InCa@@Div\@gobble#1!#2!% |
| 2764 |
\fi |
| 2765 |
\else |
| 2766 |
\ifnum#2<\z@ |
| 2767 |
-% |
| 2768 |
\expandafter\InCa@@Div\number#1\expandafter!% |
| 2769 |
\@gobble#2!% |
| 2770 |
\else |
| 2771 |
\InCa@@Div#1!#2!% |
| 2772 |
\fi |
| 2773 |
\fi |
| 2774 |
} |
| 2775 |
% \end{macrocode} |
| 2776 |
% \end{macro} |
| 2777 |
% \begin{macro}{\InCa@@Div} |
| 2778 |
% \begin{macrocode} |
| 2779 |
\def\InCa@@Div#1!#2!{% |
| 2780 |
\ifnum#1>#2 % |
| 2781 |
\ifcase#2 % 0 already catched |
| 2782 |
? \IntCalcError:ThisCannotHappen% |
| 2783 |
\or % 1 |
| 2784 |
#1% |
| 2785 |
\or % 2 |
| 2786 |
\InCa@Shr#1!% |
| 2787 |
\else |
| 2788 |
\InCa@DivStart!#1!#2!#2!% |
| 2789 |
\fi |
| 2790 |
\else |
| 2791 |
\ifnum#1=#2 % |
| 2792 |
1% |
| 2793 |
\else |
| 2794 |
0% |
| 2795 |
\fi |
| 2796 |
\fi |
| 2797 |
} |
| 2798 |
% \end{macrocode} |
| 2799 |
% \end{macro} |
| 2800 |
% \begin{macro}{\InCa@DivStart} |
| 2801 |
% \begin{macrocode} |
| 2802 |
\def\InCa@DivStart#1!#2#3!#4#5{% |
| 2803 |
\ifx#5!% |
| 2804 |
\@ReturnAfterElseFi{% |
| 2805 |
\InCa@DivStartI{#1#2}#3=!% |
| 2806 |
}% |
| 2807 |
\else |
| 2808 |
\@ReturnAfterFi{% |
| 2809 |
\InCa@DivStart{#1#2}!#3!#5% |
| 2810 |
}% |
| 2811 |
\fi |
| 2812 |
} |
| 2813 |
% \end{macrocode} |
| 2814 |
% \end{macro} |
| 2815 |
% \begin{macro}{\InCa@StartI} |
| 2816 |
% \begin{macrocode} |
| 2817 |
\def\InCa@DivStartI#1!#2!{% |
| 2818 |
\expandafter\InCa@DivStartII |
| 2819 |
\number#2\expandafter\expandafter\expandafter!% |
| 2820 |
\intcalcShl{#2}!% |
| 2821 |
#1!% |
| 2822 |
} |
| 2823 |
% \end{macrocode} |
| 2824 |
% \end{macro} |
| 2825 |
% \begin{macro}{\InCa@StartII} |
| 2826 |
% \begin{macrocode} |
| 2827 |
\def\InCa@DivStartII#1!#2!{% |
| 2828 |
\expandafter\InCa@DivStartIII |
| 2829 |
\number#1\expandafter!% |
| 2830 |
\number#2\expandafter\expandafter\expandafter!% |
| 2831 |
\intcalcShl{#2}!% |
| 2832 |
} |
| 2833 |
% \end{macrocode} |
| 2834 |
% \end{macro} |
| 2835 |
% \begin{macro}{\InCa@StartIII} |
| 2836 |
% \begin{macrocode} |
| 2837 |
\def\InCa@DivStartIII#1!#2!#3!{% |
| 2838 |
\expandafter\InCa@DivStartIV |
| 2839 |
\number#1\expandafter!% |
| 2840 |
\number#2\expandafter!% |
| 2841 |
\number#3\expandafter!% |
| 2842 |
\number\InCa@Add#3!#2!\expandafter\expandafter\expandafter!% |
| 2843 |
\intcalcShl{#3}!% |
| 2844 |
} |
| 2845 |
% \end{macrocode} |
| 2846 |
% \end{macro} |
| 2847 |
% \begin{macro}{\InCa@StartIV} |
| 2848 |
% \begin{macrocode} |
| 2849 |
\def\InCa@DivStartIV#1!#2!#3!#4!#5!#6!{% |
| 2850 |
\InCa@ProcessDiv#6!#1!#2!#3!#4!#5!/% |
| 2851 |
} |
| 2852 |
% \end{macrocode} |
| 2853 |
% \end{macro} |
| 2854 |
% \begin{macro}{\InCa@ProcessDiv} |
| 2855 |
% \begin{macrocode} |
| 2856 |
\def\InCa@ProcessDiv#1#2#3!#4!#5!#6!#7!#8!#9/{% |
| 2857 |
#9% |
| 2858 |
\ifnum#1<#4 % 0 |
| 2859 |
0% |
| 2860 |
\ifx#2=% |
| 2861 |
\else |
| 2862 |
\InCa@ProcessDiv{#1#2}#3!#4!#5!#6!#7!#8!% |
| 2863 |
\fi |
| 2864 |
\else % 1-9 |
| 2865 |
\ifnum#1<#5 % 1 |
| 2866 |
1% |
| 2867 |
\ifx#2=% |
| 2868 |
\else |
| 2869 |
\expandafter\InCa@ProcessDiv\expandafter{% |
| 2870 |
\number\InCa@Sub#1!#4!% |
| 2871 |
#2% |
| 2872 |
}#3!#4!#5!#6!#7!#8!% |
| 2873 |
\fi |
| 2874 |
\else % 2-9 |
| 2875 |
\ifnum#1<#7 % 2 3 4 5 |
| 2876 |
\ifnum#1<#6 % 2 3 |
| 2877 |
\@ReturnAfterElseFi{% |
| 2878 |
\expandafter\InCa@@ProcessDiv |
| 2879 |
\number\InCa@Sub#1!#5!!% |
| 2880 |
23% |
| 2881 |
}% |
| 2882 |
\else % 4 5 |
| 2883 |
\@ReturnAfterFi{% |
| 2884 |
\expandafter\InCa@@ProcessDiv |
| 2885 |
\number\InCa@Sub#1!#6!!% |
| 2886 |
45% |
| 2887 |
}% |
| 2888 |
\fi |
| 2889 |
#2#3!#4!#5!#6!#7!#8!% |
| 2890 |
\else % 6 7 8 9 |
| 2891 |
\ifnum#1<#8 % 6 7 |
| 2892 |
\@ReturnAfterElseFi{% |
| 2893 |
\expandafter\InCa@@ProcessDiv |
| 2894 |
\number\InCa@Sub#1!#7!!% |
| 2895 |
67% |
| 2896 |
}% |
| 2897 |
\else % 8 9 |
| 2898 |
\@ReturnAfterFi{% |
| 2899 |
\expandafter\InCa@@ProcessDiv |
| 2900 |
\number\InCa@Sub#1!#8!!% |
| 2901 |
89% |
| 2902 |
}% |
| 2903 |
\fi |
| 2904 |
#2#3!#4!#5!#6!#7!#8!% |
| 2905 |
\fi |
| 2906 |
\fi |
| 2907 |
\fi |
| 2908 |
\ifx#2=% |
| 2909 |
\expandafter\@gobble |
| 2910 |
\fi |
| 2911 |
/% |
| 2912 |
} |
| 2913 |
% \end{macrocode} |
| 2914 |
% \end{macro} |
| 2915 |
% \begin{macro}{\InCa@@ProcessDiv} |
| 2916 |
% \begin{macrocode} |
| 2917 |
\def\InCa@@ProcessDiv#1!#2#3#4#5!#6!{% |
| 2918 |
\ifnum#1<#6 % |
| 2919 |
#2% |
| 2920 |
\@ReturnAfterElseFi{% |
| 2921 |
\ifx#4=% |
| 2922 |
\expandafter\InCa@CleanupIV |
| 2923 |
\else |
| 2924 |
\@ReturnAfterFi{% |
| 2925 |
\InCa@ProcessDiv{#1#4}#5!#6!% |
| 2926 |
}% |
| 2927 |
\fi |
| 2928 |
}% |
| 2929 |
\else |
| 2930 |
#3% |
| 2931 |
\@ReturnAfterFi{% |
| 2932 |
\ifx#4=% |
| 2933 |
\expandafter\InCa@CleanupIV |
| 2934 |
\else |
| 2935 |
\@ReturnAfterFi{% |
| 2936 |
\expandafter\InCa@ProcessDiv\expandafter{% |
| 2937 |
\number\InCa@Sub#1!#6! % |
| 2938 |
#4% |
| 2939 |
}#5!#6!% |
| 2940 |
}% |
| 2941 |
\fi |
| 2942 |
}% |
| 2943 |
\fi |
| 2944 |
} |
| 2945 |
% \end{macrocode} |
| 2946 |
% \end{macro} |
| 2947 |
% \begin{macro}{\InCa@CleanupIV} |
| 2948 |
% \begin{macrocode} |
| 2949 |
\def\InCa@CleanupIV#1!#2!#3!#4!{} |
| 2950 |
% \end{macrocode} |
| 2951 |
% \end{macro} |
| 2952 |
% |
| 2953 |
% \subsubsection{\op{Mod}} |
| 2954 |
% |
| 2955 |
% \begin{macro}{\intcalcMod} |
| 2956 |
% \begin{macrocode} |
| 2957 |
\def\intcalcMod#1#2{% |
| 2958 |
\number\expandafter\InCa@Mod |
| 2959 |
\number\number#1\expandafter!% |
| 2960 |
\number#2! % |
| 2961 |
} |
| 2962 |
% \end{macrocode} |
| 2963 |
% \end{macro} |
| 2964 |
% \begin{macro}{\intcalc@Mod} |
| 2965 |
% Pseudocode/decision table for \cs{intcalc@Mod}. |
| 2966 |
% \begin{quote} |
| 2967 |
% \begin{tabular}{@{}lll@{}} |
| 2968 |
% if & $y=0$ & DivisionByZero\\ |
| 2969 |
% elsif & $y<0$ & $-\opMod(-x,-y)$\\ |
| 2970 |
% elsif & $x=0$ & 0\\ |
| 2971 |
% elsif & $y=1$ & 0\\ |
| 2972 |
% elsif & $y=2$ & $\opOdd(x)\mathbin{?}1\mathbin{:}0$\\ |
| 2973 |
% elsif & $x<0$ & |
| 2974 |
% $z\leftarrow x-(x/y)*y;\quad (z<0)\mathbin{?}z+y\mathbin{:}z$\\ |
| 2975 |
% else & & $x-(x/y)*y$\\ |
| 2976 |
% \\ |
| 2977 |
% \end{tabular} |
| 2978 |
% \end{quote} |
| 2979 |
% \begin{macrocode} |
| 2980 |
\def\InCa@Mod#1!#2!{% |
| 2981 |
\ifcase#2 % |
| 2982 |
0\IntCalcError:DivisionByZero% |
| 2983 |
\else |
| 2984 |
\ifnum#2<\z@ |
| 2985 |
-% |
| 2986 |
\expandafter\InCa@Mod |
| 2987 |
\number-#1\expandafter!% |
| 2988 |
\number-#2!% |
| 2989 |
\else |
| 2990 |
\ifcase#1 % |
| 2991 |
0% |
| 2992 |
\else |
| 2993 |
\ifcase#2 % 0 already catched |
| 2994 |
? \IntCalcError:ThisCannotHappen% |
| 2995 |
\or % 1 |
| 2996 |
0% |
| 2997 |
\or % 2 |
| 2998 |
\ifodd#1 1\else 0\fi |
| 2999 |
\else |
| 3000 |
\ifnum#1<\z@ |
| 3001 |
\expandafter\InCa@ModShift |
| 3002 |
\number-% |
| 3003 |
\expandafter\InCa@Sub |
| 3004 |
\number\@gobble#1\expandafter!% |
| 3005 |
\number\intcalcMul{#2}{% |
| 3006 |
\expandafter\InCa@Div\@gobble#1!#2!% |
| 3007 |
}!% |
| 3008 |
!#2!% |
| 3009 |
\else |
| 3010 |
\expandafter\InCa@Sub\number#1\expandafter!% |
| 3011 |
\number\intcalcMul{#2}{\InCa@Div#1!#2!}!% |
| 3012 |
\fi |
| 3013 |
\fi |
| 3014 |
\fi |
| 3015 |
\fi |
| 3016 |
\fi |
| 3017 |
} |
| 3018 |
% \end{macrocode} |
| 3019 |
% \end{macro} |
| 3020 |
% \begin{macro}{\IntCalcMod} |
| 3021 |
% \begin{macrocode} |
| 3022 |
\def\InCa@Temp#1{% |
| 3023 |
\def\IntCalcMod##1!##2!{% |
| 3024 |
\number |
| 3025 |
\ifcase##2 % |
| 3026 |
0\IntCalcError:DivisionByZero% |
| 3027 |
\else |
| 3028 |
\ifcase##1 % |
| 3029 |
0% |
| 3030 |
\else |
| 3031 |
\ifcase##2 % 0 already catched |
| 3032 |
? \IntCalcError:ThisCannotHappen |
| 3033 |
\or % 1 |
| 3034 |
0% |
| 3035 |
\or % 2 |
| 3036 |
\ifodd ##1 1\else 0\fi |
| 3037 |
\else |
| 3038 |
\expandafter\InCa@Sub\number##1\expandafter!% |
| 3039 |
\number\intcalcMul{##2}{\InCa@Div##1!##2!}!% |
| 3040 |
\fi |
| 3041 |
\fi |
| 3042 |
\fi |
| 3043 |
#1% |
| 3044 |
}% |
| 3045 |
} |
| 3046 |
\InCa@Temp{ }% |
| 3047 |
% \end{macrocode} |
| 3048 |
% \end{macro} |
| 3049 |
% \begin{macro}{\InCa@ModShift} |
| 3050 |
% \begin{macrocode} |
| 3051 |
\def\InCa@ModShift#1!#2!{% |
| 3052 |
\ifnum#1<\z@ |
| 3053 |
\expandafter\InCa@Sub\number#2\expandafter!% |
| 3054 |
\@gobble#1!% |
| 3055 |
\else |
| 3056 |
#1% |
| 3057 |
\fi |
| 3058 |
} |
| 3059 |
% \end{macrocode} |
| 3060 |
% \end{macro} |
| 3061 |
% |
| 3062 |
% \subsubsection{Help macros} |
| 3063 |
% |
| 3064 |
% \begin{macro}{\InCa@Empty} |
| 3065 |
% \begin{macrocode} |
| 3066 |
\def\InCa@Empty{} |
| 3067 |
% \end{macrocode} |
| 3068 |
% \end{macro} |
| 3069 |
% \begin{macro}{\@gobble} |
| 3070 |
% \begin{macrocode} |
| 3071 |
\expandafter\ifx\csname @gobble\endcsname\relax |
| 3072 |
\long\def\@gobble#1{}% |
| 3073 |
\fi |
| 3074 |
% \end{macrocode} |
| 3075 |
% \end{macro} |
| 3076 |
% \begin{macro}{\@ReturnAfterFi} |
| 3077 |
% \begin{macrocode} |
| 3078 |
\long\def\@ReturnAfterFi#1\fi{\fi#1}% |
| 3079 |
% \end{macrocode} |
| 3080 |
% \end{macro} |
| 3081 |
% \begin{macro}{\@ReturnAfterElseFi} |
| 3082 |
% \begin{macrocode} |
| 3083 |
\long\def\@ReturnAfterElseFi#1\else#2\fi{\fi#1}% |
| 3084 |
% \end{macrocode} |
| 3085 |
% \end{macro} |
| 3086 |
% |
| 3087 |
% \begin{macrocode} |
| 3088 |
\InCa@AtEnd% |
| 3089 |
% \end{macrocode} |
| 3090 |
% |
| 3091 |
% \begin{macrocode} |
| 3092 |
%</package> |
| 3093 |
% \end{macrocode} |
| 3094 |
%% \section{Installation} |
| 3095 |
% |
| 3096 |
% \subsection{Download} |
| 3097 |
% |
| 3098 |
% \paragraph{Package.} This package is available on |
| 3099 |
% CTAN\footnote{\CTANpkg{intcalc}}: |
| 3100 |
% \begin{description} |
| 3101 |
% \item[\CTAN{macros/latex/contrib/intcalc/intcalc.dtx}] The source file. |
| 3102 |
% \item[\CTAN{macros/latex/contrib/intcalc/intcalc.pdf}] Documentation. |
| 3103 |
% \end{description} |
| 3104 |
% |
| 3105 |
% |
| 3106 |
% \paragraph{Bundle.} All the packages of the bundle `intcalc' |
| 3107 |
% are also available in a TDS compliant ZIP archive. There |
| 3108 |
% the packages are already unpacked and the documentation files |
| 3109 |
% are generated. The files and directories obey the TDS standard. |
| 3110 |
% \begin{description} |
| 3111 |
% \item[\CTANinstall{install/macros/latex/contrib/intcalc.tds.zip}] |
| 3112 |
% \end{description} |
| 3113 |
% \emph{TDS} refers to the standard ``A Directory Structure |
| 3114 |
% for \TeX\ Files'' (\CTANpkg{tds}). Directories |
| 3115 |
% with \xfile{texmf} in their name are usually organized this way. |
| 3116 |
% |
| 3117 |
% \subsection{Bundle installation} |
| 3118 |
% |
| 3119 |
% \paragraph{Unpacking.} Unpack the \xfile{intcalc.tds.zip} in the |
| 3120 |
% TDS tree (also known as \xfile{texmf} tree) of your choice. |
| 3121 |
% Example (linux): |
| 3122 |
% \begin{quote} |
| 3123 |
% |unzip intcalc.tds.zip -d ~/texmf| |
| 3124 |
% \end{quote} |
| 3125 |
% |
| 3126 |
% \subsection{Package installation} |
| 3127 |
% |
| 3128 |
% \paragraph{Unpacking.} The \xfile{.dtx} file is a self-extracting |
| 3129 |
% \docstrip\ archive. The files are extracted by running the |
| 3130 |
% \xfile{.dtx} through \plainTeX: |
| 3131 |
% \begin{quote} |
| 3132 |
% \verb|tex intcalc.dtx| |
| 3133 |
% \end{quote} |
| 3134 |
% |
| 3135 |
% \paragraph{TDS.} Now the different files must be moved into |
| 3136 |
% the different directories in your installation TDS tree |
| 3137 |
% (also known as \xfile{texmf} tree): |
| 3138 |
% \begin{quote} |
| 3139 |
% \def\t{^^A |
| 3140 |
% \begin{tabular}{@{}>{\ttfamily}l@{ $\rightarrow$ }>{\ttfamily}l@{}} |
| 3141 |
% intcalc.sty & tex/generic/intcalc/intcalc.sty\\ |
| 3142 |
% intcalc.pdf & doc/latex/intcalc/intcalc.pdf\\ |
| 3143 |
% intcalc.dtx & source/latex/intcalc/intcalc.dtx\\ |
| 3144 |
% \end{tabular}^^A |
| 3145 |
% }^^A |
| 3146 |
% \sbox0{\t}^^A |
| 3147 |
% \ifdim\wd0>\linewidth |
| 3148 |
% \begingroup |
| 3149 |
% \advance\linewidth by\leftmargin |
| 3150 |
% \advance\linewidth by\rightmargin |
| 3151 |
% \edef\x{\endgroup |
| 3152 |
% \def\noexpand\lw{\the\linewidth}^^A |
| 3153 |
% }\x |
| 3154 |
% \def\lwbox{^^A |
| 3155 |
% \leavevmode |
| 3156 |
% \hbox to \linewidth{^^A |
| 3157 |
% \kern-\leftmargin\relax |
| 3158 |
% \hss |
| 3159 |
% \usebox0 |
| 3160 |
% \hss |
| 3161 |
% \kern-\rightmargin\relax |
| 3162 |
% }^^A |
| 3163 |
% }^^A |
| 3164 |
% \ifdim\wd0>\lw |
| 3165 |
% \sbox0{\small\t}^^A |
| 3166 |
% \ifdim\wd0>\linewidth |
| 3167 |
% \ifdim\wd0>\lw |
| 3168 |
% \sbox0{\footnotesize\t}^^A |
| 3169 |
% \ifdim\wd0>\linewidth |
| 3170 |
% \ifdim\wd0>\lw |
| 3171 |
% \sbox0{\scriptsize\t}^^A |
| 3172 |
% \ifdim\wd0>\linewidth |
| 3173 |
% \ifdim\wd0>\lw |
| 3174 |
% \sbox0{\tiny\t}^^A |
| 3175 |
% \ifdim\wd0>\linewidth |
| 3176 |
% \lwbox |
| 3177 |
% \else |
| 3178 |
% \usebox0 |
| 3179 |
% \fi |
| 3180 |
% \else |
| 3181 |
% \lwbox |
| 3182 |
% \fi |
| 3183 |
% \else |
| 3184 |
% \usebox0 |
| 3185 |
% \fi |
| 3186 |
% \else |
| 3187 |
% \lwbox |
| 3188 |
% \fi |
| 3189 |
% \else |
| 3190 |
% \usebox0 |
| 3191 |
% \fi |
| 3192 |
% \else |
| 3193 |
% \lwbox |
| 3194 |
% \fi |
| 3195 |
% \else |
| 3196 |
% \usebox0 |
| 3197 |
% \fi |
| 3198 |
% \else |
| 3199 |
% \lwbox |
| 3200 |
% \fi |
| 3201 |
% \else |
| 3202 |
% \usebox0 |
| 3203 |
% \fi |
| 3204 |
% \end{quote} |
| 3205 |
% If you have a \xfile{docstrip.cfg} that configures and enables \docstrip's |
| 3206 |
% TDS installing feature, then some files can already be in the right |
| 3207 |
% place, see the documentation of \docstrip. |
| 3208 |
% |
| 3209 |
% \subsection{Refresh file name databases} |
| 3210 |
% |
| 3211 |
% If your \TeX~distribution |
| 3212 |
% (\TeX\,Live, \mikTeX, \dots) relies on file name databases, you must refresh |
| 3213 |
% these. For example, \TeX\,Live\ users run \verb|texhash| or |
| 3214 |
% \verb|mktexlsr|. |
| 3215 |
% |
| 3216 |
% \subsection{Some details for the interested} |
| 3217 |
% |
| 3218 |
% \paragraph{Unpacking with \LaTeX.} |
| 3219 |
% The \xfile{.dtx} chooses its action depending on the format: |
| 3220 |
% \begin{description} |
| 3221 |
% \item[\plainTeX:] Run \docstrip\ and extract the files. |
| 3222 |
% \item[\LaTeX:] Generate the documentation. |
| 3223 |
% \end{description} |
| 3224 |
% If you insist on using \LaTeX\ for \docstrip\ (really, |
| 3225 |
% \docstrip\ does not need \LaTeX), then inform the autodetect routine |
| 3226 |
% about your intention: |
| 3227 |
% \begin{quote} |
| 3228 |
% \verb|latex \let\install=y\input{intcalc.dtx}| |
| 3229 |
% \end{quote} |
| 3230 |
% Do not forget to quote the argument according to the demands |
| 3231 |
% of your shell. |
| 3232 |
% |
| 3233 |
% \paragraph{Generating the documentation.} |
| 3234 |
% You can use both the \xfile{.dtx} or the \xfile{.drv} to generate |
| 3235 |
% the documentation. The process can be configured by the |
| 3236 |
% configuration file \xfile{ltxdoc.cfg}. For instance, put this |
| 3237 |
% line into this file, if you want to have A4 as paper format: |
| 3238 |
% \begin{quote} |
| 3239 |
% \verb|\PassOptionsToClass{a4paper}{article}| |
| 3240 |
% \end{quote} |
| 3241 |
% An example follows how to generate the |
| 3242 |
% documentation with pdf\LaTeX: |
| 3243 |
% \begin{quote} |
| 3244 |
%\begin{verbatim} |
| 3245 |
%pdflatex intcalc.dtx |
| 3246 |
%makeindex -s gind.ist intcalc.idx |
| 3247 |
%pdflatex intcalc.dtx |
| 3248 |
%makeindex -s gind.ist intcalc.idx |
| 3249 |
%pdflatex intcalc.dtx |
| 3250 |
%\end{verbatim} |
| 3251 |
% \end{quote} |
| 3252 |
% |
| 3253 |
% \begin{History} |
| 3254 |
% \begin{Version}{2007/09/09 v1.0} |
| 3255 |
% \item |
| 3256 |
% First version. |
| 3257 |
% \end{Version} |
| 3258 |
% \begin{Version}{2007/09/27 v1.1} |
| 3259 |
% \item |
| 3260 |
% \cs{intcalcNum} added. |
| 3261 |
% \item |
| 3262 |
% \cs{intcalcShl} and \cs{intcalcShr} allow negative numbers. |
| 3263 |
% The sign is preserved. |
| 3264 |
% \item |
| 3265 |
% Reuse \cs{@gobble} instead of own macro \cs{IntCalc@Gobble}. |
| 3266 |
% \item |
| 3267 |
% Small fixes. |
| 3268 |
% \item |
| 3269 |
% Shorter internal prefix. |
| 3270 |
% \item |
| 3271 |
% Some programmer's interface. |
| 3272 |
% \end{Version} |
| 3273 |
% \begin{Version}{2016/05/16 v1.2} |
| 3274 |
% \item |
| 3275 |
% Documentation updates. |
| 3276 |
% \end{Version} |
| 3277 |
% \begin{Version}{2019/12/15 v1.3} |
| 3278 |
% \item |
| 3279 |
% Documentation updates. |
| 3280 |
% \end{Version} |
| 3281 |
% \end{History} |
| 3282 |
% |
| 3283 |
% \PrintIndex |
| 3284 |
% |
| 3285 |
% \Finale |
| 3286 |
\endinput |