1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
|
%%
%% 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-2015 by Jean-Francois Burnol
%%
\NeedsTeXFormat{LaTeX2e}%
\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`\_
\catcode`\noexpand\:\the\catcode`\:
\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
\catcode`\, 12
\catcode`\* 12
\catcode`\( 12
\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
\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}%
\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}%
\let\xint_orthat \xint_firstofone
\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 }%
\def\BNE_wrap { !\BNE_usethe\BNE_protect\BNE_unlock }%
\protected\def\BNE_usethe\BNE_protect {\BNE:missing_bnethe!}%
\def\BNE_protect\BNE_unlock {\noexpand\BNE_protect\noexpand\BNE_unlock\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_unlock {\expandafter\BNE_unlock_a\string }%
\def\BNE_unlock_a #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\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
\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
\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 \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_scanint_b #1%
{%
\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_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_gobz_scanint_b #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_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
{%
\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_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
\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{%
\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{%
\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_<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_<op>_a
{\xint_UDsignfork
##2{\expandafter #2\expandafter ##1\romannumeral-`0#4}%
-{#3##1##2}%
\krof }%
\def #3##1##2##3##4% \BNE_until_<op>_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}{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
\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_-<level>
{% get next number+operator then switch to _until macro
\expandafter #2\romannumeral-`0\BNE_getnext
}%
\def #2##1% \BNE_until_-<level>_a
{\xint_UDsignfork
##1{\expandafter #2\romannumeral-`0#1}%
-{#3##1}%
\krof }%
\def #3##1##2##3% \BNE_until_-<level>_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_Op_opp
\romannumeral-`0\BNE_unlock ##3\endcsname }%
\fi
}%
}%
\BNE_tmpa {vi}%
\BNE_tmpa {vii}%
\BNE_tmpa {viii}%
\def\BNE_Op_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
\let\BNE_tmpa\relax \let\BNE_tmpb\relax \let\BNE_tmpc\relax
\BNErestorecatcodes
\endinput
%%
%% End of file `bnumexpr.sty'.
|