From 21fe8b8ecfb2cb7c2d3c552a1eb8b0ed10d468c6 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sun, 21 Sep 2014 21:00:01 +0000 Subject: bnumexpr (21sep14) git-svn-id: svn://tug.org/texlive/trunk@35223 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/tex/latex/bnumexpr/bnumexpr.sty | 405 ++++++++++++++++++++++ 1 file changed, 405 insertions(+) create mode 100644 Master/texmf-dist/tex/latex/bnumexpr/bnumexpr.sty (limited to 'Master/texmf-dist/tex/latex/bnumexpr') diff --git a/Master/texmf-dist/tex/latex/bnumexpr/bnumexpr.sty b/Master/texmf-dist/tex/latex/bnumexpr/bnumexpr.sty new file mode 100644 index 00000000000..748e392c117 --- /dev/null +++ b/Master/texmf-dist/tex/latex/bnumexpr/bnumexpr.sty @@ -0,0 +1,405 @@ +%% +%% This is file `bnumexpr.sty', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% bnumexpr.dtx (with options: `package') +%% +%% IMPORTANT NOTICE: +%% +%% For the copyright see the source file. +%% +%% Any modified versions of this file must be renamed +%% with new filenames distinct from bnumexpr.sty. +%% +%% For distribution of the original source see the terms +%% for copying and modification in the file bnumexpr.dtx. +%% +%% This generated file may be distributed as long as the +%% original source files, as listed above, are part of the +%% same distribution. (The sources need not necessarily be +%% in the same archive or directory.) +%%---------------------------------------------------------------- +%% The bnumexpr package: Expressions with big integers +%% Copyright (C) 2014 by Jean-Francois Burnol +%%---------------------------------------------------------------- +\NeedsTeXFormat{LaTeX2e}% +\ProvidesPackage{bnumexpr}[2014/09/21 v1.1 Expressions with big integers (jfB)]% +\edef\BNErestorecatcodes {\catcode`\noexpand\!\the\catcode`\! + \catcode`\noexpand\?\the\catcode`\? + \catcode`\noexpand\_\the\catcode`\_ + \catcode`\noexpand\:\the\catcode`\:\relax }% +\catcode`\! 11 +\catcode`\? 11 +\catcode`\_ 11 +\catcode`\: 11 +\def\BNE_tmpa {0}% +\DeclareOption {custom}{\def\BNE_tmpa {1}% + \PackageWarningNoLine{bnumexpr}{^^J + Option custom: package xint 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 {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 +\if2\BNE_tmpa % Toggle to load bigintcalc.sty +\RequirePackage{bigintcalc}% +\let\bnumexprAdd\bigintcalcAdd +\let\bnumexprSub\bigintcalcSub +\let\bnumexprMul\bigintcalcMul +\let\bnumexprDiv\bigintcalcDiv % NOTE: THIS DOES TRUNCATED DIVISION +\if1\BNE_allowpower\let\bnumexprPow\bigintcalcPow\fi +\fi +\if0\BNE_tmpa % Toggle to load xint.sty (and also xinttools.sty) +\RequirePackage{xint}% +\let\bnumexprAdd\xintiiAdd +\let\bnumexprSub\xintiiSub +\let\bnumexprMul\xintiiMul +\if1\BNE_allowpower\let\bnumexprPow\xintiiPow\fi +\def\bnumexprDiv {\romannumeral0\bnumexprdiv }% +\def\bnumexprdiv #1{\expandafter\BNE_div \romannumeral-`0#1\Z }% +\def\BNE_div #1#2\Z #3{\expandafter\BNE_div_a\expandafter #1% + \romannumeral-`0#3\Z #2\Z }% +\def\BNE_div_a #1#2% #1 de A, #2 de B. +{% + \if0#2\xint_dothis\BNE_div_divbyzero\fi + \if0#1\xint_dothis\BNE_div_aiszero\fi + \if-#2\xint_dothis{\BNE_div_bneg #1}\fi + \xint_orthat{\BNE_div_bpos #1#2}% +}% +\def\BNE_div_divbyzero #1\Z #2\Z {\BNE:DivisionByZero\space 0}% +\def\BNE_div_aiszero #1\Z #2\Z { 0}% +\def\BNE_div_bpos #1% +{% + \xint_UDsignfork + #1{\xintiiopp\BNE_div_pos {}}% + -{\BNE_div_pos #1}% + \krof +}% +\def\BNE_div_bneg #1% +{% + \xint_UDsignfork + #1{\BNE_div_pos {}}% + -{\xintiiopp\BNE_div_pos #1}% + \krof +}% +\def\BNE_div_pos #1#2\Z #3\Z{\expandafter\BNE_div_pos_a + \romannumeral0\XINT_div_prepare {#2}{#1#30}}% +\def\BNE_div_pos_a #1#2{\xintReverseOrder {#1\BNE_div_pos_b}\Z }% +\def\BNE_div_pos_b #1#2{\xint_gob_til_Z #2\BNE_div_pos_small\Z + \BNE_div_pos_c #1#2}% +\def\BNE_div_pos_c #1#2\Z {\ifnum #1>\xint_c_iv + \expandafter\BNE_div_pos_up + \else \expandafter\xintreverseorder + \fi {#2}}% +\def\BNE_div_pos_up #1{\xintinc {\xintReverseOrder{#1}}}% +\def\BNE_div_pos_small\Z\BNE_div_pos_c #1#2{\ifnum #1>\xint_c_iv\expandafter + \xint_secondoftwo\else\expandafter + \xint_firstoftwo\fi { 0}{ 1}}% +\fi +\chardef\xint_c_ 0 +\chardef\xint_c_i 1 +\chardef\xint_c_ii 2 +\chardef\xint_c_vi 6 +\chardef\xint_c_vii 7 +\chardef\xint_c_viii 8 +\chardef\xint_c_ix 9 +\long\def\xint_gobble_i #1{}% +\long\def\xint_gobble_iii #1#2#3{}% +\long\def\xint_firstofone #1{#1}% +\long\def\xint_firstoftwo #1#2{#1}% +\long\def\xint_secondoftwo #1#2{#2}% +\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}% +\long\def\xint_afterfi #1#2\fi {\fi #1}% +\long\def\xint_dothis #1#2\xint_orthat #3{\fi #1}% new in v1.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\bnumexpr {\romannumeral0\bnumeval }% +\def\bnumeval {\expandafter\BNE_wrap\romannumeral0\BNE_eval }% +\def\BNE_eval {\expandafter\BNE_until_end_a\romannumeral-`0\BNE_getnext }% +\def\BNE_wrap { !\BNE_usethe\BNE_protect\BNE_unlock }% +\protected\def\BNE_usethe\BNE_protect {\BNE:missing_bnethe!}% +\def\BNE_protect {\noexpand\BNE_protect\noexpand }% +\let\BNE_done\space +\def\thebnumexpr + {\romannumeral-`0\expandafter\BNE_unlock\romannumeral0\BNE_eval }% +\def\bnethe #1{\romannumeral-`0\expandafter\xint_gobble_iii\romannumeral-`0#1}% +\def\BNE_getnext #1% +{% + \expandafter\BNE_getnext_a\romannumeral-`0#1% +}% +\def\BNE_getnext_a #1% +{% + \xint_gob_til_! #1\BNE_gn_foundexpr !% this ! has catcode 11 + \ifcat\relax#1% \count or \numexpr etc... token or count, dimen, skip cs + \expandafter\BNE_gn_countetc + \else + \expandafter\expandafter\expandafter\BNE_gn_fork\expandafter\string + \fi + #1% +}% +\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 + \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\expandafter + \BNE_getnext\number #1% +{% + \fi\fi\fi\fi\fi\fi\fi + \expandafter\BNE_getop\csname .=\number#1\endcsname +}% +\def\BNE_gn_fork #1{% + \if#1+\xint_dothis \BNE_getnext\fi + \if#1-\xint_dothis -\fi + \if#1(\xint_dothis \BNE_oparen \fi + \xint_orthat {\BNE_scan_number #1}% +}% +\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% +}% +\def\BNE_notadigit #1{\BNE:not_a_digit! \xint_gobble_i {#1}}% +\def\BNE_scan_nbr +{% + \expandafter\BNE_getop\romannumeral-`0\expandafter + \BNE_lock\romannumeral-`0\BNE_scan_nbr_c +}% +\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_scan_nbr_b #1% #1 with catcode 12 +{% + \ifnum \xint_c_ix<1#1 \expandafter\BNE_scan_nbr_c + \else\expandafter !\fi #1% +}% +\def\BNE_scan_nbr_c #1#2% +{% + \expandafter #1\romannumeral-`0\expandafter + \BNE_scan_nbr_a\romannumeral-`0#2% +}% +\def\BNE_getop #1#2% this #1 is the current locked computed value +{% + \expandafter\BNE_getop_a\expandafter #1\romannumeral-`0#2% +}% +\catcode`* 11 +\def\BNE_getop_a #1#2% +{% if a control sequence is found, must be \relax, or possibly register or + % variable if tacit multiplication is allowed + \ifx \relax #2\xint_dothis\xint_firstofthree\fi + % tacit multiplications: + \ifcat \relax #2\xint_dothis\xint_secondofthree\fi + \if (#2\xint_dothis \xint_secondofthree\fi + \ifx !#2\xint_dothis \xint_secondofthree\fi + \xint_orthat \xint_thirdofthree + {\BNE_foundend #1}% + {\BNE_precedence_* *#1#2}% tacit multiplication + {\BNE_foundop #2#1}% +}% +\catcode`* 12 +\def\BNE_foundend {\xint_c_ \relax }% \relax is only a place-holder here. +\def\BNE_foundop #1% +{% + \ifcsname BNE_precedence_#1\endcsname + \csname BNE_precedence_#1\expandafter\endcsname + \expandafter #1% + \else + \BNE_notanoperator {#1}\expandafter\BNE_getop + \fi +}% +\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_until_end_a ##1% + {% + \xint_UDsignfork + ##1{\expandafter\BNE_until_end_a\romannumeral-`0#1}% + -{\BNE_until_end_b ##1}% + \krof + }% +}\expandafter\BNE_tmpa\csname BNE_op_-vi\endcsname +\def\BNE_until_end_b #1#2% + {% + \ifcase #1\expandafter\BNE_done + \or + \xint_afterfi{\BNE:extra_)_?\expandafter + \BNE_until_end_a\romannumeral-`0\BNE_getop }% + \else + \xint_afterfi{\expandafter\BNE_until_end_a + \romannumeral-`0\csname BNE_op_#2\endcsname }% + \fi + }% +\catcode`( 11 +\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_until_)_a ##1{\xint_UDsignfork + ##1{\expandafter \BNE_until_)_a\romannumeral-`0#1}% + -{\BNE_until_)_b ##1}% + \krof }% +}\expandafter\BNE_tmpa\csname BNE_op_-vi\endcsname +\def \BNE_until_)_b #1#2% + {% + \ifcase #1\expandafter \BNE_missing_)_? % missing ) ? + \or\expandafter \BNE_getop % found closing ) + \else \xint_afterfi + {\expandafter \BNE_until_)_a\romannumeral-`0\csname BNE_op_#2\endcsname }% + \fi + }% +\def\BNE_missing_)_? {\BNE:missing_)_inserted \xint_c_ \BNE_done }% +\let\BNE_precedence_) \xint_c_i +\let\BNE_op_) \BNE_getop +\catcode`) 12 +\def\BNE_tmpc #1#2#3#4#5#6#7% +{% + \def #1##1% \BNE_op_ + {% keep value, get next number and operator, then do until + \expandafter #2\expandafter ##1\romannumeral-`0\expandafter\BNE_getnext }% + \def #2##1##2% \BNE_until__a + {\xint_UDsignfork + ##2{\expandafter #2\expandafter ##1\romannumeral-`0#4}% + -{#3##1##2}% + \krof }% + \def #3##1##2##3##4% \BNE_until__b + {% either execute next operation now, or first do next (possibly unary) + \ifnum ##2>#5% + \xint_afterfi {\expandafter #2\expandafter ##1\romannumeral-`0% + \csname BNE_op_##3\endcsname {##4}}% + \else \xint_afterfi {\expandafter ##2\expandafter ##3% + \csname .=#6{\BNE_unlock ##1}{\BNE_unlock ##4}\endcsname }% + \fi }% + \let #7#5% +}% +\def\BNE_tmpb #1#2#3% +{% + \expandafter\BNE_tmpc + \csname BNE_op_#1\expandafter\endcsname + \csname BNE_until_#1_a\expandafter\endcsname + \csname BNE_until_#1_b\expandafter\endcsname + \csname BNE_op_-#2\expandafter\endcsname + \csname xint_c_#2\expandafter\endcsname + \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 +{% +\expandafter\BNE_tmpb + \csname BNE_op_-#1\expandafter\endcsname + \csname BNE_until_-#1_a\expandafter\endcsname + \csname BNE_until_-#1_b\expandafter\endcsname + \csname xint_c_#1\endcsname +}% +\def\BNE_tmpb #1#2#3#4% +{% + \def #1% \BNE_op_- + {% get next number+operator then switch to _until macro + \expandafter #2\romannumeral-`0\BNE_getnext + }% + \def #2##1% \BNE_until_-_a + {\xint_UDsignfork + ##1{\expandafter #2\romannumeral-`0#1}% + -{#3##1}% + \krof }% + \def #3##1##2##3% \BNE_until_-_b + {% + \ifnum ##1>#4% + \xint_afterfi {\expandafter #2\romannumeral-`0% + \csname BNE_op_##2\endcsname {##3}}% + \else + \xint_afterfi {\expandafter ##1\expandafter ##2% + \csname .=\expandafter\BNE_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 }% +\catcode`, 11 +\def\BNE_op_, #1% +{% + \expandafter \BNE_until_,_a\expandafter #1\romannumeral-`0\BNE_getnext +}% +\def\BNE_tmpa #1{% #1 = \BNE_op_-vi + \def\BNE_until_,_a ##1##2% + {% + \xint_UDsignfork + ##2{\expandafter \BNE_until_,_a\expandafter ##1\romannumeral-`0#1}% + -{\BNE_until_,_b ##1##2}% + \krof }% +}\expandafter\BNE_tmpa\csname BNE_op_-vi\endcsname +\def\BNE_until_,_b #1#2#3#4% +{% + \ifnum #2>\xint_c_ii + \xint_afterfi {\expandafter \BNE_until_,_a + \expandafter #1\romannumeral-`0% + \csname BNE_op_#3\endcsname {#4}}% + \else + \xint_afterfi {\expandafter #2\expandafter #3% + \csname .=\BNE_unlock #1, \BNE_unlock #4\endcsname }% + \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 \let\BNE_allowpower\relax +\BNErestorecatcodes +\endinput +%% +%% End of file `bnumexpr.sty'. -- cgit v1.2.3