From 64fca8fccca586cda37c00d1a32f960d48fc0a7d Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Tue, 13 Oct 2015 21:38:18 +0000 Subject: bnumexpr (13oct15) git-svn-id: svn://tug.org/texlive/trunk@38631 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/doc/latex/bnumexpr/README | 99 +-- Master/texmf-dist/doc/latex/bnumexpr/bnumexpr.pdf | Bin 92322 -> 76868 bytes .../texmf-dist/source/latex/bnumexpr/bnumexpr.dtx | 882 +++++++++++---------- .../texmf-dist/source/latex/bnumexpr/bnumexpr.ins | 6 +- Master/texmf-dist/tex/latex/bnumexpr/bnumexpr.sty | 242 +++--- 5 files changed, 604 insertions(+), 625 deletions(-) (limited to 'Master/texmf-dist') diff --git a/Master/texmf-dist/doc/latex/bnumexpr/README b/Master/texmf-dist/doc/latex/bnumexpr/README index 1f29ae7836a..c5111876d63 100644 --- a/Master/texmf-dist/doc/latex/bnumexpr/README +++ b/Master/texmf-dist/doc/latex/bnumexpr/README @@ -1,5 +1,5 @@ Source: bnumexpr.dtx -Version: v1.1b, 2014/10/28 (doc: 2014/11/04) +Version: v1.2, 2015/10/13 (doc: 2015/10/13) Author: Jean-Francois Burnol Info: Expressions with big integers License: LPPL 1.3c or later @@ -11,44 +11,44 @@ README: USAGE, INSTALLATION, LICENSE Usage - \usepackage{bnumexpr} +The package bnumexpr allows _expandable_ computations with big integers, +the four infix operators +, -, *, / (which does rounded division), the +power operators ^ or **, the factorial !, the truncated division //, and +its associated modulo /:. -Then +For example: - \thebnumexpr \relax + \thebnumexpr (92874927979^5-3197927979^6)/30!\relax -is like +outputs -4006240736596543944035189. - \the\numexpr \relax +The \relax ending token is mandatory and will be removed as a result of +the evaluation. -with the difference of accepting or producing arbitrarily big integers. -For example, +The expression parser is scaled-down from \xinttheiiexpr...\relax from +package xintexpr [1], it does not handle boolean operators, conditional +branching, variables and recognizes no functions. - \thebnumexpr 2*1234567890\relax +By default the underlying arithmetic macros are the ones provided by +package xintcore [2] (its release 1.2 is required). -outputs 2469135780 which would have created an arithmetic overflow in -\numexpr as it exceeds the maximal allowed TeX integer 2147483647. - -\bnumexpr...\relax is a scaled down version of \xintiiexpr...\relax from -package xintexpr.[1] - -- by default, bnumexpr loads xintcore [2] for its arithmetic macros - doing addition, subtraction, multiplication, division (and powers). - -- option _allowpower_ enables ^ as power operator, for example: - - \thebnumexpr 2^31\relax % smallest integer exceeding the TeX bound +[1] http://www.ctan.org/pkg/xint +[2] http://www.ctan.org/pkg/xint -- option _bigintcalc_ loads package bigintcalc [3] and uses its - arithmetic macros rather than those from xintcore. +bnumexpr has only one option _custom_ which says to not load xintcore, +and a command \bnumexprsetup to inform the package which macros to use +if not those from xintcore. -- option _l3bigint_ loads package l3bigint [4], from the experimental - trunk of the on-going LaTeX3 project. +This is a breaking release: some options and commands from v1.1 are not +defined anymore (as \bnumexprsetup provides a new interface), and +documents which used them will need updating. -- with option _custom_, no extra package is loaded and it is up to the - user to define suitably expandable macros \bnumexprAdd, - \bnumexprSub, \bnumexprMul, and \bnumexprDiv doing the basic - arithmetic operations. +Notice that the possibility not to use the xintcore macros might be +removed in the future: perhaps a future release will maintain during +computations a private internal representation (especially taylored +either for the xintcore macros or new ones which would be included +within bnumexpr.sty itself) and the constraints this implies may render +optional use of other macros impossible. Installation @@ -64,25 +64,23 @@ the following files: bnumexpr.sty this is the style file. -bnumexprReadme.md +README.md reconstitutes this README. -bnumexpr.changes +bnumexprchanges.tex lists changes from the initial version. bnumexpr.tex - can be used to generate the documentation: - - with latex+dvipdfmx: "latex bnumexpr.tex" (thrice) then "dvipdfmx bnumexpr.dvi". - Ignore dvipdfmx warnings, but if the pdf file has problems with - fonts (possibly from an old dvipdfmx), use then rather pdflatex. + Ignore dvipdfmx warnings, but if the pdf file has problems with + fonts (possibly from an old dvipdfmx), use then rather pdflatex. - with pdflatex: "pdflatex bnumexpr.tex" (thrice). - In both cases files bnumexprReadme.md and bnumexpr.changes must be + In both cases files README.md and bnumexprchanges.tex must be present in the same repertory. without bnumexpr.tex: @@ -99,44 +97,29 @@ Finishing the installation: bnumexpr.pdf --> TDS:doc/latex/bnumexpr/ README --> TDS:doc/latex/bnumexpr/ -Files bnumexpr.tex, bnumexpr.changes, bnumexprReadme.md may be -discarded. +Files bnumexpr.tex, bnumexprchanges.tex, README.md may be discarded. License -Copyright (C) 2014 by Jean-Francois Burnol +Copyright (C) 2014-2015 by Jean-Francois Burnol This Work may be distributed and/or modified under the -conditions of the LaTeX Project Public License, either -version 1.3c of this license or (at your option) any later -version. This version of this license is in +conditions of the LaTeX Project Public License 1.3c. +This version of this license is in http://www.latex-project.org/lppl/lppl-1-3c.txt -and the latest version of this license is in - - http://www.latex-project.org/lppl.txt - and version 1.3 or later is part of all distributions of LaTeX version 2005/12/01 or later. -This Work has the LPPL maintenance status "maintained". +This Work has the LPPL maintenance status "author-maintained". -The Current Maintainer of this Work is Jean-Francois Burnol. +The Author and Maintainer of this Work is Jean-Francois Burnol. This Work consists of the main source file bnumexpr.dtx and the derived files bnumexpr.sty, bnumexpr.pdf, bnumexpr.ins, bnumexpr.tex, - bnumexpr.changes, bnumexprReadme.md - -[1] http://www.ctan.org/pkg/xint - -[2] http://www.ctan.org/pkg/xint - -[3] http://www.ctan.org/pkg/bigintcalc - -[4] http://latex-project.org/svnroot/experimental/trunk/l3trial/l3bigint, -or from https://github.com/latex3/svn-mirror. + bnumexprchanges.tex, README.md diff --git a/Master/texmf-dist/doc/latex/bnumexpr/bnumexpr.pdf b/Master/texmf-dist/doc/latex/bnumexpr/bnumexpr.pdf index dcdee91d82f..7a5f1dcc475 100644 Binary files a/Master/texmf-dist/doc/latex/bnumexpr/bnumexpr.pdf and b/Master/texmf-dist/doc/latex/bnumexpr/bnumexpr.pdf differ diff --git a/Master/texmf-dist/source/latex/bnumexpr/bnumexpr.dtx b/Master/texmf-dist/source/latex/bnumexpr/bnumexpr.dtx index 76e0475319d..47db3a09200 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: <04-11-2014 at 12:11:09 CET>} +\def\bnedtxtimestamp {Time-stamp: <13-10-2015 at 18:40:32 CEST>} \iffalse % %<*drv> %% --------------------------------------------------------------- -\def\bnedocdate {2014/11/04} % package bnumexpr documentation date -\def\bnepackdate{2014/10/28} % package bnumexpr date -\def\bneversion {1.1b} % package bnumexpr version +\def\bnedocdate {2015/10/13} % package bnumexpr documentation date +\def\bnepackdate{2015/10/13} % package bnumexpr date +\def\bneversion {1.2} % package bnumexpr version % %<*readme>-------------------------------------------------------- | Source: bnumexpr.dtx -| Version: v1.1b, 2014/10/28 (doc: 2014/11/04) +| Version: v1.2, 2015/10/13 (doc: 2015/10/13) | Author: Jean-Francois Burnol | Info: Expressions with big integers | License: LPPL 1.3c or later @@ -23,52 +23,44 @@ README: [Usage], [Installation], [License] Usage ----- - \usepackage{bnumexpr} +The package `bnumexpr` allows _expandable_ computations with big +integers, the four infix operators `+`, `-`, `*`, `/` (which does +rounded division), the power operators `^` or `**`, the factorial +`!`, the truncated division `//`, and its associated modulo `/:`. -Then +For example: - \thebnumexpr \relax + \thebnumexpr (92874927979^5-3197927979^6)/30!\relax -is like +outputs `-4006240736596543944035189`. - \the\numexpr \relax +The `\relax` ending token is mandatory and will be removed as a +result of the evaluation. -with the difference of accepting or producing arbitrarily big -integers. For example, +The expression parser is scaled-down from `\xinttheiiexpr...\relax` +from package xintexpr[^1], it does not handle boolean operators, +conditional branching, variables and recognizes no functions. - \thebnumexpr 2*1234567890\relax +By default the underlying arithmetic macros are the ones provided +by package xintcore[^1] (its release 1.2 is required). -outputs `2469135780` which would have created an arithmetic overflow in -`\numexpr` as it exceeds the maximal allowed TeX integer `2147483647`. +bnumexpr has only one option _custom_ which says to not load +xintcore, and a command `\bnumexprsetup` to inform the package +which macros to use if not those from xintcore. -`\bnumexpr...\relax` is a scaled down version of `\xintiiexpr...\relax` -from package xintexpr.[^1] +This is a breaking release: some options and commands from `v1.1` +are not defined anymore (as `\bnumexprsetup` provides a new +interface), and documents which used them will need updating. -- by default, bnumexpr loads xintcore [^1] for its arithmetic macros doing - addition, subtraction, multiplication, division (and powers). - -- option _allowpower_ enables `^` as power operator, for example: - - \thebnumexpr 2^31\relax % smallest integer exceeding the TeX bound - -- option _bigintcalc_ loads package bigintcalc [^2] and uses its - arithmetic macros rather than those from xintcore. - -- option _l3bigint_ loads package l3bigint [^3], from the experimental - trunk of the on-going [LaTeX3 project](http://latex-project.org). - -- with option _custom_, no extra package is loaded and it is up to the - user to define suitably expandable macros `\bnumexprAdd`, - `\bnumexprSub`, `\bnumexprMul`, and `\bnumexprDiv` doing the basic - arithmetic operations. +Notice that the possibility not to use the xintcore macros might be +removed in the future: perhaps a future release will maintain during +computations a private internal representation (especially taylored +either for the xintcore macros or new ones which would be included +within `bnumexpr.sty` itself) and the constraints this implies may +render optional use of other macros impossible. [^1]: -[^2]: - -[^3]: , -or from . - Installation ------------ @@ -83,24 +75,24 @@ Both `"tex bnumexpr.ins"` and `"tex bnumexpr.dtx"` extract from `bnumexpr.sty` : this is the style file. -`bnumexprReadme.md` +`README.md` : reconstitutes this README. -`bnumexpr.changes` +`bnumexprchanges.tex` : lists changes from the initial version. `bnumexpr.tex` : can be used to generate the documentation: - - with latex+dvipdfmx: `"latex bnumexpr.tex"` (thrice) then + : - with latex+dvipdfmx: `"latex bnumexpr.tex"` (thrice) then `"dvipdfmx bnumexpr.dvi"`. - Ignore dvipdfmx warnings, but if the pdf file has problems with - fonts (possibly from an old dvipdfmx), use then rather pdflatex. + : Ignore dvipdfmx warnings, but if the pdf file has problems with + fonts (possibly from an old dvipdfmx), use then rather pdflatex. - - with pdflatex: `"pdflatex bnumexpr.tex"` (thrice). + : - with pdflatex: `"pdflatex bnumexpr.tex"` (thrice). - In both cases files `bnumexprReadme.md` and `bnumexpr.changes` must + : In both cases files `README.md` and `bnumexprchanges.tex` must be present in the same repertory. without `bnumexpr.tex`: @@ -117,46 +109,52 @@ Finishing the installation: bnumexpr.pdf --> TDS:doc/latex/bnumexpr/ README --> TDS:doc/latex/bnumexpr/ -Files `bnumexpr.tex`, `bnumexpr.changes`, `bnumexprReadme.md` may be +Files `bnumexpr.tex`, `bnumexprchanges.tex`, `README.md` may be discarded. License ------- -Copyright (C) 2014 by Jean-Francois Burnol +Copyright (C) 2014-2015 by Jean-Francois Burnol | This Work may be distributed and/or modified under the -| conditions of the LaTeX Project Public License, either -| version 1.3c of this license or (at your option) any later -| version. This version of this license is in +| conditions of the LaTeX Project Public License 1.3c. +| This version of this license is in > -| and the latest version of this license is in - -> - | and version 1.3 or later is part of all distributions of | LaTeX version 2005/12/01 or later. -This Work has the LPPL maintenance status "maintained". +This Work has the LPPL maintenance status "author-maintained". -The Current Maintainer of this Work is Jean-Francois Burnol. +The Author and Maintainer of this Work is Jean-Francois Burnol. This Work consists of the main source file `bnumexpr.dtx` and the derived files bnumexpr.sty, bnumexpr.pdf, bnumexpr.ins, bnumexpr.tex, - bnumexpr.changes, bnumexprReadme.md + bnumexprchanges.tex, README.md %-------------------------------------------------------- %<*!readme> %% --------------------------------------------------------------- %% The bnumexpr package: Expressions with big integers -%% Copyright (C) 2014 by Jean-Francois Burnol +%% Copyright (C) 2014-2015 by Jean-Francois Burnol %% % %<*changes>------------------------------------------------------- +\item[1.2 (2015/10/13)] + \begin{itemize} + \item requires \xintcorename |1.2| or later (if not using option |custom|). + \item additions to the syntax: factorial |!|, truncated division + |//|, its associated modulo |/:| and |**| as alternative to |^|. + \item all options removed except |custom|. + \item new command |\bnumexprsetup| which replaces the commands such as + |\bnumexprusesbigintcalc|. + \item the parser is no more limited to numbers with at most 5000 digits. + \end{itemize} + \item[1.1b (2014/10/28)] \begin{itemize} \item README converted to |markdown/pandoc| syntax, @@ -213,10 +211,10 @@ and the derived files \input docstrip.tex \askforoverwritefalse \generate{\nopreamble\nopostamble -\file{bnumexprReadme.md}{\from{bnumexpr.dtx}{readme}} +\file{README.md}{\from{bnumexpr.dtx}{readme}} \usepreamble\defaultpreamble \usepostamble\defaultpostamble -\file{bnumexpr.changes}{\from{bnumexpr.dtx}{changes}} +\file{bnumexprchanges.tex}{\from{bnumexpr.dtx}{changes}} \file{bnumexpr.tex}{\from{bnumexpr.dtx}{drv}} \file{bnumexpr.sty}{\from{bnumexpr.dtx}{package}}} \catcode32=13\relax% active space @@ -279,10 +277,10 @@ and the derived files \input docstrip.tex \askforoverwritefalse \generate{\nopreamble\nopostamble - \file{bnumexprReadme.md}{\from{bnumexpr.dtx}{readme}} + \file{README.md}{\from{bnumexpr.dtx}{readme}} \usepreamble\defaultpreamble \usepostamble\defaultpostamble - \file{bnumexpr.changes}{\from{bnumexpr.dtx}{changes}} + \file{bnumexprchanges.tex}{\from{bnumexpr.dtx}{changes}} \file{bnumexpr.ins}{\from{bnumexpr.dtx}{ins}} \file{bnumexpr.tex}{\from{bnumexpr.dtx}{drv}} \file{bnumexpr.sty}{\from{bnumexpr.dtx}{package}}} @@ -332,7 +330,8 @@ and the derived files \usepackage[hscale=0.66,vscale=0.75]{geometry} -\usepackage[zerostyle=a,scaled=0.95]{newtxtt} +% requires newtxtt 1.05 or later +\usepackage[zerostyle=a,scaled=0.95,straightquotes]{newtxtt} \renewcommand\familydefault\ttdefault \usepackage[noendash]{mathastext} \renewcommand\familydefault\sfdefault @@ -343,20 +342,20 @@ and the derived files \definecolor{JOLI}{RGB}{225,95,0} \definecolor{BLUE}{RGB}{0,0,255} \definecolor{niceone}{RGB}{38,128,192} -\colorlet{jfverbcolor}{yellow!5} +\colorlet{smallverbcolor}{RoyalPurple}% \colorlet{jfverbcolor}{yellow!5} +\colorlet{softwrapcolor}{blue} +\colorlet{digitscolor}{OrangeRed} -% transféré de xint-manual.tex +% transféré de xint-manual.tex (maintenant dans xint.dtx) \DeclareFontFamily{U}{MdSymbolC}{} \DeclareFontShape {U}{MdSymbolC}{m}{n}{<-> MdSymbolC-Regular}{} \makeatletter \newbox\cdbx@SoftWrapIcon -\colorlet {softwrapicon}{blue} - \def\cdbx@SetSoftWrapBox{% \setbox\cdbx@SoftWrapIcon\hb@xt@\z@ {\hb@xt@\fontdimen2\font - {\hss{\color{softwrapicon}\usefont{U}{MdSymbolC}{m}{n}\char"97}\hss}% + {\hss{\color{softwrapcolor}\usefont{U}{MdSymbolC}{m}{n}\char"97}\hss}% \hss}% } \makeatother @@ -380,14 +379,15 @@ pdfpagemode=UseOutlines} %---- \verb, and verbatim like `environments'. \MicroFont et \MacroFont \makeatletter -\def\MicroFont {\ttfamily \cdbx@SetSoftWrapBox } +\def\MicroFont {\ttfamily\cdbx@SetSoftWrapBox\color{smallverbcolor}} +%\def\MicroFont {\ttfamily \color[named]{OrangeRed}\cdbx@SetSoftWrapBox } % \MacroFont est utilisé par macrocode, mais sa définition est figée dans % \macro@font au \begin{document} \def\MacroFont {\ttfamily \baselineskip12pt\relax } -%--- November 4, 2014 making quotes straight. +%--- November 4, 2014 making quotes straight. (maintenu pour *) % % there is no hook in \macrocode after \dospecials etc. Thus I will need to % take the risk that some future evolution of doc.sty (or perhaps scrdoc) @@ -398,7 +398,7 @@ pdfpagemode=UseOutlines} \def\macrocode{\macro@code \frenchspacing \@vobeyspaces - \makestarlowast\makequotesstraight + \makestarlowast % \makequotesstraight (obsolète) \xmacro@code } %--- lower * symbol in text @@ -408,72 +408,92 @@ pdfpagemode=UseOutlines} \def\makestarlowast {\let*\lowast\catcode`\*\active}% \catcode`* 12 +%------------obsolete------------ %--- straight quotes, added (finally...) Nov 4, 2014 - -\begingroup\makeatletter - \catcode`\'\active - \catcode`\`\active -\@firstofone {\endgroup - \def\makequotesstraight {% textcomp package has been loaded by newtxtt - \let`\textasciigrave - \let'\textquotesingle - \catcode39\active - \catcode96\active }% -} - -% Tentative, Mardi 09 septembre 2014 à 22:41:28 -% (not usable in footnotes) -\def\verb -% on pourrait mettre le #1 ici et économiser \@@jfverb +% \begingroup\makeatletter +% \catcode`\'\active +% \catcode`\`\active +% \@firstofone {\endgroup +% \def\makequotesstraight {% textcomp package has been loaded by newtxtt +% \let`\textasciigrave +% \let'\textquotesingle +% \catcode39\active +% \catcode96\active }% +% } +%------------ + +% Tentative, mardi 09 septembre 2014 à 22:41:28 + +% Modifié mardi 13 octobre 2015 à 15:24:00 pour utilisable en +% argument, et en particulier dans un \footnote{}. Mais utilise +% \scantokens et macro délimitée maintenant. + +\def\verb #1% {% \relax\leavevmode\null - \begingroup\MicroFont + \begingroup + \MicroFont + \def\@jfverb ##1#1{\let\do\@makeother \dospecials + \makestarlowast %\let\do\do@noligs \verbatim@nolig@list % not needed here - \let\do\@makeother \dospecials - \makestarlowast \makequotesstraight % added here Nov 4, 2014 -% I should also take care of verbatim environment, but this is not needed in -% bnumexpr.dtx - \@vobeyspaces \fboxsep\z@ - \@@jfverb + \@vobeyspaces\everyeof{\noexpand}% + \expandafter\@@jfverb\scantokens{##1}\relax}% + \@jfverb }% -\def\@@jfverb #1{\catcode`#1 3 \@@@jfverb } +% Pour v1.2 je laisse tomber les colorbox. À la place je change la couleur +% du texte. J'utilise le violet de xint. (mis dans \Microfont) +% \def\@@@jfverb #1{\ifcat\noexpand#1$% $ +% \endgroup\else +% % \penalty\z@ +% \discretionary{\copy\cdbx@SoftWrapIcon}{}{}% +% % \colorbox{jfverbcolor}{\strut #1}% unfortunately, impacts pdf size +% #1% +% \expandafter\@@@jfverb\fi } -\def\@@@jfverb #1{\ifcat\noexpand#1$% $ - \endgroup\else -% \penalty\z@ - \discretionary{\copy\cdbx@SoftWrapIcon}{}{}% - \colorbox{jfverbcolor}{\strut #1}% unfortunately, impacts pdf size - \expandafter\@@@jfverb\fi } +\def\@@jfverb #1{\ifcat\noexpand#1\relax\endgroup\else + \discretionary{\copy\cdbx@SoftWrapIcon}{}{}% + #1\expandafter\@@jfverb\fi } \makeatother -% currently, used only in (sub)-section titles from implementation part -% let's use there also sans font, not monotype +% mardi 13 octobre 2015 à 15:32:51 +% le | n'est pas encore actif ici! +\catcode`| \active + \def\bneshow #1% + {|\thebnumexpr#1\relax|$$\color{digitscolor}\thebnumexpr#1\relax$$} +\catcode`| 12 \DeclareRobustCommand\csa [1]{{\char92\detokenize{#1}}} \newcommand\csh[1]{\texorpdfstring{\csa{#1}}{\textbackslash\detokenize{#1}}} \usepackage{xspace} -\def\bnename - {\texorpdfstring - {\hyperref[sec:bnumexpr]{{\color{joli}\ttzfamily bnumexpr}}} - {bnumexpr}% - \xspace }% -\def\bnenameimp +\def\bnumname + {\href{http://www.ctan.org/pkg/bnumexpr}{bnumexpr}\xspace }% + +\def\bnumnameimp {\texorpdfstring - {\hyperref[sec:bnumexprcode]{{\color[named]{RoyalPurple}\ttzfamily bnumexpr}}} + {\hyperref[sec:bnumexprcode]{{\color{smallverbcolor}\ttzfamily bnumexpr}}} {bnumexpr}% \xspace }% +\def\xintname + {\href{http://www.ctan.org/pkg/xint}{xint}\xspace }% +\def\xintcorename + {\href{http://www.ctan.org/pkg/xint}{xintcore}\xspace }% +\def\xintexprname + {\href{http://www.ctan.org/pkg/xint}{xintexpr}\xspace }% + + \frenchspacing -% possible options: custom, bigintcalc, l3bigint, nocsv, notacitmul, allowpower -\usepackage[allowpower]{bnumexpr} +\usepackage{bnumexpr} \usepackage{etoc} +\usepackage{framed} +\makeatletter\let\check@percent\relax\makeatother \begin{document} \thispagestyle{empty} \ttzfamily @@ -482,7 +502,7 @@ pdfpagemode=UseOutlines} {% \normalfont\Large\parindent0pt \parfillskip 0pt\relax \leftskip 2cm plus 1fil \rightskip 2cm plus 1fil - The \bnename package\par + The \bnumname package\par } {\centering @@ -497,205 +517,206 @@ pdfpagemode=UseOutlines} \etocsetnexttocdepth{section} \tableofcontents -\section{Readme} -\begingroup -\makeatletter\def\x{\baselineskip10pt - \ttfamily\settowidth\dimen@{X}% - %\parindent \dimexpr.5\linewidth-34\dimen@\relax - \parindent\z@ - \let\do\do@noligs\verbatim@nolig@list - \let\do\@makeother\dospecials - \makestarlowast\makequotesstraight - %\def\par{\leavevmode\null\@@par\penalty\interlinepenalty}% - \def\par{\leavevmode\null\@@par\pagebreak[1]}% - \@vobeyspaces\obeylines - \noindent\kern\parindent\input bnumexprReadme.md -\endgroup }\x +\section{Examples} +\label{sec:bnumexpr} +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. +Examples: -\section{Introduction} -\label{sec:bnumexpr} +\noindent\bneshow {1208637867168*(2187917891279+3109197072870)}% +\bneshow {(1380891090-30018902902)*(108319083901-10982903890)}% +\bneshow {30!/20!/21/22/23/24/25/(26*27*28*29)}% +\bneshow {13^50//12^50, 13^50/:12^50}% +\bneshow {13^50/12^50, 12^50}% +\bneshow {(1^10+2^10+3^10+4^10+5^10+6^10+7^10+8^10+9^10)^3}% +\bneshow {100!/36^100}% + +\section{Differences from \csh{numexpr}} + +Apart from the extension to big integers (i.e. exceeding the \TeX{} limit at +\number"7FFFFFFF), and the added operators, there are a number of important +differences between |\bnumexpr| and |\numexpr|: -Package \bnename provides |\bnumexpr...\relax| which is analogous to -|\numexpr...\relax|, while allowing arbitrarily big -integers. Important items: \begin{enumerate} \item one must use either |\thebnumexpr| or |\bnethe\bnumexpr| to get a - printable result, as |\bnumexpr...\relax| expands to a private format; - however one may embed directly one |\bnumexpr...\relax| in another - |\bnumexpr...\relax|, + printable result, as |\bnumexpr...\relax| expands to a private format, + +\item one may embed directly (without |\bnethe|) a |\bnumexpr...\relax| + in another one (or in a |\xintexpr...\relax|), but not in a + |\numexpr...\relax|; on the other hand a |\numexpr...\relax| does not need to + be prefixed by |\the| or |\number| inside |\bnethe\bnumexpr| or + |\thebnumexpr|, \item contrarily to |\numexpr|, the |\bnumexpr| parser stops only after having - found (and swallowed) the mandatory ending |\relax| token, + found (and swallowed) a mandatory ending |\relax| token, \item in particular spaces between digits do not stop |\bnumexpr|, in contrast with |\numexpr|: |\the\numexpr 3 5+79\relax| expands (in one step) to \expandafter|\the\numexpr 3 5+79\relax| - |\thebnumexpr 3 5+79\relax| expands (in two steps) to \expandafter\expandafter\expandafter|\thebnumexpr 3 5+79\relax| + |\thebnumexpr 3 5+79\relax| expands (in two steps) to + \expandafter\expandafter\expandafter|\thebnumexpr 3 5+79\relax| -\item one may do |\edef\tmp{\bnumexpr 1+2\relax}|, and then either use |\tmp| - in another |\bnumexpr...\relax|, or print it via |\bnethe\tmp|. The - computation is done at the time of the |\edef| (and two expansion steps - suffice). This is again in contrast with |\numexpr...\relax| which, without - |\the| or |\number| as prefix would not expand in an |\edef|, +\item one may do |\edef\tmp{\bnumexpr 1+2\relax}|, and then either use + |\tmp| in another |\bnumexpr...\relax|, or print it via + |\bnethe\tmp|. The computation is done at the time of the |\edef| + (and two expansion steps suffice). This is again in contrast with + |\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. This may be de-activated by option |notacitmul|, +\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. This functionality may be turned off via option |nocsv|, + each comma. -\item even with options |notacitmul| and |nocsv| the syntax is more flexible - than with |\numexpr|: things such as - |\bnumexpr -(1+1)\relax| are legal. +\item |\bnumexpr -(1+1)\relax| is legal contrarily to |\numexpr -(1+1)\relax| + which raises an error. \end{enumerate} +An important thing to keep in mind is that if one has a calculation +whose result is a small integer, acceptable by \TeX{} in |\ifnum| or +count assignments, this integer produced by |\thebnumexpr| is not +self-delimiting, contrarily to a |\numexpr...\relax| construct: the +situation is exactly as with a |\the\numexpr...\relax|, thus one may +need to terminate the number to avoid premature expansion of following +tokens; for example with the |\space| token. + The parser |\bnumexpr| is a scaled-down version of parser |\xintiiexpr| from -package \href{http://www.ctan.org/pkg/xint}{xintexpr}. The goal here is to -extend |\numexpr| only to the extent of accepting big integers. Thus by -default, the syntax allows |+,-,*,/|, parentheses, and also |\count| or -|\dimen| registers or variables. Option |allowpower| is a bonus which enables -|^| as power operator. It may well be that the code of the parser is in some -places quite sub-optimal as it was derived from code handling far more stuff. - -The |\xintNewExpr| construct has been left out. - -Package \bnename needs some underlying big integer engine to provide the -macros doing the actual computations. By default, it loads package |xintcore| (a -subset of \href{http://www.ctan.org/pkg/xint}{xint}) and its |\xintiiAdd|, -|\xintiiSub|, |\xintiiMul|, and |\xintiiDivRound| macros (also |\xintiiPow| if -option |allowpower| is made use of). -See the discussion of options |bigintcalc|, |l3bigint| and |custom| in -the next section %\autoref{sec:options} -for alternatives. - -I recall from documentation of |xintexpr| that there is a potential impact on -the memory of \TeX{} (the hash table) because each arithmetic operation is -done inside a dummy |\csname...\endcsname| used as single token to move -around in one-go the possibly hundreds of digits composing a number. This -becomes apparent only if the document does (tens of) thousands of evaluations. - -\section{Options}\label{sec:options} - -The package does by default: +package \xintexprname. It lacks in particular +boolean operators, square roots and other functions, variables, hexadecimal +inputs, etc... it may be slightly faster when handling complicated +expressions as it does not have to check so many things. + +I recall from the documentation of \xintexprname that there is a +potential impact on the memory of \TeX{} (the string pool, the hash +table) because each intermediate number is stored as a dummy control +sequence name during processing. After thousands of evaluations with +numbers having hundreds of digits parts of the \TeX{} memory will become +saturated and end the |(pdf)etex| run (but the problem can in theory be +avoided through the use of a ``bigger'' \TeX{} compiled with enlarged +memory parameters). Anyhow, computations with thousands of digits take +time, and this is probably a more stringent constraint. + +If the same expession needs to be evaluated again and again tens of +thousands of times, it may be necessary to drop use of \bnumname and +either use directly the macros from package \xintcorename, or apply +|\xintNewIIExpr| from package \xintexprname to first construct the +possibly very complicated nested macro. + +The \eTeX{} extensions are required (default on all modern installations, with +the exception of the |tex| executable, one should use |etex| rather). + +\section{Printing big numbers} + +\LaTeX{} will not split long numbers at the end of lines. I personally +often use helper macros (not in the package) of the following type: + \begin{verbatim} -\RequirePackage{xintcore} -\let\bnumexprAdd\xintiiAdd -\let\bnumexprSub\xintiiSub -\let\bnumexprMul\xintiiMul -\let\bnumexprMul\xintiiDivRound -\let\bnumexprPow\xintiiPow % only if option allowpower +\def\allowsplits #1{\ifx #1\relax \else #1\hskip 0pt plus 1pt\relax + \expandafter\allowsplits\fi}% +\def\printnumber #1{\expandafter\allowsplits \romannumeral-`0#1\relax }% +% \printnumber thus first ``fully'' expands its argument. \end{verbatim} -% To let |/| do euclidean division (like currently in |\xintiiexpr|) it is -% thus sufficient to do |\let\bnumexprDiv\xintiiQuo| after loading the package. -Option |bigintcalc| says to not load -\href{http://www.ctan.org/pkg/xint}{xintcore} -but to use rather the macros from package -\href{http://www.ctan.org/pkg/bigintcalc}{bigintcalc} -by \textsc{Heiko Oberdiek}. Note though that |/| is mapped to |\bigintcalcDiv| -which does \emph{truncated} (not rounded) division. +\def\allowsplits #1{\ifx #1\relax \else #1\hskip 0pt plus 1pt\relax + \expandafter\allowsplits\fi}% +\def\printnumber #1{\expandafter\allowsplits \romannumeral-`0#1\relax }% + +\noindent|\thebnumexpr 1000!\relax=|\phantom{0}{\color{digitscolor}\printnumber{\thebnumexpr 1000!\relax}}\par + +\section{Expression syntax} -Option |l3bigint| similarly says to use the macros which are provided with the -eponym package, a part of the development work of the -\href{http://latex-project.org/code.html}{\LaTeX3 project}. There is no power -operation available with this option. +It is the expected one with infix operators and parentheses, the +recognized operators being |+|, |-|, |*|, |/| (rounded division), +|^| (power), |**| (power), |//| (truncated division), |/:| (modulo) +and |!| (factorial). -Option |custom| does not load any package and leaves it up to the user to -specify the macros to be used, i.e. provide definitions for |\bnumexprAdd|, -|\bnumexprSub|, |\bnumexprMul|, |\bnumexprDiv| (and possibly |\bnumexprPow|). -These macros must be expandable, and they must allow arguments in need to be -first (`f'-) expanded. They should produce on output (big) integers with no -leading zeros, at most one minus sign and no plus sign (else the \bnename macro -used for handling the |-| prefix operator may need to be modified). They will be -expanded inside |\csname...\endcsname|. The macros from |xintcore.sty| (as well -as those of |bigintcalc.sty|) are expandable in a stronger sense (only two -expansion steps suffice). Perhaps speed gains are achievable from dropping these -stronger requirements. +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. -Option |nocsv| makes comma separated expressions illegal. +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)} -Option |notacitmul| removes the possibility of tacit multiplication in front of -parentheses, \string\count\space registers, sub-expressions. +The three operators |/|, |//|, |/:| are at the same level of +precedence as the multiplication |*|. The modulo |/:| is associated +with truncated division |//|. -Option |allowpower| enables the |^| as power operator (left associative). +The factorial postfix |!| has highest precedence. The minus signs +inherit the precedence level of the previously encountered operators. -\section{Further commands} +\section{Option custom, \csh{bnumexprsetup}}\label{sec:options} -The package provides |\bnumexprUsesxint|, |\bnumexprUsesbigintcalc| and -|\bnumexprUsesliiibigint|: after issuing one of these commands, -|\bnumexpr...\relax| will use the arithmetic macros from the corresponding -package. But it is up to the user to have issued the necessary |\usepackage| -or |\RequirePackage| in the preamble. It does not matter if the packages are -loaded before or after \bnename. +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 +way: +\begin{verbatim} + \usepackage{xintcore} + \bnumexprsetup{add=\xintiiAdd, sub=\xintiiSub, mul=\xintiiMul, + divround=\xintiiDivRound, divtrunc=\xintiiDivTrunc, + mod=\xintiiMod, pow=\xintiiPow, fac=\xintiiFac} +\end{verbatim} -Recall that |xintcore| is loaded by default, but is not loaded in case of one -of the options |custom|, |bigintcalc|, |l3bigint|. +The keys given to \csa{bnumexprsetup} must be lowercased. If +using \csa{bnumexprsetup}, it is not necessary to specify all keys, +for example one can do |\bnumexprsetup{mul=\MyFasterMul}|, and only +multiplication will be changed. +Naturally it is up to the user to load the appropriate package for +the alternative macros. -\section{Examples} +As per the macros which are the key values, they must have the +following properties: +\begin{enumerate} +\item they must be completely expandable (in the sense of an |\edef| + or a |\csname...\endcsname|.) +\item they must fully expand their arguments first (in the sense of + |\romannumeral-`0|.) +\item they must output a number with no leading zeros, at most one + minus sign and no plus sign. +\end{enumerate} +The first two items are truly mandatory, the last one may be not +obeyed if the extra key |opp| is used with \csa{bnumexprsetup} to +specify a suitable macro for the opposite of a number. This macro will +be presented not with a braced argument but directly with a sequence +of digits (either as gathered by the parser which skips leading +zeros, or in the format produced by the other arithmetic macros). +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. -\begin{flushleft}\parindent0pt \obeylines -|\thebnumexpr 128637867168*2187917891279\relax| % -\thebnumexpr 128637867168*2187917891279\relax - -|\thebnumexpr 30*(21-43*(512-67*(6133-812*2897)))\relax| % -\thebnumexpr 30*(21-43*(512-67*(6133-812*2897)))\relax - -\newcount\cnta\cnta 123 -\newcount\cntb \cntb 188 - -|\newcount\cnta \cnta 123 \newcount\cntb \cntb 188| -% |\the\numexpr \cnta*\cnta*\cnta\relax| % -% \the\numexpr \cnta*\cnta*\cnta\relax {} -% |\the\bnumexpr \cnta*\cnta*\cnta\relax| % -% \thebnumexpr \cnta*\cnta*\cnta\relax {} -|\the\numexpr \cnta*\cnta*\cnta/\cntb+\cntb*\cntb*\cntb/\cnta\relax| % -\the\numexpr \cnta*\cnta*\cnta/\cntb+\cntb*\cntb*\cntb/\cnta\relax {} -|\thebnumexpr \cnta*\cnta*\cnta/\cntb+\cntb*\cntb*\cntb/\cnta\relax| % -\thebnumexpr \cnta*\cnta*\cnta/\cntb+\cntb*\cntb*\cntb/\cnta\relax {} - -% |\the\numexpr \cnta*\cnta*(\cnta/\cntb)+\cntb*\cntb*(\cntb/\cnta)\relax| -% \the\numexpr \cnta*\cnta*(\cnta/\cntb)+\cntb*\cntb*(\cntb/\cnta)\relax {} -% |\thebnumexpr \cnta*\cnta*(\cnta/\cntb)+\cntb*\cntb*(\cntb/\cnta)\relax| -% \thebnumexpr \cnta*\cnta*(\cnta/\cntb)+\cntb*\cntb*(\cntb/\cnta)\relax {} -|\the\numexpr 123/188*188\relax|, |\the\numexpr 123/(188*188)\relax|, % -|\thebnumexpr 123/188*188\relax|, |\thebnumexpr 123/(188*188)\relax|. -\the\numexpr 123/188*188\relax, \the\numexpr 123/(188*188)\relax, % -\thebnumexpr 123/188*188\relax, \thebnumexpr 123/(188*188)\relax. - -\edef\tmp {\bnumexpr 121873197*123-218137917*188\relax} -|\edef\tmp {\bnumexpr 121873197*123-218137917*188\relax}\bnethe\tmp| -\bnethe\tmp {} -|\meaning\tmp| -\meaning\tmp {} -|\thebnumexpr \tmp*(173197129797-\tmp)*(2179171982-\tmp)\relax| -\thebnumexpr \tmp*(173197129797-\tmp)*(2179171982-\tmp)\relax - -|\cnta \thebnumexpr 2152966419779999/987654321\relax\space| -|\the\cnta| % -\cnta \thebnumexpr 2152966419779999/987654321\relax\space \the\cnta - -|\thebnumexpr 2179878*987654321-2152966419779999, 2179879*987654321-2152966419779999\relax| -\thebnumexpr 2179878*987654321-2152966419779999,2179879*987654321-2152966419779999\relax\ (there was indeed rounding of the exact quotient.) - -Some example with the power operator |^|: -\ \ \ \ (requires option |allowpower|, not compatible with |l3bigint|) -|\thebnumexpr (1^10+2^10+3^10+4^10+5^10+6^10)^3\relax| % -\thebnumexpr (1^10+2^10+3^10+4^10+5^10+6^10)^3\relax - -|\thebnumexpr 2^31-1,2^31,2^31+1,2^100\relax| -\thebnumexpr 2^31-1,2^31,2^31+1,2^100\relax -\end{flushleft} +\section{Readme} +\begingroup +\makeatletter\def\x{\baselineskip10pt + \ttfamily\settowidth\dimen@{X}% + %\parindent \dimexpr.5\linewidth-34\dimen@\relax + \parindent\z@ + \let\do\do@noligs\verbatim@nolig@list + \let\do\@makeother\dospecials + \makestarlowast + %\def\par{\leavevmode\null\@@par\penalty\interlinepenalty}% + \def\par{\leavevmode\null\@@par\pagebreak[1]}% + \@vobeyspaces\obeylines + \noindent\kern\parindent\input README.md +\endgroup }\x \section{Changes} %\small \begin{description} -\input bnumexpr.changes +\input bnumexprchanges.tex \end{description} \StopEventually{\end{document}\endinput} @@ -712,7 +733,7 @@ Some example with the power operator |^|: % %<*package> % -% \section{Package \bnenameimp implementation} +% \section{Package \bnumnameimp implementation} % \label{sec:bnumexprcode} % % \localtableofcontents \bigskip @@ -722,10 +743,11 @@ Some example with the power operator |^|: % control sequence attempts to trigger writing to the log of some sort of % informative message. It is recommended to set |\errorcontextlines| to at % least |2| for more meaningful context. +% % \subsection{Package identification and catcode setup} % \begin{macrocode} \NeedsTeXFormat{LaTeX2e}% -\ProvidesPackage{bnumexpr}[2014/10/28 v1.1b Expressions with big integers (jfB)]% +\ProvidesPackage{bnumexpr}[2015/10/13 v1.2 Expressions with big integers (jfB)]% \edef\BNErestorecatcodes {\catcode`\noexpand\!\the\catcode`\! \catcode`\noexpand\?\the\catcode`\? \catcode`\noexpand\_\the\catcode`\_ @@ -738,84 +760,9 @@ Some example with the power operator |^|: \catcode`\? 11 \catcode`\_ 11 \catcode`\: 11 -% \end{macrocode} -% \subsection{Package options} -% \begin{macrocode} -\def\BNE_tmpa {0}% -\DeclareOption {custom}{\def\BNE_tmpa {1}% - \PackageWarningNoLine{bnumexpr}{^^J - Option custom: package xintcore not loaded. Definitions are needed for:^^J - \protect\bnumexprAdd, \protect\bnumexprSub, - \protect\bnumexprMul\space and \protect\bnumexprDiv }% -}% -\DeclareOption {bigintcalc}{\def\BNE_tmpa {2}% - \PackageWarningNoLine{bnumexpr}{^^J - Option bigintcalc: the macros from package bigintcalc are used.^^J - Notice that / is mapped to \protect\bigintcalcDiv\space which does truncated division}% -}% -\DeclareOption {l3bigint}{\def\BNE_tmpa {3}% - \PackageWarningNoLine{bnumexpr}{^^J - Option l3bigint: the macros from package l3bigint are used.^^J - There is no power operation, currently}% -}% -\DeclareOption {nocsv}{% - \PackageInfo{bnumexpr}{Comma separated expressions disabled}% - \AtEndOfPackage{\expandafter\let\csname BNE_precedence_,\endcsname - \undefined }% -}% -\DeclareOption {notacitmul}{% - \PackageInfo{bnumexpr}{Tacit multiplication disabled}% - \AtEndOfPackage{\BNE_notacitmultiplication}% -}% -\def\BNE_allowpower {0}% -\DeclareOption {allowpower}{% - \PackageInfo{bnumexpr}{Power operator ^ authorized}% - \def\BNE_allowpower {1}% -}% -\ProcessOptions\relax -% \end{macrocode} -% \subsection{Mapping to an underlying big integer engine.} -% In case option |bigintcalc| is used, notice that |/| is mapped to the macro -% |\bigintcalcDiv| which does truncated division. We did not add the extra code -% for rounded division in that case. -% -% With option |l3bigint|, there is no power operation available currently. -% Furthermore the package is part of the experimental trunk of the \LaTeX3 -% project hence the names of its macros could change. -% \begin{macrocode} -\def\bnumexprUsesxint {% - \let\bnumexprAdd\xintiiAdd - \let\bnumexprSub\xintiiSub - \let\bnumexprMul\xintiiMul - \let\bnumexprDiv\xintiiDivRound - \let\bnumexprPow\xintiiPow -}% -\def\bnumexprUsesbigintcalc {% - \let\bnumexprAdd\bigintcalcAdd - \let\bnumexprSub\bigintcalcSub - \let\bnumexprMul\bigintcalcMul - \let\bnumexprDiv\bigintcalcDiv % NOTE: THIS DOES TRUNCATED DIVISION - \let\bnumexprPow\bigintcalcPow -}% -\def\bnumexprUsesliiibigint {% - \let\bnumexprAdd\bigint_add:nn - \let\bnumexprSub\bigint_sub:nn - \let\bnumexprMul\bigint_mul:nn - \let\bnumexprDiv\bigint_div_round:nn - \let\bnumexprPow\bigint_pow:nn % does not exist! -}% -\if0\BNE_tmpa % Toggle to load xintcore.sty - \RequirePackage{xintcore}% - \bnumexprUsesxint -\fi -\if2\BNE_tmpa % Toggle to load bigintcalc.sty - \RequirePackage{bigintcalc}% - \bnumexprUsesbigintcalc -\fi -\if3\BNE_tmpa % Toggle to load l3bigint.sty - \RequirePackage{l3bigint}% - \bnumexprUsesliiibigint -\fi +\catcode`\, 12 +\catcode`\* 12 +\catcode`\( 12 % \end{macrocode} % \subsection{Some helper macros and constants from xint} % These macros from xint should not change, hence overwriting them here should @@ -828,15 +775,11 @@ Some example with the power operator |^|: \chardef\xint_c_ 0 \chardef\xint_c_i 1 \chardef\xint_c_ii 2 -% \chardef\xint_c_iii 3 -% \chardef\xint_c_iv 4 -% \chardef\xint_c_v 5 \chardef\xint_c_vi 6 \chardef\xint_c_vii 7 \chardef\xint_c_viii 8 \chardef\xint_c_ix 9 -% \chardef\xint_c_x 10 -% \chardef\xint_c_xviii 18 +\chardef\xint_c_x 10 \long\def\xint_gobble_i #1{}% \long\def\xint_gobble_iii #1#2#3{}% \long\def\xint_firstofone #1{#1}% @@ -845,34 +788,45 @@ Some example with the power operator |^|: \long\def\xint_firstofthree #1#2#3{#1}% \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}% +\def\xint_gob_til_! #1!{}% this ! has catcode 11 +\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}% new in v1.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 }% % \end{macrocode} -% \subsection{Encapsulation of numbers in pseudo cs names} -% We define here a |\BNE_num| to not have to invoke |\xintNum|; hence -% dependency on |xint.sty| is kept to the actual arithmetic operations. We -% only need to get rid of leading zeros as plus and minus signs have already -% been stripped off; generally speaking user input will have no leading zeros -% thus the macro is designed to go fast when it is not needed... and as -% everything happens inside a |\csname...\endcsname|, we can leave some -% trailing |\fi|'s. +% \subsection{\csh{bnumexprsetup}} +% New with |v1.2|. Replaces removed |\bnumexprUsesbigintcalc| etc... % \begin{macrocode} -\edef\BNE_lock #1!{\noexpand\expandafter\space\noexpand - \csname .=\noexpand\BNE_num #1\endcsname }% -\def\BNE_num #1{\if #10\expandafter\BNE_num\else - \ifcat #1\relax 0\expandafter\expandafter\expandafter #1\else - #1\fi\fi }% -\def\BNE_unlock {\expandafter\BNE_unlock_a\string }% -\def\BNE_unlock_a #1.={}% +\catcode`! 3 +\def\bnumexprsetup #1{\BNE_parsekeys #1,=!,}% +\def\BNE_parsekeys #1=#2#3,{\ifx!#2\expandafter\BNE_parsedone\fi + \edef\BNE_tmpc{\xint_zapspaces #1 \xint_gobble_i}% + \expandafter\let\csname BNE_Op_\BNE_tmpc\endcsname=#2\BNE_parsekeys +}% +\catcode`! 11 +\def\BNE_parsedone #1\BNE_parsekeys {}% +% \end{macrocode} +% \subsection{Package options} +% \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]% + \bnumexprsetup{add=\xintiiAdd, sub=\xintiiSub, mul=\xintiiMul, + divround=\xintiiDivRound, divtrunc=\xintiiDivTrunc, + mod=\xintiiMod, pow=\xintiiPow, fac=\xintiiFac}% +\fi % \end{macrocode} % \subsection{\csh{bnumexpr}, \csh{bnethe}, \csh{thebnumexpr}, \dots} % In the full |\xintexpr|, the final unlocking may involve post-treatment of % the comma separated values, hence there are |_print| macros to handle the % possibly comma separated values. Here we may just identify |_print| with % |_unlock|. +% +% With |v1.2| the gathering of numbers happens directly inside +% |\csname...\endcsname|. There is no more a ``locking'' macro. % \begin{macrocode} \def\bnumexpr {\romannumeral0\bnumeval }% \def\bnumeval {\expandafter\BNE_wrap\romannumeral0\BNE_eval }% @@ -884,6 +838,8 @@ Some example with the power operator |^|: \def\thebnumexpr {\romannumeral-`0\expandafter\BNE_unlock\romannumeral0\BNE_eval }% \def\bnethe #1{\romannumeral-`0\expandafter\xint_gobble_iii\romannumeral-`0#1}% +\def\BNE_unlock {\expandafter\BNE_unlock_a\string }% +\def\BNE_unlock_a #1.={}% % \end{macrocode} % \subsection{\csh{BNE_getnext}} % The getnext scans forward to find a number: after expansion of what comes @@ -897,7 +853,10 @@ Some example with the power operator |^|: % number scanner. After the digit scanner finishes the integer is trimmed of % leading zeros and locked as a single token into a |\csname .=...\endcsname|. % The flow then proceeds with |\BNE_getop| which looks for the next operator -% or possibly the end of the expression. Note: |\bnumexpr\relax| is illegal. +% or possibly the end of the expression. Note: |\bnumexpr\relax| is +% illegal. +% +% Extended in v1.2 to recognize |\ht|, etc... % \begin{macrocode} \def\BNE_getnext #1% {% @@ -916,16 +875,18 @@ Some example with the power operator |^|: \def\BNE_gn_foundexpr !#1\fi !{\expandafter\BNE_getop\xint_gobble_iii }% \def\BNE_gn_countetc #1% {% - \ifx\count#1\else\ifx#1\dimen\else\ifx#1\numexpr\else\ifx#1\dimexpr\else - \ifx\skip#1\else\ifx\glueexpr#1\else\ifx\fontdimen#1\else + \ifx\count#1\else\ifx\dimen#1\else\ifx\numexpr#1\else\ifx\dimexpr#1\else + \ifx\skip#1\else\ifx\glueexpr#1\else\ifx\fontdimen#1\else\ifx\ht#1\else + \ifx\dp#1\else\ifx\wd#1\else\ifx\fontcharht#1\else\ifx\fontcharwd#1\else + \ifx\fontchardp#1\else\ifx\fontcharic#1\else \BNE_gn_unpackvar - \fi\fi\fi\fi\fi\fi\fi + \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi \expandafter\BNE_getnext\number #1% }% -\def\BNE_gn_unpackvar\fi\fi\fi\fi\fi\fi\fi\expandafter - \BNE_getnext\number #1% +\def\BNE_gn_unpackvar\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi + \expandafter\BNE_getnext\number #1% {% - \fi\fi\fi\fi\fi\fi\fi + \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi \expandafter\BNE_getop\csname .=\number#1\endcsname }% % \end{macrocode} @@ -944,41 +905,74 @@ Some example with the power operator |^|: % \subsection{Parsing an integer} % We gather a string of digits, plus and minus prefixes have already been % swallowed. There might be some leading string of zeros which will have to be -% removed. In the full |\xintexpr 1.1| the situation is more involved as it +% removed. In the full |\xintexpr| the situation is more involved as it % has to recognize and accept decimal numbers, numbers in scientific notation, % also hexadecimal numbers, function names, variable names\dots % \begin{macrocode} \def\BNE_scan_number #1% this #1 has necessarily here catcode 12 {% - \ifnum \xint_c_ix<1#1 \expandafter \BNE_scan_nbr\else - \expandafter \BNE_notadigit\fi #1% + \ifnum \xint_c_ix<1#1 \else\expandafter\BNE_notadigit\fi + \BNE_scan_nbr #1% }% -\def\BNE_notadigit #1{\BNE:not_a_digit! \xint_gobble_i {#1}}% +\def\BNE_notadigit\BNE_scan_nbr #1{\BNE:not_a_digit!\BNE_getnext }% % \end{macrocode} -% Scanning for a number. Once gathered, lock it and do |_getop|. If we hit -% against some catcode eleven |!|, this means there was a sub |\bnumexpr..\relax|. -% We then apply tacit multiplication. +% Scanning for a number. We gather it directly inside csname. earlier +% version did a chain of romannumeral. No limit on number of digits +% anymore from the maximal expansion depth. We only have to be careful +% about leading zeros. +% +% If we hit against some catcode eleven |!|, this means there was a +% sub |\bnumexpr..\relax|. We then apply tacit multiplication. % \begin{macrocode} -\def\BNE_scan_nbr +\def\BNE_scan_nbr #1% +{% the #1 here is a catcode 12 digit + \if#10\expandafter\BNE_scan_nbr_gobzeroes + \else + \expandafter\BNE_scan_nbr_start + \fi #1% +}% +\def\BNE_scan_nbr_start #1#2% +{% + \expandafter\BNE_getop\csname.=#1% + \expandafter\BNE_scanint_b\romannumeral-`0#2% +}% +\def\BNE_scan_nbr_gobzeroes #1% +{% + \expandafter\BNE_getop\csname.=% + \expandafter\BNE_gobz_scanint_b\romannumeral-`0#1% +}% +\def\BNE_scanint_b #1% {% - \expandafter\BNE_getop\romannumeral-`0\expandafter - \BNE_lock\romannumeral-`0\BNE_scan_nbr_c + \ifcat \relax #1\expandafter\BNE_scanint_endbycs\expandafter #1\fi + \ifnum\xint_c_ix<1\string#1 \else\expandafter\BNE_scanint_c\fi + \string#1\BNE_scanint_d }% -\def\BNE_scan_nbr_a #1% -{% careful that ! has catcode letter here - \ifcat \relax #1\xint_dothis{!#1}\fi % stops the scan - \ifx !#1\xint_dothis{!*!}\fi % tacit multiplication before subexpr - \xint_orthat {\expandafter\BNE_scan_nbr_b\string #1}% +\def\BNE_scanint_endbycs#1#2\BNE_scanint_d{\endcsname #1}% +\def\BNE_scanint_c\string #1\BNE_scanint_d +{% + \ifcat a#1\xint_dothis{\endcsname*}\fi % tacit multiplication + \xint_orthat {\expandafter\endcsname \string}#1% +}% +\def\BNE_scanint_d #1% +{% + \expandafter\BNE_scanint_b\romannumeral-`0#1% }% -\def\BNE_scan_nbr_b #1% #1 with catcode 12 +\def\BNE_gobz_scanint_b #1% {% - \ifnum \xint_c_ix<1#1 \expandafter\BNE_scan_nbr_c - \else\expandafter !\fi #1% + \ifcat \relax #1\expandafter\BNE_gobz_scanint_endbycs\expandafter #1\fi + \ifnum\xint_c_x<1\string#1 \else\expandafter\BNE_gobz_scanint_c\fi + \string#1\BNE_scanint_d }% -\def\BNE_scan_nbr_c #1#2% +\def\BNE_gobz_scanint_endbycs#1#2\BNE_scanint_d{0\endcsname #1}% +\def\BNE_gobz_scanint_c\string #1\BNE_scanint_d {% - \expandafter #1\romannumeral-`0\expandafter - \BNE_scan_nbr_a\romannumeral-`0#2% + \ifcat a#1\xint_dothis{0\endcsname*#1}\fi % tacit multiplication + \if 0#1\xint_dothis\BNE_gobz_scanint_d\fi + \xint_orthat {0\expandafter\endcsname \string#1}% +}% +\def\BNE_gobz_scanint_d #1% +{% + \expandafter\BNE_gobz_scanint_b\romannumeral-`0#1% }% % \end{macrocode} % \begin{macrocode} @@ -991,8 +985,10 @@ Some example with the power operator |^|: % context where the actual macro associated to the operator may vary, % depending if we are in |\xintexpr|, |\xintfloatexpr| or |\xintiiexpr|. Here % things are simpler but I have kept the general scheme, thus the actual macro -% to be used for the is not decided immediately (|xintexpr.sty| has -% extra things to allow multi-characters operators like |&&|). +% to be used for the is not decided immediately. +% +% |v1.2| adds a technique for allowing two-letters operators, for +% |//|, |/:| and |**|. % \begin{macrocode} \def\BNE_getop #1#2% this #1 is the current locked computed value {% @@ -1010,10 +1006,20 @@ Some example with the power operator |^|: \xint_orthat \xint_thirdofthree {\BNE_foundend #1}% {\BNE_precedence_* *#1#2}% tacit multiplication - {\BNE_foundop #2#1}% + {\BNE_scanop_a #2#1}% }% \catcode`* 12 \def\BNE_foundend {\xint_c_ \relax }% \relax is only a place-holder here. +\def\BNE_scanop_a #1#2#3% + {\expandafter\BNE_scanop_b\expandafter #1\expandafter #2\romannumeral-`0#3}% +\def\BNE_scanop_b #1#2#3% +{% + \ifcat#3\relax\xint_dothis{\BNE_foundop #1#2#3}\fi + \ifcsname BNE_itself_#1#3\endcsname + \xint_dothis + {\expandafter\BNE_foundop\csname BNE_itself_#1#3\endcsname #2}\fi + \xint_orthat {\BNE_foundop #1#2#3}% +}% \def\BNE_foundop #1% {% \ifcsname BNE_precedence_#1\endcsname @@ -1029,7 +1035,7 @@ Some example with the power operator |^|: % The minus sign as prefix is treated here. % \begin{macrocode} \catcode`) 11 -\def\BNE_tmpa #1{% #1=\BNE_op_-vi token +\def\BNE_tmpa #1{% \def\BNE_until_end_a ##1% {% \xint_UDsignfork @@ -1053,7 +1059,7 @@ Some example with the power operator |^|: \def\BNE_op_( {\expandafter\BNE_until_)_a\romannumeral-`0\BNE_getnext }% \let\BNE_oparen\BNE_op_( \catcode`( 12 -\def\BNE_tmpa #1{% #1=\BNE_op_-vi +\def\BNE_tmpa #1{% \def\BNE_until_)_a ##1{\xint_UDsignfork ##1{\expandafter \BNE_until_)_a\romannumeral-`0#1}% -{\BNE_until_)_b ##1}% @@ -1076,6 +1082,9 @@ Some example with the power operator |^|: % This is where the infix operators are mapped to actual macros. These macros % must ``f-expand'' their arguments, and know how to handle then big integers % having no leading zeros and at most a minus sign. +% +% |v1.2| adds |//| for truncated division, |/:| for modulo operations +% and |**| for powers (synonym to |^|). % \begin{macrocode} \def\BNE_tmpc #1#2#3#4#5#6#7% {% @@ -1108,17 +1117,31 @@ Some example with the power operator |^|: \csname #3\expandafter\endcsname \csname BNE_precedence_#1\endcsname }% -\BNE_tmpb +{vi}{bnumexprAdd}% -\BNE_tmpb -{vi}{bnumexprSub}% -\BNE_tmpb *{vii}{bnumexprMul}% -\BNE_tmpb /{vii}{bnumexprDiv}% -\if1\BNE_allowpower\BNE_tmpb ^{viii}{bnumexprPow}\fi +\BNE_tmpb +{vi}{BNE_Op_add}% +\BNE_tmpb -{vi}{BNE_Op_sub}% +\BNE_tmpb *{vii}{BNE_Op_mul}% +\BNE_tmpb /{vii}{BNE_Op_divround}% +\BNE_tmpb ^{viii}{BNE_Op_pow}% +\expandafter\def\csname BNE_itself_**\endcsname {**}% +\expandafter\def\csname BNE_itself_//\endcsname {//}% +\expandafter\def\csname BNE_itself_/:\endcsname {/:}% +\BNE_tmpb {**}{viii}{BNE_Op_pow}% +\BNE_tmpb {//}{vii}{BNE_Op_divtrunc}% +\BNE_tmpb {/:}{vii}{BNE_Op_mod}% +% \end{macrocode} +% \subsection{! as postfix factorial operator} +% New with |v1.2|. +% \begin{macrocode} +\let\BNE_precedence_! \xint_c_x +\def\BNE_tmpa #1{\def\BNE_op_! ##1{\expandafter\BNE_getop + \csname .=#1{\BNE_unlock ##1}\endcsname + }}% +\BNE_tmpa\BNE_Op_fac % \end{macrocode} % \subsection{The minus as prefix operator of variable precedence level} -% We only need here two levels of precedence, |vi| and |vii|. If the power |^| -% operation is authorized, then one further level |viii| is needed. +% It inherits the level of precedence of the previous operator. % \begin{macrocode} -\def\BNE_tmpa #1% #1=vi or vii +\def\BNE_tmpa #1% {% \expandafter\BNE_tmpb \csname BNE_op_-#1\expandafter\endcsname @@ -1144,15 +1167,15 @@ Some example with the power operator |^|: \csname BNE_op_##2\endcsname {##3}}% \else \xint_afterfi {\expandafter ##1\expandafter ##2% - \csname .=\expandafter\BNE_Opp + \csname .=\expandafter\BNE_Op_opp \romannumeral-`0\BNE_unlock ##3\endcsname }% \fi }% }% \BNE_tmpa {vi}% \BNE_tmpa {vii}% -\if1\BNE_allowpower\BNE_tmpa {viii}\fi -\def\BNE_Opp #1{\if-#1\else\if0#10\else-#1\fi\fi }% +\BNE_tmpa {viii}% +\def\BNE_Op_opp #1{\if-#1\else\if0#10\else-#1\fi\fi }% % \end{macrocode} % \subsection{The comma may separate expressions.} % It suffices to treat the comma as a binary operator of precedence |ii|. We @@ -1190,23 +1213,6 @@ Some example with the power operator |^|: \fi }% \let \BNE_precedence_, \xint_c_ii -\catcode`, 12 -% \end{macrocode} -% \subsection{Disabling tacit multiplication} -% \begin{macrocode} -\def\BNE_notacitmultiplication{% - \def\BNE_getop_a ##1##2{% - \ifx \relax ##2\expandafter\xint_firstoftwo\else - \expandafter\xint_secondoftwo\fi - {\BNE_foundend ##1}% - {\BNE_foundop ##2##1}% - }% - \def\BNE_scan_nbr_a ##1{% - \ifcat \relax ##1\expandafter\xint_firstoftwo\else - \expandafter\xint_secondoftwo\fi - {!##1}{\expandafter\BNE_scan_nbr_b\string ##1}% - }% -}% % \end{macrocode} % \subsection{Cleanup} % \begin{macrocode} @@ -1233,7 +1239,7 @@ Some example with the power operator |^|: Right bracket \] Circumflex \^ Underscore \_ Grave accent \` Left brace \{ Vertical bar \| Right brace \} Tilde \~} -\CheckSum {833} +\CheckSum {868} \makeatletter\check@checksum\makeatother \Finale %% End of file xint.dtx diff --git a/Master/texmf-dist/source/latex/bnumexpr/bnumexpr.ins b/Master/texmf-dist/source/latex/bnumexpr/bnumexpr.ins index 370e450b64f..21f9c79e120 100644 --- a/Master/texmf-dist/source/latex/bnumexpr/bnumexpr.ins +++ b/Master/texmf-dist/source/latex/bnumexpr/bnumexpr.ins @@ -22,17 +22,17 @@ %% in the same archive or directory.) %% --------------------------------------------------------------- %% The bnumexpr package: Expressions with big integers -%% Copyright (C) 2014 by Jean-Francois Burnol +%% Copyright (C) 2014-2015 by Jean-Francois Burnol %% %% tex bnumexpr.ins will extract bnumexpr.sty from bnumexpr.dtx %% \input docstrip.tex \askforoverwritefalse \generate{\nopreamble\nopostamble -\file{bnumexprReadme.md}{\from{bnumexpr.dtx}{readme}} +\file{README.md}{\from{bnumexpr.dtx}{readme}} \usepreamble\defaultpreamble \usepostamble\defaultpostamble -\file{bnumexpr.changes}{\from{bnumexpr.dtx}{changes}} +\file{bnumexprchanges.tex}{\from{bnumexpr.dtx}{changes}} \file{bnumexpr.tex}{\from{bnumexpr.dtx}{drv}} \file{bnumexpr.sty}{\from{bnumexpr.dtx}{package}}} \catcode32=13\relax% active space diff --git a/Master/texmf-dist/tex/latex/bnumexpr/bnumexpr.sty b/Master/texmf-dist/tex/latex/bnumexpr/bnumexpr.sty index ad782b7bb2b..b1b74a6b82b 100644 --- a/Master/texmf-dist/tex/latex/bnumexpr/bnumexpr.sty +++ b/Master/texmf-dist/tex/latex/bnumexpr/bnumexpr.sty @@ -22,10 +22,10 @@ %% in the same archive or directory.) %% --------------------------------------------------------------- %% The bnumexpr package: Expressions with big integers -%% Copyright (C) 2014 by Jean-Francois Burnol +%% Copyright (C) 2014-2015 by Jean-Francois Burnol %% \NeedsTeXFormat{LaTeX2e}% -\ProvidesPackage{bnumexpr}[2014/10/28 v1.1b Expressions with big integers (jfB)]% +\ProvidesPackage{bnumexpr}[2015/10/13 v1.2 Expressions with big integers (jfB)]% \edef\BNErestorecatcodes {\catcode`\noexpand\!\the\catcode`\! \catcode`\noexpand\?\the\catcode`\? \catcode`\noexpand\_\the\catcode`\_ @@ -38,71 +38,9 @@ \catcode`\? 11 \catcode`\_ 11 \catcode`\: 11 -\def\BNE_tmpa {0}% -\DeclareOption {custom}{\def\BNE_tmpa {1}% - \PackageWarningNoLine{bnumexpr}{^^J - Option custom: package xintcore not loaded. Definitions are needed for:^^J - \protect\bnumexprAdd, \protect\bnumexprSub, - \protect\bnumexprMul\space and \protect\bnumexprDiv }% -}% -\DeclareOption {bigintcalc}{\def\BNE_tmpa {2}% - \PackageWarningNoLine{bnumexpr}{^^J - Option bigintcalc: the macros from package bigintcalc are used.^^J - Notice that / is mapped to \protect\bigintcalcDiv\space which does truncated division}% -}% -\DeclareOption {l3bigint}{\def\BNE_tmpa {3}% - \PackageWarningNoLine{bnumexpr}{^^J - Option l3bigint: the macros from package l3bigint are used.^^J - There is no power operation, currently}% -}% -\DeclareOption {nocsv}{% - \PackageInfo{bnumexpr}{Comma separated expressions disabled}% - \AtEndOfPackage{\expandafter\let\csname BNE_precedence_,\endcsname - \undefined }% -}% -\DeclareOption {notacitmul}{% - \PackageInfo{bnumexpr}{Tacit multiplication disabled}% - \AtEndOfPackage{\BNE_notacitmultiplication}% -}% -\def\BNE_allowpower {0}% -\DeclareOption {allowpower}{% - \PackageInfo{bnumexpr}{Power operator ^ authorized}% - \def\BNE_allowpower {1}% -}% -\ProcessOptions\relax -\def\bnumexprUsesxint {% - \let\bnumexprAdd\xintiiAdd - \let\bnumexprSub\xintiiSub - \let\bnumexprMul\xintiiMul - \let\bnumexprDiv\xintiiDivRound - \let\bnumexprPow\xintiiPow -}% -\def\bnumexprUsesbigintcalc {% - \let\bnumexprAdd\bigintcalcAdd - \let\bnumexprSub\bigintcalcSub - \let\bnumexprMul\bigintcalcMul - \let\bnumexprDiv\bigintcalcDiv % NOTE: THIS DOES TRUNCATED DIVISION - \let\bnumexprPow\bigintcalcPow -}% -\def\bnumexprUsesliiibigint {% - \let\bnumexprAdd\bigint_add:nn - \let\bnumexprSub\bigint_sub:nn - \let\bnumexprMul\bigint_mul:nn - \let\bnumexprDiv\bigint_div_round:nn - \let\bnumexprPow\bigint_pow:nn % does not exist! -}% -\if0\BNE_tmpa % Toggle to load xintcore.sty - \RequirePackage{xintcore}% - \bnumexprUsesxint -\fi -\if2\BNE_tmpa % Toggle to load bigintcalc.sty - \RequirePackage{bigintcalc}% - \bnumexprUsesbigintcalc -\fi -\if3\BNE_tmpa % Toggle to load l3bigint.sty - \RequirePackage{l3bigint}% - \bnumexprUsesliiibigint -\fi +\catcode`\, 12 +\catcode`\* 12 +\catcode`\( 12 \chardef\xint_c_ 0 \chardef\xint_c_i 1 \chardef\xint_c_ii 2 @@ -110,6 +48,7 @@ \chardef\xint_c_vii 7 \chardef\xint_c_viii 8 \chardef\xint_c_ix 9 +\chardef\xint_c_x 10 \long\def\xint_gobble_i #1{}% \long\def\xint_gobble_iii #1#2#3{}% \long\def\xint_firstofone #1{#1}% @@ -118,18 +57,29 @@ \long\def\xint_firstofthree #1#2#3{#1}% \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}% +\def\xint_gob_til_! #1!{}% this ! has catcode 11 +\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}% new in v1.1 +\long\def\xint_dothis #1#2\xint_orthat #3{\fi #1}% \let\xint_orthat \xint_firstofone -\edef\BNE_lock #1!{\noexpand\expandafter\space\noexpand - \csname .=\noexpand\BNE_num #1\endcsname }% -\def\BNE_num #1{\if #10\expandafter\BNE_num\else - \ifcat #1\relax 0\expandafter\expandafter\expandafter #1\else - #1\fi\fi }% -\def\BNE_unlock {\expandafter\BNE_unlock_a\string }% -\def\BNE_unlock_a #1.={}% +\def\xint_zapspaces #1 #2{#1#2\xint_zapspaces }% +\catcode`! 3 +\def\bnumexprsetup #1{\BNE_parsekeys #1,=!,}% +\def\BNE_parsekeys #1=#2#3,{\ifx!#2\expandafter\BNE_parsedone\fi + \edef\BNE_tmpc{\xint_zapspaces #1 \xint_gobble_i}% + \expandafter\let\csname BNE_Op_\BNE_tmpc\endcsname=#2\BNE_parsekeys +}% +\catcode`! 11 +\def\BNE_parsedone #1\BNE_parsekeys {}% +\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]% + \bnumexprsetup{add=\xintiiAdd, sub=\xintiiSub, mul=\xintiiMul, + divround=\xintiiDivRound, divtrunc=\xintiiDivTrunc, + mod=\xintiiMod, pow=\xintiiPow, fac=\xintiiFac}% +\fi \def\bnumexpr {\romannumeral0\bnumeval }% \def\bnumeval {\expandafter\BNE_wrap\romannumeral0\BNE_eval }% \def\BNE_eval {\expandafter\BNE_until_end_a\romannumeral-`0\BNE_getnext }% @@ -140,6 +90,8 @@ \def\thebnumexpr {\romannumeral-`0\expandafter\BNE_unlock\romannumeral0\BNE_eval }% \def\bnethe #1{\romannumeral-`0\expandafter\xint_gobble_iii\romannumeral-`0#1}% +\def\BNE_unlock {\expandafter\BNE_unlock_a\string }% +\def\BNE_unlock_a #1.={}% \def\BNE_getnext #1% {% \expandafter\BNE_getnext_a\romannumeral-`0#1% @@ -157,16 +109,18 @@ \def\BNE_gn_foundexpr !#1\fi !{\expandafter\BNE_getop\xint_gobble_iii }% \def\BNE_gn_countetc #1% {% - \ifx\count#1\else\ifx#1\dimen\else\ifx#1\numexpr\else\ifx#1\dimexpr\else - \ifx\skip#1\else\ifx\glueexpr#1\else\ifx\fontdimen#1\else + \ifx\count#1\else\ifx\dimen#1\else\ifx\numexpr#1\else\ifx\dimexpr#1\else + \ifx\skip#1\else\ifx\glueexpr#1\else\ifx\fontdimen#1\else\ifx\ht#1\else + \ifx\dp#1\else\ifx\wd#1\else\ifx\fontcharht#1\else\ifx\fontcharwd#1\else + \ifx\fontchardp#1\else\ifx\fontcharic#1\else \BNE_gn_unpackvar - \fi\fi\fi\fi\fi\fi\fi + \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi \expandafter\BNE_getnext\number #1% }% -\def\BNE_gn_unpackvar\fi\fi\fi\fi\fi\fi\fi\expandafter - \BNE_getnext\number #1% +\def\BNE_gn_unpackvar\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi + \expandafter\BNE_getnext\number #1% {% - \fi\fi\fi\fi\fi\fi\fi + \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi \expandafter\BNE_getop\csname .=\number#1\endcsname }% \def\BNE_gn_fork #1{% @@ -177,30 +131,59 @@ }% \def\BNE_scan_number #1% this #1 has necessarily here catcode 12 {% - \ifnum \xint_c_ix<1#1 \expandafter \BNE_scan_nbr\else - \expandafter \BNE_notadigit\fi #1% + \ifnum \xint_c_ix<1#1 \else\expandafter\BNE_notadigit\fi + \BNE_scan_nbr #1% +}% +\def\BNE_notadigit\BNE_scan_nbr #1{\BNE:not_a_digit!\BNE_getnext }% +\def\BNE_scan_nbr #1% +{% the #1 here is a catcode 12 digit + \if#10\expandafter\BNE_scan_nbr_gobzeroes + \else + \expandafter\BNE_scan_nbr_start + \fi #1% +}% +\def\BNE_scan_nbr_start #1#2% +{% + \expandafter\BNE_getop\csname.=#1% + \expandafter\BNE_scanint_b\romannumeral-`0#2% +}% +\def\BNE_scan_nbr_gobzeroes #1% +{% + \expandafter\BNE_getop\csname.=% + \expandafter\BNE_gobz_scanint_b\romannumeral-`0#1% }% -\def\BNE_notadigit #1{\BNE:not_a_digit! \xint_gobble_i {#1}}% -\def\BNE_scan_nbr +\def\BNE_scanint_b #1% {% - \expandafter\BNE_getop\romannumeral-`0\expandafter - \BNE_lock\romannumeral-`0\BNE_scan_nbr_c + \ifcat \relax #1\expandafter\BNE_scanint_endbycs\expandafter #1\fi + \ifnum\xint_c_ix<1\string#1 \else\expandafter\BNE_scanint_c\fi + \string#1\BNE_scanint_d }% -\def\BNE_scan_nbr_a #1% -{% careful that ! has catcode letter here - \ifcat \relax #1\xint_dothis{!#1}\fi % stops the scan - \ifx !#1\xint_dothis{!*!}\fi % tacit multiplication before subexpr - \xint_orthat {\expandafter\BNE_scan_nbr_b\string #1}% +\def\BNE_scanint_endbycs#1#2\BNE_scanint_d{\endcsname #1}% +\def\BNE_scanint_c\string #1\BNE_scanint_d +{% + \ifcat a#1\xint_dothis{\endcsname*}\fi % tacit multiplication + \xint_orthat {\expandafter\endcsname \string}#1% }% -\def\BNE_scan_nbr_b #1% #1 with catcode 12 +\def\BNE_scanint_d #1% {% - \ifnum \xint_c_ix<1#1 \expandafter\BNE_scan_nbr_c - \else\expandafter !\fi #1% + \expandafter\BNE_scanint_b\romannumeral-`0#1% }% -\def\BNE_scan_nbr_c #1#2% +\def\BNE_gobz_scanint_b #1% {% - \expandafter #1\romannumeral-`0\expandafter - \BNE_scan_nbr_a\romannumeral-`0#2% + \ifcat \relax #1\expandafter\BNE_gobz_scanint_endbycs\expandafter #1\fi + \ifnum\xint_c_x<1\string#1 \else\expandafter\BNE_gobz_scanint_c\fi + \string#1\BNE_scanint_d +}% +\def\BNE_gobz_scanint_endbycs#1#2\BNE_scanint_d{0\endcsname #1}% +\def\BNE_gobz_scanint_c\string #1\BNE_scanint_d +{% + \ifcat a#1\xint_dothis{0\endcsname*#1}\fi % tacit multiplication + \if 0#1\xint_dothis\BNE_gobz_scanint_d\fi + \xint_orthat {0\expandafter\endcsname \string#1}% +}% +\def\BNE_gobz_scanint_d #1% +{% + \expandafter\BNE_gobz_scanint_b\romannumeral-`0#1% }% \def\BNE_getop #1#2% this #1 is the current locked computed value {% @@ -218,10 +201,20 @@ \xint_orthat \xint_thirdofthree {\BNE_foundend #1}% {\BNE_precedence_* *#1#2}% tacit multiplication - {\BNE_foundop #2#1}% + {\BNE_scanop_a #2#1}% }% \catcode`* 12 \def\BNE_foundend {\xint_c_ \relax }% \relax is only a place-holder here. +\def\BNE_scanop_a #1#2#3% + {\expandafter\BNE_scanop_b\expandafter #1\expandafter #2\romannumeral-`0#3}% +\def\BNE_scanop_b #1#2#3% +{% + \ifcat#3\relax\xint_dothis{\BNE_foundop #1#2#3}\fi + \ifcsname BNE_itself_#1#3\endcsname + \xint_dothis + {\expandafter\BNE_foundop\csname BNE_itself_#1#3\endcsname #2}\fi + \xint_orthat {\BNE_foundop #1#2#3}% +}% \def\BNE_foundop #1% {% \ifcsname BNE_precedence_#1\endcsname @@ -233,7 +226,7 @@ }% \def\BNE_notanoperator #1{\BNE:not_an_operator! \xint_gobble_i {#1}}% \catcode`) 11 -\def\BNE_tmpa #1{% #1=\BNE_op_-vi token +\def\BNE_tmpa #1{% \def\BNE_until_end_a ##1% {% \xint_UDsignfork @@ -257,7 +250,7 @@ \def\BNE_op_( {\expandafter\BNE_until_)_a\romannumeral-`0\BNE_getnext }% \let\BNE_oparen\BNE_op_( \catcode`( 12 -\def\BNE_tmpa #1{% #1=\BNE_op_-vi +\def\BNE_tmpa #1{% \def\BNE_until_)_a ##1{\xint_UDsignfork ##1{\expandafter \BNE_until_)_a\romannumeral-`0#1}% -{\BNE_until_)_b ##1}% @@ -306,12 +299,23 @@ \csname #3\expandafter\endcsname \csname BNE_precedence_#1\endcsname }% -\BNE_tmpb +{vi}{bnumexprAdd}% -\BNE_tmpb -{vi}{bnumexprSub}% -\BNE_tmpb *{vii}{bnumexprMul}% -\BNE_tmpb /{vii}{bnumexprDiv}% -\if1\BNE_allowpower\BNE_tmpb ^{viii}{bnumexprPow}\fi -\def\BNE_tmpa #1% #1=vi or vii +\BNE_tmpb +{vi}{BNE_Op_add}% +\BNE_tmpb -{vi}{BNE_Op_sub}% +\BNE_tmpb *{vii}{BNE_Op_mul}% +\BNE_tmpb /{vii}{BNE_Op_divround}% +\BNE_tmpb ^{viii}{BNE_Op_pow}% +\expandafter\def\csname BNE_itself_**\endcsname {**}% +\expandafter\def\csname BNE_itself_//\endcsname {//}% +\expandafter\def\csname BNE_itself_/:\endcsname {/:}% +\BNE_tmpb {**}{viii}{BNE_Op_pow}% +\BNE_tmpb {//}{vii}{BNE_Op_divtrunc}% +\BNE_tmpb {/:}{vii}{BNE_Op_mod}% +\let\BNE_precedence_! \xint_c_x +\def\BNE_tmpa #1{\def\BNE_op_! ##1{\expandafter\BNE_getop + \csname .=#1{\BNE_unlock ##1}\endcsname + }}% +\BNE_tmpa\BNE_Op_fac +\def\BNE_tmpa #1% {% \expandafter\BNE_tmpb \csname BNE_op_-#1\expandafter\endcsname @@ -337,15 +341,15 @@ \csname BNE_op_##2\endcsname {##3}}% \else \xint_afterfi {\expandafter ##1\expandafter ##2% - \csname .=\expandafter\BNE_Opp + \csname .=\expandafter\BNE_Op_opp \romannumeral-`0\BNE_unlock ##3\endcsname }% \fi }% }% \BNE_tmpa {vi}% \BNE_tmpa {vii}% -\if1\BNE_allowpower\BNE_tmpa {viii}\fi -\def\BNE_Opp #1{\if-#1\else\if0#10\else-#1\fi\fi }% +\BNE_tmpa {viii}% +\def\BNE_Op_opp #1{\if-#1\else\if0#10\else-#1\fi\fi }% \catcode`, 11 \def\BNE_op_, #1% {% @@ -371,20 +375,6 @@ \fi }% \let \BNE_precedence_, \xint_c_ii -\catcode`, 12 -\def\BNE_notacitmultiplication{% - \def\BNE_getop_a ##1##2{% - \ifx \relax ##2\expandafter\xint_firstoftwo\else - \expandafter\xint_secondoftwo\fi - {\BNE_foundend ##1}% - {\BNE_foundop ##2##1}% - }% - \def\BNE_scan_nbr_a ##1{% - \ifcat \relax ##1\expandafter\xint_firstoftwo\else - \expandafter\xint_secondoftwo\fi - {!##1}{\expandafter\BNE_scan_nbr_b\string ##1}% - }% -}% \let\BNE_tmpa\relax \let\BNE_tmpb\relax \let\BNE_tmpc\relax \BNErestorecatcodes \endinput -- cgit v1.2.3