diff options
author | Karl Berry <karl@freefriends.org> | 2017-12-06 23:55:15 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2017-12-06 23:55:15 +0000 |
commit | 7ffad570b11726b0ca150867d23878fc1a949865 (patch) | |
tree | f8ef79172d86ea7e1c18f0f3023ec2303680bdb7 /Master/texmf-dist/source/latex/bnumexpr/bnumexpr.dtx | |
parent | 80243f823ee9dede0a64eb58a955e119acfa97f4 (diff) |
bnumexpr (7dec17)
git-svn-id: svn://tug.org/texlive/trunk@46002 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/bnumexpr/bnumexpr.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/bnumexpr/bnumexpr.dtx | 167 |
1 files changed, 125 insertions, 42 deletions
diff --git a/Master/texmf-dist/source/latex/bnumexpr/bnumexpr.dtx b/Master/texmf-dist/source/latex/bnumexpr/bnumexpr.dtx index 180eda3beba..bf3200dc29d 100644 --- a/Master/texmf-dist/source/latex/bnumexpr/bnumexpr.dtx +++ b/Master/texmf-dist/source/latex/bnumexpr/bnumexpr.dtx @@ -1,18 +1,18 @@ % -*- coding: iso-latin-1; time-stamp-format: "%02d-%02m-%:y at %02H:%02M:%02S %Z" -*- %<*dtx> -\def\bnedtxtimestamp {Time-stamp: <26-07-2017 at 23:19:38 CEST>} +\def\bnedtxtimestamp {Time-stamp: <05-12-2017 at 15:54:19 CET>} \iffalse %</dtx> %<*drv> %% --------------------------------------------------------------- -\def\bnedocdate {2017/07/09}% package bnumexpr documentation date -\def\bnepackdate{2017/07/09}% package bnumexpr date -\def\bneversion {1.2b} % package bnumexpr version +\def\bnedocdate {2017/12/05}% package bnumexpr documentation date +\def\bnepackdate{2017/12/05}% package bnumexpr date +\def\bneversion {1.2c} % package bnumexpr version %</drv> %<*readme>-------------------------------------------------------- | Source: bnumexpr.dtx -| Version: v1.2b, 2017/07/09 (doc: 2017/07/09) +| Version: v1.2c, 2017/12/05 (doc: 2017/12/05) | Author: Jean-Francois Burnol | Info: Expressions with big integers | License: LPPL 1.3c @@ -29,11 +29,11 @@ rounded integer division) familiar from the `\numexpr` e-TeX parser. Besides extending the scope to arbitrarily big numbers (and having a more complete syntax, for example `-(1)` is legal input), it adds the -truncated division operator `//`, and its associated modulo `/:`, the -power operator `^` (or equivalently `**`), and the factorial post-fix -operator `!`. The space character as well as the underscore character -`_` both may serve to optionally separate digits in long numbers, for -better readability of the input. +(by default) floored division operator `//`, and its associated modulo +`/:`, the power operator `^` (or equivalently `**`), and the factorial +post-fix operator `!`. The space character as well as the underscore +character `_` both may serve to optionally separate digits in long +numbers, for better readability of the input. For example: @@ -147,6 +147,19 @@ and the derived files %% %</!readme> %<*changes>------------------------------------------------------- +\item[1.2c (2017/12/05)] \textbf{Breaking changes:} + \begin{itemize} + \item requires \xintcorename |1.2p| or later (if not using option |custom|). + \item |divtrunc| key of |\bnumexprsetup| is renamed to |div|. + \item the |//| and |/:| operators are now by default associated to the + \emph{floored} division. This is to keep in sync with the change of + \xintcorename at |1.2p|. + \item for backwards compatibility, one + may add to existing document:\newline + \string\bnumexprsetup\{div=\string\xintiiDivTrunc, + mod=\string\xintiiModTrunc\} + \end{itemize} + \item[1.2b (2017/07/09)] \begin{itemize} \item the |_| may be used to separate visually blocks of digits in long @@ -502,7 +515,38 @@ pdfpagemode=UseOutlines} {\href{http://www.ctan.org/pkg/xint}{xintcore}\xspace }% \def\xintexprname {\href{http://www.ctan.org/pkg/xint}{xintexpr}\xspace }% +\def\xintbinhexname + {\href{http://www.ctan.org/pkg/xint}{xintbinhex}\xspace }% + + +% \centeredline: OUR OWN LITTLE MACRO FOR CENTERING LINES +% ======================================================= + +% 7 mars 2013 +% ----------- +% +% This macro allows to conveniently center a line inside a paragraph and still +% allow use therein of \verb or other macros changing catcodes. +% A proposito, the \LaTeX \centerline uses \hsize and not \linewidth ! +% (which in my humble opinion is bad) +% Actually my \centeredline works nicely in list environments. + +% \ignorespaces ajouté le 9 juin 2013. + +% Note: \centeredline creates a group + +\makeatletter +\newcommand*\centeredline {% + \ifhmode \\\relax + \def\centeredline@{\hss\egroup\hskip\z@skip\ignorespaces }% + \else + \def\centeredline@{\hss\egroup }% + \fi + \afterassignment\@centeredline + \let\next=} +\def\@centeredline + {\hbox to \linewidth \bgroup \hss \bgroup \aftergroup\centeredline@ } \frenchspacing @@ -540,7 +584,7 @@ pdfpagemode=UseOutlines} Package \bnumname provides |\thebnumexpr...\relax| which is analogous to |\the\numexpr...\relax|, while allowing arbitrarily big integers, powers, -factorials, truncated division, modulo, and comma separated expressions. +factorials, floored division, modulo, and comma separated expressions. Examples: \noindent\bneshow {1_208_637_867_168*(2_187_917_891_279+3_109_197_072_870)}% @@ -560,7 +604,9 @@ differences between |\bnumexpr| and |\numexpr|: \begin{enumerate} \item one must use either |\thebnumexpr| or |\bnethe\bnumexpr| to get a - printable result, as |\bnumexpr...\relax| expands to a private format, + printable result, as |\bnumexpr...\relax| expands to a private format (using + |\number| as prefix to |\bnumexpr| would only serve to trigger the expansion + to the \bnumname private format, hence will raise a \TeX\ error), \item one may embed directly (without |\bnethe|) a |\bnumexpr...\relax| in another one (or in a |\xintexpr...\relax|), but not in a @@ -586,19 +632,37 @@ differences between |\bnumexpr| and |\numexpr|: |\numexpr...\relax| which, without |\the| (or |\number| or |\romannumeral|) as prefix would not expand inside an |\edef|, -\item tacit multiplication applies in front of parenthesized sub-expressions, - or sub |\bnumexpr...\relax| (or |\numexpr...\relax|), or in front of a - |\count| or |\dimen| register. - \item expressions may be comma separated. On input, spaces are ignored, naturally, and on output the values are comma separated with a space after - each comma. + each comma, \item |\bnumexpr -(1+1)\relax| is legal contrarily to |\numexpr -(1+1)\relax| - which raises an error. + which raises an error, -\item the |_| is legal within the digits composing a number and is silently - ignored. +\item |\numexpr 2\cnta\relax| is illegal (with |\cnta| a |\count|-variable.) + But |\bnumexpr 2\cnta\relax| is perfectly legal and will do the tacit + multiplication, +% \newcount\cnta +% \cnta 1111 +% \thebnumexpr 2\cnta\relax + +\item more generally, tacit multiplication applies in front of parenthesized + sub-expressions, or sub |\bnumexpr...\relax| (or |\numexpr...\relax|), + +\item the underscore |_| is accepted within the digits composing a number and + is silently ignored by |\bnumexpr|, + +\item |\numexpr| accepts \TeX\ syntax for hexadecimal input |"EF| (or octal + input |'377|), but currently |\bnumexpr| does not. This could possibly be + added in future% +% +\footnote{It is only a matter of copying pasting relevant code from + \xintexprname, so depends upon user demands addressed to the author |;-)|.} +% + (hexadecimal prefix |"| is part of the recognized + |\xintiiexpr| syntax from \xintexprname if \xintbinhexname is loaded.) In + the meantime, one may encapsulate such inputs (obeying \TeX's bound on + numbers) into a sub |\numexpr...\relax|. \end{enumerate} An important thing to keep in mind is that if one has a calculation @@ -662,39 +726,54 @@ often use helper macros (not in the package) of the following type: It is the expected one with infix operators and parentheses, the recognized operators being |+|, |-|, |*|, |/| (rounded division), -|^| (power), |**| (power), |//| (truncated division), |/:| (modulo) -and |!| (factorial). +|^| (power), |**| (power), |//| (by default floored division), +|/:| (the associated modulo) and |!| (factorial).% +% +\footnote{Releases |1.2b| and earlier associated in the default configuration + truncated division to |//|. This was changed at |1.2c| to stay in sync with + \xintcorename |1.2p|. For backwards compatibility, one may add to existing + document \string\bnumexprsetup\{div=\string\xintiiDivTrunc, + mod=\string\xintiiModTrunc\}.} + +The modulo |/:| is by default associated with the floored division |//|, but +using |\bnumexprsetup{mod=...}| it can, like the other operators, be remapped +to any macro of one's choice. Different computations may be separated by commas. The whole expression is handled token by token, any component (digit, operator, parenthesis... even the ending |\relax|) may arise on the spot from macro expansions. -The precedence rules are the expected ones. Notice though that in case -of equal precedence the operations are left-associative, hence:\newline -\bneshow{2^3^4, (2^3)^4, 2^(3^4)} +The precedence rules are the expected ones. -The three operators |/|, |//|, |/:| are at the same level of -precedence as the multiplication |*|. The modulo |/:| is associated -with truncated division |//|. +There is currently no user interface to change precedence levels. The +three operators |/|, |//|, |/:| are at the same level of precedence as the +multiplication |*|. The factorial postfix |!| has highest precedence. The +minus signs inherit the precedence level of the previously encountered infix +operators. -The factorial postfix |!| has highest precedence. The minus signs -inherit the precedence level of the previously encountered infix operators. +In case of equal precedence the operations are left-associative, +hence:\newline \bneshow{2^3^4, (2^3)^4, 2^(3^4)} -The underscore |_| can be used to separated digits in long numbers, for +The underscore |_| can be used to separate digits in long numbers, for readability of the input. -\section{Option custom, \csh{bnumexprsetup}}\label{sec:options} +\section{Options} + +The sole package option is |custom|: it tells \bnumname not to load +package \xintcorename. + +\section{\csh{bnumexprsetup}} Package \bnumname needs that some big integer engine provides the macros doing the actual computations. By default, it loads package \xintcorename (a subset of \href{http://www.ctan.org/pkg/xint}{xint}; -version |1.2| is required) and uses \csa{bnumexprsetup} in the following +version |1.2p| is required) and uses \csa{bnumexprsetup} in the following way: \begin{verbatim} \usepackage{xintcore} \bnumexprsetup{add=\xintiiAdd, sub=\xintiiSub, mul=\xintiiMul, - divround=\xintiiDivRound, divtrunc=\xintiiDivTrunc, + divround=\xintiiDivRound, div=\xintiiDivFloor, mod=\xintiiMod, pow=\xintiiPow, fac=\xintiiFac} \end{verbatim} @@ -728,8 +807,9 @@ Thus, |opp| could identify a plus sign |+| upfront and then act adequately.\footnote{see \csa{BNE_Op_opp} in the code for the default.} -The sole package option is |custom|: it tells \bnumname not to load -\xintcorename. +Macro |\bnumexprsetup| can be used multiple times in the same document, thus +allowing to switch math engines or to remap operators to some other arithmetic +macros of the same math engine. Its effect obeys the local scope. \section{Readme} \begingroup @@ -822,11 +902,11 @@ The sole package option is |custom|: it tells \bnumname not to load \long\def\xint_secondofthree #1#2#3{#2}% \long\def\xint_thirdofthree #1#2#3{#3}% \def\xint_gob_til_! #1!{}% this ! has catcode 11 -\def\xint_UDsignfork #1-#2#3\krof {#2}% +\long\def\xint_UDsignfork #1-#2#3\krof {#2}% \long\def\xint_afterfi #1#2\fi {\fi #1}% \long\def\xint_dothis #1#2\xint_orthat #3{\fi #1}% \let\xint_orthat \xint_firstofone -\def\xint_zapspaces #1 #2{#1#2\xint_zapspaces }% +\long\def\xint_zapspaces #1 #2{#1#2\xint_zapspaces }% % \end{macrocode} % \subsection{\csh{bnumexprsetup}} % New with |v1.2a|. Replaces removed |\bnumexprUsesbigintcalc| etc... @@ -841,14 +921,15 @@ The sole package option is |custom|: it tells \bnumname not to load \def\BNE_parsedone #1\BNE_parsekeys {}% % \end{macrocode} % \subsection{Package options} +% |v1.2c| replaces former key |divtrunc| by |div|. % \begin{macrocode} \def\BNE_tmpa {0}% \DeclareOption {custom}{\def\BNE_tmpa {1}}% \ProcessOptions\relax \if0\BNE_tmpa % Default is to load xintcore.sty - \RequirePackage{xintcore}[2015/10/10]% + \RequirePackage{xintcore}[2017/12/04]% \bnumexprsetup{add=\xintiiAdd, sub=\xintiiSub, mul=\xintiiMul, - divround=\xintiiDivRound, divtrunc=\xintiiDivTrunc, + divround=\xintiiDivRound, div=\xintiiDivFloor, mod=\xintiiMod, pow=\xintiiPow, fac=\xintiiFac}% \fi % \end{macrocode} @@ -1120,6 +1201,8 @@ The sole package option is |custom|: it tells \bnumname not to load % % |v1.2a| adds |//| for truncated division, |/:| for modulo operations % and |**| for powers (synonym to |^|). +% +% |v1.2c| has |//| and |/:| per default associated to floored division. % \begin{macrocode} \def\BNE_tmpc #1#2#3#4#5#6#7% {% @@ -1160,7 +1243,7 @@ The sole package option is |custom|: it tells \bnumname not to load \expandafter\def\csname BNE_itself_**\endcsname {^}% shortcut for alias \expandafter\def\csname BNE_itself_//\endcsname {//}% \expandafter\def\csname BNE_itself_/:\endcsname {/:}% -\BNE_tmpb {//}{vii}{BNE_Op_divtrunc}% +\BNE_tmpb {//}{vii}{BNE_Op_div}% \BNE_tmpb {/:}{vii}{BNE_Op_mod}% % \end{macrocode} % \subsection{! as postfix factorial operator} @@ -1271,7 +1354,7 @@ The sole package option is |custom|: it tells \bnumname not to load Right bracket \] Circumflex \^ Underscore \_ Grave accent \` Left brace \{ Vertical bar \| Right brace \} Tilde \~} -\CheckSum {871} +\CheckSum {873} \makeatletter\check@checksum\makeatother \Finale %% End of file xint.dtx |