summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/xint/xintcore.sty
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2016-03-13 21:18:24 +0000
committerKarl Berry <karl@freefriends.org>2016-03-13 21:18:24 +0000
commit1dece60d27697bab91c26ad47b09149c34bfe189 (patch)
tree086aeeeb33674fa6afe46f67828f1fa5944271f0 /Master/texmf-dist/tex/generic/xint/xintcore.sty
parent1dd15ac4ccc619c707b7418b3710e5f379f72f08 (diff)
xint (13mar16)
git-svn-id: svn://tug.org/texlive/trunk@40014 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/generic/xint/xintcore.sty')
-rw-r--r--Master/texmf-dist/tex/generic/xint/xintcore.sty203
1 files changed, 89 insertions, 114 deletions
diff --git a/Master/texmf-dist/tex/generic/xint/xintcore.sty b/Master/texmf-dist/tex/generic/xint/xintcore.sty
index 94980e62be4..5088cdefa12 100644
--- a/Master/texmf-dist/tex/generic/xint/xintcore.sty
+++ b/Master/texmf-dist/tex/generic/xint/xintcore.sty
@@ -21,8 +21,8 @@
%% same distribution. (The sources need not necessarily be
%% in the same archive or directory.)
%% ---------------------------------------------------------------
-%% The xint bundle v1.2e 2015/11/22
-%% Copyright (C) 2013-2015 by Jean-Francois Burnol
+%% The xint bundle 1.2f 2016/03/12
+%% Copyright (C) 2013-2016 by Jean-Francois Burnol
%% xintcore: Expandable arithmetic on big integers
%% ---------------------------------------------------------------
\begingroup\catcode61\catcode48\catcode32=10\relax%
@@ -70,7 +70,7 @@
\XINTsetupcatcodes% defined in xintkernel.sty
\XINT_providespackage
\ProvidesPackage{xintcore}%
- [2015/11/22 v1.2e Expandable arithmetic on big integers (jfB)]%
+ [2016/03/12 1.2f Expandable arithmetic on big integers (JFB)]%
\ifdefined\m@ne\let\xint_c_mone\m@ne
\else\csname newcount\endcsname\xint_c_mone \xint_c_mone -1 \fi
\newcount\xint_c_x^viii \xint_c_x^viii 100000000
@@ -122,28 +122,26 @@
{%
\noexpand\expandafter\space\noexpand\the\numexpr #1#2#3#4#5#6#7#8\relax
}%
-%%%%%%%%%%%%
\def\XINT_cuz #1#2#3#4#5#6#7#8#9%
{%
\xint_gob_til_R #9\XINT_cuz_e \R
\xint_gob_til_eightzeroes #1#2#3#4#5#6#7#8\XINT_cuz_z 00000000%
- \XINT_cuz_clean #1#2#3#4#5#6#7#8#9%
+ \XINT_cuz_done #1#2#3#4#5#6#7#8#9%
}%
-\edef\XINT_cuz_clean #1#2#3#4#5#6#7#8#9\R
+\def\XINT_cuz_z 00000000\XINT_cuz_done 00000000{\XINT_cuz }%
+\edef\XINT_cuz_done #1#2#3#4#5#6#7#8#9\R
{\noexpand\expandafter\space\noexpand\the\numexpr #1#2#3#4#5#6#7#8\relax #9}%
-\edef\XINT_cuz_e\R #1\XINT_cuz_clean #2\R
+\edef\XINT_cuz_e\R #1\XINT_cuz_done #2\R
{\noexpand\expandafter\space\noexpand\the\numexpr #2\relax }%
-\def\XINT_cuz_z 00000000\XINT_cuz_clean 00000000{\XINT_cuz }%
-%%%%%%%%%%%%
\def\XINT_cuz_byviii #1#2#3#4#5#6#7#8#9%
{%
\xint_gob_til_R #9\XINT_cuz_byviii_e \R
\xint_gob_til_eightzeroes #1#2#3#4#5#6#7#8\XINT_cuz_byviii_z 00000000%
- \XINT_cuz_byviii_clean #1#2#3#4#5#6#7#8#9%
+ \XINT_cuz_byviii_done #1#2#3#4#5#6#7#8#9%
}%
-\def\XINT_cuz_byviii_clean #1\R { #1}%
-\def\XINT_cuz_byviii_e\R #1\XINT_cuz_byviii_clean #2\R{ #2}%
-\def\XINT_cuz_byviii_z 00000000\XINT_cuz_byviii_clean 00000000{\XINT_cuz_byviii}%
+\def\XINT_cuz_byviii_z 00000000\XINT_cuz_byviii_done 00000000{\XINT_cuz_byviii}%
+\def\XINT_cuz_byviii_done #1\R { #1}%
+\def\XINT_cuz_byviii_e\R #1\XINT_cuz_byviii_done #2\R{ #2}%
\def\XINT_zeroes_forviii #1#2#3#4#5#6#7#8%
{%
\xint_gob_til_R #8\XINT_zeroes_forviii_end\R\XINT_zeroes_forviii
@@ -152,7 +150,6 @@
{%
\noexpand\expandafter\space\noexpand\xint_gob_til_one #2#3#4#5#6#7#8%
}%
-%%%%%%%%%%%%
\def\XINT_rsepbyviii #1#2#3#4#5#6#7#8%
{%
\XINT_rsepbyviii_b {#1#2#3#4#5#6#7#8}%
@@ -164,7 +161,6 @@
}%
\def\XINT_rsepbyviii_end_B #1\relax #2#3{#2.}%
\def\XINT_rsepbyviii_end_A #11#2\expandafter #3\relax #4#5{#2.1#5.}%
-%%%%%%%%%%%%
\def\XINT_sepandrev
{%
\expandafter\XINT_sepandrev_a\the\numexpr 1\XINT_rsepbyviii
@@ -177,7 +173,6 @@
}%
\def\XINT_sepandrev_end\R\XINT_sepandrev_b #1#2\W {\XINT_sepandrev_done #1}%
\def\XINT_sepandrev_done #11#2!{ }%
-%%%%%%%%%%%%
\def\XINT_sepandrev_andcount
{%
\expandafter\XINT_sepandrev_andcount_a\the\numexpr 1\XINT_rsepbyviii
@@ -220,13 +215,11 @@
{%
#2\expandafter!\the\numexpr#3\expandafter!\the\numexpr#4\expandafter
!\the\numexpr#5\expandafter!\the\numexpr#6\expandafter!\the\numexpr
- #7\expandafter
- !\the\numexpr#8\expandafter!\the\numexpr#9\expandafter!\the\numexpr
+ #7\expandafter!\the\numexpr#8\expandafter!\the\numexpr#9\expandafter!\the\numexpr
\expandafter\XINT_sepbyviii_andcount_b\the\numexpr #1+\xint_c_viii.%
}%
\def\XINT_sepbyviii_andcount_end #1\XINT_sepbyviii_andcount_b\the\numexpr
#2+\xint_c_viii.#3#4\W {\expandafter.\the\numexpr #2+#3.}%
-%%%%%%%%%%%%
\def\XINT_rev_nounsep #1#2!#3!#4!#5!#6!#7!#8!#9!%
{%
\xint_gob_til_R #9\XINT_rev_nounsep_end\R
@@ -234,13 +227,11 @@
}%
\def\XINT_rev_nounsep_end\R\XINT_rev_nounsep #1#2\W {\XINT_rev_nounsep_done #1}%
\def\XINT_rev_nounsep_done #11{ 1}%
-%%%%%%%%%%%%
\def\XINT_sepbyviii_Z #1#2#3#4#5#6#7#8%
{%
1#1#2#3#4#5#6#7#8\expandafter!\the\numexpr\XINT_sepbyviii_Z
}%
\def\XINT_sepbyviii_Z_end #1\relax {\relax\Z!}%
-%%%%%%%%%%%%
\def\XINT_unsep_cuzsmall #11#2!1#3!1#4!1#5!1#6!1#7!1#8!1#9!%
{%
\xint_gob_til_R #9\XINT_unsep_cuzsmall_end\R
@@ -250,7 +241,6 @@
\XINT_unsep_cuzsmall #1{\XINT_unsep_cuzsmall_done #1}%
\def\XINT_unsep_cuzsmall_done #1\R #2\W{\XINT_cuz_small #1}%
\def\XINT_unsep_delim {1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W}%
-%%%%%%%%%%%%
\def\XINT_div_unsepQ #11#2!1#3!1#4!1#5!1#6!1#7!1#8!1#9!%
{%
\xint_gob_til_R #9\XINT_div_unsepQ_end\R
@@ -267,7 +257,6 @@
{\the\numexpr #1\relax \Z}%
\def\XINT_div_unsepQ_y #1.#2\R #3\W{\XINT_cuz_small #2\Z}%
\def\XINT_div_unsepQ_done #1.#2\R #3\W { #1#2\Z}%
-%%%%%%%%%%%%
\def\XINT_div_unsepR #11#2!1#3!1#4!1#5!1#6!1#7!1#8!1#9!%
{%
\xint_gob_til_R #9\XINT_div_unsepR_end\R
@@ -826,15 +815,24 @@
}%
\def\XINT_sub_l #1{\xint_UDzerofork #1\XINT_sub_l_carry 0\XINT_sub_l_nocarry\krof}%
\def\XINT_sub_l_nocarry 1{1\relax }%
-\def\XINT_sub_l_carry #1!{\expandafter\XINT_sub_m\the\numexpr 1#1-\xint_c_i!}%
-\def\XINT_sub_m 1#1{\xint_UDzerofork #1\XINT_sub_n_carry 0\XINT_sub_n_nocarry\krof}%
-\def\XINT_sub_n_carry #1!{1#1\expandafter!\the\numexpr\XINT_sub_l_carry }%
-\def\XINT_sub_n_nocarry #1!#2#3!%
+\def\XINT_sub_l_carry 1#1!{\ifcase #1
+ \expandafter \XINT_sub_l_zeroa\or\expandafter\XINT_sub_l_one\else
+ \expandafter \XINT_sub_l_done\fi 1#1!}%
+\def\XINT_sub_l_done {-\xint_c_i+}%
+\def\XINT_sub_l_one 1#1!#2%
{%
- \xint_gob_til_Z #2\xint_gob_til_eightzeroes #1\XINT_sub_n_zero
- 00000000\xint_gob_til_Z\Z 1\relax #1!#2#3!%
+ \xint_gob_til_Z #2\XINT_sub_l_oneone\Z 1\relax 00000000!#2%
}%
-\def\XINT_sub_n_zero 00000000\xint_gob_til_Z\Z 1\relax 00000000!{1!}%
+\def\XINT_sub_l_oneone #1\W {1\relax \XINT_cuz_byviii!\Z 0\W\R }%
+\def\XINT_sub_l_zeroa 1#1!{199999999\expandafter!\the\numexpr \XINT_sub_l_zerob }%
+\def\XINT_sub_l_zerob 1#1!{\ifcase #1
+ \expandafter \XINT_sub_l_zeroa\or\expandafter\XINT_sub_l_zone\else
+ \expandafter \XINT_sub_l_done\fi 1#1!}%
+\def\XINT_sub_l_zone 1#1!#2%
+{%
+ \xint_gob_til_Z #2\XINT_sub_l_zoneone\Z 1\relax 00000000!#2%
+}%
+\def\XINT_sub_l_zoneone\Z 1\relax 00000000{1}%
\def\XINT_sub_p\Z\XINT_sub_l #1#2\W
{%
\xint_UDzerofork
@@ -1085,62 +1083,55 @@
1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W
}%
\def\xintiiPow {\romannumeral0\xintiipow }%
-\def\xintiipow #1%
+\def\xintiipow #1#2%
{%
- \expandafter\xint_pow\romannumeral`&&@#1\Z%
+ \expandafter\xint_pow\the\numexpr #2\expandafter.\romannumeral`&&@#1\Z%
}%
-\def\xintiPow {\romannumeral0\xintipow }%
-\def\xintipow #1%
+\def\xintiPow {\romannumeral0\xintipow }%
+\def\xintipow #1#2%
{%
- \expandafter\xint_pow\romannumeral0\xintnum{#1}\Z%
+ \expandafter\xint_pow\the\numexpr #2\expandafter.\romannumeral0\xintnum{#1}\Z%
}%
-\def\xint_pow #1#2\Z
+\def\xint_pow #1.#2%#3\Z
{%
- \xint_UDsignfork
- #1\XINT_pow_Aneg
- -\XINT_pow_Anonneg
- \krof
- #1{#2}%
+ \xint_UDzerominusfork
+ #2-\XINT_pow_AisZero
+ 0#2\XINT_pow_Aneg
+ 0-{\XINT_pow_Apos #2}%
+ \krof {#1}%
}%
-\def\XINT_pow_Aneg #1#2#3%
+\def\XINT_pow_AisZero #1#2\Z
{%
- \expandafter\XINT_pow_Aneg_\expandafter{\the\numexpr #3}#2\Z
+ \ifcase\XINT_cntSgn #1\Z
+ \xint_afterfi { 1}%
+ \or
+ \xint_afterfi { 0}%
+ \else
+ \xint_afterfi {\xintError:DivisionByZero\space 0}%
+ \fi
}%
-\def\XINT_pow_Aneg_ #1%
+\def\XINT_pow_Aneg #1%
{%
\ifodd #1
- \expandafter\XINT_pow_Aneg_Bodd
+ \expandafter\XINT_opp\romannumeral0%
\fi
- \XINT_pow_Anonneg_ {#1}%
-}%
-\def\XINT_pow_Aneg_Bodd #1%
-{%
- \expandafter\XINT_opp\romannumeral0\XINT_pow_Anonneg_
+ \XINT_pow_Apos {}{#1}%
}%
-\def\XINT_pow_Anonneg #1#2#3%
+\def\XINT_pow_Apos #1#2{\XINT_pow_Apos_a {#2}#1}%
+\def\XINT_pow_Apos_a #1#2#3%
{%
- \expandafter\XINT_pow_Anonneg_\expandafter {\the\numexpr #3}#1#2\Z
+ \xint_gob_til_Z #3\XINT_pow_Apos_short\Z
+ \XINT_pow_AatleastTwo {#1}#2#3%
}%
-\def\XINT_pow_Anonneg_ #1#2#3\Z
+\def\XINT_pow_Apos_short\Z\XINT_pow_AatleastTwo #1#2\Z
{%
- \if\relax #3\relax\xint_dothis
- {\ifcase #2 \expandafter\XINT_pow_AisZero
- \or\expandafter\XINT_pow_AisOne
- \else\expandafter\XINT_pow_AatleastTwo
- \fi }\fi
- \xint_orthat \XINT_pow_AatleastTwo {#1}{#2#3}%
-}%
-\def\XINT_pow_AisOne #1#2{ 1}%
-\def\XINT_pow_AisZero #1#2%
-{%
- \ifcase\XINT_cntSgn #1\Z
- \xint_afterfi { 1}%
- \or
- \xint_afterfi { 0}%
- \else
- \xint_afterfi {\xintError:DivisionByZero\space 0}%
- \fi
+ \ifcase #2
+ \xintError:thiscannothappen!
+ \or \expandafter\XINT_pow_AisOne
+ \else\expandafter\XINT_pow_AatleastTwo
+ \fi {#1}#2\Z
}%
+\def\XINT_pow_AisOne #1\Z{ 1}%
\def\XINT_pow_AatleastTwo #1%
{%
\ifcase\XINT_cntSgn #1\Z
@@ -1152,10 +1143,10 @@
\fi
{#1}%
}%
-\edef\XINT_pow_BisNegative #1#2%
+\edef\XINT_pow_BisNegative #1\Z
{\noexpand\xintError:FractionRoundedToZero\space 0}%
-\def\XINT_pow_BisZero #1#2{ 1}%
-\def\XINT_pow_I_in #1#2%
+\def\XINT_pow_BisZero #1\Z{ 1}%
+\def\XINT_pow_I_in #1#2\Z
{%
\expandafter\XINT_pow_I_loop
\the\numexpr #1\expandafter.%
@@ -1229,33 +1220,24 @@
\the\numexpr #1\expandafter.%
\the\numexpr\XINT_pow_mulbutcheckifsmall #3\W #3\W #2\W
}%
-\def\xintiFac {\romannumeral0\xintifac }%
-\def\xintifac #1%
-{%
- \expandafter\XINT_fac_fork\expandafter {\the\numexpr#1}%
-}%
\def\xintiiFac {\romannumeral0\xintiifac }%
-\def\xintiifac #1%
-{%
- \expandafter\XINT_fac_fork\expandafter {\romannumeral`&&@#1}%
-}%
-\let\xintFac\xintiFac \let\xintfac\xintifac
-\def\XINT_fac_fork #1%
+\def\xintiifac #1{\expandafter\XINT_fac_fork\the\numexpr#1.}%
+\def\xintiFac {\romannumeral0\xintifac }%
+\let\xintifac\xintiifac
+\def\XINT_fac_fork #1#2.%
{%
- \ifcase\XINT_cntSgn #1\Z
- \xint_afterfi{\expandafter\space\expandafter 1\xint_gobble_i }%
- \or
- \expandafter\XINT_fac_checksize
- \else
- \xint_afterfi{\expandafter\xintError:FactorialOfNegativeNumber
- \expandafter\space\expandafter 1\xint_gobble_i }%
- \fi
- {#1}%
+ \xint_UDzerominusfork
+ #1-\XINT_fac_zero
+ 0#1\XINT_fac_neg
+ 0-\XINT_fac_checksize
+ \krof #1#2.%
}%
-\def\XINT_fac_checksize #1%
+\def\XINT_fac_zero #1.{ 1}%
+\edef\XINT_fac_neg #1.{\noexpand\xintError:FactorialOfNegative\space 1}%
+\def\XINT_fac_checksize #1.%
{%
- \ifnum #1>9999
- \xint_dothis{\expandafter\xintError:FactorialOfTooBigNumber
+ \ifnum #1>\xint_c_x^iv
+ \xint_dothis{\expandafter\xintError:TooBigFactorial
\expandafter\space\expandafter 1\xint_gob_til_W }\fi
\ifnum #1>465 \xint_dothis{\XINT_fac_bigloop_a #1.}\fi
\ifnum #1>101 \xint_dothis{\XINT_fac_medloop_a #1.\XINT_mul_out}\fi
@@ -1401,7 +1383,6 @@
\expandafter\xint_exchangetwo_keepbraces
\expandafter{\romannumeral0\XINT_sub_mm_a {}{}#3\Z #2\Z}{#1}% r-> b-r
}%
-%%%%%%%%%%%%
\def\XINT_div_prepare #1%
{%
\XINT_div_prepare_a #1\R\R\R\R\R\R\R\R {10}0000001\W !{#1}%
@@ -1411,7 +1392,6 @@
\xint_gob_til_R #9\XINT_div_prepare_small\R
\XINT_div_prepare_b #9%
}%
-%%%%%%%%%%%%
\def\XINT_div_prepare_small\R #1!#2%
{%
\ifcase #2
@@ -1462,7 +1442,6 @@
{\the\numexpr #1\expandafter}\expandafter{\the\numexpr #3-#1*#2}}%
\def\XINT_div_dosmalldiv
{{\expandafter\XINT_sdiv_out\the\numexpr\XINT_smalldivx_a}}%
-%%%%%%%%%%%%
\def\XINT_div_prepare_b
{\expandafter\XINT_div_prepare_c\romannumeral0\XINT_zeroes_forviii }%
\def\XINT_div_prepare_c #1!%
@@ -1854,8 +1833,7 @@
{%
-\ifnum 0#1=\xint_c_ 1\else2\fi\relax
}%
-%%%%%%%%%%%%
-\def\XINT_sdiv_out #1\Z #2\W%
+\def\XINT_sdiv_out #1\Z!#2!%
{\expandafter
{\romannumeral0\XINT_unsep_cuzsmall#11\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W}%
{#2}}%
@@ -1864,22 +1842,22 @@
\expandafter\XINT_smalldivx_b
\the\numexpr (#3+#1)/#2-\xint_c_i!#1.#2!#3!%
}%
-\def\XINT_smalldivx_b #1!%
+\def\XINT_smalldivx_b #1#2!%
{%
\if0#1\else
- \xint_c_x^viii+#1\xint_afterfi{\expandafter!\the\numexpr}\fi
- \XINT_smalldiv_c #1!%
+ \xint_c_x^viii+#1#2\xint_afterfi{\expandafter!\the\numexpr}\fi
+ \XINT_smalldiv_c #1#2!%
}%
\def\XINT_smalldiv_c #1!#2.#3!#4!%
{%
\expandafter\XINT_smalldiv_d\the\numexpr #4-#1*#3!#2.#3!%
}%
-\def\XINT_smalldiv_d #1!#2!#3#4!%
+\def\XINT_smalldiv_d #1!#2!1#3#4!%
{%
- \xint_gob_til_Z #4\XINT_smalldiv_end \Z
- \XINT_smalldiv_e #1!#2!#3#4!%
+ \xint_gob_til_Z #3\XINT_smalldiv_end \Z
+ \XINT_smalldiv_e #1!#2!1#3#4!%
}%
-\def\XINT_smalldiv_end\Z\XINT_smalldiv_e #1!#2!1\Z!{1!\Z #1\W }%
+\def\XINT_smalldiv_end\Z\XINT_smalldiv_e #1!#2!1\Z!{1!\Z!#1!}%
\def\XINT_smalldiv_e #1!#2.#3!%
{%
\expandafter\XINT_smalldiv_f\the\numexpr
@@ -1899,18 +1877,15 @@
}%
\def\XINT_smalldiv_g 1#1!1#2!#3!#4!#5!#6!%
{%
- \expandafter\XINT_smalldiv_h
- \the\numexpr 1#6-#1.#2!#5!#3!#4!%
+ \expandafter\XINT_smalldiv_h\the\numexpr 1#6-#1.#2!#5!#3!#4!%
}%
\def\XINT_smalldiv_h 1#1#2.#3!#4!%
{%
- \expandafter\XINT_smalldiv_i
- \the\numexpr #4-#3+#1-\xint_c_i.#2!%
+ \expandafter\XINT_smalldiv_i\the\numexpr #4-#3+#1-\xint_c_i.#2!%
}%
\def\XINT_smalldiv_i #1.#2!#3!#4.#5!%
{%
- \expandafter\XINT_smalldiv_j
- \the\numexpr (#1#2+#4)/#5-\xint_c_i!#3!#1#2!#4.#5!%
+ \expandafter\XINT_smalldiv_j\the\numexpr (#1#2+#4)/#5-\xint_c_i!#3!#1#2!#4.#5!%
}%
\def\XINT_smalldiv_j #1!#2!%
{%