summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/bnumexpr/bnumexpr.dtx
blob: 23ead1e2e1e495caf0d6d85000f4725eb6a6e8e2 (plain)
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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
% -*- coding: utf-8-unix; time-stamp-format: "%02d-%02m-%:y %02H:%02M:%02S %Z"; sentence-end-double-space: t; -*-
%<*dtx>
\def\bnedtxtimestamp  {Time-stamp: <13-05-2021 12:37:08 CEST>}
\iffalse
%</dtx>
%<*drv>
%% ---------------------------------------------------------------
\def\bnedocdate {2021/05/13}% package bnumexpr documentation date
\def\bnepackdate{2021/05/13}% package bnumexpr date
\def\bneversion {1.4a}      % package bnumexpr version
%</drv>
%<*readme>--------------------------------------------------------
| Source:  bnumexpr.dtx
| Version: v1.4a, 2021/05/13 (doc: 2021/05/13)
| Author:  Jean-Francois Burnol
| Info:    Expressions with big integers
| License: LPPL 1.3c

bnumexpr usage
==============

The LaTeX package `bnumexpr` allows expandable computations with
integers and the four infix operators `+`, `-`, `*`, `/` using the
expression syntax familiar from the `\numexpr` e-TeX parser, with
these extensions:

- arbitrarily big integers,
- floored division `//`,
- associated modulo `/:`,
- power operators `^` and `**`,
- factorial post-fix operator `!`,
- comma separated expressions,
- the space character as well as the underscore may serve
  to separate groups of digits,
- optional conversion of output to hexadecimal.

