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/tex/latex/bnumexpr/bnumexpr.sty | 242 +++++++++++----------- 1 file changed, 116 insertions(+), 126 deletions(-) (limited to 'Master/texmf-dist/tex') 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