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