The expression parser is a scaled-down variant from the
`\xintiiexpr...\relax`
parser from package [xintexpr](http://ctan.org/pkg/xintexpr).

To support hexadecimal input and output, the package
[xintbinhex](http://ctan.org/pkg/xint) is loaded automatically.

The package loads by default [xintcore](http://ctan.org/pkg/xint)
but the option _custom_ together with macro `\bnumexprsetup` allow to map
the syntax elements to macros from an alternative big integer
expandable engine of the user own choosing,
and then [xintcore](http://ctan.org/pkg/xint) is not loaded.

Installation
============

Use your installation manager to install or update `bnumexpr`.

Else, obtain `bnumexpr.dtx`, from CTAN:

> <http://www.ctan.org/pkg/bnumexpr>

Run `"etex bnumexpr.dtx"` to extract these files:

`bnumexpr.sty`
  : this is the style file.

`README.md`

`bnumexprchanges.tex`
  : change history.

`bnumexpr.tex`
  : can be used to generate the documentation:

  :  - with latex+dvipdfmx: `"latex bnumexpr.tex"` (thrice) then
      `"dvipdfmx bnumexpr.dvi"`.

  :  - with pdflatex: `"pdflatex bnumexpr.tex"` (thrice).

  : In both cases files `README.md` and `bnumexprchanges.tex` must
    be located in the same repertory as `bnumexpr.tex` and `bnumexpr.dtx`.

without `bnumexpr.tex`:
  : `"pdflatex bnumexpr.dtx"` (thrice) extracts all files and
    simultaneously generates the pdf documentation.

Finishing the installation:

           bnumexpr.sty   --> TDS:tex/latex/bnumexpr/

           bnumexpr.dtx   --> TDS:source/latex/bnumexpr/

           bnumexpr.pdf   --> TDS:doc/latex/bnumexpr/
              README.me   --> TDS:doc/latex/bnumexpr/

License
=======

Copyright (C) 2014-2021 by Jean-Francois Burnol

| This Work may be distributed and/or modified under the
| 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 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 "author-maintained".

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.tex, bnumexprchanges.tex,
    and README.md

%</readme>--------------------------------------------------------
%<*!readme>
%% ---------------------------------------------------------------
%% The bnumexpr package: Expressions with big integers
%% Copyright (C) 2014-2021 by Jean-Francois Burnol
%%
%</!readme>
%<*changes>-------------------------------------------------------
\item[1.4a (2021/05/13)]
  \begin{itemize}
  \item fix undefined control sequences errors encountered by the parser in
    case of either extra or missing closing parenthesis (due to a problem
    in technology transfer at |1.4| from upstream \xintexprname).
  \item fix |\BNE_Op_opp| must now be f-expandable (also caused as a
    collateral to the technology transfer).
  \item fix user documentation regarding the constraints applying to the user
    replacement macros for the core algebra, as they have changed at |1.4|.
  \end{itemize}

\item[1.4 (2021/05/12)]
  \begin{itemize}
  \item technology transfer from \xintexprname |1.4| of
    |2020/01/31|. The |\expanded| primitive is now required (TeXLive
    2019).
  \item addition to the syntax of the |"| prefix for hexadecimal
    input.
  \item addition of |\evaltohex| which is like |\bnumeval| with an extra
    conversion step to hexadecimal notation.
  \end{itemize}

\item[1.2e (2019/01/08)]
  Fixes a documentation glitch (extra braces when mentioning |\the\numexpr| or
  |\thebnumexpr|).

\item[1.2d (2019/01/07)]
  \begin{itemize}
  \item requires \xintcorename |1.3d| or later (if not using option |custom|).
  \item adds |\bnumeval|\marg{expression} user interface.
  \end{itemize}

\item[1.2c (2017/12/05)] \textbf{Breaking changes:}
  \begin{itemize}
  \item requires \xintcorename |1.2p| or later (if not using option |custom|).
  \item |divtrunc| key of |\bnumexprsetup| is renamed to |div|.
  \item the |//| and |/:| operators are now by default associated to the
    \emph{floored} division. This is to keep in sync with the change of
    \xintcorename at |1.2p|.
  \item for backwards compatibility, one
    may add to existing document:\newline
    \string\bnumexprsetup\{div=\string\xintiiDivTrunc,
    mod=\string\xintiiModTrunc\}
  \end{itemize}

\item[1.2b (2017/07/09)]
  \begin{itemize}
  \item the |_| may be used to separate visually blocks of digits in long
    numbers.
  \end{itemize}

\item[1.2a (2015/10/14)]
  \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,
  \item the package now loads only |xintcore|, which belongs to |xint| bundle
    version |1.1| and extracts from the earlier |xint| package the core arithmetic
    operations as used by |bnumexpr|.
  \end{itemize}

\item[1.1a (2014/09/22)]
  \begin{itemize}
  \item added |l3bigint| option to use experimental \LaTeX3
    package of the same name,

  \item added Changes and Readme sections to the documentation,

  \item better |\BNE_protect| mechanism for use of
  |\bnumexpr...\relax| inside an |\edef| (without |\bnethe|). Previous one,
  inherited from |xintexpr.sty 1.09n|, assumed that the |\.=<digits>| dummy
  control sequence encapsulating the computation result had |\relax|
  meaning. But removing this assumption was only a matter of letting
  |\BNE_protect| protect two, not one, tokens. This will be backported to
  next version of \xintexprname, naturally (done with |xintexpr.sty 1.1|).
  \end{itemize}

\item[1.1 (2014/09/21)] First release. This is down-scaled from the
  (development version of) \xintexprname. Motivation came the previous day
  from a chat with \textsc{Joseph Wright} over big int status in \LaTeX3.
  The |\bnumexpr...\relax| parser can be used on top of big int macros of
  one's choice. Functionalities limited to the basic operations. I leave
  the power operator |^| as an option.
%</changes>-------------------------------------------------------
%<*drv>-----------------------------------------------------------
%% latex bnumexpr.tex (thrice) && dvipdfmx bnumexpr.dvi
%% to produce bnumexpr.pdf
%%
%% or pdflatex bnumexpr.tex (no need to change \Withdvipdfmx toggle,
%% pdf engine will be detected automatically)
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesFile{bnumexpr.tex}%
[\bnepackdate\space v\bneversion\space driver file for %
  bnumexpr documentation (JFB)]%
\PassOptionsToClass{a4paper,fontsize=11pt}{scrdoc}
\chardef\Withdvipdfmx 1 %
\chardef\NoSourceCode 0 % replace 0 by 1 for not including source code
\input bnumexpr.dtx
%%% Local Variables:
%%% mode: latex
%%% End:
%</drv>-----------------------------------------------------------
%<*dtx>
\fi % end of \iffalse block around generated files
\chardef\noetex 0
\ifx\numexpr\undefined \chardef\noetex 1 \fi
\ifnum\noetex=1 \chardef\extractfiles 0 % extract files, then stop
\else
    \ifx\ProvidesFile\undefined
      \chardef\extractfiles 0 % no LaTeX2e; etex, ... on bnumexpr.dtx
    \else % latex/pdflatex on bnumexpr.tex or on bnumexpr.dtx
      \ifx\Withdvipdfmx\undefined
        % latex run is on bnumexpr.dtx, we will extract all files
        \chardef\extractfiles 1 % 1 = extract and typeset, 2=only typeset
        \chardef\Withdvipdfmx 0 % 0 = pdflatex or latex+dvips, 1 = dvipdfmx
        \chardef\NoSourceCode 0 % 0 = include source code, 1 = do not
        \NeedsTeXFormat{LaTeX2e}%
        \PassOptionsToClass{a4paper,fontsize=11pt}{scrdoc}%
      \else % latex run is on bnumexpr.tex,
        \chardef\extractfiles 2 % no extractions
      \fi
      \ProvidesFile{bnumexpr.dtx}[bundle source (\bnedtxtimestamp)]%
    \fi
\fi
\ifnum\extractfiles<2 % extract files
\def\MessageDeFin{\newlinechar10 \let\Msg\message
\Msg{^^J}%
\Msg{********************************************************************^^J}%
\Msg{*^^J}%
\Msg{* To finish the installation you have to move the following^^J}%
\Msg{* files into a directory searched by TeX:^^J}%
\Msg{*^^J}%
\Msg{*\space\space\space\space bnumexpr.sty^^J}%
\Msg{*^^J}%
\Msg{* To produce the documentation run latex thrice on bnumexpr.tex^^J}%
\Msg{* then dvipdfmx on bnumexpr.dvi. (ignore the dvipdfmx warnings)^^J}%
\Msg{*^^J}%
\Msg{* Happy TeXing!^^J}%
\Msg{*^^J}%
\Msg{********************************************************************^^J}%
}%
\begingroup
    \input docstrip.tex
    \askforoverwritefalse
    \generate{\nopreamble\nopostamble
    \file{README.md}{\from{bnumexpr.dtx}{readme}}
    \usepreamble\defaultpreamble
    \usepostamble\defaultpostamble
    \file{bnumexprchanges.tex}{\from{bnumexpr.dtx}{changes}}
    \file{bnumexpr.tex}{\from{bnumexpr.dtx}{drv}}
    \file{bnumexpr.sty}{\from{bnumexpr.dtx}{package}}}
\endgroup
\fi % end of file extraction
\ifnum\extractfiles=0
% direct tex/etex/xetex on bnumexpr.dtx, files now extracted, stop
  \MessageDeFin\expandafter\end
\fi
% no use of docstrip to extract files if latex compilation was on bnumexpr.tex
\ifdefined\MessageDeFin\AtEndDocument{\MessageDeFin}\fi
%-------------------------------------------------------------------------------
\documentclass {scrdoc}
\ifnum\NoSourceCode=1 \OnlyDescription\fi
\usepackage{ifpdf}
\ifpdf\chardef\Withdvipdfmx 0 \fi
\makeatletter
\ifnum\Withdvipdfmx=1
   \@for\@tempa:=hyperref,bookmark,graphicx,xcolor,pict2e\do
            {\PassOptionsToPackage{dvipdfmx}\@tempa}
   %
   \PassOptionsToPackage{dvipdfm}{geometry}
   \PassOptionsToPackage{bookmarks=true}{hyperref}
   \PassOptionsToPackage{dvipdfmx-outline-open}{hyperref}
   %\PassOptionsToPackage{dvipdfmx-outline-open}{bookmark}
   %
   \def\pgfsysdriver{pgfsys-dvipdfm.def}
\else
   \PassOptionsToPackage{bookmarks=true}{hyperref}
\fi
\makeatother

\pagestyle{headings}

\usepackage[T1]{fontenc}

\usepackage[hscale=0.66,vscale=0.75]{geometry}

% requires newtxtt 1.05 or later
\usepackage[zerostyle=a,scaled=0.95,straightquotes]{newtxtt}
\renewcommand\familydefault\ttdefault
\usepackage[noendash]{mathastext}
\renewcommand\familydefault\sfdefault

\usepackage{graphicx}
\usepackage[dvipsnames]{xcolor}
\definecolor{joli}{RGB}{225,95,0}
\definecolor{JOLI}{RGB}{225,95,0}
\definecolor{BLUE}{RGB}{0,0,255}
%\definecolor{niceone}{RGB}{38,128,192}% utilisé avant pour urlcolor
%\colorlet{smallverbcolor}{RoyalPurple}% \colorlet{jfverbcolor}{yellow!5}
\colorlet{smallverbcolor}{NavyBlue}%
\colorlet{softwrapcolor}{blue}
\colorlet{digitscolor}{OrangeRed}

% transféré de xint-manual.tex (maintenant dans xint.dtx)
\DeclareFontFamily{U}{MdSymbolC}{}
\DeclareFontShape {U}{MdSymbolC}{m}{n}{<-> MdSymbolC-Regular}{}

\makeatletter
\newbox\cdbx@SoftWrapIcon
\def\cdbx@SetSoftWrapBox{%
    \setbox\cdbx@SoftWrapIcon\hb@xt@\z@
    {\hb@xt@\fontdimen2\font
        {\hss{\color{softwrapcolor}\usefont{U}{MdSymbolC}{m}{n}\char"97}\hss}%
     \hss}%
   }
\makeatother

\usepackage[english]{babel}

\usepackage{hyperref}
\hypersetup{%
%linktoc=all,%
breaklinks=true,%
colorlinks=true,%
urlcolor=SkyBlue,%
linkcolor=PineGreen,%
pdfauthor={Jean-François Burnol},%
pdftitle={The bnumexpr package},%
pdfsubject={Arithmetic with TeX},%
pdfkeywords={Expansion, arithmetic, TeX},%
pdfstartview=FitH,%
pdfpagemode=UseOutlines}
\usepackage{bookmark}

%---- \verb, and verbatim like `environments'. \MicroFont et \MacroFont
\makeatletter
\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. (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)
% invalidates the following.
%
% Actually, I should not at all rely on the doc class, I should do it all by
% myself.

\def\macrocode{\macro@code
               \frenchspacing \@vobeyspaces
               \makestarlowast % \makequotesstraight (obsolète)
               \xmacro@code }

%--- lower * symbol in text

\def\lowast{\raisebox{-.25\height}{*}}
\catcode`* \active
\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

% 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\jf@makeletter #1{\catcode`#111\relax }

\def\verb #1%
{%
  \relax\leavevmode\null
  \begingroup
   \MicroFont
   \catcode`_ 11 \catcode`! 11 \catcode`: 11 
   \catcode`< 11 \catcode`> 11
  % \scantokens will have a result of inserting a space after cs's.
  % hence the need to have the catcodes of things like _ right.
  % I also need < for > for one occasion in code comments
  % naturally won't work in footnotes though.
  % this code is truly not satisfying, but enough for my needs here.
   \def\@jfverb ##1#1{\let\do\@makeother \dospecials
                      \makestarlowast
  %\let\do\do@noligs  \verbatim@nolig@list % not needed here
                      \@vobeyspaces\everyeof{\noexpand}%
                      \expandafter\@@jfverb\scantokens{##1}\relax}%
  \@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\relax\endgroup\else
       \discretionary{\copy\cdbx@SoftWrapIcon}{}{}%
       #1\expandafter\@@jfverb\fi }

\makeatother

% mardi 13 octobre 2015 à 15:32:51
% le | n'est pas encore actif ici!
\catcode`| \active
    \def\bneshow #1%
    {|\thebnumexpr#1\relax|$$\color{digitscolor}\bnumexpr#1\relax$$}
    \def\bneshoweval #1%
    {|\bnumeval{#1}|$$\color{digitscolor}\bnumeval{#1}$$}
    \def\bneshowevaltohex #1%
    {|\evaltohex{#1}|$$\color{digitscolor}\evaltohex{#1}$$}
\catcode`| 12

\DeclareRobustCommand\csa [1]{{\char92\detokenize{#1}}}
\newcommand\csh[1]{\texorpdfstring{\csa{#1}}{\textbackslash\detokenize{#1}}}

\usepackage{xspace}

\def\bnumname
   {\href{http://www.ctan.org/pkg/bnumexpr}{bnumexpr}\xspace }%

\def\bnumnameimp
   {\texorpdfstring
          {\hyperref[sec:bnumexprcode]{{\color{smallverbcolor}\ttzfamily bnumexpr}}}
          {bnumexpr}%
    \xspace }%

\def\xintkernelname
   {\href{http://www.ctan.org/pkg/xint}{xintkernel}\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/xintexpr}{xintexpr}\xspace }%
\def\xintbinhexname
   {\href{http://www.ctan.org/pkg/xint}{xintbinhex}\xspace }%


% \centeredline: OUR OWN LITTLE MACRO FOR CENTERING LINES
% =======================================================

% 7 mars 2013
% -----------
%
% This macro allows to conveniently center a line inside a paragraph and still
% allow use therein of \verb or other macros changing catcodes.
% A proposito, the \LaTeX \centerline uses \hsize and not \linewidth !
% (which in my humble opinion is bad)

% Actually my \centeredline works nicely in list environments.

% \ignorespaces ajouté le 9 juin 2013.

% Note: \centeredline creates a group

\makeatletter
\newcommand*\centeredline {%
      \ifhmode \\\relax
        \def\centeredline@{\hss\egroup\hskip\z@skip\ignorespaces }%
      \else
        \def\centeredline@{\hss\egroup }%
      \fi
      \afterassignment\@centeredline
      \let\next=}
\def\@centeredline
    {\hbox to \linewidth \bgroup \hss \bgroup \aftergroup\centeredline@ }


\frenchspacing
\usepackage{bnumexpr}

\usepackage{etoc}

\usepackage{framed}
\makeatletter\let\check@percent\relax\makeatother
\begin{document}
\thispagestyle{empty}
\ttzfamily
\pdfbookmark[1]{Title page}{TOP}

{%
\normalfont\Large\parindent0pt \parfillskip 0pt\relax
 \leftskip 2cm plus 1fil \rightskip 2cm plus 1fil
 The \bnumname package\par
}

{\centering
  \textsc{Jean-François Burnol}\par
  \footnotesize
  jfbu (at) free (dot) fr\par
  Package version: \bneversion\ (\bnepackdate);
            documentation date: \bnedocdate.\par
  {From source file \texttt{bnumexpr.dtx}. \bnedtxtimestamp.}\par
}

\etocsetnexttocdepth{section}
\tableofcontents

\section{\csh{bnumeval} (\csh{thebnumexpr}), \csh{evaltohex}}
\label{sec:bnumexpr}

\LaTeX\ Package \bnumname provides |\thebnumexpr|\meta{expression}|\relax|:
it is analogous to
  |\the\numexpr|\meta{expression}|\relax|, with these extensions:
\begin{itemize}
\item it allows arbitrarily big integers,
\item it computes powers (with either |**| or |^| as infix operator),
\item it computes factorials (with |!| as postfix operator),
\item it has an operator |//| for floored division and |/:| for the
  associated modulo,
\item the space character is ignored and can thus be used to separate in the
  source blocks of digits for better readability of long numbers,
\item also the underscore |_| may be used as visual digit
  separator,
\item comma separated expressions are allowed.
\end{itemize}
There is also a more core-level |\bnumexpr...\relax| construct%
\footnote{Since |1.4|, one can use |\bnumexpr...\relax| directly in
  typesetting context, it is not mandatory to prefix it with |\bnethe| or to
  use |\thebnumexpr|.}%
, which expands
to a self-contained unit, rather than to explicit digit tokens (and commas).
See \autoref{sec:differences} for some related information.

There is also the alternative interface |\bnumeval|\marg{expression}, where the
expression is fetched as braced argument.

And there is |\evaltohex|\marg{expression} which does the same as |\bnumeval|
but with a conversion to hexadecimal notation of the (possibly comma
separated) output. Hexadecimal input uses the |"| prefix.

This package parser is a scaled-down variant of |\xintiiexpr| from package
\xintexprname, dropping support for nested structures, functions, variables,
booleans, etc..., but incorporating by default support for hexadecimal input
as \xintbinhexname will be automatically loaded.

The \eTeX{} extensions are required, this is the default on all modern
installations for \verb?latex|pdflatex? and also for \verb?xelatex|lualatex?.

Further, at |1.4| (|2021/05/12|) the |\expanded| primitive is
required. It is available in all engines since \TeX Live 2019.

By default the arithmetic operations are executed via the \xintcorename
macros, but via option |custom| and usage of |\bnumexprsetup| it is
possible to replace them by expandable macros of a custom origin.

\section{Examples}

\noindent\bneshow {---1 208 637 867 * (2 187 917 891 - 3 109 197 072)}%
\bneshoweval {(13_8089_1090-300_1890_2902)*(1083_1908_3901-109_8290_3890)}%
\bneshoweval {(92_874_927_979**5-31_9792_7979**6)/30!}%
\bneshoweval {30!/20!/21/22/23/24/25/(26*27*28*29)}%
\bneshoweval {13^50//12^50, 13^50/:12^50}%
\bneshoweval {13^50/12^50, 12^50}%
\bneshoweval {(1^10+2^10+3^10+4^10+5^10+6^10+7^10+8^10+9^10)^3}%
\bneshoweval {100!/36^100}%
\bneshoweval {"10*"100*"1000*"A0000, 16^(1+2+3+4)*10}%
\bneshowevaltohex{"7FFFFFFF+1, "400^3, "ABCDEF*"FEDCBA}%

\section{Differences from \csh{numexpr}}
\label{sec:differences}

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|:

\begin{enumerate}
\item contrarily to |\numexpr|, the |\bnumexpr| parser stops only after having
  found (and swallowed) a mandatory ending |\relax| token (it can arise from expansion),

\item in particular note that 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|

\item with |\edef\myVar{\thebnumexpr1+2\relax}|, the computation is of course
  done at time of the |\edef|. But one is also allowed to do
  |\edef\myVar{\bnumexpr1+2\relax}| which prepares |\myVar| as a macro which
  can be inserted in other \bnumname expressions and behave there as a
  self-contained pre-computed unit triggering tacit multiplication, or be
  typeset directly if inserted in the typesetting stream.%
%
\footnote{Prior to |1.4|, one would have had to use |\bnethe\myVar| for
  typesetting, or |\bnumeval{\myVar}|.}
%
  There is no analog with |\numexpr| as |\edef\myVar{\numexpr1+2\relax}| does
  not pre-compute anything and furthermore |\the\numexpr2\myVar\relax| in
  typesetting flow then triggers the |You can't use `\numexpr' in horizontal
  mode| error.

\item expressions may be comma separated. On input, spaces are ignored,
  and on output the values are comma separated with a space after
  each comma,

\item |\bnumexpr -(1+1)\relax| is legal contrarily to |\numexpr -(1+1)\relax|
  which raises an error,

\item |\numexpr 2\cnta\relax| is illegal (with |\cnta| a |\count|-variable.)
  But |\bnumexpr 2\cnta\relax| is perfectly legal and will do the tacit
  multiplication,

\item more generally, tacit multiplication applies in front of parenthesized
  sub-expressions, or sub |\bnumexpr...\relax| (or |\numexpr...\relax|), or
  also after parentheses in front of numbers,

\item the underscore |_| is accepted within the digits composing a number and
  is silently ignored by |\bnumexpr|.

\end{enumerate}

As hinted above |\bnumexpr...\relax| differs from |\thebnumexpr...\relax| as
the latter expands to explicit digit tokens, but the former expands to a
private self-contained format which can serve as sub-unit in other
expressions, or be used inside |\edef|.  Since |1.4| the former idiom can also
be inserted directly inside the typesetting stream, or be written out to an
external file where it will expand to some control sequences, braces, and
character tokens, all with their standard catcodes. 

One can use |\numexpr...\relax| as a sub-unit in |\bnumexpr...\relax| but the
reverse does not apply: it would either cause an error or an
anticipated end to the |\numexpr| which will think having hit a |\relax|.

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| control sequence. When using |\bnumeval{...}|
syntax as in
\begin{verbatim}
\ifnum\bnumeval{...}
...
\fi
\end{verbatim}
the end of line will insert a terminating space token. Again, here
|\bnumeval{...}| must produce an integer acceptable to \TeX, i.e. at most
{\number"7FFFFFFF} in absolute value.

\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}
\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}

\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}

It is the expected one with infix operators and parentheses, the
recognized operators being |+|, |-|, |*|, |/| (rounded division),
|^| (power), |**| (power), |//| (by default floored division),
|/:| (the associated modulo) and |!| (factorial). One can input hexadecimal
numbers as in \TeX\ syntax for number assignments, i.e. using a |"| prefix and
only uppercase letters |ABCDEF|.

The modulo |/:| is by default associated with the floored division |//|, but
using |\bnumexprsetup{mod=...}| it can, like the other operators, be remapped
to any macro of one's choice.

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.

The precedence rules are the expected ones. Tacit multiplication applies in
front of parentheses, and after them, and it has an elevated precedence
compared to multiplication explicitly induced by |*|.

There is currently no user interface to change precedence levels. The
three operators |/|, |//|, |/:| are at the same level of precedence as the
multiplication |*|. The factorial postfix |!| has highest precedence. The
minus signs inherit the precedence level of the previously encountered infix
operators.

In case of equal precedence the operations are left-associative,%
%
\footnote{But it has been announced at \xintexprname \texttt{1.4} that
  probably in future power operator will become right-associative, and if this
  is done, this will be transferred to \bnumname also.}
%
hence:\newline \bneshoweval{2^3^4, (2^3)^4, 2^(3^4)}

The underscore |_| can be used to separate digits in long numbers, for
readability of the input.

\section{Options}

The sole package option is |custom|: it tells \bnumname not to load
package \xintcorename.

\section{\csh{bnumexprsetup}}

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}) and uses \csa{bnumexprsetup} in
the following way:
\begin{verbatim}
    \usepackage{xintcore}
    \bnumexprsetup{add=\xintiiAdd, sub=\xintiiSub, mul=\xintiiMul,
                   divround=\xintiiDivRound, div=\xintiiDivFloor,
                   mod=\xintiiMod, pow=\xintiiPow, fac=\xintiiFac,
                   opp=\xintiiOpp}%
\end{verbatim}

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.

The macros serving as custom user replacements must be \emph{f}-expandable.%
%
\footnote{Prior to |1.4|, only \emph{x}-expandability was required. The author
  could relax again the constraint, if asked to do so. Or perhaps simply add
  an option for it.}
%
(except for the computation of factorials, which only has to be
\emph{x}-expandable).

They will by default receive arguments composed of explicit digit tokens, with
no leading zeros, with at most one leading minus sign and no plus sign.

The format of these arguments may depend on what the |opp=\foo| replacement
macro does. If the custom |\foo| inserts a |+| when taking the opposite of a
negative number, then the custom macros for arithmetic (and the |\foo| macro
itself) must be able to handle arguments starting optionally with such a |+|.

Macro |\bnumexprsetup| can be used multiple times in the same document, thus
allowing to switch math engines or to remap operators to some other arithmetic
macros of the same math engine. Its effect obeys the local scope.

At |1.4| release there is no option to customize how the hexadecimal input and
output is handled, it goes necessarily via the \xintbinhexname macros.

\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

%\clearpage

\section{Changes}
%\small
\begin{description}
\input bnumexprchanges.tex
\end{description}

\StopEventually{\end{document}\endinput}

\newgeometry{hscale=0.75,vscale=0.75}% ATTENTION \newgeometry fait
                                % un reset de vscale si on ne le
                                % précise pas ici !!!

\MakePercentIgnore
%
% \catcode`\<=0 \catcode`\>=11 \catcode`\*=11 \catcode`\/=11
% \let</dtx>\relax
% \def<*package>{\catcode`\<=12 \catcode`\>=12 \catcode`\*=12 \catcode`\/=12 }
%</dtx>
%<*package>
%
% \section{Package \bnumnameimp implementation}
% \label{sec:bnumexprcode}
% \etocdefaultlines
% \localtableofcontents
% \etocmarkbothnouc{Package \bnumnameimp implementation}
%
% Comments are sparse.  Actually at |1.4|, there are simply no comments. I
% transferred from \xintexprname its |\expanded| based infra-structure from
% its own |1.4| release of January 2020.
%
% Error handling by the parser is kept to a minimum; if something goes wrong,
% the offensive token gets discarded, and it is not even always the case that
% some expandable error message is issued.
%
% A few comments at |1.4a|:
% \begin{itemize}
% \item It looked a bit costly and probably would have been mostly useless to
%   end users to integrate in \bnumname support for nested structures via
%   square brackets [, ], which is in \xintexprname since its January 2020
%   |1.4| release.  But some underlying related architecture remains here; we
%   could make some micro-gains probably but diverging from upstream code
%   would make maintenance a nightmare.
% \item The |\bnumexpr\relax| syntax creating an empty ople is by itself now
%   legal, and can be injected (comma separated) in an expression, keeping it
%   invariant, however |\bnumeval{}| ends in a |File ended while scanning use
%   of \BNE_print_c| error because |\BNEprint| makes the tacit requirement
%   that the 1D ople to output has at least one item.
% \item Formerly, the |\csname...\endcsname| encapsulation technique had the
%   after-effect to allow the macros supporting the infix operators to be only
%   x-expandable.  At |1.4|, I could have still allowed only x-expandable
%   macros, but, keeping in sync with upstream, I have used only a
%   |\romannumeral| trigger and did not insert an |\expanded|, so now the
%   support macros must be f-expandable.  The |1.4a| release fixes the related
%   user documentation of |\bnumexprsetup| which was not updated at |1.4|.
%   The support macro for the factorial however needs only be x-expandable.
% \item Also, I simply do not understand why the legacy user documentation
%   said that the support macros were supposed to f-expand their arguments, as
%   they are used only with arguments being explicit digit tokens (and
%   optional minus sign).
% \item I hesitated a bit about making the decimal to hexadecimal and
%   hexadecimal to decimal support macros customizable, but dropped the
%   idea. Loading \xintbinhexname unconditionally has also the advantage to
%   not have to define some \xintkernelname provided helper macros; and it
%   still does not load \xintcorename, so is keeping dependencies somewhat low
%   and the |custom| option significant.
% \item I had fleetingly consider a parser |\hexexpr| where input is
%   hexadecimal with no |"| prefix, but implementing this basically means
%   duplicating with new names a large chunk of the parser code to have parser
%   specific |"getnext"| macros for example.  Not worth it.
% \end{itemize}
%
% \subsection{Package identification and catcode setup}
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}%
\ProvidesPackage{bnumexpr}[2021/05/13 v1.4a Expressions with big integers (JFB)]%
%    \end{macrocode}
% \subsection{Load unconditionally xintbinhex}
% Newly done at |1.4|. Formerly, \bnumname had no dependency if loaded
% with option |custom|. But for |1.4| release I have decided to add
% unconditional support for hexadecimal notation.
%
% Let's require the most recent \xintname date at time of
% writing. We should check for availability of |\expanded| but well.
%
%    \begin{macrocode}
\RequirePackage{xintbinhex}[2021/05/10]%
%    \end{macrocode}
% \subsection{\csh{bnumexprsetup}}
%    \begin{macrocode}
{\catcode`! 3 \catcode`_ 11 %
  \gdef\bnumexprsetup #1{\BNE_parsekeys #1,=!,}%
  \gdef\BNE_parsekeys #1=#2#3,%
  {%
    \ifx!#2\expandafter\BNE_parsedone\fi
    \expandafter
    \let\csname BNE_Op_\xint_zapspaces #1 \xint_gobble_i\endcsname%
    =#2\BNE_parsekeys
  }%
  \gdef\BNE_parsedone #1\BNE_parsekeys {}%
}%
%    \end{macrocode}
% \subsection{Package options}
% The keys should have been |Add|, |Sub|, \dots, not |add|, |sub|, \dots, so
% internally macros |\BNE_Op_Add| etc\dots\ macro names would be used, but well,
% let's simply leave with this.
%    \begin{macrocode}
\def\BNEtmpa {0}%
\DeclareOption {custom}{\def\BNEtmpa {1}}%
\ProcessOptions\relax
\edef\BNErestorecatcodes{\XINTrestorecatcodes}%
\XINTsetcatcodes%
\if0\BNEtmpa\expandafter\xint_secondoftwo\fi
\xint_gobble_i{%
    \RequirePackage{xintcore}[2021/05/10]%
    \bnumexprsetup{add=\xintiiAdd, sub=\xintiiSub, mul=\xintiiMul,
                   divround=\xintiiDivRound, div=\xintiiDivFloor,
                   mod=\xintiiMod, pow=\xintiiPow, fac=\xintiiFac,
                   opp=\xintiiOpp}%
}%
%    \end{macrocode}
% Strangely those three are not defined in xintkernel.sty, but only in xint.sty
%    \begin{macrocode}
\long\def\xint_firstofthree  #1#2#3{#1}%
\long\def\xint_secondofthree #1#2#3{#2}%
\long\def\xint_thirdofthree  #1#2#3{#3}%
%    \end{macrocode}
% \subsection{\csh{bnumexpr}, \csh{thebnumexpr}, \csh{bnethe}, \csh{bnumeval}}
%    \begin{macrocode}
\def\XINTfstop {\noexpand\XINTfstop}%
\def\bnumexpr  {\romannumeral0\bnumexpro}%
\def\bnumexpro {\expandafter\BNE_wrap\romannumeral0\bnebareeval }%
\def\BNE_wrap  {\XINTfstop\BNEprint.}%
\def\bnumeval #1%
   {\expanded\expandafter\BNEprint\expandafter.\romannumeral0\bnebareeval#1\relax}%
\def\evaltohex #1%
   {\expanded\expandafter\BNEprinthex\expandafter.\romannumeral0\bnebareeval#1\relax}%
\def\thebnumexpr
   {\expanded\expandafter\BNEprint\expandafter.\romannumeral0\bnebareeval}%
\def\bnebareeval{\BNE_start}%
\def\bnethe#1{\expanded\expandafter\xint_gobble_i\romannumeral`&&@#1}%
\protected\def\BNEprint.#1{{\BNE_print#1.}}%
\def\BNE_print#1{#1\expandafter\BNE_print_a\string}%
\def\BNE_print_a#1{\unless\if#1.\expandafter\BNE_print_b\fi}%
\def\BNE_print_b
   {\expandafter\BNE_print_c\expandafter{\expandafter\xint_gobble_i\string}}%
\def\BNE_print_c#1{, #1\expandafter\BNE_print_a\string}%
\protected\def\BNEprinthex.#1{{\BNE_printhex#1.}}%
\def\BNE_printhex#1{\xintDecToHex{#1}\expandafter\BNE_printhex_a\string}%
\def\BNE_printhex_a#1{\unless\if#1.\expandafter\BNE_printhex_b\fi}%
\def\BNE_printhex_b
   {\expandafter\BNE_printhex_c\expandafter{\expandafter\xint_gobble_i\string}}%
\def\BNE_printhex_c#1{, \xintDecToHex{#1}\expandafter\BNE_printhex_a\string}%
%    \end{macrocode}
% \subsection{\csh{BNE_getnext}}
%    \begin{macrocode}
\def\BNE_getnext #1%
{%
    \expandafter\BNE_put_op_first\romannumeral`&&@%
    \expandafter\BNE_getnext_a\romannumeral`&&@#1%
}%
\def\BNE_put_op_first #1#2#3{\expandafter#2\expandafter#3\expandafter{#1}}%
\def\BNE_getnext_a #1%
{%
    \ifx\relax #1\xint_dothis\BNE_foundprematureend\fi
    \ifx\XINTfstop#1\xint_dothis\BNE_subexpr\fi
    \ifcat\relax#1\xint_dothis\BNE_countetc\fi
    \xint_orthat{}\BNE_getnextfork #1%
}%
\def\BNE_foundprematureend\BNE_getnextfork #1{{}\xint_c_\relax}%
\def\BNE_subexpr #1.#2%
{%
    \expanded{\unexpanded{{#2}}\expandafter}\romannumeral`&&@\BNE_getop
}%
\def\BNE_countetc\BNE_getnextfork#1%
{%
    \if0\ifx\count#11\fi
        \ifx\dimen#11\fi
        \ifx\numexpr#11\fi
        \ifx\dimexpr#11\fi
        \ifx\skip#11\fi
        \ifx\glueexpr#11\fi
        \ifx\fontdimen#11\fi
        \ifx\ht#11\fi
        \ifx\dp#11\fi
        \ifx\wd#11\fi
        \ifx\fontcharht#11\fi
        \ifx\fontcharwd#11\fi
        \ifx\fontchardp#11\fi
        \ifx\fontcharic#11\fi 0\expandafter\BNE_fetch_as_number\fi
   \expandafter\BNE_getnext_a\number #1%
}%
\def\BNE_fetch_as_number
    \expandafter\BNE_getnext_a\number #1%
{%
    \expanded{{{\number#1}}\expandafter}\romannumeral`&&@\BNE_getop
}%
%    \end{macrocode}
% In the case of hitting a |(|, previous release inserted directly a
% |\BNE_oparen|.  But the expansion architecture imported from upstream
% |\xintiiexpr| has been refactored, and the |..._oparen| meaning and
% usage evolved.  We stick with |{}\xint_c_ii^v (| from upstream,
% which works (I am 15 months away from \xintexprname |1.4|).
%    \begin{macrocode}
\def\BNE_getnextfork #1{%
    \if#1+\xint_dothis \BNE_getnext_a \fi
    \if#1-\xint_dothis {{}{}-}\fi
    \if#1(\xint_dothis {{}\xint_c_ii^v (}\fi
    \xint_orthat {\BNE_scan_number #1}%
}%
%    \end{macrocode}
% \subsection{Parsing an integer in decimal or hexadecimal notation}
%    \begin{macrocode}
\def\BNE_scan_number #1%
{%
    \if "#1\xint_dothis \BNE_scanhex\fi
    \ifnum \xint_c_ix<1\string#1 \xint_dothis \BNE_startint\fi
    \xint_orthat \BNE_notadigit #1%
}%
\def\BNE_notadigit#1{\BNE_getnext }%
\def\BNE_startint #1%
{%
    \if #10\expandafter\BNE_gobz_a\else\expandafter\BNE_scanint_a\fi #1%
}%
\def\BNE_scanint_a #1#2%
    {\expanded\bgroup{{\iffalse}}\fi #1%
     \expandafter\BNE_scanint_main\romannumeral`&&@#2}%
\def\BNE_gobz_a #1#2%
    {\expanded\bgroup{{\iffalse}}\fi
     \expandafter\BNE_gobz_scanint_main\romannumeral`&&@#2}%
\def\BNE_scanint_main #1%
{%
    \ifcat \relax #1\expandafter\BNE_scanint_hit_cs \fi
    \ifnum\xint_c_ix<1\string#1 \else\expandafter\BNE_scanint_next\fi
    #1\BNE_scanint_again
}%
\def\BNE_scanint_again #1%
{%
    \expandafter\BNE_scanint_main\romannumeral`&&@#1%
}%
\def\BNE_scanint_hit_cs \ifnum#1\fi#2\BNE_scanint_again
{%
    \iffalse{{{\fi}}\expandafter}\romannumeral`&&@\BNE_getop#2%
}%
\def\BNE_scanint_next #1\BNE_scanint_again
{%
    \if    _#1\xint_dothis\BNE_scanint_again\fi
    \xint_orthat
    {\iffalse{{{\fi}}\expandafter}\romannumeral`&&@\BNE_getop#1}%
}%
\def\BNE_gobz_scanint_main #1%
{%
    \ifcat \relax #1\expandafter\BNE_gobz_scanint_hit_cs\fi
    \ifnum\xint_c_x<1\string#1 \else\expandafter\BNE_gobz_scanint_next\fi
    #1\BNE_scanint_again
}%
\def\BNE_gobz_scanint_again #1%
{%
    \expandafter\BNE_gobz_scanint_main\romannumeral`&&@#1%
}%
\def\BNE_gobz_scanint_hit_cs\ifnum#1\fi#2\BNE_scanint_again
{%
    0\iffalse{{{\fi}}\expandafter}\romannumeral`&&@\BNE_getop#2%
}%
\def\BNE_gobz_scanint_next #1\BNE_scanint_again
{%
    \if    _#1\xint_dothis\BNE_gobz_scanint_again\fi
    \if    0#1\xint_dothis\BNE_gobz_scanint_again\fi
    \xint_orthat
    {0\iffalse{{{\fi}}\expandafter}\romannumeral`&&@\BNE_getop#1}%
}%
\def\BNE_hex_in #1.%
{%
    \expanded{{{\xintHexToDec{#1}}}\expandafter}\romannumeral`&&@\BNE_getop
}%
\def\BNE_scanhex #1% #1="
{%
    \expandafter\BNE_hex_in\expanded\bgroup\BNE_scanhex_a
}%
\def\BNE_scanhex_a #1%
{%
    \ifcat #1\relax\xint_dothis{.\iffalse{\fi}#1}\fi
    \xint_orthat {\BNE_scanhex_aa #1}%
}%
\def\BNE_scanhex_aa #1%
{%
    \if\ifnum`#1>`/
       \ifnum`#1>`9
       \ifnum`#1>`@
       \ifnum`#1>`F
       0\else1\fi\else0\fi\else1\fi\else0\fi 1%
       \expandafter\BNE_scanhex_b
    \else
       \if _#1\xint_dothis{\expandafter\BNE_scanhex_bgob}\fi
       \xint_orthat {\xint_afterfi {.\iffalse{\fi}}}%
    \fi
    #1%
}%
\def\BNE_scanhex_b #1#2%
{%
    #1\expandafter\BNE_scanhex_a\romannumeral`&&@#2%
}%
\def\BNE_scanhex_bgob #1#2%
{%
    \expandafter\BNE_scanhex_a\romannumeral`&&@#2%
}%
%    \end{macrocode}
% \subsection{\csh{BNE_getop}}
%    \begin{macrocode}
\def\BNE_getop #1%
{%
    \expandafter\BNE_getop_a\romannumeral`&&@#1%
}%
\catcode`* 11
\def\BNE_getop_a #1%
{%
    \ifx   \relax #1\xint_dothis\xint_firstofthree\fi
    \ifcat \relax #1\xint_dothis\xint_secondofthree\fi
    \ifnum\xint_c_ix<1\string#1 \xint_dothis\xint_secondofthree\fi
    \if    (#1\xint_dothis      \xint_secondofthree\fi %)
    \xint_orthat \xint_thirdofthree
    {\BNE_foundend}%
    {\BNE_precedence_*** *#1}%
    {\expandafter\BNE_scanop_a \string#1}%
}%
\catcode`* 12
\def\BNE_foundend {\xint_c_ \relax}%
\def\BNE_scanop_a #1#2%
{%
    \expandafter\BNE_scanop_b\expandafter#1\romannumeral`&&@#2%
}%
\def\BNE_scanop_b #1#2%
{%
    \ifcat#2\relax\xint_dothis{\BNE_foundop_a #1#2}\fi
    \ifcsname BNE_itself_#1#2\endcsname
    \xint_dothis
        {\expandafter\BNE_scanop_c\csname BNE_itself_#1#2\endcsname}\fi
    \xint_orthat {\BNE_foundop_a #1#2}%
}%
\def\BNE_scanop_c #1#2%
{%
    \expandafter\BNE_scanop_d\expandafter#1\romannumeral`&&@#2%
}%
\def\BNE_scanop_d #1#2%
{%
  \ifcat#2\relax \xint_dothis{\BNE_foundop #1#2}\fi
  \ifcsname BNE_itself_#1#2\endcsname
  \xint_dothis
        {\expandafter\BNE_scanop_c\csname BNE_itself_#1#2\endcsname }\fi
  \xint_orthat {\csname BNE_precedence_#1\endcsname #1#2}%
}%
\def\BNE_foundop_a #1%
{%
    \ifcsname BNE_precedence_#1\endcsname
        \csname BNE_precedence_#1\expandafter\endcsname
        \expandafter #1%
    \else
        \xint_afterfi{\BNE_getop\romannumeral0%
        \XINT_expandableerror
        {"#1" is unknown as operator. (I)nsert one:} }%<<deliberate space
    \fi
}%
\def\BNE_foundop #1{\csname BNE_precedence_#1\endcsname #1}%
%    \end{macrocode}
% \subsection{Expansion spanning; opening and closing parentheses}
%    \begin{macrocode}
\def\BNE_tmpa #1#2#3#4#5%
{%
    \def#1% start
    {%
        \expandafter#2\romannumeral`&&@\BNE_getnext
    }%
    \def#2##1% check
    {%
        \xint_UDsignfork
          ##1{\expandafter#3\romannumeral`&&@#4}%
            -{#3##1}%
        \krof
    }%
    \def#3##1##2% checkp
    {%
        \ifcase ##1%
           \expandafter\BNE_done
        \or\expandafter#5%
        \else
           \expandafter#3\romannumeral`&&@\csname BNE_op_##2\expandafter\endcsname
        \fi
    }%
    \def#5%
    {%
        \XINT_expandableerror
        {An extra ) has been removed. Hit Return, fingers crossed.}%
        \expandafter#2\romannumeral`&&@\expandafter\BNE_put_op_first
        \romannumeral`&&@\BNE_getop_legacy
    }%
}%
\let\BNE_done\space
\def\BNE_getop_legacy #1%
{%
    \expanded{\unexpanded{{#1}}\expandafter}\romannumeral`&&@\BNE_getop
}%
\expandafter\BNE_tmpa
    \csname BNE_start\expandafter\endcsname
    \csname BNE_check\expandafter\endcsname
    \csname BNE_checkp\expandafter\endcsname
    \csname BNE_op_-xii\expandafter\endcsname
    \csname BNE_extra_)\endcsname
\catcode`) 11
\def\BNE_tmpa #1#2#3#4#5#6%
{%
    \def #1##1% op_(
    {%
        \expandafter #4\romannumeral`&&@\BNE_getnext
    }%
    \def #2##1% op_)
    {%
        \expanded{\unexpanded{\BNE_put_op_first{##1}}\expandafter}\romannumeral`&&@\BNE_getop
    }%
    \def #3% oparen
    {%
        \expandafter #4\romannumeral`&&@\BNE_getnext
    }%
    \def #4##1% check-
    {%
        \xint_UDsignfork
            ##1{\expandafter#5\romannumeral`&&@#6}%
              -{#5##1}%
        \krof
    }%
    \def #5##1##2% checkp
    {%
        \ifcase ##1\expandafter\BNE_missing_)
        \or \csname BNE_op_##2\expandafter\endcsname
        \else
          \expandafter #5\romannumeral`&&@\csname BNE_op_##2\expandafter\endcsname
        \fi
    }%
}%
\expandafter\BNE_tmpa
    \csname BNE_op_(\expandafter\endcsname
    \csname BNE_op_)\expandafter\endcsname
    \csname BNE_oparen\expandafter\endcsname
    \csname BNE_check-_)\expandafter\endcsname
    \csname BNE_checkp_)\expandafter\endcsname
    \csname BNE_op_-xii\endcsname
\let\BNE_precedence_)\xint_c_i
\def\BNE_missing_) 
   {\XINT_expandableerror{Sorry to report a missing ) at the end of this journey.}%
    \xint_c_ \BNE_done }%
\catcode`) 12
%    \end{macrocode}
% \subsection{The comma as binary operator}
% At |1.4|, it is simply a union operator for 1D oples. Inserting directly
% here a |<space><comma>| separator (as in earlier releases) in accumulated
% result would avoid having to do it on output but to the cost of diverging
% from \xintexprname upstream code, and to have to let the |\evaltohex| output
% routine handle comma separated values rather than braced values.
%    \begin{macrocode}
\def\BNE_tmpa #1#2#3#4#5%
{%
    \def #1##1% \BNE_op_,
    {%
      \expanded{\unexpanded{#2{##1}}\expandafter}%
      \romannumeral`&&@\expandafter#3\romannumeral`&&@\BNE_getnext
    }%
    \def #2##1##2##3##4{##2##3{##1##4}}% \BNE_exec_,
    \def #3##1% \BNE_check-_,
    {%
      \xint_UDsignfork
        ##1{\expandafter#4\romannumeral`&&@#5}%
          -{#4##1}%
      \krof
    }%
    \def #4##1##2% \BNE_checkp_,
    {%
      \ifnum ##1>\xint_c_iii
        \expandafter#4%
           \romannumeral`&&@\csname BNE_op_##2\expandafter\endcsname
      \else
        \expandafter##1\expandafter##2%
      \fi
    }%
}%
\expandafter\BNE_tmpa
    \csname BNE_op_,\expandafter\endcsname
    \csname BNE_exec_,\expandafter\endcsname
    \csname BNE_check-_,\expandafter\endcsname
    \csname BNE_checkp_,\expandafter\endcsname
    \csname BNE_op_-xii\endcsname
\expandafter\let\csname BNE_precedence_,\endcsname\xint_c_iii
%    \end{macrocode}
% \subsection{The minus as prefix operator of variable precedence level}
% This |\BNE_Op_opp| causes trouble as at |1.4| it must be f-expandable,
% whereas earlier it expanded inside |\csname...\endcsname| context, so I
% could define it as {\catcode`\#12 |\if-#1\else\if0#10\else-#1\fi\fi|} where
% {\catcode`\#12 |#1|} was the
% first token of unbraced argument but this meant at |1.4| an added
% |\xint_firstofone| here. Well let's return to sanity at |1.4a| and not add
% the |\xint_firstofone| and simply default |\BNE_Op_opp| to |\xintiiOpp|,
% which it should have been all along! And on this occasion let's trim user
% documentation of irrelevant complications.
%    \begin{macrocode}
\def\BNE_tmpb #1#2#3#4#5%
{%
    \def #1% \BNE_op_-<level>
    {%
      \expandafter #2\romannumeral`&&@\expandafter#3%
      \romannumeral`&&@\BNE_getnext
    }%
    \def #2##1##2##3% \BNE_exec_-<level>
    {%
      \expandafter ##1\expandafter ##2\expandafter
       {\expandafter{\romannumeral`&&@\BNE_Op_opp##3}}%
    }%
    \def #3##1% \BNE_check-_-<level>
    {%
      \xint_UDsignfork
        ##1{\expandafter #4\romannumeral`&&@#1}%
          -{#4##1}%
      \krof
    }%
    \def #4##1##2% \BNE_checkp_-<level>
    {%
      \ifnum ##1>#5%
        \expandafter #4%
        \romannumeral`&&@\csname BNE_op_##2\expandafter\endcsname
      \else
        \expandafter ##1\expandafter ##2%
      \fi
    }%
}%
\def\BNE_tmpa #1%
{%
\expandafter\BNE_tmpb
    \csname BNE_op_-#1\expandafter\endcsname
    \csname BNE_exec_-#1\expandafter\endcsname
    \csname BNE_check-_-#1\expandafter\endcsname
    \csname BNE_checkp_-#1\expandafter\endcsname
    \csname xint_c_#1\endcsname
}%
\BNE_tmpa {xii}%
\BNE_tmpa {xiv}%
\BNE_tmpa {xvi}%
\BNE_tmpa {xviii}%
%    \end{macrocode}
% \subsection{The infix operators.}
% I could have at the |1.4| refactoring injected usage of |\expanded| here,
% but kept in sync with upstream \xintexprname code.
%
% Macro names are somewhat bad and there is much risk of confusion in future
% maintenance of |\BNE_Op_| prefix (used for |\BNE_Op_add| etc...; besides
% this should have been |\BNE_Op_Add|) and |\BNE_op_| prefix (used for
% {\catcode`+ 11 |\BNE_op_+|} etc...).
%    \begin{macrocode}
\def\BNE_defbin_c #1#2#3#4#5#6#7%
{%
  \def #1##1% \BNE_op_<op>
  {%
    \expanded{\unexpanded{#2{##1}}\expandafter}%
    \romannumeral`&&@\expandafter#3\romannumeral`&&@\BNE_getnext
  }%
  \def #2##1##2##3##4% \BNE_exec_<op>
  {%
    \expandafter##2\expandafter##3\expandafter
      {\expandafter{\romannumeral`&&@#6##1##4}}%
  }%
  \def #3##1% \BNE_check-_<op>
  {%
    \xint_UDsignfork
      ##1{\expandafter#4\romannumeral`&&@#5}%
        -{#4##1}%
    \krof
  }%
  \def #4##1##2% \BNE_checkp_<op>
  {%
    \ifnum ##1>#7%
      \expandafter#4%
      \romannumeral`&&@\csname BNE_op_##2\expandafter\endcsname
    \else 
      \expandafter ##1\expandafter ##2%
    \fi
  }%
}%
\def\BNE_defbin_b #1#2#3#4%
{%
  \expandafter\BNE_defbin_c
  \csname BNE_op_#1\expandafter\endcsname
  \csname BNE_exec_#1\expandafter\endcsname
  \csname BNE_check-_#1\expandafter\endcsname
  \csname BNE_checkp_#1\expandafter\endcsname
  \csname BNE_op_-#3\expandafter\endcsname
  \csname #4\expandafter\endcsname
  \csname BNE_precedence_#1\endcsname
  \expandafter
  \let\csname BNE_precedence_#1\expandafter\endcsname
      \csname xint_c_#2\endcsname
}%
\BNE_defbin_b {//} {xiv}{xiv}{BNE_Op_div}%
\BNE_defbin_b {/:} {xiv}{xiv}{BNE_Op_mod}%
\BNE_defbin_b  +   {xii}{xii}{BNE_Op_add}%
\BNE_defbin_b  -   {xii}{xii}{BNE_Op_sub}%
\BNE_defbin_b  *   {xiv}{xiv}{BNE_Op_mul}%
\BNE_defbin_b  /   {xiv}{xiv}{BNE_Op_divround}%
\BNE_defbin_b  ^   {xviii}{xviii}{BNE_Op_pow}%
\expandafter\def\csname BNE_itself_**\endcsname {^}%
\expandafter\def\csname BNE_itself_//\endcsname {//}%
\expandafter\def\csname BNE_itself_/:\endcsname {/:}%
\expandafter\let\csname BNE_precedence_***\endcsname \xint_c_xvi
%    \end{macrocode}
% \subsection{! as postfix factorial operator}
% This one uses |\expanded|.
%    \begin{macrocode}
\catcode`! 11
\let\BNE_precedence_! \xint_c_xx
\def\BNE_op_! #1%
{%
    \expandafter\BNE_put_op_first
    \expanded{{{\BNE_Op_fac#1}}\expandafter}\romannumeral`&&@\BNE_getop
}%
%    \end{macrocode}
% \subsection{Cleanup}
%    \begin{macrocode}
\let\BNEtmpa\relax \let\BNE_tmpa\relax \let\BNE_tmpb\relax \let\BNE_tmpc\relax
\BNErestorecatcodes%
%    \end{macrocode}
% \MakePercentComment
%</package>
%<*dtx>
\DeleteShortVerb{\|}%
\CheckSum {947}%
\makeatletter\check@checksum\makeatother%
\Finale%
%% End of file xint.dtx