| 1 |
% -*- coding: utf-8; time-stamp-format: "%02d-%02m-%:y at %02H:%02M:%02S %Z" -*- |
| 2 |
% This file: xint.dtx. Proudly produced by xint-dtxbuild.sh. |
| 3 |
% Run etex on this file to extract all xint*sty files. |
| 4 |
%<*dtx> |
| 5 |
\def\xintdtxtimestamp {Time-stamp: <07-09-2025 at 00:47:30 CEST>} |
| 6 |
%</dtx> |
| 7 |
% |
| 8 |
% To build xint.pdf (with both user manual and commented source code), |
| 9 |
% the recommended way is: |
| 10 |
% |
| 11 |
% - step 1: etex xint.dtx (stop here if you only need the xint*sty files) |
| 12 |
% - step 2: make --file=Makefile.mk xint.pdf |
| 13 |
% |
| 14 |
% The above step 2 requires make + latexmk and uses latex + dvipdfmx. |
| 15 |
% |
| 16 |
% Other make targets are |
| 17 |
% - xintmanual.pdf (contains only the user documentation) |
| 18 |
% - xintsource.pdf (contains only the commented source code) |
| 19 |
% |
| 20 |
% Alternative for building xint.pdf (and extracting the xint*sty files): |
| 21 |
% |
| 22 |
% Direct runs of pdflatex, xelatex or lualatex on xint.dtx, |
| 23 |
% or (better) of latexmk -pdf (or -pdfxe, -pdflua) on xint.dtx. |
| 24 |
% |
| 25 |
% (if using xelatex, it must be with -8bit option for extracted Makefile.mk |
| 26 |
% to be valid, but this has no impact on the xint*sty files and xint.pdf). |
| 27 |
% |
| 28 |
%<*xintmandrv|xintsrcdrv|xintalldrv> |
| 29 |
%% --------------------------------------------------------------- |
| 30 |
\def\xintdocdate {2025/09/06} |
| 31 |
\def\xintbndldate{2025/09/06} |
| 32 |
\def\xintbndlversion {1.4o} |
| 33 |
%</xintmandrv|xintsrcdrv|xintalldrv> |
| 34 |
%<readme>% README |
| 35 |
%<readme>% xint 1.4o |
| 36 |
%<readme>% 2025/09/06 |
| 37 |
%<readme> |
| 38 |
%<readme> Source: xint.dtx 1.4o 2025/09/06 (doc 2025/09/06) |
| 39 |
%<readme> Author: Jean-François Burnol |
| 40 |
%<readme> Info: Expandable operations on big integers, decimals, fractions |
| 41 |
%<readme> License: LPPL 1.3c |
| 42 |
%<readme> |
| 43 |
%<*!readme&!makefile> |
| 44 |
%% --------------------------------------------------------------- |
| 45 |
%% The xint bundle 1.4o 2025/09/06 |
| 46 |
%% Copyright (C) 2013-2022, 2025 Jean-Francois Burnol |
| 47 |
%<xintkernel>%% xintkernel: Paraphernalia for the xint packages |
| 48 |
%<xinttools>%% xinttools: Expandable and non-expandable utilities |
| 49 |
%<xintcore>%% xintcore: Expandable arithmetic on big integers |
| 50 |
%<xint>%% xint: Expandable operations on big integers |
| 51 |
%<xintfrac>%% xintfrac: Expandable operations on fractions |
| 52 |
%<xintexpr>%% xintexpr: Expandable expression parser |
| 53 |
%<xintbinhex>%% xintbinhex: Expandable radix conversions (2, 8, 10, and 16) |
| 54 |
%<xintgcd>%% xintgcd: Euclidean algorithm with xint package |
| 55 |
%<xintseries>%% xintseries: Expandable partial sums with xint package |
| 56 |
%<xintcfrac>%% xintcfrac: Expandable continued fractions with xint package |
| 57 |
%<xinttrig>%% xinttrig: Trigonometry for the xintexpr package |
| 58 |
%<xintlog>%% xintlog: Logarithms and exponentials for xintexpr |
| 59 |
%% --------------------------------------------------------------- |
| 60 |
%</!readme&!makefile> |
| 61 |
%<*dtx> |
| 62 |
\bgroup\catcode2 0 \catcode`\\ 12 ^^Biffalse |
| 63 |
%</dtx> |
| 64 |
%<*readme>-------------------------------------------------------- |
| 65 |
|
| 66 |
Description |
| 67 |
=========== |
| 68 |
|
| 69 |
The main functionality is `\xintfloateval` which parses expressions |
| 70 |
involving floating point numbers, functions, variables and other syntax |
| 71 |
elements. |
| 72 |
|
| 73 |
The precision defaults to `16` decimal digits. The logarithm, |
| 74 |
exponential, direct and inverse trigonometric functions are supported up |
| 75 |
to `62` digits. The four basic operations and square-root extraction |
| 76 |
are implemented with correct rounding up to thousands of digits (roughly |
| 77 |
up to a maximum of 26000 digits for the output). |
| 78 |
|
| 79 |
A variant `\xinteval` computes with fractions. And `\xintiieval` |
| 80 |
handles only (arbitarily large) integers. |
| 81 |
|
| 82 |
All three parsers obtain their result purely expandably. They handle |
| 83 |
comma separated inputs and nested structures using square brackets. The |
| 84 |
user can declare custom variables and functions. |
| 85 |
|
| 86 |
Usage |
| 87 |
===== |
| 88 |
|
| 89 |
The way of loading `xintexpr` depends on whether you are using |
| 90 |
`LaTeX` or not. |
| 91 |
|
| 92 |
- with `LaTeX`, add `\usepackage{xintexpr}` to the document preamble, |
| 93 |
- else, do `\input xintexpr.sty` and compile with either one of `etex`, |
| 94 |
`pdftex`, `xetex`, `luatex` (they all default to the `Plain TeX` |
| 95 |
format), or with `optex` (i.e. `luatex` with `OpTeX` format), |
| 96 |
or with `context` (`luametatex` engine). |
| 97 |
|
| 98 |
Example |
| 99 |
======= |
| 100 |
|
| 101 |
Here is an example typical of the `xintexpr` users morning routine since |
| 102 |
many years (`xintexpr` was first released in 2013): |
| 103 |
|
| 104 |
\xinteval{reduce(add(1/i^3, i=1..25))} |
| 105 |
|
| 106 |
It expands (in two steps) to: |
| 107 |
|
| 108 |
2560976152652211536408111110189/2131858131361319942957376000000 |
| 109 |
|
| 110 |
Repository |
| 111 |
========== |
| 112 |
|
| 113 |
It is at https://github.com/jfbu/xint and the issue tracker |
| 114 |
is at https://github.com/jfbu/xint/issues. |
| 115 |
|
| 116 |
Documentation |
| 117 |
============= |
| 118 |
|
| 119 |
Both the user manual and the commented source code are in `xint.pdf`. |
| 120 |
|
| 121 |
A file `CHANGES.html` is provided at https://jfbu.github.io/xint. Its |
| 122 |
source `xintchanges.md` is part of the CTAN upload, and you |
| 123 |
can access it in TeXLive using `texdoc xintchanges.md`. |
| 124 |
|
| 125 |
License |
| 126 |
======= |
| 127 |
|
| 128 |
Copyright © 2013-2022, 2025 Jean-François Burnol |
| 129 |
|
| 130 |
This Work may be distributed and/or modified under the |
| 131 |
conditions of the LaTeX Project Public License version 1.3c. |
| 132 |
This version of this license is in |
| 133 |
|
| 134 |
> <http://www.latex-project.org/lppl/lppl-1-3c.txt> |
| 135 |
|
| 136 |
and version 1.3 or later is part of all distributions of |
| 137 |
LaTeX version 2005/12/01 or later. |
| 138 |
|
| 139 |
This Work has the LPPL maintenance status *author-maintained*. |
| 140 |
|
| 141 |
The Author of this Work is Jean-François Burnol. |
| 142 |
|
| 143 |
This Work consists of the file `xint.dtx` and `README.md` and their |
| 144 |
derived files such as `xint.pdf`. |
| 145 |
%</readme>-------------------------------------------------------- |
| 146 |
%<*dates>------------------------------------------------------- |
| 147 |
`1.4o (2025/09/06)` |
| 148 |
`1.4n (2025/09/05)` |
| 149 |
`1.4m (2022/06/10)` |
| 150 |
`1.4l (2022/05/29)` |
| 151 |
`1.4k (2022/05/18)` |
| 152 |
`1.4j (2021/07/13)` |
| 153 |
`1.4i (2021/06/11)` |
| 154 |
`1.4h (2021/05/27)` |
| 155 |
`1.4g (2021/05/25)` |
| 156 |
`1.4f (2021/05/10)` |
| 157 |
`1.4e (2021/05/05)` |
| 158 |
`1.4d (2021/03/29)` |
| 159 |
`1.4c (2021/02/20)` |
| 160 |
`1.4b (2020/02/25)` |
| 161 |
`1.4a (2020/02/19)` |
| 162 |
`1.4 (2020/01/31)` |
| 163 |
`1.3f (2019/09/10)` |
| 164 |
`1.3e (2019/04/05)` |
| 165 |
`1.3d (2019/01/06)` |
| 166 |
`1.3c (2018/06/17)` |
| 167 |
`1.3b (2018/05/18)` |
| 168 |
`1.3a (2018/03/07)` |
| 169 |
`1.3 (2018/03/01)` |
| 170 |
`1.2q (2018/02/06)` |
| 171 |
`1.2p (2017/12/05)` |
| 172 |
`1.2o (2017/08/29)` |
| 173 |
`1.2n (2017/08/06)` |
| 174 |
`1.2m (2017/07/31)` |
| 175 |
`1.2l (2017/07/26)` |
| 176 |
`1.2k (2017/01/06)` |
| 177 |
`1.2j (2016/12/22)` |
| 178 |
`1.2i (2016/12/13)` |
| 179 |
`1.2h (2016/11/20)` |
| 180 |
`1.2g (2016/03/19)` |
| 181 |
`1.2f (2016/03/12)` |
| 182 |
`1.2e (2015/11/22)` |
| 183 |
`1.2d (2015/11/18)` |
| 184 |
`1.2c (2015/11/16)` |
| 185 |
`1.2b (2015/10/29)` |
| 186 |
`1.2a (2015/10/19)` |
| 187 |
`1.2 (2015/10/10)` |
| 188 |
`1.1c (2015/09/12)` |
| 189 |
`1.1b (2015/08/31)` |
| 190 |
`1.1a (2014/11/07)` |
| 191 |
`1.1 (2014/10/28)` |
| 192 |
`1.09n (2014/04/01)` |
| 193 |
`1.09m (2014/02/26)` |
| 194 |
`1.09kb (2014/02/13)` |
| 195 |
`1.09k (2014/01/21)` |
| 196 |
`1.09j (2014/01/09)` |
| 197 |
`1.09i (2013/12/18)` |
| 198 |
`1.09h (2013/11/28)` |
| 199 |
`1.09g (2013/11/22)` |
| 200 |
`1.09f (2013/11/04)` |
| 201 |
`1.09e (2013/10/29)` |
| 202 |
`1.09d (2013/10/22)` |
| 203 |
`1.09c (2013/10/09)` |
| 204 |
`1.09b (2013/10/03)` |
| 205 |
`1.09a (2013/09/24)` |
| 206 |
`1.08b (2013/06/14)` |
| 207 |
`1.08a (2013/06/11)` |
| 208 |
`1.08 (2013/06/07)` |
| 209 |
`1.07 (2013/05/25)` |
| 210 |
`1.06b (2013/05/14)` |
| 211 |
`1.06 (2013/05/07)` |
| 212 |
`1.05 (2013/05/01)` |
| 213 |
`1.04 (2013/04/25)` |
| 214 |
`1.03 (2013/04/14)` |
| 215 |
`1.0 (2013/03/28)` |
| 216 |
%</dates>------------------------------------------------------ |
| 217 |
%<*makefile>------------------------------------------------------ |
| 218 |
# This file: Makefile.mk (generated from xint.dtx) |
| 219 |
# "make --file=Makefile.mk help" |
| 220 |
|
| 221 |
# The 1.4n CTAN zip includes an xintchanges.md but no CHANGES.html |
| 222 |
# anymore. The xintchanges.md is not extracted from the dtx but |
| 223 |
# kept separate. |
| 224 |
|
| 225 |
# The 1.4n CTAN zip does not ship with a commodity Makefile anymore, |
| 226 |
# use -f Makefile.mk as above or rename it to Makefile. |
| 227 |
# Also it does not include CHANGES.html. It can be build via make |
| 228 |
# or checked at https://jfbu.github.io/xint/CHANGES.html. |
| 229 |
|
| 230 |
# With 1.4n also, sourcexint.pdf got renamed into xintsource.pdf |
| 231 |
# and xint.pdf became what was called xint-all.pdf, i.e. (as was also |
| 232 |
# the case originally) it contains both user manual and documented |
| 233 |
# source code. This allows to benefit from hyperlinks between the two, |
| 234 |
# which were added already in 2022. |
| 235 |
|
| 236 |
# Starting with xint 1.3c, Latexmk is used for easier compilation of |
| 237 |
# sourcexint.pdf as the latter then included indices. These indices |
| 238 |
# got removed at 1.3e but usage of Latexmk is maintained for the build. |
| 239 |
|
| 240 |
# Originally tested on Mac OS X Mavericks with GNU Make 3.81, |
| 241 |
# TeXLive 2014 and Pandoc 1.13.1. |
| 242 |
|
| 243 |
# Note to myself: I wanted to use .RECIPEPREFIX = > but it is |
| 244 |
# supported only with GNU Make 3.82 and later. |
| 245 |
|
| 246 |
# this crazyness is to circumvent a problem with docstrip generation |
| 247 |
# of the Makefile; we do not want two empty lines becoming only one |
| 248 |
nullstring := |
| 249 |
define newline |
| 250 |
$(nullstring) |
| 251 |
|
| 252 |
endef |
| 253 |
# will speed-up a little, I think. |
| 254 |
newline := $(newline) |
| 255 |
|
| 256 |
define helptext |
| 257 |
==== INSTRUCTIONS |
| 258 |
|
| 259 |
It is recommended to work with xint.dtx and Makefile moved to some |
| 260 |
otherwise empty temporary repertory. |
| 261 |
|
| 262 |
make help |
| 263 |
Display this help using the more pager. |
| 264 |
|
| 265 |
make helpless |
| 266 |
Display this help using the less pager. |
| 267 |
|
| 268 |
make doc |
| 269 |
Produce all documentation, requires Latexmk and Pandoc. |
| 270 |
|
| 271 |
make all |
| 272 |
Produce all documentation, then creates xint.tds.zip. |
| 273 |
|
| 274 |
make xint.tds.zip |
| 275 |
Same as "make all" |
| 276 |
|
| 277 |
make xintmanual.pdf |
| 278 |
Extract files and produce xintmanual.pdf (user manual), |
| 279 |
using latex and dvipdfmx. This requires Latexmk. |
| 280 |
|
| 281 |
make xintsource.pdf |
| 282 |
Extract files and produce xintsource.pdf (source code), |
| 283 |
using latex and dvipdfmx. This requires Latexmk. |
| 284 |
|
| 285 |
make xint.pdf |
| 286 |
Extract files and produce xint.pdf (manual + code), |
| 287 |
using latex and dvipdfmx. This requires Latexmk. |
| 288 |
|
| 289 |
make CHANGES.html |
| 290 |
This requires Pandoc. |
| 291 |
|
| 292 |
make clean |
| 293 |
Remove auxiliary files and repertories. |
| 294 |
|
| 295 |
make cleanmore |
| 296 |
Remove also PDFs and ZIP archives and a few more. |
| 297 |
|
| 298 |
==== INSTALLING |
| 299 |
|
| 300 |
The following has been tested on a TeXLive installation: |
| 301 |
|
| 302 |
make installhome |
| 303 |
Create xint.tds.zip, and unzip it in <TEXMFHOME> |
| 304 |
|
| 305 |
make installlocal |
| 306 |
Create xint.tds.zip, unzip it in <TEXMFLOCAL> |
| 307 |
and then does texhash <TEXMFLOCAL> |
| 308 |
|
| 309 |
Depending on access rights "sudo make installlocal" |
| 310 |
might be needed. In case of doubt run first "make doc" |
| 311 |
then "make installlocal". If the latter fails, then |
| 312 |
try "sudo make installlocal". |
| 313 |
|
| 314 |
make uninstallhome |
| 315 |
Remove all xint files and repertories from <TEXMFHOME> |
| 316 |
|
| 317 |
make uninstalllocal |
| 318 |
Remove all xint files and repertories from <TEXMFLOCAL> |
| 319 |
and then does texhash <TEXMFLOCAL> |
| 320 |
|
| 321 |
Might need "sudo". |
| 322 |
|
| 323 |
endef |
| 324 |
|
| 325 |
# Quelques difficultés à trouver le bon choix de ' ou " et de \# |
| 326 |
# et l'utilisation des \ en fins de ligne pour que ça fonctionne. |
| 327 |
highlighting-css = ' body{margin: 0; margin-left : 10%; margin-right : 15%; margin-top: 4ex; font-size: 20px; font-family: serif; max-width: 100%; padding: 0; }\ |
| 328 |
pre {white-space: pre-wrap;}\ |
| 329 |
code {white-space: pre-wrap;}\ |
| 330 |
a:link { color: blue; }\ |
| 331 |
a:visited { color: green; }\ |
| 332 |
a:hover { text-decoration: underline; color: hotpink }\ |
| 333 |
a:active { color: brown; }\ |
| 334 |
\#TOC {float: right; position: relative; top: 100px; margin-bottom: 100px; margin-left: 20px;}' |
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
.PHONY: help helpless all doc clean cleanmore\ |
| 339 |
installhome uninstallhome installlocal uninstalllocal |
| 340 |
|
| 341 |
# for printf with subst and \n, got it from |
| 342 |
# http://stackoverflow.com/a/5887751 |
| 343 |
|
| 344 |
# I could do the trick with := here, for \n substitution, but this would add |
| 345 |
# tiny overhead to all other operations of make |
| 346 |
|
| 347 |
help: |
| 348 |
@printf '$(subst $(newline),\n,$(helptext))' | more |
| 349 |
|
| 350 |
helpless: |
| 351 |
@printf '$(subst $(newline),\n,$(helptext))' | less |
| 352 |
|
| 353 |
# RM = rm -f |
| 354 |
JF_tmpdir := $(shell mktemp -d TEMP_XINT_XXX) |
| 355 |
TEXMF_local = $(shell kpsewhich -var-value TEXMFLOCAL) |
| 356 |
TEXMF_home = $(shell kpsewhich -var-value TEXMFHOME) |
| 357 |
packages = xintkernel.sty xintcore.sty xint.sty xintfrac.sty xintexpr.sty\ |
| 358 |
xintgcd.sty xintbinhex.sty xintseries.sty xintcfrac.sty\ |
| 359 |
xinttools.sty xinttrig.sty xintlog.sty |
| 360 |
# Makefile.mk n'est pas mis dans $(extrated) pour éviter des messages |
| 361 |
# de make. Les sty (aussi extraits) sont dans $(packages). |
| 362 |
extracted = xintmanual.tex xintsource.tex xint.tex\ |
| 363 |
README.md xint-dates.txt |
| 364 |
filesfortex = $(packages) |
| 365 |
filesforsource = xint.dtx |
| 366 |
filesfordoc = xint.pdf README.md xintchanges.md |
| 367 |
auxiliaryfiles = xintmanual.dvi xintmanual.aux xintmanual.toc xintmanual.log\ |
| 368 |
xintsource.dvi xintsource.aux xintsource.toc xintsource.log\ |
| 369 |
xint.dvi xint.aux xint.toc xint.log |
| 370 |
|
| 371 |
all: $(packages) $(extracted) doc xint.tds.zip |
| 372 |
@echo 'make all done.' |
| 373 |
|
| 374 |
$(packages): xint.dtx |
| 375 |
etex xint.dtx |
| 376 |
|
| 377 |
$(extracted): xint.dtx |
| 378 |
etex xint.dtx |
| 379 |
|
| 380 |
doc: xintmanual.pdf xintsource.pdf CHANGES.html |
| 381 |
@echo 'make doc done.' |
| 382 |
|
| 383 |
xintmanual.pdf: xint.dtx xintmanual.tex |
| 384 |
latexmk xintmanual.tex |
| 385 |
dvipdfmx xintmanual.dvi |
| 386 |
|
| 387 |
xintsource.pdf: xint.dtx xintsource.tex |
| 388 |
latexmk xintsource.tex |
| 389 |
dvipdfmx xintsource.dvi |
| 390 |
|
| 391 |
xint.pdf: xint.dtx xint.tex |
| 392 |
latexmk xint.tex |
| 393 |
dvipdfmx xint.dvi |
| 394 |
|
| 395 |
CHANGES.html: xintchanges.md |
| 396 |
pandoc -o CHANGES.html -s --toc -V highlighting-css=$(highlighting-css) xintchanges.md |
| 397 |
|
| 398 |
xint.tds.zip: $(filesfordoc) $(filesforsource) $(filesfortex) |
| 399 |
rm -fr $(JF_tmpdir) |
| 400 |
mkdir -p $(JF_tmpdir)/doc/generic/xint |
| 401 |
mkdir -p $(JF_tmpdir)/source/generic/xint |
| 402 |
mkdir -p $(JF_tmpdir)/tex/generic/xint |
| 403 |
chmod -R ugo+rwx $(JF_tmpdir) |
| 404 |
cp -a $(filesfordoc) $(JF_tmpdir)/doc/generic/xint |
| 405 |
cp -a $(filesforsource) $(JF_tmpdir)/source/generic/xint |
| 406 |
cp -a $(filesfortex) $(JF_tmpdir)/tex/generic/xint |
| 407 |
cd $(JF_tmpdir); chmod -R ugo+r doc source tex |
| 408 |
umask 0022 && cd $(JF_tmpdir) &&\ |
| 409 |
zip -r xint.tds.zip doc source tex &&\ |
| 410 |
mv -f xint.tds.zip ../ |
| 411 |
rm -fr $(JF_tmpdir) |
| 412 |
@echo 'make xint.tds.zip done.' |
| 413 |
|
| 414 |
xint.zip: $(filesfordoc) $(filesforsource) $(filesfortex) xint.tds.zip |
| 415 |
mkdir -p $(JF_tmpdir)/xint |
| 416 |
chmod ugo+rwx $(JF_tmpdir)/xint |
| 417 |
cp -a $(filesfordoc) $(JF_tmpdir)/xint |
| 418 |
cp -a $(filesforsource) $(JF_tmpdir)/xint |
| 419 |
chmod -R ugo+r $(JF_tmpdir)/xint |
| 420 |
mv xint.tds.zip $(JF_tmpdir)/ |
| 421 |
umask 0022 && cd $(JF_tmpdir) && zip -r xint.zip xint.tds.zip xint |
| 422 |
mv $(JF_tmpdir)/xint.tds.zip ./ |
| 423 |
mv -f $(JF_tmpdir)/xint.zip ./ |
| 424 |
rm -fr $(JF_tmpdir) |
| 425 |
@echo 'make xint.zip done.' |
| 426 |
|
| 427 |
installhome: xint.tds.zip |
| 428 |
unzip xint.tds.zip -d $(TEXMF_home) |
| 429 |
|
| 430 |
uninstallhome: |
| 431 |
cd $(TEXMF_home) && rm -fr doc/generic/xint \ |
| 432 |
source/generic/xint \ |
| 433 |
tex/generic/xint |
| 434 |
|
| 435 |
# cf http://stackoverflow.com/a/1909390 |
| 436 |
# as kpsewhich is very slow (.5s) I want to evaluate once only. |
| 437 |
installlocal: xint.tds.zip |
| 438 |
$(eval $@_tmp := $(TEXMF_local)) |
| 439 |
unzip xint.tds.zip -d $($@_tmp) && texhash $($@_tmp) |
| 440 |
|
| 441 |
uninstalllocal: |
| 442 |
cd $(TEXMF_local) && rm -fr doc/generic/xint \ |
| 443 |
source/generic/xint \ |
| 444 |
tex/generic/xint && texhash . |
| 445 |
clean: |
| 446 |
rm -fr auto/ .auto/ TEMP*/ |
| 447 |
rm -f $(auxiliaryfiles)\ |
| 448 |
xintmanual.fls xintmanual.fdb_latexmk\ |
| 449 |
xintsource.fls xintsource.fdb_latexmk\ |
| 450 |
xint.fls xint.fdb_latexmk |
| 451 |
|
| 452 |
cleanmore: clean |
| 453 |
rm -f xintmanual.pdf xintsource.pdf xint.pdf xint.tds.zip xint.zip |
| 454 |
%</makefile>$----------------------------------------------------- |
| 455 |
%<*xintmandrv>----------------------------------------------------------- |
| 456 |
%% To extract files: |
| 457 |
%% etex xint.dtx |
| 458 |
%% |
| 459 |
%% Then execute: |
| 460 |
%% make --file=Makefile.mk xintmanual.pdf |
| 461 |
%% |
| 462 |
%% Alternative for build without `make': |
| 463 |
%% latexmk xintmanual.tex |
| 464 |
%% dvipdfmx xintmanual.dvi |
| 465 |
%% |
| 466 |
%% One can also tell latexmk to use pdflatex, lualatex or xelatex. |
| 467 |
%% Or use one of them directly enough times on xintmanual.tex. |
| 468 |
\NeedsTeXFormat{LaTeX2e} |
| 469 |
\ProvidesFile{xintmanual.tex}% |
| 470 |
[\xintbndldate\space v\xintbndlversion\space xint documentation (JFB)]% |
| 471 |
\PassOptionsToClass{a4paper,fontsize=10pt}{scrartcl} |
| 472 |
\chardef\NoSourceCode 1 |
| 473 |
\input xint.dtx |
| 474 |
%%% Local Variables: |
| 475 |
%%% mode: latex |
| 476 |
%%% TeX-PDF-from-DVI: "Dvipdfmx" |
| 477 |
%%% End: |
| 478 |
%</xintmandrv>----------------------------------------------------------- |
| 479 |
%<*xintsrcdrv>----------------------------------------------------------- |
| 480 |
%% To extract files: |
| 481 |
%% etex xint.dtx |
| 482 |
%% |
| 483 |
%% Then execute: |
| 484 |
%% make --file=Makefile.mk xintsource.pdf |
| 485 |
%% |
| 486 |
%% Alternative for build without `make': |
| 487 |
%% latexmk xintsource.tex |
| 488 |
%% dvipdfmx xintsource.dvi |
| 489 |
%% |
| 490 |
%% One can also tell latexmk to use pdflatex, lualatex or xelatex. |
| 491 |
%% Or use one of them directly enough times on xintsource.tex. |
| 492 |
\NeedsTeXFormat{LaTeX2e} |
| 493 |
\ProvidesFile{xintsource.tex}% |
| 494 |
[\xintbndldate\space v\xintbndlversion\space xint commented code (JFB)]% |
| 495 |
\PassOptionsToClass{a4paper,fontsize=10pt}{scrartcl} |
| 496 |
\chardef\NoSourceCode=0\chardef\doxintsource=1 |
| 497 |
\input xint.dtx |
| 498 |
%%% Local Variables: |
| 499 |
%%% mode: latex |
| 500 |
%%% TeX-PDF-from-DVI: "Dvipdfmx" |
| 501 |
%%% End: |
| 502 |
%</xintsrcdrv>----------------------------------------------------------- |
| 503 |
%<*xintalldrv>----------------------------------------------------------- |
| 504 |
%% To extract files: (but this is probably already done as you read this) |
| 505 |
%% etex xint.dtx |
| 506 |
%% |
| 507 |
%% Then execute: |
| 508 |
%% make --file=Makefile.mk xint.pdf |
| 509 |
%% to obtain a PDF containing both user manual and source code. |
| 510 |
%% |
| 511 |
%% Alternative for build without `make': |
| 512 |
%% |
| 513 |
%% latexmk xint.tex |
| 514 |
%% dvipdfmx xint.dvi |
| 515 |
%% |
| 516 |
%% One can also use pdflatex/lualatex/xelatex directly on xint.tex, |
| 517 |
%% (or better latexmk with suitable engine option). |
| 518 |
\NeedsTeXFormat{LaTeX2e} |
| 519 |
\ProvidesFile{xint.tex}% |
| 520 |
[\xintbndldate\space v\xintbndlversion\space xint user plus source doc (JFB)]% |
| 521 |
\PassOptionsToClass{a4paper,fontsize=10pt}{scrartcl} |
| 522 |
\chardef\NoSourceCode=0 |
| 523 |
\input xint.dtx |
| 524 |
%%% Local Variables: |
| 525 |
%%% mode: latex |
| 526 |
%%% TeX-PDF-from-DVI: "Dvipdfmx" |
| 527 |
%%% End: |
| 528 |
%</xintalldrv>----------------------------------------------------------- |
| 529 |
%<*dtx>----------------------------------------------------------- |
| 530 |
^^Bfi^^Begroup |
| 531 |
\chardef\noetex 0 |
| 532 |
\ifx\numexpr\undefined\chardef\noetex 1 \fi |
| 533 |
% changed 2021/05/30: do not extract files at all if not using etex |
| 534 |
\ifnum\noetex=1 \chardef\extractfiles 3 % no extract, no typeset |
| 535 |
\else |
| 536 |
\ifx\PassOptionsToClass\undefined |
| 537 |
\chardef\extractfiles 0 % no LaTeX2e: probably etex, xetex, ... on xint.dtx |
| 538 |
\else |
| 539 |
\ifx\NoSourceCode\undefined |
| 540 |
% latex/pdflatex/xelatex/lualatex on xint.dtx, we will extract all files |
| 541 |
\chardef\extractfiles 1 % 1 = extract and typeset, 2 = only typeset |
| 542 |
\chardef\NoSourceCode 0 % 0 = include source code, 1 = do not |
| 543 |
\NeedsTeXFormat{LaTeX2e}% |
| 544 |
\PassOptionsToClass{a4paper,fontsize=10pt}{scrartcl}% |
| 545 |
\else |
| 546 |
% latex/pdflatex/xelatex/lualatex on xint{manual,source,}.tex |
| 547 |
\chardef\extractfiles 2 % no extractions, but typeset |
| 548 |
\fi |
| 549 |
\ProvidesFile{xint.dtx}[bundle source (\xintbndlversion, \xintbndldate) % |
| 550 |
and documentation (\xintdocdate)]% |
| 551 |
\fi |
| 552 |
\fi |
| 553 |
\ifnum\extractfiles<2 % extract files |
| 554 |
\def\MessageDeFin{\newlinechar10 \let\Msg\message |
| 555 |
\Msg{^^J}% |
| 556 |
\Msg{********************************************************************^^J}% |
| 557 |
\Msg{*^^J}% |
| 558 |
\Msg{* To finish the installation you have to move the following^^J}% |
| 559 |
\Msg{* files into a directory searched by TeX:^^J}% |
| 560 |
\Msg{*^^J}% |
| 561 |
\Msg{* \space\space\space\space xintkernel.sty^^J}% |
| 562 |
\Msg{* \space\space\space\space xintcore.sty^^J}% |
| 563 |
\Msg{* \space\space\space\space xint.sty^^J}% |
| 564 |
\Msg{* \space\space\space\space xintbinhex.sty^^J}% |
| 565 |
\Msg{* \space\space\space\space xintgcd.sty^^J}% |
| 566 |
\Msg{* \space\space\space\space xintfrac.sty^^J}% |
| 567 |
\Msg{* \space\space\space\space xintseries.sty^^J}% |
| 568 |
\Msg{* \space\space\space\space xintcfrac.sty^^J}% |
| 569 |
\Msg{* \space\space\space\space xintexpr.sty^^J}% |
| 570 |
\Msg{* \space\space\space\space xinttools.sty^^J}% |
| 571 |
\Msg{* \space\space\space\space xinttrig.sty^^J}% |
| 572 |
\Msg{* \space\space\space\space xintlog.sty^^J}% |
| 573 |
\Msg{*^^J}% |
| 574 |
\Msg{* Rename Makefile.mk to Makefile if the latter is absent^^J}% |
| 575 |
\Msg{* (or use --file=Makefile.mk option of "make")^^J}% |
| 576 |
\Msg{* then "make xint.pdf" builds a PDF including both the user manual^^J}% |
| 577 |
\Msg{* and the commented source code.^^J}% |
| 578 |
\Msg{*^^J}% |
| 579 |
\Msg{* Building with "make" requires "Latexmk".^^J}% |
| 580 |
\Msg{* The target "CHANGES.html" requires "Pandoc".^^J}% |
| 581 |
\Msg{*^^J}% |
| 582 |
\Msg{* Instructions for building without "make" are in file xint.tex.^^J}% |
| 583 |
\Msg{*^^J}% |
| 584 |
\Msg{* Happy TeXing!^^J}% |
| 585 |
\Msg{*^^J}% |
| 586 |
\Msg{********************************************************************^^J}% |
| 587 |
}% |
| 588 |
\ifx\XeTeXinterchartoks\undefined\else |
| 589 |
\expandafter\def\expandafter\MessageDeFin\expandafter{\MessageDeFin |
| 590 |
\Msg{* ATTENTION! extraction with xetex must be made with -8bit option.^^J}% |
| 591 |
\Msg{* Extracted file Makefile.mk is invalid if this was not the case.^^J}% |
| 592 |
\Msg{********************************************************************^^J}% |
| 593 |
}% |
| 594 |
\fi |
| 595 |
\begingroup |
| 596 |
\input docstrip.tex |
| 597 |
\askforoverwritefalse |
| 598 |
\catcode9 11 % do not kill TAB in producing Makefile.mk |
| 599 |
\generate{\nopreamble\nopostamble |
| 600 |
\file{README.md}{\from{xint.dtx}{readme}} |
| 601 |
% 1.4n of September 2025 omits including (renamed) xintchanges.md in dtx |
| 602 |
\file{xint-dates.txt}{\from{xint.dtx}{dates}} |
| 603 |
% pure tex will use ^^I notation for TAB character, don't want that. |
| 604 |
% anyway, since 2021/05/30, tex xint.dtx has been made a no-op. |
| 605 |
% there is a problem with xelatex, it generates ^^I if not with -8bit |
| 606 |
\file{Makefile.mk}{\from{xint.dtx}{makefile}} |
| 607 |
\usepreamble\defaultpreamble |
| 608 |
\usepostamble\defaultpostamble |
| 609 |
\file{xintmanual.tex}{\from{xint.dtx}{xintmandrv}} |
| 610 |
\file{xintsource.tex}{\from{xint.dtx}{xintsrcdrv}} |
| 611 |
\file{xint.tex}{\from{xint.dtx}{xintalldrv}} |
| 612 |
\file{xintkernel.sty}{\from{xint.dtx}{xintkernel}} |
| 613 |
\file{xinttools.sty}{\from{xint.dtx}{xinttools}} |
| 614 |
\file{xintcore.sty}{\from{xint.dtx}{xintcore}} |
| 615 |
\file{xint.sty}{\from{xint.dtx}{xint}} |
| 616 |
\file{xintbinhex.sty}{\from{xint.dtx}{xintbinhex}} |
| 617 |
\file{xintgcd.sty}{\from{xint.dtx}{xintgcd}} |
| 618 |
\file{xintfrac.sty}{\from{xint.dtx}{xintfrac}} |
| 619 |
\file{xintseries.sty}{\from{xint.dtx}{xintseries}} |
| 620 |
\file{xintcfrac.sty}{\from{xint.dtx}{xintcfrac}} |
| 621 |
\file{xintexpr.sty}{\from{xint.dtx}{xintexpr}} |
| 622 |
\file{xinttrig.sty}{\from{xint.dtx}{xinttrig}} |
| 623 |
\file{xintlog.sty}{\from{xint.dtx}{xintlog}}} |
| 624 |
\endgroup |
| 625 |
\fi % end of file extraction (from etex/latex/pdflatex/... run on xint.dtx) |
| 626 |
\ifnum\extractfiles=0 % no LaTeX, files now extracted. Stop. |
| 627 |
\MessageDeFin\expandafter\end |
| 628 |
\fi |
| 629 |
\ifnum\extractfiles=1 % direct run on xint.dtx |
| 630 |
\expandafter\def\expandafter\MessageDeFin\expandafter{\MessageDeFin |
| 631 |
\Msg{* Direct (*)latex run on xint.dtx: repeat as necessary. *^^J}% |
| 632 |
\Msg{********************************************************************^^J}% |
| 633 |
}% |
| 634 |
\fi |
| 635 |
\ifnum\extractfiles=3 % |
| 636 |
\newlinechar10 |
| 637 |
\errhelp{Extraction must be done via an engine with e-TeX extensions.^^J% |
| 638 |
Please try again, using etex rather.^^J% |
| 639 |
(and if with xetex, you must use -8bit option).}% |
| 640 |
\errmessage{Extraction aborted (must be done with etex)}% |
| 641 |
\expandafter\end |
| 642 |
\fi |
| 643 |
% From this point on, run is necessarily with e-TeX. |
| 644 |
% Check if \MessageDeFin got defined, if yes put it at end of run. |
| 645 |
\ifdefined\MessageDeFin\AtEndDocument{\MessageDeFin}\fi |
| 646 |
%----------------------------------------------------------------- |
| 647 |
% |
| 648 |
\makeatletter |
| 649 |
% counts used in particular in the samples from the documentation of the |
| 650 |
% xintseries.sty package |
| 651 |
\newcount\cnta |
| 652 |
\newcount\cntb |
| 653 |
\newcount\cntc |
| 654 |
|
| 655 |
\ifdefined\doxintsource |
| 656 |
\chardef\NoSourceCode 0 |
| 657 |
\else |
| 658 |
\chardef\doxintsource 0 |
| 659 |
\fi |
| 660 |
% \doxintsource=1 means producing only source code. |
| 661 |
% It is set in xintsource.tex. Prior to 1.4l it was |
| 662 |
% set in the call with latexmk + \input syntax. |
| 663 |
% |
| 664 |
% \doxintsource=0 and \NoSourceCode=1 : include only user doc |
| 665 |
% \doxintsource=0 and \NoSourceCode=0 : combine user doc and source code |
| 666 |
% \doxintsource=1 and \NoSourceCode=1 : never happens but would mean to do |
| 667 |
% nothing! |
| 668 |
|
| 669 |
% default is to assume latex + dvipdfmx |
| 670 |
\chardef\Withdvipdfmx 1 |
| 671 |
|
| 672 |
\RequirePackage{iftex} |
| 673 |
|
| 674 |
\ifpdf \chardef\Withdvipdfmx 0 \fi |
| 675 |
\ifxetex\chardef\Withdvipdfmx 0 \fi |
| 676 |
\iftutex |
| 677 |
% they are used at some locations in this doc (independently of loading xint) |
| 678 |
\let\pdfsetrandomseed\setrandomseed |
| 679 |
\let\pdfuniformdeviate\uniformdeviate |
| 680 |
\fi |
| 681 |
|
| 682 |
% 2019/09/10 |
| 683 |
% Get rid of HARASSMENT by KOMA-Script |
| 684 |
% Must be located before \documentclass |
| 685 |
\def\class@shoulddisablepackagewarning@list{tocloft.} |
| 686 |
|
| 687 |
\ifnum\Withdvipdfmx=1 |
| 688 |
\def\pgfsysdriver{pgfsys-dvipdfm.def} |
| 689 |
\documentclass [dvipdfm, dvipdfmx]{scrartcl} |
| 690 |
\else |
| 691 |
\documentclass {scrartcl} |
| 692 |
\fi |
| 693 |
|
| 694 |
%%% START OF CUSTOM doc.sty LOADING (May 21, 2022) |
| 695 |
% |
| 696 |
% For some legacy reason (because I started like this and it |
| 697 |
% worked to my satisfaction) I had used scrdoc.cls all those |
| 698 |
% years, without in fact needing most of its features. |
| 699 |
% |
| 700 |
% It loads ltxdoc class, from which again I need very little. On |
| 701 |
% testing May 20, 2022 the upcoming LaTeX 2022-06-01 I had some |
| 702 |
% problems with ltxdoc not having suitable interface for rolling |
| 703 |
% back to doc=V2. |
| 704 |
% |
| 705 |
% I did experiment with indices for xintsource.pdf from 2018 to |
| 706 |
% 2019 but it made the build process significantly lengthier, |
| 707 |
% created heavy-sized PDF, had various issues in my context |
| 708 |
% (possibly the kind of issues doc V3 addresses about indexing |
| 709 |
% non-macro things, hyperlinks,...), and these indices basically |
| 710 |
% had not any real use as PDF search proves efficient enough, |
| 711 |
% and the structures of local tables of contents makes for |
| 712 |
% agreeable enough navigation via the input mark-up using |
| 713 |
% sectioning commands. |
| 714 |
% |
| 715 |
% Thus it turns out I need very little of doc.sty, and almost |
| 716 |
% nothing of ltxdoc.cls and scrdoc.cls. |
| 717 |
% |
| 718 |
% Let's load the doc=V2 version to avoid having to work around |
| 719 |
% hypdoc loading interfering with my use of hyperref and as said |
| 720 |
% above I don't need the hyperlinked cross-referencing as I have |
| 721 |
% it via my own mark-up to a sufficiently good enough extent, |
| 722 |
% and this holds for many many years. And I will not now change |
| 723 |
% my mark-up. |
| 724 |
\ifdefined\IfFormatAtLeastTF |
| 725 |
\IfFormatAtLeastTF{2022/06/01}% |
| 726 |
{% |
| 727 |
\IfFileExists{doc-2021-06-01.sty}% |
| 728 |
{\usepackage{doc}[=v2]}% |
| 729 |
% Why on earth do I lose my time doing this? |
| 730 |
{\GenericError |
| 731 |
{(xint build doc)\@spaces}% |
| 732 |
{xint build error: % |
| 733 |
Your LaTeX installation seems to be broken, format is\MessageBreak |
| 734 |
2022-06-01 or later but `doc' package in its `v2' version\MessageBreak |
| 735 |
seems to not be available. \space Will try with `doc' but if\MessageBreak |
| 736 |
its `v3' is used there will be an option clash error\MessageBreak |
| 737 |
regarding hyperref.}% |
| 738 |
{}% |
| 739 |
{Please make sure `doc' package matches your LaTeX format.}% |
| 740 |
\usepackage{doc}% |
| 741 |
}% |
| 742 |
}% |
| 743 |
{\usepackage{doc}}% |
| 744 |
\else |
| 745 |
\usepackage{doc} |
| 746 |
\fi |
| 747 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 748 |
% MACROS OF doc.sty WILL BE HACKED (2022/06/06) FOR THE IMPLEMENTATION PART |
| 749 |
% |
| 750 |
% First we want to turn CodelineNo into a real LaTeX counter |
| 751 |
% This will spare defining an extra counter for the hyperlinks with \hyperref |
| 752 |
\begingroup\let\newcount\@gobble\@definecounter{CodelineNo}\endgroup |
| 753 |
%%% Next line is not needed because \theCodelineNo already got that definition |
| 754 |
%%% from doc-2021-06-01.sty, and \@definecounter does not overwrite it. |
| 755 |
% \def\theCodelineNo{\reset@font\scriptsize\arabic{CodelineNo}} |
| 756 |
% But as we will reset CodelineNo at each style file we need some unique id |
| 757 |
\def\theHCodelineNo{\the\value{section}.\the\value{CodelineNo}} |
| 758 |
% This is all for now. |
| 759 |
% The further hacks are to be found after the \StopEventually (i.e. a few |
| 760 |
% thousands lines down from here if you don't have access to the private |
| 761 |
% sources, which is probably the case if you are not the author). |
| 762 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 763 |
|
| 764 |
% As explained above I was formerly using scrdoc hence ltxdoc indirectly. |
| 765 |
% Let's emulate here the little I appear to need from ltxdoc.cls and |
| 766 |
% srcdoc.cls. |
| 767 |
% |
| 768 |
\AtBeginDocument{\MakeShortVerb{\|}} |
| 769 |
\DeclareFontShape{OT1}{cmtt}{bx}{n}{<-> ssub * cmtt/m/n}{} |
| 770 |
\DeclareFontFamily{OMS}{cmtt}{\skewchar\font 48} % '60 |
| 771 |
\DeclareFontShape{OMS}{cmtt}{m}{n}{<-> ssub * cmsy/m/n}{} |
| 772 |
\DeclareFontShape{OMS}{cmtt}{bx}{n}{<-> ssub * cmsy/b/n}{} |
| 773 |
\DeclareFontShape{OT1}{cmss}{m}{it}{<->ssub*cmss/m/sl}{} |
| 774 |
\ifnum\NoSourceCode=1 |
| 775 |
\OnlyDescription |
| 776 |
\fi |
| 777 |
\CodelineNumbered |
| 778 |
\EnableCrossrefs % but this will be hacked |
| 779 |
% \setcounter{StandardModuleDepth}{1} % we don't use this mechanism currently |
| 780 |
\def\cmd#1{\cs{\expandafter\cmd@to@cs\string#1}} |
| 781 |
\def\cmd@to@cs#1#2{\char\number`#2\relax} |
| 782 |
% Here I am loading doc=v2 but formerly I was using ltxdoc via scrdoc |
| 783 |
% which I dropped at release 1.4l (2022-05-29) and without much |
| 784 |
% thinking I had kept this. |
| 785 |
\DeclareRobustCommand\cs[1]{\texttt{\bslash#1}} |
| 786 |
% As I may have the * active, or macro names with _ or ^, I should |
| 787 |
% add \detokenize. But see below for a redefinition anyhow. |
| 788 |
% |
| 789 |
% More urgent is that I am also using hyperref and this definition gives wrong |
| 790 |
% bookmarks if \cs is used in section titles. As I had very very few usags of |
| 791 |
% \cs in the whole of xint.dtx, it took me a while to realize the problem |
| 792 |
% here. Turns out that doc=v3 by default loads hypdoc which includes this |
| 793 |
% configuation for hyperref compatibility: |
| 794 |
\AtBeginDocument{% |
| 795 |
\pdfstringdefDisableCommands{\def\cs#1{\textbackslash\detokenize{#1}}}% |
| 796 |
}% |
| 797 |
% As I have not loaded hyperref yet I must delay it to AtBeginDocument. |
| 798 |
% Late May, early June 2022 I added to my custom \verb automated detection |
| 799 |
% of potential hyperlinks. So I decided to replace \cs ltxdoc definition |
| 800 |
% by suitable \verb usage. It is not important to be efficient here, |
| 801 |
% I can leave some \expandafter, in fact there are a handful of uses. |
| 802 |
\DeclareRobustCommand\cs[1]{\expandafter\verb\expandafter~\bslash#1~} |
| 803 |
% As my \verb does a verbatimizing \scantokens I don't need to worry |
| 804 |
% here about active characters but I need in the PDF string, hence |
| 805 |
% the \detokenize above. |
| 806 |
\providecommand\marg[1]{% |
| 807 |
{\ttfamily\char`\{}\meta{#1}{\ttfamily\char`\}}} |
| 808 |
\providecommand\oarg[1]{% |
| 809 |
{\ttfamily[}\meta{#1}{\ttfamily]}} |
| 810 |
\providecommand\parg[1]{% |
| 811 |
{\ttfamily(}\meta{#1}{\ttfamily)}} |
| 812 |
% \@addtoreset{CodelineNo}{part}% No need for this here |
| 813 |
% \def\partname{File}% \partname is "fixed" somewhere further down anyhow |
| 814 |
% No need for this, anyhow I don't build the indices (I did in 2018-2019 only). |
| 815 |
% \gdef\codeline@wrindex#1{\if@filesw |
| 816 |
% \begingroup |
| 817 |
% \let\protect\noexpand |
| 818 |
% \immediate\write\@indexfile |
| 819 |
% {\string\indexentry{#1}% |
| 820 |
% {\filesep\number\c@CodelineNo}}% |
| 821 |
% \endgroup\fi} |
| 822 |
% \let\filesep\@empty |
| 823 |
|
| 824 |
% There is very little we seem to need from the scrdoc extras: page geometry |
| 825 |
% is set by geometry package and a4paper option from xint.tex file. So it |
| 826 |
% seems I only need the hologo loading: |
| 827 |
\usepackage{hologo} |
| 828 |
\DeclareRobustCommand*{\eTeX}{\hologo{eTeX}}% |
| 829 |
\DeclareRobustCommand*{\LuaTeX}{\hologo{LuaTeX}}% |
| 830 |
% |
| 831 |
%%% end of ltxdoc+srcdoc emulation. See after \StopEventually for doc.sty hacks. |
| 832 |
|
| 833 |
% Remove from sectioning commands insertion of marks, because we |
| 834 |
% will do it ourself. |
| 835 |
\usepackage{etoolbox} |
| 836 |
\patchcmd{\@sect}% |
| 837 |
{\expandafter\csname#1mark\expandafter\endcsname\expandafter{\@currentheadentry}}% |
| 838 |
{}{}{\Error@CouldNotApplyFirstPatch@sect} |
| 839 |
\patchcmd{\@sect}% |
| 840 |
{\expandafter\csname#1mark\expandafter\endcsname\expandafter{\@currentheadentry}}% |
| 841 |
{}{}{\Error@CouldNotApplySecondPatch@sect} |
| 842 |
% This one now needed too, Jeudi 30 janvier 2020 |
| 843 |
% \expandafter \ifx \csname #1mark\endcsname \@gobble \@mkboth {}{}\else |
| 844 |
% \csname #1mark\expandafter \endcsname \expandafter {\@currentheadentry }\fi |
| 845 |
% \@gobble est long donc simplement |
| 846 |
\def\partmark #1{}% |
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
\pagestyle{headings} |
| 851 |
|
| 852 |
\iftutex |
| 853 |
% (if lualatex or xelatex are used to compile the documentation) |
| 854 |
% xinttools is not yet loaded hence the \AtBeginDocument |
| 855 |
% Note the subtlety: we can't do \def#1, because #1 will be the |
| 856 |
% character still with letter catcode. |
| 857 |
\AtBeginDocument{% |
| 858 |
\xintForpair #1#2 in {(δ, \delta), (ξ, \xi), (π, \pi), (≠, \neq), |
| 859 |
(α, \alpha), (τ, \tau), (λ, \lambda), (ν, \nu)} |
| 860 |
\do{\catcode`#1\active |
| 861 |
\begingroup\lccode`~=\lccode`#1 |
| 862 |
\lowercase{\endgroup\def~}{\ensuremath{#2}}}% |
| 863 |
}% |
| 864 |
\else |
| 865 |
\usepackage[T1]{fontenc} |
| 866 |
\usepackage[utf8]{inputenc} |
| 867 |
% (2016/03/02): \delta utilisé dans les commentaires de la division de xint.sty |
| 868 |
% (2017/01/03): \xi pour doc \xintnewdummy |
| 869 |
% (2019/03/31): \pi utilisé dans mes commentaires de xinttrig.sty |
| 870 |
% (2019/04/24): \neq utilisé dans un commentaire de xintlog.sty |
| 871 |
% (2025/08/30): \alpha, \tau, \lambda, \nu pour doc \xintnewdummy |
| 872 |
% |
| 873 |
% As we now (2025/08/30) load lgrmath (farther below), we have to delay this |
| 874 |
% to at begin document. |
| 875 |
\AtBeginDocument{% |
| 876 |
\DeclareUnicodeCharacter{03B4}{\ensuremath{\delta}}% δ |
| 877 |
\DeclareUnicodeCharacter{03BE}{\ensuremath{\xi}}% ξ |
| 878 |
\DeclareUnicodeCharacter{03C0}{\ensuremath{\pi}}% π |
| 879 |
\DeclareUnicodeCharacter{2260}{\ensuremath{\neq}}% ≠ |
| 880 |
\DeclareUnicodeCharacter{03B1}{\ensuremath{\alpha}}% α |
| 881 |
\DeclareUnicodeCharacter{03C4}{\ensuremath{\tau}}% τ |
| 882 |
\DeclareUnicodeCharacter{03BB}{\ensuremath{\lambda}}% λ |
| 883 |
\DeclareUnicodeCharacter{03BD}{\ensuremath{\nu}}% ν |
| 884 |
} |
| 885 |
\fi |
| 886 |
|
| 887 |
\usepackage{multicol} |
| 888 |
\usepackage{geometry} |
| 889 |
\AtBeginDocument {\ttzfamily % package newtxtt is loaded in preamble |
| 890 |
\newgeometry{textwidth=\dimexpr92\fontcharwd\font`X\relax, |
| 891 |
vscale=0.75}} |
| 892 |
|
| 893 |
\unless\ifnum\doxintsource=1 |
| 894 |
\usepackage{xintexpr} |
| 895 |
\usepackage{xintbinhex} |
| 896 |
\usepackage{xintgcd} |
| 897 |
\usepackage{xintseries} |
| 898 |
\usepackage{xintcfrac} |
| 899 |
\usepackage{amsmath}% for \cfrac usage |
| 900 |
\DeclareMathOperator{\sinc}{sinc} |
| 901 |
\fi |
| 902 |
\usepackage{pifont}% for \ding{73} (hollow star) |
| 903 |
|
| 904 |
% needed also for build of xintsource.pdf |
| 905 |
\usepackage{xinttools} |
| 906 |
|
| 907 |
\usepackage{enumitem} |
| 908 |
\usepackage{varioref} |
| 909 |
\usepackage{xspace} |
| 910 |
\usepackage[para]{footmisc} |
| 911 |
\usepackage{picture} |
| 912 |
\usepackage{graphicx} |
| 913 |
|
| 914 |
\usepackage[english]{babel} |
| 915 |
% 2022/06/05 |
| 916 |
% \usepackage{csquotes} |
| 917 |
\def\myenquote#1{{\sffamily\textquotedblleft}#1{\sffamily\textquotedblright}} |
| 918 |
|
| 919 |
% 2022/05/24, commenting out this at it appears to not be used anywhere now. |
| 920 |
% \usepackage[autolanguage,np]{numprint} |
| 921 |
% \AtBeginDocument{\npthousandsep{,\hskip .5pt plus .1pt minus .1pt}} |
| 922 |
|
| 923 |
% But surprisingly it is via numprint that I was loading array package |
| 924 |
% whose extended syntax for tabular preambles is required! |
| 925 |
\usepackage{array} |
| 926 |
|
| 927 |
\usepackage[dvipsnames,svgnames]{xcolor} |
| 928 |
%%% DEFINITIONS OF COLORS USED IN DOCUMENT |
| 929 |
|
| 930 |
|
| 931 |
% color for the \xintname, \xintexprname, etc macros |
| 932 |
\definecolor{xintnamecolor}{RGB}{228,57,0} |
| 933 |
\colorlet{XINTNAMECOLOR}{xintnamecolor} |
| 934 |
|
| 935 |
% color for their analogs \xintnameimp, etc... in implementation part |
| 936 |
\colorlet{xintnameimpcolor}{blue} |
| 937 |
\colorlet{XINTNAMEIMPCOLOR}{xintnameimpcolor} |
| 938 |
|
| 939 |
% colors for hyperref |
| 940 |
\definecolor{xinturlcolor}{RGB}{38,128,192} |
| 941 |
\colorlet{xintlinkcolor}{blue} |
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
% colors for custom \verb and everbatim/everbatim* environments |
| 948 |
% |
| 949 |
% the commented-out legacy colors used in xint.pdf for many years up to |
| 950 |
% xint 1.4j (2021/07/13) (I should retrieve since when exactly) |
| 951 |
% |
| 952 |
% \colorlet{verbcolor}{jfbrown} |
| 953 |
% \colorlet{verbsoftwrapiconcolor}{blue} |
| 954 |
% \colorlet{everbatimfgcolor}{Brown} |
| 955 |
% \colorlet{everbatimbgcolor}{yellow!5} |
| 956 |
% \colorlet{everbatimxfgcolor}{OrangeRed} |
| 957 |
% |
| 958 |
% https://contrast-ratio.com/#rgb%28165%2C100%2C10%29-on-white |
| 959 |
% says the contrast ratio on white is 4.74 and I do see the contrast |
| 960 |
% is less strong than |
| 961 |
% for the DarkBlue/Beige and Maroon/White combinations seen below |
| 962 |
% \colorlet{verbcolor}{jfbrown} |
| 963 |
% I will simply use also Maroon |
| 964 |
\colorlet{verbcolor}{Maroon} |
| 965 |
\colorlet{digitsttcolor}{verbcolor} |
| 966 |
\colorlet{verbsoftwrapiconcolor}{DarkBlue} |
| 967 |
\colorlet{everbatimfgcolor}{DarkBlue} |
| 968 |
% |
| 969 |
% According to |
| 970 |
% https://contrast-ratio.com/#rgb%2811%2C35%2C139%29-on-rgb%28245%2C244%2C220%29 |
| 971 |
% the DarkBlue on Beige |
| 972 |
% gives a contrast-ratio of 11.58 which confirmed my intuition it is not bad |
| 973 |
% "Passes AAA level for any size text and AA for user interface components and |
| 974 |
% graphical objects" |
| 975 |
% |
| 976 |
% memo: with Apple ColorPicker it seems one needs to select "sRVB" (I guess |
| 977 |
% "sRGB" in English) for values matching xcolor RGB input or the above html |
| 978 |
% page rgb(R,G,B) input, also this did not work |
| 979 |
% 100%, most probably due to the window transparency by default on my mac? |
| 980 |
\colorlet{everbatimbgcolor}{Beige} |
| 981 |
% |
| 982 |
% https://contrast-ratio.com/#rgb%28128%2C31%2C19%29-on-white |
| 983 |
% gives 9.89 contrast ratio which is a bit less but still AAA |
| 984 |
\colorlet{everbatimxfgcolor}{Maroon} |
| 985 |
% |
| 986 |
|
| 987 |
% colors for margin notes |
| 988 |
\colorlet{marginnotecolor}{PineGreen} |
| 989 |
\colorlet{marginwarningcolor}{Red} |
| 990 |
|
| 991 |
% colors for toc |
| 992 |
\colorlet{tocstylesectioncolor}{cyan} |
| 993 |
\colorlet{tocstylesectionimpcolor}{RoyalPurple} |
| 994 |
\colorlet{tocstylebundlesectioncolor}{xintnamecolor} |
| 995 |
|
| 996 |
% colors for macro code and comments |
| 997 |
\colorlet{privatecommentcolor}{cyan} |
| 998 |
\colorlet{macrocodecommentcolor}{gray} |
| 999 |
\colorlet{macrocodenewmacrocolor}{verbcolor} |
| 1000 |
\colorlet{macrocodelinktouserdoccolor}{xintnamecolor}% and bold face |
| 1001 |
\colorlet{macrocodelinktosectioncolor}{DarkBlue}% and bold face |
| 1002 |
\colorlet{macrocodelinktocodelinecolor}{DarkBlue} |
| 1003 |
\colorlet{macrocodenoncscolor}{Green} |
| 1004 |
|
| 1005 |
% colors for the implementation part and the modified macrocode macros |
| 1006 |
% are to be found after \StopEventually |
| 1007 |
|
| 1008 |
\usepackage{eso-pic}% après xcolor sinon Option clash for package xcolor. |
| 1009 |
|
| 1010 |
\ifnum\doxintsource=1 |
| 1011 |
\else |
| 1012 |
% Dependency graph done using TikZ (manually) |
| 1013 |
\usepackage{tikz} |
| 1014 |
\usetikzlibrary{shapes,arrows.meta} |
| 1015 |
\fi |
| 1016 |
|
| 1017 |
\usepackage{framed} |
| 1018 |
% SNUGFRAMED |
| 1019 |
% ========== |
| 1020 |
|
| 1021 |
\newenvironment{snugframed}{% |
| 1022 |
\fboxsep \dimexpr2\fontcharwd\font`X\relax |
| 1023 |
\advance\linewidth-2\fboxsep |
| 1024 |
\advance\csname @totalleftmargin\endcsname \fboxsep |
| 1025 |
\def\FrameCommand##1{\hskip\@totalleftmargin |
| 1026 |
\hskip-\fboxsep |
| 1027 |
\fbox{##1}\hskip-\fboxsep |
| 1028 |
% There is no \@totalrightmargin, so: |
| 1029 |
\hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}% |
| 1030 |
\MakeFramed {\advance\hsize-\width \@totalleftmargin\z@ \linewidth\hsize |
| 1031 |
\@setminipage}% |
| 1032 |
}{\par\unskip\@minipagefalse\endMakeFramed} |
| 1033 |
|
| 1034 |
% HYPERREF |
| 1035 |
% ======== |
| 1036 |
|
| 1037 |
\usepackage{hyperref} |
| 1038 |
% 2022/06/10 reduce clutter in console and log output, there are already |
| 1039 |
% enough messages telling we have to execute latex once more |
| 1040 |
\catcode`_ 11 |
| 1041 |
\def\perhapshyperref[#1]{\ifcsname r@#1\endcsname \xint_afterfi{\hyperref[#1]}\fi} |
| 1042 |
\catcode`_ 8 |
| 1043 |
|
| 1044 |
\hypersetup{% |
| 1045 |
linktoc=all,% |
| 1046 |
breaklinks=true,% |
| 1047 |
colorlinks=true,% |
| 1048 |
urlcolor=xinturlcolor,% |
| 1049 |
linkcolor=xintlinkcolor,% |
| 1050 |
pdfauthor={Jean-Fran\c cois Burnol},% |
| 1051 |
pdftitle={The xintexpr and allied packages},% |
| 1052 |
pdfsubject={Arithmetic with TeX},% |
| 1053 |
pdfkeywords={Expansion, arithmetic, TeX},% |
| 1054 |
pdfstartview=FitH,% |
| 1055 |
pdfpagemode=UseNone,% |
| 1056 |
} |
| 1057 |
|
| 1058 |
\usepackage{hypcap} |
| 1059 |
|
| 1060 |
\ifnum\doxintsource=1 |
| 1061 |
\hypersetup{pdftitle={The xintexpr and allied packages source code}} |
| 1062 |
\fi |
| 1063 |
|
| 1064 |
\usepackage{bookmark} |
| 1065 |
|
| 1066 |
% This is for having similarly named labels to get hyperlinks either to the |
| 1067 |
% user documentation or to the implementation part. From source mark-up with |
| 1068 |
% \csbxint, \csbXINT, \csb, or automated ones from |...| and the custom \verb |
| 1069 |
% However in the user manual I have so far (2022/06/11) used manually typed-in |
| 1070 |
% \label's in contrast to the almost exclusively automated ones of the implementation |
| 1071 |
% part. So for time being I keep an empty prefix here in place of something |
| 1072 |
% reasonable such as usr-. |
| 1073 |
\let\xintdoclabelprefix\empty |
| 1074 |
\def\xintimplabelprefix{src-} |
| 1075 |
|
| 1076 |
% used by \csbxint etc... |
| 1077 |
\let\xintlabelprefix\xintdoclabelprefix |
| 1078 |
|
| 1079 |
% FONTS |
| 1080 |
% ===== |
| 1081 |
|
| 1082 |
\usepackage[zerostyle=d,straightquotes,scaled=0.95]{newtxtt} |
| 1083 |
\usepackage{newtxmath} |
| 1084 |
\input ts1newtxttz.fd |
| 1085 |
|
| 1086 |
% Fix what appears to be typos in ts1newtxttz.fd 2024/03/03 |
| 1087 |
% where one sees tcx in RHS of <-> in place of tx. |
| 1088 |
% Needed to typeset the \textasciigrave in particular. |
| 1089 |
\DeclareFontShape{TS1}{newtxttz}{m}{n}{ %medium |
| 1090 |
<-> \newtxtt@@scale newtxttz\newtxtt@@fig% |
| 1091 |
}{} |
| 1092 |
\DeclareFontShape{TS1}{newtxttz}{m}{sl}{ %slanted |
| 1093 |
<-> \newtxtt@@scale newtxttzsl\newtxtt@@fig% |
| 1094 |
}{} |
| 1095 |
\DeclareFontShape{TS1}{newtxttz}{b}{n}{ %bold |
| 1096 |
<-> \newtxtt@@scale newtxbttz\newtxtt@@fig% |
| 1097 |
}{} |
| 1098 |
\DeclareFontShape{TS1}{newtxttz}{b}{sl}{ %bold slanted |
| 1099 |
<-> \newtxtt@@scale newtxbttzsl\newtxtt@@fig% |
| 1100 |
}{} |
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
\renewcommand\familydefault\ttdefault |
| 1107 |
\usepackage[noendash]{mathastext}% pas de endash dans newtxtt |
| 1108 |
|
| 1109 |
% A (somewhat surprising a priori, at least to me) effect of |
| 1110 |
% \DeclareFontEncoding{LGR}{}{} (which loads lgrenc.dfu) is that |
| 1111 |
% it redeclares all UTF-8 Greek ! So for example ξ will expand to \textxi. |
| 1112 |
% So we delayed our own \DeclareUnicodeCharacter's to \begin{document} |
| 1113 |
\usepackage[style=up,font=cmss]{lgrmath} |
| 1114 |
|
| 1115 |
% 2024/01/15: upstream update by Michael Sharpe to newtxtt, |
| 1116 |
% in particular a shorter "extra space" for the nomono font |
| 1117 |
% I thus try again with \nonfrenchspacing. |
| 1118 |
% \frenchspacing |
| 1119 |
% sans-serif in footnotes, TOC, titles, etc... |
| 1120 |
\renewcommand\familydefault\sfdefault |
| 1121 |
|
| 1122 |
% TABLES OF CONTENTS |
| 1123 |
% ================== |
| 1124 |
|
| 1125 |
\usepackage{tocloft} |
| 1126 |
\usepackage{etoc} |
| 1127 |
|
| 1128 |
\def\gobbletodot #1.{} |
| 1129 |
|
| 1130 |
\newif\ifinmanualmaintoc |
| 1131 |
\ifnum\doxintsource=0 |
| 1132 |
\inmanualmaintoctrue |
| 1133 |
\fi |
| 1134 |
\def\tocstylesectionbracedcolor{{tocstylesectioncolor}} |
| 1135 |
\def\tocstyleMARGEPAGENO {1.5em}% changera pour la partie implémentation |
| 1136 |
|
| 1137 |
|
| 1138 |
\def\tocstylesectionVSKIP{\vskip\bigskipamount} |
| 1139 |
\etocsetstyle{section}{} |
| 1140 |
{\normalfont} |
| 1141 |
{\etociffirst{}{\tocstylesectionVSKIP}% |
| 1142 |
\rightskip \tocstyleMARGEPAGENO\relax |
| 1143 |
\parfillskip -\tocstyleMARGEPAGENO\relax |
| 1144 |
\bfseries |
| 1145 |
\leftskip \leftmarginii |
| 1146 |
\noindent\llap % \llap |
| 1147 |
{\makebox[\leftmarginii][l]% et \leftmargini le 12/10/2014 |
| 1148 |
{\expandafter\textcolor\tocstylesectionbracedcolor{\etocnumber}}}% |
| 1149 |
\strut\etocname |
| 1150 |
\mdseries\nobreak\leaders\etoctoclineleaders\hfill\nobreak\strut |
| 1151 |
\makebox[\tocstyleMARGEPAGENO][r]{\etocpage}\par |
| 1152 |
\let\ETOCsectionnumber\etocthenumber |
| 1153 |
}% |
| 1154 |
{}% |
| 1155 |
|
| 1156 |
\newdimen\tocstyleLEFTMARGIN |
| 1157 |
\AtBeginDocument{\tocstyleLEFTMARGIN \dimexpr 5\fontcharwd\font`X\relax} |
| 1158 |
\etocsetstyle{subsection} |
| 1159 |
{\begingroup\normalfont |
| 1160 |
\setlength{\premulticols}{0pt}% |
| 1161 |
\setlength{\multicolsep}{0pt}% |
| 1162 |
\setlength{\columnsep}{\leftmarginii}% |
| 1163 |
\setlength{\columnseprule}{.4pt}% n'influence pas séparation colonnes |
| 1164 |
\parskip\z@skip |
| 1165 |
\raggedcolumns |
| 1166 |
\addvspace{\smallskipamount}% |
| 1167 |
\begin{multicols}{2} |
| 1168 |
\leftskip \tocstyleLEFTMARGIN % 12 octobre 2014 |
| 1169 |
\ifinmanualmaintoc |
| 1170 |
\rightskip \tocstyleMARGEPAGENO |
| 1171 |
\else |
| 1172 |
\rightskip \tocstyleMARGEPAGENO plus 2em minus 1em |
| 1173 |
\fi |
| 1174 |
\parfillskip -\tocstyleMARGEPAGENO\relax |
| 1175 |
} |
| 1176 |
{} |
| 1177 |
{\noindent |
| 1178 |
\etocifnumbered{\llap{\makebox[\tocstyleLEFTMARGIN][l]{\ttzfamily\bfseries\etoclink |
| 1179 |
{\ifinmanualmaintoc\expandafter\textcolor\tocstylesectionbracedcolor |
| 1180 |
{\normalfont\bfseries\ETOCsectionnumber}\fi |
| 1181 |
.\expandafter\gobbletodot\etocthenumber}}}}{\kern-\tocstyleLEFTMARGIN}% |
| 1182 |
\strut\etocname\nobreak |
| 1183 |
\unless\ifinmanualmaintoc\leaders\etoctoclineleaders\fi |
| 1184 |
\hfill\nobreak |
| 1185 |
\strut\makebox[\tocstyleMARGEPAGENO][r]{\small\etocpage}\endgraf } |
| 1186 |
{\end{multicols}\endgroup |
| 1187 |
}% |
| 1188 |
|
| 1189 |
\etocsetstyle{subsubsection} |
| 1190 |
{\begingroup\normalfont\small |
| 1191 |
\leftskip\dimexpr\leftmargini+1em\relax |
| 1192 |
} |
| 1193 |
{} |
| 1194 |
{\noindent |
| 1195 |
\llap{\makebox[\dimexpr\leftmargini+1em\relax][l]% |
| 1196 |
{\ttzfamily\bfseries\etoclink |
| 1197 |
{\tocstylesubsubsectionHOOK.\expandafter\gobbletodot\etocthenumber}}}% |
| 1198 |
\strut\etocname\nobreak |
| 1199 |
\leaders\etoctoclineleaders |
| 1200 |
\hfill\nobreak |
| 1201 |
\strut\makebox[\tocstyleMARGEPAGENO][r]{\small\etocpage}\endgraf |
| 1202 |
} |
| 1203 |
{\endgroup }% |
| 1204 |
|
| 1205 |
% 2018/02/28 |
| 1206 |
% quick hack to get style I want in "User defined functions" section of manual |
| 1207 |
\let\tocstylesubsubsectionHOOK\empty |
| 1208 |
\etocsetlevel{xinttable}{6}% formerly "table" was used, but forbidden since |
| 1209 |
% etoc 1.2 of 2023/10/01 |
| 1210 |
|
| 1211 |
\addtocontents{toc}{\protect\hypersetup{hidelinks}} |
| 1212 |
|
| 1213 |
% ===================== |
| 1214 |
% MISCELLANEOUS MARK-UP |
| 1215 |
% ===================== |
| 1216 |
|
| 1217 |
|
| 1218 |
\def\digitstt #1{\begingroup\color{digitsttcolor}#1\endgroup} |
| 1219 |
\let\dtt\digitstt |
| 1220 |
|
| 1221 |
% \fexpan 22 octobre 2013 |
| 1222 |
\newcommand\fexpan {\perhapshyperref[ssec:expansions]{\textit{f}-expan}} |
| 1223 |
% \xexpan ajouté 28 mai 2022 |
| 1224 |
\newcommand\xexpan {\perhapshyperref[ssec:expansions]{\textit{x}-expan}} |
| 1225 |
% Septembre 2015 |
| 1226 |
% Address updated to github repo's one, May 2018 |
| 1227 |
% They did s/master/main/ already a few years back, May 2022 |
| 1228 |
\def\liiibigint |
| 1229 |
{\href{https://github.com/latex3/latex3/tree/main/l3trial/l3bigint}{l3bigint}} |
| 1230 |
|
| 1231 |
% May 2022 |
| 1232 |
\def\liiistrformat |
| 1233 |
% {\href{https://github.com/latex3/latex3/tree/main/l3experimental/l3str}{l3str}} |
| 1234 |
{\href{https://ctan.org/pkg/l3experimental}{l3str-format}} |
| 1235 |
%\def\liiistrformatnew |
| 1236 |
% {\href{https://github.com/latex3/latex3/tree/main/l3trial/l3str-format-new}{l3str-format-new}} |
| 1237 |
|
| 1238 |
|
| 1239 |
% Margin Notes |
| 1240 |
% ============ |
| 1241 |
|
| 1242 |
% Nothing here can be used in vertical mode directly. |
| 1243 |
|
| 1244 |
\def\MyMarginNote {\@ifnextchar[\@MyMarginNote{\@MyMarginNote[]}}% |
| 1245 |
\let\inmarg\MyMarginNote |
| 1246 |
% \smash needs \hbox here since LaTeX 2018/12/01 |
| 1247 |
% https://github.com/latex3/latex2e/issues/108 |
| 1248 |
\def\@MyMarginNote [#1]#2{\@bsphack |
| 1249 |
\vadjust{\vskip-\dp\strutbox |
| 1250 |
\hbox{\smash{\hbox to 0pt |
| 1251 |
{\color{marginnotecolor}\normalfont\small |
| 1252 |
\hsize 1.6cm\rightskip.5cm minus.5cm |
| 1253 |
\hss\vtop{#2}\ $\to$#1\ }}}% |
| 1254 |
\vskip\dp\strutbox |
| 1255 |
}\strut\@esphack} |
| 1256 |
\def\MyMarginNoteWithBrace #1#2{\@bsphack |
| 1257 |
\vadjust{\vskip-\dp\strutbox |
| 1258 |
\hbox{\smash{\hbox to 0pt |
| 1259 |
{\color{marginnotecolor}%\normalfont\small |
| 1260 |
\hss #1\ $\bigg\{$#2}}}% |
| 1261 |
\vskip\dp\strutbox |
| 1262 |
}\strut\@esphack} |
| 1263 |
\def\IMPORTANT {\MyMarginNoteWithBrace |
| 1264 |
{\raisebox{-.5\height}{\resizebox{2\width}{!}{\ding{43}}}}{\ }} |
| 1265 |
\def\IMPORTANTf {\MyMarginNoteWithBrace |
| 1266 |
{\raisebox{-.5\height}{\resizebox{2\width}{!}{\ding{43}}}}% |
| 1267 |
{\kern\dimexpr\FrameSep+\FrameRule\relax\ }} |
| 1268 |
\def\etype #1{\@bsphack |
| 1269 |
\vadjust{\vskip-\dp\strutbox |
| 1270 |
\hbox{\smash{\hbox to 0pt {\hss\color{marginnotecolor}% |
| 1271 |
\itshape \xintListWithSep{\,}{#1}\ $\star$\quad }}}% |
| 1272 |
\vskip\dp\strutbox |
| 1273 |
}\strut\@esphack} |
| 1274 |
\def\xtype #1{\@bsphack |
| 1275 |
\vadjust{\vskip-\dp\strutbox |
| 1276 |
\hbox{\smash{\hbox to 0pt {\hss\color{marginnotecolor}% |
| 1277 |
\itshape \xintListWithSep{\,}{#1}\ \ding{73}\quad }}}% |
| 1278 |
\vskip\dp\strutbox }\strut\@esphack} |
| 1279 |
\def\ntype #1{\@bsphack |
| 1280 |
\vadjust{\vskip-\dp\strutbox |
| 1281 |
\hbox{\smash{\hbox to 0pt {\hss\color{marginnotecolor}% |
| 1282 |
\itshape \xintListWithSep{\,}{#1}\quad }}}% |
| 1283 |
\vskip\dp\strutbox }\strut\@esphack} |
| 1284 |
% |
| 1285 |
\def\Numf {{\vbox{\halign{\hfil##\hfil\cr \footnotesize |
| 1286 |
\upshape Num\cr |
| 1287 |
\noalign{\hrule height 0pt \vskip1pt\relax} |
| 1288 |
\itshape f\cr}}}} |
| 1289 |
\def\Ff {{\vbox{\halign{\hfil##\hfil\cr \footnotesize |
| 1290 |
\upshape Frac\cr |
| 1291 |
\noalign{\hrule height 0pt \vskip1pt\relax} |
| 1292 |
\itshape f\cr}}}} |
| 1293 |
\def\numx {{\vbox{\halign{\hfil##\hfil\cr \footnotesize |
| 1294 |
\upshape num\cr |
| 1295 |
\noalign{\hrule height 0pt \vskip1pt\relax} |
| 1296 |
\itshape x\cr}}}} |
| 1297 |
% |
| 1298 |
\def\NewWith #1{\@bsphack |
| 1299 |
\vadjust{\vskip-\dp\strutbox |
| 1300 |
\hbox{\smash{\hbox to 0pt {\hss\color{marginnotecolor}% |
| 1301 |
\normalfont\small\bfseries |
| 1302 |
\hsize 1.5cm\rightskip.5cm minus.5cm |
| 1303 |
\vtop{\noindent New with #1}\ }}}% |
| 1304 |
\vskip\dp\strutbox }\strut\@esphack} |
| 1305 |
% |
| 1306 |
\def\CHANGED #1{\@bsphack |
| 1307 |
\vadjust{\vskip-\dp\strutbox |
| 1308 |
\hbox{\smash{\hbox to 0pt {\hss\color{marginwarningcolor}% |
| 1309 |
\normalfont\small\bfseries |
| 1310 |
\hsize 1.5cm\rightskip.5cm minus.5cm |
| 1311 |
\vtop{\noindent Changed at #1!}\ }}}% |
| 1312 |
\vskip\dp\strutbox }\strut\@esphack} |
| 1313 |
|
| 1314 |
\def\DNU#1{\@bsphack |
| 1315 |
\vadjust{\vskip-\dp\strutbox |
| 1316 |
\hbox{\smash{\hbox to 0pt {\hss\color{marginwarningcolor}% |
| 1317 |
\normalfont\small\bfseries |
| 1318 |
\hsize 1.5cm\rightskip.5cm minus.5cm |
| 1319 |
\vtop{\noindent Do not use! #1}\ }}}% |
| 1320 |
\vskip\dp\strutbox }\strut\@esphack} |
| 1321 |
|
| 1322 |
\def\UNSTABLE#1{\@bsphack |
| 1323 |
\vadjust{\vskip-\dp\strutbox |
| 1324 |
\hbox{\smash{\hbox to 0pt {\hss\color{marginwarningcolor}% |
| 1325 |
\normalfont\small\bfseries |
| 1326 |
\hsize 1.5cm\rightskip.5cm minus.5cm |
| 1327 |
\vtop{\noindent Unstable! #1}\ }}}% |
| 1328 |
\vskip\dp\strutbox }\strut\@esphack} |
| 1329 |
|
| 1330 |
\def\unstable#1{\@bsphack |
| 1331 |
\vadjust{\vskip-\dp\strutbox |
| 1332 |
\hbox{\smash{\hbox to 0pt {\hss\color{marginwarningcolor}% |
| 1333 |
\normalfont\small\bfseries |
| 1334 |
\hsize 1.5cm\rightskip.5cm minus.5cm |
| 1335 |
\vtop{\noindent unstable? #1}\ }}}% |
| 1336 |
\vskip\dp\strutbox }\strut\@esphack} |
| 1337 |
|
| 1338 |
\def\DEPRECATED #1{\@bsphack |
| 1339 |
\vadjust{\vskip-\dp\strutbox |
| 1340 |
\hbox{\smash{\hbox to 0pt {\hss\color{marginnotecolor}% |
| 1341 |
\normalfont\small\bfseries |
| 1342 |
\hsize 2cm\rightskip.5cm minus.5cm |
| 1343 |
\vtop{\noindent Deprecated! (#1)}\ }}}% |
| 1344 |
\vskip\dp\strutbox }\strut\@esphack} |
| 1345 |
% |
| 1346 |
\def\CHANGEDf #1{\@bsphack |
| 1347 |
\vadjust{\vskip-\dp\strutbox |
| 1348 |
\hbox{\smash{\hbox to 0pt {\hss\color{marginwarningcolor}% |
| 1349 |
\normalfont\small\bfseries |
| 1350 |
\hsize 1.5cm\rightskip.5cm minus.5cm |
| 1351 |
\vtop{\noindent Changed at #1!}\ |
| 1352 |
\kern\dimexpr\FrameSep+\FrameRule\relax}}}% |
| 1353 |
\vskip\dp\strutbox }\strut\@esphack} |
| 1354 |
% |
| 1355 |
\def\NewWithf #1{\@bsphack |
| 1356 |
\vadjust{\vskip-\dp\strutbox |
| 1357 |
\hbox{\smash{\hbox to 0pt {\hss\color{marginnotecolor}% |
| 1358 |
\normalfont\small\bfseries |
| 1359 |
\hsize 1.5cm\rightskip.5cm minus.5cm |
| 1360 |
\vtop{\noindent New with #1}\ |
| 1361 |
\kern\dimexpr\FrameSep+\FrameRule\relax}}}% |
| 1362 |
\vskip\dp\strutbox }\strut\@esphack} |
| 1363 |
|
| 1364 |
|
| 1365 |
% \centeredline: OUR OWN LITTLE MACRO FOR CENTERING LINES |
| 1366 |
% ======================================================= |
| 1367 |
|
| 1368 |
% 7 mars 2013 |
| 1369 |
% Note (2020): now a package |
| 1370 |
\usepackage{centeredline} |
| 1371 |
|
| 1372 |
% \leftedline |
| 1373 |
% =========== |
| 1374 |
|
| 1375 |
% 12 octobre 2014 |
| 1376 |
|
| 1377 |
% Note (2020): somewhat obsoleted for many years by my usage of |
| 1378 |
% everbatim and everbatim* environments. |
| 1379 |
|
| 1380 |
\newif\ifinlefted |
| 1381 |
|
| 1382 |
\newcommand*\leftedline {% |
| 1383 |
\ifhmode \\\relax |
| 1384 |
\def\leftedline@{\hss\egroup\hskip\z@skip\ignorespaces }% |
| 1385 |
\else |
| 1386 |
\def\leftedline@{\hss\egroup }% |
| 1387 |
\fi |
| 1388 |
\afterassignment\@leftedline |
| 1389 |
\let\next=} |
| 1390 |
\def\@leftedline |
| 1391 |
{\hbox to \linewidth \bgroup \inleftedtrue |
| 1392 |
\everbatimeverypar |
| 1393 |
\bgroup |
| 1394 |
\aftergroup\leftedline@ } |
| 1395 |
|
| 1396 |
% verbatim macros and environments |
| 1397 |
% ================================ |
| 1398 |
% |
| 1399 |
% June 2013, then October 2014. |
| 1400 |
% ----------------------------- |
| 1401 |
% |
| 1402 |
\catcode`_ 11 |
| 1403 |
|
| 1404 |
% some of my verbatim environments do not make the space active (\lverb e.g.). Then |
| 1405 |
% \do@noligs must be modified, \char`#1 must be followed by a space token, else, |
| 1406 |
% the `#1 expansion will swallow one space. |
| 1407 |
\def\do@noligs #1{% |
| 1408 |
\catcode`#1\active |
| 1409 |
\begingroup |
| 1410 |
\lccode`~`#1\relax |
| 1411 |
\lowercase{% |
| 1412 |
\endgroup\def~{\leavevmode\kern\z@\char`#1 }}% |
| 1413 |
} |
| 1414 |
|
| 1415 |
% \lowast |
| 1416 |
\def\lowast{\raisebox{-.25\height}{*}} |
| 1417 |
\catcode`* 13 |
| 1418 |
\def\makestarlowast {\let*\lowast\catcode`\*\active}% |
| 1419 |
\catcode`* 12 |
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
% \verb |
| 1424 |
% ===== |
| 1425 |
|
| 1426 |
% Initially, June 2013, then Sep 9, 2014, and Oct 9-12 2014 |
| 1427 |
% |
| 1428 |
% Initial motivation was simply that doc.sty and related classes \verb |
| 1429 |
% macro is with a hard-coded \ttfamily. There were further issues. |
| 1430 |
% |
| 1431 |
% 1. With |stuff with space|, paragraph reformatting in the Emacs/AUCTeX |
| 1432 |
% buffer caused havoc. Thus I wanted the input to accept linebreaks in |
| 1433 |
% its contents. |
| 1434 |
% |
| 1435 |
% 2. Hence I did not want to have obeyed spaces obeyed, (Emacs reflowing |
| 1436 |
% of paragraph in certain contexts often adds spaces at beginning of a line) |
| 1437 |
% |
| 1438 |
% 3. Also I wanted to allow hyphenated output, at least at some |
| 1439 |
% locations. I did a first version which treated spaces, \, {, and } |
| 1440 |
% specially. |
| 1441 |
% |
| 1442 |
% 4. At some point I wanted to add some colored background (I have |
| 1443 |
% dropped that since due to pdf file size increase). |
| 1444 |
% |
| 1445 |
% 5. And also I got fed up from the non-compatibility with footnotes due |
| 1446 |
% to catcode freeze. |
| 1447 |
% |
| 1448 |
% Because of 5. I opted for a \scantokens approach, hence for a macro |
| 1449 |
% with delimited argument. Here is what I do now, this is compatible |
| 1450 |
% with short verbs. |
| 1451 |
|
| 1452 |
\def\verbcolorcmd{\color{verbcolor}} |
| 1453 |
\def\verbsoftwrapiconcolorcmd{\color{verbsoftwrapiconcolor}} |
| 1454 |
|
| 1455 |
\def\restoreMicroFont {\def\MicroFont {\ttfamily\makestarlowast |
| 1456 |
\ifinlefted\else\verbcolorcmd\fi |
| 1457 |
}} |
| 1458 |
\restoreMicroFont |
| 1459 |
|
| 1460 |
\def\verb |
| 1461 |
{% |
| 1462 |
\relax \ifmmode\else\leavevmode\null\fi |
| 1463 |
\bgroup |
| 1464 |
\let\do\@makeother \dospecials |
| 1465 |
\@ifstar{\@sverb}% \verb* is used in the index (obsolete: no indices at 1.3e), |
| 1466 |
% leave it using ambient font |
| 1467 |
{\MicroFont % used to change font (\ttfamily), color, |
| 1468 |
% will make * active via \makestarlowast |
| 1469 |
\catcode 32 10 \endlinechar 32 % allows to fetch across line breaks |
| 1470 |
\frenchspacing % since 2024/01/15 not done globally in document |
| 1471 |
\@@jfverb}% |
| 1472 |
}% |
| 1473 |
% Note (Oct 12, 2014): in the improbable situation a newlinechar is |
| 1474 |
% found in the ##1, \scantokens will convert this to an end of line in |
| 1475 |
% its "write" phase, which will be then ignored in its "read" phase due |
| 1476 |
% to \endlinechar-1. This also avoids possible creation of \par which |
| 1477 |
% would defeat \@@jfverb@@. Thus it is good. |
| 1478 |
\def\@@jfverb #1{% |
| 1479 |
\ifcat\noexpand#1\noexpand~\catcode`#1\active\fi |
| 1480 |
% No problem with the EOL for the line where the short verb delimiter stands. |
| 1481 |
\def\next ##1#1{% |
| 1482 |
% 2022/06/04 |
| 1483 |
% automated hyperlink detection |
| 1484 |
% - \detokenize needed due to * \active from \makestarlowast in \MicroFont |
| 1485 |
% - gobbling first char rather than checking if it is backslash |
| 1486 |
% (and there is an \@empty first so gobbling two tokens) |
| 1487 |
% mark-up using \csbxint is better way as it allow hyphenation after xint |
| 1488 |
% Usage of \xintlabelprefix to modify behaviour in implementation part. |
| 1489 |
% This will NOT WORK if the catcodes were already frozen... |
| 1490 |
\ifcsname r@\xintlabelprefix\detokenize\expandafter{\xint_gobble_ii##1}\endcsname |
| 1491 |
\hyperref[\xintlabelprefix\detokenize\expandafter{\xint_gobble_ii##1}]{##1}% |
| 1492 |
\egroup |
| 1493 |
\else |
| 1494 |
% this will add \discretionary's for wrapping at end of line |
| 1495 |
\@vobeyspaces\everyeof{\relax}\endlinechar\m@ne |
| 1496 |
\expandafter\@@jfverb_a\scantokens\expandafter{##1}% |
| 1497 |
\fi}% |
| 1498 |
% hack with \@empty to prevent brace stripping if catcodes have been |
| 1499 |
% frozen earlier, like in footnotes. |
| 1500 |
\next \@empty |
| 1501 |
} |
| 1502 |
% We don't want a \discretionary at the very start. |
| 1503 |
% But then an empty argument is forbidden! |
| 1504 |
\def\@@jfverb_a #1{#1\@@jfverb_b } |
| 1505 |
|
| 1506 |
\def\@@jfverb_b #1{\ifx\relax #1% |
| 1507 |
\egroup |
| 1508 |
\else |
| 1509 |
% \penalty\z@, or rather (Oct 11, 2014) but I then adjust the textwidth |
| 1510 |
% precisely: |
| 1511 |
\discretionary{\copy\SoftWrapIcon}{}{}% |
| 1512 |
#1\expandafter\@@jfverb_b\fi |
| 1513 |
} |
| 1514 |
|
| 1515 |
|
| 1516 |
\DeclareFontFamily{U}{MdSymbolC}{} |
| 1517 |
\DeclareFontShape {U}{MdSymbolC}{m}{n}{<-> MdSymbolC-Regular}{} |
| 1518 |
\newbox\SoftWrapIcon |
| 1519 |
|
| 1520 |
\def\SetSoftWrapIcon{% |
| 1521 |
\setbox\SoftWrapIcon\hb@xt@\z@ |
| 1522 |
{\kern.5ex%\hb@xt@\z@%\fontdimen2\font |
| 1523 |
%{ |
| 1524 |
\smash{\lower3pt\hbox{% |
| 1525 |
\verbsoftwrapiconcolorcmd\usefont{U}{MdSymbolC}{m}{n}\char 151 |
| 1526 |
}}%\hss}% |
| 1527 |
\hss}% |
| 1528 |
} |
| 1529 |
|
| 1530 |
\AtBeginDocument {\SetSoftWrapIcon }% ok car ttzfamily déjà fait |
| 1531 |
|
| 1532 |
\catcode`_ 8 |
| 1533 |
|
| 1534 |
% everbatim environment |
| 1535 |
% ===================== |
| 1536 |
|
| 1537 |
\def\restoreMacroFont {\def\MacroFont {\ttfamily |
| 1538 |
\ifinlefted\else\color{everbatimfgcolor}\fi |
| 1539 |
}} |
| 1540 |
\restoreMacroFont |
| 1541 |
% Notice that \macrocode uses \macro@font which stores the \MacroFont meaning |
| 1542 |
% in force at \begin{document}. But doc.sty's verbatim uses current \MacroFont |
| 1543 |
% not the meaning at \begin{document}. Comprenne qui pourra... |
| 1544 |
|
| 1545 |
% October 13-14, 2014 |
| 1546 |
% Verbatim with an \everypar hook, mainly to have background color, followed by |
| 1547 |
% execution of the contents (not limited by a group-scope) |
| 1548 |
|
| 1549 |
\catcode`_ 11 |
| 1550 |
|
| 1551 |
\def\everbatim {\s@everbatim\@everbatim} |
| 1552 |
\@namedef{everbatim*}{\s@everbatim\@everbatimx} |
| 1553 |
|
| 1554 |
% Note: one can not use everbatim inside itself or everbatim* inside itself |
| 1555 |
\def\s@everbatim {% |
| 1556 |
% \ineverbtrue |
| 1557 |
\everbatimtop % put there size changes |
| 1558 |
\topsep \z@skip |
| 1559 |
\partopsep \z@skip |
| 1560 |
\itemsep \z@skip |
| 1561 |
\parsep \z@skip |
| 1562 |
\parskip \z@skip |
| 1563 |
\lineskip \z@skip |
| 1564 |
\let\do\@makeother \dospecials |
| 1565 |
\let\do\do@noligs \verbatim@nolig@list |
| 1566 |
\makestarlowast |
| 1567 |
\everbatimhook |
| 1568 |
\trivlist |
| 1569 |
\@topsepadd \z@skip |
| 1570 |
\item\relax |
| 1571 |
\leftskip \@totalleftmargin |
| 1572 |
\rightskip \z@skip |
| 1573 |
\parindent \z@ |
| 1574 |
\parfillskip\@flushglue |
| 1575 |
\parskip \z@skip |
| 1576 |
\@@par |
| 1577 |
\def\par{\leavevmode\null\@@par\pagebreak[1]}% |
| 1578 |
\everypar\expandafter{\the\everypar \unpenalty |
| 1579 |
\everbatimeverypar |
| 1580 |
\everypar \expandafter{\the\everypar\everbatimeverypar}% |
| 1581 |
}% |
| 1582 |
\obeylines \@vobeyspaces |
| 1583 |
} |
| 1584 |
% 27 mai 2022, plus de \small |
| 1585 |
\def\everbatimtop {\MacroFont }% |
| 1586 |
\let\everbatimhook\empty |
| 1587 |
\def\everbatimeverypar{\strut |
| 1588 |
{\color{everbatimbgcolor}\vrule\@width\linewidth }% |
| 1589 |
\kern-\linewidth |
| 1590 |
\kern\everbatimindent } |
| 1591 |
\def\everbatimindent {\z@}% voir plus loin atbegindocument |
| 1592 |
|
| 1593 |
\begingroup |
| 1594 |
\lccode`X 13 |
| 1595 |
\catcode`X \active |
| 1596 |
\lccode`Y `* % this is because of \makestarlowast. |
| 1597 |
% I have to think whether this is useful: obviously if I were to provide |
| 1598 |
% everbatim and everbatim* in a package I wouldn't do that. |
| 1599 |
\catcode`Y \active |
| 1600 |
\catcode`| 0 \catcode`[ 1 \catcode`] 2 \catcode`* 12 |
| 1601 |
\catcode`{ 12 \catcode`} 12 |catcode`\\ 12 |
| 1602 |
|lowercase[|endgroup% both freezes catcodes and converts X to active ^^M |
| 1603 |
|def|@everbatim #1X#2\end{everbatim}% |
| 1604 |
[#2|end[everbatim]|everbatimbottom ] |
| 1605 |
|def|@everbatimx #1X#2\end{everbatimY}]% |
| 1606 |
{#2\end{everbatim*}% |
| 1607 |
% No group here: this allows executed code to make macro |
| 1608 |
% definitions which may reused in later uses of everbatim. |
| 1609 |
% refactored 2022/01/11, rather than passing \newlinechar value |
| 1610 |
% as was done formerly via everbatim* (see above) and fetching it here as #1 |
| 1611 |
% it is thus assumed executed contents do not terminate a scope |
| 1612 |
\edef\everbatimrestorenewlinechar{\newlinechar\the\newlinechar\relax}% |
| 1613 |
\newlinechar 13 |
| 1614 |
% refactored 2022/01/11 to fix a \parskip issue |
| 1615 |
% attention, \parskip thus set to zero for execution of contents |
| 1616 |
% reason: avoid extra space if everbatim* is in an \item of a list |
| 1617 |
% between verbatim and output of execution, if it starts a paragraph |
| 1618 |
% a \vskip-\parskip approach (cf former \everbatimundoparskip) |
| 1619 |
% would be no good in case contents create a display |
| 1620 |
\edef\everbatimrestoreparskip{\parskip\the\parskip\relax}% |
| 1621 |
\parskip\z@skip |
| 1622 |
% execution of the contents (expected to be LaTeX code...) |
| 1623 |
\everbatimxprehook |
| 1624 |
\scantokens {#2}% |
| 1625 |
\everbatimrestorenewlinechar |
| 1626 |
\everbatimrestoreparskip |
| 1627 |
\everbatimxposthook |
| 1628 |
% input after \end{everbatim*} on same line in source is allowed |
| 1629 |
}% |
| 1630 |
% L'espace venant du endofline final mis par \scantokens sera inhibé si #2 se |
| 1631 |
% termine par un % ou un \x, etc... |
| 1632 |
|
| 1633 |
\let\everbatimbottom\empty |
| 1634 |
|
| 1635 |
\def\endeverbatim{\if@newlist \leavevmode\fi\endtrivlist} |
| 1636 |
\@namedef{endeverbatim*}{\endeverbatim} |
| 1637 |
|
| 1638 |
% There is an issue with how to inhibit the \parskip if execution |
| 1639 |
% of contents generate a paragraph. Because the design is aimed at |
| 1640 |
% keeping output close to verbatim input. |
| 1641 |
% Even in a document with zero \parskip overall, the \parskip will possibly |
| 1642 |
% be reset to some annoying high value e.g. if we are in an \item of a list |
| 1643 |
% environment. |
| 1644 |
% In this documentation, many usage of everbatim* are indeed inside such |
| 1645 |
% \item's. The former (2020) approach was to do: |
| 1646 |
% \@namedef{endeverbatim*}{\endeverbatim\aftergroup\everbatimundoparskip} |
| 1647 |
% \def\everbatimundoparskip{\vbox{}\kern-\baselineskip\kern-\parskip\leavevmode} |
| 1648 |
% but it had its problems if executed contents start a display, with |
| 1649 |
% not enough vertical whitespace then |
| 1650 |
% Also if source had two everbatim* environments one after the other, |
| 1651 |
% the first one not producing any ouput, this caused overlap. |
| 1652 |
% The new approach (Feb 2022) is much simpler and avoids these problems. |
| 1653 |
|
| 1654 |
|
| 1655 |
% These definitions are provisory and get overwritten below in order |
| 1656 |
% to avoid color stack overflow problems with latex + dvipdfmx, and xelatex |
| 1657 |
\def\everbatimxprehook {\colorlet{everbsavedcolor}{.}% |
| 1658 |
\color{everbatimxfgcolor}}% |
| 1659 |
\def\everbatimxposthook{\color{everbsavedcolor}} |
| 1660 |
% actual definitions: |
| 1661 |
{\sbox0{\color{everbatimxfgcolor}\xdef\@tempa{\current@color}}} |
| 1662 |
\ifpdf |
| 1663 |
\ifluatex |
| 1664 |
\edef\everbatimxprehook |
| 1665 |
{\pdfextension colorstack\noexpand\@pdfcolorstack push{\@tempa}\relax} |
| 1666 |
\def\everbatimxposthook |
| 1667 |
{\pdfextension colorstack\@pdfcolorstack pop\relax} |
| 1668 |
\else |
| 1669 |
\edef\everbatimxprehook |
| 1670 |
{\pdfcolorstack\noexpand\@pdfcolorstack push{\@tempa}\relax} |
| 1671 |
\def\everbatimxposthook{\pdfcolorstack\@pdfcolorstack pop\relax} |
| 1672 |
\fi |
| 1673 |
\else |
| 1674 |
% Le 24 juin 2021 je vérifie que ceci est encore nécessaire avex xelatex |
| 1675 |
% (sinon color leak de OrangeRed à partir de la page 97 dans la doc) |
| 1676 |
% et aussi pour dvipdfmx (sinon color stack overflow au moment de la page 98 |
| 1677 |
% lors du passage par dvipdfmx) |
| 1678 |
\ifxetex |
| 1679 |
\edef\everbatimxprehook{\special{color push \@tempa}} |
| 1680 |
\def\everbatimxposthook{\special{color pop}} |
| 1681 |
\else |
| 1682 |
\ifnum\Withdvipdfmx=1 |
| 1683 |
\edef\everbatimxprehook{\special{color push \@tempa}} |
| 1684 |
\def\everbatimxposthook{\special{color pop}} |
| 1685 |
\fi |
| 1686 |
\fi |
| 1687 |
\fi |
| 1688 |
|
| 1689 |
|
| 1690 |
|
| 1691 |
% \everb |
| 1692 |
% ====== |
| 1693 |
% |
| 1694 |
% Original was called \dverb and I did it in June 2013. |
| 1695 |
% Then after doing everbatim, I transformed \dverb, now called \everb |
| 1696 |
% for itself being as compatible as standard verbatim with list making |
| 1697 |
% surrounding environments. |
| 1698 |
% Supposed to be used as |
| 1699 |
% \everb|@ this will be ignored |
| 1700 |
% stuff |
| 1701 |
% escape character: " |
| 1702 |
% | not necessarily starting a line. |
| 1703 |
% I chose @ as comment character, mainly for pretty-formatting of the |
| 1704 |
% source, this can be changed by \everbhook. |
| 1705 |
|
| 1706 |
% " comme caractère d'échappement. Par exemple pour colorier des parties. |
| 1707 |
% Le "" redonne à { et } leurs catcodes normaux mais attention c'est |
| 1708 |
% alors à utiliser avec un terminateur ;! pour la partie concernée |
| 1709 |
\def\restoreeverbhook{\def\everbhook{% |
| 1710 |
\def\"{\begingroup\catcode123 1 \catcode 125 2 \everbescape }% |
| 1711 |
\catcode`\" 0 \catcode`\@ 14 |
| 1712 |
}}\restoreeverbhook |
| 1713 |
|
| 1714 |
\def\everbescape #1;!{#1\endgroup } |
| 1715 |
|
| 1716 |
\def\everb {% |
| 1717 |
\bgroup |
| 1718 |
\let\everbatimhook\everbhook |
| 1719 |
\s@everbatim |
| 1720 |
\@everb |
| 1721 |
} |
| 1722 |
|
| 1723 |
\def\@everb #1{\catcode`#1\active |
| 1724 |
\lccode`\~`#1% |
| 1725 |
\lowercase{\def~{\if@newlist \leavevmode\fi |
| 1726 |
\endtrivlist |
| 1727 |
\egroup |
| 1728 |
\@doendpe |
| 1729 |
\everbatimbottom }}% |
| 1730 |
}% |
| 1731 |
|
| 1732 |
\catcode`_8 |
| 1733 |
|
| 1734 |
|
| 1735 |
% \printnumber |
| 1736 |
% ============ |
| 1737 |
|
| 1738 |
\catcode`_ 11 |
| 1739 |
\catcode`& 3 |
| 1740 |
\def\allowsplits_a {\futurelet\printnumber_token\allowsplits_b }% |
| 1741 |
\def\allowsplits_b{\ifx\printnumber_token\@sptoken\space\fi\allowsplits_c } |
| 1742 |
\def\allowsplits_c #1{\ifx \xint_dothis\xint_gobble_i\fi |
| 1743 |
\if ,#1\xint_dothis {\discretionary{\rlap,}{}{,}}\fi |
| 1744 |
\xint_orthat{\discretionary |
| 1745 |
{\copy\SoftWrapIcon}% |
| 1746 |
{}% |
| 1747 |
{}#1}\allowsplits_a }% |
| 1748 |
|
| 1749 |
\def\printnumber #1{\expandafter\allowsplits_a \romannumeral-`0#1&}% |
| 1750 |
\hyphenpenalty \z@ |
| 1751 |
|
| 1752 |
\catcode`& 4 |
| 1753 |
\catcode`_ 8 |
| 1754 |
|
| 1755 |
% Parameters for lists |
| 1756 |
% ==================== |
| 1757 |
\AtBeginDocument{% |
| 1758 |
\leftmargini \dimexpr4\fontcharwd\font`X\relax |
| 1759 |
\leftmarginii\dimexpr3\fontcharwd\font`X\relax |
| 1760 |
\leftmarginiii \leftmarginii |
| 1761 |
\leftmarginiv \leftmarginii |
| 1762 |
\parindent\dimexpr2\fontcharwd\font`X\relax |
| 1763 |
\leftmargin\leftmargini % pourquoi pas 0? |
| 1764 |
% formerly everbatim indent was set to leftmargingi, reduce it (2017/08/26) |
| 1765 |
% \edef\everbatimindent{\the\dimexpr\leftmargini\relax\space }% |
| 1766 |
% setting it to \parindent does not work with \everb construct |
| 1767 |
% \def\everbatimindent{\parindent}% |
| 1768 |
\edef\everbatimindent{\the\dimexpr2\fontcharwd\font`X\relax\space}% |
| 1769 |
\cftsubsecnumwidth 2\leftmarginii |
| 1770 |
\cftsubsubsecnumwidth 2\leftmargini |
| 1771 |
\cftsubsecindent 0pt |
| 1772 |
\cftsubsubsecindent \cftsubsecnumwidth |
| 1773 |
}% |
| 1774 |
|
| 1775 |
% ========== |
| 1776 |
% Hyperlinks |
| 1777 |
% ========== |
| 1778 |
|
| 1779 |
% \csa, \csbxint, \csh etc... |
| 1780 |
% =========================== |
| 1781 |
|
| 1782 |
% The underscore and caret things are for implementation part |
| 1783 |
\DeclareRobustCommand\csa[1] |
| 1784 |
{{\ttzfamily\char92\endlinechar-1 |
| 1785 |
\makestarlowast \catcode`_ 12 \catcode`^ 12 |
| 1786 |
\scantokens\expandafter{\detokenize{#1}}}} |
| 1787 |
% csan: n means no backslash |
| 1788 |
\DeclareRobustCommand\csan[1] |
| 1789 |
{{\ttzfamily\endlinechar-1 |
| 1790 |
\makestarlowast \catcode`_ 12 \catcode`^ 12 |
| 1791 |
\scantokens\expandafter{\detokenize{#1}}}} |
| 1792 |
% For some legacy reasons rather than doing: |
| 1793 |
% \pdfstringdefDisableCommands{% |
| 1794 |
% \def\csa#1{\textbackslash\detokenize{#1}}% |
| 1795 |
% \def\csan#1{\detokenize{#1}}% |
| 1796 |
% }% |
| 1797 |
% I defined years ago variants for usage within section titles. These |
| 1798 |
% variants will get redefined in implementation section to automatically |
| 1799 |
% insert \label's and use \csa and \csan. Here in user manual, they simply |
| 1800 |
% use \csa or \csan, but are careful to do \texorpdfstring. |
| 1801 |
\newcommand\csh[1] |
| 1802 |
{\texorpdfstring{\csa{#1}}{\textbackslash\detokenize{#1}}} |
| 1803 |
% This one is actually never used inside the user manual, only encountered |
| 1804 |
% in the implementation part. |
| 1805 |
\newcommand\cshn[1] |
| 1806 |
{\texorpdfstring{\csan{#1}}{\detokenize{#1}}} |
| 1807 |
% Let's preserve these meanings for when I will want to use them in sections |
| 1808 |
% of the implementation part but not insert labels. |
| 1809 |
\let\cshnolabel\csh |
| 1810 |
\let\cshnnolabel\cshn |
| 1811 |
% 2022/06/10 |
| 1812 |
% If producing xint-all.pdf add hyperlinks from user documentation |
| 1813 |
% to source code. Should have I used some superscript? Less trouble |
| 1814 |
% and less work intensive for TeX I guess than the centered align. |
| 1815 |
% \def\myalign@vbox#1{\leavevmode\vbox{\baselineskip\z@skip \lineskip.75ex% |
| 1816 |
% \ialign{\hfil##\hfil\crcr#1\crcr}}} |
| 1817 |
% %%\def\oalign#1{\leavevmode\vtop{\baselineskip\z@skip \lineskip.25ex% |
| 1818 |
% %% \ialign{##\crcr#1\crcr}}} |
| 1819 |
% \myalign@vbox{\hyperref[\xintimplabelprefix\detokenize{#1}]{\usebox\sourcelinkbox}\cr |
| 1820 |
% \csa{#1}}% |
| 1821 |
\def\myalign@vbox#1{%\leavevmode |
| 1822 |
\vbox{% \@tempboxa is not used by \smash... and I hope \hyperref too |
| 1823 |
\baselineskip\z@skip\lineskip.75ex\relax |
| 1824 |
\sbox\@tempboxa{\csa{#1}}% |
| 1825 |
\hbox to\wd\@tempboxa{\hss |
| 1826 |
\hyperref[\xintimplabelprefix\detokenize{#1}]{\usebox\sourcelinkbox}% |
| 1827 |
\hss}% |
| 1828 |
\box\@tempboxa }% |
| 1829 |
}% |
| 1830 |
|
| 1831 |
\newsavebox\sourcelinkbox |
| 1832 |
% \familydefault already configured |
| 1833 |
% trying to add some \vphantom{X} has no impact it seems on the |
| 1834 |
% size of the clickable area (tested with Skim and Preview on mac os) |
| 1835 |
% so using \small not \footnotesize |
| 1836 |
\sbox\sourcelinkbox{\color{macrocodelinktosectioncolor}% |
| 1837 |
\normalfont\small\itshape source} |
| 1838 |
\def\cswithsourcelink#1{\smash{\myalign@vbox{#1}}}% |
| 1839 |
% the references should exist on second LaTeX pass |
| 1840 |
% and we don't want complications in tables of contents |
| 1841 |
\def\csperhapswithlink#1{\ifx\thepage\relax\csa{#1}\else |
| 1842 |
\ifcsname r@\xintimplabelprefix\detokenize{#1}\endcsname |
| 1843 |
\cswithsourcelink{#1}% |
| 1844 |
\else |
| 1845 |
\csa{#1}% |
| 1846 |
\fi\fi |
| 1847 |
} |
| 1848 |
\ifnum\doxintsource=0 \ifnum\NoSourceCode=0 |
| 1849 |
\renewcommand\csh[1] |
| 1850 |
{\texorpdfstring |
| 1851 |
{\csperhapswithlink{#1}} |
| 1852 |
{\textbackslash\detokenize{#1}}% |
| 1853 |
} |
| 1854 |
% \renewcommand\cshn[1] |
| 1855 |
% but it is used nowhere in user manual |
| 1856 |
\fi\fi |
| 1857 |
|
| 1858 |
% The "b" is there originally for "blue" in fact, from the hyperlink. |
| 1859 |
\DeclareRobustCommand\csb [1] |
| 1860 |
{\perhapshyperref[\xintlabelprefix\detokenize{#1}]% |
| 1861 |
{{\char92 \endlinechar-1 |
| 1862 |
\makestarlowast \catcode`_ 12 \catcode`^ 12 |
| 1863 |
\scantokens\expandafter{\detokenize{#1}}}}} |
| 1864 |
\DeclareRobustCommand\csbn[1] |
| 1865 |
{\perhapshyperref[\xintlabelprefix\detokenize{#1}]% |
| 1866 |
{{\endlinechar-1 |
| 1867 |
\makestarlowast \catcode`_ 12 \catcode`^ 12 |
| 1868 |
\scantokens\expandafter{\detokenize{#1}}}}} |
| 1869 |
\DeclareRobustCommand\csbxint[1] |
| 1870 |
{\perhapshyperref[\xintlabelprefix\detokenize{xint#1}]% |
| 1871 |
{{\char92\mbox{xint}\-\endlinechar-1 |
| 1872 |
\makestarlowast \catcode`_ 12 \catcode`^ 12 |
| 1873 |
\scantokens\expandafter{\detokenize{#1}}}}} |
| 1874 |
\DeclareRobustCommand\csbXINT[1] |
| 1875 |
{\perhapshyperref[\xintlabelprefix\detokenize{XINT#1}]% |
| 1876 |
{{\char92\mbox{XINT}\-\endlinechar-1 |
| 1877 |
\makestarlowast \catcode`_ 12 \catcode`^ 12 |
| 1878 |
\scantokens\expandafter{\detokenize{#1}}}}} |
| 1879 |
|
| 1880 |
% 2022/06/08, I finally add this |
| 1881 |
% although this is is not immediately useful as I have interiorized for years |
| 1882 |
% not to use \csbxint et al. in section titles... |
| 1883 |
\pdfstringdefDisableCommands{% |
| 1884 |
\let\csb\cs % \cs already in DisableCommands, I hope its redefinition is done |
| 1885 |
% first, well yes one has to chase \ltx@GlobalAppendToMacro |
| 1886 |
% all the way to ltxcmds... |
| 1887 |
\let\csbn\detokenize |
| 1888 |
\def\csbxint#1{\textbackslash xint\detokenize{#1}}% |
| 1889 |
\def\csbXINT#1{\textbackslash XINT\detokenize{#1}}% |
| 1890 |
}% |
| 1891 |
|
| 1892 |
% \func, \funcdesc, \keyword, \keyworddesc, \prec, \precdesc, \oper, \operdesc |
| 1893 |
% ============================================================================ |
| 1894 |
|
| 1895 |
\newcommand\func[1]{\hyperlink{\detokenize{func-#1}}{#1}()} |
| 1896 |
\newcommand\funcdesc[2][x]{\item[#2({#1})]\hypertarget{\detokenize{func-#2}}{}}% |
| 1897 |
|
| 1898 |
\newcommand\keyword[1]{\hyperlink{\detokenize{kwd-#1}}{#1}} |
| 1899 |
\newcommand\keyworddesc[1]{\item[#1]\hypertarget{\detokenize{kwd-#1}}{}}% |
| 1900 |
|
| 1901 |
\let\prec\relax % sinon, c'est \mathchar"321E |
| 1902 |
\newcommand\prec[1]{\hyperlink{\detokenize{prec-#1}}{#1}} |
| 1903 |
\newcommand\precdesc[1]{\item[\texttt{#1}]\hypertarget{\detokenize{prec-#1}}{}\leavevmode}% |
| 1904 |
|
| 1905 |
%\let\var\relax % défini par koma-script-source-doc que scrdoc |
| 1906 |
% utilise avec LaTeX 2022/06/01 |
| 1907 |
% mais finalement je n'utilise plus scrdoc/ltxdoc |
| 1908 |
% mais doc directement. |
| 1909 |
\newcommand\var[1]{\hyperlink{\detokenize{var-#1}}{#1}} |
| 1910 |
\newcommand\vardesc[1]{\item[#1]\hypertarget{\detokenize{var-#1}}{}}% |
| 1911 |
|
| 1912 |
\newcommand\oper[1]{\hyperlink{\detokenize{oper-#1}}{#1}} |
| 1913 |
\newcommand\operdesc[1]{\item[\texttt{#1}]\hypertarget{\detokenize{oper-#1}}{}}% |
| 1914 |
|
| 1915 |
|
| 1916 |
% \xintname, \xintnameimp etc... |
| 1917 |
% ============================== |
| 1918 |
|
| 1919 |
|
| 1920 |
|
| 1921 |
\xintForpair #1#2 in |
| 1922 |
{(kernel,kernel), |
| 1923 |
(tools,tools), |
| 1924 |
(core,core),(,xint),(binhex,binhex),(gcd,gcd),% |
| 1925 |
(frac,frac),(series,series),(cfrac,cfrac),(expr,expr),% |
| 1926 |
(trig, trig), (log, log)} |
| 1927 |
\do |
| 1928 |
{% |
| 1929 |
\expandafter\def\csname xint#1name\endcsname |
| 1930 |
{\texorpdfstring |
| 1931 |
{\perhapshyperref[sec:#2]% |
| 1932 |
{{\color{xintnamecolor}\MakeNameUp |
| 1933 |
{\mbox{xint}\-#1} |
| 1934 |
{xint#1}% |
| 1935 |
}% |
| 1936 |
}% |
| 1937 |
}% |
| 1938 |
{xint#1}% |
| 1939 |
\xspace }% |
| 1940 |
\expandafter\def\csname xint#1nameimp\endcsname |
| 1941 |
{\texorpdfstring |
| 1942 |
{\perhapshyperref[sec:#2imp]% |
| 1943 |
{{\color{xintnameimpcolor}\MakeNameUp |
| 1944 |
{\mbox{xint}\-#1} |
| 1945 |
{xint#1}% |
| 1946 |
}% |
| 1947 |
}% |
| 1948 |
}% |
| 1949 |
{xint#1}% |
| 1950 |
\xspace }% |
| 1951 |
}% |
| 1952 |
|
| 1953 |
\def\xintbundlename |
| 1954 |
{\texorpdfstring |
| 1955 |
{\perhapshyperref[sec:bundle]% |
| 1956 |
{{\color{xintnamecolor}\MakeNameUp |
| 1957 |
{\mbox{xint} bundle} |
| 1958 |
{xintbundle}% |
| 1959 |
}% |
| 1960 |
}% |
| 1961 |
}% |
| 1962 |
{xint bundle}% |
| 1963 |
\xspace }% |
| 1964 |
|
| 1965 |
\def\DOCxintfrontpage |
| 1966 |
{\perhapshyperref[frontpage]{{\color{xintnamecolor}TOC}}}% |
| 1967 |
|
| 1968 |
\ifnum\doxintsource=1 |
| 1969 |
% xintsource.pdf |
| 1970 |
\gdef\DOCxintfrontpage |
| 1971 |
{\perhapshyperref[frontpage]{{\color{xintnameimpcolor}TOC}}}% |
| 1972 |
\else |
| 1973 |
\ifnum\NoSourceCode=0 |
| 1974 |
% xint-all.pdf |
| 1975 |
% Not using \hypersetup with linkcolor because a few pages are with |
| 1976 |
% a TOC à cheval on two pages, and my eTOCs are configured to do |
| 1977 |
% \hypersetup{hidelinks} |
| 1978 |
\protected\def\DOCxintfrontpage |
| 1979 |
{\smash{\vbox{\hbox{\perhapshyperref[partiii]{{\color{xintnameimpcolor}TOC}}}% |
| 1980 |
\kern1ex |
| 1981 |
\hbox{\perhapshyperref[frontpage]{{\color{xintnamecolor}TOC}}}}}}% |
| 1982 |
\fi\fi |
| 1983 |
|
| 1984 |
\protected\def\MakeNameUp#1#2{% |
| 1985 |
\ifcsname #2nameUp\endcsname |
| 1986 |
\expandafter\@firstoftwo\else |
| 1987 |
\expandafter\@secondoftwo |
| 1988 |
\fi |
| 1989 |
% \ifinheader 2020/01/30 |
| 1990 |
{\ifinheader\fbox{\textup{#1}}\else#1\fi}% |
| 1991 |
{#1}% |
| 1992 |
} |
| 1993 |
\newif\ifinheader |
| 1994 |
% doit être protégé |
| 1995 |
\protected\def\inheadertrue{\let\ifinheader\iftrue} |
| 1996 |
|
| 1997 |
% \RaisedLabel |
| 1998 |
% ============ |
| 1999 |
|
| 2000 |
% Samedi 16 juin 2018 à 15:23:22 |
| 2001 |
% trick to see header of target page |
| 2002 |
% there is probably better way to use the already in place |
| 2003 |
% anchor from \section, but no time to go into hyperref source |
| 2004 |
\newcommand\RaisedLabel[2][6]{% |
| 2005 |
\vspace*{-#1\baselineskip}% |
| 2006 |
\begingroup |
| 2007 |
\let\leavevmode\relax\phantomsection |
| 2008 |
\label{#2}% |
| 2009 |
\endgroup |
| 2010 |
\vspace*{#1\baselineskip}% |
| 2011 |
} |
| 2012 |
% It seems I need this for a bookmark in xint-all.pdf |
| 2013 |
% reaching the top of the page where Part III starts |
| 2014 |
% 2022/06/10 |
| 2015 |
\newcommand\RaisedTarget[2][6]{% |
| 2016 |
\vspace*{-#1\baselineskip}% |
| 2017 |
\hypertarget{#2}{}% |
| 2018 |
\vspace*{#1\baselineskip}% |
| 2019 |
} |
| 2020 |
|
| 2021 |
% begin{document} |
| 2022 |
% =============== |
| 2023 |
% \ttzfamily done at begin document |
| 2024 |
|
| 2025 |
\DeclareRobustCommand\ctanpackage[1]{\href{https://ctan.org/pkg/#1}{#1}} |
| 2026 |
|
| 2027 |
\makeatother |
| 2028 |
\begin{document}\thispagestyle{empty} |
| 2029 |
\pdfbookmark[1]{Title page}{TOP} |
| 2030 |
\def\partname{Part} |
| 2031 |
\addto\captionsenglish{\def\partname{Part}} |
| 2032 |
|
| 2033 |
|
| 2034 |
\ifnum\doxintsource=1 |
| 2035 |
\noindent\begin{minipage}[t][8\baselineskip][c]{\linewidth} |
| 2036 |
\normalfont\Huge |
| 2037 |
\centering |
| 2038 |
The \xintexprnameimp and allied packages source code\par |
| 2039 |
\else |
| 2040 |
\begingroup |
| 2041 |
\normalfont\Huge |
| 2042 |
\centering |
| 2043 |
The \xintexprname and allied packages\par |
| 2044 |
\endgroup |
| 2045 |
\fi |
| 2046 |
\RaisedLabel{frontpage} |
| 2047 |
|
| 2048 |
\normalsize\ttzfamily |
| 2049 |
{\centering |
| 2050 |
\textsc{Jean-Fran\c cois Burnol}\par |
| 2051 |
\footnotesize |
| 2052 |
jfbu (at) free (dot) fr\par |
| 2053 |
Package version: \xintbndlversion\ (\xintbndldate); |
| 2054 |
documentation date: \xintdocdate.\par |
| 2055 |
{From source file \texttt{xint.dtx}. \xintdtxtimestamp.}\par |
| 2056 |
} |
| 2057 |
|
| 2058 |
\ifnum\doxintsource=1 |
| 2059 |
\end{minipage} |
| 2060 |
\else |
| 2061 |
\medskip |
| 2062 |
\fi |
| 2063 |
|
| 2064 |
|
| 2065 |
% 31 janvier 2020 |
| 2066 |
% 2022/06/10 no need for \texorpdfstring here |
| 2067 |
|
| 2068 |
\def\DOCxintexprintro |
| 2069 |
{\perhapshyperref[part:1]{{\color{xintnamecolor}% |
| 2070 |
\MakeNameUp{Start here}% |
| 2071 |
{Start here}% |
| 2072 |
}% |
| 2073 |
}% |
| 2074 |
}% |
| 2075 |
|
| 2076 |
\def\DOCxintexprmacros |
| 2077 |
{\perhapshyperref[sec:oldxintexpr]{{\color{xintnamecolor}% |
| 2078 |
\MakeNameUp{xintexpr (old doc)}% |
| 2079 |
{xintexpr (old doc)}% |
| 2080 |
}% |
| 2081 |
}% |
| 2082 |
}% |
| 2083 |
|
| 2084 |
\def\DOCexamples |
| 2085 |
{\perhapshyperref[sec:examples]{{\color{xintnamecolor}% |
| 2086 |
\MakeNameUp{Examples}{Examples}% |
| 2087 |
}% |
| 2088 |
}% |
| 2089 |
}% |
| 2090 |
|
| 2091 |
% Vendredi 15 juin 2018 |
| 2092 |
% Someone makes the comma active (not me! not sure if doc.sty or KOMA) and |
| 2093 |
% this derails xspace.sty, in the headers, as it uses \scantokens on a list of |
| 2094 |
% tokens, so it fails to recognize the commas which of course are of catcode12 |
| 2095 |
% Update Friday, June 25 2021 |
| 2096 |
% I finally take the time to go to the root of this: the culprit is everbatim |
| 2097 |
% when its output crosses pagebreaks, but the same of course happens with |
| 2098 |
% verbatim. |
| 2099 |
% I opened ticket https://github.com/latex3/latex2e/issues/600 |
| 2100 |
\def\xintRunningHeader{{\inheadertrue\catcode`,12\relax |
| 2101 |
\DOCxintfrontpage, |
| 2102 |
\DOCxintexprintro, |
| 2103 |
\xintexprname, |
| 2104 |
\DOCxintexprmacros, |
| 2105 |
\xinttrigname, |
| 2106 |
\xintlogname, |
| 2107 |
\xinttoolsname, |
| 2108 |
\DOCexamples, |
| 2109 |
\xintbundlename}} |
| 2110 |
\markboth{\makebox[0pt]{\xintRunningHeader}}{\makebox[0pt]{\xintRunningHeader}} |
| 2111 |
|
| 2112 |
% 18 mai 2019, turned into an environment 27 mai 2022 |
| 2113 |
\newenvironment{TeXnote}{\par\small\medskip\noindent\textbf{\TeX-hackers note: |
| 2114 |
}}{\par\medskip} |
| 2115 |
|
| 2116 |
% Skips safely. |
| 2117 |
\ifnum\doxintsource=1 |
| 2118 |
\catcode`+ 0 \catcode0 9 % n'importe quoi sauf 15 (car ^^@) |
| 2119 |
\catcode`\\ 12 |
| 2120 |
+expandafter+iffalse+fi |
| 2121 |
\fi |
| 2122 |
% |
| 2123 |
\makeatletter |
| 2124 |
|
| 2125 |
\etocsetlevel{toctobookmark}{6} |
| 2126 |
|
| 2127 |
|
| 2128 |
|
| 2129 |
\etocsetlevel{xinttable}{2}% subsection |
| 2130 |
|
| 2131 |
\let\orig@etoctoclineleaders\etoctoclineleaders |
| 2132 |
\def\etoctoclineleaders |
| 2133 |
{\hbox{\normalfont\normalsize\hbox to 1ex {\hss.\hss}}} |
| 2134 |
\def\etocbelowtocskip{\z@skip} |
| 2135 |
\def\etocinnertopsep{\z@skip} |
| 2136 |
|
| 2137 |
\etocsettocstyle{}{} |
| 2138 |
\etocsettagdepth {part1A}{subsection}% style de subsection défini dans preamble |
| 2139 |
\etocsettagdepth {part1B}{section}% style de section aussi |
| 2140 |
\etocsettagdepth {macros}{none} |
| 2141 |
\etocsettagdepth {implementation}{none} |
| 2142 |
|
| 2143 |
\etocsettocdepth{subsection} |
| 2144 |
%% Legacy etoc style for part, with an improvement to get "Part" |
| 2145 |
%% hyperlinked |
| 2146 |
%% Also some hack to let the TOC of xint-all.pdf fit on one page |
| 2147 |
%% `part': |
| 2148 |
\etocsetstyle{part} |
| 2149 |
{\ifnum\doxintsource=0 \ifnum\NoSourceCode=0 % both true only for xint-all.pdf |
| 2150 |
\def\etocabovetocskip{\z@skip}% |
| 2151 |
\def\etocsepminusone{\bigskipamount}% |
| 2152 |
\def\etocsepzero{\medskipamount}% |
| 2153 |
\def\tocstylesectionVSKIP{\vskip\smallskipamount}% |
| 2154 |
\fi\fi |
| 2155 |
\addpenalty\@M\etocskipfirstprefix} |
| 2156 |
{\addpenalty\@secpenalty} |
| 2157 |
{% |
| 2158 |
\begingroup |
| 2159 |
\etocfontminusone |
| 2160 |
\addvspace{\etocsepminusone}% |
| 2161 |
\parindent \z@ |
| 2162 |
\leftskip \etocminusoneleftmargin |
| 2163 |
\rightskip \etocminusonerightmargin |
| 2164 |
\parfillskip \@flushglue |
| 2165 |
% original from etoc : |
| 2166 |
%\vbox{\etocifnumbered{\etocpartname\enspace\etocnumber.\quad}{}...} |
| 2167 |
\vbox{\etocifnumbered{\etoclink{\etocpartname\enspace\etocthenumber.}\quad}{}% |
| 2168 |
\etocname |
| 2169 |
\baselineskip\etocbaselinespreadminusone\baselineskip |
| 2170 |
\par}% |
| 2171 |
\addpenalty\@M |
| 2172 |
\addvspace{\etocsepzero}% |
| 2173 |
\endgroup} |
| 2174 |
{}% |
| 2175 |
|
| 2176 |
% THIS IS THE FIRST HALF OF THE TOC ON PAGE 1 |
| 2177 |
\tableofcontents |
| 2178 |
|
| 2179 |
|
| 2180 |
% May 23 2022, some hack to replace the \etocmulticolstyle and |
| 2181 |
% have same output except that Part line will use full line width |
| 2182 |
% |
| 2183 |
% Formerly I used this but the Part was then folded... |
| 2184 |
% \etocmulticolstyle [2]{\parskip\z@skip%\raggedcolumns |
| 2185 |
% \setlength{\columnsep}{\leftmarginii}% |
| 2186 |
% \setlength{\columnseprule}{0pt}% |
| 2187 |
% }% |
| 2188 |
% |
| 2189 |
\etocsetstyle{part}% @minusone in etoc.sty |
| 2190 |
{\if1\ifnum\doxintsource=1 0\fi\ifnum\NoSourceCode=1 0\fi1% xint-all.pdf |
| 2191 |
\def\etocabovetocskip{\z@skip}% |
| 2192 |
\def\etocsepminusone{\bigskipamount}% |
| 2193 |
\def\etocsepzero{\medskipamount}% |
| 2194 |
\fi |
| 2195 |
\addpenalty\@M\etocskipfirstprefix} |
| 2196 |
% May 23, 2022 |
| 2197 |
% Small hack to configure to our taste the TOC for the pdf combining |
| 2198 |
% the user manual and the source code. We want a Part III in the TOC, |
| 2199 |
% and the sections of Part II with a multicols. We can not open the |
| 2200 |
% multicols in the `part' style and have it closed in the 4th argument |
| 2201 |
% of \etocsettyle, as it needs to be closed when Part III will be |
| 2202 |
% typeset. Thanks to \etocskipfirstprefix we can simply close it |
| 2203 |
% in the "EtocPrefix", this \end{multicols} will be skipped for the |
| 2204 |
% first one. |
| 2205 |
% |
| 2206 |
% However, as this closes a group we will use \etocglobaldefs for this |
| 2207 |
% toc else \etocname, etc... would not have the good meanings. I think |
| 2208 |
% there must be some hack like this in etoc manual. |
| 2209 |
{\end{multicols}% |
| 2210 |
\addpenalty\@secpenalty |
| 2211 |
} |
| 2212 |
{% |
| 2213 |
% \kern and not \vskip to avoid multicolumn balncing columns |
| 2214 |
\def\tocstylesectionVSKIP{\kern\smallskipamount}% |
| 2215 |
\if1\ifnum\doxintsource=1 0\fi\ifnum\NoSourceCode=1 0\fi1% |
| 2216 |
% xint-all.pdf only |
| 2217 |
% quite a challenge to get everything on single page, but not too cramped... |
| 2218 |
\def\tocstylesectionVSKIP{\kern.75\smallskipamount}% |
| 2219 |
\fi |
| 2220 |
\begingroup % adapted from etoc.sty default Part style |
| 2221 |
\etocfontminusone |
| 2222 |
\addvspace{\etocsepminusone}% |
| 2223 |
\parindent \z@ |
| 2224 |
\leftskip \etocminusoneleftmargin |
| 2225 |
\rightskip \etocminusonerightmargin |
| 2226 |
\parfillskip \@flushglue |
| 2227 |
% \etoclink is handy else only the number get hyperlinked |
| 2228 |
\vbox{\etocifnumbered{\etoclink{\etocpartname\enspace\etocthenumber.\quad}}{}\etocname |
| 2229 |
\baselineskip\etocbaselinespreadminusone\baselineskip |
| 2230 |
\par}% |
| 2231 |
\addpenalty\@M\addvspace{\etocsepzero}% |
| 2232 |
\endgroup |
| 2233 |
% now emulate what \etocmulticolstyle would have set-up |
| 2234 |
\let\etocoldpar\par% surely fishy by now but I am copying from |
| 2235 |
% how \etocsettocstyle is used by \etocmulticolstyle |
| 2236 |
\addvspace{\etocabovetocskip}% configured below |
| 2237 |
\multicolpretolerance\etocmulticolpretolerance |
| 2238 |
\multicoltolerance\etocmulticoltolerance |
| 2239 |
\setlength{\columnsep}{\etoccolumnsep}% |
| 2240 |
\setlength{\multicolsep}{\etocmulticolsep}% |
| 2241 |
\begin{multicols}{2}[\parskip\z@skip%\raggedcolumns |
| 2242 |
\setlength{\columnsep}{\leftmarginii}% |
| 2243 |
\setlength{\columnseprule}{0pt}% |
| 2244 |
\etocoldpar |
| 2245 |
%\addvspace{\etocinnertopsep} |
| 2246 |
\addvspace{\etocabovetocskip}]% |
| 2247 |
}% |
| 2248 |
{\end{multicols} |
| 2249 |
}% |
| 2250 |
|
| 2251 |
% this macro is defined by etoc for use in its own display styles |
| 2252 |
% like the one from \etocmulticolstyle. We use it manually above. |
| 2253 |
\renewcommand*\etocabovetocskip{\bigskipamount} |
| 2254 |
\makeatother |
| 2255 |
|
| 2256 |
\etocsettagdepth {part1A}{none} |
| 2257 |
\etocsettagdepth {part1B}{none} |
| 2258 |
\etocsettagdepth {macros} {section} |
| 2259 |
\ifnum\doxintsource=1 % xintsource.pdf |
| 2260 |
\etocsettagdepth {implementation}{section} |
| 2261 |
\else |
| 2262 |
\ifnum\NoSourceCode=1 % xint.pdf |
| 2263 |
\etocsettagdepth {implementation}{part} |
| 2264 |
\else % xint-all.pdf |
| 2265 |
\etocsettagdepth {implementation}{section} |
| 2266 |
\fi |
| 2267 |
\fi |
| 2268 |
% THIS IS THE SECOND HALF OF THE TOC ON PAGE 1, WITH PARTS II AND III |
| 2269 |
\etocglobaldefs |
| 2270 |
\tableofcontents |
| 2271 |
\etoclocaldefs |
| 2272 |
|
| 2273 |
|
| 2274 |
\etocignoredepthtags |
| 2275 |
% 30 juillet 2025, simplification du contrôle espacement après TOCs |
| 2276 |
\makeatletter |
| 2277 |
\def\etocabovetocskip{\z@skip} |
| 2278 |
\makeatother |
| 2279 |
\def\etocbelowtocskip{\bigskipamount} |
| 2280 |
\etocmulticolstyle [1]{% |
| 2281 |
\phantomsection% \section* {Contents} |
| 2282 |
\etoctoccontentsline*{toctobookmark}{Contents}{2}% |
| 2283 |
} |
| 2284 |
|
| 2285 |
\inmanualmaintocfalse |
| 2286 |
|
| 2287 |
\clearpage |
| 2288 |
|
| 2289 |
% ---- |
| 2290 |
% Fibonacci code |
| 2291 |
% December 7, 2013. Expandably computing a big Fibonacci number |
| 2292 |
% with the help of TeX+\numexpr+\xintexpr, © Jean-François Burnol |
| 2293 |
\catcode`_ 11 |
| 2294 |
% |
| 2295 |
% ajouté 7 janvier 2014 au xint.dtx pour 1.07j. |
| 2296 |
% |
| 2297 |
% Le 17 janvier je me décide de simplifier l'algorithme car l'original ne tenait |
| 2298 |
% pas compte de la relation toujours vraie A=B+C dans les matrices symétriques |
| 2299 |
% utilisées en sous-main [[A,B],[B,C]]. |
| 2300 |
% |
| 2301 |
% la version ici est celle avec les * omis: car multiplication tacite devant les |
| 2302 |
% sous-expressions depuis 1.09j, et aussi devant les parenthèses depuis 1.09k. |
| 2303 |
\def\Fibonacci #1{% |
| 2304 |
\expandafter\Fibonacci_a\expandafter |
| 2305 |
{\the\numexpr #1\expandafter}\expandafter |
| 2306 |
{\romannumeral0\xintiiexpro 1\expandafter\relax\expandafter}\expandafter |
| 2307 |
{\romannumeral0\xintiiexpro 1\expandafter\relax\expandafter}\expandafter |
| 2308 |
{\romannumeral0\xintiiexpro 1\expandafter\relax\expandafter}\expandafter |
| 2309 |
{\romannumeral0\xintiiexpro 0\relax}} |
| 2310 |
% |
| 2311 |
\def\Fibonacci_a #1{% |
| 2312 |
\ifcase #1 |
| 2313 |
\expandafter\Fibonacci_end_i |
| 2314 |
\or |
| 2315 |
\expandafter\Fibonacci_end_ii |
| 2316 |
\else |
| 2317 |
\ifodd #1 |
| 2318 |
\expandafter\expandafter\expandafter\Fibonacci_b_ii |
| 2319 |
\else |
| 2320 |
\expandafter\expandafter\expandafter\Fibonacci_b_i |
| 2321 |
\fi |
| 2322 |
\fi {#1}% |
| 2323 |
}% |
| 2324 |
\def\Fibonacci_b_i #1#2#3{\expandafter\Fibonacci_a\expandafter |
| 2325 |
{\the\numexpr #1/2\expandafter}\expandafter |
| 2326 |
{\romannumeral0\xintiiexpro sqr(#2)+sqr(#3)\expandafter\relax\expandafter}\expandafter |
| 2327 |
{\romannumeral0\xintiiexpro (2#2-#3)#3\relax}% |
| 2328 |
}% end of Fibonacci_b_i |
| 2329 |
\def\Fibonacci_b_ii #1#2#3#4#5{\expandafter\Fibonacci_a\expandafter |
| 2330 |
{\the\numexpr (#1-1)/2\expandafter}\expandafter |
| 2331 |
{\romannumeral0\xintiiexpro sqr(#2)+sqr(#3)\expandafter\relax\expandafter}\expandafter |
| 2332 |
{\romannumeral0\xintiiexpro (2#2-#3)#3\expandafter\relax\expandafter}\expandafter |
| 2333 |
{\romannumeral0\xintiiexpro #2#4+#3#5\expandafter\relax\expandafter}\expandafter |
| 2334 |
{\romannumeral0\xintiiexpro #2#5+#3(#4-#5)\relax}% |
| 2335 |
}% end of Fibonacci_b_ii |
| 2336 |
\def\Fibonacci_end_i #1#2#3#4#5{\xintthe#5} |
| 2337 |
\def\Fibonacci_end_ii #1#2#3#4#5{\xinttheiiexpr #2#5+#3(#4-#5)\relax} |
| 2338 |
\catcode`_ 8 |
| 2339 |
|
| 2340 |
\def\Fibo #1.{\Fibonacci {#1}} |
| 2341 |
|
| 2342 |
\def\specialprintone #1% |
| 2343 |
{% |
| 2344 |
\ifx #1\relax \else \makebox[877496sp]{#1}\hskip 0pt plus 2sp\relax |
| 2345 |
\expandafter\specialprintone\fi |
| 2346 |
}% |
| 2347 |
\def\specialprintnumber #1% first ``fully'' expands its argument. |
| 2348 |
{\expandafter\specialprintone \romannumeral-`0#1\relax }% |
| 2349 |
|
| 2350 |
\AddToShipoutPicture*{% |
| 2351 |
\put(10.5cm,14.85cm) |
| 2352 |
{\makebox(0,0) |
| 2353 |
{\resizebox{17cm}{!}{\vbox |
| 2354 |
{\hsize 8cm\Huge\baselineskip.8\baselineskip\color{black!5}% |
| 2355 |
\specialprintnumber{F(1250)=}% |
| 2356 |
\specialprintnumber{\Fibonacci{1250}}}\par}% |
| 2357 |
}% |
| 2358 |
}% |
| 2359 |
} |
| 2360 |
|
| 2361 |
|
| 2362 |
\pdfbookmark[1]{Dependency graph}{DependencyGraph} |
| 2363 |
|
| 2364 |
|
| 2365 |
|
| 2366 |
|
| 2367 |
\tikzstyle{block} = [rectangle, draw, |
| 2368 |
fill=yellow!10, |
| 2369 |
% fill opacity=0.5, |
| 2370 |
draw=black!30, |
| 2371 |
line width=2pt, |
| 2372 |
text width=6em, text centered, rounded corners, minimum height=4em] |
| 2373 |
\tikzstyle{line} = [draw, line width=1pt, color=black!30] |
| 2374 |
|
| 2375 |
%\vspace*{\stretch{0.1666}} |
| 2376 |
|
| 2377 |
\begin{figure}[ht!] |
| 2378 |
\phantomsection\label{dependencygraph} |
| 2379 |
\centeredline{% |
| 2380 |
\begin{tikzpicture}[node distance = 2.5cm] |
| 2381 |
% Place nodes |
| 2382 |
\node [block] (kernel) {\xintkernelname}; |
| 2383 |
% \node [left of=kernel] (A) {}; |
| 2384 |
% \node [right of=kernel] (B) {}; |
| 2385 |
\node [block, below of=kernel] (core) {\xintcorename}; |
| 2386 |
\node [block, right of=core, xshift=1cm] (binhex) {\xintbinhexname}; |
| 2387 |
\node [block, left of=core, xshift=-2.5cm] (tools) {\xinttoolsname}; |
| 2388 |
\node [block, below of=core] (xint) {\xintname}; |
| 2389 |
\node [block, right of=xint, xshift=1cm] (bnumexpr) {\ctanpackage{bnumexpr}}; |
| 2390 |
\node [block, left of=xint, xshift=-0.5cm] (gcd) {\xintgcdname}; |
| 2391 |
\node [block, below of=xint] (frac) {\xintfracname}; |
| 2392 |
\node [block, below of=frac, yshift=-.5cm] (expr) {\xintexprname}; |
| 2393 |
\node [block, below right of=expr, yshift=-.5cm, xshift=2.25cm] (polexpr) {\ctanpackage{polexpr}}; |
| 2394 |
\node [block, below of=polexpr] (session) {rlwrap etex \ctanpackage{xintsession}}; |
| 2395 |
\node [block, below of=expr, yshift=-.5cm] (trig) {\xinttrigname}; |
| 2396 |
\node [block, left of=trig] (log) {\xintlogname}; |
| 2397 |
\node [block, left of=log, xshift=-1cm] (poormanlog) {\ctanpackage{poormanlog}}; |
| 2398 |
\node [block, below of=gcd, yshift=1cm] (cfrac) {\xintcfracname}; |
| 2399 |
\node [block, below of=cfrac, yshift=1cm] (series) {\xintseriesname}; |
| 2400 |
% Draw edges |
| 2401 |
\path [line,-{Stealth[length=5mm]}] (kernel) -- (core); |
| 2402 |
\path [line,-{Stealth[length=5mm]}] (kernel) -- (tools); |
| 2403 |
\path [line,-{Stealth[length=5mm]}] (kernel) -- (binhex); |
| 2404 |
\path [line,-{Stealth[length=5mm]}] (core) -- (bnumexpr); |
| 2405 |
\path [line,-{Stealth[length=5mm]}] (binhex) -- (bnumexpr); |
| 2406 |
\path [line,-{Stealth[length=5mm]}] (core) -- (xint); |
| 2407 |
\path [line,-{Stealth[length=5mm]}] (xint) -- (frac); |
| 2408 |
\path [line,-{Stealth[length=5mm]}] (xint) -- (gcd); |
| 2409 |
\path [line,-{Stealth[length=5mm]}] (frac) -- (expr); |
| 2410 |
\path [line,-{Stealth[length=5mm]}] (frac) -- (series); |
| 2411 |
\path [line,-{Stealth[length=5mm]}] (frac) -- (cfrac); |
| 2412 |
\path [line,-{Stealth[length=5mm]}] (expr) -- (polexpr); |
| 2413 |
\path [line,{Stealth[length=5mm]}-{Stealth[length=5mm]}] (expr) -- (trig); |
| 2414 |
\path [line,{Stealth[length=5mm]}-{Stealth[length=5mm]}] (expr) -- (log); |
| 2415 |
\path [line,-{Stealth[length=5mm]}] (poormanlog) -- (log); |
| 2416 |
\path [line,-{Stealth[length=5mm]}] (expr) -- (polexpr); |
| 2417 |
\path [line,-{Stealth[length=5mm]}] (expr) -- (session); |
| 2418 |
\path [line,-{Stealth[length=5mm]}] (polexpr) -- (session); |
| 2419 |
\path [line,-{Stealth[length=5mm]}] (trig.south) to [out=-90,in=180] (session.west); |
| 2420 |
\path [line,-{Stealth[length=5mm]}] (log.south) to [out=-90,in=180] (session.west); |
| 2421 |
% at 1.4n, xintbinhex is automatically loaded by xintexpr, no more "dashed" |
| 2422 |
\path [line,-{Stealth[length=5mm]}] (binhex.south east) to [out=-45,in=0] (expr); |
| 2423 |
% at 1.4 xintgcd loads xinttools |
| 2424 |
\path [line,-{Stealth[length=5mm]}] (tools.south west) to [out=-90,in=180](gcd.west); |
| 2425 |
% at 1.4n, xintcfrac loads xinttools automatically |
| 2426 |
\path [line,-{Stealth[length=5mm]}] (tools.south west) to [out=-90,in=180](cfrac.west); |
| 2427 |
\path [line,-{Stealth[length=5mm]}] (tools.south west) to [out=-90,in=180] (expr.west); |
| 2428 |
\end{tikzpicture}}\bigskip |
| 2429 |
\end{figure} |
| 2430 |
|
| 2431 |
\vspace{\baselineskip} |
| 2432 |
|
| 2433 |
\begin{addmargin}{1.5cm} |
| 2434 |
\normalfont\footnotesize Dependency graph for the |
| 2435 |
\xintbundlename components. |
| 2436 |
% |
| 2437 |
Modules pointed to by arrows \textbf{automatically} |
| 2438 |
import the module from which the arrow originates. |
| 2439 |
|
| 2440 |
\ctanpackage{bnumexpr} is a \LaTeX{} |
| 2441 |
package by the author which uses (by default) |
| 2442 |
\xintcorename as its mathematical engine. To use it under Plain e\TeX{} |
| 2443 |
issue first |\input miniltx.tex| then |\input bnumexpr.sty|. |
| 2444 |
|
| 2445 |
\ctanpackage{polexpr} handles definitions and algebraic operatione on |
| 2446 |
one-variable polynomials, as well as root localization to arbitrary |
| 2447 |
precision. It works both with Plain \TeX\ and with \LaTeX. |
| 2448 |
|
| 2449 |
\xinttrigname and \xintlogname are loaded automatically by \xintexprname; |
| 2450 |
they should not be loaded directly via a separate |\usepackage| (in \LaTeX). |
| 2451 |
|
| 2452 |
\ctanpackage{poormanlog} is a \TeX{} and |
| 2453 |
\LaTeX{} package by the author which is loaded automatically by \xintlogname. |
| 2454 |
|
| 2455 |
\ctanpackage{xintsession} is invoked on the command line as |etex |
| 2456 |
xintsession| (or, much better if available: |rlwrap etex xintsession|). |
| 2457 |
\par |
| 2458 |
\end{addmargin} |
| 2459 |
\vfill |
| 2460 |
|
| 2461 |
\clearpage |
| 2462 |
\etocdepthtag.toc {part1A} |
| 2463 |
|
| 2464 |
\csname Start herenameUp\endcsname |
| 2465 |
\part{The \xintexprname package} |
| 2466 |
\RaisedLabel[12]{part:1} |
| 2467 |
|
| 2468 |
\etocsetnexttocdepth{section} |
| 2469 |
\localtableofcontents |
| 2470 |
|
| 2471 |
\section {Introduction} |
| 2472 |
\localtableofcontents |
| 2473 |
|
| 2474 |
\begin{framed} |
| 2475 |
\textsc{Jürgen Gilg}'s interest into what he called |
| 2476 |
{|"XINT"|} was instrumental in keeping the author motivated |
| 2477 |
over the years. |
| 2478 |
% |
| 2479 |
We exchanged on many topics extending beyond \TeX{} and often reacted |
| 2480 |
similarly to private and public events. I knew he was a very kind |
| 2481 |
and devoted person, who took care of the needs of others prior to |
| 2482 |
his own, although he never mentioned it. |
| 2483 |
% |
| 2484 |
Jürgen suffered a sudden, unexpected, and deadly stroke in |
| 2485 |
May 2022. I will miss his friendship profoundly. |
| 2486 |
\end{framed} |
| 2487 |
|
| 2488 |
\subsection{Compatible engines and formats} |
| 2489 |
|
| 2490 |
The components of the \xintbundlename can be used indifferently with |
| 2491 |
Plain \TeX{} (and other formats, as mentioned next) or with \LaTeX{}. |
| 2492 |
The sole difference being that with the latter the loading must be done |
| 2493 |
by \cs{usepackage} whereas with any non-\LaTeX{} format it has to be via |
| 2494 |
\cs{input} (using |.sty| filename extension, not |.tex|). |
| 2495 |
|
| 2496 |
The engine can be PDF\TeX, Xe\TeX, or Lua\TeX. |
| 2497 |
|
| 2498 |
With release |1.4n| you can also use the packages with Con\TeX t (only |
| 2499 |
latest one, with LuaMeta\TeX{} engine), and Op\TeX. |
| 2500 |
|
| 2501 |
You can't use the \xintbundlename with Knuth's original |tex| binary, |
| 2502 |
because its functionalities require \cs{numexpr} and other e-\TeX{} |
| 2503 |
extensions as well as the more recent \cs{expanded} engine primitive |
| 2504 |
(and \cs{pdfstrcomp} or \cs{strcmp}). |
| 2505 |
|
| 2506 |
\xintexprname will be probably the main entry point, and it actually |
| 2507 |
automatically loads most other components. The aim of \xintexprname is |
| 2508 |
to provide expandable parsers of numerical expressions, either floating |
| 2509 |
point numbers or fractions. |
| 2510 |
|
| 2511 |
\subsection{Usage} |
| 2512 |
|
| 2513 |
Here is an example: |
| 2514 |
\begin{everbatim*} |
| 2515 |
\xintfloateval{cos(3Pi/17)*sin(1)^0.123 + log(3.42e5)} |
| 2516 |
\end{everbatim*} |
| 2517 |
|
| 2518 |
You can get the result with more digits: |
| 2519 |
\begingroup |
| 2520 |
\begin{everbatim*} |
| 2521 |
\xintSetDigits*{32} |
| 2522 |
\xintfloateval{cos(3Pi/17)*sin(1)^0.123 + log(3.42e5)} |
| 2523 |
\end{everbatim*} |
| 2524 |
\endgroup |
| 2525 |
|
| 2526 |
And with still more digits (the |[-2]| rounds away the two least |
| 2527 |
significant digits of the result): |
| 2528 |
\begingroup |
| 2529 |
\begin{everbatim*} |
| 2530 |
\xintSetDigits*{62} |
| 2531 |
\xintfloateval[-2]{cos(3Pi/17)*sin(1)^0.123 + log(3.42e5)} |
| 2532 |
\end{everbatim*} |
| 2533 |
\endgroup |
| 2534 |
|
| 2535 |
Here is now an example with fractions: |
| 2536 |
\begin{everbatim*} |
| 2537 |
\xinteval{reduce(add(1/i^3, i=1..25))} |
| 2538 |
\end{everbatim*} |
| 2539 |
|
| 2540 |
And two examples with large integers: |
| 2541 |
\begin{everbatim*} |
| 2542 |
$2^{1000}=\printnumber{\xinteval{2^1000}}$.\newline |
| 2543 |
$100!^3=\printnumber{\xintiieval{100!^3}}$. |
| 2544 |
\end{everbatim*} |
| 2545 |
|
| 2546 |
The \hyperref[ssec:printnumber]{\string\printnumber} utility to wrap |
| 2547 |
very long output is not part of the package. It is documented in |
| 2548 |
\autoref{ssec:printnumber} next. |
| 2549 |
|
| 2550 |
The table of \hyperref[tab:functions]{built-in functions} |
| 2551 |
and the one of \hyperref[tab:precedences]{built-in operators} |
| 2552 |
will give a quick overview of the available syntax. |
| 2553 |
|
| 2554 |
|
| 2555 |
\subsection{\ctanpackage{xintsession}} |
| 2556 |
|
| 2557 |
The simplest way\footnote{I am assuming here in the displayed example a |
| 2558 |
Unixen system, i.e. Mac OS or Linux, adapt to your environment.} to |
| 2559 |
test the syntax is to work interactively on the command line (this |
| 2560 |
feature is available since April 2021, the version of |
| 2561 |
\ctanpackage{xintsession} used here is |1.3a|). Beware though that |
| 2562 |
ill-formed inputs will trigger \TeX{} famously antiquated error handling, |
| 2563 |
from which it is hard to recover, altough hitting |S| may sometimes |
| 2564 |
miraculously bring you back to the \ctanpackage{xintsession} prompt. |
| 2565 |
\begin{everbatim} |
| 2566 |
rlwrap etex xintsession |
| 2567 |
[...welcome banner...] |
| 2568 |
Magic words: `&pause' (or `;'), `&help', `&bye', |
| 2569 |
`&exact', `&fp', `&int', `&pol'. |
| 2570 |
|
| 2571 |
\jobname is xintsession |
| 2572 |
Transcript will go to log and to xintsession-210609_12h00.tex |
| 2573 |
Starting in exact mode (floating point evaluations use 16 digits) |
| 2574 |
>>> 2^100; |
| 2575 |
@_1 1267650600228229401496703205376 |
| 2576 |
>>> cos(1); |
| 2577 |
@_2 0.5403023058681397 |
| 2578 |
>>> &fp=32 |
| 2579 |
(/usr/local/texlive/2021/texmf-dist/tex/generic/xint/xintlog.sty) |
| 2580 |
(/usr/local/texlive/2021/texmf-dist/tex/generic/xint/xinttrig.sty) |
| 2581 |
fp mode (log and trig reloaded at Digits=32) |
| 2582 |
>>> cos(1); |
| 2583 |
@_3 0.54030230586813971740093660744298 |
| 2584 |
>>> 3^1000; |
| 2585 |
@_4 1.3220708194808066368904552597521e477 |
| 2586 |
>>> &exact |
| 2587 |
exact mode (floating point evaluations use 32 digits) |
| 2588 |
>>> 3^1000; |
| 2589 |
|
| 2590 |
@_5 13220708194808066368904552597521443659654220327521481676649203682268285 |
| 2591 |
9734670489954077831385060806196390977769687258235595095458210061891186534272525 |
| 2592 |
7953674027620225198320803878014774228964841274390400117588618041128947815623094 |
| 2593 |
4380615661730540866744905061781254803444055470543970388958174653682549161362208 |
| 2594 |
3026856377858229022841639830788789691855640408489893760937324217184635993869551 |
| 2595 |
6765018940588109060426089671438864102814350385648747165832010614366132173102768 |
| 2596 |
902855220001 |
| 2597 |
>>> &bye |
| 2598 |
Did I say something wrong? |
| 2599 |
Session transcript written on xintsession-210609_12h00.tex |
| 2600 |
) |
| 2601 |
No pages of output. |
| 2602 |
Transcript written on xintsession.log. |
| 2603 |
\end{everbatim} |
| 2604 |
|
| 2605 |
\subsection{\ctanpackage{polexpr}} |
| 2606 |
|
| 2607 |
The package \ctanpackage{polexpr} enriches the \csbxint{eval} syntax |
| 2608 |
(but not the one of \csbxint{floateval}) with a polynomial type with |
| 2609 |
associated constructor |pol([c0,c1,...])|, and polynomial specific |
| 2610 |
functions such as |polgcd(pol1, pol2, ...)|. |
| 2611 |
|
| 2612 |
Full usage of polynomials (and algebraic notations |c_0 + c_1 x + c_2 |
| 2613 |
x^2 + ...| for input and also output) goes through a dedicated |\poldef| |
| 2614 |
parser which is based upon \csbxint{defvar}/\csbxint{deffunc} and is a |
| 2615 |
necessary step to then access via a dedicated macro interface operations |
| 2616 |
such as identifying all rational roots and isolating all real roots to |
| 2617 |
arbitrary precision. |
| 2618 |
|
| 2619 |
The simplest manner to experiment with \ctanpackage{polexpr} is via the |
| 2620 |
|&pol| mode of \ctanpackage{xintsession}. |
| 2621 |
|
| 2622 |
\subsection{\ctanpackage{bnumexpr}} |
| 2623 |
|
| 2624 |
This \LaTeX{} package loads \xintcorename and \xintbinhexname and |
| 2625 |
provides \cs{bnumeval} which is a scaled-down \csbxint{iieval} (omitting |
| 2626 |
support for nested structures, functions, variables, boolean branching, |
| 2627 |
etc...). It can be used with Plain e\TeX, thanks to |
| 2628 |
\ctanpackage{miniltx}. For this, use |\input miniltx.tex| followed by |
| 2629 |
|\input bnumexpr.sty| (remark: \ctanpackage{miniltx} is not needed for |
| 2630 |
\xintexprname). |
| 2631 |
|
| 2632 |
|
| 2633 |
\cs{bnumeval} is thus a boosted \cs{inteval} which addition of support |
| 2634 |
for arbitrarily large integers, powers with |**| and |^|, rounded |
| 2635 |
division with |/|, floored division with |//| and associated modulo |
| 2636 |
|/:|, factorials via |!| postfix operator, comma separated multi-item |
| 2637 |
expressions. |
| 2638 |
|
| 2639 |
It also supports as \csbxint{iieval} does the |'|, |"|, |0b|, |0o| and |
| 2640 |
|0x| input prefixes and the optional arguments |[b]|, |[o]|, or |[h]|. |
| 2641 |
|
| 2642 |
Further, it provides an interface (which does not exist with |
| 2643 |
\xintexprname) to let all operations be done by macros of one's own |
| 2644 |
choosing, as replacement for some or all of the operations by default |
| 2645 |
implemented via the help of \xintcorename and \xintbinhexname. It even |
| 2646 |
makes it possible to add to the syntax extra infix or postfix operators |
| 2647 |
and to modify the precedence levels of those already defined. |
| 2648 |
|
| 2649 |
|
| 2650 |
\subsection{Printing big numbers on the page}\label{ssec:printnumber} |
| 2651 |
|
| 2652 |
When producing very long numbers there is the question of printing them on |
| 2653 |
the page, without going beyond the page limits. In this document, I have most |
| 2654 |
of the time made use of a ``|\printnumber|'' macro, which is not provided by |
| 2655 |
the package. A primitive form would be: |
| 2656 |
\everb|@ |
| 2657 |
\def\allowsplits #1{\ifx #1\relax \else #1\hskip 0pt plus 1pt\relax |
| 2658 |
\expandafter\allowsplits\fi}% |
| 2659 |
\def\printnumber #1{\expandafter\allowsplits \romannumeral-`0#1\relax }% |
| 2660 |
| |
| 2661 |
|
| 2662 |
This macro triggers ``\fexpan sion'' of its argument (and indeed |
| 2663 |
\csbxint{eval} and friends expand completely under such trigger), then |
| 2664 |
it goes through the computation result character by character inserting |
| 2665 |
\TeX\ potential break points in-between them. It is ineffective in math |
| 2666 |
mode, one would need to add some |\allowbreak|'s. The |\printnumber| |
| 2667 |
used for building this documentation uses slightly different and more |
| 2668 |
sophisticated mechanisms and can be |
| 2669 |
found in the source file |xint.dtx|. |
| 2670 |
|
| 2671 |
\subsection{Repository} |
| 2672 |
|
| 2673 |
It is at \url{https://github.com/jfbu/xint}. At this stage, it does not |
| 2674 |
recored real-time development status but only actual successive |
| 2675 |
\href{https://ctan.org}{CTAN} releases since 2013. Use it to report |
| 2676 |
issues. Don't forget to include |@jfbu| in the ticket else I will not |
| 2677 |
be pinged. |
| 2678 |
|
| 2679 |
A front page at \url{https://jfbu.github.io/xint} provides, in addition |
| 2680 |
to the present |xint.pdf| and to |README.md| a file |CHANGES.html|, |
| 2681 |
which contains the complete list of changes relevant to user level |
| 2682 |
since the initial release of the package: |
| 2683 |
% |
| 2684 |
\centeredline{\url{https://jfbu.github.io/xint/CHANGES.html}} |
| 2685 |
|
| 2686 |
Its version |xintchanges.md| in Markdown format is included in the |
| 2687 |
\href{https://ctan.org/pkg/xint}{CTAN} upload, |
| 2688 |
% |
| 2689 |
\centeredline{|texdoc xintchanges.md|} |
| 2690 |
|
| 2691 |
Warning: I don't have the time to maintain perfectly such large |
| 2692 |
documentation. It combines old documentation which never really got |
| 2693 |
updated and may be locally obsolete with more recent stuff mostly |
| 2694 |
written on occasion of the |1.4| release of January 2020 and the |1.4e| |
| 2695 |
one of May 2021, and the intervening changes might also have made some |
| 2696 |
of it not completely accurate, despite my best efforts. |
| 2697 |
|
| 2698 |
\subsection{License and installation instructions} |
| 2699 |
|
| 2700 |
\label{ssec:install} |
| 2701 |
|
| 2702 |
The \xintbundlename components are made available under the |
| 2703 |
\href{http://www.latex-project.org/lppl/lppl-1-3c.txt}{LaTeX Project |
| 2704 |
Public License 1.3c}. They are included in all major \TeX\ |
| 2705 |
distributions, thus there is probably no need for a custom install: just |
| 2706 |
use the package manager to update if necessary the \xintbundlename |
| 2707 |
components to the latest version available. |
| 2708 |
|
| 2709 |
Else, \href{https://ctan.org/pkg/xint}{CTAN} access provides |xint.tds.zip| |
| 2710 |
which has all source code and documentation in a TDS-compliant archive, only |
| 2711 |
waiting to be |unzip -d <DIR>| into some suitable hierarchical structure. |
| 2712 |
|
| 2713 |
See \url{https://jfbu.github.io/xint} for how to build from the |
| 2714 |
\href{https://ctan.org/tex-archive/macros/generic/xint}{CTAN |
| 2715 |
xint}.dtx source file. |
| 2716 |
|
| 2717 |
\clearpage |
| 2718 |
\expandafter\let\csname Start herenameUp\endcsname\undefined |
| 2719 |
\csname xintexprnameUp\endcsname |
| 2720 |
\section{Syntax reference and user guide} |
| 2721 |
\RaisedLabel{sec:expr} |
| 2722 |
|
| 2723 |
\localtableofcontents |
| 2724 |
|
| 2725 |
\begin{framed} |
| 2726 |
\textbf{WARNING:} this documentation goes sometimes into too much |
| 2727 |
details, and does need some improvements. But there is no time for |
| 2728 |
that at |1.4n|. Although people do not believe me when I say that, |
| 2729 |
there is ample intellectual reward in actually reading the documentation, |
| 2730 |
and it would be nice if at least, at last someone on Earth did, |
| 2731 |
once (as \textsc{Jürgen Gilg} some years back). |
| 2732 |
\end{framed} |
| 2733 |
|
| 2734 |
\subsection{The three parsers} |
| 2735 |
|
| 2736 |
|
| 2737 |
\xintexprname provides three numerical expression parsers corresponding to |
| 2738 |
these three respective tasks: |
| 2739 |
\begin{description}[noitemsep] |
| 2740 |
\item[\csa{xintfloateval}:] evaluations with floating point numbers; the default precision is with 16 digits, it can be set via \csbxint{SetDigits*}, |
| 2741 |
\item[\csa{xinteval}:] exact evaluations with fractions, decimal fixed point numbers, numbers |
| 2742 |
in scientific notation, with no size limitation, |
| 2743 |
\item[\csa{xintiieval}:] evaluations allowing only integers with no size limitation, |
| 2744 |
\end{description} |
| 2745 |
and two secondary ones which act like the exact evaluator then round the |
| 2746 |
output to a given number of fractional digits, or convert them to |
| 2747 |
|false| or |true|\CHANGED{1.4m} according to whether they vanish or do not vanish. |
| 2748 |
|
| 2749 |
\begin{framed} |
| 2750 |
Please note the following: |
| 2751 |
\begin{itemize}[noitemsep] |
| 2752 |
\item If you find that \csbxint{floateval} is too much of a mouthful, |
| 2753 |
you create an alias named, for example, |\fpeval|. Oops, no, that |
| 2754 |
is \LaTeX3 very efficient floating point engine. It is faster at |
| 2755 |
its (unchangeable) precision of 16 decimal digits than |
| 2756 |
\csbxint{floateval} due to various reasons, one of them being that |
| 2757 |
\xintexprname birth was related to big integers only, and floating |
| 2758 |
point support in arbitrary precision was added on top of that, via |
| 2759 |
some expedients which have never been refactored, in view of the |
| 2760 |
massive work that this would entail by now. But for example you |
| 2761 |
could do |\let\evalfp\xintfloateval| if you want a shorter name. By |
| 2762 |
the way |\xintfloateval| could very well have been christened |
| 2763 |
|\xintfpeval| but when the author wrote the first release in 2013 he |
| 2764 |
was barely if at all aware of existence of \LaTeX3, and of its |
| 2765 |
|l3fp| component. |
| 2766 |
\item Although \csbxint{eval} manipulates arbitrarily long integers or |
| 2767 |
fractions it also accepts scientific notation on input, as well as |
| 2768 |
all the mathematical functions (evaluated using the prevailing |
| 2769 |
digits precision), and (depending on customization) can thus produce |
| 2770 |
also scientific notation on output. |
| 2771 |
\item So far, individual operations and the printing routine of |
| 2772 |
\csbxint{eval} do not automatically reduce fractions to their lowest |
| 2773 |
terms. |
| 2774 |
\end{itemize} |
| 2775 |
\end{framed} |
| 2776 |
% They are designed to be compatible with expansion only context. All |
| 2777 |
% computations ultimately rely on (and reduce to) usage of the |\numexpr| |
| 2778 |
% primitive from \eTeX{}% |
| 2779 |
% % |
| 2780 |
% \footnote{It can handle only integers, and they must be at most |
| 2781 |
% $2^{31}-1={}$\dtt{\the\numexpr"7FFFFFFF\relax}. Thus some work has to be done |
| 2782 |
% to handle arbitrarily big integers or arbitrary float precision.}. |
| 2783 |
% % |
| 2784 |
% These \eTeX{} extensions date |
| 2785 |
% back to 1999 and are by default incorporated into the |pdftex| |
| 2786 |
% etc...\@{} executables from major modern \TeX{} installations for more than |
| 2787 |
% fifteen years now. |
| 2788 |
|
| 2789 |
The interface is: |
| 2790 |
\begin{itemize} |
| 2791 |
\item \csbxint{eval}\marg{expression} handles integers, decimal numbers, |
| 2792 |
numbers in scientific notation and fractions. The algebraic computations are |
| 2793 |
done \emph{exactly}, and in particular \oper{/} simply constructs |
| 2794 |
fractions. Use \oper{//} for floored division. |
| 2795 |
\begin{everbatim*} |
| 2796 |
\xinteval{add(x/(x+1), x = 1000..1014)}\par |
| 2797 |
\end{everbatim*} |
| 2798 |
The output in this specific example came out irreducible. In general one needs |
| 2799 |
a \func{reduce} wrapper for an irreducible output: |
| 2800 |
\begin{everbatim*} |
| 2801 |
\[\xinteval{subs((y,reduce(y)), y = mul(x/1000, x = 10..[10]..90))}\] |
| 2802 |
\end{everbatim*} |
| 2803 |
|
| 2804 |
|
| 2805 |
Arbitrarily long numbers are allowed in the input. The space character |
| 2806 |
(contrarily to the situation inside |\numexpr|) and also the underscore |
| 2807 |
character (as allowed in Python too) can serve to separate groups of digits |
| 2808 |
for better readability. But the package currently provides no macros to let |
| 2809 |
the output be formatted with such separators. |
| 2810 |
\begin{everbatim*} |
| 2811 |
\xinteval{123_456_789_012^5} |
| 2812 |
\end{everbatim*} |
| 2813 |
|
| 2814 |
Hexadecimal,\NewWith{1.4n} octal and binary (with fractional part allowed) can be |
| 2815 |
input using suitable prefixes: respectively |"| or |0x|, |'| or |0o|, |
| 2816 |
and |0b|: |
| 2817 |
\begin{everbatim*} |
| 2818 |
\xinteval{0b111111111111.111111111111} |
| 2819 |
\end{everbatim*} |
| 2820 |
|
| 2821 |
|
| 2822 |
\item \csbxint{ieval}\oarg{D}\marg{expression} is the same parser as |
| 2823 |
\csbxint{eval}, i.e. accepts the same inputs and does all computations |
| 2824 |
exactly in the same manner, but it then rounds its final result to the |
| 2825 |
nearest integer, or, in case there is an optional argument |[D]|, to: |
| 2826 |
\begin{itemize} |
| 2827 |
\item if |D>0|: the nearest fixed point number with |D| digits after the |
| 2828 |
decimal mark, |
| 2829 |
\item if |D=0|: the nearest integer (as for \csbxint{ieval} with no optional argument), |
| 2830 |
\item if |D<0|: the rounded quotient by |10^(-D)|. |
| 2831 |
\end{itemize} |
| 2832 |
|
| 2833 |
The optional argument \oarg{D} can also be located |
| 2834 |
\emph{within} the braces at the start of the expression (this was actually |
| 2835 |
the legacy syntax until |1.4k|). |
| 2836 |
|
| 2837 |
\item \csbxint{iieval}\marg{expression} executes computations \emph{on (big) |
| 2838 |
integers only.} It is (only slightly) faster than \csbxint{eval} for |
| 2839 |
the same expression. |
| 2840 |
|
| 2841 |
Attention: the forward slash \oper{/} does the \emph{rounded} integer |
| 2842 |
division to match behaviour of |\numexpr|. The \oper{//} operator does |
| 2843 |
floored division as in \csbxint{eval}. The \oper{/:} is the associated |
| 2844 |
modulo operator (we could easily let the catcode 12 |%| |
| 2845 |
character be an alias, but using such an unusual percent character |
| 2846 |
would be a bit cumbersome in a \TeX{} workflow, if only for matters of |
| 2847 |
syntax highlighting in \TeX-aware text editors). |
| 2848 |
\begin{everbatim*} |
| 2849 |
% add the i^5 only if i is a multiple of 7 |
| 2850 |
\xintiieval{add((i/:7)?{omit}{i^5}, i=1000..1020)} |
| 2851 |
\end{everbatim*} |
| 2852 |
|
| 2853 |
An\NewWith{1.4n} optional argument |[h]|, |[o]|, or |[b]| says to convert the output |
| 2854 |
to hexadecimal, octal or binary: |
| 2855 |
\begin{everbatim*} |
| 2856 |
\xintiieval[h]{3^100} |
| 2857 |
\end{everbatim*} |
| 2858 |
|
| 2859 |
|
| 2860 |
\item \csbxint{floateval}\oarg{Q}\marg{expression} does floating point |
| 2861 |
computations with a given precision, which defaults to |16|. The precision |
| 2862 |
|P| can be set using \csbxint{Digits*}|:=P\relax| or \csbxint{SetDigits*}|{P}| |
| 2863 |
syntaxes. |
| 2864 |
|
| 2865 |
Its optional argument |[Q]|, if present, means to do a \emph{final} float |
| 2866 |
rounding to a mantissa of |Q| digits (this thus makes sense only if |
| 2867 |
|Q<P|). |
| 2868 |
|
| 2869 |
A negative |Q| is allowed and means to round to |P+Q| digits only. |
| 2870 |
|
| 2871 |
Prior to |1.4k| the optional argument \oarg{Q} had to be located |
| 2872 |
\emph{within} the braces at the start of the expression. The legacy |
| 2873 |
syntax is and will keep being allowed. |
| 2874 |
|
| 2875 |
|
| 2876 |
|
| 2877 |
The infix operator \oper{/} will compute the correct rounding of the exact |
| 2878 |
fraction. The operator \oper{//} is floored division and \oper{/:} is its |
| 2879 |
associated modulo (see also \func{divmod}). |
| 2880 |
\begin{everbatim*} |
| 2881 |
\begingroup |
| 2882 |
\xintDigits:=64\relax |
| 2883 |
\xintfloateval{sqrt(3)} |
| 2884 |
\endgroup |
| 2885 |
\end{everbatim*} |
| 2886 |
|
| 2887 |
The four basic operations and the square root achieve \emph{correct |
| 2888 |
rounding.}\footnote{when the inputs are already floating point numbers |
| 2889 |
with at most |P|-digits mantissas.} |
| 2890 |
|
| 2891 |
On output, \csbxint{floateval} uses \csbxint{PFloat} for each numeric |
| 2892 |
leaf. This can be modified (cf.\@{} \csbxint{floatexprPrintOne}). |
| 2893 |
\end{itemize} |
| 2894 |
|
| 2895 |
% The user can define variables and functions. Definition of functions is either |
| 2896 |
% per parser (\csbxint{deffunc}, \csbxint{deffloatfunc}, ...), but there are |
| 2897 |
% some restrictions, or generic (\csbxint{NewFunction}) but the latter is only |
| 2898 |
% syntactic sugar for function-like disguise of a \TeX{} macro having not done |
| 2899 |
% any pre-parsing. |
| 2900 |
|
| 2901 |
There is a core syntax: |
| 2902 |
\begin{itemize}[nosep] |
| 2903 |
\item \csbxint{expr}\meta{expression}|\relax|, |
| 2904 |
\item \csbxint{iexpr}\meta{expression}|\relax|, |
| 2905 |
\item \csbxint{iiexpr}\meta{expression}|\relax|, |
| 2906 |
\item \csbxint{floatexpr}\meta{expression}|\relax|, |
| 2907 |
\item \csbxint{boolexpr}\meta{expression}|\relax|. |
| 2908 |
\end{itemize} |
| 2909 |
\csbxint{boolexpr}\meta{expression}|\relax| does all computations like |
| 2910 |
\csbxint{expr} then converts all (non-empty) leaves% |
| 2911 |
% |
| 2912 |
\footnote{Currently, empty leaves are output using \csbxint{exprEmptyItem}, |
| 2913 |
i.e.\@{} default to \dtt{\xintexprEmptyItem}. This may change.} |
| 2914 |
% |
| 2915 |
to |true| or |false| (cf.\@{} \csbxint{boolexprPrintOne}). There is no |
| 2916 |
|\xintbooleval|.\CHANGED{1.4m}\footnote{This was |True| and |False| prior |
| 2917 |
to |1.4m|.} |
| 2918 |
|
| 2919 |
Formerly the \csbxint{expr}|...\relax| legacy syntax had to be prefixed |
| 2920 |
by |\xintthe| if in typesetting context, else an error was raised |
| 2921 |
(deliberately). The |\xintthe| prefix was made optional at |1.4|. |
| 2922 |
|
| 2923 |
In an |\edef| these constructs expand to some braced nested data, all |
| 2924 |
computations having been completely done, which is prefixed with some |
| 2925 |
|\protected| \myenquote{typesetter} macros. |
| 2926 |
|
| 2927 |
In an |\edef|, \csbxint{eval} (in contrast to \csbxint{expr}), or |
| 2928 |
\csbxint{floateval} (in contrast to \csbxint{floatexpr}) expand the |
| 2929 |
\myenquote{typesetting macros} and the final complete expansion consists of |
| 2930 |
explicit digits and other characters such as those of scientific |
| 2931 |
notation or square brackets.% |
| 2932 |
% |
| 2933 |
\footnote{\csbxint{eval} and \csbxint{expr} both expand completely in exactly |
| 2934 |
two steps. And \csbxint{expr} expands fully under \fexpan sion (of the |
| 2935 |
|\romannumeral0| or |-`0| type). As per \csbxint{eval} attention that it may |
| 2936 |
expand to nothing, then naturally \fexpan sion propagates to tokens |
| 2937 |
following up in the input stream.} |
| 2938 |
|
| 2939 |
In \LaTeX\ it is possible to use the core syntax |
| 2940 |
\csbxint{expr}\meta{expression}|\relax| also in so-called moving arguments, |
| 2941 |
because when written out to a file the final expansion outcome uses only |
| 2942 |
standard catcodes and thus will get retokenized and expand as expected if |
| 2943 |
it has been written to an external file which is then reloaded. |
| 2944 |
|
| 2945 |
One needs \csbxint{eval} et al.\@{} only if one really wants the final digits |
| 2946 |
(and other characters), for example in a context where \TeX{} expects a number |
| 2947 |
or a dimension. |
| 2948 |
|
| 2949 |
As alternative to \csbxint{eval}\marg{expression}, an equivalent is |
| 2950 |
\csbxint{the}\csbxint{expr}\meta{expression}|\relax|. Similarly \csbxint{the} |
| 2951 |
can prefix all other core parsers. And one can also use \csbxint{theexpr} as |
| 2952 |
shortcut for \csbxint{the}\csbxint{expr}. |
| 2953 |
|
| 2954 |
Doing exact computations with fractions leads very quickly to very big results |
| 2955 |
(and furthermore one needs to use explicitly the |reduce()| function to |
| 2956 |
convert the fractions into smallest terms). Thus most probably what you want |
| 2957 |
is \csbxint{floateval} and \csbxint{floatexpr}. |
| 2958 |
|
| 2959 |
|
| 2960 |
\subsection{Output customization} |
| 2961 |
|
| 2962 |
\subsubsection{\csh{xintfloatexprPrintOne} et al{.} for numerical values} |
| 2963 |
\label{xintexprEmptyItem} |
| 2964 |
\label{xintexprPrintOne} |
| 2965 |
\label{xintiiexprPrintOne} |
| 2966 |
\label{xintiiexprPrintOneHex} |
| 2967 |
\label{xintiiexprPrintOneOct} |
| 2968 |
\label{xintiiexprPrintOneBin} |
| 2969 |
\label{xintiexprPrintOne} |
| 2970 |
\label{xintfloatexprPrintOne} |
| 2971 |
\label{xintboolexprPrintOne} |
| 2972 |
|
| 2973 |
The package provides only minimal facilities for formatting the output |
| 2974 |
from \csbxint{eval} or \csbxint{floateval} or\dots. And this output may |
| 2975 |
well consist of comma separated values, even nested ones with, by |
| 2976 |
default, square brackets. First we explain how to influence the handling |
| 2977 |
of individual \myenquote{leaves}. |
| 2978 |
|
| 2979 |
Here are the default definitions to this effect: |
| 2980 |
\begin{everbatim} |
| 2981 |
\def\xintexprEmptyItem{[]} % (all parsers) |
| 2982 |
\def\xintexprPrintOne #1{\xintFracToSci{#1}} % \xinteval |
| 2983 |
\def\xintiexprPrintOne #1{\xintDecToString{#1}} % \xintieval |
| 2984 |
\def\xintiiexprPrintOne#1{#1} % \xintiieval |
| 2985 |
\def\xintfloatexprPrintOne [#1]#2{\xintPFloat[#1]{#2}} % \xintfloateval |
| 2986 |
\def\xintboolexprPrintOne#1{\xintiiifNotZero{#1}{true}{false}} |
| 2987 |
\end{everbatim} |
| 2988 |
They can be re-defined to one's wishes. If configured to do anything |
| 2989 |
non expandable they must be |\protected|. \LaTeX\ users will want to use |
| 2990 |
|\RenewDocumentCommand| for this. |
| 2991 |
\begin{TeXnote} |
| 2992 |
\begin{itemize} |
| 2993 |
\item Actually, the defaults are more done in the style |
| 2994 |
\begin{everbatim} |
| 2995 |
\let\xintexprPrintOne\xintFracToSci |
| 2996 |
\end{everbatim} |
| 2997 |
thus sparing grabbing the argument |#1|. And one can do |
| 2998 |
\begin{everbatim} |
| 2999 |
\def\xintexprPrintOne{\xintFracToSci} |
| 3000 |
\end{everbatim} |
| 3001 |
too. |
| 3002 |
\item |\xintexprPrintOne| defaults in truth to some private variant of |
| 3003 |
\csbxint{FracToSci} with exactly the same output but able to understand |
| 3004 |
only certain limited types of inputs as used internally. |
| 3005 |
\item |\xintiiexprPrintOne| is used with \csbxint{iieval}. But it |
| 3006 |
gets replaced with |\xintiiexprPrintOneHex|, |
| 3007 |
|\xintiiexprPrintOneOct|, or |\xintiiexprPrintOneOct| if the |
| 3008 |
optional argument |[h]|, |[o]|, or |[b]| is used.\NewWith{1.4n} These macros |
| 3009 |
default to respectively \csbxint{DecToHex}, \csbxint{DecToOct} and |
| 3010 |
\csbxint{DecToBin}. |
| 3011 |
\item |\xintfloatexprPrintOne| defaults in fact to a private variant of |
| 3012 |
\csbxint{PFloat} which assumes the optional argument |[P]| is present as |
| 3013 |
it will be the case always in this context. This optional argument |
| 3014 |
|[P]| is the optional argument |[Q]| of \csbxint{floateval} (or |
| 3015 |
|Digits+Q| if |Q<0|). |
| 3016 |
\item The typesetter for \csbxint{iiexpr} simply prints ``as is'', but this |
| 3017 |
may change in future, if some internal format is used requiring a |
| 3018 |
conversion step. |
| 3019 |
\end{itemize} |
| 3020 |
\end{TeXnote} |
| 3021 |
|
| 3022 |
Here is a possibly not up-to-date list of macros of interest, whose |
| 3023 |
documentations you might consider reading (the first two require math |
| 3024 |
mode): |
| 3025 |
\begin{itemize}[nosep] |
| 3026 |
\item \csbxint{TeXFromSci}, |
| 3027 |
\item \csbxint{TeXFrac}, |
| 3028 |
\item \csbxint{DecToString}, |
| 3029 |
\item \csbxint{PRaw}, |
| 3030 |
\item \csbxint{FracToSci}, |
| 3031 |
\item \csbxint{FracToDecimal}, |
| 3032 |
\item \csbxint{PFloat}, |
| 3033 |
\item and \csbxint{FloatToDecimal}. |
| 3034 |
\end{itemize} |
| 3035 |
Naming scheme, as one can see, has been pretty much incoherent, apologies. |
| 3036 |
|
| 3037 |
Among packages providing macros formatting numeric values, there are |
| 3038 |
\ctanpackage{numprint} and its macro |\np| (or |\numprint| without the |
| 3039 |
option |np|), and \ctanpackage{siunitx} |
| 3040 |
and its |\num|, and possibly more packages not known to the author.% |
| 3041 |
% |
| 3042 |
\footnote{There does not seems to be yet a \LaTeX\ user level interface to the |
| 3043 |
\liiistrformat\ package, part of |l3experimental|, which provides an |
| 3044 |
implementation of the Python |format| function.} |
| 3045 |
% |
| 3046 |
These macros are suitable in combination with \csbxint{Float} as in the |
| 3047 |
example below to customize the \csbxint{floateval} output. |
| 3048 |
% 27 mai 2022, en effet \num{1/7} ne marche pas et \numprint{1/7} non plus |
| 3049 |
Numerical output from \csbxint{eval} is more challenging as |
| 3050 |
individual values may naturally contain the |/| character for fractions which the |
| 3051 |
above mentioned packages will not know how to handle, as far as I know. |
| 3052 |
|
| 3053 |
|
| 3054 |
Here an example, with \LaTeX{} and |\num| from \ctanpackage{siunitx}: |
| 3055 |
\begin{everbatim} |
| 3056 |
\RenewDocummentCommand\xintfloatexprPrintOne{o m}{\num{\xintFloat[#1]{#2}}} |
| 3057 |
\end{everbatim} |
| 3058 |
We could have used here simply |\def| with delimited parameters |[#1]#2| because: |
| 3059 |
\begin{itemize}[nosep] |
| 3060 |
\item the optional argument will always be present at time of use, |
| 3061 |
\item |\num| is a |\protected| macro. |
| 3062 |
\end{itemize} |
| 3063 |
Note that when using only |\def| for the definition, the argument of |\num| |
| 3064 |
is getting to be expanded first, but |\num| would have done that anyhow. |
| 3065 |
|
| 3066 |
With \ctanpackage{numprint}, one can similarly do: |
| 3067 |
\begin{everbatim} |
| 3068 |
\RenewDocumentCommand\xintfloatexprPrintOne{o m}{\numprint{\xintPFloat[#1]{#2}}} |
| 3069 |
\end{everbatim} |
| 3070 |
This used \csbxint{PFloat} rather than \csbxint{Float} as with |\num|. |
| 3071 |
This is because (in my limited testing) |\numprint| with not silently |
| 3072 |
remove a zero scientific exponent but it will typeset it, for example as |
| 3073 |
$1.5\cdot10^0$. So we use our own \csbxint{PFloat} poor man |
| 3074 |
\myenquote{prettifier}. |
| 3075 |
|
| 3076 |
Maybe you want to use a macro which is unable to have |
| 3077 |
|\xintPFloat[#1]{#2}| as argument because it needs to see only a number |
| 3078 |
in scientific notation and nothing else. If that macro is |\protected|, |
| 3079 |
do the definition with |\def|. It it is not |\protected| and not |
| 3080 |
purely expandable either, one can do this: |
| 3081 |
\begin{everbatim} |
| 3082 |
\protected\def\myfoo{\foo}%<<<--- with options perhaps |
| 3083 |
\def\xintfloatexprPrintOne[#1]#2{\myfoo{\xintPFloat[#1]{#2}}} |
| 3084 |
\end{everbatim} |
| 3085 |
Then when |\myfoo| finally expands, its argument has been expanded already. |
| 3086 |
|
| 3087 |
|
| 3088 |
The current behaviour of \csbxint{floateval} corresponds to this set-up: |
| 3089 |
\begin{everbatim} |
| 3090 |
\def\xintfloatexprPrintOne [#1]#2{\xintPFloat[#1]{#2}} |
| 3091 |
\end{everbatim} |
| 3092 |
and to this default configuration of \csbxint{PFloat}: |
| 3093 |
\begin{everbatim} |
| 3094 |
\def\xintPFloatE{e} |
| 3095 |
\def\xintPFloatZero{0} |
| 3096 |
\def\xintPFloatIntSuffix{} |
| 3097 |
\def\xintPFloatLengthOneSuffix{} |
| 3098 |
\def\xintPFloatNoSciEmax{5} |
| 3099 |
\def\xintPFloatNoSciEmin{-4} |
| 3100 |
\def\xintPFloatMinTrimmed{4} |
| 3101 |
\end{everbatim} |
| 3102 |
|
| 3103 |
With the custom replacement |
| 3104 |
\begin{everbatim} |
| 3105 |
\def\xintfloatexprPrintOne{\xintFloatToDecimal} |
| 3106 |
\end{everbatim} |
| 3107 |
the \csbxint{floateval} output will use decimal fixed point notation, |
| 3108 |
i.e.\@{} no scientific exponents, and as many zeros as are needed (but no |
| 3109 |
more, as trailing zeros will be removed from the significant digits). |
| 3110 |
Here is an example comparing outputs from the |
| 3111 |
default configuration and custom ones: |
| 3112 |
\begingroup % DÉBUT DU GROUPE POUR DES EXEMPLES |
| 3113 |
\begin{everbatim*} |
| 3114 |
\xintfloateval{exp(-32.456)/2000} (default, i.e. PFloat)\newline |
| 3115 |
\def\xintfloatexprPrintOne{\xintFloatToDecimal}% |
| 3116 |
\xintfloateval{exp(-32.456)/2000} (FloatToDecimal)\newline |
| 3117 |
\def\xintfloatexprPrintOne[#1]#2{\xintTeXFromSci{\xintFloat[#1]{#2}}}% |
| 3118 |
$\xintfloateval{exp(-32.456)/2000}$ (TeXFromSci on Float)\par % math mode required |
| 3119 |
\end{everbatim*} |
| 3120 |
|
| 3121 |
Some examples showing now the effect of sensible customizations on \csbxint{eval}: |
| 3122 |
\begin{everbatim*} |
| 3123 |
\xinteval{exp(-32.456)/2000} (default, i.e. FracToSci)\newline |
| 3124 |
\def\xintexprPrintOne{\xintFracToDecimal}% |
| 3125 |
\xinteval{exp(-32.456)/2000} (FracToDecimal)\newline |
| 3126 |
\def\xintexprPrintOne#1{\xintTeXFromSci{\xintFracToSci{#1}}}% |
| 3127 |
$\xinteval{exp(-32.456)/2000}$ (TexFromSci on FracToSci)\par % math mode required |
| 3128 |
\end{everbatim*} |
| 3129 |
Notice that the |/2000| denominator remains ``as is'' in the |
| 3130 |
output, in conformity with the documented behaviour of |
| 3131 |
\csbxint{FracToSci} in the first example and of \csbxint{FracToDecimal} |
| 3132 |
for the second example. This has not changed since |1.4| (the handling |
| 3133 |
of the numerator part has changed at |1.4e| and again slightly at |
| 3134 |
|1.4k|, the zero value being now always printed as \dtt{0} and not |
| 3135 |
\dtt{0} or \dtt{0.0} depending on the input) but is to be considered |
| 3136 |
unstable and undecided so far. |
| 3137 |
|
| 3138 |
A slightly more costly typesetter could be for example: |
| 3139 |
\begin{everbatim} |
| 3140 |
\def\xintexprPrintOne#1{\xintDecToStringREZ{\xintIrr{#1}}} |
| 3141 |
\end{everbatim} |
| 3142 |
Then |
| 3143 |
\begin{itemize}[nosep] |
| 3144 |
\item the fraction (inclusive of its power of ten part) will be reduced |
| 3145 |
to lowest terms (see \csbxint{Irr}), |
| 3146 |
\item next the trailing zeros will be moved as an exponent (positive or |
| 3147 |
negative) to the numerator, |
| 3148 |
\item this numerator with a power of ten part will be printed in decimal |
| 3149 |
fixed point notation, with as few zeros as are needed, |
| 3150 |
\item and finally the denominator |B|, which has been trimmed of trailing |
| 3151 |
zeros, will be printed as |/B| or not at all if |B=1|. |
| 3152 |
\end{itemize} |
| 3153 |
With the |
| 3154 |
use case above: |
| 3155 |
\begin{everbatim*} |
| 3156 |
\def\xintexprPrintOne#1{\xintDecToStringREZ{\xintIrr{#1}}} |
| 3157 |
\xinteval{exp(-32.456)/2000}\par |
| 3158 |
\end{everbatim*} |
| 3159 |
This trailing |/2| is somewhat of a pain, but as documented and |
| 3160 |
mentioned already \csbxint{DecToStringREZ} currently has not been |
| 3161 |
educated to identify its presence and handle it. Slightly faster (see |
| 3162 |
\csbxint{PIrr}) is |
| 3163 |
\begin{everbatim} |
| 3164 |
\def\xintexprPrintOne#1{\xintDecToStringREZ{\xintPIrr{#1}}} |
| 3165 |
\end{everbatim} |
| 3166 |
which with the used example produces the same output. |
| 3167 |
|
| 3168 |
One can also consider this for math mode: |
| 3169 |
\begin{everbatim*} |
| 3170 |
\def\xintexprPrintOne#1{\xintTeXFromSci{\xintDecToStringREZ{\xintIrr{#1}}}} |
| 3171 |
$\xinteval{exp(-32.456)/2000}$\par |
| 3172 |
\end{everbatim*} |
| 3173 |
See our hesitations about what \csbxint{TeXFromSci} should do with |
| 3174 |
denominators. |
| 3175 |
|
| 3176 |
\begin{TeXnote} |
| 3177 |
One can hope that in future \csbxint{DecToString} will identify |
| 3178 |
denominators being products of only two's and five's, but even then of |
| 3179 |
course \csbxint{TeXFromSci} will have to decide how to handle other |
| 3180 |
denominators. |
| 3181 |
\end{TeXnote} |
| 3182 |
|
| 3183 |
\endgroup % FIN DU GROUPE POUR LES EXEMPLES |
| 3184 |
|
| 3185 |
|
| 3186 |
\begin{TeXnote} |
| 3187 |
The macro used as customization of \csbxint{exprPrintOne} (whose default is |
| 3188 |
a private variant of \csbxint{FracToSci} with exactly same output) must |
| 3189 |
understand the internal \xintfracname format |A/B[N]|, but with the |/B| and |
| 3190 |
|[N]| parts being only optional. This is not a problem when using for this |
| 3191 |
task (nested) macros of \xintfracname, as they of course accept such |
| 3192 |
inputs as argument and in fact much more general ones. |
| 3193 |
|
| 3194 |
In particular one can benefit from \csbxint{Raw}, or \csbxint{RawBraced}, to |
| 3195 |
convert the argument into a well defined shape (|A/B[N]| for the former and |
| 3196 |
|{N}{A}{B}| for the latter) and then work from there. |
| 3197 |
|
| 3198 |
The macro used by \csbxint{floatexprPrintOne} has the guarantee that the |
| 3199 |
|[P]| will be always present at expansion time. |
| 3200 |
|
| 3201 |
The customization should be compatible with being exposed to |\expanded| |
| 3202 |
(which is like expansion in an |\edef|), either from being completely |
| 3203 |
expandable or at the opposite from being |\protected|. \LaTeX2e commands |
| 3204 |
defined via |\newcommand| as macros with one optional parameter are not |
| 3205 |
compatible with this requirement. |
| 3206 |
|
| 3207 |
Attention! The interface requirements described above for the macros |
| 3208 |
customizing the behaviours of \csbxint{exprPrintOne} and |
| 3209 |
\csbxint{floatexprPrintOne} may change at any release... as they |
| 3210 |
depend on some internal structures and it is not certain backwards |
| 3211 |
compatiblity will be maintained systematically in case of evolution. |
| 3212 |
\end{TeXnote} |
| 3213 |
|
| 3214 |
\subsubsection{\csh{xintthealign} for output of general oples} |
| 3215 |
\label{xintthealign} |
| 3216 |
|
| 3217 |
With \csbxint{thealign} one can get nested data use a \TeX{} alignment in the |
| 3218 |
output. Here is an example : |
| 3219 |
\begin{everbatim*} |
| 3220 |
\xintthealign\xintexpr ndseq(1/(i+j), i = 1..10; j=1..10)\relax |
| 3221 |
\end{everbatim*} |
| 3222 |
Attention, this \csa{xintthealign} must be a prefix to \csbxint{expr}, |
| 3223 |
or \csbxint{floatexpr} etc..., but there will be low-level \TeX\ errors |
| 3224 |
if it is used to prefix \csbxint{eval} et al. or \csbxint{theexpr} et al. |
| 3225 |
|
| 3226 |
It is possible to customize the behaviour of |\xintthealign|. For example: |
| 3227 |
\begin{everbatim} |
| 3228 |
\protected\def\xintexpralignbegin {\halign\bgroup\tabskip2ex\hfil##&&##\hfil\cr}% |
| 3229 |
\def\xintexpralignend {\crcr\egroup}% removed \protected at 1.4c |
| 3230 |
\protected\def\xintexpralignlinesep {,\cr}% separates "lines" |
| 3231 |
\protected\def\xintexpralignleftsep {&}% at left of first item in a "line" |
| 3232 |
% (after "left bracket") |
| 3233 |
\protected\def\xintexpraligninnersep {,&}% at the left of non-first items |
| 3234 |
\protected\def\xintexpralignrightsep {&}% at right of last item in a "line" |
| 3235 |
% (before "right bracket") |
| 3236 |
\protected\def\xintexpralignleftbracket {[}% |
| 3237 |
\protected\def\xintexpralignrightbracket{]}% |
| 3238 |
\end{everbatim} |
| 3239 |
The above definitions use |\protected| with no strong reason, as the |
| 3240 |
replacement tokens are not expanding anyhow, but the idea is that this |
| 3241 |
allows to execute a computation via an |\edef| and later one can change |
| 3242 |
the meaning of the auxiliary macros depending on what one wants to do |
| 3243 |
with the expansion result. |
| 3244 |
|
| 3245 |
\begin{TeXnote} |
| 3246 |
\csa{xintexpralignend} is expanded once, after the body has been submitted |
| 3247 |
to exhaustive expansion (|\expanded| induced), and prior to the expansion of |
| 3248 |
\csa{xintexpralignbegin}. |
| 3249 |
\end{TeXnote} |
| 3250 |
|
| 3251 |
Although we will try to keep stable the way \myenquote{regular arrays} as in the |
| 3252 |
above example are rendered by default,\UNSTABLE{} the |\xintthealign| |
| 3253 |
macro (and its associated customizability) is to be considered |
| 3254 |
work-in-progress and may experience breaking changes. |
| 3255 |
|
| 3256 |
Use for example this for outputting to a file or a terminal:% |
| 3257 |
% |
| 3258 |
{\catcode`^ 12 |
| 3259 |
\footnote{With the |xetex| engine this will need its |-8bit| option else |
| 3260 |
the |^^J| in |\xintexpralignlinesep| will be printed literally instead |
| 3261 |
of being converted into a line separator in the file or terminal output.}} |
| 3262 |
\begin{everbatim} |
| 3263 |
% Better here without \protected. |
| 3264 |
% We assume here \newlinechar has the LaTeX setting. |
| 3265 |
\def\xintexpralignbegin {}% |
| 3266 |
\def\xintexpralignend {}% |
| 3267 |
\def\xintexpralignlinesep {,^^J}% separates "lines" |
| 3268 |
\def\xintexpralignleftsep { }% at left of first item in a "line" (after brackets) |
| 3269 |
\def\xintexpraligninnersep {, }% at the left of non-first items |
| 3270 |
\def\xintexpralignrightsep { }% at right of last item in a "line" (before brackets) |
| 3271 |
\def\xintexpralignleftbracket {[}% |
| 3272 |
\def\xintexpralignrightbracket{]}% |
| 3273 |
\end{everbatim} |
| 3274 |
|
| 3275 |
In the \LaTeX{} example next using a |pmatrix| environment, |\noexpand| |
| 3276 |
rather than |\protected| is used. This environment will not break |
| 3277 |
across pages, contrarily to the display produced by the default |
| 3278 |
\csbxint{thealign} configuration which uses \TeX{}'s |\halign|. |
| 3279 |
%\kern10\baselineskip |
| 3280 |
%\hbox{Big empty space here} |
| 3281 |
%\kern-11\baselineskip |
| 3282 |
\begin{everbatim*} |
| 3283 |
\[ |
| 3284 |
\def\xintexpralignbegin {\begin{pmatrix}}% |
| 3285 |
\def\xintexpralignend {\end{pmatrix}}% |
| 3286 |
\def\xintexpralignlinesep {\noexpand\\}% needed to counteract an internal \expanded |
| 3287 |
\def\xintexpraligninnersep {&}% |
| 3288 |
\let\xintexpralignleftbracket\empty \let\xintexpralignleftsep\empty |
| 3289 |
\let\xintexpralignrightbracket\empty \let\xintexpralignrightsep\empty |
| 3290 |
% by default amsmath matrices can have 10 columns at most |
| 3291 |
% (cf amsmath documentation for what to do to allow more) |
| 3292 |
l.c.m.=\xintthealign\xintiiexpr ndmap(lcm, 1..12; 1..10)\relax |
| 3293 |
\] |
| 3294 |
\end{everbatim*} |
| 3295 |
|
| 3296 |
\subsection{Built-in operators and their precedences} |
| 3297 |
|
| 3298 |
|
| 3299 |
|
| 3300 |
The parser implements precedence rules based on concepts which are summarized |
| 3301 |
below (only for binary infix operators): |
| 3302 |
\begin{itemize}[noitemsep] |
| 3303 |
\item an infix operator has two associated precedence levels, say |L| for left |
| 3304 |
and |
| 3305 |
|R| for right, |
| 3306 |
\item the parser proceeds from left to right, pausing each time it has found a |
| 3307 |
new number and an operator following it, |
| 3308 |
\item the parser compares the left-precedence |L| of the new found operator to |
| 3309 |
the right-precedence |R_last| of the last delayed operation (which already |
| 3310 |
has one argument and would like to know if it can use the new found one): if |
| 3311 |
|L| is at most equal to it, the delayed operation is now executed, else the |
| 3312 |
new-found operation is kept around to be executed first, once it will have |
| 3313 |
gathered its arguments, of which only one is known at this stage. |
| 3314 |
\end{itemize} |
| 3315 |
This means for example in the case of the multiplication \oper{\lowast} and the |
| 3316 |
division operators \oper{/}, \oper{//}, \oper{/:} that they are parsed in a |
| 3317 |
left-associative way because they all share the same (left and right) |
| 3318 |
precedence level. This is the case with the analogous operators from the |
| 3319 |
Python language, as well. |
| 3320 |
|
| 3321 |
At |1.4g| the power operators were changed to act in a right associative |
| 3322 |
way. Again, this matches the behaviour of e.g.\@{} Python:% |
| 3323 |
\begin{everbatim*} |
| 3324 |
\xinteval{2^-3^4} |
| 3325 |
\end{everbatim*} |
| 3326 |
|
| 3327 |
|
| 3328 |
\makeatletter |
| 3329 |
\def\@floatboxreset{\@setminipage}% faudra contrôler celui-là |
| 3330 |
\makeatother |
| 3331 |
\begin{table}[htbp] |
| 3332 |
\edef\Ampersand{\string&}% |
| 3333 |
\edef\restorehtdpstrutbox |
| 3334 |
{\ht\strutbox\the\ht\strutbox\dp\strutbox\the\dp\strutbox} |
| 3335 |
\ht\strutbox12pt\dp\strutbox5pt |
| 3336 |
\capstart |
| 3337 |
\centering\begin{tabular}{|c|p{.5\textwidth}|} |
| 3338 |
\hline |
| 3339 |
\multicolumn{2}{|p{.6\textwidth}|}{\prec{$\infty$}: |
| 3340 |
at this top level the syntax elements whose |
| 3341 |
execution |
| 3342 |
is done prior to operators preceding them: |
| 3343 |
\begin{itemize}[nosep] |
| 3344 |
\item |
| 3345 |
\hyperref[ssec:builtinfunctions]{built-in} or |
| 3346 |
\hyperref[ssec:userfunctions]{user-defined} functions, |
| 3347 |
\item \hyperref[ssec:uservariables]{variables}, |
| 3348 |
\item the \oper{\empty\lowast} unpacking operator, |
| 3349 |
\item and intrinsic constituents of numbers: decimal mark \oper{\strut.}, |
| 3350 |
\oper{e} and \oper{E} of scientific notation, hexadecimal prefix |
| 3351 |
\oper{"}. |
| 3352 |
\end{itemize}\par\kern-\baselineskip\relax}% |
| 3353 |
\\\hline\hline |
| 3354 |
Precedence&``Operators'' at this level\strut\\ |
| 3355 |
\hline |
| 3356 |
\prec{20}& postfix \oper{!} and branching \oper{?}, \oper{??} operators\strut\\\hline |
| 3357 |
% |
| 3358 |
\prec{-}& minus sign as unary operator inherits the right-\hskip0pt precedence of |
| 3359 |
the infix operator it follows, if that precedence is higher than the one of |
| 3360 |
binary \oper{+} and \oper{-}, else it inherits the latter\strut\\\hline |
| 3361 |
% |
| 3362 |
\prec{18} (17)& \oper{\string^} and \oper{\lowast\lowast} are synonymous; |
| 3363 |
they act in a right-associative way (\textcolor[named]{Red}{\bfseries Changed at 1.4g!})\strut\\\hline |
| 3364 |
% |
| 3365 |
\prec{16} (14)& \hyperref[ssec:tacit multiplication]{Tacit |
| 3366 |
multiplication} has an elevated (left) precedence\strut\\\hline |
| 3367 |
% |
| 3368 |
\prec{14}& \oper{\lowast}, \oper{/}, \oper{//} (floored division), |
| 3369 |
and \oper{/:} (associated modulo, alias |
| 3370 |
\oper{'mod'})\strut\\\hline |
| 3371 |
% |
| 3372 |
\prec{12}& \oper{+}, \oper{-}\strut\\\hline |
| 3373 |
% |
| 3374 |
\prec{10}& \oper{<}, \oper{>}, \oper{==}, \oper{<=}, \oper{>=}, |
| 3375 |
\oper{!=} (they can be chained)\strut\\\hline |
| 3376 |
% |
| 3377 |
\prec{8}& Boolean conjunction \oper{\Ampersand\Ampersand} and |
| 3378 |
its alias \oper{'and'}\strut\\\hline |
| 3379 |
% |
| 3380 |
\prec{6}& Boolean disjunction \oper{\string|\string|} and |
| 3381 |
its alias \oper{'or'}. Also \oper{'xor'} and |
| 3382 |
\oper{\strut..}, \oper{..[}, |
| 3383 |
\oper{{]..}}, and \oper{:} have |
| 3384 |
this precedence\strut\\\hline |
| 3385 |
% |
| 3386 |
\prec{4}& the brackets for slicers and extractors \oper{\empty[}, |
| 3387 |
\oper{\empty]}\strut\\\hline |
| 3388 |
% |
| 3389 |
\prec{3}& the comma \oper{,}\strut\\\hline |
| 3390 |
% |
| 3391 |
\prec{2}& the bracketers \oper{[}, \oper{]} construct nestable \myenquote{arrays}\strut\\\hline |
| 3392 |
% |
| 3393 |
\prec{1}& the parentheses \oper{(}, \oper{)}, and the semi-colon |
| 3394 |
\oper{;} in \func{iter}, \func{rseq}, and further structures\strut\\\hline |
| 3395 |
% |
| 3396 |
\hline |
| 3397 |
% |
| 3398 |
\multicolumn{2}{|p{.6\textwidth}|}{% |
| 3399 |
\begin{itemize}[nosep] |
| 3400 |
\item Binary operators have a left and a right precedence, which for |
| 3401 |
most coincide. The right precedence is indicated within parentheses. |
| 3402 |
\item |
| 3403 |
\hyperref[ssec:tacit multiplication]{Tacit multiplication} has an elevated |
| 3404 |
left precedence level: |(1+2)/(3+4)5| |
| 3405 |
is computed as |(1+2)/((3+4)*5)| and |x/2y| is interpreted as |x/(2*y)| |
| 3406 |
when using variables. |
| 3407 |
\end{itemize} |
| 3408 |
}\\\hline |
| 3409 |
\end{tabular} |
| 3410 |
\caption{Precedence levels} |
| 3411 |
\label{tab:precedences} |
| 3412 |
\etoctoccontentsline {xinttable}{\protect\emph{Table of precedence levels of operators}} |
| 3413 |
\restorehtdpstrutbox |
| 3414 |
\end{table} |
| 3415 |
|
| 3416 |
The entries of \autoref{tab:precedences} are hyperlinked to the more detailed |
| 3417 |
discussion at each level. In these entries the number within parentheses |
| 3418 |
indicates the right-\hskip0pt precedence, if it differs from the left. |
| 3419 |
|
| 3420 |
\begin{description} |
| 3421 |
%[parsep=0pt, listparindent=\leftmarginiii] |
| 3422 |
% [parsep=0pt,align=left,itemindent=0pt, |
| 3423 |
% leftmargin=\leftmarginii, labelwidth=\leftmarginii, labelsep=0pt, |
| 3424 |
% labelindent=0pt, listparindent=\leftmarginiii] |
| 3425 |
\edef\Ampersand{\string&}% |
| 3426 |
|
| 3427 |
\precdesc{$\infty$} At this highest level of precedence, one finds: |
| 3428 |
\begin{description} |
| 3429 |
\item[{\hyperref[ssec:builtinfunctions]{functions} and |
| 3430 |
\hyperref[ssec:uservariables]{variables}}] |
| 3431 |
Functions (even the logic functions |
| 3432 |
\func{!} and \func{?} whose names consist of a single non-letter character) |
| 3433 |
must be used with parentheses. These parentheses may arise from expansion |
| 3434 |
after the function name is parsed (there are exceptions which are documented |
| 3435 |
at the relevant locations.) |
| 3436 |
|
| 3437 |
\operdesc{\empty\lowast} Python-like \myenquote{unpacking} prefix operator. Sometimes one |
| 3438 |
needs to use it as function |*()| (but I can't find an example right now) |
| 3439 |
but most of the time parentheses are unneeded. |
| 3440 |
|
| 3441 |
\operdesc{\strut.} is decimal mark; the number scanner treats it as an inherent, |
| 3442 |
optional and unique component of a being formed number. |
| 3443 |
|\xintexpr 0.^2+2^.0\relax| is interpreted as |0^2+2^0| and |
| 3444 |
thus produces \dtt{\xintexpr 0.^2+2^.0\relax}. |
| 3445 |
|
| 3446 |
Since release |1.2| an isolated decimal mark is illegal |
| 3447 |
input in the \xintexprname parsers (it remains legal as argument to the |
| 3448 |
macros of \xintfracname). |
| 3449 |
|
| 3450 |
\operdesc{e} scientific notation. |
| 3451 |
|
| 3452 |
\operdesc{E} scientific notation. For output, see \csbxint{PFloatE}. |
| 3453 |
|
| 3454 |
\operdesc{"} prefix for hexadecimal input. Only uppercase letters, and |
| 3455 |
one optional |.| separating integer and fractional hexadecimal parts. |
| 3456 |
|
| 3457 |
\begin{everbatim*} |
| 3458 |
\xintexpr "FEDCBA9876543210\relax\newline |
| 3459 |
\xintexpr ".FEDCBA9876543210\relax\newline |
| 3460 |
\xintexpr 16^5-("F75DE.0A8B9+"8A21.F5746+16^-5)\relax |
| 3461 |
\end{everbatim*} |
| 3462 |
|
| 3463 |
It is possible that in future the |"| prefix could be dropped in favour of |
| 3464 |
|0x| prefix. This would free |"| to be used for input of \myenquote{string}-like |
| 3465 |
entities. |
| 3466 |
\end{description} |
| 3467 |
|
| 3468 |
|
| 3469 |
\precdesc{20} |
| 3470 |
The postfix operators |!| and the branching conditionals |?|, |??|. |
| 3471 |
\begin{description} |
| 3472 |
\operdesc{!} computes the factorial of an integer. |
| 3473 |
|
| 3474 |
\operdesc{?} is used as |(stuff)?{yes}{no}|. It |
| 3475 |
evaluates |stuff| and chooses the |yes| branch if the result is |
| 3476 |
non-zero, else it executes |no|. After evaluation of |stuff| it acts as |
| 3477 |
a macro with two mandatory arguments within braces, chooses the |
| 3478 |
correct branch \emph{without evaluating the wrong one}. Once the braces |
| 3479 |
are removed, the parser scans and expands the uncovered material. |
| 3480 |
% so for |
| 3481 |
% example |
| 3482 |
% % |
| 3483 |
% \leftedline{|\xinttheiexpr (3>2)?{5+6}{7-1}2^3\relax|} |
| 3484 |
% % |
| 3485 |
% is legal and computes |
| 3486 |
% |5+62^3=|\dtt{\xinttheiexpr(3>2)?{5+(6}{7-(1}2^3)\relax}. It would be |
| 3487 |
% better practice to include here the |2^3| inside the branches. The |
| 3488 |
% contents of the branches may be arbitrary as long as once glued to what is |
| 3489 |
% next the syntax is respected: {|\xintexpr (3>2)?{5+(6}{7-(1}2^3)\relax| |
| 3490 |
% also works.} |
| 3491 |
|
| 3492 |
\operdesc{??} is used as |(stuff)??{<0}{=0}{>0}|, |
| 3493 |
where |stuff| is anything, its sign is evaluated and depending on the sign |
| 3494 |
the correct branch is un-braced, the two others are discarded with no |
| 3495 |
evaluation of their contents. |
| 3496 |
% The un-braced branch will then be parsed as |
| 3497 |
% usual. |
| 3498 |
% % |
| 3499 |
% \leftedline{|\def\x{0.33}\def\y{1/3}|} |
| 3500 |
% % |
| 3501 |
% \leftedline{|\xinttheexpr (\x-\y)??{sqrt}{0}{1/}(\y-\x)\relax|% |
| 3502 |
% \dtt{=\def\x{0.33}\def\y{1/3}% |
| 3503 |
% \xinttheexpr (\x-\y)??{sqrt}{0}{1/}(\y-\x)\relax }} |
| 3504 |
% % |
| 3505 |
\end{description} |
| 3506 |
|
| 3507 |
\precdesc{-} As unary operator, the minus sign inherits as precedence the |
| 3508 |
minimum of |12| (which is the precedence for addition and subtraction) and |
| 3509 |
of the (right-) precedence of the operators preceding it (if any). |
| 3510 |
\begin{everbatim*} |
| 3511 |
\xintexpr -3-4*-5^-7, (-3)-(4*(-(5^(-7))))\relax\newline |
| 3512 |
\xintexpr -3^-4*-5-7, (-((3^(-4))*(-5)))-7\relax\newline |
| 3513 |
|2^-10| gives \xintexpr 2^-10\relax\space |
| 3514 |
\end{everbatim*}and is thus perfectly legal, no need for parentheses. |
| 3515 |
|
| 3516 |
The |+| character as prefix unary operator is simply ignored during |
| 3517 |
input parsing. |
| 3518 |
|
| 3519 |
\precdesc{18} |
| 3520 |
\begin{description} |
| 3521 |
\operdesc{\string^} |
| 3522 |
\operdesc{\lowast\lowast} Both compute powers. They act in a right associative |
| 3523 |
way. |
| 3524 |
\begin{everbatim*} |
| 3525 |
\xintiiexpr 2^3^4\relax |
| 3526 |
\end{everbatim*} |
| 3527 |
\end{description} |
| 3528 |
% et: |
| 3529 |
% *2^-3^-4; |
| 3530 |
% (@_1) 0.991479137495678 |
| 3531 |
% *2**-3**-4; |
| 3532 |
% (@_2) 0.991479137495678 |
| 3533 |
% Python: |
| 3534 |
% >>> 2**-3**-4; |
| 3535 |
% 0.9914791374956781 |
| 3536 |
|
| 3537 |
\precdesc{16} see \hyperref[ssec:tacit multiplication]{Tacit multiplication}. |
| 3538 |
|
| 3539 |
\precdesc{14} |
| 3540 |
\begin{description} |
| 3541 |
\operdesc{\lowast} multiplication |
| 3542 |
|
| 3543 |
\operdesc{/} division: |
| 3544 |
\begin{itemize} |
| 3545 |
\item in \csbxint{eval}: exact division in the field of rational numbers (not |
| 3546 |
automatically reduced to lowest terms), |
| 3547 |
\item in \csbxint{floateval}: correct rounding of the exact division; the two |
| 3548 |
operands are, if necessary, float-rounded before the fraction is |
| 3549 |
evaluated and rounded (to obtain the correcty rounded |A/B| |
| 3550 |
without prior rounding of |A| and |B| see \func{qfloat}), |
| 3551 |
\item in \csbxint{iieval}: for compatibility with the legacy behaviour of |
| 3552 |
|/| in |\numexpr|, it rounds the exact fraction \emph{with half-integers |
| 3553 |
going towards the infinity of the same sign}. |
| 3554 |
\end{itemize} |
| 3555 |
The division is left-associative. Example: |
| 3556 |
\begin{everbatim*} |
| 3557 |
\xintexpr reduce(100/50/2)\relax |
| 3558 |
\end{everbatim*} |
| 3559 |
|
| 3560 |
\operdesc{//} floored division (and thus produces an integer, see |
| 3561 |
\func{divmod} for details) |
| 3562 |
|
| 3563 |
\operdesc{/:} the associated modulo (see \func{divmod} and \func{mod}) |
| 3564 |
|
| 3565 |
Left-associativity applies to the division operators: |
| 3566 |
\begin{everbatim*} |
| 3567 |
\xintexpr 100000/:13, 100000 'mod' 13\relax, \xintexpr 100000/:13/13\relax |
| 3568 |
\end{everbatim*} |
| 3569 |
|
| 3570 |
Nothing special needs to be done in contexts such as \LaTeX3 |
| 3571 |
|\ExplSyntaxOn| where |:| is of catcode letter, but if |:| is an |
| 3572 |
active character one needs to use input such as |/\string :| |
| 3573 |
(or replace it with usage of the function \func{mod}). |
| 3574 |
|
| 3575 |
Bulky workarounds such as |/\string :| are \fbox{\emph{unneeded}} if activation |
| 3576 |
is due to Babel.\NewWith{1.4n} See also \csbxint{exprSafeCatcodes} and |
| 3577 |
a framed note found in \autoref{xintexpr}. |
| 3578 |
|
| 3579 |
\operdesc{'mod'} is same as \oper{/:}. |
| 3580 |
|
| 3581 |
\fbox{Attention:}\IMPORTANTf{} with \ctanpackage{polexpr} loaded, which |
| 3582 |
allows |'| in variable and function names, |'mod'| can not follow |
| 3583 |
a variable name. Add parentheses around the variable, or use |/:|. |
| 3584 |
|
| 3585 |
\end{description} |
| 3586 |
|
| 3587 |
\precdesc{12} |
| 3588 |
\begin{description} |
| 3589 |
\operdesc{+} addition |
| 3590 |
|
| 3591 |
\operdesc{-} subtraction. According to the general left-associativity rule in |
| 3592 |
case of equal precedence, it is |
| 3593 |
left associative: |
| 3594 |
\begin{everbatim*} |
| 3595 |
\xintiiexpr 100-50-2\relax |
| 3596 |
\end{everbatim*} |
| 3597 |
\end{description} |
| 3598 |
|
| 3599 |
\precdesc{10} Comparison operators are (as in Python) all at the same level of |
| 3600 |
precedence, use parentheses for disambiguation. |
| 3601 |
\begin{description} |
| 3602 |
\operdesc{<} |a<b| evaluates to \dtt{1} if the strict inequality holds to \dtt{0} |
| 3603 |
if not. |
| 3604 |
|
| 3605 |
\operdesc{>} |a>b| evaluates to \dtt{1} if the strict inequality holds to \dtt{0} |
| 3606 |
if not. |
| 3607 |
|
| 3608 |
\operdesc{==} |a==b| evaluates to \dtt{1} if equality holds to \dtt{0} |
| 3609 |
if not. |
| 3610 |
|
| 3611 |
\operdesc{<=} |a<=b| evaluates to \dtt{1} if left hand side is at most equal |
| 3612 |
to right hand side, to \dtt{0} |
| 3613 |
if not. |
| 3614 |
|
| 3615 |
\operdesc{>=} |a>=b| evaluates to \dtt{1} if left hand side is at least equal |
| 3616 |
to right hand side, to \dtt{0} |
| 3617 |
if not. |
| 3618 |
|
| 3619 |
\operdesc{!=} |a!=b| evaluates to \dtt{1} if they differ, to \dtt{0} |
| 3620 |
if not. |
| 3621 |
\end{description} |
| 3622 |
|
| 3623 |
Comparisons can be chained arbitrarily, e.g., |x < y <= z != |
| 3624 |
t| is equivalent to |x < y 'and' y <= z 'and' z != t| (and also to |all(x<y, |
| 3625 |
y<=z, z!=t)|), except that if |y| and |z| involve computations, they |
| 3626 |
are evaluated only once. Currently there is no short-circuit here, i.e.\@ |
| 3627 |
even if some intermediate comparison turns out false (in fact |0|), all the |
| 3628 |
remaining conditionals will still be evaluated. |
| 3629 |
|
| 3630 |
\begin{everbatim*} |
| 3631 |
\xintifboolexpr{1<=2!=3<4>1}{true}{\error}, |
| 3632 |
\xintifboolexpr{1<=2>=3<4>1}{\error}{false}, |
| 3633 |
\xintifboolexpr{3 != 3! == 6 != 4! == 24}{true}{\error} |
| 3634 |
\end{everbatim*} |
| 3635 |
|
| 3636 |
\precdesc{8} |
| 3637 |
\begin{description} |
| 3638 |
\operdesc{\Ampersand\Ampersand} logical conjunction. Evaluates to \dtt{1} if |
| 3639 |
both sides are non-zero, to \dtt{0} if not. |
| 3640 |
|
| 3641 |
\operdesc{'and'} same as \verb+&&+. See |
| 3642 |
also the \func{all} multi-arguments function. |
| 3643 |
|
| 3644 |
\fbox{Attention:}\IMPORTANTf{} with \ctanpackage{polexpr} loaded, which |
| 3645 |
allows |'| in variable and function names, |'and'| can not follow |
| 3646 |
a variable name. Add parentheses around the variable, or use |&&|. |
| 3647 |
\end{description} |
| 3648 |
|
| 3649 |
\precdesc{6} |
| 3650 |
\begin{description} |
| 3651 |
\operdesc{\string|\string|} logical (inclusive) disjunction. Evaluates to |
| 3652 |
\dtt{1} if one or both sides are non-zero, to \dtt{0} if not. |
| 3653 |
|
| 3654 |
\operdesc{'or'} same as as \verb+||+. See also the \func{any} multi-arguments |
| 3655 |
function. |
| 3656 |
|
| 3657 |
\fbox{Attention:}\IMPORTANTf{} with \ctanpackage{polexpr} loaded, which |
| 3658 |
allows |'| in variable and function names, |'or'| can not follow |
| 3659 |
a variable name. Add parentheses around the variable, or use \verb=||=. |
| 3660 |
|
| 3661 |
\operdesc{'xor'} logical (exclusive) disjunction. |
| 3662 |
|
| 3663 |
\fbox{Attention:}\IMPORTANTf{} with \ctanpackage{polexpr} loaded, which |
| 3664 |
allows |'| in variable and function names, |'xor'| can not follow a variable |
| 3665 |
name. Add parentheses around the variable, or use the \func{xor} function syntax. |
| 3666 |
|
| 3667 |
\operdesc{\strut..} |
| 3668 |
\operdesc{..[} |
| 3669 |
\operdesc{{]..}} Syntax for arithmetic |
| 3670 |
progressions. See \autoref{ssec:arithseq}. |
| 3671 |
|
| 3672 |
\operdesc{:} This is a separator involved in |[a:b]| Python-like slicing syntax. |
| 3673 |
\end{description} |
| 3674 |
|
| 3675 |
\precdesc{4} |
| 3676 |
\begin{description} |
| 3677 |
\operdesc{\empty[} |
| 3678 |
\operdesc{\empty]} |
| 3679 |
Involved in Python-like slicing |[a:b]| and extracting |[N]| syntax. And its |
| 3680 |
extension à la NumPy |[a:b,N,c:d,...,:]|. Ellipsis |...| is not yet implemented. |
| 3681 |
The \myenquote{step} parameter as in |[a:b:step]| is not yet implemented. |
| 3682 |
\end{description} |
| 3683 |
|
| 3684 |
\precdesc{3} |
| 3685 |
\begin{description} |
| 3686 |
\operdesc{,} |
| 3687 |
The comma separates expressions (or function arguments).% |
| 3688 |
% |
| 3689 |
\footnote{The comma |
| 3690 |
is really like a binary operator, which may be called ``join''. It has |
| 3691 |
lowest precedence of all (apart the parentheses) because when it is |
| 3692 |
encountered all postponed operations are executed in order to finalize its |
| 3693 |
\emph{first} operand; only a new comma or a closing parenthesis or the end |
| 3694 |
of the expression will finalize its \emph{second} operand.} |
| 3695 |
% |
| 3696 |
\begin{everbatim*} |
| 3697 |
\xintiiexpr 2^3,3^4,5^6\relax |
| 3698 |
\end{everbatim*} |
| 3699 |
\end{description} |
| 3700 |
|
| 3701 |
\precdesc{2} |
| 3702 |
\begin{description} |
| 3703 |
\operdesc{[} |
| 3704 |
\operdesc{]} The bracketers construct nestable \myenquote{array-like} |
| 3705 |
structures. Arbitrary (heterogeneous) nesting is allowed. For output related |
| 3706 |
matters see \csbxint{thealign} (its usage is optional, without it rendering |
| 3707 |
is \myenquote{one-dimensional}). Output shape of non-homogeneous arrays is to |
| 3708 |
be considered unstable at this time. |
| 3709 |
\end{description} |
| 3710 |
|
| 3711 |
\precdesc{1} |
| 3712 |
\begin{description} |
| 3713 |
\operdesc{(} |
| 3714 |
\operdesc{)} |
| 3715 |
The parentheses serve as mandatory part of the syntax for functions, and to |
| 3716 |
disambiguate precedences.% |
| 3717 |
% |
| 3718 |
\footnote{It is not apt to describle the |
| 3719 |
opening parenthesis as an operator, but the closing parenthesis is analogous |
| 3720 |
to a postfix unary operator. It has lowest precedence which means |
| 3721 |
that when it is encountered all postponed operations are executed to finalize |
| 3722 |
its operand. The start of this operand was decided by the opening |
| 3723 |
parenthesis.} |
| 3724 |
% |
| 3725 |
They do not construct any nested structure. |
| 3726 |
|
| 3727 |
\operdesc{;} The semi-colon as involved as part of the syntax of \func{iter}, |
| 3728 |
\func{rseq}, \func{ndseq}, \func{ndmap} has the same |
| 3729 |
precedence as a closing parenthesis. |
| 3730 |
\end{description} |
| 3731 |
|
| 3732 |
\item[|\relax|] This is the expression terminator for \csbxint{expr} et al. |
| 3733 |
It may arise from expansion during the parsing itself. As alternative to |
| 3734 |
\csbxint{expr} (et al.) use |
| 3735 |
\csbxint{eval} (et al.) which have the usual macro interface (with one mandatory |
| 3736 |
argument). |
| 3737 |
\end{description} |
| 3738 |
|
| 3739 |
The |;| also serves as syntax terminator for \csbxint{defvar} and |
| 3740 |
\csbxint{deffunc}. It can in this rôle not arise from expansion as the |
| 3741 |
expression body up to it is fetched by a delimited macro. But this is done in |
| 3742 |
a way which does not require any specific hiding for inner semi-colons as |
| 3743 |
involved in the syntax of \func{iter}, etc... |
| 3744 |
|
| 3745 |
\subsection{Built-in functions}\label{ssec:builtinfunctions} |
| 3746 |
|
| 3747 |
|
| 3748 |
See \autoref{tab:functions} whose elements are hyperlinked to the |
| 3749 |
corresponding definitions. |
| 3750 |
|
| 3751 |
Functions are at the same top level of priority. All functions even |
| 3752 |
\func{?} and \func{!} require parentheses around their arguments. |
| 3753 |
|
| 3754 |
% Table of functions |
| 3755 |
|
| 3756 |
\begin{table}[htbp] |
| 3757 |
\capstart |
| 3758 |
\centering |
| 3759 |
\xintAssignArray\xintCSVtoList{!, ?, \textasciigrave\lowast\textasciigrave, \textasciigrave+\textasciigrave, |
| 3760 |
abs, add, all, any, acos, acosd, Arg, Argd, asin, asind, atan, atand, |
| 3761 |
atan2, atan2d, |
| 3762 |
binomial, bool, |
| 3763 |
ceil, cos, cosd, cot, cotd, cotg, csc, cscd, |
| 3764 |
divmod, even, exp, |
| 3765 |
factorial, first, flat, float, float\string_dgt, floor, frac, gcd, |
| 3766 |
if, ifint, ifone, ifsgn, ilog10, iquo, irem, isint, isone, iter, iterr, inv, |
| 3767 |
last, lcm, len, log, log10, max, min, mod, mul, |
| 3768 |
ndmap, ndseq, ndfillraw, |
| 3769 |
not, num, nuple, odd, |
| 3770 |
pArg, pArgd, pfactorial, pow, pow10, preduce, |
| 3771 |
qfloat, qfrac, qint, qrand, qraw, |
| 3772 |
random, randrange, rbit, reduce, reversed, round, rrseq, rseq, |
| 3773 |
sec, secd, seq, sgn, sin, sinc, sind, sqr, sqrt, sqrtr, |
| 3774 |
subs, subsm, subsn, |
| 3775 |
tan, tand, tg, togl, trunc, unpack, |
| 3776 |
xor, zip} |
| 3777 |
\to\Functions |
| 3778 |
\cnta\Functions{0} |
| 3779 |
\cntb\xinttheexpr ceil(\cnta/7)\relax\space |
| 3780 |
\newcommand\builtinfunction[1]{\expandafter\expandafter\expandafter\func |
| 3781 |
\expandafter\expandafter\expandafter{\Functions{#1}}}% |
| 3782 |
\centeredline{\begin{tabular}{|*{7}{p{2cm}|}} |
| 3783 |
\hline |
| 3784 |
\xintFor* #1 in {\xintSeq{1}{\cntb}}\do |
| 3785 |
{\builtinfunction{#1}& |
| 3786 |
\builtinfunction{#1+\cntb}&% |
| 3787 |
\builtinfunction{#1+2*\cntb}&% |
| 3788 |
\builtinfunction{#1+3*\cntb}&% |
| 3789 |
\builtinfunction{#1+4*\cntb}&% |
| 3790 |
\builtinfunction{#1+5*\cntb}&% |
| 3791 |
\ifnumgreater{#1+6*\cntb}{\cnta} |
| 3792 |
{} |
| 3793 |
{\builtinfunction{#1+6*\cntb}}% |
| 3794 |
\\\hline}% |
| 3795 |
\end{tabular}} |
| 3796 |
\caption{Functions (click on names)}\label{tab:functions} |
| 3797 |
\etoctoccontentsline {xinttable}{\protect\emph{Table of functions in expressions}} |
| 3798 |
\etocsetnexttocdepth{subsubsection} |
| 3799 |
\localtableofcontents |
| 3800 |
\end{table} |
| 3801 |
|
| 3802 |
|
| 3803 |
Miscellaneous notes: |
| 3804 |
\begin{itemize}[nosep] |
| 3805 |
\item since release |1.3d| \func{gcd} and \func{lcm} are extended to apply |
| 3806 |
to fractions too, and do NOT require the loading of \xintgcdname, |
| 3807 |
|
| 3808 |
\item The randomness related functions \func{random}, \func{qrand} and |
| 3809 |
\func{randrange} require that the \TeX\ engine provides the |
| 3810 |
\csa{uniformdeviate} or \csa{pdfuniformdeviate} primitive. This is |
| 3811 |
currently the case for |pdftex|, |(u)ptex|, |luatex|, and also for |
| 3812 |
|xetex| since \TeX Live 2019.\IMPORTANT |
| 3813 |
|
| 3814 |
\item \func{togl} is provided for the case |etoolbox| package is loaded, |
| 3815 |
|
| 3816 |
\item \func{bool}, \func{togl} use delimited macros to fetch their argument and the |
| 3817 |
closing parenthesis must be explicit, it can not arise from |
| 3818 |
on the spot expansion. The same holds for \func{qint}, \func{qfrac}, |
| 3819 |
\func{qfloat}, \func{qraw}, \func{random} and \func{qrand}. |
| 3820 |
|
| 3821 |
\item Also \hyperlink{ssec:dummies}{functions with dummy variables} use |
| 3822 |
delimited macros for some tasks. See the relevant explanations there. |
| 3823 |
|
| 3824 |
\item Functions may be called with \emph{oples} as arguments as long as |
| 3825 |
the total length is the number of arguments the function expects. |
| 3826 |
\end{itemize} |
| 3827 |
|
| 3828 |
\subsubsection{Functions with no argument} |
| 3829 |
|
| 3830 |
\begin{description} |
| 3831 |
% [parsep=0pt,align=left, |
| 3832 |
% leftmargin=0pt, itemindent=0pt, |
| 3833 |
% labelwidth=-\fontdimen2\font, labelsep=\fontdimen2\font, labelindent=0pt, |
| 3834 |
% listparindent=\leftmarginiii] |
| 3835 |
|
| 3836 |
\funcdesc[]{random} returns a random float |x| verifying |0 <= x < 1|. It |
| 3837 |
obeys the prevailing precision as set by \csbxint{Digits}: i.e.\@{} with |P| |
| 3838 |
being the precision the random float multiplied by |10^P| is an integer, |
| 3839 |
uniformly distributed in the |0..10^P-1| range. |
| 3840 |
|
| 3841 |
This description implies that if |x| turns out to be |<0.1| then |
| 3842 |
its (normalized) mantissa has |P-1| digits and a trailing zero, if |x<0.01| |
| 3843 |
it has |P-2| digits and two trailing zeros, etc... This is what is observed |
| 3844 |
also with Python's |random()|, of course with |10| replaced there by radix |
| 3845 |
|2|.% |
| 3846 |
\begin{everbatim*} |
| 3847 |
\pdfsetrandomseed 12345 |
| 3848 |
\xintDigits:=37\relax |
| 3849 |
\xintthefloatexpr random()\relax\newline |
| 3850 |
\xintthefloatexpr random()\relax\par |
| 3851 |
\end{everbatim*} |
| 3852 |
|
| 3853 |
\funcdesc[]{qrand} returns a random float |0 <= x < 1| using \dtt{16} digits of |
| 3854 |
precision (i.e.\@{} |10^{16}x| is an integer). This is provided when speed is a |
| 3855 |
at premium as it is optimized for precision being precisely \dtt{16}.% |
| 3856 |
|
| 3857 |
\begin{everbatim*} |
| 3858 |
% still with 37 digits as prevailing float precision |
| 3859 |
\xintthefloatexpr qrand(), random()\relax\newline |
| 3860 |
\xintDigits:=16\relax |
| 3861 |
\xintthefloatexpr qrand(), random()\relax\par |
| 3862 |
\end{everbatim*} |
| 3863 |
|
| 3864 |
One can use both |qrand()| and |random()| inside the |\xintexpr| parser too. |
| 3865 |
But inside the integer only |\xintiiexpr| parser they will cause some |
| 3866 |
low-level error as soon as they get involved in any kind of computation as |
| 3867 |
they use an internal format not recognized by the integer-only parser. |
| 3868 |
|
| 3869 |
See further \func{randrange}, which generates random integers. |
| 3870 |
|
| 3871 |
Currently there is no |uniform()| function% |
| 3872 |
% |
| 3873 |
\footnote{Because I am not sure how to handle rounding issues: should the |
| 3874 |
computation proceed exactly and a rounding be done only at very end?} |
| 3875 |
% |
| 3876 |
but it can be created by user: |
| 3877 |
\begin{everbatim*} |
| 3878 |
\xintdeffloatfunc uniform(a, b):= a + (b-a)*random(); |
| 3879 |
\romannumeral\xintreplicate{10}% |
| 3880 |
{% |
| 3881 |
\xintthefloatexpr uniform(123.45678, 123.45679)\relax\newline |
| 3882 |
}% |
| 3883 |
\end{everbatim*} |
| 3884 |
|
| 3885 |
\funcdesc[]{rbit} returns a random |0| or |1|. |
| 3886 |
|
| 3887 |
\end{description} |
| 3888 |
|
| 3889 |
\subsubsection{Functions with one argument} |
| 3890 |
|
| 3891 |
\begin{description} |
| 3892 |
% [parsep=0pt,align=left, |
| 3893 |
% leftmargin=0pt, itemindent=0pt, |
| 3894 |
% labelwidth=-\fontdimen2\font, labelsep=\fontdimen2\font, labelindent=0pt, |
| 3895 |
% listparindent=\leftmarginiii] |
| 3896 |
|
| 3897 |
\funcdesc{num} truncates to the nearest integer (truncation towards zero). It |
| 3898 |
has the same sign as |x|, except of course with |-1<x<1| as then |num(x)| is |
| 3899 |
zero. |
| 3900 |
\begin{everbatim*} |
| 3901 |
\xinttheexpr num(3.1415^20), num(1e20)\relax |
| 3902 |
\end{everbatim*} |
| 3903 |
The output is an explicit integer with as many zeros are as necessary. Even |
| 3904 |
in float expressions, there will be an intermediate stage where all needed digits |
| 3905 |
are there, but then the integer is immediately reparsed as a float to the target |
| 3906 |
precision, either because some operation applies to it, or from the output |
| 3907 |
routine of \csbxint{floatexpr} if it stood there alone. Hence, |
| 3908 |
inserting something like |num(1e10000)| is costly as it really creates ten |
| 3909 |
thousand zeros, even though later the whole thing becomes a float again. On |
| 3910 |
the other hand naturally |1e10000| without |num()| would be simply parsed as |
| 3911 |
a floating point number and would cause no specific overhead. |
| 3912 |
|
| 3913 |
\funcdesc{frac} fractional part. |
| 3914 |
For all numbers |x=num(x)+frac(x)|, and |frac(x)| has the same sign as |x| |
| 3915 |
except when |x| is an integer, as then |frac(x)| vanishes. |
| 3916 |
\begin{everbatim*} |
| 3917 |
\xintthefloatexpr frac(-355/113), frac(-1129.218921791279)\relax |
| 3918 |
\end{everbatim*} |
| 3919 |
|
| 3920 |
\funcdesc{reduce} reduces a fraction to smallest terms |
| 3921 |
\begin{everbatim*} |
| 3922 |
\xinttheexpr reduce(50!/20!/20!/10!)\relax |
| 3923 |
\end{everbatim*} |
| 3924 |
|
| 3925 |
Recall that this is NOT done automatically, for example when adding fractions. |
| 3926 |
\funcdesc{preduce} internally, fractions may have some power of ten part |
| 3927 |
(for example when they got input in scientific notation). This function |
| 3928 |
ignores the decimal part when doing the reduction. See \csbxint{PIrr}. |
| 3929 |
\begin{everbatim*} |
| 3930 |
\xinttheexpr preduce(10e7/2), reduce(10e7/2)\relax |
| 3931 |
\end{everbatim*} |
| 3932 |
|
| 3933 |
\funcdesc{abs} absolute value |
| 3934 |
\funcdesc{sgn} sign. See also \csbxint{ifsgnexpr}. |
| 3935 |
\funcdesc{inv} inverse. |
| 3936 |
\funcdesc{floor} floor function. |
| 3937 |
\funcdesc{ceil} ceil function. |
| 3938 |
\funcdesc{sqr} square. |
| 3939 |
\item[ilog10(x)]\hypertarget{func:ilog10-ii} |
| 3940 |
in |\xintiiexpr| the integer exponent $a$ such that $10^a\leq |
| 3941 |
\mathrm{abs}(x)< 10^{a+1}$; returns (this may evolve in future) |
| 3942 |
\dtt{\xintiieval{ilog10(0)}} if $x$ vanishes (i.e.\@{} \dtt{0x7fff8000}). |
| 3943 |
\begin{everbatim*} |
| 3944 |
\xintiieval{ilog10(1), ilog10(-1234567), ilog10(-123456789123456789), ilog10(2**31)}\par |
| 3945 |
\end{everbatim*} |
| 3946 |
See \func{ilog10} for the behaviour in \csbxint{expr}-essions. |
| 3947 |
\item[sqrt(x)]\hypertarget{func:sqrt-ii} |
| 3948 |
in |\xintiiexpr|, truncated square root; in |\xintexpr| or |
| 3949 |
|\xintfloatexpr| this is the floating point square root, and there is an |
| 3950 |
optional second argument for the precision. See \func{sqrt}. |
| 3951 |
\funcdesc{sqrtr} available \emph{only} in |\xintiiexpr|, rounded square root. |
| 3952 |
\item[factorial(x)]\hypertarget{func:factorial-ii} factorial function (like the |
| 3953 |
post-fix \oper{!} operator.) When used in |\xintexpr| or |
| 3954 |
|\xintfloatexpr| there is an optional second argument. See \func{factorial}. |
| 3955 |
\funcdesc{?} is the truth value, $1$ if non zero, $0$ if zero. Must use parentheses. |
| 3956 |
\funcdesc{!} is logical not, $0$ if non zero, $1$ if zero. Must use parentheses. |
| 3957 |
\funcdesc{not} logical not. |
| 3958 |
\funcdesc{even} is the evenness of the truncation |num(x)|. |
| 3959 |
\begin{everbatim*} |
| 3960 |
\xintthefloatexpr [3] seq((x,even(x)), x=-5/2..[1/3]..+5/2)\relax |
| 3961 |
\end{everbatim*} |
| 3962 |
|
| 3963 |
\funcdesc{odd} is the oddness of the truncation |num(x)|. |
| 3964 |
\begin{everbatim*} |
| 3965 |
\xintthefloatexpr [3] seq((x,odd(x)), x=-5/2..[1/3]..+5/2)\relax |
| 3966 |
\end{everbatim*} |
| 3967 |
|
| 3968 |
\funcdesc{isint} evaluates to 1 if |x| is an integer, to 0 if |
| 3969 |
not. See \func{ifint}. |
| 3970 |
\begin{everbatim*} |
| 3971 |
$\xinttheexpr -5/3..[1/3]..+5/3\relax |
| 3972 |
\rightarrow \xinttheexpr seq(isint(x), x=-5/3..[1/3]..+5/3)\relax$ |
| 3973 |
\end{everbatim*} |
| 3974 |
|
| 3975 |
\funcdesc{isone} evaluates to 1 if |x| is 1, to 0 if not. |
| 3976 |
See \func{ifone}. |
| 3977 |
\begin{everbatim*} |
| 3978 |
$\xintthefloatexpr subs(((x-1)/x, x/x, (x+1)/x), x=2**30)\relax |
| 3979 |
\rightarrow |
| 3980 |
\xintthefloatexpr seq(isone(y), y=subs(((x-1)/x, x/x, (x+1)/x), x=2**30))\relax$ |
| 3981 |
\end{everbatim*} |
| 3982 |
|
| 3983 |
\funcdesc{qint} belongs with \func{qfrac}, \func{qfloat}, \func{qraw} to a |
| 3984 |
special category: |
| 3985 |
\begin{enumerate}[nolistsep] |
| 3986 |
\item They require the closing parenthesis of their argument to be |
| 3987 |
immediately visible, it can not arise from expansion. |
| 3988 |
\item They grab the argument and store it directly; the format must be |
| 3989 |
compatible with what is expected at macro level. |
| 3990 |
\item And in particular the argument can not be a variable, it has to be |
| 3991 |
numerical. |
| 3992 |
\end{enumerate} |
| 3993 |
|
| 3994 |
\func{qint} achieves the same result as |num|, but the argument is grabbed |
| 3995 |
as a whole without expansion and handed over to the |
| 3996 |
\csbxint{iNum} macro. The |q| stands for ``quick'', and |qint| is thought |
| 3997 |
out for use in \csbxint{iiexpr}|...\relax| with integers having dozens of |
| 3998 |
digits. |
| 3999 |
|
| 4000 |
Testing showed that using |qint()| starts getting advantageous for inputs |
| 4001 |
having more (or \fexpan ding to more) than circa \dtt{20} explicit digits. |
| 4002 |
But for hundreds of digits the input gain becomes a negligible |
| 4003 |
proportion of (for example) the cost of a multiplication. |
| 4004 |
|
| 4005 |
Leading signs and then |
| 4006 |
zeroes will be handled appropriately but spaces will not be systematically |
| 4007 |
stripped. They should cause no harm and will be removed as soon as the |
| 4008 |
number is used with one of the basic operators. This input mode \emph{does |
| 4009 |
not accept decimal part or scientific part}. |
| 4010 |
\begin{everbatim} |
| 4011 |
\def\x{....many many many ... digits}\def\y{....also many many many digits...} |
| 4012 |
\xinttheiiexpr qint(\x)*qint(\y)+qint(\y)^2\relax\par |
| 4013 |
\end{everbatim} |
| 4014 |
|
| 4015 |
\funcdesc{qfrac} does the same as \dtt{qint} except that it accepts |
| 4016 |
fractions, decimal numbers, scientific numbers as they are understood by |
| 4017 |
the macros of package \xintfracname. Thus, it is for use in |
| 4018 |
\csbxint{expr}|...\relax|. It is not usable within an |
| 4019 |
|\xintiiexpr|-ession, except if hidden inside functions such as |
| 4020 |
\dtt{round} or \dtt{trunc} which then produce integers acceptable to the |
| 4021 |
integer-only parser. It has nothing to do with |frac| (sigh...). |
| 4022 |
|
| 4023 |
\funcdesc{qfloat} does the same as \dtt{qfrac} and then converts to a float |
| 4024 |
with the precision given by the setting of |\xintDigits|. This can be used |
| 4025 |
in \csbxint{expr} to round a fraction as a float with the same result as |
| 4026 |
with the |float()| function (whereas using |\xintfloatexpr A/B\relax| |
| 4027 |
inside \csbxint{expr}|...\relax| would first round |A| and |B| to the |
| 4028 |
target precision); or it can be used inside |
| 4029 |
\csbxint{floatexpr}|...\relax| as a faster alternative to wrapping |
| 4030 |
the fraction in a sub-\csbxint{expr}-ession. |
| 4031 |
For example, the next two computations done with \dtt{16} digits |
| 4032 |
of precision do not give the same result: |
| 4033 |
\begin{everbatim*} |
| 4034 |
\xintthefloatexpr qfloat(12345678123456785001/12345678123456784999)-0.5\relax\newline |
| 4035 |
\xintthefloatexpr 12345678123456785001/12345678123456784999-0.5\relax\newline |
| 4036 |
\xintthefloatexpr 1234567812345679/1234567812345678-0.5\relax\newline |
| 4037 |
\xintthefloatexpr \xintexpr12345678123456785001/12345678123456784999\relax-0.5\newline |
| 4038 |
\end{everbatim*}% |
| 4039 |
because the second is equivalent to the third, whereas the |
| 4040 |
first one is equivalent to the fourth one. Equivalently one can use |
| 4041 |
|qfrac| to the same effect (the subtraction provoking the rounding of its |
| 4042 |
two arguments before further processing.) |
| 4043 |
|
| 4044 |
Note that if the input needs no special rounding, the internal form of the |
| 4045 |
output keeps a short mantissa (it does not add padding zeros to make it of |
| 4046 |
length equal to the float precision). For example |qfloat(2[20])| would |
| 4047 |
keep internally the input format. |
| 4048 |
|
| 4049 |
\funcdesc{float\string_dgt} is like \func{float} and avoids \func{float}'s |
| 4050 |
check whether it used with its second optional argument. This is useful |
| 4051 |
in the context of converting function definitions done via |
| 4052 |
\csbxint{deffunc} (see explanations there) to functions usable in |
| 4053 |
\csbxint{floateval}. |
| 4054 |
|
| 4055 |
\funcdesc{nuple} is currently same as |[...]|.\DNU{(1.4)} Reserved for |
| 4056 |
possible alternative meaning in future. |
| 4057 |
\begin{everbatim*} |
| 4058 |
\xinteval{nuple(1,2,3)} |
| 4059 |
\end{everbatim*} |
| 4060 |
|
| 4061 |
\funcdesc{unpack} is alternative for |*| unpacking operator. |
| 4062 |
\begin{everbatim*} |
| 4063 |
\xinteval{unpack([1,2,3])} |
| 4064 |
\end{everbatim*} |
| 4065 |
|
| 4066 |
\funcdesc[ople]{flat} removes all nesting to produce a |
| 4067 |
(non-bracketed) ople having the same leaves (some possibly empty) but |
| 4068 |
located at depth 1. |
| 4069 |
\begin{everbatim*} |
| 4070 |
\xinteval{flat([[[[1,[],3],[4,[[[5,6,[]],[8,9],[[],11]],12],[13,14]]], [[],16]]], [])} |
| 4071 |
\end{everbatim*} |
| 4072 |
|
| 4073 |
I almost\unstable{} delayed indefinitely release because I was hesitating |
| 4074 |
on the name: perhaps better with |flattened()|, but long names add |
| 4075 |
(negligible, but still) overhead compared to short names. For this reason, |
| 4076 |
consider that name may change. |
| 4077 |
|
| 4078 |
|
| 4079 |
\end{description} |
| 4080 |
|
| 4081 |
\subsubsection{Functions with an alphanumeric argument} |
| 4082 |
|
| 4083 |
\begin{description} |
| 4084 |
% [parsep=0pt,align=left, |
| 4085 |
% leftmargin=0pt, itemindent=0pt, |
| 4086 |
% labelwidth=-\fontdimen2\font, labelsep=\fontdimen2\font, labelindent=0pt, |
| 4087 |
% listparindent=\leftmarginiii] |
| 4088 |
|
| 4089 |
\funcdesc[name]{bool} |
| 4090 |
returns |
| 4091 |
$1$ if the \TeX{} conditional |\ifname| would act as |\iftrue| and |
| 4092 |
$0$ otherwise. This works with conditionals defined by |\newif| (in |
| 4093 |
\TeX{} or \LaTeX{}) or with primitive conditionals such as |
| 4094 |
|\ifmmode|. For example: |
| 4095 |
% |
| 4096 |
\leftedline{|\xintifboolexpr{25*4-if(bool(mmode),100,75)}{YES}{NO}|} |
| 4097 |
% |
| 4098 |
will return $\xintifboolexpr{25*4-if(bool(mmode),100,75)}{YES}{NO}$ |
| 4099 |
if executed in math mode (the computation is then $100-100=0$) and |
| 4100 |
\xintifboolexpr{25*4-if(bool(mmode),100,75)}{YES}{NO} if not (the |
| 4101 |
\func{if} conditional is described below; the |
| 4102 |
\csbxint{ifboolexpr} test automatically encapsulates its first |
| 4103 |
argument in an |\xintexpr| and follows the first branch if the |
| 4104 |
result is non-zero (see \autoref{xintifboolexpr})). |
| 4105 |
|
| 4106 |
The alternative syntax |25*4-\ifmmode100\else75\fi| could have been |
| 4107 |
used here, the usefulness of |bool(name)| lies in the availability |
| 4108 |
in the |\xintexpr| syntax of the logic operators of conjunction |
| 4109 |
|&&|, inclusive disjunction \verb+||+, negation |!| (or |not|), of |
| 4110 |
the multi-operands functions |all|, |any|, |xor|, of the two |
| 4111 |
branching operators |if| and |ifsgn| (see also |?| and |??|), which |
| 4112 |
allow arbitrarily complicated combinations of various |bool(name)|. |
| 4113 |
\funcdesc[name]{togl} |
| 4114 |
returns $1$ |
| 4115 |
if the \LaTeX{} package \ctanpackage{etoolbox}% |
| 4116 |
% |
| 4117 |
% |
| 4118 |
% |
| 4119 |
\footnote{\url{https://ctan.org/pkg/etoolbox}} |
| 4120 |
% |
| 4121 |
has been used to define a toggle named |name|, and this toggle is |
| 4122 |
currently set to |true|. Using |togl| in an |\xintexpr..\relax| |
| 4123 |
without having loaded |
| 4124 |
\ctanpackage{etoolbox} will result in an |
| 4125 |
error from |\iftoggle| being a non-defined macro. If |etoolbox| is |
| 4126 |
loaded but |togl| is used on a name not recognized by |etoolbox| |
| 4127 |
the error message will be of the type ``ERROR: Missing |\endcsname| |
| 4128 |
inserted.'', with further information saying that |\protect| should |
| 4129 |
have not been encountered (this |\protect| comes from the expansion |
| 4130 |
of the non-expandable |etoolbox| error message). |
| 4131 |
|
| 4132 |
When |bool| or |togl| is encountered by the |\xintexpr| parser, the |
| 4133 |
argument enclosed in a parenthesis pair is expanded as usual from |
| 4134 |
left to right, token by token, until the closing parenthesis is |
| 4135 |
found, but everything is taken literally, no computations are |
| 4136 |
performed. For example |togl(2+3)| will test the value of a toggle |
| 4137 |
declared to |etoolbox| with name |2+3|, and not |5|. Spaces are |
| 4138 |
gobbled in this process. It is impossible to use |togl| on such |
| 4139 |
names containing spaces, but |\iftoggle{name with spaces}{1}{0}| |
| 4140 |
will work, naturally, as its expansion will pre-empt the |
| 4141 |
|\xintexpr| scanner. |
| 4142 |
|
| 4143 |
There isn't in |\xintexpr...| a |test| function available analogous |
| 4144 |
to the |test{\ifsometest}| construct from the |etoolbox| package; |
| 4145 |
but any \emph{expandable} |\ifsometest| can be inserted directly in |
| 4146 |
an |\xintexpr|-ession as |\ifsometest10| (or |\ifsometest{1}{0}|), |
| 4147 |
for example |if(\ifsometest{1}{0},YES,NO)| (see the |if| operator |
| 4148 |
below) works. |
| 4149 |
|
| 4150 |
A straight |\ifsometest{YES}{NO}| would do the same more |
| 4151 |
efficiently, the point of |\ifsometest10| is to allow arbitrary |
| 4152 |
boolean combinations using the (described later) \verb+&&+ and |
| 4153 |
\verb+||+ logic operators: |
| 4154 |
\verb+\ifsometest10 && \ifsomeothertest10 || \ifsomethirdtest10+, |
| 4155 |
etc... |YES| or |NO| above stand for material compatible with the |
| 4156 |
|\xintexpr| parser syntax. |
| 4157 |
|
| 4158 |
See also \csbxint{ifboolexpr}, in this context. |
| 4159 |
\end{description} |
| 4160 |
|
| 4161 |
\subsubsection{Functions with one mandatory and a second but optional argument} |
| 4162 |
|
| 4163 |
\begin{description} |
| 4164 |
% [parsep=0pt,align=left, |
| 4165 |
% leftmargin=0pt, itemindent=0pt, |
| 4166 |
% labelwidth=-\fontdimen2\font, labelsep=\fontdimen2\font, labelindent=0pt, |
| 4167 |
% listparindent=\leftmarginiii] |
| 4168 |
|
| 4169 |
\funcdesc[{x[, n]}]{round} Rounds its first argument to an integer multiple |
| 4170 |
of |10^(-n)| (i.e. it \emph{quantizes}). The case of negative |n| is new with |
| 4171 |
|1.4a|. Positive |n| corresponds to conversion to a fixed point number with |
| 4172 |
|n| digits after decimal mark. |
| 4173 |
\begin{everbatim*} |
| 4174 |
\xinteval{round(-2^30/3^5,12), round(-2^30/3^5,-3)} |
| 4175 |
\end{everbatim*} |
| 4176 |
\funcdesc[{x[, n]}]{trunc} Truncates its first argument to an integer |
| 4177 |
multiple of |10^(-n)|. The case of negative |n| is new with |
| 4178 |
|1.4a|. |
| 4179 |
\begin{everbatim*} |
| 4180 |
\xinteval{trunc(-2^30/3^5,12), trunc(-2^30/3^5,-3)} |
| 4181 |
\end{everbatim*} |
| 4182 |
|
| 4183 |
\funcdesc[{x[, n]}]{float} Rounds its first argument to a floating point number, with a |
| 4184 |
precision given by the second argument, which must be positive. |
| 4185 |
\begin{everbatim*} |
| 4186 |
\xinteval{float(-2^30/3^5,12), float(-2^30/3^5, 1)} |
| 4187 |
\end{everbatim*} |
| 4188 |
|
| 4189 |
% AUCTeX EXTREMEMENT PENIBLE AVEC L'INDENTATION FORCEE SOUS M-q |
| 4190 |
|
| 4191 |
For this example and earlier ones if the parser had been |
| 4192 |
\csbxint{floateval}, not \csbxint{eval}, the first argument (here |
| 4193 |
|2^30/3^5|) would already have been computed as floating point number with |
| 4194 |
numerator and denominator rounded separately first to the prevailing |
| 4195 |
precision. To avoid that, use |\xintexpr...\relax| wrapper. |
| 4196 |
Then the rounding or truncation will be applied to an exact fraction. |
| 4197 |
|
| 4198 |
\funcdesc[{x[, n]}]{sfloat} It is the same as \func{float}, |
| 4199 |
but in case of a short (non-fractional) input it gets stored internally |
| 4200 |
without adding zeros to make the mantissa have the \csbxint{theDigits} |
| 4201 |
length. One may wonder then what is the utility of \func{sfloat}? See for |
| 4202 |
an example of use the documentation of \csbxint{deffunc}. Notice however |
| 4203 |
that this is a bit experimental and may evolve in future when \xintname |
| 4204 |
gets a proper internal data structure for floating point numbers. The |
| 4205 |
non-normalized format is useful for multiplication or division, but float |
| 4206 |
additions and subtractions usually convert their arguments to a normalized |
| 4207 |
mantissa. |
| 4208 |
|
| 4209 |
\funcdesc[{x[, n]}]{ilog10} If there is an optional argument |n|, returns the (relative) integer $a$ such that $10^a\leq |
| 4210 |
\mathrm{abs}(float(x, n)) < 10^{a+1}$. In absence of the |
| 4211 |
optional argument: |
| 4212 |
\begin{itemize}[nosep] |
| 4213 |
\item in \csbxint{expr}, it returns the exponent $a$ such that $10^a\leq |
| 4214 |
\mathrm{abs}(x) < 10^{a+1}$. |
| 4215 |
\item in \csbxint{floatexpr}, the input is first rounded to |
| 4216 |
\csbxint{theDigits} float precision, then the exponent $a$ is evaluated. |
| 4217 |
\end{itemize} |
| 4218 |
\begin{everbatim*} |
| 4219 |
\xintfloateval{ilog10(99999999/10000000, 8), ilog10(-999999995/100000000, 8), |
| 4220 |
ilog10(-999999995/100000000, 9)}\newline |
| 4221 |
\xinteval{ilog10(-999999995/100000000), ilog10(-999999995/100000000, 8)} |
| 4222 |
\end{everbatim*} |
| 4223 |
|
| 4224 |
If the input vanishes the function outputs |
| 4225 |
\dtt{\xinteval{ilog10(0)}} (i.e.\@{} |-0x7fff8000| which is near the |
| 4226 |
minimal TeX number |-0x7fffffff|). This is also subject to change. |
| 4227 |
|
| 4228 |
The \hyperlink{func:ilog10-ii}{integer-only} variant for \csbxint{iiexpr} |
| 4229 |
admits no optional argument. |
| 4230 |
|
| 4231 |
\funcdesc[{x[, n]}]{sqrt} in \csa{xintexpr}|...\relax| and \csa{xintfloatexpr}|...\relax| |
| 4232 |
it achieves the precision given by the optional second argument. For |
| 4233 |
legacy reasons the |sqrt| function in \csa{xintiiexpr} \emph{truncates} |
| 4234 |
(to an integer), whereas |sqrt| in \csa{xintfloatexpr}|...\relax| (and in |
| 4235 |
\csa{xintexpr}|...\relax| which borrows it) \emph{rounds} (in the sense of |
| 4236 |
floating numbers). There is |sqrtr| in \csa{xintiiexpr} for |
| 4237 |
\emph{rounding} to nearest integer. |
| 4238 |
\begin{everbatim*} |
| 4239 |
\xinttheexpr sqrt(2,31)\relax\ and \xinttheiiexpr sqrt(num(2e60))\relax |
| 4240 |
\end{everbatim*} |
| 4241 |
|
| 4242 |
There is an \hyperlink{func:sqrt-ii}{integer only} variant for |
| 4243 |
\csbxint{iiexpr}. |
| 4244 |
|
| 4245 |
\funcdesc[{x[, n]}]{factorial} when the second optional argument is made |
| 4246 |
use of inside \csa{xintexpr}|...\relax|, this switches to the use of the |
| 4247 |
float version, rather than the exact one. |
| 4248 |
\begin{everbatim*} |
| 4249 |
\xinttheexpr factorial (100,32)\relax, {\xintDigits:=32\relax \xintthefloatexpr |
| 4250 |
factorial (100)\relax}\newline |
| 4251 |
\xinttheexpr factorial (50)\relax\newline |
| 4252 |
\xinttheexpr factorial (50, 32)\relax |
| 4253 |
\end{everbatim*} |
| 4254 |
|
| 4255 |
The \hyperlink{func:factorial-ii}{integer only variant} of course has no |
| 4256 |
optional second argument. |
| 4257 |
|
| 4258 |
\funcdesc[{A[, B]}]{randrange} when used with a single argument |A| returns a random |
| 4259 |
integer |0 <= x < A|, and when used with two arguments |A| and |B| returns |
| 4260 |
a random integer |A <= x < B|. As in Python it is an \myenquote{empty range} error |
| 4261 |
in first case if |A| is zero or negative and in second case if |B <= A|. |
| 4262 |
|
| 4263 |
Attention that the arguments are first converted to integers using |
| 4264 |
\csbxint{Num} (i.e.\@{} truncated towards zero). |
| 4265 |
|
| 4266 |
The function can be used in all three parsers. Of course the size is not |
| 4267 |
limited (but in the float parser, the integer will be rounded if involved |
| 4268 |
in any operation). |
| 4269 |
\begin{everbatim*} |
| 4270 |
\pdfsetrandomseed 12345 |
| 4271 |
\xinttheiiexpr randrange(10**20)\relax\newline |
| 4272 |
\xinttheiiexpr randrange(1234*10**16, 1235*10**16)\relax\newline |
| 4273 |
\printnumber{\xinttheiiexpr randrange(10**199,10**200)\relax}\par |
| 4274 |
\end{everbatim*} |
| 4275 |
For the support macros see \csbxint{RandomDigits}, \csbxint{iiRandRange}, |
| 4276 |
\csbxint{iiRandRangeAtoB}. For some details regarding how \xintname |
| 4277 |
uses the engine provided generator of pseudo-random numbers, see |
| 4278 |
\csbxint{UniformDeviate}. |
| 4279 |
|
| 4280 |
\end{description} |
| 4281 |
|
| 4282 |
\subsubsection{Functions with two arguments} |
| 4283 |
|
| 4284 |
\begin{description} |
| 4285 |
% [parsep=0pt,align=left, |
| 4286 |
% leftmargin=0pt, itemindent=0pt, |
| 4287 |
% labelwidth=-\fontdimen2\font, labelsep=\fontdimen2\font, labelindent=0pt, |
| 4288 |
% listparindent=\leftmarginiii] |
| 4289 |
|
| 4290 |
\funcdesc[m, n]{iquo} Only available in |\xintiiexpr/\xintiieval| |
| 4291 |
context. Computes the Euclidean quotient. Matches with the remainder |
| 4292 |
defined in next item. See \csbxint{iiQuo}. |
| 4293 |
|
| 4294 |
\funcdesc[m, n]{irem} Only available in |\xintiiexpr/\xintiieval| |
| 4295 |
context. Computes the Euclidean remainder. Attention that, following |
| 4296 |
mathematical definition, it is always non-negative. See \csbxint{iiRem}. |
| 4297 |
|
| 4298 |
\funcdesc[f, g]{mod} computes |f - g*floor(f/g)|. Hence its output is a |
| 4299 |
general fraction or floating point number or integer depending on the |
| 4300 |
used parser. If non-zero, it has the same sign as |g|. |
| 4301 |
|
| 4302 |
Prior to |1.2p| it computed |f - g*trunc(f/g)|. |
| 4303 |
|
| 4304 |
The \oper{/:} and \oper{'mod'} infix operators are both mapped to the same underlying |
| 4305 |
macro as this |mod(f, g)| function. At |1.3| this macro produces smaller |
| 4306 |
denominators when handling fractions than formerly. |
| 4307 |
\begin{everbatim*} |
| 4308 |
\xinttheexpr mod(11/7,1/13), reduce(((11/7)//(1/13))*1/13+mod(11/7,1/13)), |
| 4309 |
mod(11/7,1/13)- (11/7)/:(1/13), (11/7)//(1/13)\relax\newline |
| 4310 |
\xintthefloatexpr mod(11/7,1/13)\relax\par |
| 4311 |
\end{everbatim*} |
| 4312 |
|
| 4313 |
Attention: the precedence rules mean that |29/5 /: 3/5| is handled like |
| 4314 |
|((29/5)/:3)/5|. This is coherent with behaviour of Python language for |
| 4315 |
example: |
| 4316 |
\begin{everbatim} |
| 4317 |
>>> 29/5 % 3/5, 11/3 % 17/19, 11/57 |
| 4318 |
(0.5599999999999999, 0.19298245614035087, 0.19298245614035087) |
| 4319 |
>>> (29/5) % (3/5), (11/3) % (17/19), 5/57 |
| 4320 |
(0.4, 0.08771929824561386, 0.08771929824561403) |
| 4321 |
\end{everbatim} |
| 4322 |
For comparison (observe on the last lines how |\xintfloatexpr| is more accurate than |
| 4323 |
Python!): |
| 4324 |
\begin{everbatim*} |
| 4325 |
\noindent\xinttheexpr 29/5 /: 3/5, 11/3 /: 17/19\relax\newline |
| 4326 |
\xinttheexpr (29/5) /: (3/5), (11/3) /: (17/19)\relax\newline |
| 4327 |
\xintthefloatexpr 29/5 /: 3/5, 11/3 /: 17/19, 11/57\relax\newline |
| 4328 |
\xintthefloatexpr (29/5) /: (3/5), (11/3) /: (17/19), 5/57\relax\newline |
| 4329 |
5/57 = \xinttheexpr trunc(5/57, 20)\relax\dots\newline |
| 4330 |
\end{everbatim*}% |
| 4331 |
Regarding some details of behaviour in |\xintfloatexpr|, see discussion of |
| 4332 |
|divmod| function next. |
| 4333 |
|
| 4334 |
\funcdesc[f, g]{divmod} computes the two mathematical values |floor(f/g)| and |
| 4335 |
|mod(f,g)=f - g*floor(f/g)| and produces them as a bracketed |
| 4336 |
pair |
| 4337 |
in |
| 4338 |
other terms it is analogous to the Python |divmod| function. Its output is |
| 4339 |
equivalent to using |f//g, f/:g| but its implementation avoids doing twice |
| 4340 |
the needed division. |
| 4341 |
|
| 4342 |
In |\xintfloatexpr...\relax| the modulo is rounded to the prevailing |
| 4343 |
precision. The quotient is like in the other parsers an exact integer. It |
| 4344 |
will be rounded as soon as it is used in further operations, or via the global |
| 4345 |
output routine of |\xintfloatexpr|. \emph{Those examples behave as in |1.3f| |
| 4346 |
because assignments to multiple variables tacitly unpack if this is |
| 4347 |
necessary.} |
| 4348 |
\begin{everbatim*} |
| 4349 |
\xintdefvar Q, R := divmod(3.7, 1.2);% |
| 4350 |
\xinttheexpr Q, R, 1.2Q + R\relax\newline |
| 4351 |
\xintdefiivar Q, R := divmod(100, 17);% |
| 4352 |
\xinttheiiexpr Q, R, 17Q + R\relax\newline |
| 4353 |
\xintdeffloatvar Q, R := divmod(100, 17e-20);% |
| 4354 |
\xintthefloatexpr Q, R, 17e-20 * Q + R\relax\newline |
| 4355 |
% show Q exactly, although defined as float it can be used in iiexpr: |
| 4356 |
\xinttheiiexpr Q\relax\ (we see it has more than 16 digits)\par |
| 4357 |
\xintunassignvar{Q}\xintunassignvar{R}% |
| 4358 |
\end{everbatim*} |
| 4359 |
Again: |f//g| or the first item output by |divmod(f, g)| is an integer |q| |
| 4360 |
which when computed inside |\xintfloatexpr..\relax| is not yet rounded to |
| 4361 |
the prevailing float precision; the second item |f-q*g| is the rounding to |
| 4362 |
float precision of the exact mathematical value evaluated with this exact |
| 4363 |
|q|. \emph{This behaviour may change in future major release;\IMPORTANT{} |
| 4364 |
perhaps |q| will be rounded and |f-q*g| will correspond to usage of this |
| 4365 |
rounded |q|.} |
| 4366 |
|
| 4367 |
As |\xintfloatexpr| rounds its global result, or rounds operands at |
| 4368 |
each arithmetic operation, it requires special circumstances to show that |
| 4369 |
the |q| is produced unrounded. Either as in the above example or this one |
| 4370 |
with comparison operators: |
| 4371 |
\begin{everbatim*} |
| 4372 |
\xintDigits := 4\relax |
| 4373 |
\xintthefloatexpr if(12345678//23==537000, 1, 0), 12345678//23\relax\newline |
| 4374 |
\xintthefloatexpr if(float(12345678//23)==537000, 1, 0)\relax\par |
| 4375 |
\xintDigits := 16\relax |
| 4376 |
\end{everbatim*} |
| 4377 |
In the first line, the comparison is done with |
| 4378 |
|floor(12350000/23)|\dtt{=\xinttheiiexpr12350000/23\relax} (notice in |
| 4379 |
passing that |12345678//23| was evaluated as |12350000//23| because the |
| 4380 |
operands are first rounded to \dtt{4} digits of floating point precision), hence the conditional |
| 4381 |
takes the "False" branch. In the second line the |float| forces rounding of |
| 4382 |
the output to \dtt{4} digits, and the conditional takes the "True" branch. |
| 4383 |
|
| 4384 |
% pour mémoire, Python : |
| 4385 |
% >>> divmod(100,17e-20) |
| 4386 |
% (5.88235294117647e+20, 1.4756182441723705e-19) |
| 4387 |
% mais faudra voir avec le module Decimal |
| 4388 |
|
| 4389 |
This example shows also that comparison operators in |
| 4390 |
|\xintfloatexpr..\relax| act on unrounded operands. |
| 4391 |
|
| 4392 |
\funcdesc[x, y]{binomial} computes binomial coefficients. |
| 4393 |
It returns zero if |y<0| or |x<y| and raises an error if |x<0| (or if |
| 4394 |
|x>99999999|.) |
| 4395 |
\begin{everbatim*} |
| 4396 |
\xinttheexpr seq(binomial(20, i), i=0..20)\relax |
| 4397 |
\end{everbatim*} |
| 4398 |
\begin{everbatim*} |
| 4399 |
\printnumber{\xintthefloatexpr seq(binomial(100, 50+i), i=-5..+5)\relax}% |
| 4400 |
\end{everbatim*} |
| 4401 |
|
| 4402 |
The arguments must be (expand to) short integers. |
| 4403 |
\funcdesc[a, b]{pfactorial} computes partial factorials i.e.\@ |
| 4404 |
|pfactorial(a,b)| evaluates the product |(a+1)...b|. |
| 4405 |
\begin{everbatim*} |
| 4406 |
\xinttheexpr seq(pfactorial(20, i), i=20..30)\relax |
| 4407 |
\end{everbatim*} |
| 4408 |
|
| 4409 |
The arguments must (expand to) short integers. See \autoref{xintiiPFactorial} |
| 4410 |
for the behaviour if the arguments are negative. |
| 4411 |
|
| 4412 |
\funcdesc[\TeX-macro, n-uple]{ndfillraw} The second argument is |[N1, N2, ..., |
| 4413 |
Nk]|. The construct fills an |N1xN2x...xNk| hyperrectangular |
| 4414 |
nested list by evaluating the given |macro| as many times as needed. The |
| 4415 |
expansion result goes directly into internal data and must thus comply with |
| 4416 |
what is expected internally for an individual numeric leaf (at |1.4|, |
| 4417 |
\xintfracname raw format worked for |\xintexpr| or |\xintfloatexpr|, but not |
| 4418 |
|\xintiiexpr|, and this may have changed since).\DNU{} This is an experimental |
| 4419 |
function serving to generate either constant or random arrays. Attention that |
| 4420 |
% |
| 4421 |
% BORDEL \textbf{\sffamily...} NON, {\bfseries\sffamily ...} NON |
| 4422 |
% LaTeX Font Warning: Font shape `T1/cmss/b/n' undefined |
| 4423 |
% (Font) using `T1/cmss/m/n' instead on input line 1826. |
| 4424 |
% |
| 4425 |
% ceci est ok {\fontseries{bx}\sffamily\TeX-macro} |
| 4426 |
% https://github.com/latex3/latex2e/issues/277 |
| 4427 |
{\fontseries{bx}\sffamily \TeX-macro} |
| 4428 |
stands here for any expandable \TeX{} |
| 4429 |
\emph{macro}, and an |\xintexpr|-ession at this location thus requires an |
| 4430 |
explicit |\xinteval| wrapping. |
| 4431 |
\end{description} |
| 4432 |
|
| 4433 |
\subsubsection{Functions with 3 or 4 arguments} |
| 4434 |
|
| 4435 |
\begin{description} |
| 4436 |
% [parsep=0pt,align=left, |
| 4437 |
% leftmargin=0pt, itemindent=0pt, |
| 4438 |
% labelwidth=-\fontdimen2\font, labelsep=\fontdimen2\font, labelindent=0pt, |
| 4439 |
% listparindent=\leftmarginiii] |
| 4440 |
|
| 4441 |
\funcdesc[cond,yes,no]{if} (twofold-way conditional)\mbox{} |
| 4442 |
|
| 4443 |
checks if |cond| is true or false and takes the corresponding |
| 4444 |
branch. Any non zero number or fraction is logical true. The zero |
| 4445 |
value is logical false. Both ``branches'' are evaluated (they are |
| 4446 |
not really branches but just numbers). See also the \oper{?} operator. |
| 4447 |
|
| 4448 |
\funcdesc[x,yes,no]{ifint} (twofold-way conditional)\mbox{} |
| 4449 |
|
| 4450 |
checks if |x| is an integer and in that case chooses the ``yes'' branch.% |
| 4451 |
|
| 4452 |
See also \func{isint}. |
| 4453 |
|
| 4454 |
\funcdesc[x,yes,no]{ifone} (twofold-way conditional)\mbox{} |
| 4455 |
|
| 4456 |
checks if |x| is equal to one and in that case chooses the ``yes'' branch.% |
| 4457 |
|
| 4458 |
Slightly more efficient than |if(x==1,..,..)|. See also \func{isone}. |
| 4459 |
|
| 4460 |
\funcdesc[cond,<0,=0,>0]{ifsgn} (threefold-way conditional)\mbox{} |
| 4461 |
|
| 4462 |
checks the sign of |cond| and |
| 4463 |
proceeds correspondingly. All three are evaluated. See also the \oper{??} |
| 4464 |
operator. |
| 4465 |
|
| 4466 |
\end{description} |
| 4467 |
|
| 4468 |
\subsubsection{Functions with an arbitrary number of arguments} |
| 4469 |
|
| 4470 |
The functions \func{all}, \func{any}, \func{xor}, |
| 4471 |
\func{\textasciigrave+\textasciigrave}, |
| 4472 |
\func{\textasciigrave\lowast\textasciigrave}, |
| 4473 |
\func{max}, \func{min}, \func{gcd}, \func{lcm}, \func{first}, \func{last}, |
| 4474 |
\func{reversed} and \func{len} work both with \myenquote{open} and \myenquote{packed} lists (aka |nutples|). |
| 4475 |
|
| 4476 |
Since |1.4|, when used with a single argument which is a |nutple|, it is automatically unpacked. |
| 4477 |
But from |1.4| to |1.4h| these functions could not be used with a single numeric argument: either they had at least two arguments, or only one and it had to be a |nutple|. At |1.4i| it is again possible to use them with a lone numeric argument. |
| 4478 |
|
| 4479 |
In the specific case of \func{reversed} with a |nutple| argument the output is then repacked so that |
| 4480 |
the output is a |nutple| if and only if the input was one (the reversal does |
| 4481 |
not propagate to deeper nested |nutple|'s, it applies only at depth one). |
| 4482 |
|
| 4483 |
\begin{description} |
| 4484 |
% [parsep=0pt,align=left, |
| 4485 |
% leftmargin=0pt, itemindent=0pt, |
| 4486 |
% labelwidth=-\fontdimen2\font, labelsep=\fontdimen2\font, labelindent=0pt, |
| 4487 |
% listparindent=\leftmarginiii] |
| 4488 |
|
| 4489 |
\funcdesc[stuff]{qraw} It\DNU{} injects directly tokens to represent |
| 4490 |
internally numerical data. Will break at any release modifying the internal |
| 4491 |
data format specifications (which are not always documented). |
| 4492 |
|
| 4493 |
\funcdesc[x, y, ...]{all} inserts a logical |AND| in-between its arguments and evaluates the |
| 4494 |
resulting logical assertion (as with all functions, all arguments are |
| 4495 |
evaluated). |
| 4496 |
\begin{everbatim*} |
| 4497 |
\xinteval{all(1,1,1), all([1,0,1]), all([1,1,1])} |
| 4498 |
\end{everbatim*} |
| 4499 |
|
| 4500 |
\funcdesc[x, y, ...]{any} inserts a logical |OR| in-between its arguments and evaluates the |
| 4501 |
resulting logical assertion, |
| 4502 |
\begin{everbatim*} |
| 4503 |
\xinteval{any(0,0,0), any([1,0,1]), any([0,0,0])} |
| 4504 |
\end{everbatim*} |
| 4505 |
|
| 4506 |
\funcdesc[x, y, ...]{xor} inserts a logical |XOR| in-between its arguments and evaluates |
| 4507 |
the resulting logical assertion, |
| 4508 |
\begin{everbatim*} |
| 4509 |
\xinteval{xor(1,1,1), xor([1,0,1]), xor([1,1,1])} |
| 4510 |
\end{everbatim*} |
| 4511 |
|
| 4512 |
\funcdesc[x, y, ...]{\textasciigrave+\textasciigrave} adds (left ticks mandatory): |
| 4513 |
\begin{everbatim*} |
| 4514 |
\xinttheexpr `+`(1,3,19), `+`(1**2,3**2,sqr(19)), `+`([1**2,3**2,sqr(19)])\relax |
| 4515 |
\end{everbatim*} |
| 4516 |
|
| 4517 |
\funcdesc[x, y, ...]{\textasciigrave\lowast\textasciigrave} multiplies (left ticks mandatory): |
| 4518 |
\begin{everbatim*} |
| 4519 |
\xinttheexpr `*`(1,3,19), `*`(1^2,3^2,19^2), `*`([1^2,3^2,19^2])\relax |
| 4520 |
\end{everbatim*} |
| 4521 |
|
| 4522 |
\funcdesc[x, y, ...]{max} maximum of the (arbitrarily many) arguments, |
| 4523 |
\begin{everbatim*} |
| 4524 |
\xinttheexpr max(1,3,19), min([1,3,19])\relax |
| 4525 |
\end{everbatim*} |
| 4526 |
|
| 4527 |
\funcdesc[x, y, ...]{min} minimum of the (arbitrarily many) arguments, |
| 4528 |
\begin{everbatim*} |
| 4529 |
\xinttheexpr min(1,3,19), min([1,3,19])\relax |
| 4530 |
\end{everbatim*} |
| 4531 |
|
| 4532 |
\funcdesc[x, y, ...]{gcd} computes the positive generator of the fractional |
| 4533 |
ideal of rational numbers $x\mathbb Z + y\mathbb Z + ... \subset \mathbb |
| 4534 |
Q$. Since |1.4d| the output is always in lowest terms. |
| 4535 |
|
| 4536 |
This example shows how to reduce an n-uple to its primitive part: |
| 4537 |
\begin{everbatim*} |
| 4538 |
\xinteval{gcd(7/300, 11/150, 13/60)}\newline |
| 4539 |
$(7/300, 11/150, 13/60)\to |
| 4540 |
(\xinteval{subsn(seq(reduce(x/D), x = L), D=gcd(L); L=7/300, 11/150, 13/60)})$\newline |
| 4541 |
\xintexpr gcd([7/300, 11/150, 13/60])\relax\par |
| 4542 |
\end{everbatim*} |
| 4543 |
MEMO |
| 4544 |
Perhaps a future release will provide a |primpart()| function as built-in |
| 4545 |
functionality. |
| 4546 |
|
| 4547 |
In case of strict integers, using a |\xintiiexpr...\relax| wrapper is |
| 4548 |
advantageous as the integer-only |gcd()| is more efficient. |
| 4549 |
% |
| 4550 |
% ceci semble encore à peu près exact à 1.4d : |
| 4551 |
% (about |6X|) than the one accepting general fractional inputs. |
| 4552 |
% |
| 4553 |
As \csbxint{iiexpr} accepts only strict integers, doing this may require |
| 4554 |
wrapping the argument in \func{num}. |
| 4555 |
|
| 4556 |
\funcdesc[x, y, ...]{lcm} computes the positive generator of the |
| 4557 |
fractional ideal of rational numbers $x\mathbb Z \cap y\mathbb Z \cap ... |
| 4558 |
\subset \mathbb Q$. |
| 4559 |
\begin{everbatim*} |
| 4560 |
\xinttheexpr lcm([7/300, 11/150, 13/60])\relax |
| 4561 |
\end{everbatim*} |
| 4562 |
As for \func{gcd}, since |1.4d| the output is always in lowest terms. |
| 4563 |
% Memo 1.4d: This |
| 4564 |
% function got (I did not tests extensively) a |4X| speed gain for inputs being |
| 4565 |
% only integers |
| 4566 |
For strict integers it is slightly advantageous to use a sub |
| 4567 |
\csbxint{iiexpr}-ession. |
| 4568 |
% |
| 4569 |
% je disais à 1.4: |
| 4570 |
% (about |9X|) than the one accepting general fractional inputs. |
| 4571 |
% mais à 1.4d c'est seulement 2X : le lcm pour les fractions |
| 4572 |
% a quadruplé sa vitesse ! |
| 4573 |
% |
| 4574 |
|
| 4575 |
\funcdesc[x, y, ...]{first} first item of the list or nutple argument: |
| 4576 |
\begin{everbatim*} |
| 4577 |
\xintiiexpr first([last(-7..3), [58, 97..105]])\relax |
| 4578 |
\end{everbatim*} |
| 4579 |
\funcdesc[x, y, ...]{last} last item of the list or nutple argument: |
| 4580 |
\begin{everbatim*} |
| 4581 |
\xintiiexpr last([-7..3, 58, first(97..105)])\relax |
| 4582 |
\end{everbatim*} |
| 4583 |
\funcdesc[x, y, ...]{reversed} reverses the order of the comma separated list |
| 4584 |
or inside a nutple: |
| 4585 |
\begin{everbatim*} |
| 4586 |
\xintiieval{reversed(reversed(1..5), reversed([1..5]))} |
| 4587 |
\end{everbatim*} |
| 4588 |
|
| 4589 |
The above is correct as \xintexprname functions may produce oples and this is |
| 4590 |
the case here. |
| 4591 |
\funcdesc[x, y, ...]{len} computes the number of items in a comma separated |
| 4592 |
list or inside a nutple (at first level only: it is not a counter of leaves). |
| 4593 |
\begin{everbatim*} |
| 4594 |
\xinttheiiexpr len(37.5), len(1..50, [101..150], 1001..1050), len([1..10])\relax |
| 4595 |
\end{everbatim*} |
| 4596 |
|
| 4597 |
\funcdesc[\lowast nutples]{zip} behaves similarly to |
| 4598 |
the Python function of the same name: i.e. it produces \emph{an ople of nutples, |
| 4599 |
where the i-th nutple contains the i-th element from each of the argument |
| 4600 |
nutples. The ople ends when the shortest input nutple is exhausted. |
| 4601 |
With a single nutple argument, it returns an ople of 1-nutples. |
| 4602 |
With no arguments, it returns the empty ople.} |
| 4603 |
|
| 4604 |
As there is no exact match in \xintexprname of the concept of \myenquote{iterator} object,% |
| 4605 |
% |
| 4606 |
\footnote{% |
| 4607 |
Speaking of iterators, I have some ideas about this: as \csbxint{expr} does not |
| 4608 |
have the global expression in its hands it is difficult to organize globally |
| 4609 |
expandably the idea of iterator, but locally via syntax like the one for |
| 4610 |
\func{seq} this is feasible. When one thinks about it, \func{seq} is closely related |
| 4611 |
to the iterator idea.} |
| 4612 |
% |
| 4613 |
there is a significant difference here that (for example) the |zip(x,x,x)| |
| 4614 |
Python idiom to cluster the iterator |x| into successive chunks of length 3 |
| 4615 |
does not apply. Consider for this reason even the name of the function as |
| 4616 |
work-in-progress, susceptible to change.\unstable{} |
| 4617 |
\begin{everbatim*} |
| 4618 |
\xintiieval{zip([1..9], [0, 1, 2], [11..29], [111..139])} |
| 4619 |
\end{everbatim*} |
| 4620 |
|
| 4621 |
See also \csbxint{thespaceseparated} for some possible usage in combination with \func{flat}. |
| 4622 |
|
| 4623 |
\end{description} |
| 4624 |
|
| 4625 |
\subsubsection{Functions requiring dummy variables} |
| 4626 |
\hypertarget{ssec:dummies}{} |
| 4627 |
|
| 4628 |
The pseudo-functions \xintFor #1 in {subs, seq, subsm, subsn, iter, add, mul, |
| 4629 |
rseq, iterr, rrseq, iterr, ndseq, ndmap, ndfillraw} \do |
| 4630 |
{\func{#1}\xintifForLast{}{, }} use delimited macros for some tasks: |
| 4631 |
\begin{itemize} |
| 4632 |
\item for all of them, whenever a |<varname>=| chunk must be parsed into a |
| 4633 |
(non-assigned) variable name, then the equal sign must be visible, |
| 4634 |
\item and if the syntax is with |,<varname>=| the initial comma also must be |
| 4635 |
visible (spaces do not matter), |
| 4636 |
\item for all of them but \func{ndmap} and \func{ndfillraw} the final closing |
| 4637 |
parenthesis must be visible. |
| 4638 |
\end{itemize} |
| 4639 |
Although delimited macros involving commas are used to locate |,<varname=| |
| 4640 |
this is done in a way silently ignoring commas located inside correctly |
| 4641 |
balanced parentheses. Thus, as the examples will show, nesting works as |
| 4642 |
expected. |
| 4643 |
|
| 4644 |
The semi-colons involved in the syntax may arise from expansion alone. For |
| 4645 |
\func{rseq}, \func{iter}, \func{rrseq} and \func{iterr} the |,<varname>=| part |
| 4646 |
may also be created from the expansion which will generate the initial comma |
| 4647 |
separated values delimited by a semi-colon. |
| 4648 |
|
| 4649 |
Prior to |1.4|, semi-colons needed to be braced or otherwise hidden when |
| 4650 |
located in an expression parsed by \csbxint{defvar} or |
| 4651 |
\csbxint{deffunc}, to not be confused with the expression |
| 4652 |
terminator. |
| 4653 |
|
| 4654 |
\func{seq}, \func{rseq}, \func{iter}, \func{rrseq}, |
| 4655 |
\func{iterr} and also \func{add}, \func{mul}, but not \func{subs} admit the |
| 4656 |
\keyword{omit}, \keyword{abort}, and \func{break} keywords. This is a |
| 4657 |
new feature at |1.4| for \func{add} and \func{mul}. |
| 4658 |
|
| 4659 |
In the case |
| 4660 |
of a potentially infinite list generated by the |<integer>++| syntax, use of |
| 4661 |
\keyword{abort} or of \func{break} is mandatory, naturally. |
| 4662 |
|
| 4663 |
All lowercase and uppercase Latin letters are pre-configured for usage as |
| 4664 |
dummy variables. In Unicode engines one can use \csbxint{newdummy} to turn any |
| 4665 |
letter into a usable dummy variable. |
| 4666 |
|
| 4667 |
And since |1.4|, \csbxint{newdummy} works (in all engines) to |
| 4668 |
turn a multi-letter word into a dummy variable. In the descriptions, |
| 4669 |
|varname| stands for such a dummy variable, either single-letter or word. |
| 4670 |
|
| 4671 |
\begin{description} |
| 4672 |
% [parsep=0pt,align=left, |
| 4673 |
% leftmargin=0pt, itemindent=0pt, |
| 4674 |
% labelwidth=-\fontdimen2\font, labelsep=\fontdimen2\font, labelindent=0pt, |
| 4675 |
% listparindent=\leftmarginiii] |
| 4676 |
\funcdesc[expr, varname=values]{subs} for variable substitution. |
| 4677 |
\begin{everbatim*} |
| 4678 |
\xinttheexpr subs(subs(seq(x*z,x=1..10),z=y^2),y=10)\relax\newline |
| 4679 |
\end{everbatim*}% |
| 4680 |
Attention that |xz| generates an error, one must use explicitely |x*z|, else |
| 4681 |
the parser expects a variable with name |xz|. |
| 4682 |
|
| 4683 |
\func{subs} is useful when defining macros for which some argument will be |
| 4684 |
used more than once but may itself be a complicated expression or macro, and |
| 4685 |
should be evaluated only once, for matters of efficiency. But \func{subs} is |
| 4686 |
helpless in function definitions: all places where a variable is substituted |
| 4687 |
will receive the complete recipe to compute the variable, rather than evaluate |
| 4688 |
only once. |
| 4689 |
|
| 4690 |
One should rather define auxiliary functions to compute intermediate |
| 4691 |
results. Or one can use \func{seq}. See the documentation of |
| 4692 |
\csbxint{deffunc}. |
| 4693 |
|
| 4694 |
\funcdesc[expr, varname=values]{add} addition |
| 4695 |
\begin{everbatim*} |
| 4696 |
\xintiiexpr add(x^3,x=1..20), add(x(x+1), x=1,3,19)\relax\newline |
| 4697 |
\xintiiexpr add(x^3, x = 1..[2]..20)\relax\newline % add only odd cubes |
| 4698 |
\xintiiexpr add((odd(x))?{x^3}{omit}, x = 1..20)\relax\par % add only odd cubes |
| 4699 |
\end{everbatim*} |
| 4700 |
|
| 4701 |
At |1.4| (fixed at |1.4a|), the keywords \keyword{omit} (as in |
| 4702 |
example above), \keyword{abort} and \func{break} are allowed. |
| 4703 |
The meaning of \func{break} is specific: its argument serves as last |
| 4704 |
operand for the addition, not as ultimate value. |
| 4705 |
\begin{everbatim*} |
| 4706 |
\xintiiexpr add((x>10)?{break(1000)}{x}, x = 1..15)\relax |
| 4707 |
\end{everbatim*} |
| 4708 |
|
| 4709 |
The |@| special variable holds the so-far accumulated value. Initially its |
| 4710 |
value is zero. |
| 4711 |
\begin{everbatim*} |
| 4712 |
\xintiiexpr add(1 + @, i=1..10)\relax % iterates x <- 2x+1 |
| 4713 |
\end{everbatim*} |
| 4714 |
|
| 4715 |
See \func{\textasciigrave+\textasciigrave} for syntax simply adding items of a |
| 4716 |
list without usage of a dummy variable. |
| 4717 |
|
| 4718 |
\funcdesc[expr, varname=values]{mul} multiplication |
| 4719 |
\begin{everbatim*} |
| 4720 |
\xintiiexpr mul(x^2, x = 1, 3, 19, 37..50)\relax |
| 4721 |
\end{everbatim*} |
| 4722 |
|
| 4723 |
The |@| special variable holds the so-far accumulated value. Initially its |
| 4724 |
value is one. |
| 4725 |
|
| 4726 |
At |1.4| (fixed at |1.4a|), the keywords \keyword{omit}, |
| 4727 |
\keyword{abort} and \func{break} are allowed. The meaning of \func{break} is |
| 4728 |
specific: its argument serves as last operand for the multiplication, not as |
| 4729 |
ultimate value. |
| 4730 |
\begin{everbatim*} |
| 4731 |
\xintiieval{mul((i==100)?{break(i^4)}{i}, i = 98, 99, 100)} |
| 4732 |
\end{everbatim*} |
| 4733 |
|
| 4734 |
See \func{\textasciigrave\lowast\textasciigrave} for syntax without a dummy variable. |
| 4735 |
|
| 4736 |
\funcdesc[expr, varname=values]{seq} comma separated values generated according to a formula |
| 4737 |
\begin{everbatim*} |
| 4738 |
\xintiiexpr seq(x(x+1)(x+2)(x+3),x=1..10), `*`(seq(3x+2,x=1..10))\relax |
| 4739 |
\end{everbatim*} |
| 4740 |
\begin{everbatim*} |
| 4741 |
\smallskip |
| 4742 |
\leavevmode\vbox{\xintthealign\xintiiexpr [seq([seq(i^2+j^2, i=0..j)], j=0..10)]\relax} |
| 4743 |
\end{everbatim*} |
| 4744 |
|
| 4745 |
\funcdesc[initial value; expr, varname=values]{rseq} recursive sequence, |@| for the previous value. |
| 4746 |
\begin{everbatim*} |
| 4747 |
\printnumber {\xintthefloatexpr subs(rseq (1; @/2+y/2@, i=1..10),y=1000)\relax }\newline |
| 4748 |
\end{everbatim*}% |
| 4749 |
Attention: in the example above |y/2@| is interpreted as |
| 4750 |
|y/(2*@)|.\IMPORTANT{} With versions |1.2c| or earlier it would have been |
| 4751 |
interpreted as |(y/2)*@|. |
| 4752 |
|
| 4753 |
In case the initial stretch is a comma separated list, |@| refers at the first |
| 4754 |
iteration to the whole list. Use parentheses at each iteration to maintain |
| 4755 |
this ``nuple''. For example: |
| 4756 |
\begin{everbatim*} |
| 4757 |
\printnumber{\xintthefloatexpr rseq(1,10^6; |
| 4758 |
(sqrt(@[0]*@[1]),(@[0]+@[1])/2), i=1..7)\relax } |
| 4759 |
\end{everbatim*} |
| 4760 |
|
| 4761 |
Prior to |1.4| the above example had to be written with |[@]|. This is still |
| 4762 |
possible (|@| stands for an ople with two items, bracketing then extracting is |
| 4763 |
like extracting directly), but it is leaner to drop the extra \myenquote{packing}. |
| 4764 |
|
| 4765 |
\funcdesc[initial value; expr, varname=values]{iter} is exactly like |rseq|, except that it only prints |
| 4766 |
the last iteration. |
| 4767 |
|
| 4768 |
|
| 4769 |
\hypertarget{BrentSalamin}{} |
| 4770 |
|iter()| is convenient to handle compactly higher order iterations. |
| 4771 |
We can illustrate its use with an expandable (!) |
| 4772 |
implementation of the Brent-Salamin algorithm for the computation of $\pi$: |
| 4773 |
\begin{everbatim*} |
| 4774 |
\xintDigits:= 87\relax % we target 84 digits, and use 3 guard digits |
| 4775 |
\xintdeffloatfunc BS(a, b, t, p):= 0.5*(a+b), sqrt(a*b), t-p*sqr(a-b), |
| 4776 |
\xintiiexpr 2p\relax; |
| 4777 |
\xinteval |
| 4778 |
{trunc(% I feel truncation is better than rounding to display decimals of π |
| 4779 |
\xintfloatexpr |
| 4780 |
iter(1, sqrt(0.5), 1, 1; % initial values |
| 4781 |
% this 43 is 84/2 + 1 |
| 4782 |
(@[0]-@[1]<2e-43)?% stopping criteria; takes into account that the |
| 4783 |
% exit computation (break() argument) doubles |
| 4784 |
% number of exact digits (roughly) |
| 4785 |
{break(sqr(@[0]+@[1])/@[2])} % ... do final computation, |
| 4786 |
{BS(@)}, % else do iteration |
| 4787 |
i=1++) % This generates infinite iteration. The i is not used. |
| 4788 |
\relax |
| 4789 |
% this 83 is 84 - 1 (there is a digit known to be 3 actually, before decimal mark) |
| 4790 |
, 83)% closing parenthesis of trunc() |
| 4791 |
}...% some dots following end of \xinteval argument |
| 4792 |
\xintDigits:=16\relax |
| 4793 |
\end{everbatim*}\newline |
| 4794 |
You can try with |\xintDigits:=1004\relax| and |2e-501| in place of |
| 4795 |
|\xintDigits:=87\relax| and |2e-43|, but be patient for some seconds |
| 4796 |
for the result. Of course don't truncate the final |
| 4797 |
result to only \dtt{83} fractional decimal digits but \dtt{1000}...\@ |
| 4798 |
and better to wrap the whole thing in |\message| or |
| 4799 |
|\immediate\write128| or |\edef| because it will then run in the right margin. |
| 4800 |
|
| 4801 |
Prior to |1.4| the above example had to use notation such as |[@][0]|; this |
| 4802 |
would still work but |@[0]| is leaner. |
| 4803 |
|
| 4804 |
\funcdesc[initial values; expr, varname=values]{rrseq} recursive sequence with multiple initial terms. Say, there are |
| 4805 |
|K| of them. Then |@1|, ..., |@4| and then |@@(n)| up to |n=K| refer to the |
| 4806 |
last |K| values. Notice the difference with |rseq()| for which |@| refers to |
| 4807 |
a list of items in case the initial value is a list and not a single item.% |
| 4808 |
% |
| 4809 |
\footnote{Prior to |1.4|, one could use |@| in |rrseq()| and |iterr()| as an |
| 4810 |
alias to |@1|. This undocumented feature is dropped and |@| will break |rrseq()| and |iterr()|.} |
| 4811 |
% |
| 4812 |
Using |rrseq()| with |@1| etc...\@{} accessors may be perhaps a bit |
| 4813 |
more efficient than using |rseq()| with a list as staring value and |
| 4814 |
constructs such as |@[0]|, |@[1]| (or rather |@[-1]|, |@[-2]| to |
| 4815 |
mimick what |@1|, |@2|, |@3|, |@4| and |@@(integer)| do in |rrseq()|. |
| 4816 |
\begin{everbatim*} |
| 4817 |
\xinttheiiexpr rrseq(0,1; @1+@2, i=2..30)\relax |
| 4818 |
\end{everbatim*} |
| 4819 |
\begin{everbatim*} |
| 4820 |
\xinttheiiexpr rseq(1; 2@, i=1..10)\relax |
| 4821 |
\end{everbatim*} |
| 4822 |
\begin{everbatim*} |
| 4823 |
\xinttheiiexpr rseq(1; 2@+1, i=1..10)\relax |
| 4824 |
\end{everbatim*} |
| 4825 |
\begin{everbatim*} |
| 4826 |
\xinttheiiexpr rseq(2; @(@+1)/2, i=1..5)\relax |
| 4827 |
\end{everbatim*} |
| 4828 |
|
| 4829 |
\begin{everbatim*} |
| 4830 |
\xinttheiiexpr rrseq(0,1,2,3,4,5; @1+@2+@3+@4+@@(5)+@@(6), i=1..20)\relax |
| 4831 |
\end{everbatim*} |
| 4832 |
|
| 4833 |
I implemented an |Rseq| which at all times keeps the memory of \emph{all} |
| 4834 |
previous items, but decided to drop it as the package was becoming big. |
| 4835 |
|
| 4836 |
\funcdesc[initial values; expr, varname=values]{iterr} same as |rrseq| but does not print any value until the last |K|. |
| 4837 |
\begin{everbatim*} |
| 4838 |
\xinttheiiexpr iterr(0,1; @1+@2, i=2..5, 6..10)\relax |
| 4839 |
% the iterated over list is allowed to have disjoint defining parts. |
| 4840 |
\end{everbatim*} |
| 4841 |
|
| 4842 |
\funcdesc[expr, var1=value1; var2=value2; ....; varN=valueN{[;]}]{subsm} |
| 4843 |
Simultaneous |
| 4844 |
substitutions. The assigned values must not involve the |
| 4845 |
variables. An optional final |
| 4846 |
semi-colon is allowed. |
| 4847 |
\begin{everbatim*} |
| 4848 |
\xintiieval{subsm(x+2y+3z+4t, x=1; y=10; z=100; t=1000;)} |
| 4849 |
\end{everbatim*} |
| 4850 |
|
| 4851 |
\funcdesc[expr, var1=value1; var2=value2; ....; varN=valueN{[;]}]{subsn} |
| 4852 |
Simultaneous |
| 4853 |
substitutions. The assigned values may involve all variables |
| 4854 |
located further to its right. An optional final |
| 4855 |
semi-colon is allowed. |
| 4856 |
\begin{everbatim*} |
| 4857 |
\xintiieval{subsn(x+y+z+t, x=20y; y=20z; z=20t; t=1)} |
| 4858 |
\end{everbatim*} |
| 4859 |
|
| 4860 |
\funcdesc[function, values1; values2; ....; valuesN{[;]}]{ndmap} |
| 4861 |
% |
| 4862 |
Construction of a nested list (a priori having |N| dimensions) from function |
| 4863 |
values. The function must be an |N|-variable function (or a function accepting |
| 4864 |
arbitrarily many arguments), but it is not constrained to produce only scalar |
| 4865 |
values. Only in the latter case is the output really an |N|-dimensional |
| 4866 |
\myenquote{|ndlist|} type object. An optional final semi-colon in the input before the |
| 4867 |
closing parenthesis is |
| 4868 |
allowed. |
| 4869 |
\begin{everbatim*} |
| 4870 |
\xintdeffunc foo(a,b,c,d) = a+b+c+d; |
| 4871 |
\begin{multicols}{2} |
| 4872 |
\xintthealign\xintexpr ndmap(foo, 1000,2000,3000; 100,200,300; 10,20,30; 1,2,3)\relax |
| 4873 |
\end{multicols} |
| 4874 |
\end{everbatim*} |
| 4875 |
|
| 4876 |
\funcdesc[expr, var1=values1; var2=values2; ....; varN = valuesN{[;]}]{ndseq} |
| 4877 |
% |
| 4878 |
Constructs a nested list (a priori having |N| dimensions) from |
| 4879 |
substitutions in an expression involving |N| (dummy) variables. The |
| 4880 |
expression is not constrained to produce only scalar values. Only in the |
| 4881 |
latter case is the output really an |N|-dimensional \myenquote{|ndlist|} type object. |
| 4882 |
An optional final semi-colon in the input before the closing parenthesis is |
| 4883 |
allowed. |
| 4884 |
\begin{everbatim*} |
| 4885 |
\begin{multicols}{2} |
| 4886 |
\xintthealign\xintexpr ndseq(a+b+c+d, a=1000,2000,3000; b=100,200,300; |
| 4887 |
c=10,20,30; d=1,2,3;)\relax |
| 4888 |
\end{multicols}% in case of page break, this makes amusing zigzag rendering |
| 4889 |
\end{everbatim*} |
| 4890 |
|
| 4891 |
\end{description} |
| 4892 |
|
| 4893 |
Recursions may be nested, with |@@@(n)| giving access to the values of the |
| 4894 |
outer recursion\dots and there is even |@@@@(n)| to access the outer outer |
| 4895 |
recursion but I never tried it! |
| 4896 |
|
| 4897 |
The following keywords are recognized: |
| 4898 |
\begin{description} |
| 4899 |
\keyworddesc{abort} it is a pseudo-variable which indicates to stop here and now. |
| 4900 |
|
| 4901 |
\keyworddesc{omit} it is a pseudo-variable which says to omit this value and |
| 4902 |
go to next one. |
| 4903 |
|
| 4904 |
\funcdesc[stuff]{break} says to abort and insert |stuff| as last value. |
| 4905 |
|
| 4906 |
\keyworddesc{<integer>++} serves to generate a potentially infinite list. In |
| 4907 |
conjunction with an \keyword{abort} or \func{break} this is often |
| 4908 |
more efficient than iterating over a pre-established list of values. |
| 4909 |
\begin{everbatim*} |
| 4910 |
\xinttheiiexpr iter(1;(@>10^40)?{break(@)}{2@},i=1++)\relax |
| 4911 |
\end{everbatim*} |
| 4912 |
is the smallest power of 2 with at least fourty one digits. |
| 4913 |
|
| 4914 |
The |i=<integer>++| syntax (any letter is allowed in place of |i|) works only |
| 4915 |
in the form |<letter>=<integer>++|, something like |x=10,17,30++| is not |
| 4916 |
legal. The |<integer>| must be a \TeX-allowable integer. |
| 4917 |
\begin{everbatim*} |
| 4918 |
First Fibonacci number at least |2^31| and its index |
| 4919 |
% we use iterr to refer via @1 and @2 to the previous and previous to previous. |
| 4920 |
\xinttheiiexpr iterr(0,1; (@1>=2^31)?{break(@1, i)}{@2+@1}, i=1++)\relax |
| 4921 |
\end{everbatim*}% |
| 4922 |
. If one also wants the previous Fibonacci number one only has to use |break(@2, |
| 4923 |
@1, i)| in the above example. |
| 4924 |
\end{description} |
| 4925 |
|
| 4926 |
|
| 4927 |
\subsection{Generators of arithmetic progressions} |
| 4928 |
\label{ssec:arithseq} |
| 4929 |
|
| 4930 |
\begin{itemize} |
| 4931 |
\item |a..b| constructs the \textbf{small} integers from the ceil $\lceil |
| 4932 |
a\rceil$ to the floor |
| 4933 |
$\lfloor b\rfloor$ (possibly a decreasing sequence): one has to be careful |
| 4934 |
if using this for algorithms that |1..0| for example is not empty or |1| |
| 4935 |
but expands to |1, 0|. Again, |a..b| \emph{can not} be used with |a| and |
| 4936 |
|b| greater than $2^{31}-1$. Also, only about at most \dtt{5000} integers |
| 4937 |
can be generated (this depends upon some \TeX{} memory settings). |
| 4938 |
|
| 4939 |
The |..| has lower precedence than the arithmetic operations. |
| 4940 |
\begin{everbatim*} |
| 4941 |
\xintexpr 1.5+0.4..2.3+1.1\relax; \xintexpr 1.9..3.4\relax; \xintexpr 2..3\relax |
| 4942 |
\end{everbatim*} |
| 4943 |
|
| 4944 |
The step of replacing $a$ by its ceil and $b$ by its floor is a kind of |
| 4945 |
silly overhead, but $a$ and $b$ are allowed to be themselves the result |
| 4946 |
of computations and there is no notion of \myenquote{int} type in \csbxint{eval}. |
| 4947 |
The solution is, when $a$ and $b$ are given explicit integers to |
| 4948 |
temporarily switch to the \csbxint{iiexpr} parser: |
| 4949 |
\begin{everbatim*} |
| 4950 |
\xintexpr \xintiiexpr 1..10\relax\relax |
| 4951 |
\end{everbatim*} |
| 4952 |
|
| 4953 |
On the other hand integers from |\xintexpr 1..10\relax| are already in |
| 4954 |
raw \xintfracname format for example |3/1[0]| which speeds up their usage |
| 4955 |
in the macros internally involved in computations...\@{} thus perhaps what one |
| 4956 |
gains on one side is lost on the other side. |
| 4957 |
|
| 4958 |
\item |a..[d]..b| generates \myenquote{real} numbers along arithmetic progression |
| 4959 |
of reason |d|. It does |
| 4960 |
\emph{not} replace |a| by its ceil, nor |b| by its floor. The generated |
| 4961 |
list is empty if |b-a| and |d| are of opposite signs; if |d=0| or if |a=b| |
| 4962 |
the list expands to single element |a|. |
| 4963 |
\begin{everbatim*} |
| 4964 |
\xintexpr 1.5..[1.01]..11.23\relax |
| 4965 |
\end{everbatim*} |
| 4966 |
|
| 4967 |
At |1.4|, this generator behaves in \csbxint{floatexpr} exactly as in |
| 4968 |
\csbxint{expr}, i.e.\@{} \emph{exactly}. This is breaking |
| 4969 |
change. |
| 4970 |
\begin{everbatim*} |
| 4971 |
\xintDigits:=6; |
| 4972 |
\xintexpr\xintfloatexpr 100..[1.23456]..110\relax\relax |
| 4973 |
\xintDigits:=16; |
| 4974 |
\end{everbatim*} |
| 4975 |
|
| 4976 |
This demonstration embedded the float expression in the exact parser only |
| 4977 |
to avoid the rounding to the prevailing precision on output, thus we can |
| 4978 |
see that internally additions are done exactly and not with |
| 4979 |
\dtt{6} digits mantissas (in this example). |
| 4980 |
\end{itemize} |
| 4981 |
|
| 4982 |
\subsection{Python slicing and indexing of one-di\-men\-sional sequences} |
| 4983 |
\label{ssec:lists} |
| 4984 |
|
| 4985 |
We denote here by \emph{list} or \emph{sequence} a general \emph{ople}, either |
| 4986 |
given as a variable or explicitly. \emph{In the former case the parentheses are |
| 4987 |
optional}.% |
| 4988 |
% |
| 4989 |
\footnote{Even for an \myenquote{open list}, if it is given as a \emph{variable} then the indexing or slicing will not apply to its last item but to itself as an entity.} |
| 4990 |
|
| 4991 |
\begin{itemize} |
| 4992 |
\item |(list)[n]| returns the |n+1|th item if |n>=0|. If |n<0| it enumerates |
| 4993 |
items from the tail. Items are numbered as in Python, the |
| 4994 |
first element corresponding to |n=0|. |
| 4995 |
\begin{everbatim*} |
| 4996 |
\xintexpr (0..10)[6], (0..10)[-1], (0..10)[23*18-22*19]\relax |
| 4997 |
\end{everbatim*} |
| 4998 |
|
| 4999 |
This also works for singleton \emph{oples} which are in fact a \emph{number}: |
| 5000 |
\begin{everbatim*} |
| 5001 |
\xintexpr (7)[0], (7)[-1], 9, (7)[-2], 9\relax |
| 5002 |
\end{everbatim*} |
| 5003 |
|
| 5004 |
In the example above the parentheses serve to disambiguate from the raw |
| 5005 |
\xintfracname format such as |7[-1]| which, although discouraged, is accepted |
| 5006 |
on input. And we used a trick to show that |(7)[-2]| returns |nil|. |
| 5007 |
|
| 5008 |
The behaviour changes for singleton \emph{oples} which are not |
| 5009 |
\emph{numbers}. They are thus \emph{nutples}, or equivalently they are the |
| 5010 |
bracketing (bracing, packing) of another \emph{ople}. In this case, the meaning |
| 5011 |
of the syntax for item indexing is, as in Python, item |
| 5012 |
\emph{extraction}: |
| 5013 |
|
| 5014 |
\begin{everbatim*} |
| 5015 |
\xintexpr [0,1,2,3,4,5][2], [0,1,2,3,4,5][-3]\relax\newline |
| 5016 |
\xintexpr [0,[1,2,3,4,5],6][1][-1]\relax |
| 5017 |
\end{everbatim*} |
| 5018 |
|
| 5019 |
\item |(list)[:n]| produces the first |n| elements if |n>0|, or suppresses |
| 5020 |
the last \verb+|n|+ elements if |n<0|. |
| 5021 |
\begin{everbatim*} |
| 5022 |
\xintiiexpr (0..10)[:6]\relax\ and \xintiiexpr (0..10)[:-6]\relax |
| 5023 |
\end{everbatim*} |
| 5024 |
|
| 5025 |
As above, the meaning change for \emph{nutples} and fits with expectations |
| 5026 |
from Python regarding its sequence types: |
| 5027 |
\begin{everbatim*} |
| 5028 |
\xintiiexpr [0..10][:6]\relax\ and \xintiiexpr [0..10][:-6]\relax |
| 5029 |
\end{everbatim*} |
| 5030 |
|
| 5031 |
\item |(list)[n:]| suppresses the first |n| elements if |n>0|, or extracts |
| 5032 |
the last \verb+|n|+ elements if |n<0|. |
| 5033 |
\begin{everbatim*} |
| 5034 |
\xintiiexpr (0..10)[6:]\relax\ and \xintiiexpr (0..10)[-6:]\relax |
| 5035 |
\end{everbatim*} |
| 5036 |
|
| 5037 |
As above, the meaning change for \emph{nutples} and fit with expectations |
| 5038 |
from Python with \emph{tuple} or \emph{list} types: |
| 5039 |
\begin{everbatim*} |
| 5040 |
\xintiiexpr [0..10][6:]\relax\ and \xintiiexpr [0..10][-6:]\relax |
| 5041 |
\end{everbatim*} |
| 5042 |
|
| 5043 |
\item Finally, |(list)[a:b]| also works according to the Python ``slicing'' |
| 5044 |
rules (inclusive of negative indices). Notice though that stepping is |
| 5045 |
currently not supported. |
| 5046 |
\begin{everbatim*} |
| 5047 |
\xinttheiiexpr (1..20)[6:13]\relax\ = \xinttheiiexpr (1..20)[6-20:13-20]\relax |
| 5048 |
\newline |
| 5049 |
\xinttheiiexpr [1..20][6:13]\relax\ = \xinttheiiexpr [1..20][6-20:13-20]\relax |
| 5050 |
\end{everbatim*} |
| 5051 |
|
| 5052 |
\item It is naturally possible to execute such slicing operations one after |
| 5053 |
the other (the syntax is simplified compared to before |1.4|): |
| 5054 |
\begin{everbatim*} |
| 5055 |
\xintexpr (1..50)[13:37][10:-10]\relax\newline |
| 5056 |
\xintexpr (1..50)[13:37][10:-10][-1]\relax |
| 5057 |
\end{everbatim*} |
| 5058 |
\end{itemize} |
| 5059 |
|
| 5060 |
|
| 5061 |
\subsection{NumPy like nested slicing and indexing for arbitrary oples and nutples} |
| 5062 |
|
| 5063 |
I will give one illustrative example and refer to the NumPy documentation for |
| 5064 |
more. |
| 5065 |
|
| 5066 |
Notice though that our interpretation of the syntax is more general than |
| 5067 |
NumPy's concepts (of basic slicing/indexing): |
| 5068 |
\begin{itemize} |
| 5069 |
\item slicing and itemizing apply also to non-bracketed objects i.e.\@{} \emph{oples}, |
| 5070 |
\item the leaves do not have to be all at the same depth, |
| 5071 |
\item there are never any out-of-range index errors: out-of-range indices |
| 5072 |
are silently ignored. |
| 5073 |
\end{itemize} |
| 5074 |
|
| 5075 |
\begin{everbatim*} |
| 5076 |
\begin{multicols}{3} |
| 5077 |
\xintdefvar myArray = ndseq(a+b+c, a=100,200,300; b=40,50,60; c=7,8,9); |
| 5078 |
myArray = \xintthealign\xintexpr myArray\relax |
| 5079 |
\columnbreak |
| 5080 |
mySubArray = \xintthealign\xintexpr myArray[0:2,0:2,0:2]\relax |
| 5081 |
myExtractedSubArray = \xintthealign\xintexpr myArray[0:2,0:2,0:2][0]\relax |
| 5082 |
\columnbreak |
| 5083 |
myExtractedSubArray = \xintthealign\xintexpr myArray[0:2,0:2,0:2][0,1]\relax |
| 5084 |
\noindent |
| 5085 |
firstExtractedScalar = \xintexpr myArray[0:2,0:2,0:2][0,1,0]\relax\newline |
| 5086 |
secondExtractedScalar = \xintexpr myArray[0,1,0]\relax\par |
| 5087 |
\end{multicols} |
| 5088 |
\end{everbatim*} |
| 5089 |
|
| 5090 |
As said before, \emph{stepping} is not yet implemented. Also the NumPy |
| 5091 |
extension to Python for item selection (i.e.\@{} via a |tuple| of comma separated |
| 5092 |
indices) is not yet implemented. |
| 5093 |
|
| 5094 |
\subsection{Tacit multiplication} |
| 5095 |
\label{ssec:tacit multiplication} |
| 5096 |
|
| 5097 |
Tacit multiplication (insertion of a |*|) applies when the parser is currently |
| 5098 |
either scanning the digits of a number (or its decimal part or scientific |
| 5099 |
part, or hexadecimal input), or is looking for an infix operator, and: |
| 5100 |
\begin{enumerate}[nosep, label=(\arabic*.)] |
| 5101 |
\item \relax\emph{encounters a count or dimen or skip register or variable or an |
| 5102 |
\eTeX{} expression,} or |
| 5103 |
\item \emph{encounters a sub-\csa{xintexpr}ession}, or |
| 5104 |
\item \emph{encounters an opening parenthesis}, or |
| 5105 |
\item \emph{encounters a |
| 5106 |
letter (which is interpreted as signaling the start of either a variable or |
| 5107 |
a function name)}, or |
| 5108 |
\item (of course, only when in state "looking for an operator") \emph{encounters a digit}. |
| 5109 |
\end{enumerate} |
| 5110 |
|
| 5111 |
\begin{framed} |
| 5112 |
\centeredline{\textcolor{Red}{\textbf{!!!!ATTENTION!!!!}}} |
| 5113 |
|
| 5114 |
Explicit digits prefixing a variable, or a function, whose name starts with |
| 5115 |
an |e| or |E| will trap the parser into trying to build a number in |
| 5116 |
scientific notation. So the |*| must be explicitly inserted. |
| 5117 |
|
| 5118 |
\begin{everbatim} |
| 5119 |
\xintdefiivar e := (2a+4b+6d+N)/:7;% |
| 5120 |
\xintdefiivar f := (c+11d+22*e)//451;% 22e would raise errors |
| 5121 |
\end{everbatim} |
| 5122 |
|
| 5123 |
I don't think I will fix this anytime soon... |
| 5124 |
\end{framed} |
| 5125 |
|
| 5126 |
\begin{framed} |
| 5127 |
For example, if |x, y, z| are variables all three of |(x+y)z|, |x(y+z)|, |
| 5128 |
|(x+y)(x+z)| will create a tacit multiplication. |
| 5129 |
|
| 5130 |
Furthermore starting with release |
| 5131 |
|1.2e|, %\MyMarginNote[\kern\dimexpr\FrameSep+\FrameRule\relax]{Changed} |
| 5132 |
whenever tacit multiplication is applied, in all cases it \emph{always} |
| 5133 |
``ties'' more\IMPORTANT{} than normal multiplication or division, but |
| 5134 |
still less than power. Thus |x/2y| is interpreted as |x/(2y)| and |
| 5135 |
similarly for |x/2max(3,5)| but |x^2y| is still interpreted as |(x^2)*y| |
| 5136 |
and |2n!| as |2*n!|. |
| 5137 |
|
| 5138 |
\begin{everbatim*} |
| 5139 |
\xintdefvar x:=30;\xintdefvar y:=5;% |
| 5140 |
\xinttheexpr (x+y)x, x/2y, x^2y, x!, 2x!, x/2max(x,y)\relax |
| 5141 |
\end{everbatim*} |
| 5142 |
|
| 5143 |
Since |1.2q| tacit multiplication is triggered also in cases such as |
| 5144 |
|(1+2)5| or |10!20!30!|. |
| 5145 |
|
| 5146 |
\begin{everbatim*} |
| 5147 |
\xinttheexpr (10+7)5, 4!4!, add(i, i=1..10)10, max(x, y)100\relax |
| 5148 |
\end{everbatim*} |
| 5149 |
|
| 5150 |
The ``tie more'' rule applies to all cases of tacit multiplication. It |
| 5151 |
impacts only situations with a division operator as the last seen |
| 5152 |
operator, as multiplication is mathematically associative. |
| 5153 |
\begin{everbatim*} |
| 5154 |
\xinttheexpr 1/(3)5, (1+2)/(3+4)(5+6), 2/x(10), 2/10x, |
| 5155 |
3/y\xintiiexpr 5+6\relax, 1/x(y)\relax\ |
| 5156 |
differ from\newline\xinttheexpr 1/3*5, (1+2)/(3+4)*(5+6), 2/x*(10), 2/10*x, |
| 5157 |
3/y*\xintiiexpr 5+6\relax, 1/x*(y)\relax\par |
| 5158 |
\end{everbatim*} |
| 5159 |
\end{framed} |
| 5160 |
|
| 5161 |
Note that |y|\csbxint{theiiexpr}| 5+6\relax| would have tried to use a variable |
| 5162 |
with name |y11| rather than doing |y*11|: tacit multiplication works only |
| 5163 |
in front of sub-\csbxint{expr}essions, not in front of |
| 5164 |
\csbxint{theexpr}essions which are unlocked into explicit digits. |
| 5165 |
|
| 5166 |
|
| 5167 |
Here is an expression whose meaning is |
| 5168 |
completely modified by the ``tie more'' property of tacit multiplication: |
| 5169 |
|
| 5170 |
|
| 5171 |
\begin{everbatim} |
| 5172 |
\xintdeffunc e(z):=1+z(1+z/2(1+z/3(1+z/4))); |
| 5173 |
\end{everbatim} |
| 5174 |
will be parsed as |
| 5175 |
\begin{everbatim} |
| 5176 |
\xintdeffunc e(z):=1+z*(1+z/(2*(1+z/(3*(1+z/4))))); |
| 5177 |
\end{everbatim} |
| 5178 |
which is not at all the presumably hoped for: |
| 5179 |
\begin{everbatim} |
| 5180 |
\xintdeffunc e(z):=1+z*(1+(z/2)*(1+(z/3)*(1+(z/4)))); |
| 5181 |
\end{everbatim} |
| 5182 |
% This case can be handled this way: |
| 5183 |
% \begin{everbatim} |
| 5184 |
% \xintdeffunc e(z):=(((z/4+1)z/3+1)z/2+1)z+1; |
| 5185 |
% \end{everbatim} |
| 5186 |
|
| 5187 |
|
| 5188 |
\subsection{User defined variables} |
| 5189 |
\label{ssec:uservariables} |
| 5190 |
\label{xintdefvar} |
| 5191 |
\label{xintdefiivar} |
| 5192 |
\label{xintdeffloatvar} |
| 5193 |
|
| 5194 |
Since release |1.1| it is possible to make an assignment to a variable name |
| 5195 |
and let it be known to the parsers of \xintexprname. Since |1.2p| simultaneous |
| 5196 |
assignments are possible. Since |1.4| simultaneous assignments are possible with |
| 5197 |
a right-hand-side being a |nutple| which will be automatically unpacked. |
| 5198 |
\begin{everbatim*} |
| 5199 |
\xintdefvar myPi:=3.141592653589793238462643;% |
| 5200 |
$myPi = \xinteval{myPi}$\newline % (there is already built-in Pi variable) |
| 5201 |
\xintdefvar x_1, x_2, x_3 := 10, 20, 30;% |
| 5202 |
$x_1 = \xinteval{x_1}, x_2 = \xinteval{x_2}, x_3 = \xinteval{x_3}$\newline |
| 5203 |
\xintdefvar x_1, x_2, x_3 := [100, 200, 300];% |
| 5204 |
$x_1 = \xinteval{x_1}, x_2 = \xinteval{x_2}, x_3 = \xinteval{x_3}$\par |
| 5205 |
\end{everbatim*} |
| 5206 |
|
| 5207 |
|
| 5208 |
Simultaneous assignments with more variables than values do not |
| 5209 |
raise an error but simply set the extra variables to the \dtt{nil} value. |
| 5210 |
\begin{everbatim*} |
| 5211 |
\xintdefiivar a, b, c := [1, 2];% will be automatically unpacked |
| 5212 |
The value of a is \xinteval{a}, the one of b is \xinteval{b} and |
| 5213 |
the one of c is \xinteval{c}. |
| 5214 |
\end{everbatim*} |
| 5215 |
\begin{everbatim*} |
| 5216 |
\xintdefiivar a, b, c := 314;% |
| 5217 |
The value of a is \xinteval{a}, the one of b is \xinteval{b} and |
| 5218 |
the one of c is \xinteval{c}. |
| 5219 |
\end{everbatim*} |
| 5220 |
|
| 5221 |
Notice that \dtt{nil} variables must be used with caution as they break |
| 5222 |
arithmetic operations if used as operands to them. And they are not the same |
| 5223 |
as the \dtt{None} variables, which can also be input as |[]|. |
| 5224 |
|
| 5225 |
Simultaneous assignments with less variables than values do not |
| 5226 |
raise an error but set the last variable to be the ople concatenating the |
| 5227 |
remaining values. |
| 5228 |
\begin{everbatim*} |
| 5229 |
\xintdefiivar seq := 1..10;% |
| 5230 |
\xintdefiivar a, seq := seq;% |
| 5231 |
\xintdefiivar b, seq := seq;% |
| 5232 |
\xintdefiivar c, d, seq := seq;% |
| 5233 |
The value of a is \xinteval{a}, the one of b is \xinteval{b}, the one of c is \xinteval{c}, |
| 5234 |
the one of d is \xinteval{d}, the one of seq is \xinteval{seq}. |
| 5235 |
\end{everbatim*} |
| 5236 |
|
| 5237 |
In the above we define a variable |seq| but there is a built-in |
| 5238 |
function \func{seq}. It is indeed allowed to use the same name for both a |
| 5239 |
variable and a function.% |
| 5240 |
% |
| 5241 |
\footnote{But until a bugfix added at release |1.4i|, some built-in function |
| 5242 |
names (those implementing syntax with dummy variables, and the so-called |
| 5243 |
\myenquote{pseudo}-functions) were fragile under such overloading.} |
| 5244 |
But for safety we will unassign |seq| now: |
| 5245 |
\begin{everbatim*} |
| 5246 |
\xintunassignvar{a}\xintunassignvar{b}\xintunassignvar{c}\xintunassignvar{d}% |
| 5247 |
\xintunassignvar{seq}% |
| 5248 |
\end{everbatim*}% |
| 5249 |
Single letter names |a..z| and |A..Z| are pre-declared by the package for use |
| 5250 |
as a special type of variables called ``dummy variables''. Unnassigning them |
| 5251 |
restores this initial meaning. See further \csbxint{unassignvar} and |
| 5252 |
\csbxint{newdummy}. Since |1.4| even assigned variables can be used in the |
| 5253 |
call signatures of function declarations. |
| 5254 |
|
| 5255 |
Regarding the manipulation of an \myenquote{open list} as above, there is no way |
| 5256 |
to obtain with only one use of the variable both its last item and the |
| 5257 |
reduction of the variable to its truncated self. One can do rather: |
| 5258 |
\begin{everbatim*} |
| 5259 |
\xintdefiivar mylist := 1..10;% |
| 5260 |
\xintdefiivar z, mylist := last(mylist), mylist[:-1];% |
| 5261 |
The value of z is \xinteval{z} and mylist is now \xinteval{mylist}.\par |
| 5262 |
\end{everbatim*} |
| 5263 |
This uses twice |mylist| and is about the same as doing it in two steps: |
| 5264 |
\begin{everbatim*} |
| 5265 |
\xintdefiivar w := last(mylist);% |
| 5266 |
\xintdefiivar mylist := mylist[:-1];% |
| 5267 |
The value of w is \xinteval{w} and mylist is now \xinteval{mylist}.% |
| 5268 |
\xintunassignvar{z}\xintunassignvar{w}\xintunassignvar{mylist}\par |
| 5269 |
\end{everbatim*} |
| 5270 |
|
| 5271 |
It is recommended generally speaking to work with \myenquote{closed (i.e. bracketed) |
| 5272 |
lists} because only them and numbers can be arguments to functions (but see |
| 5273 |
\csbxint{deffunc} and the notion of variadic last argument). For more on the |
| 5274 |
Python-like slicing used above see \autoref{ssec:lists} and |
| 5275 |
\autoref{sssec:opleslicing}. For more information relative to variables |
| 5276 |
versus arguments see \autoref{sssec:funcargs}. |
| 5277 |
|
| 5278 |
\begin{itemize}[noitemsep] |
| 5279 |
\item For catcodes issues (particularly, for the semi-colon used to delimit |
| 5280 |
the fetched expression), see the discussion of \csbxint{exprSafeCatcodes} and some comments in the section documenting \csbxint{deffunc}. |
| 5281 |
\item |
| 5282 |
Both syntaxes |\xintdefvar foo := <expr>;| and |\xintdefvar foo = <expr>;| |
| 5283 |
are accepted. |
| 5284 |
\item |
| 5285 |
Spaces in the variable name or around the equal sign are removed and are |
| 5286 |
immaterial. |
| 5287 |
\item |
| 5288 |
The variable names are expanded in an |\edef| (and stripped of spaces). |
| 5289 |
Example: |
| 5290 |
\begin{everbatim} |
| 5291 |
\xintdefvar x\xintListWithSep{, x}{\xintSeq{0}{10}} := seq(2**i, i = 0..10);% |
| 5292 |
\end{everbatim} |
| 5293 |
This defines |x0|, |x1|, \dots, |x10| for future usage. |
| 5294 |
\end{itemize} |
| 5295 |
|
| 5296 |
Legal variable names are composed of letters, digits, |_| and |@| and |
| 5297 |
characters. A variable name must start with a letter. Variable names starting |
| 5298 |
with a |@| or |_| are reserved for internal usage.% |
| 5299 |
% |
| 5300 |
\footnote{The process of variable declaration does not check that these rules |
| 5301 |
are met, and breakage will arise on use, if rules are not followed. For |
| 5302 |
example, prior to |1.4g|, using a variable (illegally) |
| 5303 |
declared with a name starting with a (normal, catcode 8) |_| triggered an |
| 5304 |
infinite loop.} |
| 5305 |
|
| 5306 |
As |x_1x_2| or even |x_1x| are licit variable names, and as the parser does |
| 5307 |
not trace back its steps, input syntax must be |x_1*x_2| if the aim is to |
| 5308 |
multiply such variables. |
| 5309 |
|
| 5310 |
Using \csa{xintdefvar}, \csa{xintdefiivar}, or \csa{xintdeffloatvar} means |
| 5311 |
that the variable value will be computed using respectively \csa{xintexpr}, |
| 5312 |
\csa{xintiiexpr} or \csa{xintfloatexpr}. It can then be used in all three |
| 5313 |
parsers, as long as the parser understands the format. Currently this means |
| 5314 |
that variables using \csa{xintdefvar} or \csa{xintdeffloatvar} can be used |
| 5315 |
freely either with \csa{xintexpr} or \csa{xintfloatexpr} but not with |
| 5316 |
\csa{xintiiexpr}, and variables defined via \csa{xintdefiivar} can be used in |
| 5317 |
all parsers. |
| 5318 |
|
| 5319 |
When defining a variable with \csa{xintdeffloatvar} it (or |
| 5320 |
generally speaking its numerical leaves) is rounded to \csbxint{theDigits} |
| 5321 |
precision. So the variable holds the same value as would be printed via |
| 5322 |
\csbxint{floateval} for the same computation. |
| 5323 |
|
| 5324 |
Prior to |1.4e|, this was the case only if the variable definition actually |
| 5325 |
involved some computation. |
| 5326 |
|
| 5327 |
However the \csbxint{floatexpr}|..\relax| wrapper by itself induces no rounding. If |
| 5328 |
it is encountered in the typesetting flow, the print-out will be rounded to |
| 5329 |
\csbxint{theDigits} precision, but this is an effet of behaving like |
| 5330 |
\csbxint{floateval} in this context. |
| 5331 |
\begin{everbatim*} |
| 5332 |
% Since 1.4e, \xintdeffloatvar always rounds (to \xinttheDigits) |
| 5333 |
\xintdeffloatvar e:=2.7182818284590452353602874713526624977572470936999595749669676;% |
| 5334 |
1) \xintexpr e\relax\newline % shows the recorded value: it is rounded |
| 5335 |
2) \xintfloatexpr % when used in typesetting flow, acts like \xintfloateval: |
| 5336 |
2.7182818284590452353602874713526624977572470936999595749669676 |
| 5337 |
\relax\newline % the print-out is rounded. |
| 5338 |
3) \xintexpr |
| 5339 |
\xintfloatexpr |
| 5340 |
2.7182818284590452353602874713526624977572470936999595749669676 |
| 5341 |
\relax |
| 5342 |
\relax\newline |
| 5343 |
% |
| 5344 |
% but we can see via the \xintexpr wrapper all the digits were there rounding |
| 5345 |
% can be forced using an extra 0+, the float() function, or the [D] option. |
| 5346 |
% tidbit: comparison operators do not pre-round, so 1.2345678 is not same as |
| 5347 |
% (1.2345678+0) in low precision. |
| 5348 |
% |
| 5349 |
\begingroup\xintDigits:=4;% |
| 5350 |
4) \xintifboolfloatexpr{1.2345 == 1.23456} |
| 5351 |
{\error}{Different! Comparisons do not pre-round to Digits precision.}\newline |
| 5352 |
5) \xintifboolfloatexpr{1.2345 == 1.2345 + 0} |
| 5353 |
{\error}{Different! Right hand side rounded from operation, |
| 5354 |
left hand side not rounded.}\par |
| 5355 |
\endgroup |
| 5356 |
\end{everbatim*} |
| 5357 |
|
| 5358 |
% not so exciting example |
| 5359 |
% In the next examples we examine the effect of cumulated float operations on |
| 5360 |
% rounding errors: |
| 5361 |
% \begin{everbatim*} |
| 5362 |
% \xintdefvar e_1:=add(1/i!, i=0..10);% exact sum |
| 5363 |
% \xintdeffloatvar e_2:=add(1/i!, i=0..10);% float sum |
| 5364 |
% \xintthefloatexpr e_1, e_2\relax\newline |
| 5365 |
% \xintdefvar e_3:=e_1+add(1/i!, i=11..20);% exact sum |
| 5366 |
% \xintdeffloatvar e_4:=e_2+add(1/i!, i=11..20);% float sum |
| 5367 |
% \xintthefloatexpr e_3, e_4\relax\newline |
| 5368 |
% \xintdeffloatvar e:=2.7182818284590452353602874713526624977572470936999595749669676;% |
| 5369 |
% \xintDigits:=24\relax |
| 5370 |
% \xintthefloatexpr[16] e, e^1000, e^1000000\relax (e rounded to 24 digits first)\newline |
| 5371 |
% \xintDigits:=16\relax |
| 5372 |
% \xintthefloatexpr e, e^1000, e^1000000\relax (e rounded to 16 digits first)\par |
| 5373 |
% \end{everbatim*} |
| 5374 |
|
| 5375 |
After issuing \csbxint{verbosetrue} the values of defined variables are |
| 5376 |
written out to the log (and terminal). As in this example: |
| 5377 |
\begin{everbatim} |
| 5378 |
Package xintexpr Info: (on line 1) |
| 5379 |
Variable myPi defined with value {3141592653589793238462643[-24]}. |
| 5380 |
Package xintexpr Info: (on line 2) |
| 5381 |
Variable x_1 defined with value {10}. |
| 5382 |
Package xintexpr Info: (on line 2) |
| 5383 |
Variable x_2 defined with value {20}. |
| 5384 |
Package xintexpr Info: (on line 2) |
| 5385 |
Variable x_3 defined with value {30}. |
| 5386 |
Package xintexpr Info: (on line 3) |
| 5387 |
Variable List defined with value {0}{1}{3}{6}{10}{15}{21}{28}{36}{45}{55} |
| 5388 |
. |
| 5389 |
Package xintexpr Info: (on line 4) |
| 5390 |
Variable Nuple defined with value {{0}{1}{9}{36}{100}{225}{441}{784}{1296 |
| 5391 |
}{2025}{3025}}. |
| 5392 |
Package xintexpr Info: (on line 5) |
| 5393 |
Variable FourthPowers defined with value {{0}{1}{81}{1296}{10000}{50625}{ |
| 5394 |
194481}{614656}{1679616}{4100625}{9150625}}. |
| 5395 |
\end{everbatim} |
| 5396 |
|
| 5397 |
\subsubsection{\csh{xintunassignvar}} |
| 5398 |
\label{xintunassignvar} |
| 5399 |
|
| 5400 |
\csa{xintunassignvar}\marg{variable} will make the \meta{variable} un-assigned. |
| 5401 |
For example in the previous section we used |
| 5402 |
\begin{everbatim} |
| 5403 |
\xintdeffloatvar e := ...some value...; |
| 5404 |
\end{everbatim} |
| 5405 |
To undo one either waits for the current scope (e.g.\@ a \LaTeX{} |
| 5406 |
environment) to expire or the impatient does: |
| 5407 |
\begin{everbatim*} |
| 5408 |
\xintunassignvar{e} |
| 5409 |
\end{everbatim*} |
| 5410 |
|
| 5411 |
In this special case\IMPORTANT{} of using \csa{xintunassignvar} with a |
| 5412 |
single \meta{letter} the effect is actually to let |
| 5413 |
the \meta{letter} recover the meaning of a dummy variable (i.e.\@ it is |
| 5414 |
the same as using \csbxint{newdummy} documented in the next section): |
| 5415 |
\begin{everbatim*} |
| 5416 |
% overwriting a dummy letter |
| 5417 |
\xintdefvar i := 3;% |
| 5418 |
\xinteval{i^3} is as expected but |\xinteval{add(i,i=1..10)}| computes |
| 5419 |
\xinteval{add(i,i=1..10)} because "i" has the fixed value 3.\newline |
| 5420 |
\xintunassignvar{i}% back to normal |
| 5421 |
After |\xintunassignvar{i}| |
| 5422 |
|\xinteval{add(i,i=..10)}| is evluated with "i" acting as a dummy variable |
| 5423 |
and thus outputs \xinteval{add(i,i=..10)}.\par |
| 5424 |
\end{everbatim*} |
| 5425 |
|
| 5426 |
Under \csbxint{globaldefstrue} regime the effect of \csa{xintunassignvar} is |
| 5427 |
of global scope. |
| 5428 |
|
| 5429 |
\subsubsection{\csh{xintnewdummy}} |
| 5430 |
\label{xintnewdummy} |
| 5431 |
|
| 5432 |
|
| 5433 |
Any catcode 11 character can serve as a dummy variable, via this declaration: |
| 5434 |
\begin{everbatim} |
| 5435 |
\xintnewdummy{<letter>}% the <letter> must be of catcode letter! |
| 5436 |
\end{everbatim} |
| 5437 |
For example with Lua\TeX\ or Xe\TeX\ the following works: |
| 5438 |
\begin{everbatim} |
| 5439 |
% Requires a Unicode engine |
| 5440 |
\xintnewdummy{ξ} |
| 5441 |
\xinteval{add(ξ, ξ=1..10)} |
| 5442 |
\end{everbatim} |
| 5443 |
|
| 5444 |
Starting with |1.4|, it is allowed to use \csa{xintnewdummy} to define |
| 5445 |
``dummy variables'' having names with more than one letter. They can |
| 5446 |
then be used as expected: |
| 5447 |
\begin{everbatim} |
| 5448 |
% Requires a Unicode engine |
| 5449 |
\xintnewdummy{ατλν} |
| 5450 |
\xintdeffunc test(ατλν) = sqr(1 + ατλν); |
| 5451 |
\xinteval{seq(test(ατλν), ατλν = 0..10)} |
| 5452 |
\end{everbatim} |
| 5453 |
|
| 5454 |
Remark regarding Op\TeX: it is a format using Lua\TeX, but non ascii |
| 5455 |
letters have catcode ``other''. So for the above example to compile |
| 5456 |
with |optex|, the catcodes need to be set to ``letter'' beforehand: |
| 5457 |
\begin{everbatim} |
| 5458 |
% Requires a Unicode engine |
| 5459 |
% next line is required if with OpTeX (only): |
| 5460 |
\xintFor* #1 in {ατλν}\do{\catcode`#1=11 } |
| 5461 |
\xintnewdummy{ατλν} |
| 5462 |
\xintdeffunc test(ατλν) = sqr(1 + ατλν); |
| 5463 |
\xinteval{seq(test(ατλν), ατλν = 0..10)} |
| 5464 |
\end{everbatim} |
| 5465 |
|
| 5466 |
Under \csbxint{globaldefstrue} regime the effect of \csa{xintnewdummy} is |
| 5467 |
of global scope. |
| 5468 |
|
| 5469 |
\subsubsection{\csh{xintensuredummy}, \csh{xintrestorevariable}} |
| 5470 |
\label{xintensuredummy} |
| 5471 |
\label{xintrestorevariable} |
| 5472 |
|
| 5473 |
Use |
| 5474 |
\begin{everbatim} |
| 5475 |
\xintensuredummy{<character>} |
| 5476 |
... |
| 5477 |
... code using the (catcode 11) character as a dummy variable |
| 5478 |
... |
| 5479 |
\xintrestorevariable{<character>} |
| 5480 |
\end{everbatim} |
| 5481 |
if other parts need the letter as an assigned variable name. For example |
| 5482 |
\xinttrigname being written at high level needs a few genuine dummy variables, |
| 5483 |
and it uses \csbxint{ensuredummy} to be certain everything is ok. |
| 5484 |
|
| 5485 |
\subsection{User defined functions} |
| 5486 |
\label{ssec:userfunctions} |
| 5487 |
\def\tocstylesubsubsectionHOOK#1#2#3{} |
| 5488 |
\etocsetnexttocdepth{subsubsection} |
| 5489 |
\localtableofcontents |
| 5490 |
\let\tocstylesubsubsectionHOOK\empty |
| 5491 |
|
| 5492 |
|
| 5493 |
\subsubsection{\csh{xintdeffunc}} |
| 5494 |
\label{xintdeffunc} |
| 5495 |
|
| 5496 |
Here is an example: |
| 5497 |
\begin{everbatim*} |
| 5498 |
\xintdeffunc |
| 5499 |
Rump(x,y):=1335 y^6/4 + x^2 (11 x^2 y^2 - y^6 - 121 y^4 - 2) + 11 y^8/2 + x/2y; |
| 5500 |
\end{everbatim*}(notice the numerous tacit multiplications in this expression; |
| 5501 |
and that |x/2y| is interpreted as |x/(2y)|.) |
| 5502 |
|
| 5503 |
\begin{framed} |
| 5504 |
\begin{itemize} |
| 5505 |
\item The ending semi-colon is allowed to be of active catcode, as |
| 5506 |
|\xintdeffunc| temporarily resets catcodes via |
| 5507 |
\csbxint{exprSafeCatcodes} before parsing the expression. |
| 5508 |
|
| 5509 |
But this will fail if the whole thing is inside a macro |
| 5510 |
definition. Then the used semi-colon must be the standard one. |
| 5511 |
|
| 5512 |
In the case of a \LaTeX{} document using Babel, and a language such |
| 5513 |
as French which makes the semi-colon active, it is still the |
| 5514 |
standard one inside the preamble, so there is no problem there. |
| 5515 |
|
| 5516 |
For a macro definition done inside the document body, which, as I |
| 5517 |
understand, is sin, almost evil, either turn off locally the |
| 5518 |
activation (|\string;| will not work because \csbxint{deffunc} uses |
| 5519 |
delimited macros to fetch all the way to the semi-colon), or define |
| 5520 |
in the preamble |\MyDefFunc{#1}| to do |\xintdeffunc #1;| and use |
| 5521 |
that in the |\newcommand\foo| inside the document body. |
| 5522 |
|
| 5523 |
\item Semi-colons used inside the expression need not be hidden inside |
| 5524 |
braces. (new with |1.4|) |
| 5525 |
\item The colon before the equal sign is optional and its (reasonable) |
| 5526 |
catcode does not matter. |
| 5527 |
\end{itemize} |
| 5528 |
\end{framed} |
| 5529 |
|
| 5530 |
Here are a few important items (bookmark this for reading again later once you |
| 5531 |
have gained experience in using this interface...): |
| 5532 |
\begin{itemize} |
| 5533 |
\item The function names are composed of letters, digits, underscores or |@| |
| 5534 |
signs. A function name must start with a letter. It may be a single letter |
| 5535 |
(see \autoref{sssec:overload}). |
| 5536 |
\item The variable names used in the function signature may be multi-letter |
| 5537 |
words. It is also allowed for them to already be in use for previously |
| 5538 |
declared variables. Their meanings will get restored for usage after the |
| 5539 |
function declaration. |
| 5540 |
\item A function can be declared with at most nine arguments. It can be declared as a |
| 5541 |
function with no arguments. |
| 5542 |
\item If in the function declaration the last argument is |
| 5543 |
prefixed by |*|, it stands for a |nutple| which will gather all arguments of |
| 5544 |
the function call beyond the first positional ones. See \autoref{sssec:funcargs} |
| 5545 |
for additional explanations on such \myenquote{variadic} arguments. |
| 5546 |
\item Recursive definitions are possible; for them to not generate error or |
| 5547 |
fall in infinite loops, the use of the short-circuit conditionals |?| and |
| 5548 |
|??| is \emph{mandatory}. |
| 5549 |
\item If a function is used in another definition it will check if it is |
| 5550 |
applied to numerical arguments and if this is the case will expand |
| 5551 |
fully. |
| 5552 |
\item The previous item has an exception for functions with no arguments; they |
| 5553 |
never expand immediately in other function definitions (else they would be |
| 5554 |
almost like variables). This provides a way to define functions with |
| 5555 |
parameters: simply let their definition use some functions with no arguments. |
| 5556 |
\item A function declared via \csbxint{deffunc} remains \fbox{unknown} to |
| 5557 |
\csbxint{floatexpr} (or \csbxint{floateval}). See \csbxint{deffloatfunc}, |
| 5558 |
\csbxint{defiifunc}. One can use the same formula in a new definition, but |
| 5559 |
if one wants the expansion to execute in a parser independent way, one can |
| 5560 |
transfer a function with scalar values like this: |
| 5561 |
\begin{everbatim} |
| 5562 |
\xintdeffloatfunc foo(x) := float_dgt(\xintexpr foo(x)\relax); |
| 5563 |
\end{everbatim} |
| 5564 |
The \func{float\string_dgt} wrapper (which was renamed at |
| 5565 |
|1.4e|) is in order for the float variant to produce an already-rounded |
| 5566 |
value, possibly speeding-up usage if used as input for other |
| 5567 |
functions. Using \func{float} here would work the same but the produced |
| 5568 |
function would incorporate a routine to check (at time of use, because at |
| 5569 |
time of definition it is impossible to tell what will be the case) if it is |
| 5570 |
applied to one or two arguments. |
| 5571 |
|
| 5572 |
\item And in the reverse direction one can do: |
| 5573 |
\begin{everbatim} |
| 5574 |
\xintdeffunc bar(x) := \xintfloatexpr bar(float(x))\relax; |
| 5575 |
\end{everbatim} |
| 5576 |
With this the transplanted float-function will expand in \csbxint{expr} as |
| 5577 |
it would have in \csbxint{floatexpr}, i.e.\@{} using float operations; this is |
| 5578 |
different from declaring the function again with the same expression as used |
| 5579 |
for the original, as it would have then been parsed with a mapping of infix |
| 5580 |
operators to the macros doing the exact operations, not the floating point |
| 5581 |
ones. |
| 5582 |
|
| 5583 |
The inner \func{float} above is not mandatory but recommended: the macro |
| 5584 |
associated to the user float function |bar(x)| may use many times its |
| 5585 |
argument |x| and does not worry about rounding it, because its expectation |
| 5586 |
is that it is already rounded; but in \csbxint{expr} that value could very |
| 5587 |
well be a fraction |19/13| and its float rounding will be done again by each |
| 5588 |
float macro receiving it as argument; with a \func{float} used as above this |
| 5589 |
will have already been done once and the ulterior roundings are faster: they |
| 5590 |
have nothing to do apart from realizing that they have nothing to do.... One |
| 5591 |
can also use \func{sfloat}, this would serve to nothing for the |19/13| case |
| 5592 |
but would possibly for a short integer input involved in multiplications. |
| 5593 |
|
| 5594 |
Here it is not needed to use \func{float\string_dgt}, because it will be |
| 5595 |
identified at time of definition that \func{float} is used without optional |
| 5596 |
argument. |
| 5597 |
|
| 5598 |
An external \func{float\string_dgt} could be added but is not a priori |
| 5599 |
necessary, except perhaps if the |bar()| function has been defined at a low |
| 5600 |
level using support macros producing output with garbage extra digits, which |
| 5601 |
usually would be rounded out in input to other float functions. |
| 5602 |
|
| 5603 |
\end{itemize} |
| 5604 |
|
| 5605 |
|
| 5606 |
A function once declared is a first class citizen, its |
| 5607 |
expression is entirely parsed and converted into a big nested \fexpan dable |
| 5608 |
macro. |
| 5609 |
|
| 5610 |
When used its action is via this defined macro. For example |
| 5611 |
\begin{everbatim*} |
| 5612 |
\xintdeffunc |
| 5613 |
e(z):=(((((((((z/10+1)z/9+1)z/8+1)z/7+1)z/6+1)z/5+1)z/4+1)z/3+1)z/2+1)z+1; |
| 5614 |
\end{everbatim*} |
| 5615 |
creates a macro whose meaning one can find in the log file, after |
| 5616 |
\csbxint{verbosetrue}. Here it is (it has at |1.4| an extra external brace pair |
| 5617 |
compared to what happened with earlier releases): |
| 5618 |
\begin{everbatim} |
| 5619 |
Function e for \xintexpr parser associated to \XINT_expr_userfunc_e with me |
| 5620 |
aning macro:#1->{\xintAdd {\xintMul {\xintAdd {\xintDiv {\xintMul {\xintAdd {\x |
| 5621 |
intDiv {\xintMul {\xintAdd {\xintDiv {\xintMul {\xintAdd {\xintDiv {\xintMul {\ |
| 5622 |
xintAdd {\xintDiv {\xintMul {\xintAdd {\xintDiv {\xintMul {\xintAdd {\xintDiv { |
| 5623 |
\xintMul {\xintAdd {\xintDiv {\xintMul {\xintAdd {\xintDiv {#1}{10}}{1}}{#1}}{9 |
| 5624 |
}}{1}}{#1}}{8}}{1}}{#1}}{7}}{1}}{#1}}{6}}{1}}{#1}}{5}}{1}}{#1}}{4}}{1}}{#1}}{3} |
| 5625 |
}{1}}{#1}}{2}}{1}}{#1}}{1}} |
| 5626 |
\end{everbatim} |
| 5627 |
|
| 5628 |
The above is not entirely true. At |1.4|, \csbxint{deffunc} is |
| 5629 |
more powerful and digests more of the syntax but it may have to store it in |
| 5630 |
such a way that usage will be done via a sub-expression: hence it is not the |
| 5631 |
case that the original expression has been \emph{entirely} parsed. See |
| 5632 |
\csbxint{NewFunction} for related discussion. |
| 5633 |
|
| 5634 |
The main difficulty of \csbxint{deffunc} is with the pseudo-functions |
| 5635 |
\func{seq}, \func{iter}, etc..., which admit the keywords \keyword{omit}, |
| 5636 |
\keyword{abort}, \func{break}. We have no alternative for them, if the |
| 5637 |
iterated over values are not entirely numerical than to postpone expansion, |
| 5638 |
but this means simply storing for later a possibly big sub-expression. |
| 5639 |
|
| 5640 |
At |1.4| we did some obstinate work to make this working but: |
| 5641 |
\begin{itemize} |
| 5642 |
\item this means that the stored function body has not been entirely parsed, |
| 5643 |
parsing will happen on the fly at each execution for small or large bits, |
| 5644 |
\item there remains a main stumbling-block. If the variables used in the |
| 5645 |
function declaration are used only in the iterated over values or the |
| 5646 |
initial values, then the mechanism may work. If however they are used not |
| 5647 |
only in those values iterated over but directly in the expression which the |
| 5648 |
generators map to the iterated over values, then it will break |
| 5649 |
certainly. Indeed at this stage the variables are simply names, and it is |
| 5650 |
impossible to transfer the mechanism which converts these names into |
| 5651 |
numerical arguments for delayed usage by the declared function. Except if |
| 5652 |
one is ready to basically freeze the entire thing; which then is not any |
| 5653 |
different at all than using \csbxint{NewFunction}. |
| 5654 |
\end{itemize} |
| 5655 |
|
| 5656 |
Conclusion: if some \csbxint{deffunc} break, check if it does not fit the |
| 5657 |
above criterion before reporting...\@{} and recall \csbxint{NewFunction} is your |
| 5658 |
friend. It has the big advantage of declaring a function for all parsers |
| 5659 |
simultaneously! |
| 5660 |
|
| 5661 |
A special note on \func{subs}: it is and has always been hopeless in \csbxint{deffunc} |
| 5662 |
context. All it does (if it works at all) after being malaxed by |
| 5663 |
\csbxint{deffunc} is to copy over at the indicated places the \emph{recipe} to |
| 5664 |
compute something. Thus at every location where that something is needed it will be |
| 5665 |
evaluated from scratch again. Yes, this is disappointing. But...\@{} on the other |
| 5666 |
hand the more general \func{seq} does work, or pretends to work. Let me |
| 5667 |
illustrate to make thinks clear. We start with this: |
| 5668 |
\begin{everbatim*} |
| 5669 |
\xintverbosetrue |
| 5670 |
\xintdeffunc foo(x,y,z) = subs(S + S^2, S = x+y+z); |
| 5671 |
\xintdeffunc bar(x,y,z) = seq(S + S^2, S = x+y+z); |
| 5672 |
\xintexpr foo(100,10,1), bar(100,10,1)\relax |
| 5673 |
\xintverbosefalse |
| 5674 |
\end{everbatim*} |
| 5675 |
|
| 5676 |
It produces in the log: |
| 5677 |
\begin{everbatim} |
| 5678 |
Package xintexpr Info: (on line 2) |
| 5679 |
Function foo for \xintexpr parser associated to \XINT_expr_userfunc_foo wit |
| 5680 |
h meaning macro:#1#2#3->{\xintAdd {\xintAdd {\xintAdd {#1}{#2}}{#3}}{\xintPow { |
| 5681 |
\xintAdd {\xintAdd {#1}{#2}}{#3}}{2}}} |
| 5682 |
Package xintexpr Info: (on line 3) |
| 5683 |
Function bar for \xintexpr parser associated to \XINT_expr_userfunc_bar wit |
| 5684 |
h meaning macro:#1#2#3->\expanded \bgroup \expanded {\unexpanded {\XINT_expr_se |
| 5685 |
q:_b {\xintbareeval S + S^2\relax !S}}{\xintAdd {\xintAdd {#1}{#2}}{#3}}^} |
| 5686 |
\end{everbatim} |
| 5687 |
Even without understanding all details one sees that in the first case the |
| 5688 |
|\xintAdd {\xintAdd {#1}{#2}}{#3}}| appears twice, and in the second case only |
| 5689 |
once. But in the second case we have a yet to evaluate expression. So the |
| 5690 |
second approach is not much different in its effect than using the more |
| 5691 |
simple-minded \csbxint{NewFunction}. Besides one gets a feeling why the |
| 5692 |
function arguments can not appear in the expression but only in the iterated |
| 5693 |
over values, because there is no way to understand what |x|, |y|, |z| are |
| 5694 |
supposed to mean without adding extra structure showing they map to |#1|, |
| 5695 |
|#2|, |#3|. |
| 5696 |
|
| 5697 |
The above remarks apply to \func{subsm} and \func{subsn}. Even if they do work |
| 5698 |
in \csbxint{deffunc} context (warning, testing at |1.4| release has remained |
| 5699 |
minimal), they will not bring added efficiency if the substituted values are |
| 5700 |
to be used multiple times. They may still be useful to visually simplify the |
| 5701 |
input of a big expression by expressing it in terms of smaller constituents. |
| 5702 |
|
| 5703 |
Another workaround if one wants genuine (not \myenquote{macro}-) functions for some |
| 5704 |
expression where the same thing is used multiple times is to define helper |
| 5705 |
functions computing the intermediate data. One can see illustrations of this |
| 5706 |
in the code source of \xinttrigname (or in the matrix multiplication example |
| 5707 |
at the end of this chapter). |
| 5708 |
|
| 5709 |
\subsubsection{\csh{xintdefiifunc}} |
| 5710 |
\label{xintdefiifunc} |
| 5711 |
|
| 5712 |
With \csbxint{deffunc} the created function is known by the \csbxint{expr} |
| 5713 |
parser only. |
| 5714 |
For usage in the \csbxint{iiexpr} parser, it is required to use |
| 5715 |
\csa{xintdefiifunc}. |
| 5716 |
|
| 5717 |
\subsubsection{\csh{xintdeffloatfunc}} |
| 5718 |
\label{xintdeffloatfunc} |
| 5719 |
|
| 5720 |
With \csbxint{deffunc} the created function is known by the \csbxint{expr} |
| 5721 |
parser only. For usage in the \csbxint{floatexpr} parser, it is required to use |
| 5722 |
\csa{xintdeffloatfunc}. |
| 5723 |
|
| 5724 |
Note: the optional argument |[Q]| accepted by \csbxint{floatexpr} does not |
| 5725 |
work with \csbxint{deffloatfunc}. It is still possible to wrap the expression |
| 5726 |
in |float(expression,Q)|, if it evaluates to a scalar. |
| 5727 |
|
| 5728 |
\subsubsection{\csh{xintdefufunc}, \csh{xintdefiiufunc}, \csh{xintdeffloatufunc}} |
| 5729 |
\label{xintdefufunc} |
| 5730 |
\label{xintdefiiufunc} |
| 5731 |
\label{xintdeffloatufunc} |
| 5732 |
|
| 5733 |
This allows to define so-called \myenquote{Universal functions}. This is terminology |
| 5734 |
borrowed from |NumPy|. |
| 5735 |
|
| 5736 |
Here is an example: |
| 5737 |
\begin{everbatim*} |
| 5738 |
\xintdefiivar Array = ndmap(lcm, 1..5; 1..10; 1..10); |
| 5739 |
Array = \xintthealign\xintiiexpr Array\relax |
| 5740 |
\xintdefiiufunc foo(x) = x^3; |
| 5741 |
\begin{figure}[htbp] |
| 5742 |
\caption{Output of a universal function acting on an array}\label{fig:ufunc} |
| 5743 |
\centeredline{$\vcenter{\xintthealign\xintiiexpr foo(Array)\relax}$} |
| 5744 |
\end{figure} |
| 5745 |
See \autopageref{fig:ufunc} for the output. |
| 5746 |
\end{everbatim*} |
| 5747 |
|
| 5748 |
The function can be applied to any nested strucure: |
| 5749 |
\begin{everbatim*} |
| 5750 |
\xintiiexpr foo([1, [2, [3, [4, [5, 6, 7, 8, 9, 10]]]]])\relax |
| 5751 |
\end{everbatim*} |
| 5752 |
|
| 5753 |
It must be defined as function acting on scalars, but its value type is not constrained. |
| 5754 |
\begin{everbatim*} |
| 5755 |
\xintdefiivar Array = [1..10]; |
| 5756 |
\xintdefiiufunc foo(x) = [1..x]; |
| 5757 |
\xintthealign\xintiiexpr foo(Array)\relax |
| 5758 |
\end{everbatim*} |
| 5759 |
|
| 5760 |
It is even allowed to produce oples and act on oples: |
| 5761 |
\begin{everbatim*} |
| 5762 |
\xintdefiivar Ople = 1..10; |
| 5763 |
\xintdefiiufunc bar(x) = x, x^2, x^3; |
| 5764 |
\xintiiexpr bar(Ople)\relax |
| 5765 |
\end{everbatim*} |
| 5766 |
|
| 5767 |
|
| 5768 |
\subsubsection{Using the same name for both a variable and a function} |
| 5769 |
\label{sssec:overload} |
| 5770 |
|
| 5771 |
It is licit to overload a variable name (all Latin letters are predefined as |
| 5772 |
dummy variables) with a function name and vice versa. The parsers will decide |
| 5773 |
from the context if the function or variable interpretation must be used |
| 5774 |
(dropping various cases of tacit multiplication as normally applied). |
| 5775 |
\begin{everbatim*} |
| 5776 |
\xintdefiifunc f(x):=x^3; |
| 5777 |
\xinttheiiexpr add(f(f),f=100..120)\relax\newline |
| 5778 |
\xintdeffunc f(x,y):=x^2+y^2; |
| 5779 |
\xinttheexpr mul(f(f(f,f),f(f,f)),f=1..10)\relax |
| 5780 |
\xintunassigniiexprfunc{f}\xintunassignexprfunc{f}% |
| 5781 |
\end{everbatim*} |
| 5782 |
|
| 5783 |
\subsubsection{\csh{xintunassignexprfunc}, \csh{xintunassigniiexprfunc}, |
| 5784 |
\csh{xintunassignfloatexprfunc}} |
| 5785 |
\label{xintunassignexprfunc} |
| 5786 |
\label{xintunassigniiexprfunc} |
| 5787 |
\label{xintunassignfloatexprfunc} |
| 5788 |
|
| 5789 |
Function names can be unassigned via \csa{xintunassignexprfunc}\marg{name}, |
| 5790 |
\csa{xintunassigniiexprfunc}\marg{name}, and |
| 5791 |
\csa{xintunassignfloatexprfunc}\marg{name}. |
| 5792 |
\begin{everbatim*} |
| 5793 |
\xintunassignexprfunc{e} |
| 5794 |
\xintunassignexprfunc{f} |
| 5795 |
\end{everbatim*} |
| 5796 |
|
| 5797 |
Warning: no check is done to avoid undefining built-in functions... |
| 5798 |
|
| 5799 |
\subsubsection{\csh{ifxintverbose} conditional} |
| 5800 |
\label{xintverbosetrue} |
| 5801 |
\label{xintverbosefalse} |
| 5802 |
\label{ifxintverbose} |
| 5803 |
|
| 5804 |
With |\xintverbosetrue| the meanings of the |
| 5805 |
functions (or rather their associated macros) will be written to the log. For |
| 5806 |
example the |Rump| declaration above generates this in the log file: |
| 5807 |
\begin{everbatim} |
| 5808 |
Function Rump for \xintexpr parser associated to \XINT_expr_userfunc_Rump w |
| 5809 |
ith meaning macro:#1#2->{\xintAdd {\xintAdd {\xintAdd {\xintDiv {\xintMul {1335 |
| 5810 |
}{\xintPow {#2}{6}}}{4}}{\xintMul {\xintPow {#1}{2}}{\xintSub {\xintSub {\xintS |
| 5811 |
ub {\xintMul {11}{\xintMul {\xintPow {#1}{2}}{\xintPow {#2}{2}}}}{\xintPow {#2} |
| 5812 |
{6}}}{\xintMul {121}{\xintPow {#2}{4}}}}{2}}}}{\xintDiv {\xintMul {11}{\xintPow |
| 5813 |
{#2}{8}}}{2}}}{\xintDiv {#1}{\xintMul {2}{#2}}}} |
| 5814 |
\end{everbatim} |
| 5815 |
|
| 5816 |
\begin{framed} |
| 5817 |
The meanings written out to the log for more complicated functions may |
| 5818 |
sometimes use the same character at different locations but with different |
| 5819 |
catcodes.\IMPORTANTf |
| 5820 |
|
| 5821 |
It may thus be impossible to retokenize it (even after having removed the |
| 5822 |
extra spaces from the added line breaks). |
| 5823 |
|
| 5824 |
This is in contrast with variable values which are always output in the log |
| 5825 |
in the benign way, using digits, braces and some characters of catcode 12. |
| 5826 |
\end{framed} |
| 5827 |
|
| 5828 |
\subsubsection{\csh{ifxintglobaldefs} conditional} |
| 5829 |
\label{xintglobaldefstrue} |
| 5830 |
\label{xintglobaldefsfalse} |
| 5831 |
\label{ifxintglobaldefs} |
| 5832 |
|
| 5833 |
If true user defined variables (\csbxint{defvar}, ...) and functions |
| 5834 |
(\csbxint{deffunc}, ..., \csbxint{NewFunction}) for the expression parsers, as |
| 5835 |
well as macros obtained via \csbxint{NewExpr} et al.\@{} have global scope. If |
| 5836 |
false (default) they have local scope. |
| 5837 |
|
| 5838 |
\subsubsection{\csh{xintNewFunction}} |
| 5839 |
\label{xintNewFunction} |
| 5840 |
|
| 5841 |
This is syntactic sugar which allows to use notation of functions for what is |
| 5842 |
nothing more in disguise than a \TeX{} macro. Here is an example: |
| 5843 |
\begin{everbatim*} |
| 5844 |
\xintNewFunction {foo}[3]{add(mul(x+i, i=#1..#2),x=1..#3)} |
| 5845 |
\end{everbatim*} |
| 5846 |
|
| 5847 |
We now have a genuine function |foo()| of three variables which can |
| 5848 |
be used in \emph{all three parsers}. |
| 5849 |
\begin{everbatim*} |
| 5850 |
\xintexpr seq(foo(0, 3, j), j= 1..10)\relax |
| 5851 |
\end{everbatim*} |
| 5852 |
|
| 5853 |
Each time the created \myenquote{macro-function} |foo()| will be encountered the |
| 5854 |
corresponding replacement text will get inserted as a sub-expression (of the |
| 5855 |
same type as the surrounding one), the macro parameters having been replaced |
| 5856 |
with the (already evaluated) function arguments, and the parser \emph{will |
| 5857 |
then have to parse the expression.} It is very much like a macro |
| 5858 |
substitution, but with parentheses and comma separated arguments (which can be |
| 5859 |
arbitrary expressions themselves). |
| 5860 |
|
| 5861 |
It differs fundamentally from \csbxint{deffunc} as it realizes no pre-parsing |
| 5862 |
whatsoever of the associated sub-expression; using it shortens the input but |
| 5863 |
not the parsing time (which however is most of the time negligible compared to |
| 5864 |
actual numerical computations). Use it for syntax which \csbxint{deffunc} |
| 5865 |
does not parse successfully. |
| 5866 |
|
| 5867 |
|
| 5868 |
\subsection{Examples of user defined functions} |
| 5869 |
|
| 5870 |
\subsubsection{Example with vectors and matrices} |
| 5871 |
\label{sssec:csv} |
| 5872 |
|
| 5873 |
Suppose we want to manipulate 3-dimensional vectors, which will be represented |
| 5874 |
as |nutples| of length 3. And let's add a bit of matrix algebra. |
| 5875 |
\begin{everbatim*} |
| 5876 |
\xintdeffunc dprod(V, W) := V[0]*W[0] + V[1]*W[1] + V[2]*W[2]; |
| 5877 |
\xintdeffunc cprod(V, W) := [V[1]*W[2] - V[2]*W[1], |
| 5878 |
V[2]*W[0] - V[0]*W[2], |
| 5879 |
V[0]*W[1] - V[1]*W[0]]; |
| 5880 |
\xintdeffunc Det3(U, V, W) := dprod(cprod(U, V), W); |
| 5881 |
\xintdeffunc DetMat(M) = Det3(*M); |
| 5882 |
\xintdeffunc RowMat(U, V, W) := [U, V, W]; |
| 5883 |
\xintdeffunc ColMat(U, V, W) := [[U[0], V[0], W[0]], |
| 5884 |
[U[1], V[1], W[1]], |
| 5885 |
[U[2], V[2], W[2]]]; |
| 5886 |
\xintdeffunc MatMul(A, B) := |
| 5887 |
[[A[0,0]*B[0,0]+A[0,1]*B[1,0]+A[0,2]*B[2,0], |
| 5888 |
A[0,0]*B[0,1]+A[0,1]*B[1,1]+A[0,2]*B[2,1], |
| 5889 |
A[0,0]*B[0,2]+A[0,1]*B[1,2]+A[0,2]*B[2,2]], |
| 5890 |
[A[1,0]*B[0,0]+A[1,1]*B[1,0]+A[1,2]*B[2,0], |
| 5891 |
A[1,0]*B[0,1]+A[1,1]*B[1,1]+A[1,2]*B[2,1], |
| 5892 |
A[1,0]*B[0,2]+A[1,1]*B[1,2]+A[1,2]*B[2,2]], |
| 5893 |
[A[2,0]*B[0,0]+A[2,1]*B[1,0]+A[2,2]*B[2,0], |
| 5894 |
A[2,0]*B[0,1]+A[2,1]*B[1,1]+A[2,2]*B[2,1], |
| 5895 |
A[2,0]*B[0,2]+A[2,1]*B[1,2]+A[2,2]*B[2,2]]]; |
| 5896 |
|
| 5897 |
\xintdefvar vec1, vec2, vec3 := [1, 1, 1], [1, 1/2, 1/4], [1, 1/3, 1/9]; |
| 5898 |
\xintdefvar mat1 = RowMat(vec1, vec2, vec3); |
| 5899 |
\xintdefvar mat2 = ColMat(vec1, vec2, vec3); |
| 5900 |
\xintdefvar mat12 = MatMul(mat1,mat2); |
| 5901 |
\xintdefvar mat21 = MatMul(mat2,mat1); |
| 5902 |
Some computations (|align| executes multiple times hence we pre-computed!): |
| 5903 |
\begin{align*} |
| 5904 |
M_1 &= \vcenter{\xintthealign \xintexpr mat1\relax}&&\qquad |
| 5905 |
M_2 . M_1 = \vcenter{\xintthealign \xintexpr mat21\relax}\\[3\jot] |
| 5906 |
M_2 &= \vcenter{\xintthealign \xintexpr mat2\relax}&&\qquad |
| 5907 |
M_1 . M_2 = \vcenter{\xintthealign \xintexpr mat12\relax} |
| 5908 |
\end{align*} |
| 5909 |
$$ |
| 5910 |
\det(M_1) = \xinteval{DetMat(mat1)},\quad |
| 5911 |
\det(M_1.M_2) = \xinteval{reduce(DetMat(mat12))},\quad |
| 5912 |
\det(M_2.M_1) = \xinteval{reduce(DetMat(mat21))} |
| 5913 |
$$ |
| 5914 |
\end{everbatim*}% |
| 5915 |
For some hair-raising experience check the \csbxint{verbosetrue} output in the |
| 5916 |
log...\@{} here is an alternative with two (three, counting |dprod()|) helper |
| 5917 |
functions: |
| 5918 |
\begin{everbatim*} |
| 5919 |
% annoying that Tr also starts Trace, but Spur is available |
| 5920 |
% well Sp also starts Spectrum. Big problems. |
| 5921 |
\xintdeffunc Tr(M) := |
| 5922 |
[[M[0,0], M[1,0], M[2,0]], |
| 5923 |
[M[0,1], M[1,1], M[2,1]], |
| 5924 |
[M[0,2], M[1,2], M[2,2]]]; |
| 5925 |
|
| 5926 |
\xintdeffunc MatMul_a(r1, r2, r3, c1, c2, c3) := |
| 5927 |
[[dprod(r1, c1), dprod(r1, c2), dprod(r1, c3)], |
| 5928 |
[dprod(r2, c1), dprod(r2, c2), dprod(r2, c3)], |
| 5929 |
[dprod(r3, c1), dprod(r3, c2), dprod(r3, c3)]]; |
| 5930 |
|
| 5931 |
\xintdeffunc MatMul(A, B) := MatMul_a(*A, *Tr(B)); |
| 5932 |
\end{everbatim*} |
| 5933 |
|
| 5934 |
And once we have the transpose and the scalar product of vectors, we can |
| 5935 |
simply use \func{ndmap} for a lean syntax (this would extend to arbitrary |
| 5936 |
dimension): |
| 5937 |
\begin{everbatim*} |
| 5938 |
\xintdeffunc MatMul(A, B) = ndmap(dprod, *A; *Tr(B)); |
| 5939 |
\xintdefvar mat1212 = MatMul(mat12, mat12); |
| 5940 |
\begingroup |
| 5941 |
\def\xintexprPrintOne #1{\xintTeXFrac{#1}}% |
| 5942 |
\def\xintexpralignbegin {\begin{pmatrix}}% |
| 5943 |
\def\xintexpralignend {\end{pmatrix}}% |
| 5944 |
\def\xintexpralignlinesep {\noexpand\\[2\jot]}% counteract an internal \expanded |
| 5945 |
\def\xintexpraligninnersep {&}% |
| 5946 |
\let\xintexpralignleftbracket\empty \let\xintexpralignleftsep\empty |
| 5947 |
\let\xintexpralignrightbracket\empty \let\xintexpralignrightsep\empty |
| 5948 |
$$ \xintthealign \xintexpr mat1\relax \cdot \xintthealign \xintexpr mat2\relax \cdot |
| 5949 |
\xintthealign \xintexpr mat1\relax \cdot \xintthealign \xintexpr mat2\relax = |
| 5950 |
\xintthealign \xintexpr mat12\relax ^2 = \xintthealign \xintexpr mat1212\relax$$ |
| 5951 |
$$ \det(M_1\cdot M_2 \cdot M_1 \cdot M_2) = \xinteval{reduce(DetMat(mat1212))}$$ |
| 5952 |
\endgroup |
| 5953 |
\end{everbatim*} |
| 5954 |
|
| 5955 |
\subsubsection{Example with the \textsc{Rump} test} |
| 5956 |
\label{sssec:Rump} |
| 5957 |
|
| 5958 |
Let's try out our |Rump()| function: |
| 5959 |
\begin{everbatim*} |
| 5960 |
\xinttheexpr Rump(77617,33096)\relax. |
| 5961 |
\end{everbatim*} |
| 5962 |
Nothing problematic for an \emph{exact} evaluation, naturally! |
| 5963 |
|
| 5964 |
Thus to test the \textsc{Rump} polynomial (it is not quite a polynomial with |
| 5965 |
its |x/2y| final term) with floats, we \emph{must} also |
| 5966 |
declare |Rump| as a function to be used there: |
| 5967 |
\begin{everbatim*} |
| 5968 |
\xintdeffloatfunc |
| 5969 |
Rump(x,y):=333.75 y^6 + x^2 (11 x^2 y^2 - y^6 - 121 y^4 - 2) + 5.5 y^8 + x/2y; |
| 5970 |
\end{everbatim*} |
| 5971 |
|
| 5972 |
The numbers are scanned with the current precision, hence as here it is |
| 5973 |
\dtt{16}, they are scanned exactly in this case. We can then vary the |
| 5974 |
precision for the evaluation. |
| 5975 |
\begin{everbatim*} |
| 5976 |
\def\CR{\cr} |
| 5977 |
\halign |
| 5978 |
{\tabskip1ex |
| 5979 |
\hfil\bfseries#&\xintDigits:=\xintiloopindex\relax |
| 5980 |
\xintthefloatexpr Rump(77617,33096)#\cr |
| 5981 |
\xintiloop [8+1] |
| 5982 |
\xintiloopindex &\relax\CR |
| 5983 |
\ifnum\xintiloopindex<40 \repeat |
| 5984 |
} |
| 5985 |
\end{everbatim*} |
| 5986 |
|
| 5987 |
\subsubsection{Examples of recursive definitions} |
| 5988 |
\label{sssec:recursive} |
| 5989 |
|
| 5990 |
Recursive definitions \emph{require} using the short-circuit branching |
| 5991 |
operators. |
| 5992 |
\begin{everbatim*} |
| 5993 |
\xintdeffunc GCD(a,b):=(b)?{GCD(b,a/:b)}{a}; |
| 5994 |
\end{everbatim*} |
| 5995 |
This of course is the Euclide algorithm: it will be here applied to variables |
| 5996 |
which may be fractions. For example: |
| 5997 |
\begin{everbatim*} |
| 5998 |
\xinttheexpr GCD(385/102, 605/238)\relax |
| 5999 |
\end{everbatim*} |
| 6000 |
|
| 6001 |
There is already a built-in \func{gcd} (which |
| 6002 |
accepts arbitrarily many arguments): |
| 6003 |
\begin{everbatim*} |
| 6004 |
\xinttheexpr gcd(385/102, 605/238)\relax |
| 6005 |
\end{everbatim*} |
| 6006 |
|
| 6007 |
Our second example is modular exponentiation: |
| 6008 |
\begin{everbatim*} |
| 6009 |
\xintdefiifunc powmod_a(x, m, n) := |
| 6010 |
isone(m)? |
| 6011 |
% m=1, return x modulo n |
| 6012 |
{ x /: n } |
| 6013 |
% m > 1 test if odd or even and do recursive call |
| 6014 |
{ odd(m)? { x*sqr(powmod_a(x, m//2, n)) /: n } |
| 6015 |
{ sqr(powmod_a(x, m//2, n)) /: n } |
| 6016 |
} |
| 6017 |
; |
| 6018 |
\xintdefiifunc powmod(x, m, n) := (m)?{powmod_a(x, m, n)}{1}; |
| 6019 |
\end{everbatim*} |
| 6020 |
I have made the definition here for the |\xintiiexpr| parser; we could do the |
| 6021 |
same for the |\xintexpr|-parser (but its usage with big powers would quickly |
| 6022 |
create big denominators, think |powmod(1/2, 1000, 1)| for example.) |
| 6023 |
\begin{everbatim*} |
| 6024 |
\xinttheiiexpr seq(powmod(x, 1000, 128), x=9, 11, 13, 15, 17, 19, 21)\relax\par |
| 6025 |
\end{everbatim*} |
| 6026 |
The function assumes the exponent is non-negative (the Python |pow| behaved |
| 6027 |
the same until |3.8| release), but zealous users will add the necessary code for negative |
| 6028 |
exponents, after having defined another function for modular inverse! |
| 6029 |
|
| 6030 |
If function |A| needs function |B| which needs function |A| start by giving to |
| 6031 |
|B| some dummy definition, define |A|, then define |B| properly. TODO: add |
| 6032 |
some example here... |
| 6033 |
|
| 6034 |
\subsection {Links to some (old) examples within this document} |
| 6035 |
\label{sec:awesome} |
| 6036 |
|
| 6037 |
\begin{itemize} |
| 6038 |
\item The utilities provided by \xinttoolsname (\autoref{sec:tools}), some |
| 6039 |
completely expandable, others not, are of independent interest. Their use |
| 6040 |
is illustrated through various examples: among those, it is shown in |
| 6041 |
\autoref{ssec:quicksort} how to implement in a completely expandable way |
| 6042 |
the \hyperref[ssec:quicksort]{Quick Sort algorithm} and also how to illustrate |
| 6043 |
it graphically. Other examples include some dynamically constructed |
| 6044 |
alignments with automatically computed prime number cells: one using a |
| 6045 |
completely expandable prime test and \csbxint{ApplyUnbraced} |
| 6046 |
(\autoref{ssec:primesI}), another one with \csbxint{For*} (\autoref{ssec:primesIII}). |
| 6047 |
|
| 6048 |
\item One has also a \hyperref[edefprimes]{computation of primes within an |
| 6049 |
\csa{edef}} (\autoref{xintiloop}), with the help of \csbxint{iloop}. |
| 6050 |
Also with \csbxint{iloop} an |
| 6051 |
\hyperref[ssec:factorizationtable]{automatically generated table of |
| 6052 |
factorizations} (\autoref{ssec:factorizationtable}). |
| 6053 |
|
| 6054 |
\item The code for the title page fun with Fibonacci numbers is given in |
| 6055 |
\autoref{ssec:fibonacci} with \csbxint{For*} joining the game. |
| 6056 |
|
| 6057 |
\item The computations of \hyperref[ssec:Machin]{ $\pi$ and $\log 2$} |
| 6058 |
(\autoref{ssec:Machin}) using \xintname and the computation of the |
| 6059 |
\hyperref[ssec:e-convergents]{convergents of $e$} with the further help of |
| 6060 |
the \xintcfracname package are among further examples. |
| 6061 |
|
| 6062 |
\item Also included, |
| 6063 |
an \hyperlink{BrentSalamin}{expandable implementation of the Brent-Salamin |
| 6064 |
algorithm} for evaluating $\pi$. |
| 6065 |
|
| 6066 |
\item The \autoref{ssec:PrimesIV} implements expandably the Miller-Rabin |
| 6067 |
pseudo-primality test. |
| 6068 |
|
| 6069 |
|
| 6070 |
\item The functionalities of \xintexprname are illustrated with various |
| 6071 |
other examples, in \autoref{xintdeffunc}, |
| 6072 |
\hyperlink{ssec:dummies}{Functions with dummy variables}, |
| 6073 |
\autoref{ssec:moredummies} or \hyperref[sssec:recursive]{Recursive definitions}. |
| 6074 |
\end{itemize} |
| 6075 |
% ça va sans dire |
| 6076 |
% Almost all of the computational results interspersed throughout the |
| 6077 |
% documentation are not hard-coded in the source file of this document but are |
| 6078 |
% obtained via the expansion of the package macros during the \TeX{} |
| 6079 |
% run.% |
| 6080 |
|
| 6081 |
\subsection{Oples and nutples: the \texttt{1.4} terminology} |
| 6082 |
\label{oples} |
| 6083 |
|
| 6084 |
\emph{Skip this on first reading, else you will never start using the |
| 6085 |
package.} \fbox{SKIP THIS!} (understood?) |
| 6086 |
|
| 6087 |
In this section I will describe a mathematical terminology which models |
| 6088 |
how the parser handles the input syntax with numbers, commas, and brackets, |
| 6089 |
and how it maps internally to \TeX\ specific concept, particularly braces and |
| 6090 |
macro arguments. |
| 6091 |
|
| 6092 |
\etocsetnexttocdepth{subsubsection} |
| 6093 |
\localtableofcontents |
| 6094 |
|
| 6095 |
\subsubsection{Base terminology} |
| 6096 |
|
| 6097 |
We start with a set $\mathcal{A}$ of \emph{atoms}, which represent numeric |
| 6098 |
data. In \TeX{} syntax such \emph{atoms} are always braced, more precisely, |
| 6099 |
currently they look like |
| 6100 |
% |
| 6101 |
\centeredline{\dtt{\{raw format within \TeX{} braces\}}} |
| 6102 |
% |
| 6103 |
The \TeX{} braces are not set-theoretical braces here, they are simply used |
| 6104 |
for \TeX nical reasons (one could imagine using rather some terminator token, |
| 6105 |
but ultimately support macros for built-in and user defined functions rely on |
| 6106 |
\TeX\ macros with undelimited parameters, at least so far). |
| 6107 |
|
| 6108 |
Our category $\mathcal{C}$ of \myenquote{oples} is the smallest collection of |
| 6109 |
\emph{totally ordered finite sets} verifying these properties: |
| 6110 |
\begin{enumerate} |
| 6111 |
\item The empty set \dtt{$\emptyset$} is an \emph{ople}, i.e.\@{} it belongs to |
| 6112 |
$\mathcal{C}$. |
| 6113 |
\item Each singleton set \dtt{$\{O\}$} whose element \dtt{$O$} is either an |
| 6114 |
\emph{atom} $a\in\mathcal{A}$ or an \emph{ople} qualifies as an \emph{ople}. |
| 6115 |
\item $\mathcal{C}$ is stable by concatenation. |
| 6116 |
\end{enumerate} |
| 6117 |
|
| 6118 |
Notes: |
| 6119 |
\begin{itemize} |
| 6120 |
\item |
| 6121 |
We refer to the empty set \dtt{$\emptyset$} via the variable \emph{nil}.% |
| 6122 |
% |
| 6123 |
\footnote{There is |
| 6124 |
actually a built-in variable with this name. At |1.4|, |\xintexpr\relax| is |
| 6125 |
legal and also generates the \emph{nil}.} |
| 6126 |
|
| 6127 |
\item It is convenient to accept the empty set as being also an |
| 6128 |
\emph{atom}. If this is done, then we may refer to the original |
| 6129 |
\emph{atoms} (elements of $\mathcal{A}$) as \emph{non empty numerical data}. |
| 6130 |
|
| 6131 |
\item |
| 6132 |
Concatenation is represented in the syntax by the |
| 6133 |
comma. Thus repeated commas are like only one and |nil| is a neutral element. |
| 6134 |
|
| 6135 |
\item A singleton \emph{ople} \dtt{$\{a\}$} whose single element is a |
| 6136 |
(non-empty) \emph{atom} is called a \emph{number}.% |
| 6137 |
% |
| 6138 |
\footnote{This has to be taken in a general sense, for example with |
| 6139 |
\ctanpackage{polexpr}, polynomials are represented by such \myenquote{numbers}.} |
| 6140 |
% |
| 6141 |
|
| 6142 |
\item |
| 6143 |
The operation of constructing \dtt{$\{O\}$} from the \emph{ople} \dtt{$O$} is |
| 6144 |
called \emph{bracing} (set theory, \TeX), or \emph{bracketing} (\xintexprname |
| 6145 |
input syntax, Python |lists|), or \emph{packing} (as a reverse to Python's |
| 6146 |
unpacking of sequence type objects). In the expression input syntax it |
| 6147 |
corresponds to enclosing \dtt{$O$} within square brackets: \dtt{$[O]$}. |
| 6148 |
|
| 6149 |
\item A braced \emph{ople} is called a \emph{nutple}. Among them \dtt{\{nil\}} |
| 6150 |
(aka $\{\emptyset\}$) is a bit special. It is called the \emph{none-ple}.% |
| 6151 |
% |
| 6152 |
\footnote{Prior to version |1.4j| of this documentation it was called the |
| 6153 |
\emph{not-ple}.} |
| 6154 |
% |
| 6155 |
It is not \dtt{nil}.% |
| 6156 |
% |
| 6157 |
\footnote{There is (experimental) a pre-defined \myenquote{\dtt{None}} variable which |
| 6158 |
stands for the \emph{none-ple}. It can also be input as |[]|.} |
| 6159 |
\end{itemize} |
| 6160 |
|
| 6161 |
Each \emph{ople} has a \emph{length} which is its cardinality as set. The |
| 6162 |
singleton |oples| are called \emph{one-ples}. There are thus two types of |
| 6163 |
\emph{one-ples}: |
| 6164 |
\begin{itemize} |
| 6165 |
\item \emph{numbers} \dtt{$\{a\}$}, $a \in \mathcal{A}$, |
| 6166 |
\item \emph{nutples} \dtt{$\{O\}$}, $O \in \mathcal{C}$. |
| 6167 |
\end{itemize} |
| 6168 |
|
| 6169 |
If we consider the empty set |nil| on the same footing as |atoms|, the two |
| 6170 |
types have only one common object which is the \emph{none-ple}. As a rule |
| 6171 |
arithmetic operations will either break or silently convert the \emph{none-ple} |
| 6172 |
to the zero value: |
| 6173 |
\begin{everbatim*} |
| 6174 |
\xinteval{3+[], 5^[], 10*[]} |
| 6175 |
\end{everbatim*}. |
| 6176 |
But attention that \csbxint{iieval} in contrast to \csbxint{eval} is broken by |
| 6177 |
such inputs. |
| 6178 |
|
| 6179 |
\subsubsection{Items (and sub-items) versus elements} |
| 6180 |
|
| 6181 |
In order to illustrate these concepts, let us consider how one should |
| 6182 |
interpret notation such as |3,5,7,9| when it arises in an |
| 6183 |
\csbxint{expr}|ession|: |
| 6184 |
\begin{description} |
| 6185 |
\item[tempting vocabulary:] Each of |3|, |5|, |7|, and |9| is an \emph{item}, or |
| 6186 |
\emph{element} of the (comma separated) \emph{list}. In other terms we have |
| 6187 |
here a list with 4 items. |
| 6188 |
\item[rigorous vocabulary:] each one of |3|, |5|, |7|, |9| stands for an |
| 6189 |
\emph{ople} (of the \emph{one-ple} type) and |3,5,7,9| stands for their \emph{concatenation}. |
| 6190 |
\end{description} |
| 6191 |
It is important to understand that in an \csbxint{expr}|ession|, there is no |
| 6192 |
difference between |3,5,7| and |3,,,,5,,,,,,,,,7|. So the view of the comma |
| 6193 |
as separator is misleading. In other terms, the comma is NOT a separator but |
| 6194 |
the (associative) operator of concatenation of totally ordered sets, and the |
| 6195 |
number |3| for example represents a (singleton) set. |
| 6196 |
|
| 6197 |
If we want to refer to |3| or |5| or |7| or |9| as \myenquote{the items of the |
| 6198 |
(open) list |3,5,7,9|} (and probably this documentation already has such |
| 6199 |
utterances, due to legacy reasons from the pre-|1.4| internal model), we |
| 6200 |
\emph{must} realize that this clashes with using the word \emph{item} as |
| 6201 |
synonymous to \emph{element} in the set-theoretical sense. |
| 6202 |
|
| 6203 |
To repeat, any ople \dtt{$O$} is a finite totally ordered set: if not the empty |
| 6204 |
set, it has \emph{elements} \dtt{$a_1$}, \dots, \dtt{$a_k$}, and the above means that |
| 6205 |
its \emph{items} are the singleton oples (aka one-ples) \dtt{$I_1=\{a_1\}$}, |
| 6206 |
\dots, \dtt{$I_k=\{a_k\}$}. Each \dtt{$a_j$} may be an |atom|, then |
| 6207 |
\dtt{$I_j$} is a |number|, or \dtt{$a_j$} is an |ople| (possibly the empty set), then |
| 6208 |
\dtt{$I_j$} is a |nutple| whose depth is one more than the one of the ople |
| 6209 |
\dtt{$a_j$}. |
| 6210 |
|
| 6211 |
Thus we can refer to \myenquote{items} but must then understand they are not \myenquote{elements}: |
| 6212 |
\myenquote{items} are \myenquote{singleton sub-sets}. The cardinality (aka length) of an ople is |
| 6213 |
also the number of its |
| 6214 |
items. It would be tempting to use the terminology \myenquote{sub-item} to keep in mind they are \myenquote{sub-sets} |
| 6215 |
but this would again create confusion: a |nutple| has only one item which is |
| 6216 |
itself; and we need some terminology to refer to the individual numbers in the |
| 6217 |
|nutple| given in input as |[1,2,3]| for example. It is natural to refer to |
| 6218 |
|1|, |2|, |3| as \myenquote{sub-items} of |[1,2,3]| as the latter may be an \myenquote{item} (it |
| 6219 |
is in particular an \myenquote{item} of itself, the unique one at that). |
| 6220 |
|
| 6221 |
We distinguish the |oples| of length zero (there is only one, the empty set) |
| 6222 |
or at least two as those which can never be an \myenquote{item}. Those of length one, |
| 6223 |
the |one-ples|, are exactly those which can be \myenquote{items}. Among them some may |
| 6224 |
have \myenquote{sub-items}, they are the |nutples| with the exception of the |none-ple|. |
| 6225 |
And the others do not have \myenquote{sub-items}, they are the |numbers| and the |none-ple| (whose input syntax is |
| 6226 |
either |[]| or the variable |None|).% |
| 6227 |
% |
| 6228 |
\footnote{% |
| 6229 |
A note on the \csbxint{verbosetrue} regime: for a variable defined to be |
| 6230 |
|3,5,7,9|, it will say that its value is |{3}{5}{7}{9}|, because it does not |
| 6231 |
keep the external set-theoretical braces. The braces here are only \TeX{} |
| 6232 |
braces, and |{3}| is an |atom|. The |number| would be |{{3}}| with the |
| 6233 |
external braces being set-theoretical and also used internally as \TeX{} |
| 6234 |
braces. From the four numbers |{{3}}|, ..., |{{9}}| concatenation gives |
| 6235 |
|{{3}{5}{7}{9}}|, which is the |ople| |3,5,7,9|. But the log view drops |
| 6236 |
deliberately the external braces. If the variable is defined to be the |
| 6237 |
|nutple| |[3,5,7,9]|, then the log view will be |{{3}{5}{7}{9}}| (up to |
| 6238 |
details on how exactly the numeric quantities are coded) and the actual |
| 6239 |
internal \TeX{} entity will be |{{{3}{5}{7}{9}}}|, where the two external |
| 6240 |
layers of braces are both set-theoretical and \TeX nical braces.} |
| 6241 |
|
| 6242 |
|
| 6243 |
\subsubsection{Oples as trees} |
| 6244 |
|
| 6245 |
We say that the empty set |nil| and \emph{atoms} are \emph{leaves}. |
| 6246 |
|
| 6247 |
We associate with any \emph{ople} a tree. The root is the ople. In the case of |
| 6248 |
the |nil| ople, there is nothing else than the root, which we then consider |
| 6249 |
also a \emph{leaf}. Else the children at top level are the successive |
| 6250 |
\emph{elements} (not \myenquote{items}!) of the ople.% |
| 6251 |
% |
| 6252 |
\footnote{\label{fn:alttree}% |
| 6253 |
We could also consider a tree for which the children of the root node would |
| 6254 |
be its items and recursively; in that case the leaves would be |numbers| and |
| 6255 |
possibly the |None|. The tree of the |nil| would be the empty tree, the tree |
| 6256 |
of |None| would have a single node and no edges. Such a tree would match |
| 6257 |
the input syntax (of course applying the rule that iterated commas are like |
| 6258 |
only one). The tree which is described in this section matches more |
| 6259 |
directly the internal syntax, hence is more useful to the author, who is |
| 6260 |
also the sole reader who extracts some benefit from reading this |
| 6261 |
documentation once in a while.} |
| 6262 |
% |
| 6263 |
Among the elements some are \emph{atoms} giving \emph{leaves} of the tree, |
| 6264 |
others are \emph{nutples} which in turn have children. In the special case of |
| 6265 |
the \emph{none-ple} we consider it has a child, which is the empty set and this |
| 6266 |
is why we consider the empty set |nil| to be also a potential \emph{leaf}. We |
| 6267 |
then proceed recursively. We thus obtain from the root \emph{ople} a tree |
| 6268 |
whose vertices are either \emph{oples} or \emph{leaves}. Only the empty set |
| 6269 |
|nil| is both a \emph{leaf} and an \emph{ople}. |
| 6270 |
|
| 6271 |
Considering the empty set |nil| as an \emph{atom} fits with the \xintexprname |
| 6272 |
internal implementation based on \TeX: |nil| is an empty pair of braces |{}|, |
| 6273 |
whereas an \emph{atom} is a braced representation of a numeric value using |
| 6274 |
digits and other characters. We construct \emph{oples} by putting one after |
| 6275 |
the other such constituents and bracing them, and then repeating the process |
| 6276 |
recursively. |
| 6277 |
|
| 6278 |
It has also an impact on the definition of the \emph{depth} (a.k.a as |
| 6279 |
\emph{maximal dimension}) of an \emph{ople}. For example the \emph{ople} |
| 6280 |
$\{\emptyset A_1A_2\}$ with three elements, among them the empty set and two |
| 6281 |
atoms is said to have depth $1$, or to have maximal dimension $1$. And |
| 6282 |
$\{\{\emptyset\}A_1A_2\}$ is of depth $2$ because it has a leaf (the empty |
| 6283 |
set) which is a child of a child of the \emph{ople}. NumPy \emph{ndarrays} |
| 6284 |
have a more restricted structure for example |
| 6285 |
$\{\{A_{00}A_{01}\}\{A_{10}A_{11}\}\}$ is a $2$-dimensional array, where all |
| 6286 |
leaves are at the same depth. When slicing empties the array from its atoms, |
| 6287 |
NumPy keeps the shape information but prints the array as $[]$. This will not |
| 6288 |
be the case with \xintexprname, which has no other way to indicate the shape |
| 6289 |
than display it. |
| 6290 |
\begin{everbatim*} |
| 6291 |
\xinteval{[[],[]]} |
| 6292 |
\end{everbatim*} |
| 6293 |
\begin{everbatim*} |
| 6294 |
\xinteval{[[0,1],[10,11]][:,2:]} |
| 6295 |
\end{everbatim*} |
| 6296 |
|
| 6297 |
\subsubsection{Ople slicing and indexing} |
| 6298 |
\label{sssec:opleslicing} |
| 6299 |
|
| 6300 |
\myenquote{Set-theoretical} slicing of an \emph{ople} means replacing it with one of its |
| 6301 |
subsets. This applies also if it is a \emph{number}. Then it can be sliced |
| 6302 |
only to itself or to the empty set (indeed it has only one element, which is |
| 6303 |
an atom). Similarly the \emph{none-ple} can only be sliced to give itself or |
| 6304 |
the empty set. And more generally a \emph{nutple} is a singleton so also can |
| 6305 |
only be set-sliced to either the empty set or itself. |
| 6306 |
|
| 6307 |
\xintexprname extends \myenquote{Python-like} slicing to act on \emph{oples}: |
| 6308 |
\begin{itemize}[nosep] |
| 6309 |
\item if they are not \emph{nutples} set-theoretical slicing applies, |
| 6310 |
\item if they are \emph{nutples} (only case having a one-to-one |
| 6311 |
correspondence in Python) then the slicing happens \emph{within brackets}: |
| 6312 |
i.e.\@{} the \emph{nutple} is unpacked then the set-theoretical slicing is |
| 6313 |
applied, then the result is \emph{repacked} to produce a new \emph{nutple}. |
| 6314 |
\end{itemize} |
| 6315 |
With these conventions the \emph{none-ple} for example is invariant under |
| 6316 |
slicing: unpacking it gives the empty set, which has only the empty set as |
| 6317 |
subset and repacking gives back the \emph{none-ple}. Slicing a general |
| 6318 |
\emph{nutple} returns a \emph{nutple} but now of course in general distinct |
| 6319 |
from the first one. |
| 6320 |
|
| 6321 |
The input syntax for Python slicing is to postfix a variable or a |
| 6322 |
parenthesized ople with |[a:b]|. See \autoref{ssec:lists} for more. There |
| 6323 |
are never any out-of-range errors when slicing or indexing. All operations |
| 6324 |
are licit and resolved by the |nil|, a.k.a. empty set. |
| 6325 |
|
| 6326 |
\myenquote{Set-theoretical} item indexing of an \emph{ople} means reducing it to a |
| 6327 |
subset which is a singleton. It is thus a special case of set-theoretical |
| 6328 |
slicing (which is the general process of selecting a subset as replacement of |
| 6329 |
a set). |
| 6330 |
|
| 6331 |
\xintexprname extends \myenquote{Python-like} indexing to act on \emph{oples}: |
| 6332 |
\begin{itemize}[nosep] |
| 6333 |
\item if they are not \emph{nutples} set-theoretical item indexing applies, |
| 6334 |
\item if they are \emph{nutples} (only case having a one-to-one |
| 6335 |
correspondence in Python) then the meaning becomes \emph{extracting}: i.e.\@ |
| 6336 |
the \emph{nutple} is unpacked then the set-theoretical indexing is applied, |
| 6337 |
but the result is \emph{not repacked}. |
| 6338 |
\end{itemize} |
| 6339 |
For example when applied to the \emph{none-ple} we always obtain |
| 6340 |
the |nil|. Whereas as we saw slicing the \emph{none-ple} always gives back the |
| 6341 |
\emph{none-ple}. Indexing is denoted in the syntax by postfixing by |[N]|. Thus |
| 6342 |
for \emph{nutples} (which are analogous to Python objects), there is genuine |
| 6343 |
difference between the |[N]| extractor and the |[N:N+1]| slicer. But for |
| 6344 |
\emph{oples} which are either |nil|, a \emph{number}, or of length at least 2, |
| 6345 |
there is no difference. |
| 6346 |
|
| 6347 |
\subsubsection{Nested slicing of oples} |
| 6348 |
|
| 6349 |
Nested slicing is a concept from NumPy, which is extended by \xintexprname to |
| 6350 |
trees of varying depths. We have a chain of slicers and extractors. I will |
| 6351 |
describe only the case of slicers and letting them act on a |nutple|. The |
| 6352 |
first slicer gives back a new |nutple|. The second slicer will be applied to |
| 6353 |
each of one of its remaining elements. However some of them may be |
| 6354 |
\emph{atoms} or the empty set. In the NumPy context all leaves are at the |
| 6355 |
same depth thus this can happen only when we have reached beyond the last |
| 6356 |
dimension (axis). This is not permitted by NumPy and generates an error. |
| 6357 |
\xintexprname does not generate an error. But any attempt to slice an |
| 6358 |
\emph{atom} or the empty set (as element of its container) removes it. Recall |
| 6359 |
we call them \emph{leaves}. We can not slice leaves. We can only slice |
| 6360 |
non-leaf elements: such items are necessarily |nutples|. The procedure then |
| 6361 |
applies recursively. |
| 6362 |
|
| 6363 |
If we handle an extractor rather than a slicer, the procedure is similar: we |
| 6364 |
can not extract out of an \emph{atom} or the empty set. They are thus |
| 6365 |
removed. Else we have a |nutple|. It is thus unpacked and replaced by the |
| 6366 |
selected element. This element may be an atom or the empty set and any further |
| 6367 |
slicer or extractor will remove them, or it is a |nutple| and the procedure |
| 6368 |
applies with the next slicer/extractor. |
| 6369 |
|
| 6370 |
\xintexprname allows to apply such a |[a:b,c:d,N,e:f,...]| chain of |
| 6371 |
slicing/extracting also to an \emph{ople}, which is not a \emph{nutple}. We |
| 6372 |
simply apply the first step as has been described previously and successive |
| 6373 |
steps will only get applied to either \emph{nutples} or \emph{leaves}, the |
| 6374 |
latter getting silently removed by any attempted operation. |
| 6375 |
|
| 6376 |
\subsubsection{Function arguments versus variables} |
| 6377 |
\label{sssec:funcargs} |
| 6378 |
|
| 6379 |
In a function declaration with \csbxint{deffunc}, the call signature is parsed |
| 6380 |
as a comma separated list, so here it is not true that repeated commas are |
| 6381 |
like only one: repeated commas are not allowed and will break the function |
| 6382 |
declaration. |
| 6383 |
|
| 6384 |
When \xintexprname parses a function call, it first constructs the ople which |
| 6385 |
is delimited by the opening and closing parentheses, then it applies the |
| 6386 |
function body, after having mapped the successive items (not the elements) of |
| 6387 |
the parsed ople to the variables appearing in the function call |
| 6388 |
signature. Hence the arguments in the call signature stand for |one-ples| |
| 6389 |
(i.e.\@{} either |numbers| or |nutples|). |
| 6390 |
|
| 6391 |
Let me explain why we can not define a function |foo(A,B)| of two oples: the |
| 6392 |
function call will evaluate as an ople what is enclosed within the |
| 6393 |
parentheses. It is then impossible in general to split this uniquely into two |
| 6394 |
oples |A| and |B|, except if for example we know a priori the length of |A|. |
| 6395 |
We could imagine defining a declarative interface for a |foo(A,B)| with |A| |
| 6396 |
preset to have \dtt{37} items or at least a pre-defined number of items but |
| 6397 |
this is extraneous layer for a functionality no-one will use. |
| 6398 |
|
| 6399 |
The alternative would be to consider that declaring |foo(A,B)| means |A| will |
| 6400 |
pick-up always the first item and |B| all the remaining ones, and thus will be |
| 6401 |
an ople; here, there are some \TeX nical implementation reasons which have |
| 6402 |
dissuaded the author to do this. |
| 6403 |
|
| 6404 |
In its place, a special syntax |foo(A,*B)| for the declaration of the function |
| 6405 |
is available. It means that |B| stands for the |nutple| which |
| 6406 |
receives as items all arguments in the function call beyond the first one |
| 6407 |
already assigned to |A|. |
| 6408 |
|
| 6409 |
More generally, the last positional argument in a function declaration can |
| 6410 |
have the form |*|\meta{argname}. This then means that \meta{argname} |
| 6411 |
represents a |nutple| which will receive as items all arguments in the |
| 6412 |
function call remaining after the earlier positional arguments have been |
| 6413 |
assigned. The declared function body is free to again use the syntax |
| 6414 |
|*|\meta{argname} which will unpack it and thus produce the ople concatenating |
| 6415 |
all such optional arguments. |
| 6416 |
|
| 6417 |
With \csbxint{defvar} one can define a variable with value an |ople| of |
| 6418 |
arbitrary cardinality. Such a variable can be used in a function call, it |
| 6419 |
will then occupy the place of as many arguments as its cardinality (which is |
| 6420 |
its number of elements, hence of its associated items). For example if |
| 6421 |
function |foo| was declared as a function of 5 arguments |f(a,b,c,d,e)| it is |
| 6422 |
legitimate to use it as |f(A,B)| if |A| is an ople-valued variable of length |
| 6423 |
three and |B| of length two. The actual arguments |a,b,c,d,e| will be made to |
| 6424 |
match the three items of |A| and the two items of |B|. |
| 6425 |
|
| 6426 |
\subsubsection{Final words on leaves} |
| 6427 |
|
| 6428 |
In case things were too clear, let's try to add a bit of confusion with an |
| 6429 |
extra word on \emph{leaves}. When we discuss informally (particularly to |
| 6430 |
compare with NumPy) an input such as |
| 6431 |
\begin{everbatim} |
| 6432 |
[[1, 2], [3, 4]] |
| 6433 |
\end{everbatim} |
| 6434 |
we may well refer to |1|, |2|, |3|, and |4| as being \myenquote{the leaves of the 2d |
| 6435 |
array}. But obviously we have here numbers and previously we explained that a |
| 6436 |
number is not a \emph{leaf}, its \emph{atom} is. Well, the point here is that |
| 6437 |
we must make a difference between the input form as above and the actual |
| 6438 |
constructed \emph{ople} the parser will obtain out of it. In the input we do |
| 6439 |
have numbers. The comma is a \emph{concatenator}, it is not a separator for |
| 6440 |
enumeration! The \emph{ople} which corresponds to it has a \TeX{} |
| 6441 |
representation like this: |
| 6442 |
\begin{everbatim} |
| 6443 |
{{{1}{2}}{{3}{4}}} |
| 6444 |
\end{everbatim} |
| 6445 |
where we don't have the \emph{numbers} anymore (which would look like |{{1}}|, |
| 6446 |
|{{2}}|, ...) but numeric \emph{atoms} |{1}|, |{2}|, |{3}|, |{4}| where the |
| 6447 |
braces are \TeX{} braces and \textbf{not} set-theoretical braces (the other |
| 6448 |
braces are both). Hence we should see the above as the |ople| |
| 6449 |
$\{\{A_{00}A_{01}\}\{A_{10}A_{11}\}\}$ with atoms $A_{00}=\{1\}$, ..., being the |
| 6450 |
\emph{leaves} of the tree associated to (or which is) the \emph{ople}. |
| 6451 |
|
| 6452 |
Numbers may be called the \emph{leaves} of the \textbf{input}, but once |
| 6453 |
parsed, the input becomes an \emph{ople} which is |
| 6454 |
(morally) a tree whose leaves are \emph{atoms} (and the empty set). |
| 6455 |
This discussion can also be revisited with footnote |
| 6456 |
%%\footref{fn:alttree} |
| 6457 |
\ref{fn:alttree} in mind. |
| 6458 |
|
| 6459 |
\subsubsection{Farewell, thanks for your visit!} |
| 6460 |
|
| 6461 |
I hope this is clear to everyone. If not, maybe time to say this section is |
| 6462 |
not needed to understand almost all of the manual, but I needed to |
| 6463 |
write it to be able to maintain in future my own software. |
| 6464 |
|
| 6465 |
|
| 6466 |
\subsection{Expansion (for geeks only)} |
| 6467 |
|
| 6468 |
As mentioned already, the parsers are compatible with expansion-only |
| 6469 |
context. |
| 6470 |
|
| 6471 |
Also, they expand the expression piece by piece: the normal mode of operation |
| 6472 |
of the parsers is to unveil the parsed material token by token. Unveiling is |
| 6473 |
a process combining space swallowing, brace removal (one level generally), and |
| 6474 |
\fexpan sion. |
| 6475 |
|
| 6476 |
For example a closing parenthesis after some function arguments does not have |
| 6477 |
to be immediately visible, it and the arguments themselves may arise from |
| 6478 |
\fexpan sion (applied before grabbing each successive token). Even the ending |
| 6479 |
|\relax| may arise from expansion. Even though the \csbxint{eval} user |
| 6480 |
interface means that the package has at some point the entire expression in |
| 6481 |
its hands, it immediately re-inserts it into token stream with an additional |
| 6482 |
postfixed |\relax| and from this point on has lost any ways (a simple-minded |
| 6483 |
delimited macro won't do because the expression is allowed to contain |
| 6484 |
sub-\csbxint{expr}essions, even nested) to manipulate formally again the whole |
| 6485 |
thing; it can only re-discover it one token at a time. |
| 6486 |
|
| 6487 |
This general behaviour (which allows much more freedom in assembling |
| 6488 |
expressions than is usually the case with familiar programming languages such |
| 6489 |
as Python, although admittedly that freedom will prove useful only to |
| 6490 |
power-\TeX users and possibly does not have that many significant use cases) |
| 6491 |
has significative exceptions. These exceptions are mostly related to |
| 6492 |
\myenquote{pseudo}-functions. A \myenquote{pseudo}-function will grab some of its arguments via |
| 6493 |
delimited macros. For example |subs(expr1,x=expr2)| needs to see the comma, |
| 6494 |
equal sign and closing parenthesis. But it has mechanisms to allow |expr1| and |
| 6495 |
|expr2| to possess their own commas and parentheses. |
| 6496 |
|
| 6497 |
Inner semi-colons on the other hand currently always can originate from expansion. |
| 6498 |
Defining functions or variables requires a visible semi-colon acting as |
| 6499 |
delimiter of the expression, but inner semi-colons do not need to be |
| 6500 |
hidden within braces or macros. |
| 6501 |
|
| 6502 |
The expansion stops only when the ending |\relax| has been found |
| 6503 |
(it is then removed from the token stream). |
| 6504 |
|
| 6505 |
For catcode related matters see \csbxint{exprSafeCatcodes}. |
| 6506 |
|
| 6507 |
A word of warning on the bracketed optional argument of respectively |
| 6508 |
\csbxint{floatexpr} and \csbxint{iexpr}. When defining macros which will hand |
| 6509 |
over some argument to one of these two parsers, the argument may potentially |
| 6510 |
start with a left square bracket |[| (e.g. argument could be |[1, 2, 3]|) and |
| 6511 |
this will break the parser. The fix is to use in the macro definition |
| 6512 |
|\xintfloatexpr\empty|. This extra |\empty| token will prevent the parser |
| 6513 |
from thinking there is an optional argument and it will then disappear during |
| 6514 |
expansion. |
| 6515 |
|
| 6516 |
\begin{footnotesize} |
| 6517 |
If comparing to other languages able to handle floating point numbers or big |
| 6518 |
integers, such as Python, one should take into account that what the \xintname |
| 6519 |
packages manipulate are streams of ascii bytes, one per digit. At no time |
| 6520 |
(due to expandability) is it possible to store intermediate results in an |
| 6521 |
arithmetic CPU register; each elementary operation via |\the\numexpr| will |
| 6522 |
output digit tokens (hence as many bytes), not things such as handles to |
| 6523 |
memory locations where some numbers are stored as memory words. The process |
| 6524 |
can never put aside things but can only possibly permute them with upcoming |
| 6525 |
tokens, to use them later, or, via combinations of |\expanded| and |
| 6526 |
|\unexpanded| or some other more antiquated means grab some tokens and shift |
| 6527 |
the expansion to some distant locations to later come back. The process is a |
| 6528 |
never-ending one-dimensional one...\par |
| 6529 |
\end{footnotesize} |
| 6530 |
|
| 6531 |
\subsection{Known bugs/features (last updated at \texttt{1.4n})} |
| 6532 |
|
| 6533 |
\begin{description} |
| 6534 |
|
| 6535 |
% probable wont-fix |
| 6536 |
\item[{\cs{xinteval}\char`\{\cs{xintLength}\char`\{\cs{par}\cs{par}\cs{par}\char`\}\char`\}} complains about a Runaway argument:]\mbox{} |
| 6537 |
|
| 6538 |
|\xintLength{\par\par\par}| has no issue as |
| 6539 |
|\xintLength| is a |\long| macro but this is not the case of |
| 6540 |
|\xinteval|. Most macros of a non arithmetic nature in |
| 6541 |
\xintkernelname and \xinttoolsname are declared |\long| but |
| 6542 |
absolutely none in \xintexprname, and its dependencies \xintname, etc... |
| 6543 |
% |
| 6544 |
As a remark in passing, I could not use the \LaTeX{} |\item| directly:% |
| 6545 |
% |
| 6546 |
\footnote{For those who wonder my custom |\verb| employs a |
| 6547 |
|\scantokens| approach, so it can be used in the argument of a |
| 6548 |
macro, for example \verb+\footnote{\verb|\verb|}+.} |
| 6549 |
% |
| 6550 |
\begin{everbatim} |
| 6551 |
Runaway argument? |
| 6552 |
{|\xinteval {\xintLength { |
| 6553 |
! Paragraph ended before \@item was complete. |
| 6554 |
<to be read again> |
| 6555 |
\par |
| 6556 |
l.4434 \item[{|\xinteval{\xintLength{\par |
| 6557 |
\par\par}| complains about a Runawa... |
| 6558 |
\end{everbatim} |
| 6559 |
This is the reason I guess why everything is a priori |\long| in the |
| 6560 |
\LaTeX3 interface except if asked for otherwise (as far as I know). |
| 6561 |
|
| 6562 |
Although most macros are dealing with inputs which can only be with digits |
| 6563 |
and some other character tokens, it would still be quite some work to |
| 6564 |
chase all top-level ones. Besides, in pratice, it does help better locate |
| 6565 |
ill-formed input. |
| 6566 |
|
| 6567 |
|
| 6568 |
\item[|if(100>0,(100,125),(100,128))| breaks my code:] |
| 6569 |
% |
| 6570 |
This is a feature. This is a syntax error, as the comma serves to contatenate |
| 6571 |
"oples" (see \autoref{oples}), and parentheses do not create analogs of |
| 6572 |
"tuples", so this input is parsed the same as |
| 6573 |
\begin{everbatim} |
| 6574 |
if(100>0,100,125,100,128) |
| 6575 |
\end{everbatim} |
| 6576 |
which is an error as \func{if} requires exactly three arguments, not |
| 6577 |
five. Use: |
| 6578 |
\begin{everbatim} |
| 6579 |
if(100>0,[100,125],[100,128]) |
| 6580 |
\end{everbatim} |
| 6581 |
which will expand to the "tuple" |[100,125]|. |
| 6582 |
|
| 6583 |
|
| 6584 |
\item[{\cs{xintdeffunc} |foo(x):= gcd((x>0)?{[x,125]}{[x,128]});| |
| 6585 |
creates a broken function:}] |
| 6586 |
% |
| 6587 |
Bug. Normally \func{gcd} (and other |
| 6588 |
multi-arguments functions) work both with open lists of arguments or |
| 6589 |
bracketed lists ("nutples") and the above syntax would work perfectly fine |
| 6590 |
in numerical context. But the presence of the \oper{?} breaks in |
| 6591 |
\csbxint{deffunc} context the flexibility of \func{gcd}. |
| 6592 |
|
| 6593 |
Currently working alternatives: |
| 6594 |
\begin{everbatim} |
| 6595 |
\xintdeffunc foo(x) := gcd(if(x>0, [x,125], [x,128])); |
| 6596 |
\xintdeffunc foo(x) := if(x>0, gcd(x,125), gcd(x,128)); |
| 6597 |
\xintdeffunc foo(x) := if(x>0, gcd([x,125]), gcd([x,128])); |
| 6598 |
\xintdeffunc foo(x) := gcd((x>0)?{x,125}{x,128}); |
| 6599 |
\xintdeffunc foo(x) := (x>0)?{gcd(x,125)}{gcd(x,128)}; |
| 6600 |
\xintdeffunc foo(x) := (x>0)?{gcd([x,125])}{gcd([x,128])}; |
| 6601 |
\end{everbatim} |
| 6602 |
The same problem will arise with an \oper{??} nested inside \func{gcd} or |
| 6603 |
similar functions, in an \csbxint{deffunc}. |
| 6604 |
|
| 6605 |
\item[{\cs{xinteval}|{0^-.5}| says "0 raised to power -1"}] |
| 6606 |
% |
| 6607 |
Feature. Half integer exponents are handled via a square-root extraction, so |
| 6608 |
here \xintexprname wanted to first raise \dtt{0} to power \dtt{-1}, as |
| 6609 |
reported. |
| 6610 |
|
| 6611 |
\item[{Comparison operator |==| crashes with nutples}] |
| 6612 |
% |
| 6613 |
Not yet implemented... |
| 6614 |
|
| 6615 |
\item[{I liked the ``broadcasting'' |[1..10]^10| syntax, but it |
| 6616 |
was removed at 1.4}] |
| 6617 |
% |
| 6618 |
Patience...\@{} |seq(x^10,x=1..10)| is alternative (add external |[..]| to get |
| 6619 |
a nutple). |
| 6620 |
|
| 6621 |
\item[{|1e\numexpr5+2\relax| crashes}] |
| 6622 |
% |
| 6623 |
Not clear yet if bug or feature. |
| 6624 |
The syntax accepted in the scientific part is limited, and failure |
| 6625 |
is expected: hitting a |\numexpr| |
| 6626 |
when parsing a number triggers insertion of a tacit multiplication and then |
| 6627 |
|1e| is missing the scientific exponent. The same happens with |1e(2+3)|. |
| 6628 |
Use syntax such as |1e\the\numexpr5+2\relax|, or |1e\xinteval{5+2}| |
| 6629 |
(although here this relies on output format of |\xinteval| using integer |
| 6630 |
notation with no decoration in this case). |
| 6631 |
|
| 6632 |
\item[{|seq(1e-i,i=1..5)| crashes}] |
| 6633 |
% |
| 6634 |
Not clear if bug or feature. Use |seq(1e\xinteval{-i},i=1..5)| or, as a |
| 6635 |
possibly faster way |seq(1e\xintiieval{-i},i=\xintiiexpr1..5\relax)|. |
| 6636 |
|
| 6637 |
\item[{\keyword{omit}/\keyword{abort} if nested and not last in the sub-expression cause a crash}] |
| 6638 |
% |
| 6639 |
For example |seq(subs((i)?{i}{abort},t=i)+10, i=-2, -1, 0, 1)| crashes, due |
| 6640 |
to the presence of the |+10|. This is a longstanding limitation, applying |
| 6641 |
ever since |omit/abort| were added to the syntax at |1.1|. Even without |
| 6642 |
the |+10| the nested case was broken by a |1.4| regression and got fixed |
| 6643 |
only at |1.4h|. The non-nested case |seq((i)?{i}{abort}+10, i=-2, -1, 0, |
| 6644 |
1)| works and the \myenquote{must be last in expression if nested} limitation is |
| 6645 |
currently considered a feature. |
| 6646 |
|
| 6647 |
\item[{|\xintdeffunc X(a,k)= add(n^k, n=1..a);| creates a broken function:}] |
| 6648 |
% |
| 6649 |
Bug. Sadly \csbxint{deffunc} has problems. When it does not work, use |
| 6650 |
\csbxint{NewFunction} to define the function. Examples: |
| 6651 |
\begin{everbatim*} |
| 6652 |
\xintNewFunction{myX}[2]{add(n^#2, n=1..#1)}\xinteval{myX(10,7)}\newline |
| 6653 |
\xintNewFunction{myY}[2]{mul(1 - j/#1, j=1..#2-1)}\xintfloateval{myY(10,10)} |
| 6654 |
\end{everbatim*} |
| 6655 |
|
| 6656 |
\item[{|seq([i,i\string^2], i=1..10)| crashes with Ooops, looks like we are missing a |
| 6657 |
]. Aborting!}] |
| 6658 |
% |
| 6659 |
Bug. The cause is that the square brackets do not hide the comma from |
| 6660 |
|seq()| parsing. Contrarily to what happens with parentheses, there |
| 6661 |
is no balancing mechanism for square brackets. Work-arounds: either |
| 6662 |
use an extra pair of parentheses |seq(([i,i^2]), ...)| or hide the |
| 6663 |
inner comma within braces |seq([i{,}i^2], ...)|. |
| 6664 |
|
| 6665 |
\item[{|subs([x,x^2],x=3);| crashes with Ooops, looks like we are missing a ]. Aborting!}] |
| 6666 |
% |
| 6667 |
Bug. Same cause as previous one. Workaround: use parentheses |
| 6668 |
|subs(([x,x^2]),x=3| or curly braces |subs({[x,x^2]},x=3|. |
| 6669 |
\begin{everbatim*} |
| 6670 |
\xinteval{subs({[x^10,x^20,x^30]}, x=17)} |
| 6671 |
\end{everbatim*} |
| 6672 |
|
| 6673 |
\item[{|seq([x,2x,3x],x=3..5);| crashes with Ooops, looks like we are |
| 6674 |
missing a ]. Aborting!}] |
| 6675 |
% |
| 6676 |
Bug. Same cause as previous one. The |
| 6677 |
workaround is again to use braces to hide the inner commas. |
| 6678 |
\begin{everbatim*} |
| 6679 |
\xinteval{seq({[x^10,x^20,x^30]}, x=1, 2, 3)} |
| 6680 |
\end{everbatim*} |
| 6681 |
|
| 6682 |
\item[{% |
| 6683 |
\settowidth{\dimen0}{we are missing a ]. Aborting!}% |
| 6684 |
\makebox[\the\dimen0][l] |
| 6685 |
{\parbox[b]{\linewidth} |
| 6686 |
{|iter([1,10^6];[sqrt(@[0]*@[1]),(@[0]+@[1])/2], i=1..7)| |
| 6687 |
also complains with Ooops, looks like we are missing a ]. Aborting!}% |
| 6688 |
}% |
| 6689 |
}] |
| 6690 |
% |
| 6691 |
Bug. Turns out that braces would not do the job here, but parentheses do work: |
| 6692 |
\begingroup\xintSetDigits{32}% |
| 6693 |
\begin{everbatim*} |
| 6694 |
% 32 digits and 8 iterations v------ parentheses added ------v |
| 6695 |
\xintfloateval{iter([1,10^6];([sqrt(@[0]*@[1]),(@[0]+@[1])/2]), i=1..8)} |
| 6696 |
\end{everbatim*} |
| 6697 |
\endgroup |
| 6698 |
\end{description} |
| 6699 |
|
| 6700 |
|
| 6701 |
More bugs are known to the author and many more no doubt exist. |
| 6702 |
|
| 6703 |
\clearpage |
| 6704 |
\etocdepthtag.toc {part1B} |
| 6705 |
|
| 6706 |
\let\xintexprnameUp\undefined |
| 6707 |
\csname xintexpr (old doc)nameUp\endcsname |
| 6708 |
\section{The macros of \xintexprname (ancient documentation, mostly)}% |
| 6709 |
\RaisedLabel{sec:oldxintexpr} |
| 6710 |
|
| 6711 |
\localtableofcontents |
| 6712 |
|
| 6713 |
The \xintexprname package was first released with version |1.07| |
| 6714 |
(|2013/05/25|) of the \xintbundlename. It was substantially enhanced with |
| 6715 |
release |1.1| from |2014/10/28|. |
| 6716 |
|
| 6717 |
The |1.4| release from |2020/01/31| maintains the same general architecture |
| 6718 |
but needed adapting all the code base for the switch from |\csname| to |
| 6719 |
|\expanded| techniques. On this occasion the mechanism for defining functions |
| 6720 |
was substantially strengthened. The parser core mechanisms were improved too. |
| 6721 |
|
| 6722 |
The package loads automatically \xintfracname and \xinttoolsname. |
| 6723 |
|
| 6724 |
This section should be trimmed to contain only information not |
| 6725 |
already covered in \autoref{sec:expr}. |
| 6726 |
|
| 6727 |
\subsection{The \csh{xintexpr} expressions} |
| 6728 |
\label{xintexpr} |
| 6729 |
\label{xinttheexpr} |
| 6730 |
\label{xintthe} |
| 6731 |
|
| 6732 |
An \xintexprname{}ession is a construct |
| 6733 |
\csbxint{expr}\meta{expandable\_expression}|\relax|\etype{x} where the |
| 6734 |
expandable expression is read and completely expanded from left to right. |
| 6735 |
|
| 6736 |
An |\xintexpr...\relax| \emph{must} end in a |\relax| (which will be absorbed). |
| 6737 |
Contrarily to a |\numexpr| expression, it is printable as is without a prefix |
| 6738 |
|\the| or |\number| (don't use them with |\xintexpr| this will raise an |
| 6739 |
error). |
| 6740 |
|
| 6741 |
But one can use |\xintthe| prefix if one does need the explicit digits and |
| 6742 |
other characters as in the final typesetted result. |
| 6743 |
|
| 6744 |
As an alternative and equivalent syntax to |
| 6745 |
\begin{everbatim} |
| 6746 |
\xintexpr round(<expression>, D)\relax |
| 6747 |
\end{everbatim} |
| 6748 |
there is |
| 6749 |
\begin{everbatim} |
| 6750 |
\xintiexpr [D] <expression> \relax |
| 6751 |
\end{everbatim} |
| 6752 |
For |D>0| this produces a decimal number with |D| figures after the decimal |
| 6753 |
mark, which is the rounding of the expression. For |D=0| the rounding to an |
| 6754 |
integer is produced. For |D<0| (and this was changed at |1.4f|), the rounded |
| 6755 |
quotient of the expression by \verb=1e|D|= is produced. |
| 6756 |
\begin{itemize} |
| 6757 |
\item the expression may contain arbitrarily many levels of nested parenthesized |
| 6758 |
sub-expressions, |
| 6759 |
\item the expression may contain explicitely or from a macro expansion a |
| 6760 |
sub-expression |\xintexpr...\relax|, which itself may contain a |
| 6761 |
sub-expressions etc\dots |
| 6762 |
\item to let sub-contents evaluate as a sub-unit it should thus be either |
| 6763 |
\begin{enumerate} |
| 6764 |
\item parenthesized, |
| 6765 |
\item or a sub-expression |\xintexpr...\relax|. |
| 6766 |
\end{enumerate} |
| 6767 |
\item to use an expression as argument to macros from \xintfracname, |
| 6768 |
or more generally to macros which expand their arguments, one must use the |
| 6769 |
|\xinttheexpr...\relax| or |\xintthe\xintexpr...\relax| forms. |
| 6770 |
\item one should not use |\xintthe\xintexpr...\relax| as a sub-constituent of |
| 6771 |
another expression but only the |
| 6772 |
|\xintexpr...\relax| form which is more efficient in this context. |
| 6773 |
\item each \xintexprname{}ession, whether prefixed or not with |\xintthe|, is |
| 6774 |
completely expandable and obtains its result in two expansion steps. |
| 6775 |
\end{itemize} |
| 6776 |
|
| 6777 |
The information now following is possibly in need of updates. |
| 6778 |
|
| 6779 |
\begin{itemize}[parsep=0pt, labelwidth=\leftmarginii, |
| 6780 |
itemindent=0pt, listparindent=\leftmarginiii, leftmargin=\leftmarginii] |
| 6781 |
\item An expression is built the standard way with opening and closing |
| 6782 |
parentheses, infix operators, and (big) numbers, with possibly a fractional |
| 6783 |
part, and/or scientific notation (except for \csbxint{iiexpr} which only |
| 6784 |
admits big integers). All variants work with comma separated expressions. On |
| 6785 |
output each comma will be followed by a space. A decimal number must have |
| 6786 |
digits either before or after the decimal mark. |
| 6787 |
|
| 6788 |
\item As everything gets expanded, the characters |.|, |+|, |-|, |*|, |/|, |^|, |
| 6789 |
|!|, |&|, \verb+|+, |?|, |:|, |<|, |>|, |=|, |(|, |)|, |"|, |]|, |[|, |@| |
| 6790 |
and the comma |,| should not (if used in the expression) be active. |
| 6791 |
|
| 6792 |
\begin{snugframed} |
| 6793 |
\begin{itemize}[nosep] |
| 6794 |
\item Babel-activated\NewWithf{1.4n} characters (for example |!|, |
| 6795 |
|?|, |;| and |:| with French) are not a problem. |
| 6796 |
\item If the character is active due to some other mechanism, prefix it with |
| 6797 |
|\string|. |
| 6798 |
\item A few syntax elements involving the comma, the equal sign and the |
| 6799 |
closing parenthesis are implemented using delimited macros. They are |
| 6800 |
not allowed to be catcode active (even via Babel) and |\string| will |
| 6801 |
not work. Use then \csbxint{exprSafeCatcodes}, see next. |
| 6802 |
\end{itemize} |
| 6803 |
\end{snugframed} |
| 6804 |
|
| 6805 |
One can use \csbxint{exprSafeCatcodes} to reset all |
| 6806 |
characters potentially needed by \csbxint{expr} to their standard catcodes |
| 6807 |
and \csbxint{exprRestoreCatcodes} then restores the former status. |
| 6808 |
|
| 6809 |
Note that this is what \csbxint{defvar} and \csbxint{deffunc} do automatically. |
| 6810 |
Expandable \csbxint{floateval} et al. can't do that. |
| 6811 |
|
| 6812 |
\item Count registers and |\numexpr|-essions are accepted (LaTeX{}'s counters |
| 6813 |
can be inserted using |\value|) natively without |\the| or |\number| as |
| 6814 |
prefix. Also dimen registers and control sequences, skip registers and |
| 6815 |
control sequences (\LaTeX{}'s lengths), |\dimexpr|-essions, |
| 6816 |
|\glueexpr|-essions are automatically unpacked using |\number|, discarding |
| 6817 |
the stretch and shrink components and giving the dimension value in |sp| |
| 6818 |
units ($1/65536$th of a \TeX{} point). Furthermore, tacit multiplication is |
| 6819 |
implied, when the (count or dimen or glue) register or variable, or the |
| 6820 |
(|\numexpr| or |\dimexpr| or |\glueexpr|) expression is immediately prefixed |
| 6821 |
by a (decimal) number. See \autoref{ssec:tacit multiplication} for the complete rules |
| 6822 |
of tacit multiplication.\IMPORTANT |
| 6823 |
|
| 6824 |
\item With a macro |\x| defined like this: |
| 6825 |
% |
| 6826 |
\leftedline{|\def\x {\xintexpr \a + \b \relax}| or |\edef\x {\xintexpr |
| 6827 |
\a+\b\relax}|} |
| 6828 |
% |
| 6829 |
one may then do |\xintthe\x|, either for printing the result on the page or |
| 6830 |
to use it in some other macros expanding their arguments. The |\edef| does |
| 6831 |
the computation immediately but keeps it in a protected form. |
| 6832 |
Naturally, the |\edef| is only possible if |\a| and |\b| are already |
| 6833 |
defined. With both approaches the |\x| can be inserted in other expressions, |
| 6834 |
as for example (assuming naturally as we use an |\edef| that in the |
| 6835 |
`yet-to-be computed' case the |\a| and |\b| now have some suitable meaning): |
| 6836 |
% |
| 6837 |
\leftedline {|\edef\y {\xintexpr \x^3\relax}|} |
| 6838 |
|
| 6839 |
\item There is also \csbxint{boolexpr}| ... \relax| and |
| 6840 |
\csbxint{theboolexpr}| ... \relax|. |
| 6841 |
|
| 6842 |
\item See also |
| 6843 |
\csbxint{ifboolexpr} (\autoref{xintifboolexpr}) and the |
| 6844 |
\func{bool} and \func{togl} functions |
| 6845 |
in \autoref{sec:expr}. Here is an example. Well in fact the |
| 6846 |
example ended up using only \csbxint{boolexpr} so it |
| 6847 |
was modified to use \csbxint{ifboolexpr}. |
| 6848 |
\catcode`| 12 % |
| 6849 |
\begin{everbatim*} |
| 6850 |
\xintdeffunc A(p,q,r) = p && (q || r) ; |
| 6851 |
\xintdeffunc B(p,q,r) = p || (q && r) ; |
| 6852 |
\xintdeffunc C(p,q,r) = xor(p, q, r) ; |
| 6853 |
|
| 6854 |
\centeredline{\normalcolor |
| 6855 |
\begin{tabular}{ccrclcl} |
| 6856 |
\xintFor* #1 in {{False}{True}} \do {% |
| 6857 |
\xintFor* #2 in {{False}{True}} \do {% |
| 6858 |
\xintFor* #3 in {{False}{True}} \do {% |
| 6859 |
#1 &AND &(#2 &OR )&is&\textcolor[named]{OrangeRed} |
| 6860 |
{\xintifboolexpr{A(#1,#2,#3)}{true}{false}}\\ |
| 6861 |
#1 &OR &(#2 &AND )&is&\textcolor[named]{OrangeRed} |
| 6862 |
{\xintifboolexpr{B(#1,#2,#3)}{yes}{no}}\\ |
| 6863 |
#1 &XOR & #2 &XOR  &is&\textcolor[named]{OrangeRed} |
| 6864 |
{\xintifboolexpr{C(#1,#2,#3)}{oui}{non}}\\ |
| 6865 |
}}} |
| 6866 |
\end{tabular}% |
| 6867 |
} |
| 6868 |
\end{everbatim*}\catcode`| 13 |
| 6869 |
|
| 6870 |
\item See also \csbxint{ifsgnexpr}. |
| 6871 |
|
| 6872 |
\item There is \csbxint{floatexpr}| ... \relax| where the algebra is done |
| 6873 |
in floating point approximation (also for each intermediate result). Use the |
| 6874 |
syntax |\xintDigits:=N\relax| to set the precision. Default: $16$ digits. |
| 6875 |
% |
| 6876 |
\leftedline{|\xintthefloatexpr 2^100000\relax:| \dtt{\xintthefloatexpr |
| 6877 |
2^100000\relax }} |
| 6878 |
% |
| 6879 |
The square-root operation can be used in |\xintexpr|, it is computed |
| 6880 |
as a float with the precision set by |\xintDigits| or by the optional |
| 6881 |
second argument: |
| 6882 |
% |
| 6883 |
\begin{everbatim*} |
| 6884 |
\xinttheexpr sqrt(2,60)\relax\newline |
| 6885 |
Here the [60] is to avoid truncation to |\xinttheDigits| of precision on output. |
| 6886 |
\newline |
| 6887 |
\printnumber{\xintthefloatexpr [60] sqrt(2,60)\relax} |
| 6888 |
\end{everbatim*} |
| 6889 |
|
| 6890 |
Floats are quickly indispensable when using the power function, as exact |
| 6891 |
results will easily have hundreds, even thousands of digits. |
| 6892 |
% |
| 6893 |
\begin{everbatim*} |
| 6894 |
\xintDigits:=48\relax \xintthefloatexpr 2^100000\relax |
| 6895 |
\end{everbatim*} |
| 6896 |
|
| 6897 |
Only integer and (in |\xintfloatexpr...\relax|) half-integer exponents are |
| 6898 |
allowed. |
| 6899 |
|
| 6900 |
\item if one uses \emph{macros} within |\xintexpr..\relax| one should |
| 6901 |
obviously take into account that the parser will \emph{not} see the macro |
| 6902 |
arguments, hence one cannot use the syntax there, except if the arguments |
| 6903 |
are themselves wrapped as |\xinttheexpr...\relax| and assuming the macro |
| 6904 |
\fexpan ds these arguments. |
| 6905 |
\end{itemize} |
| 6906 |
\subsection{\texorpdfstring{\texttt{\protect\string\numexpr}}{\textbackslash |
| 6907 |
numexpr} or \texorpdfstring{\texttt{\protect\string\dimexpr}}{\textbackslash |
| 6908 |
dimexpr} expressions, count and dimension registers and variables} |
| 6909 |
\label{ssec:countinexpr} |
| 6910 |
|
| 6911 |
Count registers, count control sequences, dimen registers, dimen control |
| 6912 |
sequences (like |\parindent|), skips and skip control sequences, |\numexpr|, |
| 6913 |
|\dimexpr|, |\glueexpr|, |\fontdimen| can be inserted directly, they will be |
| 6914 |
unpacked using |\number| which gives the internal value in terms of scaled |
| 6915 |
points for the dimensional variables: $1$\,|pt|${}=65536$\,|sp| (stretch and |
| 6916 |
shrink components are thus discarded). |
| 6917 |
|
| 6918 |
Tacit multiplication (see \autoref{ssec:tacit multiplication}) is implied, |
| 6919 |
when a number or decimal number prefixes such a register or control sequence. |
| 6920 |
\LaTeX{} lengths are skip control sequences and \LaTeX{} counters should be |
| 6921 |
inserted using |\value|. |
| 6922 |
|
| 6923 |
Release |1.2| of the |\xintexpr| parser also recognizes and prefixes with |
| 6924 |
|\number| the |\ht|, |\dp|, and |\wd| \TeX{} primitives as well as the |
| 6925 |
|\fontcharht|, |\fontcharwd|, |\fontchardp| and |\fontcharic| \eTeX{} |
| 6926 |
primitives. |
| 6927 |
|
| 6928 |
In the case of numbered registers like |\count255| or |\dimen0| (or |\ht0|), |
| 6929 |
the resulting digits will be re-parsed, so for example |\count255 0| is like |
| 6930 |
|100| if |\the\count255| would give |10|. The same happens with inputs such |
| 6931 |
as |\fontdimen6\font|. And |\numexpr 35+52\relax| will be exactly as if |87| |
| 6932 |
as been encountered by the parser, thus more digits may follow: |\numexpr |
| 6933 |
35+52\relax 000| is like |87000|. If a new |\numexpr| follows, it is treated |
| 6934 |
as what would happen when |\xintexpr| scans a number and finds a non-digit: it |
| 6935 |
does a tacit multiplication. |
| 6936 |
\begin{everbatim*} |
| 6937 |
\xinttheexpr \numexpr 351+877\relax\numexpr 1000-125\relax\relax{} is the same |
| 6938 |
as \xinttheexpr 1228*875\relax. |
| 6939 |
\end{everbatim*} |
| 6940 |
|
| 6941 |
Control sequences however (such as |\parindent|) are picked up as a whole by |
| 6942 |
|\xintexpr|, and the numbers they define cannot be extended extra digits, a |
| 6943 |
syntax error is raised if the parser finds digits rather than a legal |
| 6944 |
operation after such a control sequence. |
| 6945 |
|
| 6946 |
A token list variable must be prefixed by |\the|, it will not be unpacked |
| 6947 |
automatically (the parser will actually try |\number|, and thus fail). Do not |
| 6948 |
use |\the| but only |\number| with a dimen or skip, as the |\xintexpr| parser |
| 6949 |
doesn't understand |pt| and its presence is a syntax error. To use a dimension |
| 6950 |
expressed in terms of points or other \TeX{} recognized units, incorporate it in |
| 6951 |
|\dimexpr...\relax|. |
| 6952 |
|
| 6953 |
Regarding how dimensional expressions are converted by \TeX{} into scaled points |
| 6954 |
see also \autoref{sec:Dimensions}. |
| 6955 |
|
| 6956 |
\subsection{Catcodes and spaces} |
| 6957 |
|
| 6958 |
The main problems are caused by active characters, because \csbxint{expr} et |
| 6959 |
al.\@{} expand forward whatever comes from token stream; they apply |\string| |
| 6960 |
only in a second step. For example the catcode of |&| from |&&| Boolean |
| 6961 |
disjunction is not really important as long as it is not active, or comment, |
| 6962 |
or escape...\@{} or brace...\@{} or ignored...\@{} in brief, as long as it is reasonable, |
| 6963 |
and in particular whether |@| is of catcode letter or other does not matter. |
| 6964 |
|
| 6965 |
It is always possible to insert manually the |\string| in the expression |
| 6966 |
before a problematic (but reasonable) character catcode, or even to use |
| 6967 |
|\detokenize| for a big chunk. |
| 6968 |
|
| 6969 |
\subsubsection{\csh{xintexprSafeCatcodes}} |
| 6970 |
\label{xintexprSafeCatcodes} |
| 6971 |
|
| 6972 |
Some problems with active characters can be resolved on the fly by prefixing |
| 6973 |
them by |\string| but some aspects of the parsing done by \csbxint{expr} |
| 6974 |
involves delimited macros which need the comma, equality sign and closing |
| 6975 |
parenthesis to have their standard catcodes. |
| 6976 |
|
| 6977 |
So \csbxint{exprSafeCatcodes} is provided as a utility to set in one go |
| 6978 |
catcodes of many characters to \csbxint{expr}-safely compatible values. This |
| 6979 |
is a non-expandable step as it changes catcodes. |
| 6980 |
% This is used |
| 6981 |
% internally by \csbxint{NewExpr} (restoring the catcodes on exit), hence it |
| 6982 |
% does not have to be protected against active characters when used at |
| 6983 |
% top-level. |
| 6984 |
|
| 6985 |
\csbxint{defvar}, \csbxint{deffunc}, et al., use it, and then they restore |
| 6986 |
catcodes to the prior state via \csbxint{exprRestoreCatcodes}. |
| 6987 |
|
| 6988 |
% As \csbxint{NewExpr} and \csbxint{deffunc} and variants use internally some |
| 6989 |
% |\scantokens|, they will (reasonably) succeed in sanitizing catcodes in the |
| 6990 |
% expressions, even if all is from the replacement text of some macro whose |
| 6991 |
% definition was done under some special catcode regime. |
| 6992 |
|
| 6993 |
% \csbxint{deffunc} is more lenient than \csbxint{defvar} regarding catcodes of |
| 6994 |
% characters in expression bodies as it does some |\scantokens| which will reset |
| 6995 |
% compatible catcodes. |
| 6996 |
|
| 6997 |
% Even if used in a context where catcodes are already set, \csbxint{deffunc}, |
| 6998 |
% \csbxint{defvar} and variants ignore completely the colon in |:=| so it can |
| 6999 |
% have any (reasonable) catcode. Moreover it is optional. |
| 7000 |
|
| 7001 |
% The semi-colon in the syntax of \csbxint{Digits} is no real problem either |
| 7002 |
% (cf. \csbxint{Digits} documentation). |
| 7003 |
|
| 7004 |
\subsubsection{\csh{xintexprRestoreCatcodes}} |
| 7005 |
\label{xintexprRestoreCatcodes} |
| 7006 |
|
| 7007 |
Restores the catcodes to the state prevailing at the time of the last executed |
| 7008 |
\csbxint{exprSafeCatcodes} (if located at the same \LaTeX\ environment or |
| 7009 |
\TeX\ grouping level). |
| 7010 |
|
| 7011 |
Prior to |1.4k|, in a situation like the following: |
| 7012 |
\begin{everbatim} |
| 7013 |
\xintexprSafeCatcodes |
| 7014 |
....stuff possibly changing catcodes |
| 7015 |
\xintexprSafeCatcodes |
| 7016 |
....stuff possibly changing catcodes |
| 7017 |
\xintexprSafeCatcodes |
| 7018 |
....stuff possibly changing catcodes |
| 7019 |
\xintexprRestoreCatcodes |
| 7020 |
\end{everbatim} |
| 7021 |
On exit, the catcodes recovered their status as prior to the \emph{first} |
| 7022 |
\csbxint{exprSafeCatcodes}. Since |1.4k|, they are set to what they were |
| 7023 |
prior to the \emph{last} \csbxint{exprSafeCatcodes}, i.e. the mechanism is now |
| 7024 |
similar to a ``last in, first out'' stack. |
| 7025 |
|
| 7026 |
Note that no global assignments are made so the behaviour can be modified |
| 7027 |
by usage of \TeX\ groups or \LaTeX\ environments: e.g. if an |
| 7028 |
\csbxint{exprSafeCatcodes} is issued inside a \LaTeX\ environment it does not |
| 7029 |
have to be paired by \csbxint{exprRestoreCatcodes} explicitly, the catcode |
| 7030 |
scope is limited by the environment. |
| 7031 |
|
| 7032 |
\bigskip |
| 7033 |
|
| 7034 |
Spaces inside an |\xinttheexpr...\relax| should mostly be |
| 7035 |
innocuous (except inside macro arguments). |
| 7036 |
|
| 7037 |
|\xintexpr| and |\xinttheexpr| are for the most part agnostic regarding |
| 7038 |
catcodes, |
| 7039 |
but the characters |
| 7040 |
% |+|, |-|, |*|, |/|, |^|, |!|, |&|, \verb+|+, |?|, |:|, |<|, |>|, |
| 7041 |
%|=|, |(|, |)|, |"|, |[|, |]|, |;|, |
| 7042 |
in the expression should not be \myenquote{active} (except on purpose) |
| 7043 |
as everything is expanded along the way, and |\xintexpr| will choke on |
| 7044 |
typesetting related commands. One can (in almost all cases) use |
| 7045 |
|\string| to prefix a problematic character. |
| 7046 |
|
| 7047 |
\begin{snugframed} |
| 7048 |
Babel-activated\NewWithf{1.4n} characters are not a problem. |
| 7049 |
\end{snugframed} |
| 7050 |
|
| 7051 |
Digits, slash, square brackets, minus sign, in the output from an |
| 7052 |
|\xinttheexpr| are all of catcode 12. For |\xintthefloatexpr| the `e' in the |
| 7053 |
output has its standard catcode ``letter''. |
| 7054 |
|
| 7055 |
\subsection{Expandability, \csh{xintexpro}} |
| 7056 |
|
| 7057 |
As is the case with all other package macros |\xintexpr| \fexpan ds (in two |
| 7058 |
steps) to its final (somewhat protected) result; and |\xinttheexpr| \fexpan ds |
| 7059 |
(in two steps) to the chain of digits (and possibly minus sign |-|, decimal |
| 7060 |
mark |.|, fraction slash |/|, scientific |e|, square brackets |[|, |]|) |
| 7061 |
representing the result. |
| 7062 |
|
| 7063 |
The once expanded |\xintexpr| is |\romannumeral0\xintexpro|. And there |
| 7064 |
are similarly |\xintiexpro| |\xintiiexpro| and |\xintfloatexpro|. For an |
| 7065 |
example see \autoref{ssec:fibonacci}. |
| 7066 |
|
| 7067 |
An expression can only be legally terminated by a |\relax| token, which |
| 7068 |
will be absorbed. This token may arose from expansion, it does not have |
| 7069 |
to be immediately visible. |
| 7070 |
|
| 7071 |
It is quite possible to nest expressions among themselves; for example, if one |
| 7072 |
needs inside an |\xintiiexpr...\relax| to do some computations with fractions, |
| 7073 |
rounding the final result to an integer, one just has to insert |
| 7074 |
|\xintiexpr...\relax|. The functioning of the infix operators will not be in |
| 7075 |
the least affected from the fact that the outer ``environment'' is the |
| 7076 |
|\xintiiexpr| one. |
| 7077 |
|
| 7078 |
|
| 7079 |
\subsection{\csh{xintDigits*}, \csh{xintSetDigits*}} |
| 7080 |
\label{xintDigits*} |
| 7081 |
\label{xintSetDigits*} |
| 7082 |
|
| 7083 |
These starred variants of \csbxint{Digits} and \csbxint{SetDigits} execute |
| 7084 |
\csbxint{reloadxinttrig} and \csbxint{reloadxintlog}. |
| 7085 |
|
| 7086 |
\subsection{\csh{xintiexpr}, \csh{xinttheiexpr}} |
| 7087 |
\label{xintiexpr}\label{xinttheiexpr} |
| 7088 |
|
| 7089 |
Equivalent\etype{x} to doing |\xintexpr round(...)\relax| (more precisely, |
| 7090 |
|round| is applied to each leaf item of the |ople| independently of its |
| 7091 |
depth). |
| 7092 |
|
| 7093 |
Intermediate calculations are exact, only the final output gets |
| 7094 |
rounded. Half integers are rounded towards $+\infty$ for positive |
| 7095 |
numbers and towards $-\infty$ for negative ones. |
| 7096 |
|
| 7097 |
An optional parameter |D| within brackets, immediately after |\xintiexpr| is |
| 7098 |
allowed: it instructs (for |D>0|) the expression to do its final rounding to |
| 7099 |
the nearest value with that many digits after the decimal mark, i.e.\@ |
| 7100 |
|\xintiexpr [D] <expression>\relax| is equivalent (in case of a single |
| 7101 |
expression) to |\xintexpr round(<expression>, D)\relax|. |
| 7102 |
|
| 7103 |
|\xintiexpr [0] ...| is the same as |\xintiexpr ...| and rounds to an integer. |
| 7104 |
|
| 7105 |
The case of negative |D| gives quantization to an integer multiple of |
| 7106 |
\dtt{1e-D}. This was modified at |1.4f| and the produced value |
| 7107 |
is now the rounded quotient by \dtt{1e-D} (i.e. no trailing zeros nor |
| 7108 |
scientific exponent in the output). |
| 7109 |
|
| 7110 |
If truncation rather than rounding is needed on can use |\xintexpr |
| 7111 |
trunc(...)\relax| for truncation to an integer or |\xintexpr |
| 7112 |
trunc(...,D)\relax| for quantization to an integer multiple or \dtt{1eD} (if |
| 7113 |
|D>0|, for |D<0| the analog would be |trunc((...)/1e-D)|). But |
| 7114 |
this works only for a single scalar value. |
| 7115 |
|
| 7116 |
\begin{framed} |
| 7117 |
When defining a macro doing something such as |\xintiexpr #1\relax|, |
| 7118 |
it is recommended to rather use |\xintiexpr\empty #1\relax|, as the |
| 7119 |
|#1| may start with a |[| which without the |\empty| would be |
| 7120 |
interpreted by |\xintiexpr| as the start of the optional |[D]|. |
| 7121 |
\end{framed} |
| 7122 |
|
| 7123 |
\subsection{\csh{xintiiexpr}, \csh{xinttheiiexpr}} |
| 7124 |
\label{xintiiexpr}\label{xinttheiiexpr} |
| 7125 |
|
| 7126 |
This variant\etype{x} does not know fractions. It deals almost only with long |
| 7127 |
integers. Comma separated lists of expressions are allowed. |
| 7128 |
|
| 7129 |
\begin{framed} |
| 7130 |
It maps |/| to the \emph{rounded} quotient. The operator |
| 7131 |
|//| is, like in |\xintexpr...\relax|, mapped to \emph{truncated} division. |
| 7132 |
The Euclidean quotient (which for positive operands is like the truncated |
| 7133 |
quotient) was, prior to release |1.1|, associated to |/|. The function |
| 7134 |
|quo(a,b)| can still be employed. |
| 7135 |
\end{framed} |
| 7136 |
|
| 7137 |
The \csbxint{iiexpr}-essions use the `ii' macros for addition, subtraction, |
| 7138 |
multiplication, power, square, sums, products, Euclidean quotient and |
| 7139 |
remainder. |
| 7140 |
|
| 7141 |
The \func{floor} and \func{ceil} functions are available in this integer |
| 7142 |
only parser, with arguments allowed to be decimal numbers. But for |
| 7143 |
example |floor(5/3)| returns the perhaps counter intuitive value |2|, |
| 7144 |
because |/| does the rounded division to an integer. To force the |
| 7145 |
parser to allow fractions and not interpret |/| as integer-only |
| 7146 |
operator, uses \func{qfrac} as in the examples below. |
| 7147 |
|
| 7148 |
Also \func{round} and \func{trunc} are allowed in |
| 7149 |
\csbxint{iiexpr}-essions: they are mapped to \csbxint{iRound} and |
| 7150 |
\csbxint{iTrunc} which explains how they behave with respect to their |
| 7151 |
optional second argument. |
| 7152 |
\begin{everbatim*} |
| 7153 |
\xinttheiiexpr 5/3, round(5/3,3), trunc(5/3,3), trunc(\xintDiv {5}{3},3), |
| 7154 |
trunc(\xintRaw {5/3},3)\relax{} are problematic, but |
| 7155 |
% |
| 7156 |
\xinttheiiexpr 5/3, round(qfrac(5/3),3), trunc(qfrac(5/3),3), floor(qfrac(5/3)), |
| 7157 |
ceil(qfrac(5/3))\relax{} work! |
| 7158 |
\end{everbatim*} |
| 7159 |
|
| 7160 |
\begin{framed} |
| 7161 |
Scientific notation is not accepted on input for operations, but can |
| 7162 |
be wrapped in the \func{num} or \func{round} functions. They |
| 7163 |
will use as many zeroes as necessary on output. |
| 7164 |
\begin{everbatim*} |
| 7165 |
% This illustrates output can only use pure integer notation: |
| 7166 |
\xinttheiiexpr num(1e80)\relax |
| 7167 |
\end{everbatim*} |
| 7168 |
\begin{everbatim*} |
| 7169 |
% This should (as num truncates) compute 13456+10000: |
| 7170 |
\xinttheiiexpr num(13.4567e3)+num(10000123e-3)\relax |
| 7171 |
\end{everbatim*} |
| 7172 |
\end{framed} |
| 7173 |
|
| 7174 |
|
| 7175 |
The |reduce| function is not available and will raise an error. The |frac| |
| 7176 |
function also. The |sqrt| function is mapped to \csbxint{iiSqrt} which gives |
| 7177 |
a truncated square root. The |sqrtr| function is mapped to \csbxint{iiSqrtR} |
| 7178 |
which gives a rounded square root. |
| 7179 |
|
| 7180 |
One can use the Float macros if one is careful to use |num|, or |round| |
| 7181 |
etc\dots on their output. |
| 7182 |
|
| 7183 |
\begin{everbatim*} |
| 7184 |
\xinttheiiexpr \xintFloatSqrt [20]{2}, |
| 7185 |
\xintFloatSqrt [20]{3}\relax % no operations |
| 7186 |
\end{everbatim*} |
| 7187 |
The above went through because no actual operations were carried out. But it |
| 7188 |
is dangerous because the ``printer'' for \csbxint{theiiexpr} could choke on |
| 7189 |
such values. By default however it does nothing. |
| 7190 |
|
| 7191 |
In the next example there will be an addition. So we firt apply |round| to |
| 7192 |
get integers (the second argument of |round| and |trunc| tells how many digits |
| 7193 |
from after the decimal mark one should keep.) |
| 7194 |
\begin{everbatim*} |
| 7195 |
\xinttheiiexpr round(\xintFloatSqrt [20]{2},19) + |
| 7196 |
round(\xintFloatSqrt [20]{3},19)\relax |
| 7197 |
\end{everbatim*} |
| 7198 |
|
| 7199 |
The whole point of \csbxint{iiexpr} is to gain some speed in |
| 7200 |
\emph{integer-only} algorithms, and the above explanations related to how to |
| 7201 |
nevertheless use fractions therein are a bit peripheral. We observed |
| 7202 |
(2013/12/18) of the order of $30$\% speed gain when dealing with numbers with |
| 7203 |
circa one hundred digits (1.2: this info may be obsolete). |
| 7204 |
|
| 7205 |
|
| 7206 |
\subsection{\csh{xintboolexpr}, \csh{xinttheboolexpr}} |
| 7207 |
\label{xintboolexpr}\label{xinttheboolexpr} |
| 7208 |
|
| 7209 |
Equivalent\etype{x} to doing |\xintexpr ...\relax| and returning |true| if the |
| 7210 |
result does not vanish, and |false| if the result is zero. As |\xintexpr|, this |
| 7211 |
can be used on comma separated lists of expressions, and even bracketed lists. |
| 7212 |
|
| 7213 |
It can be customized, one only needs to modify the following: |
| 7214 |
\begin{everbatim} |
| 7215 |
\def\xintboolexprPrintOne#1{\xintiiifNotZero{#1}{true}{talse}}% |
| 7216 |
\end{everbatim} |
| 7217 |
Not only are |true| and |false| usable in input, also |True| and |False| are |
| 7218 |
pre-declared variables. |
| 7219 |
|
| 7220 |
There is quirk in case it is used as a sub-expression: the boolean |
| 7221 |
expression needs at least one logic operation else the value is not |
| 7222 |
standardized to |1| or |0|, for example we get from |
| 7223 |
\begin{everbatim*} |
| 7224 |
\xinttheexpr \xintboolexpr 1.23\relax\relax\newline |
| 7225 |
\end{everbatim*}which is to be compared with |
| 7226 |
\begin{everbatim*} |
| 7227 |
\xinttheboolexpr 1.23\relax |
| 7228 |
\end{everbatim*} |
| 7229 |
|
| 7230 |
% A related issue existed with |
| 7231 |
% |\xinttheexpr \xintiexpr 1.23\relax\relax|, which was fixed with |1.1| |
| 7232 |
% release, and I decided back then not to add the needed overhead also to the |
| 7233 |
% |\xintboolexpr| context, as one only needs to use |?(1.23)| for example or |
| 7234 |
% involve the |1.23| in any logic operation like |1.23 'and' 3.45|, or involve |
| 7235 |
% the |\xintboolexpr ..\relax | itself with any logical operation, contrarily to |
| 7236 |
% the sub-|\xintiexpr| case where |\xinttheexpr 1+\xintiexpr 1.23\relax\relax| |
| 7237 |
% did behave contrarily to expectations until |1.1|. |
| 7238 |
|
| 7239 |
|
| 7240 |
\subsection{\csh{xintfloatexpr}, |
| 7241 |
\csh{xintthefloatexpr}} |
| 7242 |
\label{xintfloatexpr}\label{xintthefloatexpr} |
| 7243 |
|
| 7244 |
\csbxint{floatexpr}|...\relax|\etype{x} is a variant of |
| 7245 |
|\xintexpr...\relax| which does floating point operations. |
| 7246 |
|
| 7247 |
The target precision for the computation is from the |
| 7248 |
current setting of |\xintDigits|. Comma separated lists of expressions are |
| 7249 |
allowed. |
| 7250 |
|
| 7251 |
An optional parameter within brackets |[Q]| is allowed at the very start |
| 7252 |
of the expression: |
| 7253 |
\begin{itemize} |
| 7254 |
\item if positive it instructs the macro to round the result to that |
| 7255 |
many digits of precision. It thus makes sense to employ it only if |
| 7256 |
this parameter is less than the \csbxint{theDigits} precision. |
| 7257 |
\item if negative it means to trim off that many digits (of course, in |
| 7258 |
the sense of rounding the values to shorter mantissas). Don't use it |
| 7259 |
to trim all digits (or more than all)! |
| 7260 |
\end{itemize} |
| 7261 |
|
| 7262 |
Since |1.2f| all float operations first round their arguments; a parsed number |
| 7263 |
is not rounded prior to its use as operand to such a float operation. |
| 7264 |
|
| 7265 |
|\xintDigits:=36\relax|\xintDigits:=36\relax |
| 7266 |
% |
| 7267 |
\leftedline{|\xintthefloatexpr |
| 7268 |
(1/13+1/121)*(1/179-1/173)/(1/19-1/18)\relax|} |
| 7269 |
% |
| 7270 |
\leftedline{\dtt{\xintthefloatexpr |
| 7271 |
(1/13+1/121)*(1/179-1/173)/(1/19-1/18)\relax}} |
| 7272 |
% 0.00564487459334466559166166079096852897 |
| 7273 |
% |
| 7274 |
\leftedline{|\xintthefloatexpr\xintexpr |
| 7275 |
(1/13+1/121)*(1/179-1/173)/(1/19-1/18)\relax\relax|} |
| 7276 |
% |
| 7277 |
\leftedline{\dtt{\xintthefloatexpr\xintexpr |
| 7278 |
(1/13+1/121)*(1/179-1/173)/(1/19-1/18)\relax\relax}} |
| 7279 |
|
| 7280 |
\xintDigits := 16; |
| 7281 |
|
| 7282 |
The latter is the rounding of the exact result. The former one has |
| 7283 |
its last three digits wrong due to the cumulative effect of rounding errors |
| 7284 |
in the intermediate computations, as compared to exact evaluations. |
| 7285 |
|
| 7286 |
|
| 7287 |
|
| 7288 |
|
| 7289 |
I recall here from \autoref{ssec:floatingpoint} that with release |1.2f| the |
| 7290 |
float macros for addition, subtraction, multiplication and division round |
| 7291 |
their arguments first to |P| significant places with |P| the asked-for |
| 7292 |
precision of the output; and similarly the power macros and the |
| 7293 |
square root macro. This does not modify anything for computations with |
| 7294 |
arguments having at most |P| significant places already. |
| 7295 |
|
| 7296 |
\begin{framed} |
| 7297 |
When defining a macro doing something such as |\xintfloatexpr #1\relax|, |
| 7298 |
it is recommended to rather use |\xintfloatexpr\empty #1\relax|, as the |
| 7299 |
|#1| may start with a |[| which without the |\empty| would be |
| 7300 |
interpreted by |\xintfloatexpr| as the start of the optional |[Q]|. |
| 7301 |
\end{framed} |
| 7302 |
|
| 7303 |
\subsection{\csh{xinteval}, \csh{xintieval}, \csh{xintiieval}, |
| 7304 |
\csh{xintfloateval}} |
| 7305 |
\label{xinteval}\label{xintieval}\label{xintiieval}\label{xintfloateval} |
| 7306 |
|
| 7307 |
\csbxint{eval}\etype{x} is an \fexpan dable macro which is basically |
| 7308 |
defined in such a way that |\xinteval|\marg{expression} behaves like |
| 7309 |
\csbxint{theexpr}\marg{expression}|\relax|. It expands completely in |
| 7310 |
two steps and delivers its output using digits, the dot |.| as decimal |
| 7311 |
separator, the letter |e| for scientific notation, the slash |/| for |
| 7312 |
fractions, as well as commas in case of multi-items expression and |
| 7313 |
square brackets |[| and |]| for nesting. |
| 7314 |
|
| 7315 |
\csbxint{ieval}\etype{x} is similarly related to \csbxint{theiexpr}. It |
| 7316 |
admits an optional argument |[D]| which may be located in the expected |
| 7317 |
location from conventions of \LaTeX2e macros with optional argument, but |
| 7318 |
had been long constrained (until |1.4k|) to be inside the braces at the |
| 7319 |
start of the expression. |
| 7320 |
\begin{everbatim*} |
| 7321 |
\xintieval[7]{355/113} = \xintieval{[7]355/113} |
| 7322 |
\end{everbatim*} |
| 7323 |
\begin{framed} |
| 7324 |
When defining a macro doing something such as |\xintieval{#1}|, |
| 7325 |
it is recommended to rather use |\xintieval{\empty #1}|, as the |
| 7326 |
|#1| may start with a |[| which without the |\empty| would be |
| 7327 |
interpreted by |\xintieval| as the start of the optional |[D]|. |
| 7328 |
\end{framed} |
| 7329 |
|
| 7330 |
\csbxint{iieval}\etype{x} is similarly related to \csbxint{theiiexpr}. |
| 7331 |
% \begin{everbatim*} |
| 7332 |
% \xintiieval{add(x^2, x = 100..110), add(x^3, x = 100..110)} |
| 7333 |
% \end{everbatim*} |
| 7334 |
|
| 7335 |
\csbxint{floateval}\etype{x} is similarly related to |
| 7336 |
\csbxint{thefloatexpr}. It admits an optional argument |[Q]| which |
| 7337 |
may be located either outside (since |1.4k|) or inside the braces. |
| 7338 |
\begin{everbatim*} |
| 7339 |
\xintfloateval [7]{355/113} = \xintfloateval{[7] 355/113} |
| 7340 |
\end{everbatim*} |
| 7341 |
|
| 7342 |
When negative, the optional argument tells how many digits to remove |
| 7343 |
from the prevailing precision: |
| 7344 |
\begin{everbatim*} |
| 7345 |
\xintfloateval[-2]{355/113}= |
| 7346 |
\xintfloateval{[-2]355/113} has \xinttheDigits\ minus 2 digits. |
| 7347 |
\end{everbatim*} |
| 7348 |
|
| 7349 |
\begin{framed} |
| 7350 |
When defining a macro doing something such as |\xintfloateval{#1}|, |
| 7351 |
it is recommended to rather use |\xintfloateval{\empty #1}|, as the |
| 7352 |
|#1| may start with a |[| which without the |\empty| would be |
| 7353 |
interpreted by |\xintfloateval| as the start of the optional |[Q]|. |
| 7354 |
\end{framed} |
| 7355 |
|
| 7356 |
|
| 7357 |
\subsection{Using an expression parser within another one} |
| 7358 |
|
| 7359 |
This was already illustrated before. In the following: |
| 7360 |
\begin{everbatim*} |
| 7361 |
\xintfloatexpr \xintexpr add(1/i, i=1234..1243)\relax ^100\relax |
| 7362 |
\end{everbatim*}, |
| 7363 |
the inner sum is computed exactly. Then it will be rounded to |\xinttheDigits| |
| 7364 |
significant digits, and then its power will be evaluated as a float operation. |
| 7365 |
One should avoid the "|\xintthe|" parsers in inner positions as this induces |
| 7366 |
digit by digit parsing of the inner computation result by the outer parser. |
| 7367 |
Here is the same computation done with floats all the way: |
| 7368 |
\begin{everbatim*} |
| 7369 |
\xintfloatexpr add(1/i, i=1234..1243)^100\relax |
| 7370 |
\end{everbatim*} |
| 7371 |
|
| 7372 |
Not surprisingly this differs from the previous one which was exact until |
| 7373 |
raising to the |100|th power. |
| 7374 |
|
| 7375 |
The fact that the inner expression occurs inside a bigger one has nil |
| 7376 |
influence on its behaviour. There is the limitation though that the outputs |
| 7377 |
from \csbxint{expr} and \csbxint{floatexpr} can not be used directly in |
| 7378 |
\csbxint{theiiexpr} integer-only parser. But one can do: |
| 7379 |
\begin{everbatim*} |
| 7380 |
\xintiiexpr round(\xintfloatexpr 3.14^10\relax)\relax % or trunc |
| 7381 |
\end{everbatim*} |
| 7382 |
|
| 7383 |
|
| 7384 |
\subsection{The \csh{xintthecoords} macro} |
| 7385 |
\label{xintthecoords} |
| 7386 |
|
| 7387 |
It converts (in two expansion steps) the expansion result of |
| 7388 |
\csbxint{floatexpr} (or \csbxint{expr} or \csbxint{iiexpr}) into the |(a, b) |
| 7389 |
(c, d) ...| format for list of coordinates as expected by the |TikZ| |
| 7390 |
|coordinates| syntax.% |
| 7391 |
\begin{everbatim*} |
| 7392 |
\begin{figure}[htbp] |
| 7393 |
\centering\begin{tikzpicture}[scale=10]\xintDigits:=8\relax |
| 7394 |
\clip (-1.1,-.25) rectangle (.3,.25); |
| 7395 |
\draw [blue] (-1.1,0)--(1,0); |
| 7396 |
\draw [blue] (0,-1)--(0,+1); |
| 7397 |
\draw [red] plot[smooth] coordinates {% |
| 7398 |
%%% \xintthecoords converts output of next expression into the |
| 7399 |
%%% (x1, y1) (x2, y2) ... |
| 7400 |
%%% format |
| 7401 |
\xintthecoords\xintfloatexpr |
| 7402 |
%%% This syntax -1+[0..4]/2 is currenty dropped at xint 1.4 |
| 7403 |
%%% seq((x^2-1,mul(x-t,t=-1+[0..4]/2)),x=-1.2..[0.1]..+1.2)\relax |
| 7404 |
%%% Use this: |
| 7405 |
seq((x^2-1,mul(x-t,t=seq(-1+u/2, u=0..4))),x=-1.2..[0.1]..+1.2) |
| 7406 |
\relax |
| 7407 |
}; |
| 7408 |
\end{tikzpicture} |
| 7409 |
\caption{Coordinates with \csbxint{thecoords}.} |
| 7410 |
\end{figure} |
| 7411 |
\end{everbatim*} |
| 7412 |
|
| 7413 |
% Notice: if x goes not take exactly value 1 or -1, the origin appears slightly |
| 7414 |
% off the curve, not MY fault!!! |
| 7415 |
It is currently undecided how \csa{xintthecoords} should handle bracketed |
| 7416 |
data.\UNSTABLE{} Currently, it (or |TikZ|) will break it the input contains |
| 7417 |
nested structures. One can use it with \func{flat} which removes all nesting. |
| 7418 |
And in combination with \func{zip} it is easy to plot data given by some |
| 7419 |
mechanism in separate |
| 7420 |
lists of x- and y-coordinates (see an example in next section) |
| 7421 |
|
| 7422 |
\subsection{The \csh{xintthespaceseparated} macro} |
| 7423 |
\label{xintthespaceseparated} |
| 7424 |
|
| 7425 |
It converts (in two expansion steps) the expansion result of |
| 7426 |
\csbxint{floatexpr} (or \csbxint{expr} or \csbxint{iiexpr}) into the space |
| 7427 |
separated format suitable for usage with |PS-Tricks| |\listplot| macro. |
| 7428 |
|
| 7429 |
Here is for example some syntax (the replacement text of |\foo|, which is used |
| 7430 |
here only to show that indeed complete expansion is attained in two steps) |
| 7431 |
which can be used as argument to |\listplot|. Using 4 fractional decimal |
| 7432 |
digits is sufficient when unit is the centimeter (it gives a fixed point |
| 7433 |
precision of one micron, amply enough for plots...). |
| 7434 |
\begin{everbatim*} |
| 7435 |
\oodef\foo{% |
| 7436 |
\xintthespaceseparated |
| 7437 |
\xintiexpr[4]\xintfloatexpr seq((i, log10(i)), i=1..[0.5]..10)\relax\relax |
| 7438 |
}\meaning\foo |
| 7439 |
\end{everbatim*} |
| 7440 |
|
| 7441 |
Here we don't really need the inner |\xintfloatexpr...\relax| because the |
| 7442 |
\func{log10} function works the same in the exact parser |\xintexpr| but in |
| 7443 |
general this is recommended. |
| 7444 |
|
| 7445 |
It is currently undecided how \csa{xintthespaceseparated} should handle |
| 7446 |
bracketed data.\UNSTABLE{} Currently, it (or |\listplot|) will break if the |
| 7447 |
input contains nested structures. One can use it with \func{flat} which |
| 7448 |
removes all nesting. And in combination with \func{zip} it is easy to plot |
| 7449 |
data given by some mechanism in separate lists of x- and y-coordinates. |
| 7450 |
|
| 7451 |
\begin{everbatim*} |
| 7452 |
% let's imagine we have something like this |
| 7453 |
\def\Xcoordinates{1, 3, 5, 7, 9} |
| 7454 |
\def\Ycoordinates{1, 9, 25, 49, 81} |
| 7455 |
% then: |
| 7456 |
|\xintthespaceseparated\xintexpr flat(zip([\Xcoordinates], [\Ycoordinates]))\relax| |
| 7457 |
is suitable to use as argument to |\listplot|, as it expands to |
| 7458 |
\xintthespaceseparated\xintexpr flat(zip([\Xcoordinates], [\Ycoordinates]))\relax |
| 7459 |
\end{everbatim*} |
| 7460 |
|
| 7461 |
\subsection{\csh{xintifboolexpr}, \csh{xintifboolfloatexpr}, \csh{xintifbooliiexpr}} |
| 7462 |
\label{xintifboolexpr} |
| 7463 |
\label{xintifboolfloatexpr} |
| 7464 |
\label{xintifbooliiexpr} |
| 7465 |
|
| 7466 |
\csa{xintifboolexpr}\marg{expr}\marg{YES}\marg{NO}\etype{xnn} does |
| 7467 |
\csbxint{theexpr}<expr>|\relax| and then executes the \meta{YES} or the |
| 7468 |
\meta{NO} branch depending on whether the outcome was non-zero or zero. Thus |
| 7469 |
one can read \emph{if bool expr} as meaning \emph{if not zero}: |
| 7470 |
\centeredline{if \meta{expr}-ession does not vanish do \meta{YES} else do |
| 7471 |
\meta{NO}} |
| 7472 |
|
| 7473 |
The expression is not limited to using only comparison operators and Boolean |
| 7474 |
logic (|<|, |>|, |==|, |!=|, |&&|, \verb+||+, \func{all}, \func{any}, |
| 7475 |
\func{xor}, \func{bool}, \func{togl}, ...), it can be the most general |
| 7476 |
computation. |
| 7477 |
|
| 7478 |
\csa{xintifboolfloatexpr}\marg{expr}\marg{YES}\marg{NO}\etype{xnn} does |
| 7479 |
\csbxint{thefloatexpr}\meta{expr}|\relax| and then executes the \meta{YES} or the |
| 7480 |
\meta{NO} branch depending on whether the outcome was non zero or zero. |
| 7481 |
|
| 7482 |
\csa{xintifbooliiexpr}\marg{expr}\marg{YES}\marg{NO}\etype{xnn} does |
| 7483 |
\csbxint{theiiexpr}\meta{expr}|\relax| and then executes the \meta{YES} or the |
| 7484 |
\meta{NO} branch depending on whether the outcome was non zero or zero. |
| 7485 |
|
| 7486 |
The expression argument must be a single one, comma separated sub-expressions |
| 7487 |
will cause low-level errors. |
| 7488 |
|
| 7489 |
\subsection{\csh{xintifsgnexpr}, \csh{xintifsgnfloatexpr}, \csh{xintifsgniiexpr}} |
| 7490 |
\label{xintifsgnexpr} |
| 7491 |
\label{xintifsgnfloatexpr} |
| 7492 |
\label{xintifsgniiexpr} |
| 7493 |
|
| 7494 |
\csa{xintifsgnexpr}\marg{expr}\marg{<0}\marg{=0}\marg{>0}\etype{xnnn} evaluates |
| 7495 |
the \csbxint{expr}ession and chooses the branch corresponding to its sign. |
| 7496 |
|
| 7497 |
\csa{xintifsgnfloatexpr}\marg{expr}\marg{<0}\marg{=0}\marg{>0}\etype{xnnn} evaluates |
| 7498 |
the \csbxint{floatexpr}ession and chooses the branch corresponding to its sign. |
| 7499 |
|
| 7500 |
\csa{xintifsgniiexpr}\marg{expr}\marg{<0}\marg{=0}\marg{>0}\etype{xnnn} evaluates |
| 7501 |
the \csbxint{iiexpr}ession and chooses the branch corresponding to its sign. |
| 7502 |
|
| 7503 |
The expression argument must be a single one, comma separated sub-expressions |
| 7504 |
will cause low-level errors. |
| 7505 |
|
| 7506 |
\subsection{The \csh{xintNewExpr}, \csh{xintNewIIExpr}, |
| 7507 |
\csh{xintNewFloatExpr}, \csh{xintNewIExpr}, and \csh{xintNewBoolExpr} |
| 7508 |
macros} |
| 7509 |
\label{xintNewExpr} |
| 7510 |
\label{xintNewIIExpr} |
| 7511 |
\label{xintNewFloatExpr} |
| 7512 |
\label{xintNewIExpr} |
| 7513 |
\label{xintNewBoolExpr} |
| 7514 |
|
| 7515 |
\csbxint{NewExpr} macro is used as: |
| 7516 |
% |
| 7517 |
\leftedline{|\xintNewExpr{\myformula}[n]|\marg{stuff}, where} |
| 7518 |
\begin{itemize} |
| 7519 |
\item \meta{stuff} will be inserted inside |\xinttheexpr . . . \relax|, |
| 7520 |
\item |n| is an integer between zero and nine, inclusive, which is the number |
| 7521 |
of parameters of |\myformula|, |
| 7522 |
\item the placeholders |#1|, |#2|, ..., |#n| are used inside \meta{stuff} in |
| 7523 |
their usual r\^ole,% |
| 7524 |
% |
| 7525 |
\catcode`# 12 |
| 7526 |
\footnote{if \csa{xintNewExpr} is used inside a macro, |
| 7527 |
the |#|'s must be doubled as usual.} |
| 7528 |
\footnote{the |#|'s will in pratice have their usual |
| 7529 |
catcode, but category code other |#|'s are accepted too.} |
| 7530 |
\catcode`# 6 |
| 7531 |
% |
| 7532 |
\item the |[n]| is \emph{mandatory}, even for |n=0|.% |
| 7533 |
\footnote{there is some use for \csa{xintNewExpr}|[0]| compared to an |
| 7534 |
\csa{edef} as \csa{xintNewExpr} has some built-in catcode protection.} |
| 7535 |
\item the macro |\myformula| is defined without checking if it already exists, |
| 7536 |
\LaTeX{} users might prefer to do first |\newcommand*\myformula {}| to get a |
| 7537 |
reasonable error message in case |\myformula| already exists, |
| 7538 |
\item the protection against active characters is done automatically (as long |
| 7539 |
as the whole thing has not already been fetched as a macro argument and |
| 7540 |
the catcodes correspondingly already frozen). |
| 7541 |
\end{itemize} |
| 7542 |
|
| 7543 |
It (if it succeeds) will be a completely expandable macro entirely built-up using |\xintAdd|, |
| 7544 |
|\xintSub|, |\xintMul|, |\xintDiv|, |\xintPow|, etc\dots as corresponds to the |
| 7545 |
expression written with the infix operators. |
| 7546 |
Macros created by |\xintNewExpr| can thus be nested. |
| 7547 |
|
| 7548 |
\begin{everbatim*} |
| 7549 |
\xintNewFloatExpr \FA [2]{(#1+#2)^10} |
| 7550 |
\xintNewFloatExpr \FB [2]{sqrt(#1*#2)} |
| 7551 |
\begin{enumerate}[nosep] |
| 7552 |
\item \FA {5}{5} |
| 7553 |
\item \FB {30}{10} |
| 7554 |
\item \FA {\FB {30}{10}}{\FB {40}{20}} |
| 7555 |
\end{enumerate} |
| 7556 |
\end{everbatim*} |
| 7557 |
|
| 7558 |
The documentation is much shortened here because \csbxint{NewExpr} and \csbxint{deffunc} |
| 7559 |
are very much related one with the other. |
| 7560 |
|
| 7561 |
\begin{framed} |
| 7562 |
ATTENTION! |
| 7563 |
|
| 7564 |
The original spirit of \csbxint{NewExpr} was to define a (possibly very big) |
| 7565 |
macro using only \xintfracname, and this means in particular that it must be |
| 7566 |
used only with arguments compatible with the \xintfracname input |
| 7567 |
format.\IMPORTANTf |
| 7568 |
|
| 7569 |
Thus an |\xintexpr| declared variable has no chance to work, it must be |
| 7570 |
wrapped explicitly in |\xinteval{...}| to be fetched as argument to a macro |
| 7571 |
constructed by \csbxint{NewExpr}. |
| 7572 |
\end{framed} |
| 7573 |
|
| 7574 |
They share essentially the same limitations. |
| 7575 |
|
| 7576 |
Notice though that \csbxint{NewFloatExpr} accepts and recognizes the optional |
| 7577 |
argument |[Q]| of \csbxint{floatexpr}, contrarily to \csbxint{deffloatfunc}. |
| 7578 |
Use an |\empty| in case the contents are not known in advance. |
| 7579 |
|
| 7580 |
|
| 7581 |
Historical note: prior to |1.4|, \xintexprname used a |\csname..\endcsname| |
| 7582 |
encapsulation technique which impacted the string pool memory. The |
| 7583 |
\csbxint{NewExpr} was designed as a method to pre-parse the expression and |
| 7584 |
produce one single, gigantic, nested usage of the relevant \xintfracname |
| 7585 |
macros. This way, only those macros were expanded which had nil impact on the |
| 7586 |
\TeX{} string pool. |
| 7587 |
|
| 7588 |
Later on it was found that this mechanism could be employed to define |
| 7589 |
functions. Basically underneath |98%| of \csbxint{NewExpr} and |
| 7590 |
\csbxint{deffunc} are using the same shared code. |
| 7591 |
|
| 7592 |
\xintDigits:= 16\relax |
| 7593 |
|
| 7594 |
\subsection{Analogies and differences of \csh{xintiiexpr} with \csh{numexpr}} |
| 7595 |
|
| 7596 |
\csbxint{iiexpr}|..\relax| is a parser of expressions knowing only (big) |
| 7597 |
integers. There are, besides the enlarged range of allowable inputs, some |
| 7598 |
important differences of syntax between |\numexpr| and |\xintiiexpr| and |
| 7599 |
variants: |
| 7600 |
\begin{itemize} |
| 7601 |
\item Contrarily to |\numexpr|, the |\xintiiexpr| parser will stop expanding |
| 7602 |
only after having encountered (and swallowed) a \emph{mandatory} |\relax| |
| 7603 |
token. |
| 7604 |
\item In particular, spaces between digits (and not only around infix |
| 7605 |
operators or parentheses) do not stop |\xintiiexpr|, contrarily to the |
| 7606 |
situation with |numexpr|: |\the\numexpr 7 + 3 5\relax| expands (in one |
| 7607 |
step)% |
| 7608 |
% |
| 7609 |
\footnote {The |\numexpr| triggers continued expansion after the space |
| 7610 |
following the |3| to check if some operator like |+| is upstream. But |
| 7611 |
after having found the |5| it treats it as and end-marker.} |
| 7612 |
% |
| 7613 |
to \dtt{\detokenize\expandafter{\the\numexpr 7 + 3 5\relax}\unskip}, whereas |
| 7614 |
|\xintthe\xintiiexpr 7 + 3 5\relax| expands (in two steps) to |
| 7615 |
\dtt{\detokenize\expandafter\expandafter\expandafter {\xintthe\xintiiexpr 7 |
| 7616 |
+ 3 5\relax}}.% |
| 7617 |
% |
| 7618 |
\footnote {Since |1.2l| one can also use the underscore |_| to separate digits |
| 7619 |
for readability of long numbers.} |
| 7620 |
|
| 7621 |
\item Inside an |\edef|, an expression |\xintiiexpr...\relax| get fully |
| 7622 |
evaluated, whereas |\numexpr| without |\the| or |\number| prefix would not, |
| 7623 |
if not itself embedded in another |\the\numexpr| or similar context. |
| 7624 |
\item (ctd.) The private format to which |\xintiiexpr...\relax| (et al.) |
| 7625 |
evaluates may use |\xintthe| prefix to turn into explicit digits, |
| 7626 |
(for example in arguments to some macros which expand their arguments). The |\the| \TeX\ primitive prefix would |
| 7627 |
not work here. |
| 7628 |
\item (ctd.) One can embed a |\numexpr...\relax| (with its |\relax|!) inside an |
| 7629 |
|\xintiiexpr...\relax| without |\the| or |\number|, but the reverse situation |
| 7630 |
requires usage of |\xintthe| or \csbxint{eval} user interface, |
| 7631 |
\item |\the\numexpr -(1)\relax| is illegal. In contrast |\xinttheiiexpr -(1)\relax| is |
| 7632 |
perfectly legal and gives the expected result (what else ?). |
| 7633 |
\item |\the\numexpr 2+-(1+1)\relax| is illegal. In contrast |
| 7634 |
|\xinttheiiexpr 2+-(1+1)\relax| is legal. |
| 7635 |
\item |\the\numexpr 2\cnta\relax| is illegal (with |\cnta| a |\count| register.) |
| 7636 |
In contrast |
| 7637 |
|\xinttheiiexpr 2\cnta\relax| is perfectly legal and will do the tacit |
| 7638 |
multiplication. |
| 7639 |
\item |\the\numexpr| or |\number\numexpr| expands in one step, but |
| 7640 |
|\xintthe\xintiiexpr| or |\xinttheiiexpr| needs two steps. |
| 7641 |
\end{itemize} |
| 7642 |
|
| 7643 |
\subsection{Chaining expressions for expandable algorithmics} |
| 7644 |
\label{ssec:fibonacci} |
| 7645 |
|
| 7646 |
We will see in this section how to chain |\xintexpr|-essions with |
| 7647 |
|\expandafter|'s, like it is possible with |\numexpr|. For this it is |
| 7648 |
convenient to use |\romannumeral0\xintexpro| which is the once-expanded form of |
| 7649 |
|\xintexpr|, as we can then chain using only one |\expandafter| each time. |
| 7650 |
|
| 7651 |
For example, here is the code employed for the background of page 2. |
| 7652 |
It computes (expandably, of course!) the 1250th Fibonacci |
| 7653 |
number. |
| 7654 |
|
| 7655 |
\begin{everbatim*} |
| 7656 |
\catcode`_ 11 |
| 7657 |
\def\Fibonacci #1{% \Fibonacci{N} computes F(N) with F(0)=0, F(1)=1. |
| 7658 |
\expandafter\Fibonacci_a\expandafter |
| 7659 |
{\the\numexpr #1\expandafter}\expandafter |
| 7660 |
{\romannumeral0\xintiiexpro 1\expandafter\relax\expandafter}\expandafter |
| 7661 |
{\romannumeral0\xintiiexpro 1\expandafter\relax\expandafter}\expandafter |
| 7662 |
{\romannumeral0\xintiiexpro 1\expandafter\relax\expandafter}\expandafter |
| 7663 |
{\romannumeral0\xintiiexpro 0\relax}} |
| 7664 |
% |
| 7665 |
\def\Fibonacci_a #1{% |
| 7666 |
\ifcase #1 |
| 7667 |
\expandafter\Fibonacci_end_i |
| 7668 |
\or |
| 7669 |
\expandafter\Fibonacci_end_ii |
| 7670 |
\else |
| 7671 |
\ifodd #1 |
| 7672 |
\expandafter\expandafter\expandafter\Fibonacci_b_ii |
| 7673 |
\else |
| 7674 |
\expandafter\expandafter\expandafter\Fibonacci_b_i |
| 7675 |
\fi |
| 7676 |
\fi {#1}% |
| 7677 |
}% * signs are omitted from the next macros, tacit multiplications |
| 7678 |
\def\Fibonacci_b_i #1#2#3{\expandafter\Fibonacci_a\expandafter |
| 7679 |
{\the\numexpr #1/2\expandafter}\expandafter |
| 7680 |
{\romannumeral0\xintiiexpro sqr(#2)+sqr(#3)\expandafter\relax |
| 7681 |
\expandafter}\expandafter |
| 7682 |
{\romannumeral0\xintiiexpro (2#2-#3)#3\relax}% |
| 7683 |
}% end of Fibonacci_b_i |
| 7684 |
\def\Fibonacci_b_ii #1#2#3#4#5{\expandafter\Fibonacci_a\expandafter |
| 7685 |
{\the\numexpr (#1-1)/2\expandafter}\expandafter |
| 7686 |
{\romannumeral0\xintiiexpro sqr(#2)+sqr(#3)\expandafter\relax |
| 7687 |
\expandafter}\expandafter |
| 7688 |
{\romannumeral0\xintiiexpro (2#2-#3)#3\expandafter\relax\expandafter}\expandafter |
| 7689 |
{\romannumeral0\xintiiexpro #2#4+#3#5\expandafter\relax\expandafter}\expandafter |
| 7690 |
{\romannumeral0\xintiiexpro #2#5+#3(#4-#5)\relax}% |
| 7691 |
}% end of Fibonacci_b_ii |
| 7692 |
% code as used on title page: |
| 7693 |
%\def\Fibonacci_end_i #1#2#3#4#5{\xintthe#5} |
| 7694 |
%\def\Fibonacci_end_ii #1#2#3#4#5{\xinttheiiexpr #2#5+#3(#4-#5)\relax} |
| 7695 |
% new definitions: |
| 7696 |
\def\Fibonacci_end_i #1#2#3#4#5{{#4}{#5}}% {F(N+1)}{F(N)} in \xintexpr format |
| 7697 |
\def\Fibonacci_end_ii #1#2#3#4#5% |
| 7698 |
{\expandafter |
| 7699 |
{\romannumeral0\xintiiexpro #2#4+#3#5\expandafter\relax |
| 7700 |
\expandafter}\expandafter |
| 7701 |
{\romannumeral0\xintiiexpro #2#5+#3(#4-#5)\relax}}% idem. |
| 7702 |
% \FibonacciN returns F(N) (in encapsulated format: needs \xintthe for printing) |
| 7703 |
\def\FibonacciN {\expandafter\xint_secondoftwo\romannumeral-`0\Fibonacci }% |
| 7704 |
\catcode`_ 8 |
| 7705 |
\end{everbatim*} |
| 7706 |
|
| 7707 |
|
| 7708 |
The macro |\Fibonacci| produces not one specific value |F(N)| but a pair of |
| 7709 |
successive values |{F(N)}{F(N+1)}| which can then serve as starting point of |
| 7710 |
another routine devoted to compute a whole sequence |F(N), F(N+1), |
| 7711 |
F(N+2),....|. Each of |F(N)| and |F(N+1)| is kept in the encapsulated internal |
| 7712 |
\xintexprname format. |
| 7713 |
|
| 7714 |
|\FibonacciN| produces the single |F(N)|. It also keeps it in the private |
| 7715 |
format; thus printing it will need the |\xintthe| prefix. |
| 7716 |
|
| 7717 |
\begingroup\footnotesize\sffamily\baselineskip 10pt |
| 7718 |
Here a code snippet which |
| 7719 |
checks the routine via a \string\message\ of the first $51$ Fibonacci |
| 7720 |
numbers (this is not an efficient way to generate a sequence of such |
| 7721 |
numbers, it is only for validating \csa{FibonacciN}). |
| 7722 |
% |
| 7723 |
\begin{everbatim} |
| 7724 |
\def\Fibo #1.{\xintthe\FibonacciN {#1}}% |
| 7725 |
\message{\xintiloop [0+1] \expandafter\Fibo\xintiloopindex., |
| 7726 |
\ifnum\xintiloopindex<49 \repeat \xintthe\FibonacciN{50}.} |
| 7727 |
\end{everbatim} |
| 7728 |
\endgroup |
| 7729 |
|
| 7730 |
The way we use |\expandafter|'s to chain successive |\xintiiexpro| evaluations |
| 7731 |
is exactly analogous to what is possible with |\numexpr|. The various |
| 7732 |
|\romannumeral0\xintiiexpro| could very well all have been |\xintiiexpr|'s but |
| 7733 |
then we would have needed |\expandafter\expandafter\expandafter| each |
| 7734 |
time. |
| 7735 |
|
| 7736 |
\begin{framed} |
| 7737 |
There is a difference though: |\numexpr| does \emph{NOT} expand inside an |
| 7738 |
|\edef|, and to force its expansion we must prefix it with |\the| or |
| 7739 |
|\number| or |\romannumeral| or another |\numexpr| which is itself prefixed, |
| 7740 |
etc\dots. |
| 7741 |
|
| 7742 |
But |\xintexpr|, |\xintiexpr|, ..., expand fully in an |\edef|, with the |
| 7743 |
completely expanded |
| 7744 |
result encapsulated in a private format. |
| 7745 |
|
| 7746 |
Using |\xintthe| as prefix is necessary to print the result (like |\the| or |
| 7747 |
|\number| in the case of |\numexpr|), but it is not necessary to get the |
| 7748 |
computation done (contrarily to the situation with |\numexpr|). |
| 7749 |
\end{framed} |
| 7750 |
|
| 7751 |
|
| 7752 |
Our |\Fibonacci| expands completely under \fexpan sion, so we can use |
| 7753 |
\hyperref[fdef]{\ttfamily\char92fdef} rather than |\edef| in a situation such |
| 7754 |
as |
| 7755 |
% |
| 7756 |
\leftedline {|\fdef \X {\FibonacciN {100}}|\;,} |
| 7757 |
% |
| 7758 |
but it is usually about as efficient to employ |\edef|. And if we want |
| 7759 |
% |
| 7760 |
\leftedline{|\edef \Y {(\FibonacciN{100},\FibonacciN{200})}|\;,} |
| 7761 |
% |
| 7762 |
then |\edef| is necessary. |
| 7763 |
|
| 7764 |
Allright, so let's now give the code to generate |{F(N)}{F(N+1)}{F(N+2)}...|, |
| 7765 |
using |\Fibonacci| for the first two and then using the standard recursion |
| 7766 |
|F(N+2)=F(N+1)+F(N)|: |
| 7767 |
|
| 7768 |
\catcode`_ 11 |
| 7769 |
\def\FibonacciSeq #1#2{%#1=starting index, #2>#1=ending index |
| 7770 |
\expandafter\Fibonacci_Seq\expandafter |
| 7771 |
{\the\numexpr #1\expandafter}\expandafter{\the\numexpr #2-1}% |
| 7772 |
}% |
| 7773 |
\def\Fibonacci_Seq #1#2{% |
| 7774 |
\expandafter\Fibonacci_Seq_loop\expandafter |
| 7775 |
{\the\numexpr #1\expandafter}\romannumeral0\Fibonacci {#1}{#2}% |
| 7776 |
}% |
| 7777 |
\def\Fibonacci_Seq_loop #1#2#3#4{% standard Fibonacci recursion |
| 7778 |
{#3}\unless\ifnum #1<#4 \Fibonacci_Seq_end\fi |
| 7779 |
\expandafter\Fibonacci_Seq_loop\expandafter |
| 7780 |
{\the\numexpr #1+1\expandafter}\expandafter |
| 7781 |
{\romannumeral0\xintiiexpro #2+#3\relax}{#2}{#4}% |
| 7782 |
}% |
| 7783 |
\def\Fibonacci_Seq_end\fi\expandafter\Fibonacci_Seq_loop\expandafter |
| 7784 |
#1\expandafter #2#3#4{\fi {#3}}% |
| 7785 |
\catcode`_ 8 |
| 7786 |
|
| 7787 |
\begingroup |
| 7788 |
\everb|@ |
| 7789 |
\catcode`_ 11 |
| 7790 |
\def\FibonacciSeq #1#2{%#1=starting index, #2>#1=ending index |
| 7791 |
\expandafter\Fibonacci_Seq\expandafter |
| 7792 |
{\the\numexpr #1\expandafter}\expandafter{\the\numexpr #2-1}% |
| 7793 |
}% |
| 7794 |
\def\Fibonacci_Seq #1#2{% |
| 7795 |
\expandafter\Fibonacci_Seq_loop\expandafter |
| 7796 |
{\the\numexpr #1\expandafter}\romannumeral0\Fibonacci {#1}{#2}% |
| 7797 |
}% |
| 7798 |
\def\Fibonacci_Seq_loop #1#2#3#4{% standard Fibonacci recursion |
| 7799 |
{#3}\unless\ifnum #1<#4 \Fibonacci_Seq_end\fi |
| 7800 |
\expandafter\Fibonacci_Seq_loop\expandafter |
| 7801 |
{\the\numexpr #1+1\expandafter}\expandafter |
| 7802 |
{\romannumeral0\xintiiexpro #2+#3\relax}{#2}{#4}% |
| 7803 |
}% |
| 7804 |
\def\Fibonacci_Seq_end\fi\expandafter\Fibonacci_Seq_loop\expandafter |
| 7805 |
#1\expandafter #2#3#4{\fi {#3}}% |
| 7806 |
\catcode`_ 8 |
| 7807 |
| |
| 7808 |
\endgroup |
| 7809 |
|
| 7810 |
This |\FibonacciSeq| macro is |
| 7811 |
completely expandable but it is not \fexpan dable. |
| 7812 |
|
| 7813 |
This is not a problem in the next example which uses \csbxint{For*} as the |
| 7814 |
latter applies repeatedly full expansion to what comes next each time it |
| 7815 |
fetches an item from its list argument. Thus \csbxint{For*} still manages to |
| 7816 |
generate the list via iterated full expansion. |
| 7817 |
|
| 7818 |
|
| 7819 |
\begin{figure*}[ht!] |
| 7820 |
\phantomsection\label{fibonacci} |
| 7821 |
\newcounter{myindex} |
| 7822 |
\fdef\Fibxxx{\FibonacciN {30}}% |
| 7823 |
\setcounter{myindex}{30}% |
| 7824 |
\centeredline{\tabskip 1ex |
| 7825 |
\vbox{\halign{\bfseries#.\hfil&#\hfil &\hfil #\cr |
| 7826 |
\xintFor* #1 in {\FibonacciSeq {30}{59}}\do |
| 7827 |
{\themyindex &\xintthe#1 & |
| 7828 |
\xintiiRem{\xintthe#1}{\xintthe\Fibxxx}\stepcounter{myindex}\cr }}% |
| 7829 |
}\vrule |
| 7830 |
\vbox{\halign{\bfseries#.\hfil&#\hfil &\hfil #\cr |
| 7831 |
\xintFor* #1 in {\FibonacciSeq {60}{89}}\do |
| 7832 |
{\themyindex &\xintthe#1 & |
| 7833 |
\xintiiRem{\xintthe#1}{\xintthe\Fibxxx}\stepcounter{myindex}\cr }}% |
| 7834 |
}\vrule |
| 7835 |
\vbox{\halign{\bfseries#.\hfil&#\hfil &\hfil #\cr |
| 7836 |
\xintFor* #1 in {\FibonacciSeq {90}{119}}\do |
| 7837 |
{\themyindex &\xintthe#1 & |
| 7838 |
\xintiiRem{\xintthe#1}{\xintthe\Fibxxx}\stepcounter{myindex}\cr }}% |
| 7839 |
}}% |
| 7840 |
% |
| 7841 |
\centeredline{Some Fibonacci numbers together with their residues modulo |
| 7842 |
|F(30)|\dtt{=\xintthe\Fibxxx}} |
| 7843 |
\end{figure*} |
| 7844 |
|
| 7845 |
\begingroup |
| 7846 |
\def\everbhook{\catcode`@ 14 }% |
| 7847 |
% à propos après donc de nombreuses années j'ai fait finalement |
| 7848 |
% un bug report https://github.com/latex3/latex2e/issues/823 |
| 7849 |
\everb|@ |
| 7850 |
\newcounter{myindex}% not "index", which would overwrite theindex environment! |
| 7851 |
% (many have probably been bitten by this trap) |
| 7852 |
\tabskip 1ex |
| 7853 |
\fdef\Fibxxx{\FibonacciN {30}}% |
| 7854 |
\setcounter{myindex}{30}% |
| 7855 |
\vbox{\halign{\bfseries#.\hfil&#\hfil &\hfil #\cr |
| 7856 |
\xintFor* #1 in {\FibonacciSeq {30}{59}}\do |
| 7857 |
{\themyindex &\xintthe#1 & |
| 7858 |
\xintiiRem{\xintthe#1}{\xintthe\Fibxxx}\stepcounter{myindex}\cr }}% |
| 7859 |
}\vrule |
| 7860 |
\vbox{\halign{\bfseries#.\hfil&#\hfil &\hfil #\cr |
| 7861 |
\xintFor* #1 in {\FibonacciSeq {60}{89}}\do |
| 7862 |
{\themyindex &\xintthe#1 & |
| 7863 |
\xintiiRem{\xintthe#1}{\xintthe\Fibxxx}\stepcounter{myindex}\cr }}% |
| 7864 |
}\vrule |
| 7865 |
\vbox{\halign{\bfseries#.\hfil&#\hfil &\hfil #\cr |
| 7866 |
\xintFor* #1 in {\FibonacciSeq {90}{119}}\do |
| 7867 |
{\themyindex &\xintthe#1 & |
| 7868 |
\xintiiRem{\xintthe#1}{\xintthe\Fibxxx}\stepcounter{myindex}\cr }}% |
| 7869 |
}% |
| 7870 |
| |
| 7871 |
\endgroup |
| 7872 |
|
| 7873 |
This produces the Fibonacci numbers from |F(30)| to |F(119)|, and |
| 7874 |
computes also all the |
| 7875 |
congruence classes modulo |F(30)|. The output has |
| 7876 |
been put in a \hyperref[fibonacci]{float}, which appears |
| 7877 |
\vpageref[above]{fibonacci}. I leave to the mathematically inclined |
| 7878 |
readers the task to explain the visible patterns\dots |;-)|. |
| 7879 |
|
| 7880 |
\subsection{When expandability is too much} |
| 7881 |
|
| 7882 |
Let's use the macros of \autoref{ssec:fibonacci} related to Fibonacci numbers. |
| 7883 |
Notice that the $47$th Fibonacci number is \dtt{\xintthe\FibonacciN {47}} thus |
| 7884 |
already too big for \TeX{} and \eTeX{}. |
| 7885 |
|
| 7886 |
|
| 7887 |
The |\FibonacciN| macro found in \autoref{ssec:fibonacci} is completely |
| 7888 |
expandable, it is even \fexpan dable. We need a wrapper with |\xintthe| |
| 7889 |
prefix |
| 7890 |
\begin{everbatim*} |
| 7891 |
\def\theFibonacciN{\xintthe\FibonacciN} |
| 7892 |
\end{everbatim*} |
| 7893 |
to print in the document or to use within |\message| (or \LaTeX\ |typeout|) to |
| 7894 |
write to the log and terminal. |
| 7895 |
|
| 7896 |
\begingroup |
| 7897 |
\def\A {1859} \def\B {1573} |
| 7898 |
\edef\X {\theFibonacciN\A} \edef\Y {\theFibonacciN\B} |
| 7899 |
\edef\GCDAB {\xintiiGCD\A\B}\edef\Z {\theFibonacciN\GCDAB} |
| 7900 |
\edef\GCDXY{\xintiiGCD\X\Y} |
| 7901 |
|
| 7902 |
The |\xintthe| prefix also allows its use it as argument to the \xintname |
| 7903 |
macros: for example if we are interested in knowing how many digits |
| 7904 |
$F(1250)$ has, it suffices to issue |\xintLen {\theFibonacciN {1250}}| |
| 7905 |
(which expands to \dtt{\xintLen {\theFibonacciN {1250}}}). Or if we want to |
| 7906 |
check the formula $gcd(F(1859),F(1573))=F(gcd(1859,1573))=F(143)$, we only |
| 7907 |
need% |
| 7908 |
% |
| 7909 |
\footnote{The |
| 7910 |
\csa{xintiiGCD} macro is provided by both the \xintgcdname package (since |
| 7911 |
|1.0|) and by the \xintname package (since |1.3d|).} |
| 7912 |
% |
| 7913 |
\begin{everbatim} |
| 7914 |
$\xintiiGCD{\theFibonacciN{1859}}{\theFibonacciN{1573}}=% |
| 7915 |
\theFibonacciN{\xintiiGCD{1859}{1573}}$ |
| 7916 |
\end{everbatim} |
| 7917 |
% |
| 7918 |
which produces: |
| 7919 |
% |
| 7920 |
\leftedline{$\dtt{\xintiiGCD{\X}{\Y}}=\dtt{\theFibonacciN{\GCDAB}}$} |
| 7921 |
|
| 7922 |
The |\theFibonacciN| macro expanded its |\xintiiGCD{1859}{1573}| argument via the |
| 7923 |
services of |\numexpr|: this step allows only things obeying the \TeX{} bound, |
| 7924 |
naturally! (but \dtt{F(\xintiiPow2{31}}) would be rather big anyhow...). |
| 7925 |
|
| 7926 |
This is very convenient but of course it repeats the complete evaluation each |
| 7927 |
time it is done. In practice, it is often useful to store the result of such |
| 7928 |
evaluations in macros. Any |\edef| will break expandability, but if the goal |
| 7929 |
is at some point to print something to the |dvi| or |pdf| output, and not only |
| 7930 |
to the |log| file, then expandability has to be broken one day or another! |
| 7931 |
|
| 7932 |
Hence, in practice, if we want to print in the document some computation |
| 7933 |
results, we can proceed like this and avoid having to repeat identical |
| 7934 |
evaluations: |
| 7935 |
\begin{everbatim} |
| 7936 |
\begingroup |
| 7937 |
\def\A {1859} \def\B {1573} |
| 7938 |
\edef\X {\theFibonacciN\A} \edef\Y {\theFibonacciN\B} |
| 7939 |
\edef\GCDAB {\xintiiGCD\A\B}\edef\Z {\theFibonacciN\GCDAB} |
| 7940 |
\edef\GCDXY{\xintiiGCD\X\Y} |
| 7941 |
The identity $\gcd(F(\A),F(\B))=F(\gcd(\A,\B))$ can be checked via evaluation |
| 7942 |
of both sides: $\gcd(F(\A),F(\B))=\gcd(\printnumber\X,\printnumber\Y)= |
| 7943 |
\printnumber{\GCDXY} = F(\gcd(\A,\B)) = F(\GCDAB) =\printnumber\Z$.\par |
| 7944 |
% some further computations involving \A, \B, \X, \Y |
| 7945 |
\endgroup % closing the group removes assignments to \A, \B, ... |
| 7946 |
% or choose longer names less susceptible to overwrite something. |
| 7947 |
% Note: there is no LaTeX \newecommand which would be to \edef like |
| 7948 |
% \newcommand is to \def |
| 7949 |
\end{everbatim} |
| 7950 |
The identity $\gcd(F(\A),F(\B))=F(\gcd(\A,\B))$ can be checked via evaluation |
| 7951 |
of both sides: $\gcd(F(\A),F(\B))=\gcd(\printnumber\X,\printnumber\Y)= |
| 7952 |
\printnumber{\GCDXY} = F(\gcd(\A,\B)) = F(\GCDAB) =\printnumber\Z$.\par |
| 7953 |
\endgroup |
| 7954 |
|
| 7955 |
One may legitimately ask the author: why expandability |
| 7956 |
to such extremes, for things such as big fractions or floating point numbers |
| 7957 |
(even continued fractions...) which anyhow can not be used directly within |
| 7958 |
\TeX's primitives such as |\ifnum|? Why insist on a concept |
| 7959 |
which is foreign to the vast majority of \TeX\ users and even programmers? |
| 7960 |
|
| 7961 |
I have no answer: it made definitely sense at the start of \xintname (see |
| 7962 |
\autoref{ssec:origins}) and once started I could not stop. |
| 7963 |
|
| 7964 |
|
| 7965 |
\subsection{Acknowledgements (2013/05/25)} |
| 7966 |
|
| 7967 |
I was greatly helped in my preparatory thinking, prior to producing such an |
| 7968 |
expandable parser, by the commented source of the |
| 7969 |
\href{https://ctan.org/pkg/l3kernel}{l3fp} package, specifically the |
| 7970 |
|l3fp-parse.dtx| file (in the version of April-May 2013; I think there was in |
| 7971 |
particular a text called ``roadmap'' which was helpful). Also the source of the |
| 7972 |
|calc| package was instructive, despite the fact that here for |\xintexpr| the |
| 7973 |
principles are necessarily different due to the aim of achieving expandability. |
| 7974 |
|
| 7975 |
\clearpage |
| 7976 |
\expandafter\let\csname xintexpr (old doc)nameUp\endcsname\undefined |
| 7977 |
\csname xinttrignameUp\endcsname |
| 7978 |
|
| 7979 |
\section{The \xinttrigname package} |
| 7980 |
\RaisedLabel{sec:trig} |
| 7981 |
|
| 7982 |
\localtableofcontents |
| 7983 |
|
| 7984 |
This package provides trigonometric functions for use with \xintexprname. |
| 7985 |
The sole macro is \csbxint{reloadxinttrig}. |
| 7986 |
|
| 7987 |
This package was first included in release |1.3e| (|2019/04/05|) of |
| 7988 |
\xintexprname. It is automatically loaded by \xintexprname. |
| 7989 |
|
| 7990 |
At |1.4e| (|2021/05/05|) the accuracy was significantly |
| 7991 |
increased: formerly the high-level user interface used to define |
| 7992 |
the functions had as consequences that intermediate steps of the computations |
| 7993 |
could not operate with guard digits, and as a result the last two digits |
| 7994 |
were most of the time off (at least the last one). Now, computations are done |
| 7995 |
internally in extended precision, and the accuracy is high up to the last |
| 7996 |
digits, with faithful rounding and high probability of correct rounding. And |
| 7997 |
the maximal number of digits was raised slightly to \dtt{62} digits. |
| 7998 |
|
| 7999 |
At \dtt{8} digits a special, faster, mode is used, which is less accurate. But faster. |
| 8000 |
|
| 8001 |
\textbf{Acknowledgements:} I finally decided to release some such functions |
| 8002 |
under friendly pressure of Jürgen \textsc{Gilg} and Thomas \textsc{Söll}, let |
| 8003 |
them both be thanked here. |
| 8004 |
|
| 8005 |
Jürgen passed away in 2022. I will miss our friendship which was born and grew |
| 8006 |
from numerous and regular exchanges on topics not limited to this package or |
| 8007 |
even the \TeX\ world. Let's now continue to \myenquote{take care and keep motivated}! |
| 8008 |
|
| 8009 |
\subsection{\csh{xintreloadxinttrig}}\label{xintreloadxinttrig} |
| 8010 |
|
| 8011 |
The library is loaded automatically by \xintexprname at start-up. |
| 8012 |
It is then configured for \dtt{16} digits. |
| 8013 |
|
| 8014 |
To work for example with \dtt{48} digits, execute \csbxint{SetDigits*}|{48}| |
| 8015 |
or \csbxint{Digits*}|:=48;| (the ending |;| can be replaced by a |\relax| in |
| 8016 |
case of problems due to it being active, e.g.\@{} with \LaTeX\ and some languages). |
| 8017 |
|
| 8018 |
With the non-starred variant \csbxint{Digits}|:=48;|\IMPORTANTf{} it is needed |
| 8019 |
to issue \csbxint{reloadxinttrig} to recalibrate the functions provided by the |
| 8020 |
library (and the exponential/logarithm functions will only be updated if also |
| 8021 |
\csbxint{reloadxintlog} is used). |
| 8022 |
|
| 8023 |
% Absence of guard digits (whether in the used hard-coded constants or in |
| 8024 |
% passing over values from one auxiliary function to the next) due to high level |
| 8025 |
% (user) interface used for the programming means that the produced values are |
| 8026 |
% definitely expected to be wrong in the last digit or last two digits. I should |
| 8027 |
% actually give some estimate of the actual maximal error in |ulps| unit, but I |
| 8028 |
% have not done the complete analysis for lack of time. |
| 8029 |
|
| 8030 |
% Final computation results should thus probably be printed via |
| 8031 |
% \csbxint{floateval}|{[-2]....}| in order to strip off (with rounding) the last |
| 8032 |
% two digits, if one does not like seeing those non-meaningful figures in the |
| 8033 |
% last one or two positions (I don't say those last two figures are |
| 8034 |
% \emph{systematically} off). For example, to achieve \dtt{16} digits of |
| 8035 |
% precision one should work with a precision of 18 digits (being careful to have |
| 8036 |
% issued \csbxint{reloadxinttrig}) and round results using |
| 8037 |
% \csbxint{floateval}|{[-2]....}|. |
| 8038 |
|
| 8039 |
% Another approach is to use \csbxint{ieval}|{[D]...}| for conversion to |
| 8040 |
% a fixed point format. |
| 8041 |
|
| 8042 |
% In future, lower level coding will probably replace the high-level interface, |
| 8043 |
% or at least the macros produced by the high-level interface will be hacked |
| 8044 |
% into to tell the float macros to work at a somewhat elevated precision. |
| 8045 |
|
| 8046 |
\subsection{Constants} |
| 8047 |
|
| 8048 |
Their values (with more digits) get incorporated into the trigonometrical |
| 8049 |
functions at the time of their definitions during loading or reloading of the |
| 8050 |
package. They are left free to use, or modified, or \csbxint{unassignvar}'d, |
| 8051 |
as this will have no impact whatsoever on the functions. |
| 8052 |
|
| 8053 |
\begin{description} |
| 8054 |
\vardesc{twoPi} what could that be? |
| 8055 |
\vardesc{threePiover2} |
| 8056 |
\vardesc{Pi} |
| 8057 |
\vardesc{Piover2} |
| 8058 |
\vardesc{oneRadian} this is one radian in degrees: $180/\pi$ |
| 8059 |
\vardesc{oneDegree} this is one degree in radian: $\pi/180$ |
| 8060 |
\end{description} |
| 8061 |
|
| 8062 |
\subsection{Functions} |
| 8063 |
|
| 8064 |
\subsubsection{Direct trigonometry} |
| 8065 |
|
| 8066 |
With the variable in radians: |
| 8067 |
|
| 8068 |
\begin{description} |
| 8069 |
\funcdesc{sin} sine |
| 8070 |
\funcdesc{cos} cosine |
| 8071 |
\funcdesc{tan} tangent |
| 8072 |
\funcdesc{cot} cotangent |
| 8073 |
\funcdesc{sec} secant |
| 8074 |
\funcdesc{csc} cosecant |
| 8075 |
\end{description} |
| 8076 |
|
| 8077 |
With the variable in degrees: |
| 8078 |
|
| 8079 |
\begin{description} |
| 8080 |
\funcdesc{sind} sine |
| 8081 |
\funcdesc{cosd} cosine |
| 8082 |
\funcdesc{tand} tangent |
| 8083 |
\funcdesc{cotd} cotangent |
| 8084 |
\funcdesc{secd} secant |
| 8085 |
\funcdesc{cscd} cosecant |
| 8086 |
\end{description} |
| 8087 |
|
| 8088 |
Only available with the variable in radians: |
| 8089 |
\begin{description} |
| 8090 |
\funcdesc{tg} tangent |
| 8091 |
\funcdesc{cotg} cotangent |
| 8092 |
\funcdesc{sinc} cardinal sine $\sinc(x) = \sin(x)/x$ |
| 8093 |
\end{description} |
| 8094 |
|
| 8095 |
\subsubsection{Inverse trigonometry} |
| 8096 |
|
| 8097 |
With the value in radians: |
| 8098 |
|
| 8099 |
\begin{description} |
| 8100 |
\funcdesc{asin} arcsine |
| 8101 |
\funcdesc{acos} arccosine |
| 8102 |
\funcdesc{atan} arctangent |
| 8103 |
\funcdesc[x, y]{Arg} the main branch of the argument of the complex number |
| 8104 |
|x+iy|, from $-\pi$ (excluded) to $\pi$ (included). As the output is rounded |
| 8105 |
-\var{Pi} is a possible return value. |
| 8106 |
\funcdesc[x, y]{pArg} the branch of the argument of the complex number |
| 8107 |
|x+iy| with values going from $0$ (included) to $2\pi$ (excluded). Inherent |
| 8108 |
rounding makes \var{twoPi} a possible return value. |
| 8109 |
\funcdesc[y, x]{atan2} it is |Arg(x, y)|. Note the reversal of the arguments, |
| 8110 |
this seems to be the most frequently encountered convention across languages. |
| 8111 |
\end{description} |
| 8112 |
|
| 8113 |
With the value in degrees: |
| 8114 |
|
| 8115 |
\begin{description} |
| 8116 |
\funcdesc{asind} arcsine |
| 8117 |
\funcdesc{acosd} arccosine |
| 8118 |
\funcdesc{atand} arctangent |
| 8119 |
\funcdesc[x, y]{Argd} the main branch of the argument of the complex number |
| 8120 |
|x+iy|, from $-180$ (excluded) to $180$ (included). Inherent rounding of |
| 8121 |
output can cause |-180| |
| 8122 |
to be returned. |
| 8123 |
\funcdesc[x, y]{pArgd} the branch of the argument of the complex number |
| 8124 |
|x+iy| with values going from $0$ (included) to $360$ (excluded). Inherent rounding of |
| 8125 |
output can cause |360| to be returned. |
| 8126 |
\funcdesc[y, x]{atan2d} it is |Argd(x, y)|. Note the reversal of the arguments, |
| 8127 |
this seems to be the most frequently encountered convention across languages. |
| 8128 |
\end{description} |
| 8129 |
|
| 8130 |
\subsubsection{Conversion functions (optional definitions left to user |
| 8131 |
decision)} |
| 8132 |
|
| 8133 |
Python provides functions |degrees()| and |radians()|. But as most of the |
| 8134 |
\xinttrigname functions are already defined for the two units, I felt this was |
| 8135 |
not really needed. It is a oneliner to add them: |
| 8136 |
\begin{everbatim} |
| 8137 |
\xintdeffloatfunc radians(x) := x * oneDegree; |
| 8138 |
\xintdeffloatfunc degrees(x) := x * oneRadian; |
| 8139 |
\xintdeffunc radians(x) := float_dgt(x * oneDegree); |
| 8140 |
\xintdeffunc degrees(x) := float_dgt(x * oneRadian); |
| 8141 |
\end{everbatim} |
| 8142 |
|
| 8143 |
The \func{float\string_dgt} does a float rounding to \csbxint{theDigits} |
| 8144 |
precision (recall that |*| is mapped to exact multiplication in |
| 8145 |
\csbxint{deffunc}). |
| 8146 |
|
| 8147 |
\subsection{Important implementation notes} |
| 8148 |
\label{ssec:trignotes} |
| 8149 |
|
| 8150 |
\begin{itemize} |
| 8151 |
\item Currently, \xintname is lacking some dedicated internal representation |
| 8152 |
of floats which means that most operations re-parse the digit tokens of their |
| 8153 |
arguments to count them\dots\ this does not contribute to efficiency (you |
| 8154 |
can load the module under |\xintverbosetrue| regime and see how the nested |
| 8155 |
macros look like and get an idea of how many times some rather silly |
| 8156 |
re-counting of mantissa lengths will get done!) |
| 8157 |
\item One should not overwrite some function names which are employed as |
| 8158 |
auxiliaries; refer to |xintsource.pdf|. |
| 8159 |
\item Floats with large exponents are integers and are multiple of \dtt{1000}; |
| 8160 |
hence modulo \dtt{360} all such ``angles'' are multiple of \dtt{40} degrees. |
| 8161 |
Needless to say that considering usage of the |sind()| and |cosd()| functions |
| 8162 |
with such large float numbers is meaningless. |
| 8163 |
\item See |xintsource.pdf| for some comments on limitations of the range |
| 8164 |
reduction implementation. |
| 8165 |
% \item Regarding |sin()| and |cos()|, \xinttrigname converts their argument to |
| 8166 |
% degrees by multiplication by (pre-rounded) $180/\pi$, then does range |
| 8167 |
% reduction modulo $360$ and finally goes back to radians in the appropriate |
| 8168 |
% octants to use usual Taylor series (roughly said). For large floats, the |
| 8169 |
% output value will thus be one of |sind(40n)|, |cosd(40n)|, |n=0..8|. If the |
| 8170 |
% unit in the last place of original variable was for example \dtt{1e9} the |
| 8171 |
% final result means nothing at all: the unit in the last place interval |
| 8172 |
% extends above possibly astronomical numbers of intervals of length $2\pi$. |
| 8173 |
|
| 8174 |
% This intrinsic problem is not a by-product of conversion problems to and |
| 8175 |
% from degrees, it is an in-built inadequacy of the concept of floating point |
| 8176 |
% numbers to provide meaning to evaluating trigonometrical functions. The |
| 8177 |
% argument should be treated as a uniformly distributed random variable modulo |
| 8178 |
% $2\pi$, and the sine and cosine values should be random variables realizing |
| 8179 |
% the value distribution of these mathematical functions. Clearly this adds |
| 8180 |
% some (rather severe) implementation complications such as deciding how to |
| 8181 |
% make the transition to randomness. Too lazy for that. |
| 8182 |
|
| 8183 |
% Opting for a random value also raises the question of how to deal with |
| 8184 |
% multiple such evaluations at the same argument in a single expression. I |
| 8185 |
% would argue again that as it is evil to consider meaningless quantities, it |
| 8186 |
% is not a problem if new compilations give different results, or even single |
| 8187 |
% compilation gives different results in various parts of the same formula, |
| 8188 |
% that's the whole point of randomness! As said already, I got too lazy to |
| 8189 |
% consider seriously implementing such a non-standard philosophy, despite its |
| 8190 |
% compelling soundness. |
| 8191 |
% \item Did I say the implementation was done at very high level (for the most |
| 8192 |
% part), hence has ample room for optimization? This is particularly the case |
| 8193 |
% for the handling of small inputs by functions such as sine or arcsine. |
| 8194 |
\end{itemize} |
| 8195 |
|
| 8196 |
\subsection{Some example evaluations} |
| 8197 |
|
| 8198 |
\noindent |
| 8199 |
\begin{everbatim*} |
| 8200 |
\xintDigits* := 48\relax |
| 8201 |
Digits at \xinttheDigits:\newline |
| 8202 |
$sind(17)\approx\xintfloateval{sind(17)}$\newline |
| 8203 |
$cosd(17)\approx\xintfloateval{cosd(17)}$\newline |
| 8204 |
$tand(17)\approx\xintfloateval{tand(17)}$\newline |
| 8205 |
$sind(43)\approx\xintfloateval{sind(43)}$\newline |
| 8206 |
$cosd(43)\approx\xintfloateval{cosd(43)}$\newline |
| 8207 |
$tand(43)\approx\xintfloateval{tand(43)}$\newline |
| 8208 |
$asind(0.3)\approx\xintfloateval{asind(0.3)}$\newline |
| 8209 |
$acosd(0.3)\approx\xintfloateval{acosd(0.3)}$\newline |
| 8210 |
$atand(3)\approx\xintfloateval{atand(3)}$\newline |
| 8211 |
$tan(atan(7))\approx\xintfloateval{tan(atan(7))}$\newline |
| 8212 |
$asind(sind(25))\approx\xintfloateval{asind(sind(25))}$\par\medskip |
| 8213 |
\noindent\xintDigits* := 24\relax |
| 8214 |
Digits at \xinttheDigits:\newline |
| 8215 |
$sind(17)\approx\xintfloateval{sind(17)}$\newline |
| 8216 |
$cosd(17)\approx\xintfloateval{cosd(17)}$\newline |
| 8217 |
$tand(17)\approx\xintfloateval{tand(17)}$\newline |
| 8218 |
$sind(43)\approx\xintfloateval{sind(43)}$\newline |
| 8219 |
$cosd(43)\approx\xintfloateval{cosd(43)}$\newline |
| 8220 |
$tand(43)\approx\xintfloateval{tand(43)}$\newline |
| 8221 |
$asind(0.3)\approx\xintfloateval{asind(0.3)}$\newline |
| 8222 |
$acosd(0.3)\approx\xintfloateval{acosd(0.3)}$\newline |
| 8223 |
$atand(3)\approx\xintfloateval{atand(3)}$\newline |
| 8224 |
$tan(atan(7))\approx\xintfloateval{tan(atan(7))}$\newline |
| 8225 |
$asind(sind(25))\approx\xintfloateval{asind(sind(25))}$\par |
| 8226 |
\xintDigits* := 16\relax |
| 8227 |
\end{everbatim*} |
| 8228 |
|
| 8229 |
\clearpage |
| 8230 |
\let\xinttrignameUp\undefined |
| 8231 |
\csname xintlognameUp\endcsname |
| 8232 |
\def\n{|{N}|} |
| 8233 |
\def\m{|{M}|} |
| 8234 |
\def\x{|{x}|} |
| 8235 |
|
| 8236 |
\section{The \xintlogname package} |
| 8237 |
\RaisedLabel{sec:log} |
| 8238 |
|
| 8239 |
\localtableofcontents |
| 8240 |
|
| 8241 |
This package provides logarithms, exponentials and fractional powers for use |
| 8242 |
with \xintexprname. |
| 8243 |
|
| 8244 |
This package was first included in release |1.3e| (|2019/04/05|) of |
| 8245 |
\xintexprname. It is automatically loaded by \xintexprname. |
| 8246 |
|
| 8247 |
At release |1.4e| (|2021/05/05|) it was substantially extended to cover |
| 8248 |
usage with mantissas of up to \dtt{62} digits. |
| 8249 |
|
| 8250 |
At |Digits| set to \dtt{8} or less, the old faster but less accurate |
| 8251 |
macros based on \ctanpackage{poormanlog} are used. These macros compute |
| 8252 |
logarithms and exponentials with about \dtt{8} or \dtt{9} nine digits |
| 8253 |
of \emph{fixed point} precision. |
| 8254 |
|
| 8255 |
\begin{TeXnote} |
| 8256 |
There is thus, for |Digits=8| or less a systematic loss of rounding |
| 8257 |
precision in the floating point sense for logarithms of inputs close |
| 8258 |
to \dtt{1}: e.g. |log10(1.0011871)| is produced as |5.15245e-4| which |
| 8259 |
stands for |0.000515145| having indeed \dtt{9} correct fractional |
| 8260 |
digits, but only \dtt{6} correct digits in the floating point sense. |
| 8261 |
Situation is worse for |log()| as it applies a conversion factor and |
| 8262 |
does not remove the trailing junk digits, which we don't have for |
| 8263 |
|log10()|. Check |xintsource.pdf| and \ctanpackage{poormanlog} README |
| 8264 |
for more info. |
| 8265 |
\end{TeXnote} |
| 8266 |
|
| 8267 |
\subsection{\csh{xintreloadxintlog}}\label{xintreloadxintlog} |
| 8268 |
|
| 8269 |
The library is loaded automatically by \xintexprname at start-up. |
| 8270 |
It is then configured for \dtt{16} digits. |
| 8271 |
|
| 8272 |
To work for example with \dtt{48} digits, execute \csbxint{SetDigits*}|{48}| |
| 8273 |
or \csbxint{Digits*}|:=48;| (the ending |;| can be replaced by a |\relax| in |
| 8274 |
case of problems due to it being active, e.g.\@{} with \LaTeX\ and some languages). |
| 8275 |
|
| 8276 |
With the non-starred variant \csbxint{Digits}|:=48;|\IMPORTANTf{} it is needed |
| 8277 |
to issue \csbxint{reloadxintlog} to recalibrate the functions provided by the |
| 8278 |
library (and the trigonometric functions will only be updated if also |
| 8279 |
\csbxint{reloadxinttrig} is used). |
| 8280 |
|
| 8281 |
\subsection{Functions} |
| 8282 |
|
| 8283 |
% All those functions achieve only about \dtt{8} or \dtt{9} digits of precision. |
| 8284 |
% Notice in particular that the digits beyond the ninth printed by \func{log} |
| 8285 |
% have no significance (here we suppose |1<x<10|), but I did not add the |
| 8286 |
% rounding overhead as it is expected anyhow that the final result will be |
| 8287 |
% appropriately rounded. Notice however that \func{log10} should be seen as |
| 8288 |
% going from floating point to fixed point (in the sense of the number of |
| 8289 |
% fractional digits) and \func{pow10} from fixed point to floating point. |
| 8290 |
|
| 8291 |
\begin{description} |
| 8292 |
\funcdesc{log10} logarithm in base 10 |
| 8293 |
|
| 8294 |
\funcdesc{pow10} fractional powers of 10 |
| 8295 |
|
| 8296 |
\funcdesc{log} natural logarithm |
| 8297 |
|
| 8298 |
\funcdesc{exp} exponential function |
| 8299 |
|
| 8300 |
\funcdesc[x, y]{pow} computes $x^y$ either via the formula |pow10(y*log10(x))| |
| 8301 |
(applied with some internally increased accuracy), for |y| neither an integer |
| 8302 |
nor an half-integer; or via the legacy \csbxint{FloatPower} and |
| 8303 |
\csbxint{FloatSqrt} macros if the exponent is integer or half-integer. |
| 8304 |
Integer exponents trigger an exact evalution in \csbxint{eval} if |
| 8305 |
the output will not exceed (or will only slightly exceed) \dtt{10000} digits |
| 8306 |
(separately for numerator and denominator), else the power is computed in the |
| 8307 |
floating point sense. |
| 8308 |
\end{description} |
| 8309 |
|
| 8310 |
\begin{everbatim*} |
| 8311 |
\xintfloateval{log(2), exp(1), 2^(1/3), 2^10000} |
| 8312 |
\end{everbatim*} |
| 8313 |
|
| 8314 |
\pdfstringdefDisableCommands{\let\cs\empty} |
| 8315 |
|
| 8316 |
\subsection{Some information on how powers are computed} |
| 8317 |
|
| 8318 |
For powers |a^b| or |a**b| in \csbxint{floateval} the following rules apply: |
| 8319 |
\begin{enumerate}[noitemsep] |
| 8320 |
\item a check is made if exponent is integer or half-integer, |
| 8321 |
\item if this is the case legacy \csbxint{FloatPower} (combined with |
| 8322 |
\csbxint{FloatSqrt} for half-integer case) |
| 8323 |
are used to evaluate the power (and |a| can be negative if exponent is |
| 8324 |
integer), |
| 8325 |
\item else the power is computed as |pow10(b*log10(a))| (but keeping some |
| 8326 |
extra digits in intermediate evaluations; in particular |b| is not |
| 8327 |
float-rounded, but |a| is). |
| 8328 |
\end{enumerate} |
| 8329 |
The reason is that the log/exp approach loses accuracy for very big |
| 8330 |
exponents (say for exponents of the order of \dtt{100000000} or more). Here is |
| 8331 |
an example of a precise computation with a very large exponent (\dtt{\xintiieval{12^16}}): |
| 8332 |
\begin{everbatim*} |
| 8333 |
$\xintTeXFromSci{\xintfloateval{1.00000001^\xintiiexpr 12^16\relax}}$\newline |
| 8334 |
\xintDigits:=48;%\xintreloadxintlog is not done as log10/pow10 will not be used |
| 8335 |
$\xintTeXFromSci{\xintfloateval{1.00000001^12^16}}$\newline |
| 8336 |
\xintDigits:=64;%\xintreloadxintlog is not done as log10/pow10 will not be used |
| 8337 |
$\xintTeXFromSci{\xintfloateval{1.00000001^12^16}}$\newline |
| 8338 |
\xintDigits:=80;%\xintreloadxintlog is not done as log10/pow10 will not be used |
| 8339 |
$\xintTeXFromSci{\xintfloateval{1.00000001^12^16}}$ |
| 8340 |
\xintDigits:=16;% |
| 8341 |
\end{everbatim*} |
| 8342 |
|
| 8343 |
Notes: |
| 8344 |
\begin{itemize}[noitemsep] |
| 8345 |
\item in the case with \dtt{16} digits precision, we ensured |12^16| got |
| 8346 |
computed exactly with all its \dtt{18} digits and was not rounded to only |
| 8347 |
\dtt{16} digits (and confirmation is that the result matches the second one |
| 8348 |
at \dtt{48} digits), |
| 8349 |
\item the |1.4g| right associativity |
| 8350 |
of powers is taken into account to drop parentheses. |
| 8351 |
\end{itemize} |
| 8352 |
|
| 8353 |
As the legacy \csbxint{FloatPower} and \csbxint{FloatSqrt} work in arbitrary |
| 8354 |
precision, the result for integer or half-integer exponents is produced with a |
| 8355 |
full-size mantissa, even if |Digits| is more than \dtt{62} (as is examplified |
| 8356 |
above). |
| 8357 |
|
| 8358 |
In the |10^(b*log10(a))| branch the mantissa size is limited to the minimum of |
| 8359 |
|Digits| and of \dtt{64}. Its last digits will start being wrong if |b| |
| 8360 |
becomes about (in absolute value) \dtt{100000000}. If you really need to |
| 8361 |
compute powers with exponents that large or larger, it is recommended to |
| 8362 |
decompose the exponent as a sum of the nearest integer or half-integer and a |
| 8363 |
fractional part and express the power as a product. This is not done |
| 8364 |
automatically as it would add some overhead in general for some a priori very |
| 8365 |
rare use cases. |
| 8366 |
|
| 8367 |
% And recall that the decimal exponents of final and |
| 8368 |
% intermediate results should obey the \TeX\ bound for integers anyhow, i.e. be |
| 8369 |
% at most (in absolute value) \dtt{\number"7FFFFFFF}, add some safety margin... |
| 8370 |
|
| 8371 |
In \csbxint{eval}, this is as in \csbxint{floateval} but for one difference: integer |
| 8372 |
exponents will trigger an exact evaluation, as long as: |
| 8373 |
\begin{itemize} |
| 8374 |
\item the exponent absolute value is at most \dtt{9999}, |
| 8375 |
\item it is evaluated a priori, based on the length of the input, that the |
| 8376 |
output will have at most \dtt{10000} digits (or only a bit more), separately |
| 8377 |
for numerator and denominator. |
| 8378 |
\end{itemize} |
| 8379 |
The check for integralness of exponent is not on its mathematical value |
| 8380 |
but on its internal representation, for speed. So |6/3| is not recognized as |
| 8381 |
being an integer exponent in \csbxint{eval}; but in \csbxint{floateval}, the |
| 8382 |
|6/3| will have been computed and recognized as |2|. Also |2.00| or |200e-2| |
| 8383 |
is recognized as an integer in both parsers. Similar remarks apply to |
| 8384 |
half-integer case. |
| 8385 |
|
| 8386 |
To compute exactly higher powers than |2^9999| or |9^9999| or |99^5000| or |
| 8387 |
|999^3333|, etc..., use \csbxint{iieval}. See \csbxint{iiPow} for related |
| 8388 |
comments if you don't want to melt your CPU. |
| 8389 |
|
| 8390 |
If |Digits| is at most \dtt{8}, logarithms are computed faster but |
| 8391 |
with less accuracy; internally, using \dtt{9} \emph{fixed |
| 8392 |
point fractional digits}. And powers |a^b| lose accuracy in |
| 8393 |
last digits quickly as |b| rises. Here is what was observed |
| 8394 |
with some random tests: |
| 8395 |
\begin{itemize}[noitemsep] |
| 8396 |
\item for |b| neither integer nor half-integer and |1<b<10|, |
| 8397 |
roughly \dtt{8} correct digits for between \dtt{80}\% and \dtt{90}\% of |
| 8398 |
cases and in the remaining cases only a \dtt{1ulp} error. |
| 8399 |
\item for |b| neither integer nor half-integer and |10^e<b<10^(e+1)|, |
| 8400 |
roughly \dtt{8-e} digits are correct for about |
| 8401 |
\dtt{90}\% of cases and there is a one unit error in the last of |
| 8402 |
those digits in the remaining cases. |
| 8403 |
\end{itemize} |
| 8404 |
To maintain higher accuracy, split the input as |a^n a^h| with |n| |
| 8405 |
integer or half-integer nearest to |b|. After having considered (and |
| 8406 |
implemented) the method, decision was made to not incorporate it as it |
| 8407 |
would induce serious overhead generally speaking. The |a^b| with |
| 8408 |
fractional exponent |b| such that |abs(b)<10| are currently computed |
| 8409 |
with at most \dtt{1ulp} error in the vast majority of cases it seems, |
| 8410 |
which is largely precise enough for plots, and then speed matters |
| 8411 |
most. Larger exponents can be handled (since |1.4f|) via manually |
| 8412 |
implementing the splitting trick, as described above. |
| 8413 |
|
| 8414 |
The documentation of the legacy macro \csbxint{FloatPower} (which is used for |
| 8415 |
powers with integer and half-integer exponents) explains it has a guaranteed |
| 8416 |
error bound of |0.52ulp|, in arbitrary precision. Generally speaking, the |
| 8417 |
math functions added at |1.4e| target even smaller errors (but only up to |
| 8418 |
\dtt{62} digits), something of the order of |0.505ulp|, and in practice they |
| 8419 |
seem to achieve even better than \dtt{99\%} of correct rounding probability |
| 8420 |
(at least in their natural ranges, and it varies according to the value of |
| 8421 |
|Digits|). Perhaps in future I will re-examine whether it is worthwile to |
| 8422 |
increase a bit the theoretical accuracy of \csbxint{FloatPower}, as I have not |
| 8423 |
had the time to really measure systematically its pratical accuracy, all |
| 8424 |
anecdotical evidence showing it is good. |
| 8425 |
|
| 8426 |
\clearpage |
| 8427 |
\let\xintlognameUp\undefined |
| 8428 |
\csname xinttoolsnameUp\endcsname |
| 8429 |
\def\n{|{N}|} |
| 8430 |
\def\m{|{M}|} |
| 8431 |
\def\x{|{x}|} |
| 8432 |
\section{Macros of the \xinttoolsname package} |
| 8433 |
\RaisedLabel{sec:tools} |
| 8434 |
|
| 8435 |
\localtableofcontents |
| 8436 |
|
| 8437 |
These utilities used to be provided within the \xintname package; since |1.09g| |
| 8438 |
(|2013/11/22|) they have been moved to an independently usable package |
| 8439 |
\xinttoolsname, which has none of the \xintname facilities regarding big |
| 8440 |
numbers. Whenever relevant release |1.09h| has made the macros |\long| so they |
| 8441 |
accept |\par| tokens on input. |
| 8442 |
|
| 8443 |
The completely expandable utilities (up to \csbxint{iloop}) are documented |
| 8444 |
first, then the non expandable utilities. |
| 8445 |
|
| 8446 |
\autoref{sec:examples} |
| 8447 |
gives additional (some quite dated) examples of use of macros of this package. |
| 8448 |
|
| 8449 |
\xinttoolsname is automatically loaded by \xintexprname. |
| 8450 |
|
| 8451 |
\subsection{\csh{xintRevWithBraces}}\label{xintRevWithBraces} |
| 8452 |
|
| 8453 |
%{\small New in release |1.06|.\par} |
| 8454 |
|
| 8455 |
\edef\X{\xintRevWithBraces{12345}} |
| 8456 |
\edef\y{\xintRevWithBraces\X} |
| 8457 |
\expandafter\def\expandafter\w\expandafter |
| 8458 |
{\romannumeral0\xintrevwithbraces{{\A}{\B}{\C}{\D}{\E}}} |
| 8459 |
|
| 8460 |
% |
| 8461 |
\csa{xintRevWithBraces}\marg{list}\etype{f} first does the \fexpan sion of its |
| 8462 |
argument then it reverses the order of the tokens, or braced material, it |
| 8463 |
encounters, maintaining existing braces and adding a brace pair around each |
| 8464 |
naked token encountered. Space tokens (in-between top level braces or naked |
| 8465 |
tokens) are gobbled. This macro is mainly thought out for use on a \meta{list} |
| 8466 |
of such braced material; with such a list as argument the \fexpan sion will only |
| 8467 |
hit against the first opening brace, hence do nothing, and the braced stuff may |
| 8468 |
thus be macros one does not want to expand. |
| 8469 |
% |
| 8470 |
\leftedline{|\edef\x{\xintRevWithBraces{12345}}|} |
| 8471 |
% |
| 8472 |
\leftedline{|\meaning\x:|\dtt{\meaning\X}} |
| 8473 |
% |
| 8474 |
\leftedline{|\edef\y{\xintRevWithBraces\x}|} |
| 8475 |
% |
| 8476 |
\leftedline{|\meaning\y:|\dtt{\meaning\y}} |
| 8477 |
% |
| 8478 |
The examples above could be defined with |\edef|'s because the braced material |
| 8479 |
did not contain macros. Alternatively: |
| 8480 |
% |
| 8481 |
\leftedline{|\expandafter\def\expandafter\w\expandafter|} |
| 8482 |
% |
| 8483 |
\leftedline{|{\romannumeral0\xintrevwithbraces{{\A}{\B}{\C}{\D}{\E}}}|} |
| 8484 |
% |
| 8485 |
\leftedline{|\meaning\w:|\dtt{\meaning\w}} |
| 8486 |
% |
| 8487 |
The macro \csa{xintReverseWithBracesNoExpand}\etype{n} does the same job |
| 8488 |
without the initial expansion of its argument. |
| 8489 |
|
| 8490 |
|
| 8491 |
\subsection{\csh{xintZapFirstSpaces}, \csh{xintZapLastSpaces}, \csh{xintZapSpaces}, \csh{xintZapSpacesB}} |
| 8492 |
\label{xintZapFirstSpaces} |
| 8493 |
\label{xintZapLastSpaces} |
| 8494 |
\label{xintZapSpaces} |
| 8495 |
\label{xintZapSpacesB} |
| 8496 |
%{\small New with release |1.09f|.\par} |
| 8497 |
|
| 8498 |
\csa{xintZapFirstSpaces}\marg{stuff}\etype{n} does not do \emph{any} expansion |
| 8499 |
of its argument, nor brace removal of any sort, nor does it alter \meta{stuff} |
| 8500 |
in anyway apart from stripping away all \emph{leading} spaces. |
| 8501 |
|
| 8502 |
This macro will be mostly of interest to programmers who will know what I will |
| 8503 |
now be talking about. \emph{The essential points, naturally, are the complete |
| 8504 |
expandability and the fact that no brace removal nor any other alteration is |
| 8505 |
done to the input.} |
| 8506 |
|
| 8507 |
\TeX's input scanner already converts consecutive blanks into single space |
| 8508 |
tokens, but |\xintZapFirstSpaces| handles successfully also inputs with |
| 8509 |
consecutive multiple space tokens. |
| 8510 |
However, it is assumed that \meta{stuff} does not contain (except inside braced |
| 8511 |
sub-material) space tokens of character code distinct from $32$. |
| 8512 |
|
| 8513 |
It expands in two steps, and if the goal is to apply it to the |
| 8514 |
expansion text of |\x| to define |\y|, then one can do: |
| 8515 |
|\odef\y{\romannumeral0\expandafter\xintzapfirstspaces\expandafter{\x}}| |
| 8516 |
(one can also define a wrapper macro to |\xintZapFirstSpaces| in order to |
| 8517 |
expand once the argument first, but \xinttoolsname not being a programming |
| 8518 |
layer, it provides no \myenquote{Generate Variants} facilities). |
| 8519 |
|
| 8520 |
Other use case: inside a macro which received a parameter |#1|, one can do |
| 8521 |
|\oodef\x{\xintZapFirstSpaces {#1}}|, or, if |#1|, after leading spaces have |
| 8522 |
been stripped can accept |\edef| expansion, one can do |
| 8523 |
|\edef\x{\xintZapFirstSpaces{#1}}|. |
| 8524 |
|
| 8525 |
\begingroup |
| 8526 |
\def\x { \a { \X } { \b \Y } } |
| 8527 |
% |
| 8528 |
\leftedline{|\xintZapFirstSpaces { \a { \X } { \b \Y } }->|% |
| 8529 |
\dtt{\color{magenta}{}\expandafter\detokenize\expandafter |
| 8530 |
{\romannumeral0\expandafter\xintzapfirstspaces\expandafter{\x}}}+++} |
| 8531 |
\endgroup |
| 8532 |
|
| 8533 |
\medskip |
| 8534 |
|
| 8535 |
\noindent\csbxint{ZapLastSpaces}\marg{stuff}\etype{n} does not do \emph{any} expansion of |
| 8536 |
its argument, nor brace removal of any sort, nor does it alter \meta{stuff} in |
| 8537 |
anyway apart from stripping away all \emph{ending} spaces. The same remarks as |
| 8538 |
for \csbxint{ZapFirstSpaces} apply. |
| 8539 |
|
| 8540 |
\begingroup |
| 8541 |
\def\x { \a { \X } { \b \Y } } |
| 8542 |
% |
| 8543 |
\leftedline{|\xintZapLastSpaces { \a { \X } { \b \Y } }->|% |
| 8544 |
\dtt{\color{magenta}{}\expandafter\detokenize\expandafter |
| 8545 |
{\romannumeral0\expandafter\xintzaplastspaces\expandafter{\x}}}+++} |
| 8546 |
\endgroup |
| 8547 |
|
| 8548 |
\medskip |
| 8549 |
|
| 8550 |
\noindent\csbxint{ZapSpaces}\marg{stuff}\etype{n} does not do \emph{any} |
| 8551 |
expansion of its |
| 8552 |
argument, nor brace removal of any sort, nor does it alter \meta{stuff} in |
| 8553 |
anyway apart from stripping away all \emph{leading} and all \emph{ending} |
| 8554 |
spaces. The same remarks as for \csbxint{ZapFirstSpaces} apply. |
| 8555 |
|
| 8556 |
\begingroup |
| 8557 |
\def\x { \a { \X } { \b \Y } } |
| 8558 |
% |
| 8559 |
\leftedline{|\xintZapSpaces { \a { \X } { \b \Y } }->|% |
| 8560 |
\dtt{\color{magenta}{}\expandafter\detokenize\expandafter |
| 8561 |
{\romannumeral0\expandafter\xintzapspaces\expandafter{\x}}}+++} |
| 8562 |
\endgroup |
| 8563 |
|
| 8564 |
\medskip |
| 8565 |
|
| 8566 |
\noindent\csbxint{ZapSpacesB}\marg{stuff}\etype{n} does not do \emph{any} |
| 8567 |
expansion of |
| 8568 |
its argument, nor does it alter \meta{stuff} in anyway apart from stripping away |
| 8569 |
all leading and all ending spaces and possibly removing one level of braces if |
| 8570 |
\meta{stuff} had the shape |<spaces>{braced}<spaces>|. The same remarks as for |
| 8571 |
\csbxint{ZapFirstSpaces} apply. |
| 8572 |
|
| 8573 |
\begingroup |
| 8574 |
\def\x { \a { \X } { \b \Y } } |
| 8575 |
% |
| 8576 |
\leftedline{|\xintZapSpacesB { \a { \X } { \b \Y } }->|% |
| 8577 |
\dtt{\color{magenta}{}\expandafter\detokenize\expandafter |
| 8578 |
{\romannumeral0\expandafter\xintzapspacesb\expandafter{\x}}}+++} |
| 8579 |
\def\x { { \a { \X } { \b \Y } } } |
| 8580 |
% |
| 8581 |
\leftedline{|\xintZapSpacesB { { \a { \X } { \b \Y } } }->|% |
| 8582 |
\dtt{\color{magenta}{}\expandafter\detokenize\expandafter |
| 8583 |
{\romannumeral0\expandafter\xintzapspacesb\expandafter{\x}}}+++} |
| 8584 |
\endgroup |
| 8585 |
The spaces here at the start and end of the output come from the braced |
| 8586 |
material, and are not removed (one would need a second application for that; |
| 8587 |
recall though that the \xintname zapping macros do not expand their argument). |
| 8588 |
|
| 8589 |
\subsection{\csh{xintCSVtoList}} |
| 8590 |
\label{xintCSVtoList} |
| 8591 |
\label{xintCSVtoListNoExpand} |
| 8592 |
|
| 8593 |
|
| 8594 |
\csa{xintCSVtoList}|{a,b,c...,z}|\etype{f} returns |{a}{b}{c}...{z}|. A |
| 8595 |
\emph{list} is by |
| 8596 |
convention in this manual simply a succession of tokens, where each braced thing |
| 8597 |
will count as one item (``items'' are defined according to the rules of \TeX{} |
| 8598 |
for fetching undelimited parameters of a macro, which are exactly the same rules |
| 8599 |
as for \LaTeX{} and macro arguments [they are the same things]). The word |
| 8600 |
`list' in `comma separated list of items' has its usual linguistic meaning, |
| 8601 |
and then an ``item'' is what is delimited by commas. |
| 8602 |
|
| 8603 |
So \csa{xintCSVtoList} takes on input a `comma separated list of items' and |
| 8604 |
converts it into a `\TeX{} list of braced items'. The argument to |
| 8605 |
|\xintCSVtoList| may be a macro: it will first be |
| 8606 |
\hyperref[ssec:expansions]{\fexpan ded}. Hence the item before the first comma, |
| 8607 |
if it is itself a macro, will be expanded which may or may not be a good thing. |
| 8608 |
A space inserted at the start of the first item serves to stop that expansion |
| 8609 |
(and disappears). The macro \csbxint{CSVtoListNoExpand}\etype{n} does the same |
| 8610 |
job without |
| 8611 |
the initial expansion of the list argument. |
| 8612 |
|
| 8613 |
Apart from that no expansion of the items is done and the list items may thus be |
| 8614 |
completely arbitrary (and even contain perilous stuff such as unmatched |\if| |
| 8615 |
and |\fi| tokens). |
| 8616 |
|
| 8617 |
Contiguous spaces and tab characters, are collapsed by \TeX{} |
| 8618 |
into single spaces. All such spaces around commas% |
| 8619 |
% |
| 8620 |
\footnote{and multiple space tokens are not a problem; but those at the |
| 8621 |
top level (not hidden inside braces) \emph{must} be of character code |
| 8622 |
|32|.} |
| 8623 |
% |
| 8624 |
\fbox{are removed}, as well as |
| 8625 |
the spaces at the start and the spaces at the end of the list.% |
| 8626 |
% |
| 8627 |
\footnote{let us recall that this is all done completely expandably... |
| 8628 |
There is absolutely no alteration of any sort of the item apart from |
| 8629 |
the stripping of initial and final space tokens (of character code |
| 8630 |
|32|) and brace removal if and only if the item apart from intial and |
| 8631 |
final spaces (or more generally multiple |char 32| space tokens) is |
| 8632 |
braced.} |
| 8633 |
% |
| 8634 |
The items may contain explicit |\par|'s or |
| 8635 |
empty lines (converted by the \TeX{} input parsing into |\par| tokens). |
| 8636 |
|
| 8637 |
\begingroup |
| 8638 |
|
| 8639 |
\edef\X{\xintCSVtoList { 1 ,{ 2 , 3 , 4 , 5 }, a , {b,T} U , { c , d } , { {x , |
| 8640 |
y} } }} |
| 8641 |
|
| 8642 |
% |
| 8643 |
\leftedline{|\xintCSVtoList { 1 ,{ 2 , 3 , 4 , 5 }, a , {b,T} U , { c , d } , |
| 8644 |
{ {x , y} } }|} |
| 8645 |
% |
| 8646 |
\leftedline{|->|% |
| 8647 |
{\makeatletter\dtt{\expandafter\strip@prefix\meaning\X}}} |
| 8648 |
|
| 8649 |
One sees on this example how braces protect commas from |
| 8650 |
sub-lists to be perceived as delimiters of the top list. Braces around an entire |
| 8651 |
item are removed, even when surrounded by spaces before and/or after. Braces for |
| 8652 |
sub-parts of an item are not removed. |
| 8653 |
|
| 8654 |
We observe also that there is a slight difference regarding the brace stripping |
| 8655 |
of an item: if the braces were not surrounded by spaces, also the initial and |
| 8656 |
final (but no other) spaces of the \emph{enclosed} material are removed. This is |
| 8657 |
the only situation where spaces protected by braces are nevertheless removed. |
| 8658 |
|
| 8659 |
From the rules above: for an empty argument (only spaces, no braces, no comma) |
| 8660 |
the output is |
| 8661 |
\dtt{\expandafter\detokenize\expandafter{\romannumeral0\xintcsvtolist { }}} |
| 8662 |
(a list with one empty item), |
| 8663 |
for ``|<opt. spaces>{}<opt. |
| 8664 |
spaces>|'' the output is |
| 8665 |
\dtt{\expandafter\detokenize\expandafter |
| 8666 |
{\romannumeral0\xintcsvtolist { {} }}} |
| 8667 |
(again a list with one empty item, the braces were removed), |
| 8668 |
for ``|{ }|'' the output is |
| 8669 |
\dtt{\expandafter\detokenize\expandafter |
| 8670 |
{\romannumeral0\xintcsvtolist {{ }}}} |
| 8671 |
(again a list with one empty item, the braces were removed and then |
| 8672 |
the inner space was removed), |
| 8673 |
for ``| { }|'' the output is |
| 8674 |
\dtt{\expandafter\detokenize\expandafter |
| 8675 |
{\romannumeral0\xintcsvtolist { { }}}} (again a list with one empty item, the initial space served only to stop the expansion, so this was like ``|{ }|'' as input, the braces were removed and the inner space was stripped), |
| 8676 |
for ``\texttt{\ \{\ \ \}\ }'' the output is |
| 8677 |
\dtt{\expandafter\detokenize\expandafter |
| 8678 |
{\romannumeral0\xintcsvtolist { { } }}} (this time the ending space of the first |
| 8679 |
item meant that after brace removal the inner spaces were kept; recall though |
| 8680 |
that \TeX{} collapses on input consecutive blanks into one space token), |
| 8681 |
for ``|,|'' the output consists of two consecutive |
| 8682 |
empty items |
| 8683 |
\dtt{\expandafter\detokenize\expandafter{\romannumeral0\xintcsvtolist |
| 8684 |
{,}}}. Recall that on output everything is braced, a |{}| is an ``empty'' |
| 8685 |
item. |
| 8686 |
% |
| 8687 |
Most of the above is mainly irrelevant for every day use, apart perhaps from the |
| 8688 |
fact to be noted that an empty input does not give an empty output but a |
| 8689 |
one-empty-item list (it is as if an ending comma was always added at the end of |
| 8690 |
the input). |
| 8691 |
|
| 8692 |
\def\y { \a,\b,\c,\d,\e} |
| 8693 |
\expandafter\def\expandafter\Y\expandafter{\romannumeral0\xintcsvtolist{\y}} |
| 8694 |
\def\t {{\if},\ifnum,\ifx,\ifdim,\ifcat,\ifmmode} |
| 8695 |
\expandafter\def\expandafter\T\expandafter{\romannumeral0\xintcsvtolist{\t}} |
| 8696 |
|
| 8697 |
% |
| 8698 |
\leftedline{|\def\y{ \a,\b,\c,\d,\e} \xintCSVtoList\y->|% |
| 8699 |
{\makeatletter\dtt{\expandafter\strip@prefix\meaning\Y}}} |
| 8700 |
% |
| 8701 |
\leftedline{|\def\t {{\if},\ifnum,\ifx,\ifdim,\ifcat,\ifmmode}|} |
| 8702 |
% |
| 8703 |
\leftedline |
| 8704 |
{|\xintCSVtoList\t->|\makeatletter\dtt{\expandafter\strip@prefix\meaning\T}} |
| 8705 |
% |
| 8706 |
The results above were automatically displayed using \TeX's primitive |
| 8707 |
\csa{meaning}, which adds a space after each control sequence name. These spaces |
| 8708 |
are not in the actual braced items of the produced lists. The first items |\a| |
| 8709 |
and |\if| were either preceded by a space or braced to prevent expansion. The |
| 8710 |
macro \csa{xintCSVtoListNoExpand} would have done the same job without the |
| 8711 |
initial expansion of the list argument, hence no need for such protection but if |
| 8712 |
|\y| is defined as |\def\y{\a,\b,\c,\d,\e}| we then must do: |
| 8713 |
% |
| 8714 |
\leftedline{|\expandafter\xintCSVtoListNoExpand\expandafter {\y}|} Else, we |
| 8715 |
may have direct use: % |
| 8716 |
% |
| 8717 |
\leftedline{|\xintCSVtoListNoExpand |
| 8718 |
{\if,\ifnum,\ifx,\ifdim,\ifcat,\ifmmode}|} |
| 8719 |
% |
| 8720 |
\leftedline{|->|\dtt{\expandafter\detokenize\expandafter |
| 8721 |
{\romannumeral0\xintcsvtolistnoexpand |
| 8722 |
{\if,\ifnum,\ifx,\ifdim,\ifcat,\ifmmode}}}} |
| 8723 |
% |
| 8724 |
Again these spaces are an artefact from the use in the source of the document of |
| 8725 |
\csa{meaning} (or rather here, \csa{detokenize}) to display the result of using |
| 8726 |
\csa{xintCSVtoListNoExpand} (which is done for real in this document |
| 8727 |
source). |
| 8728 |
|
| 8729 |
For the similar conversion from comma separated list to braced items list, but |
| 8730 |
without removal of spaces around the commas, there is |
| 8731 |
\csa{xintCSVtoListNonStripped}\etype{f} and |
| 8732 |
\csa{xintCSVtoListNonStrippedNoExpand}\etype{n}. |
| 8733 |
|
| 8734 |
\endgroup |
| 8735 |
|
| 8736 |
\subsection{\csh{xintNthElt}}\label{xintNthElt} |
| 8737 |
|
| 8738 |
|
| 8739 |
\def\macro #1{\the\numexpr 9-#1\relax} |
| 8740 |
|
| 8741 |
\csa{xintNthElt\x}\marg{list}\etype{\numx f} gets (expandably) the |x|th |
| 8742 |
item of the \meta{list}. A braced item will lose one level of brace |
| 8743 |
pairs. The token list is first \fexpan ded. |
| 8744 |
|
| 8745 |
Items are counted starting at one. |
| 8746 |
|
| 8747 |
\leftedline{|\xintNthElt {3}{{agh}\u{zzz}\v{Z}}| is |
| 8748 |
\texttt{\xintNthElt {3}{{agh}\u{zzz}\v{Z}}}} |
| 8749 |
% |
| 8750 |
\leftedline{|\xintNthElt {3}{{agh}\u{{zzz}}\v{Z}}| is |
| 8751 |
\texttt{\expandafter\expandafter\expandafter |
| 8752 |
\detokenize\expandafter\expandafter\expandafter {\xintNthElt |
| 8753 |
{3}{{agh}\u{{zzz}}\v{Z}}}}} |
| 8754 |
% |
| 8755 |
\leftedline{|\xintNthElt {2}{{agh}\u{{zzz}}\v{Z}}| is |
| 8756 |
\texttt{\expandafter\expandafter\expandafter |
| 8757 |
\detokenize\expandafter\expandafter\expandafter {\xintNthElt |
| 8758 |
{2}{{agh}\u{{zzz}}\v{Z}}}}} |
| 8759 |
% |
| 8760 |
\leftedline{|\xintNthElt {37}{\xintiiFac {100}}|\dtt{=\xintNthElt |
| 8761 |
{37}{\xintiiFac {100}}} is the thirty-seventh digit of $100!$.} |
| 8762 |
% |
| 8763 |
\leftedline{|\xintNthElt {10}{\xintFtoCv |
| 8764 |
{566827/208524}}|\dtt{=\xintNthElt {10}{\xintFtoCv |
| 8765 |
{566827/208524}}}} |
| 8766 |
\leftedline{is the tenth convergent of $566827/208524$ (uses \xintcfracname |
| 8767 |
package).} |
| 8768 |
% |
| 8769 |
\leftedline{|\xintNthElt {7}{\xintCSVtoList {1,2,3,4,5,6,7,8,9}}|% |
| 8770 |
\dtt{=\xintNthElt {7}{\xintCSVtoList {1,2,3,4,5,6,7,8,9}}}} |
| 8771 |
% |
| 8772 |
\leftedline{|\xintNthElt {0}{\xintCSVtoList {1,2,3,4,5,6,7,8,9}}|% |
| 8773 |
\dtt{=\xintNthElt {0}{\xintCSVtoList {1,2,3,4,5,6,7,8,9}}}} |
| 8774 |
% |
| 8775 |
\leftedline{|\xintNthElt {-3}{\xintCSVtoList {1,2,3,4,5,6,7,8,9}}|% |
| 8776 |
\dtt{=\xintNthElt {-3}{\xintCSVtoList {1,2,3,4,5,6,7,8,9}}}} |
| 8777 |
|
| 8778 |
If |x=0|, |
| 8779 |
the macro returns the \emph{length} of the expanded list: this is not equivalent |
| 8780 |
to \csbxint{Length} which does no pre-expansion. And it is different from |
| 8781 |
\csbxint{Len} which is to be used only on integers or fractions. |
| 8782 |
|
| 8783 |
If |x<0|, the macro returns the \verb+|x|+th element from the end of the list. |
| 8784 |
Thus for example |x=-1| will fetch the last item of the list. |
| 8785 |
% |
| 8786 |
\leftedline {|\xintNthElt {-5}{{{agh}}\u{zzz}\v{Z}}| is |
| 8787 |
\texttt{\expandafter\expandafter\expandafter \detokenize |
| 8788 |
\expandafter\expandafter\expandafter{\xintNthElt {-5}{{{agh}}\u{zzz}\v{Z}}}}} |
| 8789 |
|
| 8790 |
The macro \csa{xintNthEltNoExpand}\etype{\numx n} does the same job but without |
| 8791 |
first expanding the list argument: |\xintNthEltNoExpand {-4}{\u\v\w T\x\y\z}| is |
| 8792 |
\xintNthEltNoExpand {-4}{\a\b\c\u\v\w T\x\y\z}. |
| 8793 |
|
| 8794 |
If |x| is strictly larger (in absolute value) than the length of the list |
| 8795 |
then |\xintNthElt| produces empty contents. |
| 8796 |
|
| 8797 |
\subsection{\csh{xintNthOnePy}} |
| 8798 |
\label{xintNthOnePy} |
| 8799 |
|
| 8800 |
\csa{xintNthOnePy\x}\marg{list}\etype{\numx f} gets (expandably) the |x|th |
| 8801 |
item of the \meta{list}, adding a brace pair if there wasn't one. |
| 8802 |
|
| 8803 |
Attention, items are counted starting at zero. For negative index, behaves |
| 8804 |
as \csbxint{NthElt}. |
| 8805 |
|
| 8806 |
If the index is out of range, the empty output is returned. If the input list |
| 8807 |
was empty (had no items) the empty output is returned. |
| 8808 |
|
| 8809 |
\subsection{\csh{xintKeep}}\label{xintKeep} |
| 8810 |
|
| 8811 |
\csa{xintKeep\x}\marg{list}\etype{\numx f} expands the token list argument |L| |
| 8812 |
and produces a new list, depending on the value of |x|: |
| 8813 |
\begin{itemize}[nosep] |
| 8814 |
\item if |x>0|, the new list contains the first |x| items from |L| (counting |
| 8815 |
starts at one.) \emph{Each |
| 8816 |
such item will be output within a brace pair.} Use \csbxint{KeepUnbraced} if |
| 8817 |
this is not desired. This means that if the list item was braced to start |
| 8818 |
with, there is no modification, but if it was a token without braces, |
| 8819 |
then it acquires them. |
| 8820 |
\item if |x>=length(L)|, the new list is the old one with all its items now |
| 8821 |
braced. |
| 8822 |
\item if |x=0| the empty list is returned. |
| 8823 |
\item if |x<0| the last \verb+|x|+ elements compose the output in the same |
| 8824 |
order as in the initial list; as the macro proceeds by removing head items |
| 8825 |
the kept items end up in output as they were in input: no added braces. |
| 8826 |
\item if |x<=-length(L)| the output is identical with the input. |
| 8827 |
\end{itemize} |
| 8828 |
|
| 8829 |
\csa{xintKeepNoExpand} does the same without first \fexpan ding its list |
| 8830 |
argument. |
| 8831 |
% |
| 8832 |
\begin{everbatim*} |
| 8833 |
\fdef\test {\xintKeep {17}{\xintKeep {-69}{\xintSeq {1}{100}}}}\meaning\test\par |
| 8834 |
\noindent\fdef\test {\xintKeep {7}{{1}{2}{3}{4}{5}{6}{7}{8}{9}}}\meaning\test\par |
| 8835 |
\noindent\fdef\test {\xintKeep {-7}{{1}{2}{3}{4}{5}{6}{7}{8}{9}}}\meaning\test\par |
| 8836 |
\noindent\fdef\test {\xintKeep {7}{123456789}}\meaning\test\par |
| 8837 |
\noindent\fdef\test {\xintKeep {-7}{123456789}}\meaning\test\par |
| 8838 |
\end{everbatim*} |
| 8839 |
|
| 8840 |
|
| 8841 |
\subsection{\csh{xintKeepUnbraced}}\label{xintKeepUnbraced} |
| 8842 |
|
| 8843 |
Same as \csbxint{Keep} but no brace pairs are added around the kept items from |
| 8844 |
the head of the list in the case |x>0|: each such item will lose one level of |
| 8845 |
braces. Thus, to remove braces from all items of the list, one can use |
| 8846 |
\csbxint{KeepUnbraced} with its first argument larger than the length of the |
| 8847 |
list; the same is obtained from \csbxint{ListWithSep}|{}|\marg{list}. But the |
| 8848 |
new list will then have generally many more items than the original ones, |
| 8849 |
corresponding to the unbraced original items. |
| 8850 |
|
| 8851 |
For |x<0| the macro is no different from \csbxint{Keep}. Hence the name is a |
| 8852 |
bit misleading because brace removal will happen only if |x>0|. |
| 8853 |
|
| 8854 |
\csa{xintKeepUnbracedNoExpand} does the same without first \fexpan ding |
| 8855 |
its list argument. |
| 8856 |
% |
| 8857 |
\begin{everbatim*} |
| 8858 |
\fdef\test {\xintKeepUnbraced {10}{\xintSeq {1}{100}}}\meaning\test\par |
| 8859 |
\noindent\fdef\test {\xintKeepUnbraced {7}{{1}{2}{3}{4}{5}{6}{7}{8}{9}}}% |
| 8860 |
\meaning\test\par |
| 8861 |
\noindent\fdef\test {\xintKeepUnbraced {-7}{{1}{2}{3}{4}{5}{6}{7}{8}{9}}}% |
| 8862 |
\meaning\test\par |
| 8863 |
\noindent\fdef\test {\xintKeepUnbraced {7}{123456789}}\meaning\test\par |
| 8864 |
\noindent\fdef\test {\xintKeepUnbraced {-7}{123456789}}\meaning\test\par |
| 8865 |
\end{everbatim*} |
| 8866 |
|
| 8867 |
\subsection{\csh{xintTrim}}\label{xintTrim} |
| 8868 |
|
| 8869 |
\csa{xintTrim\x}\marg{list}\etype{\numx f} expands the list argument and |
| 8870 |
gobbles its first |x| elements. |
| 8871 |
\begin{itemize}[nosep] |
| 8872 |
\item if |x>0|, the first |x| items from |L| are gobbled. The remaining items |
| 8873 |
are not modified. |
| 8874 |
\item if |x>=length(L)|, the returned list is empty. |
| 8875 |
\item if |x=0| the original list is returned (with no added braces.) |
| 8876 |
\item if |x<0| the last \verb+|x|+ items of the list are removed. \emph{The |
| 8877 |
head items end up braced in the output.} Use \csbxint{TrimUnbraced} if |
| 8878 |
this is not desired. |
| 8879 |
\item if |x<=-length(L)| the output is empty. |
| 8880 |
\end{itemize} |
| 8881 |
|
| 8882 |
\csa{xintTrimNoExpand} does the same without first \fexpan ding its list |
| 8883 |
argument. |
| 8884 |
\begin{everbatim*} |
| 8885 |
\fdef\test {\xintTrim {17}{\xintTrim {-69}{\xintSeq {1}{100}}}}\meaning\test\par |
| 8886 |
\noindent\fdef\test {\xintTrim {7}{{1}{2}{3}{4}{5}{6}{7}{8}{9}}}\meaning\test\par |
| 8887 |
\noindent\fdef\test {\xintTrim {-7}{{1}{2}{3}{4}{5}{6}{7}{8}{9}}}\meaning\test\par |
| 8888 |
\noindent\fdef\test {\xintTrim {7}{123456789}}\meaning\test\par |
| 8889 |
\noindent\fdef\test {\xintTrim {-7}{123456789}}\meaning\test\par |
| 8890 |
\end{everbatim*} |
| 8891 |
|
| 8892 |
\subsection{\csh{xintTrimUnbraced}}\label{xintTrimUnbraced} |
| 8893 |
|
| 8894 |
Same as \csbxint{Trim} but in case of a negative |x| (cutting items from |
| 8895 |
the tail), the kept items from the head are not enclosed in brace pairs. They |
| 8896 |
will lose one level of braces. The name is a bit misleading |
| 8897 |
because when |x>0| there is no brace-stripping done on the kept items, because |
| 8898 |
the macro works simply by gobbling the head ones. |
| 8899 |
|
| 8900 |
\csa{xintTrimUnbracedNoExpand} does the same without first \fexpan ding its list |
| 8901 |
argument. |
| 8902 |
|
| 8903 |
\begin{everbatim*} |
| 8904 |
\fdef\test {\xintTrimUnbraced {-90}{\xintSeq {1}{100}}}\meaning\test\par |
| 8905 |
\noindent\fdef\test {\xintTrimUnbraced {7}{{1}{2}{3}{4}{5}{6}{7}{8}{9}}}% |
| 8906 |
\meaning\test\par |
| 8907 |
\noindent\fdef\test {\xintTrimUnbraced {-7}{{1}{2}{3}{4}{5}{6}{7}{8}{9}}}% |
| 8908 |
\meaning\test\par |
| 8909 |
\noindent\fdef\test {\xintTrimUnbraced {7}{123456789}}\meaning\test\par |
| 8910 |
\noindent\fdef\test {\xintTrimUnbraced {-7}{123456789}}\meaning\test\par |
| 8911 |
\end{everbatim*} |
| 8912 |
|
| 8913 |
\subsection{\csh{xintListWithSep}}\label{xintListWithSep} |
| 8914 |
|
| 8915 |
|
| 8916 |
\def\macro #1{\the\numexpr 9-#1\relax} |
| 8917 |
|
| 8918 |
\csa{xintListWithSep}\marg{sep}\marg{list}\etype{nf} inserts the separator |
| 8919 |
\meta{sep} in-between all items of the given list of braced items (or |
| 8920 |
individual tokens). The items are fetched as does \TeX\ with undelimited macro |
| 8921 |
arguments, thus they end up unbraced in output. If the \meta{list} is only one |
| 8922 |
(or multiple) space tokens, the output is empty. |
| 8923 |
|
| 8924 |
The list argument \meta{list} gets \fexpan ded first (thus if it is a macro |
| 8925 |
whose contents are braced items, the first opening brace stops the expansion, |
| 8926 |
and it is as if the macro had been expanded once.) The separator \meta{sep} is |
| 8927 |
not pre-expanded, it ends up as is in the output (if the \meta{list} contained |
| 8928 |
at least two items.) |
| 8929 |
|
| 8930 |
The variant \csa{xintListWithSepNoExpand}\etype{nn} does the same |
| 8931 |
job without the initial expansion of the \meta{list} argument. |
| 8932 |
\begin{everbatim*} |
| 8933 |
\edef\foo{\xintListWithSep{, }{123456789{10}{11}{12}}}\meaning\foo\newline |
| 8934 |
\edef\foo{\xintListWithSep{:}{\xintiiFac{20}}}\meaning\foo\newline |
| 8935 |
\oodef\FOO{\xintListWithSepNoExpand{\FOO}{\bat\baz\biz\buz}}\meaning\FOO\newline |
| 8936 |
% a braced item or a space stops the f-expansion: |
| 8937 |
\oodef\foo{\xintListWithSep{\FOO}{{\bat}\baz\biz\buz}}\meaning\foo\newline |
| 8938 |
\oodef\foo{\xintListWithSep{\FOO}{ \bat\baz\biz\buz}}\meaning\foo\par |
| 8939 |
\end{everbatim*} |
| 8940 |
|
| 8941 |
\subsection{\csh{xintApply}}\label{xintApply} |
| 8942 |
|
| 8943 |
|
| 8944 |
\def\macro #1{\the\numexpr 9-#1\relax} |
| 8945 |
|
| 8946 |
\csa{xintApply}|{\macro}|\marg{list}\etype{ff} expandably applies the one |
| 8947 |
parameter macro |\macro| to each item in the \meta{list} given as second |
| 8948 |
argument and returns a new list with these outputs: each item is given one after |
| 8949 |
the other as parameter to |\macro| which is expanded at that time (as usual, |
| 8950 |
\emph{i.e.\@} fully for what comes first), the results are braced and output |
| 8951 |
together as a succession of braced items (if |\macro| is defined to start with a |
| 8952 |
space, the space will be gobbled and the |\macro| will not be expanded; it is |
| 8953 |
allowed to have its own arguments, the list items serve as last arguments to |
| 8954 |
|\macro|). Hence |\xintApply{\macro}{{1}{2}{3}}| returns |
| 8955 |
|{\macro{1}}{\macro{2}}{\macro{3}}| where all instances of |\macro| have been |
| 8956 |
already \fexpan ded. |
| 8957 |
|
| 8958 |
Being expandable, |\xintApply| is useful for example inside alignments where |
| 8959 |
implicit groups make standard loops constructs usually fail. In such situation |
| 8960 |
it is often not wished that the new list elements be braced, see |
| 8961 |
\csbxint{ApplyUnbraced}. The |\macro| does not have to be expandable: |
| 8962 |
|\xintApply| will try to expand it, the expansion may remain partial. |
| 8963 |
|
| 8964 |
The \meta{list} may |
| 8965 |
itself be some macro expanding (in the previously described way) to the list of |
| 8966 |
tokens to which the macro |\macro| will be applied. For example, if the |
| 8967 |
\meta{list} expands to some positive number, then each digit will be replaced by |
| 8968 |
the result of applying |\macro| on it. % |
| 8969 |
% |
| 8970 |
\leftedline{|\def\macro #1{\the\numexpr |
| 8971 |
9-#1\relax}|} % |
| 8972 |
% |
| 8973 |
\leftedline{|\xintApply\macro{\xintiiFac |
| 8974 |
{20}}|\dtt{=\xintApply\macro{\xintiiFac {20}}}} |
| 8975 |
|
| 8976 |
The macro \csa{xintApplyNoExpand}\etype{fn} does the same job without the first |
| 8977 |
initial expansion which gave the \meta{list} of braced tokens to which |\macro| |
| 8978 |
is applied. |
| 8979 |
|
| 8980 |
\subsection{\csh{xintApplyUnbraced}}\label{xintApplyUnbraced} |
| 8981 |
|
| 8982 |
|
| 8983 |
\csa{xintApplyUnbraced}|{\macro}|\marg{list}\etype{ff} is like \csbxint{Apply}. |
| 8984 |
The difference is that after having expanded its list argument, and applied |
| 8985 |
|\macro| in turn to each item from the list, it reassembles the outputs without |
| 8986 |
enclosing them in braces. The net effect is the same as doing |
| 8987 |
% |
| 8988 |
\leftedline{|\xintListWithSep {}{\xintApply {\macro}|\marg{list}|}|} This is |
| 8989 |
useful for preparing a macro which will itself define some other macros or make |
| 8990 |
assignments, as the scope will not be limited by brace pairs. |
| 8991 |
% |
| 8992 |
\begin{everbatim*} |
| 8993 |
\def\macro #1{\expandafter\def\csname myself#1\endcsname {#1}} |
| 8994 |
\xintApplyUnbraced\macro{{elta}{eltb}{eltc}} |
| 8995 |
\begin{enumerate}[nosep,label=(\arabic{*})] |
| 8996 |
\item \meaning\myselfelta |
| 8997 |
\item \meaning\myselfeltb |
| 8998 |
\item \meaning\myselfeltc |
| 8999 |
\end{enumerate} |
| 9000 |
\end{everbatim*} |
| 9001 |
|
| 9002 |
% |
| 9003 |
The macro \csa{xintApplyUnbracedNoExpand}\etype{fn} does the same job without |
| 9004 |
the first initial expansion which gave the \meta{list} of braced tokens to which |
| 9005 |
|\macro| is applied. |
| 9006 |
|
| 9007 |
\subsection{\csh{xintSeq}}\label{xintSeq} |
| 9008 |
|
| 9009 |
\csa{xintSeq}|[d]{x}{y}|\etype{{{\upshape[\numx]}}\numx\numx} generates |
| 9010 |
expandably |{x}{x+d}...| up to and possibly including |{y}| if |d>0| or down |
| 9011 |
to and including |{y}| if |d<0|. Naturally |{y}| is omitted if |y-x| is not a |
| 9012 |
multiple of |d|. If |d=0| the macro returns |{x}|. If |y-x| and |d| have |
| 9013 |
opposite signs, the macro returns nothing. If the optional argument |d| is |
| 9014 |
omitted it is taken to be the sign of |y-x|. Hence |\xintSeq {1}{0}| is not |
| 9015 |
empty but |{1}{0}|. But |\xintSeq [1]{1}{0}| is empty. |
| 9016 |
|
| 9017 |
|
| 9018 |
The arguments |x| and |y| are expanded inside a |\numexpr| so they may be |
| 9019 |
count registers or a \LaTeX{} |\value{countername}|, or arithmetic with such |
| 9020 |
things. |
| 9021 |
|
| 9022 |
% |
| 9023 |
\begin{everbatim*} |
| 9024 |
\xintListWithSep{,\hskip2pt plus 1pt minus 1pt }{\xintSeq {12}{-25}} |
| 9025 |
\end{everbatim*} |
| 9026 |
% |
| 9027 |
\begin{everbatim*} |
| 9028 |
\xintiiSum{\xintSeq [3]{1}{1000}} |
| 9029 |
\end{everbatim*} |
| 9030 |
|
| 9031 |
When the macro is used without the optional argument |d|, it can only generate |
| 9032 |
up to about $5000$ numbers\IMPORTANT, the precise value depends upon some |
| 9033 |
\TeX{} memory parameter (input save stack). |
| 9034 |
|
| 9035 |
With the optional argument |d| the macro proceeds differently (but less |
| 9036 |
efficiently) and does not stress the input save stack. |
| 9037 |
|
| 9038 |
|
| 9039 |
|
| 9040 |
\subsection{\csh{xintloop}, \csh{xintbreakloop}, \csh{xintbreakloopanddo}, \csh{xintloopskiptonext}} |
| 9041 |
\label{xintloop} |
| 9042 |
\label{xintbreakloop} |
| 9043 |
\label{xintbreakloopanddo} |
| 9044 |
\label{xintloopskiptonext} |
| 9045 |
|
| 9046 |
|\xintloop|\meta{stuff}|\if<test>...\repeat|\xtype{} is an expandable loop |
| 9047 |
compatible with nesting. However to break out of the loop one almost always need |
| 9048 |
some un-expandable step. The cousin \csbxint{iloop} is \csbxint{loop} with an |
| 9049 |
embedded expandable mechanism allowing to exit from the loop. The iterated |
| 9050 |
macros may contain |\par| tokens or empty lines. |
| 9051 |
|
| 9052 |
If a sub-loop is to be used all the material from the start of the main loop and |
| 9053 |
up to the end of the entire subloop should be braced; these braces will be |
| 9054 |
removed and do not create a group. The simplest to allow the nesting of one or |
| 9055 |
more sub-loops is to brace everything between \csa{xintloop} and \csa{repeat}, |
| 9056 |
being careful not to leave a space between the closing brace and |\repeat|. |
| 9057 |
|
| 9058 |
As this loop and \csbxint{iloop} will primarily be of interest to experienced |
| 9059 |
\TeX{} macro programmers, my description will assume that the user is |
| 9060 |
knowledgeable enough. Some examples in this document will be perhaps more |
| 9061 |
illustrative than my attemps at explanation of use. |
| 9062 |
|
| 9063 |
One can abort the loop with \csbxint{breakloop}; this should not be used inside |
| 9064 |
the final test, and one should expand the |\fi| from the corresponding test |
| 9065 |
before. One has also \csbxint{breakloopanddo} whose first argument will be |
| 9066 |
inserted in the token stream after the loop; one may need a macro such as |
| 9067 |
|\xint_afterfi| to move the whole thing after the |\fi|, as a simple |
| 9068 |
|\expandafter| will not be enough. |
| 9069 |
|
| 9070 |
One will usually employ some count registers to manage the exit test from the |
| 9071 |
loop; this breaks expandability, see \csbxint{iloop} for an expandable integer |
| 9072 |
indexed loop. Use in alignments will be complicated by the fact that cells |
| 9073 |
create groups, and also from the fact that any encountered unexpandable material |
| 9074 |
will cause the \TeX{} input scanner to insert |\endtemplate| on each encountered |
| 9075 |
|&| or |\cr|; thus |\xintbreakloop| may not work as expected, but the situation |
| 9076 |
can be resolved via |\xint_firstofone{&}| or use of |\TAB| with |\def\TAB{&}|. |
| 9077 |
It is thus simpler for alignments to use rather than \csbxint{loop} either the |
| 9078 |
expandable \csbxint{ApplyUnbraced} or the non-expandable but alignment |
| 9079 |
compatible \csbxint{ApplyInline}, \csbxint{For} or \csbxint{For*}. |
| 9080 |
|
| 9081 |
As an example, let us suppose we have two macros |\A|\marg{i}\marg{j} and |
| 9082 |
|\B|\marg{i}\marg{j} behaving like (small) integer valued matrix entries, and we |
| 9083 |
want to define a macro |\C|\marg{i}\marg{j} giving the matrix product (|i| and |
| 9084 |
|j| may be count registers). We will assume that |\A[I]| expands to the number |
| 9085 |
of rows, |\A[J]| to the number of columns and want the produced |\C| to act in |
| 9086 |
the same manner. The code is very dispendious in use of |\count| registers, not |
| 9087 |
optimized in any way, not made very robust (the defined macro can not have the |
| 9088 |
same name as the first two matrices for example), we just wanted to quickly |
| 9089 |
illustrate use of the nesting capabilities of |\xintloop|.% |
| 9090 |
% |
| 9091 |
\footnote{for a more sophisticated implementation of matrix |
| 9092 |
multiplication, inclusive of determinants, inverses, and display |
| 9093 |
utilities, with entries big integers or decimal numbers or even |
| 9094 |
fractions see some code online posted |
| 9095 |
from |
| 9096 |
November 11, 2013.} |
| 9097 |
% |
| 9098 |
|
| 9099 |
|
| 9100 |
\begin{everbatim*} |
| 9101 |
\newcount\rowmax \newcount\colmax \newcount\summax |
| 9102 |
\newcount\rowindex \newcount\colindex \newcount\sumindex |
| 9103 |
\newcount\tmpcount |
| 9104 |
\makeatletter |
| 9105 |
\def\MatrixMultiplication #1#2#3{% |
| 9106 |
\rowmax #1[I]\relax |
| 9107 |
\colmax #2[J]\relax |
| 9108 |
\summax #1[J]\relax |
| 9109 |
\rowindex 1 |
| 9110 |
\xintloop % loop over row index i |
| 9111 |
{\colindex 1 |
| 9112 |
\xintloop % loop over col index k |
| 9113 |
{\tmpcount 0 |
| 9114 |
\sumindex 1 |
| 9115 |
\xintloop % loop over intermediate index j |
| 9116 |
\advance\tmpcount \numexpr #1\rowindex\sumindex*#2\sumindex\colindex\relax |
| 9117 |
\ifnum\sumindex<\summax |
| 9118 |
\advance\sumindex 1 |
| 9119 |
\repeat }% |
| 9120 |
\expandafter\edef\csname\string#3{\the\rowindex.\the\colindex}\endcsname |
| 9121 |
{\the\tmpcount}% |
| 9122 |
\ifnum\colindex<\colmax |
| 9123 |
\advance\colindex 1 |
| 9124 |
\repeat }% |
| 9125 |
\ifnum\rowindex<\rowmax |
| 9126 |
\advance\rowindex 1 |
| 9127 |
\repeat |
| 9128 |
\expandafter\edef\csname\string#3{I}\endcsname{\the\rowmax}% |
| 9129 |
\expandafter\edef\csname\string#3{J}\endcsname{\the\colmax}% |
| 9130 |
\def #3##1{\ifx[##1\expandafter\Matrix@helper@size |
| 9131 |
\else\expandafter\Matrix@helper@entry\fi #3{##1}}% |
| 9132 |
}% |
| 9133 |
\def\Matrix@helper@size #1#2#3]{\csname\string#1{#3}\endcsname }% |
| 9134 |
\def\Matrix@helper@entry #1#2#3% |
| 9135 |
{\csname\string#1{\the\numexpr#2.\the\numexpr#3}\endcsname }% |
| 9136 |
\def\A #1{\ifx[#1\expandafter\A@size |
| 9137 |
\else\expandafter\A@entry\fi {#1}}% |
| 9138 |
\def\A@size #1#2]{\ifx I#23\else4\fi}% 3rows, 4columns |
| 9139 |
\def\A@entry #1#2{\the\numexpr #1+#2-1\relax}% not pre-computed... |
| 9140 |
\def\B #1{\ifx[#1\expandafter\B@size |
| 9141 |
\else\expandafter\B@entry\fi {#1}}% |
| 9142 |
\def\B@size #1#2]{\ifx I#24\else3\fi}% 4rows, 3columns |
| 9143 |
\def\B@entry #1#2{\the\numexpr #1-#2\relax}% not pre-computed... |
| 9144 |
\makeatother |
| 9145 |
\MatrixMultiplication\A\B\C \MatrixMultiplication\C\C\D |
| 9146 |
\MatrixMultiplication\C\D\E \MatrixMultiplication\C\E\F |
| 9147 |
\begin{multicols}2 |
| 9148 |
\[\begin{pmatrix} |
| 9149 |
\A11&\A12&\A13&\A14\\ |
| 9150 |
\A21&\A22&\A23&\A24\\ |
| 9151 |
\A31&\A32&\A33&\A34 |
| 9152 |
\end{pmatrix} |
| 9153 |
\times |
| 9154 |
\begin{pmatrix} |
| 9155 |
\B11&\B12&\B13\\ |
| 9156 |
\B21&\B22&\B23\\ |
| 9157 |
\B31&\B32&\B33\\ |
| 9158 |
\B41&\B42&\B43 |
| 9159 |
\end{pmatrix} |
| 9160 |
= |
| 9161 |
\begin{pmatrix} |
| 9162 |
\C11&\C12&\C13\\ |
| 9163 |
\C21&\C22&\C23\\ |
| 9164 |
\C31&\C32&\C33 |
| 9165 |
\end{pmatrix}\] |
| 9166 |
\[\begin{pmatrix} |
| 9167 |
\C11&\C12&\C13\\ |
| 9168 |
\C21&\C22&\C23\\ |
| 9169 |
\C31&\C32&\C33 |
| 9170 |
\end{pmatrix}^2 = \begin{pmatrix} |
| 9171 |
\D11&\D12&\D13\\ |
| 9172 |
\D21&\D22&\D23\\ |
| 9173 |
\D31&\D32&\D33 |
| 9174 |
\end{pmatrix}\] |
| 9175 |
\[\begin{pmatrix} |
| 9176 |
\C11&\C12&\C13\\ |
| 9177 |
\C21&\C22&\C23\\ |
| 9178 |
\C31&\C32&\C33 |
| 9179 |
\end{pmatrix}^3 = \begin{pmatrix} |
| 9180 |
\E11&\E12&\E13\\ |
| 9181 |
\E21&\E22&\E23\\ |
| 9182 |
\E31&\E32&\E33 |
| 9183 |
\end{pmatrix}\] |
| 9184 |
\[\begin{pmatrix} |
| 9185 |
\C11&\C12&\C13\\ |
| 9186 |
\C21&\C22&\C23\\ |
| 9187 |
\C31&\C32&\C33 |
| 9188 |
\end{pmatrix}^4 = \begin{pmatrix} |
| 9189 |
\F11&\F12&\F13\\ |
| 9190 |
\F21&\F22&\F23\\ |
| 9191 |
\F31&\F32&\F33 |
| 9192 |
\end{pmatrix}\] |
| 9193 |
\end{multicols} |
| 9194 |
\end{everbatim*} |
| 9195 |
|
| 9196 |
|
| 9197 |
\subsection{\csh{xintiloop}, \csh{xintiloopindex}, \csh{xintouteriloopindex}, |
| 9198 |
\csh{xintbreakiloop}, \csh{xintbreakiloopanddo}, \csh{xintiloopskiptonext}, |
| 9199 |
\csh{xintiloopskipandredo}} |
| 9200 |
\label{xintiloop} |
| 9201 |
\label{xintbreakiloop} |
| 9202 |
\label{xintbreakiloopanddo} |
| 9203 |
\label{xintiloopskiptonext} |
| 9204 |
\label{xintiloopskipandredo} |
| 9205 |
\label{xintiloopindex} |
| 9206 |
\label{xintouteriloopindex} |
| 9207 |
|
| 9208 |
\csa{xintiloop}|[start+delta]|\meta{stuff}|\if<test> ... \repeat|\xtype{} is a |
| 9209 |
completely expandable nestable loop. complete expandability depends naturally on |
| 9210 |
the actual iterated contents, and complete expansion will not be achievable |
| 9211 |
under a sole \fexpan sion, as is indicated by the hollow star in the margin; |
| 9212 |
thus the loop can be used inside an |\edef| but not inside arguments to the |
| 9213 |
package macros. It can be used inside an |\xintexpr..\relax|. The |
| 9214 |
|[start+delta]| is mandatory, not optional. |
| 9215 |
|
| 9216 |
This loop benefits via \csbxint{iloopindex} to (a limited access to) the integer |
| 9217 |
index of the iteration. The starting value |start| (which may be a |\count|) and |
| 9218 |
increment |delta| (\emph{id.}) are mandatory arguments. A space after the |
| 9219 |
closing square bracket is not significant, it will be ignored. Spaces inside the |
| 9220 |
square brackets will also be ignored as the two arguments are first given to a |
| 9221 |
|\numexpr...\relax|. Empty lines and explicit |\par| tokens are accepted. |
| 9222 |
|
| 9223 |
As with \csbxint{loop}, this tool will mostly be of interest to advanced users. |
| 9224 |
For nesting, one puts inside braces all the |
| 9225 |
material from the start (immediately after |[start+delta]|) and up to and |
| 9226 |
inclusive of the inner loop, these braces will be removed and do not create a |
| 9227 |
loop. In case of nesting, \csbxint{outeriloopindex} gives access to the index of |
| 9228 |
the outer loop. If needed one could write on its model a macro giving access to |
| 9229 |
the index of the outer outer loop (or even to the |nth| outer loop). |
| 9230 |
|
| 9231 |
The \csa{xintiloopindex} and \csa{xintouteriloopindex} can not be used inside |
| 9232 |
braces, and generally speaking this means they should be expanded first when |
| 9233 |
given as argument to a macro, and that this macro receives them as delimited |
| 9234 |
arguments, not braced ones. Or, but naturally this will break expandability, one |
| 9235 |
can assign the value of \csa{xintiloopindex} to some |\count|. Both |
| 9236 |
\csa{xintiloopindex} and \csa{xintouteriloopindex} extend to the litteral |
| 9237 |
representation of the index, thus in |\ifnum| tests, if it comes last one has to |
| 9238 |
correctly end the macro with a |\space|, or encapsulate it in a |
| 9239 |
|\numexpr..\relax|. |
| 9240 |
|
| 9241 |
When the repeat-test of the loop is, for example, |\ifnum\xintiloopindex<10 |
| 9242 |
\repeat|, this means that the last iteration will be with |\xintiloopindex=10| |
| 9243 |
(assuming |delta=1|). There is also |\ifnum\xintiloopindex=10 \else\repeat| to |
| 9244 |
get the last iteration to be the one with |\xintiloopindex=10|. |
| 9245 |
|
| 9246 |
One has \csbxint{breakiloop} and \csbxint{breakiloopanddo} to abort the loop. |
| 9247 |
The syntax of |\xintbreakiloopanddo| is a bit surprising, the sequence of tokens |
| 9248 |
to be executed after breaking the loop is not within braces but is delimited by |
| 9249 |
a dot as in: |
| 9250 |
% |
| 9251 |
\leftedline{|\xintbreakiloopanddo <afterloop>.etc.. etc... \repeat|} |
| 9252 |
% |
| 9253 |
The reason is that one may wish to use the then current value of |
| 9254 |
|\xintiloopindex| in |<afterloop>| but it can't be within braces at the time it |
| 9255 |
is evaluated. However, it is not that easy as |\xintiloopindex| must be expanded |
| 9256 |
before, so one ends up with code like this: |
| 9257 |
% |
| 9258 |
\leftedline |
| 9259 |
{|\expandafter\xintbreakiloopanddo\expandafter\macro\xintiloopindex.%|} |
| 9260 |
% |
| 9261 |
\leftedline{|etc.. etc.. \repeat|} |
| 9262 |
% |
| 9263 |
As moreover the |\fi| from the test leading to the decision of breaking out of |
| 9264 |
the loop must be cleared out of the way, the above should be |
| 9265 |
a branch of an expandable conditional test, else one needs something such |
| 9266 |
as: |
| 9267 |
% |
| 9268 |
\leftedline |
| 9269 |
{|\xint_afterfi{\expandafter\xintbreakiloopanddo\expandafter\macro\xintiloopindex.}%|} |
| 9270 |
% |
| 9271 |
\leftedline{|\fi etc..etc.. \repeat|} |
| 9272 |
|
| 9273 |
There is \csbxint{iloopskiptonext} to abort the current iteration and skip to |
| 9274 |
the next, \hyperref[xintiloopskipandredo]{\ttfamily\hyphenchar\font45 \char92 |
| 9275 |
xintiloopskip\-and\-redo} to skip to the end of the current iteration and redo |
| 9276 |
it with the same value of the index (something else will have to change for this |
| 9277 |
not to become an eternal loop\dots ). |
| 9278 |
|
| 9279 |
Inside alignments, if the looped-over text contains a |&| or a |\cr|, any |
| 9280 |
un-expandable material before a \csbxint{iloopindex} will make it fail because |
| 9281 |
of |\endtemplate|; in such cases one can always either replace |&| by a macro |
| 9282 |
expanding to it or replace it by a suitable |\firstofone{&}|, and similarly for |
| 9283 |
|\cr|. |
| 9284 |
|
| 9285 |
\phantomsection\label{edefprimes} |
| 9286 |
As an example, let us construct an |\edef\z{...}| which will define |\z| to be a |
| 9287 |
list of prime numbers: |
| 9288 |
\begin{everbatim*} |
| 9289 |
\begingroup |
| 9290 |
\edef\z |
| 9291 |
{\xintiloop [10001+2] |
| 9292 |
{\xintiloop [3+2] |
| 9293 |
\ifnum\xintouteriloopindex<\numexpr\xintiloopindex*\xintiloopindex\relax |
| 9294 |
\xintouteriloopindex, |
| 9295 |
\expandafter\xintbreakiloop |
| 9296 |
\fi |
| 9297 |
\ifnum\xintouteriloopindex=\numexpr |
| 9298 |
(\xintouteriloopindex/\xintiloopindex)*\xintiloopindex\relax |
| 9299 |
\else |
| 9300 |
\repeat |
| 9301 |
}% no space here |
| 9302 |
\ifnum \xintiloopindex < 10999 \repeat }% |
| 9303 |
\meaning\z\endgroup |
| 9304 |
\end{everbatim*}and we should have taken |
| 9305 |
some steps to not have a trailing comma, but |
| 9306 |
the point was to show that one can do that in an |\edef|\,! See also |
| 9307 |
\autoref{ssec:primesII} which extracts from this code its way of testing |
| 9308 |
primality. |
| 9309 |
|
| 9310 |
Let us create an alignment where each row will contain all divisors of its |
| 9311 |
first entry. |
| 9312 |
Here is the output, thus obtained without any count register: |
| 9313 |
\begin{everbatim*} |
| 9314 |
\begin{multicols}2 |
| 9315 |
\tabskip1ex \normalcolor |
| 9316 |
\halign{&\hfil#\hfil\cr |
| 9317 |
\xintiloop [1+1] |
| 9318 |
{\expandafter\bfseries\xintiloopindex & |
| 9319 |
\xintiloop [1+1] |
| 9320 |
\ifnum\xintouteriloopindex=\numexpr |
| 9321 |
(\xintouteriloopindex/\xintiloopindex)*\xintiloopindex\relax |
| 9322 |
\xintiloopindex&\fi |
| 9323 |
\ifnum\xintiloopindex<\xintouteriloopindex\space % CRUCIAL \space HERE |
| 9324 |
\repeat \cr }% |
| 9325 |
\ifnum\xintiloopindex<30 |
| 9326 |
\repeat |
| 9327 |
} |
| 9328 |
\end{multicols} |
| 9329 |
\end{everbatim*} |
| 9330 |
We wanted this first entry in bold face, but |\bfseries| leads to |
| 9331 |
unexpandable tokens, so the |\expandafter| was necessary for |\xintiloopindex| |
| 9332 |
and |\xintouteriloopindex| not to be confronted with a hard to digest |
| 9333 |
|\endtemplate|. An alternative way of coding: |
| 9334 |
% |
| 9335 |
\begin{everbatim} |
| 9336 |
\tabskip1ex |
| 9337 |
\def\firstofone #1{#1}% |
| 9338 |
\halign{&\hfil#\hfil\cr |
| 9339 |
\xintiloop [1+1] |
| 9340 |
{\bfseries\xintiloopindex\firstofone{&}% |
| 9341 |
\xintiloop [1+1] \ifnum\xintouteriloopindex=\numexpr |
| 9342 |
(\xintouteriloopindex/\xintiloopindex)*\xintiloopindex\relax |
| 9343 |
\xintiloopindex\firstofone{&}\fi |
| 9344 |
\ifnum\xintiloopindex<\xintouteriloopindex\space % \space is CRUCIAL |
| 9345 |
\repeat \firstofone{\cr}}% |
| 9346 |
\ifnum\xintiloopindex<30 \repeat } |
| 9347 |
\end{everbatim} |
| 9348 |
|
| 9349 |
\begin{framed} |
| 9350 |
The next utilities are not compatible with expansion-only context. |
| 9351 |
\end{framed} |
| 9352 |
|
| 9353 |
\subsection{\csh{xintApplyInline}}\label{xintApplyInline} |
| 9354 |
|
| 9355 |
|
| 9356 |
\csa{xintApplyInline}|{\macro}|\marg{list}\ntype{o{\lowast f}} works non |
| 9357 |
expandably. It applies the one-parameter |\macro| to the first element of the |
| 9358 |
expanded list (|\macro| may have itself some arguments, the list item will be |
| 9359 |
appended as last argument), and is then re-inserted in the input stream after |
| 9360 |
the tokens resulting from this first expansion of |\macro|. The next item is |
| 9361 |
then handled. |
| 9362 |
|
| 9363 |
This is to be used in situations where one needs to do some repetitive |
| 9364 |
things. It is not expandable and can not be completely expanded inside a |
| 9365 |
macro definition, to prepare material for later execution, contrarily to what |
| 9366 |
\csbxint{Apply} or \csbxint{ApplyUnbraced} achieve. |
| 9367 |
|
| 9368 |
\begin{everbatim*} |
| 9369 |
\def\Macro #1{\advance\cnta #1 , \the\cnta} |
| 9370 |
\cnta 0 |
| 9371 |
0\xintApplyInline\Macro {3141592653}. |
| 9372 |
\end{everbatim*} |
| 9373 |
The first argument |\macro| does not have to be an expandable macro. |
| 9374 |
|
| 9375 |
\csa{xintApplyInline} submits its second, token list parameter to an |
| 9376 |
\hyperref[ssec:expansions]{\fexpan |
| 9377 |
sion}. Then, each \emph{unbraced} item will also be \fexpan ded. This provides |
| 9378 |
an easy way to insert one list inside another. \emph{Braced} items are not |
| 9379 |
expanded. Spaces in-between items are gobbled (as well as those at the start |
| 9380 |
or the end of the list), but not the spaces \emph{inside} the braced items. |
| 9381 |
|
| 9382 |
\csa{xintApplyInline}, despite being non-expandable, does survive to |
| 9383 |
contexts where the executed |\macro| closes groups, as happens inside |
| 9384 |
alignments with the tabulation character |&|. |
| 9385 |
This tabular provides an example:\par |
| 9386 |
\begin{everbatim*} |
| 9387 |
\centerline{\normalcolor\begin{tabular}{ccc} |
| 9388 |
$N$ & $N^2$ & $N^3$ \\ \hline |
| 9389 |
\def\Row #1{ #1 & \xintiiSqr {#1} & \xintiiPow {#1}{3} \\ \hline }% |
| 9390 |
\xintApplyInline \Row {\xintCSVtoList{17,28,39,50,61}} |
| 9391 |
\end{tabular}}\medskip |
| 9392 |
\end{everbatim*} |
| 9393 |
|
| 9394 |
We see that despite the fact that the first encountered tabulation character in |
| 9395 |
the first row close a group and thus erases |\Row| from \TeX's memory, |
| 9396 |
|\xintApplyInline| knows how to deal with this. |
| 9397 |
|
| 9398 |
Using \csbxint{ApplyUnbraced} is an alternative: the difference is that |
| 9399 |
this would have prepared all rows first and only put them back into the |
| 9400 |
token stream once they are all assembled, whereas with |\xintApplyInline| |
| 9401 |
each row is constructed and immediately fed back into the token stream: when |
| 9402 |
one does things with numbers having hundreds of digits, one learns that |
| 9403 |
keeping on hold and shuffling around hundreds of tokens has an impact on |
| 9404 |
\TeX{}'s speed (make this ``thousands of tokens'' for the impact to be |
| 9405 |
noticeable). |
| 9406 |
|
| 9407 |
One may nest various |\xintApplyInline|'s. For example (see the |
| 9408 |
\hyperref[float]{table} \vpageref{float}):\par |
| 9409 |
\begin{everbatim*} |
| 9410 |
\begin{figure*}[ht!] |
| 9411 |
\centering\phantomsection\label{float} |
| 9412 |
\def\Row #1{#1:\xintApplyInline {\Item {#1}}{0123456789}\\ }% |
| 9413 |
\def\Item #1#2{&\xintiiPow {#1}{#2}}% |
| 9414 |
\centeredline {\begin{tabular}{ccccccccccc} &0&1&2&3&4&5&6&7&8&9\\ \hline |
| 9415 |
\xintApplyInline \Row {0123456789} |
| 9416 |
\end{tabular}} |
| 9417 |
\end{figure*} |
| 9418 |
\end{everbatim*} |
| 9419 |
|
| 9420 |
One could not move the definition of |\Item| inside the tabular, |
| 9421 |
as it would get lost after the first |&|. But this |
| 9422 |
works: |
| 9423 |
\everb|@ |
| 9424 |
\begin{tabular}{ccccccccccc} |
| 9425 |
&0&1&2&3&4&5&6&7&8&9\\ \hline |
| 9426 |
\def\Row #1{#1:\xintApplyInline {&\xintiiPow {#1}}{0123456789}\\ }% |
| 9427 |
\xintApplyInline \Row {0123456789} |
| 9428 |
\end{tabular} |
| 9429 |
| |
| 9430 |
|
| 9431 |
A limitation is that, contrarily to what one may have expected, the |
| 9432 |
|\macro| for an |\xintApplyInline| can not be used to define |
| 9433 |
the |\macro| for a nested sub-|\xintApplyInline|. For example, |
| 9434 |
this does not work:\par |
| 9435 |
\everb|@ |
| 9436 |
\def\Row #1{#1:\def\Item ##1{&\xintiiPow {#1}{##1}}% |
| 9437 |
\xintApplyInline \Item {0123456789}\\ }% |
| 9438 |
\xintApplyInline \Row {0123456789} % does not work |
| 9439 |
| |
| 9440 |
\noindent But see \csbxint{For}. |
| 9441 |
|
| 9442 |
\subsection{\csh{xintFor}, \csh{xintFor*}}\label{xintFor}\label{xintFor*} |
| 9443 |
|
| 9444 |
\csbxint{For}\ntype{on} is a new kind of for loop.\footnote{first introduced |
| 9445 |
with \xintname |1.09c| of |2013/10/09|.} Rather than using macros |
| 9446 |
for encapsulating list items, its behaviour is like a macro with parameters: |
| 9447 |
|#1|, |#2|, \dots, |#9| are used to represent the items for up to nine levels of |
| 9448 |
nested loops. Here is an example: |
| 9449 |
% |
| 9450 |
\everb|@ |
| 9451 |
\xintFor #9 in {1,2,3} \do {% |
| 9452 |
\xintFor #1 in {4,5,6} \do {% |
| 9453 |
\xintFor #3 in {7,8,9} \do {% |
| 9454 |
\xintFor #2 in {10,11,12} \do {% |
| 9455 |
$$#9\times#1\times#3\times#2=\xintiiPrd{{#1}{#2}{#3}{#9}}$$}}}} |
| 9456 |
| |
| 9457 |
\noindent This example illustrates that one does not have to use |#1| as the |
| 9458 |
first one: |
| 9459 |
the order is arbitrary. But each level of nesting should have its specific macro |
| 9460 |
parameter. Nine levels of nesting is presumably overkill, but I did not know |
| 9461 |
where it was reasonable to stop. |\par| tokens are accepted in both the comma |
| 9462 |
separated list and the replacement text. |
| 9463 |
|
| 9464 |
\begin{framed} |
| 9465 |
\TeX nical notes: |
| 9466 |
|
| 9467 |
\begin{itemize} |
| 9468 |
\item The |#1| is replaced in the iterated-over text exactly as in general |
| 9469 |
\TeX\ macros or \LaTeX\ commands. This spares the user quite a few |
| 9470 |
|\expandafter|'s or other tricks needed with loops which have the |
| 9471 |
values encapsulated in macros, like \LaTeX's |\@for| and |\@tfor|. |
| 9472 |
|
| 9473 |
\item \csa{xintFor} (and \csa{xintFor*}) isn't purely expandable: one can |
| 9474 |
not use it inside an |\edef|. But it may be used, as will be shown in |
| 9475 |
examples, in some contexts such as \LaTeX's |tabular| which are usually |
| 9476 |
hostile to non-expandable loops. |
| 9477 |
|
| 9478 |
\item \csa{xintFor} (and \csa{xintFor*}) does some assignments prior to |
| 9479 |
executing each iteration of the replacement text, but it acts purely |
| 9480 |
expandably after the last iteration, hence if for example the replacement |
| 9481 |
text ends with a |\\|, the loop can be used insided a tabular and be |
| 9482 |
followed by a |\hline| without creating the dreaded ``|Misplaced |
| 9483 |
\noalign|'' error. |
| 9484 |
|
| 9485 |
\item As stated in previous item the first iteration follows some |
| 9486 |
non-expandable internal dealings. This means for example that in \LaTeX{}, |
| 9487 |
one can not inject a |\multicolumn| in the first iteration. Sometimes one |
| 9488 |
way work around this by injecting father |&\multicolumn| or |\\ |
| 9489 |
\multicolumn|. |
| 9490 |
|
| 9491 |
\item It does not create groups. |
| 9492 |
|
| 9493 |
\item It makes no global assignments. |
| 9494 |
|
| 9495 |
\item The iterated replacement text may close a group which was opened even |
| 9496 |
before the start of the loop (typical example being with |&| in |
| 9497 |
alignments). |
| 9498 |
\begin{everbatim*} |
| 9499 |
\begin{tabular}{rccccc} |
| 9500 |
\hline |
| 9501 |
\xintFor #1 in {A, B, C} \do {% |
| 9502 |
#1:\xintFor #2 in {a, b, c, d, e} \do {&($ #2 \to #1 $)}\\ }% |
| 9503 |
\hline |
| 9504 |
\end{tabular} |
| 9505 |
\end{everbatim*} |
| 9506 |
|
| 9507 |
\item There is no facility provided which would give access to a count of |
| 9508 |
the number of iterations as it is technically not easy to do so it in a |
| 9509 |
way working with nested loops while maintaining the ``expandable after |
| 9510 |
done'' property; something in the spirit of \csbxint{iloopindex} is |
| 9511 |
possible but this approach would bring its own limitations and |
| 9512 |
complications. Hence the user is invited to update her own count or |
| 9513 |
\LaTeX{} counter or macro at each iteration, if needed. |
| 9514 |
|
| 9515 |
\item A |\macro| whose definition uses internally an \csbxint{For} loop |
| 9516 |
may be used inside another \csbxint{For} loop even if the two loops both |
| 9517 |
use the same macro parameter. The loop definition inside |\macro| |
| 9518 |
must use |##| as is the general rule for definitions done inside macros. |
| 9519 |
|
| 9520 |
\item \csbxint{For} is for comma separated values and \csbxint{For*} for |
| 9521 |
lists of braced items; their respective expansion policies differ. They |
| 9522 |
are described later. |
| 9523 |
\end{itemize} |
| 9524 |
\unskip |
| 9525 |
\end{framed} |
| 9526 |
|
| 9527 |
\noindent Regarding \csbxint{For}: |
| 9528 |
\begin{itemize}[nosep, listparindent=\leftmarginiii] |
| 9529 |
\item the spaces between the various declarative elements are all optional, |
| 9530 |
\item in the list of comma separated values, spaces around the commas or at |
| 9531 |
the start and end are ignored, |
| 9532 |
\item if an item must contain itself its own commas, then it should |
| 9533 |
be braced, and the braces will be removed before feeding the iterated-over |
| 9534 |
text, |
| 9535 |
\item the list may be a macro, it is expanded only once, |
| 9536 |
\item items are not pre-expanded. The first item should be braced or start |
| 9537 |
with a space if the list is explicit and the item should not be |
| 9538 |
pre-expanded, |
| 9539 |
\item empty items give empty |#1|'s in the replacement text, they are not |
| 9540 |
skipped, |
| 9541 |
\item an empty list executes once the replacement text with an empty parameter |
| 9542 |
value, |
| 9543 |
\item the list, if not a macro, \fbox{must be braced.} |
| 9544 |
\end{itemize} |
| 9545 |
|
| 9546 |
\noindent Regarding \csbxint{For*}:\ntype{{\lowast f}n} |
| 9547 |
\begin{itemize}[nosep, listparindent=\leftmarginiii] |
| 9548 |
\item it handles lists of braced items (or naked tokens), |
| 9549 |
\item it \hyperref[ssec:expansions]{\fexpan ds} the list, |
| 9550 |
\item and more generally it \hyperref[ssec:expansions]{\fexpan ds} each naked |
| 9551 |
token encountered |
| 9552 |
before assigning the |#1| values (gobbling spaces in the process); |
| 9553 |
this |
| 9554 |
makes it easy to simulate concatenation of multiple lists|\x|, |\y|: |
| 9555 |
if |\x| expands to |{1}{2}{3}| and |\y| expands to |{4}{5}{6}| then |{\x\y}| |
| 9556 |
as argument to |\xintFor*| has the same effect as |{{1}{2}{3}{4}{5}{6}}|. |
| 9557 |
|
| 9558 |
For a further illustration see the use of |\xintFor*| at the end of |
| 9559 |
\autoref{ssec:fibonacci}. |
| 9560 |
\item spaces at the start, end, or in-between items are gobbled (but naturally |
| 9561 |
not the spaces inside \emph{braced} items), |
| 9562 |
\item except if the list argument is a macro (with no parameters), \fbox{it |
| 9563 |
must be braced.}, |
| 9564 |
\item an empty list leads to an empty result. |
| 9565 |
\end{itemize} |
| 9566 |
|
| 9567 |
The macro \csbxint{Seq} which generates arithmetic sequences is to be used |
| 9568 |
with \csbxint{For*} as its output consists of successive braced numbers (given |
| 9569 |
as digit tokens). |
| 9570 |
\begin{everbatim*} |
| 9571 |
\xintFor* #1 in {\xintSeq [+2]{-7}{+2}}\do {stuff |
| 9572 |
with #1\xintifForLast{\par}{\newline}} |
| 9573 |
\end{everbatim*} |
| 9574 |
|
| 9575 |
|
| 9576 |
When nesting \csa{xintFor*} loops, using \csa{xintSeq} in the inner loops is |
| 9577 |
inefficient, as the arithmetic sequence will be re-created each time. A more |
| 9578 |
efficient style is: |
| 9579 |
% |
| 9580 |
\begin{everbatim} |
| 9581 |
\edef\innersequence {\xintSeq[+2]{-50}{50}}% |
| 9582 |
\xintFor* #1 in {\xintSeq {13}{27}} \do |
| 9583 |
{\xintFor* #2 in \innersequence \do {stuff with #1 and #2}% |
| 9584 |
.. some other macros .. } |
| 9585 |
\end{everbatim} |
| 9586 |
|
| 9587 |
This is a general remark applying for any nesting of loops, one should avoid |
| 9588 |
recreating the inner lists of arguments at each iteration of the outer loop. |
| 9589 |
|
| 9590 |
|
| 9591 |
When the loop is defined inside a macro for later execution the |#| characters |
| 9592 |
must be doubled.% |
| 9593 |
% |
| 9594 |
\footnote{sometimes what seems to be a macro argument isn't really; in |
| 9595 |
\csa{raisebox\{1cm\}\{}\csa{xintFor \#1 in \{a,b,c\} }\csa{do |
| 9596 |
\{\#1\}\}} no doubling should be done.} |
| 9597 |
% |
| 9598 |
For example: |
| 9599 |
% |
| 9600 |
\begin{everbatim*} |
| 9601 |
\def\T{\def\z {}% |
| 9602 |
\xintFor* ##1 in {{u}{v}{w}} \do {% |
| 9603 |
\xintFor ##2 in {x,y,z} \do {% |
| 9604 |
\expandafter\def\expandafter\z\expandafter {\z\sep (##1,##2)} }% |
| 9605 |
}% |
| 9606 |
}% |
| 9607 |
\T\def\sep {\def\sep{, }}\z |
| 9608 |
\end{everbatim*} |
| 9609 |
|
| 9610 |
Similarly when the replacement text |
| 9611 |
of |\xintFor| defines a macro with parameters, the macro character |#| must be |
| 9612 |
doubled. |
| 9613 |
|
| 9614 |
|
| 9615 |
The iterated macros as well as the list items are allowed to contain explicit |
| 9616 |
|\par| tokens. |
| 9617 |
|
| 9618 |
|
| 9619 |
\subsection{\csh{xintifForFirst}, \csh{xintifForLast}} |
| 9620 |
\label{xintifForFirst}\label{xintifForLast} |
| 9621 |
|
| 9622 |
\csbxint{ifForFirst}\,\texttt{\{YES branch\}\{NO branch\}}\etype{nn} |
| 9623 |
and \csbxint{ifForLast}\,\texttt{\{YES |
| 9624 |
branch\}\hskip 0pt plus 0.2em \{NO branch\}}\etype{nn} execute the |YES| or |
| 9625 |
|NO| branch |
| 9626 |
if the |
| 9627 |
\csbxint{For} |
| 9628 |
or \csbxint{For*} loop is currently in its first, respectively last, iteration. |
| 9629 |
|
| 9630 |
Designed to work as expected under nesting (but see frame next.) Don't forget |
| 9631 |
an empty brace pair |{}| if a branch is to do nothing. May be used multiple |
| 9632 |
times in the replacement text of the loop. |
| 9633 |
|
| 9634 |
\begin{framed} |
| 9635 |
\noindent Pay attention to these implementation features: |
| 9636 |
\begin{itemize}[nosep, listparindent=\leftmarginiii] |
| 9637 |
\item \emph{if an inner \csbxint{For} loop is positioned before the |
| 9638 |
\csb{xintifForFirst} or \csb{xintifForLast} of the outer loop it will |
| 9639 |
contaminate their settings. This applies also naturally if the inner loop |
| 9640 |
arises from the expansion of some macro located before the outer |
| 9641 |
conditionals.} |
| 9642 |
|
| 9643 |
One fix is to make sure that the outer conditionals are expanded before the |
| 9644 |
inner loop is executed, e.g. this will be the case if the inner loop is |
| 9645 |
located inside one of the branches of the conditional. |
| 9646 |
|
| 9647 |
Another approach is to enclose, if feasible, the inner loop in a group of |
| 9648 |
its own. |
| 9649 |
\item \emph{if the replacement text closes a group (e.g. from a |&| inside an |
| 9650 |
alignment), the conditionals will lose their ascribed meanings and end up |
| 9651 |
possibly undefined, depending whether there is some outer loop whose |
| 9652 |
execution started before the opening of the group.} |
| 9653 |
|
| 9654 |
The fix is to arrange things so that the conditionals are expanded |
| 9655 |
before \TeX\ encounters the closing-group token. |
| 9656 |
\end{itemize} |
| 9657 |
\end{framed} |
| 9658 |
|
| 9659 |
\subsection{ \csh{xintBreakFor}, \csh{xintBreakForAndDo}} |
| 9660 |
\label{xintBreakFor}\label{xintBreakForAndDo} |
| 9661 |
|
| 9662 |
One may immediately terminate an \csbxint{For} or \csbxint{For*} loop with |
| 9663 |
\csbxint{BreakFor}. |
| 9664 |
|
| 9665 |
\begin{framed} |
| 9666 |
As it acts by clearing up all the rest of the replacement text when |
| 9667 |
encountered, it will not work from inside some |\if...\fi| without |
| 9668 |
suitable |\expandafter| or swapping technique. |
| 9669 |
|
| 9670 |
Also it can't be used from inside braces as from there it can't see the end |
| 9671 |
of the replacement text. |
| 9672 |
\end{framed} |
| 9673 |
|
| 9674 |
There is also \csbxint{BreakForAndDo}. Both are illustrated by various examples |
| 9675 |
in the next section which is devoted to ``forever'' loops. |
| 9676 |
|
| 9677 |
\subsection{\csh{xintintegers}, \csh{xintdimensions}, \csh{xintrationals}} |
| 9678 |
\label{xintegers}\label{xintintegers} |
| 9679 |
\label{xintdimensions}\label{xintrationals} |
| 9680 |
|
| 9681 |
If the list argument to \csbxint{For} (or \csbxint{For*}, both are equivalent in |
| 9682 |
this context) is \csbxint{integers} (equivalently \csbxint{egers}) or more |
| 9683 |
generally \csbxint{integers}|[||start|\allowbreak|+|\allowbreak|delta||]| |
| 9684 |
(\emph{the whole within braces}!)% |
| 9685 |
% |
| 9686 |
\footnote{the |start+delta| optional specification may have extra spaces |
| 9687 |
around the plus sign of near the square brackets, such spaces are |
| 9688 |
removed. The same applies with \csa{xintdimensions} and |
| 9689 |
\csa{xintrationals}.}, |
| 9690 |
% |
| 9691 |
then \csbxint{For} does an infinite iteration where |
| 9692 |
|#1| (or |#2|, \dots, |#9|) will run through the arithmetic sequence of (short) |
| 9693 |
integers with initial value |start| and increment |delta| (default values: |
| 9694 |
|start=1|, |delta=1|; if the optional argument is present it must contains both |
| 9695 |
of them, and they may be explicit integers, or macros or count registers). The |
| 9696 |
|#1| (or |#2|, \dots, |#9|) will stand for |\numexpr <opt sign><digits>\relax|, |
| 9697 |
and the litteral representation as a string of digits can thus be obtained as |
| 9698 |
\fbox{\csa{the\#1}} or |\number#1|. Such a |#1| can be used in an |\ifnum| test |
| 9699 |
with no need to be postfixed with a space or a |\relax| and one should |
| 9700 |
\emph{not} add them. |
| 9701 |
|
| 9702 |
If the list argument is \csbxint{dimensions} or more generally |
| 9703 |
\csbxint{dimensions}|[||start|\allowbreak|+|\allowbreak|delta||]| (\emph{within |
| 9704 |
braces}!), then |
| 9705 |
\csbxint{For} does an infinite iteration where |#1| (or |#2|, \dots, |#9|) will |
| 9706 |
run through the arithmetic sequence of dimensions with initial value |
| 9707 |
|start| and increment |delta|. Default values: |start=0pt|, |delta=1pt|; if |
| 9708 |
the optional argument is present it must contain both of them, and they may |
| 9709 |
be explicit specifications, or macros, or dimen registers, or length macros |
| 9710 |
in \LaTeX{} (the stretch and shrink components will be discarded). The |#1| |
| 9711 |
will be |\dimexpr <opt sign><digits>sp\relax|, from which one can get the |
| 9712 |
litteral (approximate) representation in points via |\the#1|. So |#1| can be |
| 9713 |
used anywhere \TeX{} expects a dimension (and there is no need in conditionals |
| 9714 |
to insert a |\relax|, and one should \emph{not} do it), and to print its value |
| 9715 |
one uses \fbox{\csa{the\#1}}. The chosen representation guarantees exact |
| 9716 |
incrementation with no rounding errors accumulating from converting into |
| 9717 |
points at each step. |
| 9718 |
|
| 9719 |
|
| 9720 |
|
| 9721 |
|
| 9722 |
|
| 9723 |
|
| 9724 |
If the list argument to \csbxint{For} (or \csbxint{For*}) is \csbxint{rationals} |
| 9725 |
or more generally |
| 9726 |
\csbxint{rationals}|[||start|\allowbreak|+|\allowbreak|delta||]| (\emph{within |
| 9727 |
braces}!), then \csbxint{For} does an infinite iteration where |#1| (or |#2|, |
| 9728 |
\dots, |#9|) will run through the arithmetic sequence of \xintfracname fractions |
| 9729 |
with initial value |start| and increment |delta| (default values: |start=1/1|, |
| 9730 |
|delta=1/1|). This loop works \emph{only with \xintfracname loaded}. if the |
| 9731 |
optional argument is present it must contain both of them, and they may be given |
| 9732 |
in any of the formats recognized by \xintfracname (fractions, decimal |
| 9733 |
numbers, numbers in scientific notations, numerators and denominators in |
| 9734 |
scientific notation, etc...) , or as macros or count registers (if they are |
| 9735 |
short integers). The |#1| (or |#2|, \dots, |#9|) will be an |a/b| fraction |
| 9736 |
(without a |[n]| part), where |
| 9737 |
the denominator |b| is the product of the denominators of |
| 9738 |
|start| and |delta| (for reasons of speed |#1| is not reduced to irreducible |
| 9739 |
form, and for another reason explained later |start| and |delta| are not put |
| 9740 |
either into irreducible form; the input may use explicitely \csa{xintIrr} to |
| 9741 |
achieve that). |
| 9742 |
\begin{everbatim*} |
| 9743 |
\begingroup\small |
| 9744 |
\noindent\parbox{\dimexpr\linewidth-3em}{\color[named]{OrangeRed}% |
| 9745 |
\xintFor #1 in {\xintrationals [10/21+1/21]} \do |
| 9746 |
{#1=\xintifInt {#1} |
| 9747 |
{\textcolor{blue}{\xintTrunc{10}{#1}}} |
| 9748 |
{\xintTrunc{10}{#1}}% display in blue if an integer |
| 9749 |
\xintifGt {#1}{1.123}{\xintBreakFor}{, }% |
| 9750 |
}} |
| 9751 |
\endgroup\smallskip |
| 9752 |
\end{everbatim*} |
| 9753 |
|
| 9754 |
\smallskip The example above confirms that computations are done exactly, and |
| 9755 |
illustrates that the two initial (reduced) denominators are not multiplied when |
| 9756 |
they are found to be equal. It is thus recommended to input |start| and |delta| |
| 9757 |
with a common smallest possible denominator, or as fixed point numbers with the |
| 9758 |
same numbers of digits after the decimal mark; and this is also the reason why |
| 9759 |
|start| and |delta| are not by default made irreducible. As internally the |
| 9760 |
computations are done with numerators and denominators completely expanded, one |
| 9761 |
should be careful not to input numbers in scientific notation with exponents in |
| 9762 |
the hundreds, as they will get converted into as many zeroes. |
| 9763 |
|
| 9764 |
\begin{everbatim*} |
| 9765 |
\noindent\parbox{\dimexpr.7\linewidth}{\raggedright |
| 9766 |
\xintFor #1 in {\xintrationals [0.000+0.125]} \do |
| 9767 |
{\edef\tmp{\xintTrunc{3}{#1}}% |
| 9768 |
\xintifInt {#1} |
| 9769 |
{\textcolor{blue}{\tmp}} |
| 9770 |
{\tmp}% |
| 9771 |
\xintifGt {#1}{2}{\xintBreakFor}{, }% |
| 9772 |
}}\smallskip |
| 9773 |
\end{everbatim*} |
| 9774 |
|
| 9775 |
We see here that \csbxint{Trunc} outputs (deliberately) zero as $0$, not (here) |
| 9776 |
$0.000$, the idea being not to lose the information that the truncated thing was |
| 9777 |
truly zero. Perhaps this behaviour should be changed? or made optional? Anyhow |
| 9778 |
printing of fixed points numbers should be dealt with via dedicated packages |
| 9779 |
such as |numprint| or |siunitx|.\par |
| 9780 |
|
| 9781 |
|
| 9782 |
\subsection{\csh{xintForpair}, \csh{xintForthree}, \csh{xintForfour}}\label{xintForpair}\label{xintForthree}\label{xintForfour} |
| 9783 |
|
| 9784 |
The syntax\ntype{on} is illustrated in this |
| 9785 |
example. The notation is the usual one for |n|-uples, with parentheses and |
| 9786 |
commas. Spaces around commas and parentheses are ignored. |
| 9787 |
% |
| 9788 |
\begin{everbatim*} |
| 9789 |
{\centering\begin{tabular}{cccc} |
| 9790 |
\xintForpair #1#2 in { ( A , a ) , ( B , b ) , ( C , c ) } \do {% |
| 9791 |
\xintForpair #3#4 in { ( X , x ) , ( Y , y ) , ( Z , z ) } \do {% |
| 9792 |
$\Biggl($\begin{tabular}{cc} |
| 9793 |
-#1- & -#3-\\ |
| 9794 |
-#4- & -#2-\\ |
| 9795 |
\end{tabular}$\Biggr)$&}\\\noalign{\vskip1\jot}}% |
| 9796 |
\end{tabular}\\} |
| 9797 |
\end{everbatim*} |
| 9798 |
|
| 9799 |
\csbxint{Forpair} must be followed by either |#1#2|, |#2#3|, |#3#4|, \dots, or |
| 9800 |
|#8#9| with |#1| usable as an alias for |#1#2|, |#2| as alias for |#2#3|, |
| 9801 |
etc \dots\ and similarly for \csbxint{Forthree} (using |#1#2#3| or simply |
| 9802 |
|#1|, |#2#3#4| or simply |#2|, \dots) and \csbxint{Forfour} (with |#1#2#3#4| |
| 9803 |
etc\dots). |
| 9804 |
|
| 9805 |
Nesting works as long as the macro parameters are distinct among |#1|, |#2|, |
| 9806 |
..., |#9|. A macro which expands to an \csa{xintFor} or a |
| 9807 |
\csa{xintFor(pair,three,four)} can be used in another one with no constraint |
| 9808 |
about using distinct macro parameters. |
| 9809 |
|
| 9810 |
|\par| tokens are accepted in both the comma separated list and the |
| 9811 |
replacement text. |
| 9812 |
|
| 9813 |
|
| 9814 |
\subsection{\csh{xintAssign}}\label{xintAssign} |
| 9815 |
|
| 9816 |
\csa{xintAssign}\meta{braced things}\csa{to}% |
| 9817 |
\meta{as many cs as they are things} %\ntype{{(f$\to$\lowast [x)}{\lowast N}} |
| 9818 |
% |
| 9819 |
defines (without checking if something gets overwritten) the control sequences |
| 9820 |
on the right of \csa{to} to expand to the successive tokens or braced items |
| 9821 |
located to the left of \csa{to}. \csa{xintAssign} is not an expandable macro. |
| 9822 |
|
| 9823 |
\fexpan sion is first applied to the material in front of \csa{xintAssign} |
| 9824 |
which is fetched as one argument if it is braced. Then the expansion of this |
| 9825 |
argument is examined and successive items are assigned to the macros following |
| 9826 |
|\to|. There must be exactly as many macros as items. No check is done. The |
| 9827 |
macro assignments are done with removal of one level of brace pairs from each |
| 9828 |
item. |
| 9829 |
|
| 9830 |
After the initial \fexpan sion, each assigned (brace-stripped) item will be |
| 9831 |
expanded according to the setting of the optional parameter. |
| 9832 |
|
| 9833 |
For example |\xintAssign [e]...| means that all assignments are done using |
| 9834 |
|\edef|. With |[f]| the assignments will be made using |
| 9835 |
\hyperref[fdef]{\ttfamily\char92fdef}. The default is simply to make the |
| 9836 |
definitions with |\def|, corresponding to an empty optional paramter |[]|. |
| 9837 |
Possibilities for the optional parameter are: |[], [g], [e], [x], [o], [go], |
| 9838 |
[oo], [goo], [f], [gf]|. For example |[oo]| means a double expansion. |
| 9839 |
\begin{everbatim*} |
| 9840 |
\xintAssign \xintiiDivision{1000000000000}{133333333}\to\Q\R |
| 9841 |
\meaning\Q\newline |
| 9842 |
\meaning\R\newline |
| 9843 |
\xintAssign {{\xintiiDivision{1000000000000}{133333333}}}\to\X |
| 9844 |
\meaning\X\newline |
| 9845 |
\xintAssign [oo]{{\xintiiDivision{1000000000000}{133333333}}}\to\X |
| 9846 |
\meaning\X\newline |
| 9847 |
\xintAssign \xintiiPow{7}{13}\to\SevenToThePowerThirteen |
| 9848 |
\meaning\SevenToThePowerThirteen\par |
| 9849 |
\end{everbatim*} |
| 9850 |
|
| 9851 |
Two special cases: |
| 9852 |
\begin{itemize}[nosep] |
| 9853 |
\item if after this initial expansion no brace is found immediately after |
| 9854 |
\csa{xintAssign}, it is assumed that there is only one control sequence |
| 9855 |
following |\to|, and this control sequence is then defined via |\def| (or |
| 9856 |
what is set-up by the optional parameter) to expand to the material between |
| 9857 |
\csa{xintAssign} and \csa{to}. |
| 9858 |
\item if the material between \csa{xintAssign} and |\to| is enclosed in two |
| 9859 |
brace pairs, the first brace pair is removed, then the \fexpan sion is |
| 9860 |
immediately stopped by the inner brace pair, hence \csa{xintAssign} now |
| 9861 |
finds a unique item and thus defines only a single macro to be this item, |
| 9862 |
which is now stripped of the second pair of braces. |
| 9863 |
\end{itemize} |
| 9864 |
|
| 9865 |
|
| 9866 |
\emph{Note:} prior to release |1.09j|, |\xintAssign| did an |\edef| by default |
| 9867 |
for each item assignment but it now does |\def| corresponding to no or empty |
| 9868 |
optional parameter. |
| 9869 |
|
| 9870 |
It is allowed for the successive braced items to be separated by spaces. They |
| 9871 |
are removed during the assignments. But if a single macro is defined (which |
| 9872 |
happens if the argument after \fexpan sion does not start with a brace), |
| 9873 |
naturally the scooped up material has all intervening spaces, as it is |
| 9874 |
considered a |
| 9875 |
single item. But an upfront initial space will have been absorbed by \fexpan |
| 9876 |
sion. |
| 9877 |
\begin{everbatim*} |
| 9878 |
\def\X{ {a} {b} {c} {d} }\def\Y { u {a} {b} {c} {d} } |
| 9879 |
\xintAssign\X\to\A\B\C\D |
| 9880 |
\xintAssign\Y\to\Z |
| 9881 |
\meaning\A, \meaning\B, \meaning\C, \meaning\D+++\newline |
| 9882 |
\meaning\Z+++\par |
| 9883 |
\end{everbatim*} |
| 9884 |
As usual successive space characters in input make for a single \TeX\ space token. |
| 9885 |
|
| 9886 |
|
| 9887 |
\subsection{\csh{xintAssignArray}}\label{xintAssignArray} |
| 9888 |
|
| 9889 |
\xintAssignArray \xintBezout {1000}{113}\to\Bez |
| 9890 |
|
| 9891 |
\csa{xintAssignArray}\meta{braced things}\csa{to}\csa{myArray} |
| 9892 |
% |
| 9893 |
%\ntype{{(f$\to$\lowast x)}N} |
| 9894 |
% |
| 9895 |
first expands fully what comes immediately after |\xintAssignArray| and |
| 9896 |
expects to find a list of braced things |{A}{B}...| (or tokens). It then |
| 9897 |
defines \csa{myArray} as a macro with one parameter, such that \csa{myArray\x} |
| 9898 |
expands to give the |x|th braced thing of this original |
| 9899 |
list (the argument \texttt{\x} itself is fed to a |\numexpr| by |\myArray|, |
| 9900 |
and |\myArray| expands in two steps to its output). With |0| as parameter, |
| 9901 |
\csa{myArray}|{0}| returns the number |M| of elements of the array so that the |
| 9902 |
successive elements are \csa{myArray}|{1}|, \dots, \csa{myArray}|{M}|. |
| 9903 |
% |
| 9904 |
\leftedline{|\xintAssignArray \xintBezout {1000}{113}\to\Bez|} will set |
| 9905 |
|\Bez{0}| to \dtt{\Bez0}, |\Bez{1}| to \dtt{\Bez1}, |\Bez{2}| to |
| 9906 |
\dtt{\Bez2}, and |\Bez{3}| to \dtt{\Bez3}: |
| 9907 |
\dtt{$\Bez1\times1000+\Bez2\times113=\Bez3$.} |
| 9908 |
This macro is incompatible with expansion-only contexts. |
| 9909 |
|
| 9910 |
\csa{xintAssignArray} admits an optional parameter, for example |
| 9911 |
|\xintAssignArray [e]| means that the definitions of the macros will be made |
| 9912 |
with |\edef|. The empty optional parameter (default) means that definitions |
| 9913 |
are done with |\def|. Other possibilities: |[], [o], [oo], [f]|. Contrarily to |
| 9914 |
\csbxint{Assign} one can not use the |g| here to make the definitions global. |
| 9915 |
For this, one should rather do |\xintAssignArray| within a group starting with |
| 9916 |
|\globaldefs 1|. |
| 9917 |
|
| 9918 |
|
| 9919 |
\subsection{\csh{xintDigitsOf}}\label{xintDigitsOf} |
| 9920 |
|
| 9921 |
This is a synonym for \csbxint{AssignArray},\ntype{fN} to be used to define |
| 9922 |
an array giving all the digits of a given (positive, else the minus sign will |
| 9923 |
be treated as first item) number. |
| 9924 |
\begingroup\xintDigitsOf\xintiiPow {7}{500}\to\digits |
| 9925 |
% |
| 9926 |
\leftedline{|\xintDigitsOf\xintiiPow {7}{500}\to\digits|} |
| 9927 |
\noindent $7^{500}$ has |\digits{0}=|\digits{0} digits, and the 123rd among them |
| 9928 |
(starting from the most significant) is |
| 9929 |
|\digits{123}=|\digits{123}. |
| 9930 |
\endgroup |
| 9931 |
|
| 9932 |
\subsection{\csh{xintRelaxArray}}\label{xintRelaxArray} |
| 9933 |
|
| 9934 |
\csa{xintRelaxArray}\csa{myArray} %\ntype{N} |
| 9935 |
% |
| 9936 |
(globally) sets to \csa{relax} all macros which were defined by the previous |
| 9937 |
\csa{xintAssignArray} with \csa{myArray} as array macro. |
| 9938 |
|
| 9939 |
\clearpage |
| 9940 |
\let\xinttoolsnameUp\undefined |
| 9941 |
\def\n{|{N}|} |
| 9942 |
\def\m{|{M}|} |
| 9943 |
\def\x{|{x}|} |
| 9944 |
|
| 9945 |
\csname ExamplesnameUp\endcsname |
| 9946 |
\section {Additional (old) examples with \xinttoolsname or \xintexprname or both} |
| 9947 |
\RaisedLabel{sec:examples} |
| 9948 |
|
| 9949 |
\localtableofcontents |
| 9950 |
|
| 9951 |
Note: \xintexprname.sty automatically loads \xinttoolsname.sty. |
| 9952 |
|
| 9953 |
The examples given here start to feel dated and are currently in need of some |
| 9954 |
rewrite to better illustrate newer features of the package. |
| 9955 |
|
| 9956 |
\subsection{More examples with dummy variables} |
| 9957 |
\label{ssec:moredummies} |
| 9958 |
|
| 9959 |
These examples were first added to this manual at the time of the |1.1| |
| 9960 |
release (|2014/10/29|). |
| 9961 |
|
| 9962 |
\begin{everbatim*} |
| 9963 |
Prime numbers are always cool |
| 9964 |
\xinttheiiexpr seq((seq((subs((x/:m)?{(m*m>x)?{1}{0}}{-1},m=2n+1)) |
| 9965 |
??{break(0)}{omit}{break(1)},n=1++))?{x}{omit}, |
| 9966 |
x=10001..[2]..10200)\relax |
| 9967 |
\end{everbatim*} |
| 9968 |
|
| 9969 |
The syntax in this last example may look a bit involved (...\@{} and it is so I |
| 9970 |
admit). First |x/:m| computes |x modulo m| (this is the modulo with respect to |
| 9971 |
floored division). The |(x)?{yes}{no}| construct checks if |x| (which |
| 9972 |
\emph{must} be within parentheses) is true or false, i.e.\@{} non zero or zero. It |
| 9973 |
then executes either the |yes| or the |no| branch, the non chosen branch is |
| 9974 |
\emph{not} evaluated. Thus if |m| divides |x| we are in the second (``false'') |
| 9975 |
branch. This gives a |-1|. This |-1| is the argument to a |??| branch which is |
| 9976 |
of the type |(y)??{y<0}{y=0}{y>0}|, thus here the |y<0|, i.e.\@, |break(0)| is |
| 9977 |
chosen. This |0| is thus given to another |?| which consequently chooses |
| 9978 |
|omit|, hence the number is not kept in the list. The numbers which survive |
| 9979 |
are the prime numbers. |
| 9980 |
|
| 9981 |
\begin{everbatim*} |
| 9982 |
The first Fibonacci number beyond |2^64|, |2^64|, and the index are respectively |
| 9983 |
\xinttheiiexpr subs(iterr(0,1;(@1>N)?{break(@1,N,i)}{@1+@2},i=1++),N=2^64)\relax. |
| 9984 |
\end{everbatim*} |
| 9985 |
|
| 9986 |
% A006877 In the `3x+1' problem, these values for the starting value set new |
| 9987 |
% records for number of steps to reach 1. (Formerly M0748) 14 1, 2, 3, 6, 7, |
| 9988 |
% 9, 18, 25, 27, 54, 73, 97, 129, 171, 231, 313, 327, 649, 703, 871, 1161, |
| 9989 |
% 2223, 2463, 2919, 3711, 6171, 10971, 13255, 17647, 23529, 26623, 34239, |
| 9990 |
% 35655, 52527, 77031, 106239, 142587, 156159, 216367, 230631, 410011, 511935, |
| 9991 |
% 626331, 837799 |
| 9992 |
|
| 9993 |
One more recursion: |
| 9994 |
\begin{everbatim*} |
| 9995 |
\def\syr #1{\xinttheiiexpr |
| 9996 |
rseq(#1; (@<=1)?{break(i)}{odd(@)?{3@+1}{@//2}},i=0++)\relax} |
| 9997 |
The 3x+1 problem: \syr{231}\par |
| 9998 |
\end{everbatim*} |
| 9999 |
|
| 10000 |
OK, a final one:% |
| 10001 |
\begin{everbatim*} |
| 10002 |
\def\syrMax #1{\xintiiexpr iterr(#1,#1;even(i)? |
| 10003 |
{(@2<=1)?{break(@1,i//2)} |
| 10004 |
{odd(@2)?{3@2+1}{@2//2}}} |
| 10005 |
{(@1>@2)?{@1}{@2}},i=0++)\relax } |
| 10006 |
With initial value 1161, the maximal intermediate value and the number of steps |
| 10007 |
needed to reach 1 are respectively \syrMax{1161}.\par |
| 10008 |
\end{everbatim*} |
| 10009 |
|
| 10010 |
Look at the |
| 10011 |
\hyperlink{BrentSalamin}{Brent-Salamin algorithm implementation} for a more |
| 10012 |
interesting recursion. |
| 10013 |
|
| 10014 |
% \begin{everbatim*} |
| 10015 |
% \newcommand\Factors [1]{\xinttheiiexpr |
| 10016 |
% subs(seq((i/:3=1)?{omit}{[L][i]},i=0..len(L)-1), |
| 10017 |
% L=rseq(#1;(p^2>[@][0])?{([@][0]>1)?{break(1,[@][0],1)}{abort}} |
| 10018 |
% {(([@][0])/:p)?{omit} |
| 10019 |
% {iter(([@][0])//p; (@/:p)?{break(@,p,e)}{@//p},e=1++)}},p=2++))\relax } |
| 10020 |
% \Factors {41^4*59^2*29^3*13^5*17^8*29^2*59^4*37^6} |
| 10021 |
% \end{everbatim*} |
| 10022 |
|
| 10023 |
% This might look a bit scary, I admit.% |
| 10024 |
% % |
| 10025 |
% \footnote{Look at the |
| 10026 |
% \hyperlink{BrentSalamin}{Brent-Salamin algorithm implementation} for a much |
| 10027 |
% saner example.} |
| 10028 |
% % |
| 10029 |
|
| 10030 |
% \xintexprname has minimal tools and |
| 10031 |
% is obstinate about doing everything expandably! We are hampered by absence of a |
| 10032 |
% notion of ``nuple''. The algorithm divides |N| by |2| until no more possible, |
| 10033 |
% then by |3|, then by |4| (which is silly), then by |5|, then by |6| (silly |
| 10034 |
% again), \dots. |
| 10035 |
|
| 10036 |
% The variable |L=rseq(#1;...)| expands, if one follows the steps, to a comma |
| 10037 |
% separated list starting with the initial (evaluated) |N=#1| and then |
| 10038 |
% pseudo-triplets where the first item is |N| trimmed of small primes, the |
| 10039 |
% second item is the last prime divisor found, and the third item is its |
| 10040 |
% exponent in original |N|. |
| 10041 |
|
| 10042 |
% The algorithm needs to keep handy the last computed quotient by prime powers, |
| 10043 |
% hence all of them, but at the very end it will be cleaner to get rid of them |
| 10044 |
% (this corresponds to the first line in the code above). This is achieved in a |
| 10045 |
% cumbersome inefficient way; indeed each item extraction |[L][i]| is costly: it |
| 10046 |
% is not like accessing an array stored in memory, due to expandability, nothing |
| 10047 |
% can be stored in memory! Nevertheless, this step could be done here in a far |
| 10048 |
% less inefficient manner if there was a variant of |seq| which, in the spirit |
| 10049 |
% of \csbxint{iloopindex}, would know how many steps it had been through so far. |
| 10050 |
% This is a feature to be added to |\xintexpr|! (as well as a |++| construct |
| 10051 |
% allowing a non unit step). |
| 10052 |
|
| 10053 |
% Notice that in |iter(([@][0])//p;| the |@| refers to the previous triplet (or |
| 10054 |
% in the first step to |N|), but the latter |@| showing up in |(@/:p)?| refers |
| 10055 |
% to the previous value computed by |iter|. |
| 10056 |
|
| 10057 |
% \begin{snugframed} |
| 10058 |
% Parentheses are essential in |..([y][0])| else the parser will see |..[| and |
| 10059 |
% end up in ultimate confusion, and also in |([@][0])/:p| else the parser will |
| 10060 |
% see the itemwise operator |]/| on lists and again be very confused (I could |
| 10061 |
% implement a |]/:| on lists, but in this situation this would also be very |
| 10062 |
% confusing to the parser.) |
| 10063 |
% \end{snugframed} |
| 10064 |
|
| 10065 |
% See \autoref{ssec:factorize} for a routine |\Factorize| written directly with |
| 10066 |
% \xintname macros. Last time I checked |\Factors| was about seven times slower |
| 10067 |
% than |\Factorize| in test cases such as |
| 10068 |
% |16246355912554185673266068721806243461403654781833| and others. Among the |
| 10069 |
% various things explaining the speed difference, there is fact that the |
| 10070 |
% |\Factorize| algorithm step by increments of two, not one, and also it divides |
| 10071 |
% only once, obtaining quotient and remainder in one go. These two things |
| 10072 |
% already make for a speed-up factor of about four. Thus, |\Factors| is not |
| 10073 |
% completely inefficient in comparison, and was quite easier to come up with |
| 10074 |
% than |\Factorize|. |
| 10075 |
|
| 10076 |
\subsection{Completely expandable prime test} |
| 10077 |
\label{ssec:primesI} |
| 10078 |
|
| 10079 |
Let us now construct a completely expandable macro which returns $1$ if its |
| 10080 |
given input is prime and $0$ if not: |
| 10081 |
\everb|@ |
| 10082 |
\def\remainder #1#2{\the\numexpr #1-(#1/#2)*#2\relax } |
| 10083 |
\def\IsPrime #1% |
| 10084 |
{\xintANDof {\xintApply {\remainder {#1}}{\xintSeq {2}{\xintiiSqrt{#1}}}}} |
| 10085 |
| |
| 10086 |
|
| 10087 |
This uses \csbxint{iiSqrt} and assumes its input is at least $5$. Rather than |
| 10088 |
\xintname's own \csbxint{iiRem} we used a quicker |\numexpr| expression as we |
| 10089 |
are dealing with short integers. Also we used \csbxint{ANDof} which will |
| 10090 |
return $1$ only if all the items are non-zero. The macro is a bit |
| 10091 |
silly with an even input, ok, let's enhance it to detect an even input: |
| 10092 |
\everb|@ |
| 10093 |
\def\IsPrime #1% |
| 10094 |
{\xintiiifOdd {#1} |
| 10095 |
{\xintANDof % odd case |
| 10096 |
{\xintApply {\remainder {#1}} |
| 10097 |
{\xintSeq [2]{3}{\xintiiSqrt{#1}}}% |
| 10098 |
}% |
| 10099 |
} |
| 10100 |
{\xintifEq {#1}{2}{1}{0}}% |
| 10101 |
} |
| 10102 |
| |
| 10103 |
|
| 10104 |
We used the \xintname expandable tests (on big integers or fractions) |
| 10105 |
in order for |\IsPrime| to be \fexpan dable. |
| 10106 |
|
| 10107 |
Our integers are short, but without |\expandafter|'s with |
| 10108 |
|\@firstoftwo|, % @ n'est plus actif dans le dtx 1.1 ! |
| 10109 |
or some other related techniques, |
| 10110 |
direct use of |\ifnum..\fi| tests is dangerous. So to make the macro more |
| 10111 |
efficient we are going to use the expandable tests provided by the package |
| 10112 |
\href{http://ctan.org/pkg/etoolbox}{etoolbox}% |
| 10113 |
% |
| 10114 |
\footnote{\url{http://ctan.org/pkg/etoolbox}}. |
| 10115 |
% |
| 10116 |
The macro becomes: |
| 10117 |
% |
| 10118 |
\everb|@ |
| 10119 |
\def\IsPrime #1% |
| 10120 |
{\ifnumodd {#1} |
| 10121 |
{\xintANDof % odd case |
| 10122 |
{\xintApply {\remainder {#1}}{\xintSeq [2]{3}{\xintiiSqrt{#1}}}}} |
| 10123 |
{\ifnumequal {#1}{2}{1}{0}}} |
| 10124 |
| |
| 10125 |
|
| 10126 |
In the odd case however we have to assume the integer is at least $7$, as |
| 10127 |
|\xintSeq| generates an empty list if |#1=3| or |5|, and |\xintANDof| returns |
| 10128 |
$1$ when supplied an empty list. Let us ease up a bit |\xintANDof|'s work by |
| 10129 |
letting it work on only $0$'s and $1$'s. We could use: |
| 10130 |
% |
| 10131 |
\everb|@ |
| 10132 |
\def\IsNotDivisibleBy #1#2% |
| 10133 |
{\ifnum\numexpr #1-(#1/#2)*#2=0 \expandafter 0\else \expandafter1\fi} |
| 10134 |
| |
| 10135 |
\noindent |
| 10136 |
where the |\expandafter|'s are crucial for this macro to be \fexpan dable and |
| 10137 |
hence work within the applied \csbxint{ANDof}. Anyhow, now that we have loaded |
| 10138 |
\href{http://ctan.org/pkg/etoolbox}{etoolbox}, we might as well use: |
| 10139 |
% |
| 10140 |
\everb|@ |
| 10141 |
\newcommand{\IsNotDivisibleBy}[2]{\ifnumequal{#1-(#1/#2)*#2}{0}{0}{1}} |
| 10142 |
| |
| 10143 |
\noindent |
| 10144 |
Let us enhance our prime macro to work also on the small primes: |
| 10145 |
\everb|@ |
| 10146 |
\newcommand{\IsPrime}[1] % returns 1 if #1 is prime, and 0 if not |
| 10147 |
{\ifnumodd {#1} |
| 10148 |
{\ifnumless {#1}{8} |
| 10149 |
{\ifnumequal{#1}{1}{0}{1}}% 3,5,7 are primes |
| 10150 |
{\xintANDof |
| 10151 |
{\xintApply |
| 10152 |
{ \IsNotDivisibleBy {#1}}{\xintSeq [2]{3}{\xintiiSqrt{#1}}}}% |
| 10153 |
}}% END OF THE ODD BRANCH |
| 10154 |
{\ifnumequal {#1}{2}{1}{0}}% EVEN BRANCH |
| 10155 |
} |
| 10156 |
| |
| 10157 |
|
| 10158 |
The input is still assumed positive. There is a deliberate blank before |
| 10159 |
\csa{IsNotDivisibleBy} to use this feature of \csbxint{Apply}: a space stops the |
| 10160 |
expansion of the applied macro (and disappears). This expansion will be done by |
| 10161 |
\csbxint{ANDof}, which has been designed to skip everything as soon as it finds |
| 10162 |
a false (i.e.\@{} zero) input. This way, the efficiency is considerably improved. |
| 10163 |
|
| 10164 |
We did generate via the \csbxint{Seq} too many potential divisors though. Later |
| 10165 |
sections give two variants: one with \csbxint{iloop} (\autoref{ssec:primesII}) |
| 10166 |
which is still expandable and another one (\autoref{ssec:primesIII}) which is a |
| 10167 |
close variant of the |\IsPrime| code above but with the \csbxint{For} loop, thus |
| 10168 |
breaking expandability. The \hyperref[ssec:primesII]{xintiloop variant} does not |
| 10169 |
first evaluate the integer square root, the \hyperref[ssec:primesIII]{xintFor |
| 10170 |
variant} still does. I did not compare their efficiencies. |
| 10171 |
|
| 10172 |
|
| 10173 |
Let us construct with this expandable primality test a table of the prime |
| 10174 |
numbers up to $1000$. We need to count how many we have in order to know how |
| 10175 |
many tab stops one shoud add in the last row.% |
| 10176 |
% |
| 10177 |
\footnote{although a tabular row may have less tabs than in the |
| 10178 |
preamble, there is a problem with the \char`\|\space\space vertical |
| 10179 |
rule, if one does that.} |
| 10180 |
% |
| 10181 |
There is some subtlety for this |
| 10182 |
last row. Turns out to be better to insert a |\\| only when we know for sure we |
| 10183 |
are starting a new row; this is how we have designed the |\OneCell| macro. And |
| 10184 |
for the last row, there are many ways, we use again |\xintApplyUnbraced| but |
| 10185 |
with a macro which gobbles its argument and replaces it with a tabulation |
| 10186 |
character. The \csbxint{For*} macro would be more elegant here. |
| 10187 |
% |
| 10188 |
\everb?@ |
| 10189 |
\newcounter{primecount} |
| 10190 |
\newcounter{cellcount} |
| 10191 |
\newcommand{\NbOfColumns}{13} |
| 10192 |
\newcommand{\OneCell}[1]{% |
| 10193 |
\ifnumequal{\IsPrime{#1}}{1} |
| 10194 |
{\stepcounter{primecount} |
| 10195 |
\ifnumequal{\value{cellcount}}{\NbOfColumns} |
| 10196 |
{\\\setcounter{cellcount}{1}#1} |
| 10197 |
{&\stepcounter{cellcount}#1}% |
| 10198 |
} % was prime |
| 10199 |
{}% not a prime, nothing to do |
| 10200 |
} |
| 10201 |
\newcommand{\OneTab}[1]{&} |
| 10202 |
\begin{tabular}{|*{\NbOfColumns}{r}|} |
| 10203 |
\hline |
| 10204 |
2 \setcounter{cellcount}{1}\setcounter{primecount}{1}% |
| 10205 |
\xintApplyUnbraced \OneCell {\xintSeq [2]{3}{999}}% |
| 10206 |
\xintApplyUnbraced \OneTab |
| 10207 |
{\xintSeq [1]{1}{\the\numexpr\NbOfColumns-\value{cellcount}\relax}}% |
| 10208 |
\\ |
| 10209 |
\hline |
| 10210 |
\end{tabular} |
| 10211 |
There are \arabic{primecount} prime numbers up to 1000. |
| 10212 |
? |
| 10213 |
|
| 10214 |
The table has been put in \hyperref[primesupto1000]{float} which appears |
| 10215 |
\vpageref{primesupto1000}. |
| 10216 |
We had to be careful to use in the last row \csbxint{Seq} with its optional |
| 10217 |
argument |[1]| so as to not generate a decreasing sequence from |1| to |0|, but |
| 10218 |
really an empty sequence in case the row turns out to already have all its |
| 10219 |
cells (which doesn't happen here but would with a number of columns dividing |
| 10220 |
$168$). |
| 10221 |
% |
| 10222 |
\newcommand{\IsNotDivisibleBy}[2]{\ifnumequal{#1-(#1/#2)*#2}{0}{0}{1}} |
| 10223 |
|
| 10224 |
\newcommand{\IsPrime}[1] |
| 10225 |
{\ifnumodd {#1} |
| 10226 |
{\ifnumless {#1}{8} |
| 10227 |
{\ifnumequal{#1}{1}{0}{1}}% 3,5,7 are primes |
| 10228 |
{\xintANDof |
| 10229 |
{\xintApply |
| 10230 |
{ \IsNotDivisibleBy {#1}}{\xintSeq [2]{3}{\xintiiSqrt{#1}}}}% |
| 10231 |
}}% END OF THE ODD BRANCH |
| 10232 |
{\ifnumequal {#1}{2}{1}{0}}% EVEN BRANCH |
| 10233 |
} |
| 10234 |
|
| 10235 |
\newcounter{primecount} |
| 10236 |
\newcounter{cellcount} |
| 10237 |
\newcommand{\NbOfColumns}{13} |
| 10238 |
\newcommand{\OneCell}[1] |
| 10239 |
{\ifnumequal{\IsPrime{#1}}{1} |
| 10240 |
{\stepcounter{primecount} |
| 10241 |
\ifnumequal{\value{cellcount}}{\NbOfColumns} |
| 10242 |
{\\\setcounter{cellcount}{1}#1} |
| 10243 |
{&\stepcounter{cellcount}#1}% |
| 10244 |
} % was prime |
| 10245 |
{}% not a prime nothing to do |
| 10246 |
} |
| 10247 |
\newcommand{\OneTab}[1]{&} |
| 10248 |
\begin{figure*}[ht!] |
| 10249 |
\centering |
| 10250 |
\phantomsection\label{primesupto1000} |
| 10251 |
\begin{tabular}{|*{\NbOfColumns}{r}|} |
| 10252 |
\hline |
| 10253 |
2\setcounter{cellcount}{1}\setcounter{primecount}{1}% |
| 10254 |
\xintApplyUnbraced \OneCell {\xintSeq [2]{3}{999}}% |
| 10255 |
\xintApplyUnbraced \OneTab |
| 10256 |
{\xintSeq [1]{1}{\the\numexpr\NbOfColumns-\value{cellcount}\relax}}% |
| 10257 |
\\ |
| 10258 |
\hline |
| 10259 |
\end{tabular} |
| 10260 |
\smallskip |
| 10261 |
\centeredline{There are \arabic{primecount} prime numbers up to 1000.} |
| 10262 |
\end{figure*} |
| 10263 |
|
| 10264 |
\subsection{Another completely expandable prime test} |
| 10265 |
\label{ssec:primesII} |
| 10266 |
|
| 10267 |
The |\IsPrime| macro from \autoref{ssec:primesI} checked expandably if a (short) |
| 10268 |
integer was prime, here is a partial rewrite using \csbxint{iloop}. We use the |
| 10269 |
|etoolbox| expandable conditionals for convenience, but not everywhere as |
| 10270 |
|\xintiloopindex| can not be evaluated while being braced. This is also the |
| 10271 |
reason why |\xintbreakiloopanddo| is delimited, and the next macro |
| 10272 |
|\SmallestFactor| which returns the smallest prime factor examplifies that. One |
| 10273 |
could write more efficient completely expandable routines, the aim here was only |
| 10274 |
to illustrate use of the general purpose \csbxint{iloop}. A little table giving |
| 10275 |
the first values of |\SmallestFactor| follows, its coding uses \csbxint{For}, |
| 10276 |
which is described later; none of this uses count registers. |
| 10277 |
% |
| 10278 |
|
| 10279 |
|
| 10280 |
\begin{everbatim*} |
| 10281 |
% clean up possible left-over mess from previous examples |
| 10282 |
\let\IsPrime\undefined \let\SmallestFactor\undefined |
| 10283 |
\newcommand{\IsPrime}[1] % returns 1 if #1 is prime, and 0 if not |
| 10284 |
{\ifnumodd {#1} |
| 10285 |
{\ifnumless {#1}{8} |
| 10286 |
{\ifnumequal{#1}{1}{0}{1}}% 3,5,7 are primes |
| 10287 |
{\if |
| 10288 |
\xintiloop [3+2] |
| 10289 |
\ifnum#1<\numexpr\xintiloopindex*\xintiloopindex\relax |
| 10290 |
\expandafter\xintbreakiloopanddo\expandafter1\expandafter.% |
| 10291 |
\fi |
| 10292 |
\ifnum#1=\numexpr (#1/\xintiloopindex)*\xintiloopindex\relax |
| 10293 |
\else |
| 10294 |
\repeat 00\expandafter0\else\expandafter1\fi |
| 10295 |
}% |
| 10296 |
}% END OF THE ODD BRANCH |
| 10297 |
{\ifnumequal {#1}{2}{1}{0}}% EVEN BRANCH |
| 10298 |
}% |
| 10299 |
\catcode`_ 11 |
| 10300 |
\newcommand{\SmallestFactor}[1] % returns the smallest prime factor of #1>1 |
| 10301 |
{\ifnumodd {#1} |
| 10302 |
{\ifnumless {#1}{8} |
| 10303 |
{#1}% 3,5,7 are primes |
| 10304 |
{\xintiloop [3+2] |
| 10305 |
\ifnum#1<\numexpr\xintiloopindex*\xintiloopindex\relax |
| 10306 |
\xint_afterfi{\xintbreakiloopanddo#1.}% |
| 10307 |
\fi |
| 10308 |
\ifnum#1=\numexpr (#1/\xintiloopindex)*\xintiloopindex\relax |
| 10309 |
\xint_afterfi{\expandafter\xintbreakiloopanddo\xintiloopindex.}% |
| 10310 |
\fi |
| 10311 |
\iftrue\repeat |
| 10312 |
}% |
| 10313 |
}% END OF THE ODD BRANCH |
| 10314 |
{2}% EVEN BRANCH |
| 10315 |
}% |
| 10316 |
\catcode`_ 8 |
| 10317 |
{\centering |
| 10318 |
\begin{tabular}{|c|*{10}c|} |
| 10319 |
\hline |
| 10320 |
\xintFor #1 in {0,1,2,3,4,5,6,7,8,9}\do {&\bfseries #1}\\ |
| 10321 |
\hline |
| 10322 |
\bfseries 0&--&--&2&3&2&5&2&7&2&3\\ |
| 10323 |
\xintFor #1 in {1,2,3,4,5,6,7,8,9}\do |
| 10324 |
{\bfseries #1% |
| 10325 |
\xintFor #2 in {0,1,2,3,4,5,6,7,8,9}\do |
| 10326 |
{&\SmallestFactor{#1#2}}\\}% |
| 10327 |
\hline |
| 10328 |
\end{tabular}\par |
| 10329 |
} |
| 10330 |
\end{everbatim*} |
| 10331 |
|
| 10332 |
\subsection{Miller-Rabin Pseudo-Primality expandably} |
| 10333 |
\label{ssec:PrimesIV} |
| 10334 |
|
| 10335 |
|
| 10336 |
% At the time of writing, the code at the link above is still the version from |
| 10337 |
% April 2016 and it needed some hacks to get recursive (pseudo)-functions |
| 10338 |
% defined. Since |1.2h| of |2016/11/20| there is \csbxint{NewFunction} which |
| 10339 |
% allows us here to avoid such internal hacking. |
| 10340 |
|
| 10341 |
% And since |1.3| of |2018/03/01|, it is possible to use \csbxint{defiifunc} |
| 10342 |
% also for recursive definitions, so we use it here, but we can benefit from it |
| 10343 |
% only for modular exponentiation as the rest of the code uses |iter| or |break| |
| 10344 |
% statements which are not yet compatible with \csbxint{defiifunc}. |
| 10345 |
|
| 10346 |
The |isPseudoPrime(n)| is usable in \csbxint{iiexpr}-essions and establishes |
| 10347 |
if its (positive) argument is a Miller-Rabin PseudoPrime to the bases $2, 3, |
| 10348 |
5, 7, 11, 13, 17$. If this is true and $n<341550071728321$ (which has 15 |
| 10349 |
digits) then $n$ really is a prime number. |
| 10350 |
|
| 10351 |
Similarly $n=3825123056546413051$ (19 digits) is the smallest composite number |
| 10352 |
which is a strong pseudo prime for bases $2, 3, 5, 7, 11, 13, 17, 19$ and |
| 10353 |
$23$. It is easy to extend the code below to include these additional tests |
| 10354 |
(we could make the list of tested bases an argument too, now that I think |
| 10355 |
about it.) |
| 10356 |
|
| 10357 |
For more information see |
| 10358 |
\centeredline{\url{https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test#Deterministic_variants_of_the_test}} |
| 10359 |
and |
| 10360 |
\centeredline{\url{http://primes.utm.edu/prove/prove2_3.html}} |
| 10361 |
|
| 10362 |
In particular, according to \textsc{Jaeschke} \emph{On strong pseudoprimes to |
| 10363 |
several bases,} Math. Comp., 61 (1993) 915-926, if $n < 4,759,123,141$ it is |
| 10364 |
enough to establish Rabin-Miller pseudo-primality to bases $a = 2, 7, 61$ to |
| 10365 |
prove that $n$ is prime. This range is enough for \TeX\ numbers and we could |
| 10366 |
then write a very fast expandable primality test for such numbers using only |
| 10367 |
|\numexpr|. Left as an exercise\dots |
| 10368 |
|
| 10369 |
\begin{everbatim*} |
| 10370 |
% I -------------------------------- Modular Exponentiation |
| 10371 |
% Computes x^m modulo n (with m non negative). |
| 10372 |
% We will always use it with 1 < x < n |
| 10373 |
% |
| 10374 |
% With xint 1.4 we should use ? and ?? (although in the case at hand ifsgn() |
| 10375 |
% and if() would be ok but I should not say that). |
| 10376 |
% |
| 10377 |
\xintdefiifunc powmod_a(x, m, n) := |
| 10378 |
isone(m)? |
| 10379 |
% m=1, return x modulo n |
| 10380 |
{ x /: n } |
| 10381 |
% m > 1 test if odd or even and do recursive call |
| 10382 |
{ odd(m)? { x*sqr(powmod_a(x, m//2, n)) /: n } |
| 10383 |
{ sqr(powmod_a(x, m//2, n)) /: n } |
| 10384 |
} |
| 10385 |
; |
| 10386 |
\xintdefiifunc powmod(x, m, n) := (m)?{powmod_a(x, m, n)}{1}; |
| 10387 |
|
| 10388 |
%% Syntax used before xint 1.4: |
| 10389 |
% \xintdefiifunc powmod_a(x, m, n) := |
| 10390 |
% ifone(m, |
| 10391 |
% % m=1, return x modulo n |
| 10392 |
% x /: n, |
| 10393 |
% % m > 1 test if odd or even and do recursive call |
| 10394 |
% if(odd(m), (x*sqr(powmod_a(x, m//2, n))) /: n, |
| 10395 |
% sqr(powmod_a(x, m//2, n)) /: n |
| 10396 |
% ) |
| 10397 |
% ); |
| 10398 |
% \xintdefiifunc powmod(x, m, n) := if(m, powmod_a(x, m, n), 1); |
| 10399 |
|
| 10400 |
% II ------------------------------ Miller-Rabin compositeness witness |
| 10401 |
|
| 10402 |
% n=2^k m + 1 with m odd and k at least 1 |
| 10403 |
|
| 10404 |
% Choose 1<x<n. |
| 10405 |
% compute y=x^m modulo n |
| 10406 |
% if equals 1 we can't say anything |
| 10407 |
% if equals n-1 we can't say anything |
| 10408 |
% else put j=1, and |
| 10409 |
% compute repeatedly the square, incrementing j by 1 each time, |
| 10410 |
% thus always we have y^{2^{j-1}} |
| 10411 |
% -> if at some point n-1 mod n found, we can't say anything and break out |
| 10412 |
% -> if however we never find n-1 mod n before reaching |
| 10413 |
% z=y^{2^{k-1}} with j=k |
| 10414 |
% we then have z^2=x^{n-1}. |
| 10415 |
% Suppose z is not -1 mod n. If z^2 is 1 mod n, then n can be prime only if |
| 10416 |
% z is 1 mod n, and we can go back up, until initial y, and we have already |
| 10417 |
% excluded y=1. Thus if z is not -1 mod n and z^2 is 1 then n is not prime. |
| 10418 |
% But if z^2 is not 1, then n is not prime by Fermat. Hence (z not -1 mod n) |
| 10419 |
% implies (n is composite). (Miller test) |
| 10420 |
|
| 10421 |
% let's use again xintexpr indecipherable (except to author) syntax. Of course |
| 10422 |
% doing it with macros only would be faster. |
| 10423 |
|
| 10424 |
% Here \xintdefiifunc is not usable because not compatible with iter, break, ... |
| 10425 |
% but \xintNewFunction comes to the rescue. |
| 10426 |
|
| 10427 |
\xintNewFunction{isCompositeWitness}[4]{% x=#1, n=#2, m=#3, k=#4 |
| 10428 |
subs((y==1)?{0} |
| 10429 |
{iter(y;(j==#4)?{break(!(@==#2-1))} |
| 10430 |
{(@==#2-1)?{break(0)}{sqr(@)/:#2}},j=1++)} |
| 10431 |
,y=powmod(#1,#3,#2))} |
| 10432 |
|
| 10433 |
% added note (2018/03/07) it is possible in the above that m=#3 is never |
| 10434 |
% zero, so we should rather call powmod_a for a small gain, but I don't |
| 10435 |
% have time to re-read the code comments and settle this. |
| 10436 |
|
| 10437 |
% III ------------------------------------- Strong Pseudo Primes |
| 10438 |
|
| 10439 |
% cf |
| 10440 |
% http://oeis.org/A014233 |
| 10441 |
% <http://mathworld.wolfram.com/Rabin-MillerStrongPseudoprimeTest.html> |
| 10442 |
% <http://mathworld.wolfram.com/StrongPseudoprime.html> |
| 10443 |
|
| 10444 |
% check if positive integer <49 si a prime. |
| 10445 |
% 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47 |
| 10446 |
\def\IsVerySmallPrime #1% |
| 10447 |
{\ifnum#1=1 \xintdothis0\fi |
| 10448 |
\ifnum#1=2 \xintdothis1\fi |
| 10449 |
\ifnum#1=3 \xintdothis1\fi |
| 10450 |
\ifnum#1=5 \xintdothis1\fi |
| 10451 |
\ifnum#1=\numexpr (#1/2)*2\relax\xintdothis0\fi |
| 10452 |
\ifnum#1=\numexpr (#1/3)*3\relax\xintdothis0\fi |
| 10453 |
\ifnum#1=\numexpr (#1/5)*5\relax\xintdothis0\fi |
| 10454 |
\xintorthat 1} |
| 10455 |
|
| 10456 |
\xintNewFunction{isPseudoPrime}[1]{% n = #1 |
| 10457 |
(#1<49)?% use ? syntax to evaluate only what is needed |
| 10458 |
% prior to 1.4 we had \xintthe#1 here but the actual tokens represented |
| 10459 |
% by this #1 when isPseudoPrime() function expands have changed and |
| 10460 |
% the correct way is now \xintiieval{#1} to hand over explicit digits to |
| 10461 |
% the \IsVerySmallPrime macro. |
| 10462 |
{\IsVerySmallPrime{\xintiieval{#1}}} |
| 10463 |
{(even(#1))? |
| 10464 |
{0} |
| 10465 |
{subs(% |
| 10466 |
% L expands to two values m, k hence isCompositeWitness does get |
| 10467 |
% its four variables x, n, m, k |
| 10468 |
isCompositeWitness(2, #1, L)? |
| 10469 |
{0}% |
| 10470 |
{isCompositeWitness(3, #1, L)? |
| 10471 |
{0}% |
| 10472 |
{isCompositeWitness(5, #1, L)? |
| 10473 |
{0}% |
| 10474 |
{isCompositeWitness(7, #1, L)? |
| 10475 |
{0}% |
| 10476 |
% above enough for N<3215031751 hence all TeX numbers |
| 10477 |
{isCompositeWitness(11, #1, L)? |
| 10478 |
{0}% |
| 10479 |
% above enough for N<2152302898747, hence all 12-digits numbers |
| 10480 |
{isCompositeWitness(13, #1, L)? |
| 10481 |
{0}% |
| 10482 |
% above enough for N<3474749660383 |
| 10483 |
{isCompositeWitness(17, #1, L)? |
| 10484 |
{0}% |
| 10485 |
% above enough for N<341550071728321 |
| 10486 |
{1}% |
| 10487 |
}% not needed to comment-out end of lines spaces inside |
| 10488 |
}% \xintexpr but this is too much of a habit for me with TeX! |
| 10489 |
}% I left some after the ? characters. |
| 10490 |
}% |
| 10491 |
}% |
| 10492 |
}% this computes (m, k) such that n = 2^k m + 1, m odd, k>=1 |
| 10493 |
, L=iter(#1//2;(even(@))?{@//2}{break(@,k)},k=1++))% |
| 10494 |
}% |
| 10495 |
}% |
| 10496 |
} |
| 10497 |
|
| 10498 |
% if needed: |
| 10499 |
%\def\IsPseudoPrime #1{\xinttheiiexpr isPseudoPrime(#1)\relax} |
| 10500 |
|
| 10501 |
\noindent The smallest prime number at least equal to 3141592653589 is |
| 10502 |
\xintiiexpr |
| 10503 |
seq(isPseudoPrime(3141592653589+n)? |
| 10504 |
{break(3141592653589+n)}{omit}, n=0++)\relax. |
| 10505 |
% we could not use 3141592653589++ syntax because it works only with TeX numbers |
| 10506 |
\par |
| 10507 |
\end{everbatim*} |
| 10508 |
|
| 10509 |
|
| 10510 |
|
| 10511 |
|
| 10512 |
|
| 10513 |
\subsection{A table of factorizations} |
| 10514 |
\label{ssec:factorizationtable} |
| 10515 |
|
| 10516 |
As one more example with \csbxint{iloop} let us use an alignment to display the |
| 10517 |
factorization of some numbers. The loop will actually only play a minor r\^ole |
| 10518 |
here, just handling the row index, the row contents being almost entirely |
| 10519 |
produced via a macro |\factorize|. The factorizing macro does not use |
| 10520 |
|\xintiloop| as it didn't appear to be the convenient tool. As |\factorize| will |
| 10521 |
have to be used on |\xintiloopindex|, it has been defined as a delimited macro. |
| 10522 |
|
| 10523 |
To spare some fractions of a second in the compilation time of this document |
| 10524 |
(which has many many other things to do), \number"7FFFFFED{} and |
| 10525 |
\number"7FFFFFFF, which turn out to be prime numbers, are not given to |
| 10526 |
|factorize| but just typeset directly; this illustrates use of |
| 10527 |
\csbxint{iloopskiptonext}. |
| 10528 |
|
| 10529 |
The code next generates a \hyperref[floatfactorize]{table} which has |
| 10530 |
been made into a float appearing \vpageref{floatfactorize}. Here is now |
| 10531 |
the code for factorization; the conditionals use the package provided |
| 10532 |
|\xint_firstoftwo| and |\xint_secondoftwo|, one could have employed |
| 10533 |
rather \LaTeX{}'s own |\@firstoftwo| and |\@secondoftwo|, or, simpler |
| 10534 |
still in \LaTeX{} context, the |\ifnumequal|, |\ifnumless| \dots, |
| 10535 |
utilities from the package |etoolbox| which do exactly that under the |
| 10536 |
hood. Only \TeX{} acceptable numbers are treated here, but it would be |
| 10537 |
easy to make a translation and use the \xintname macros, thus extending |
| 10538 |
the scope to big numbers; naturally up to a cost in speed. |
| 10539 |
|
| 10540 |
The reason for some strange looking expressions is to avoid arithmetic overflow. |
| 10541 |
|
| 10542 |
\begin{everbatim*} |
| 10543 |
\catcode`_ 11 |
| 10544 |
\def\abortfactorize #1\xint_secondoftwo\fi #2#3{\fi} |
| 10545 |
|
| 10546 |
\def\factorize #1.{\ifnum#1=1 \abortfactorize\fi |
| 10547 |
\ifnum\numexpr #1-2=\numexpr ((#1/2)-1)*2\relax |
| 10548 |
\expandafter\xint_firstoftwo |
| 10549 |
\else\expandafter\xint_secondoftwo |
| 10550 |
\fi |
| 10551 |
{2&\expandafter\factorize\the\numexpr#1/2.}% |
| 10552 |
{\factorize_b #1.3.}}% |
| 10553 |
|
| 10554 |
\def\factorize_b #1.#2.{\ifnum#1=1 \abortfactorize\fi |
| 10555 |
\ifnum\numexpr #1-(#2-1)*#2<#2 |
| 10556 |
#1\abortfactorize |
| 10557 |
\fi |
| 10558 |
\ifnum \numexpr #1-#2=\numexpr ((#1/#2)-1)*#2\relax |
| 10559 |
\expandafter\xint_firstoftwo |
| 10560 |
\else\expandafter\xint_secondoftwo |
| 10561 |
\fi |
| 10562 |
{#2&\expandafter\factorize_b\the\numexpr#1/#2.#2.}% |
| 10563 |
{\expandafter\factorize_b\the\numexpr #1\expandafter.% |
| 10564 |
\the\numexpr #2+2.}}% |
| 10565 |
\catcode`_ 8 |
| 10566 |
\begin{figure*}[ht!] |
| 10567 |
\centering\phantomsection\label{floatfactorize}\normalcolor |
| 10568 |
\tabskip1ex |
| 10569 |
\centeredline{\vbox{\halign {\hfil\strut#\hfil&&\hfil#\hfil\cr\noalign{\hrule} |
| 10570 |
\xintiloop ["7FFFFFE0+1] |
| 10571 |
\expandafter\bfseries\xintiloopindex & |
| 10572 |
\ifnum\xintiloopindex="7FFFFFED |
| 10573 |
\number"7FFFFFED\cr\noalign{\hrule} |
| 10574 |
\expandafter\xintiloopskiptonext |
| 10575 |
\fi |
| 10576 |
\expandafter\factorize\xintiloopindex.\cr\noalign{\hrule} |
| 10577 |
\ifnum\xintiloopindex<"7FFFFFFE |
| 10578 |
\repeat |
| 10579 |
\bfseries \number"7FFFFFFF&\number "7FFFFFFF\cr\noalign{\hrule} |
| 10580 |
}}} |
| 10581 |
\centeredline{A table of factorizations} |
| 10582 |
\end{figure*} |
| 10583 |
\end{everbatim*} |
| 10584 |
|
| 10585 |
\subsection{Another table of primes} |
| 10586 |
\label{ssec:primesIII} |
| 10587 |
|
| 10588 |
As a further example, let us dynamically generate a tabular with the first $50$ |
| 10589 |
prime numbers after $12345$. First we need a macro to test if a (short) number |
| 10590 |
is prime. Such a completely expandable macro was given in \autoref{ssec:primesI}, |
| 10591 |
here we consider a variant which will be slightly more efficient. This new |
| 10592 |
|\IsPrime| has two parameters. The first one is a macro which it redefines to |
| 10593 |
expand to the result of the primality test applied to the second argument. For |
| 10594 |
convenience we use the \href{http://ctan.org/pkg/etoolbox}{etoolbox} wrappers to |
| 10595 |
various |\ifnum| tests, although here there isn't anymore the constraint of |
| 10596 |
complete expandability (but using explicit |\if..\fi| in tabulars has its |
| 10597 |
quirks); equivalent tests are provided by \xintname, but they have some overhead |
| 10598 |
as they are able to deal with arbitrarily big integers. |
| 10599 |
|
| 10600 |
\def\IsPrime #1#2% |
| 10601 |
{\edef\TheNumber {\the\numexpr #2}% positive integer |
| 10602 |
\ifnumodd {\TheNumber} |
| 10603 |
{\ifnumgreater {\TheNumber}{1} |
| 10604 |
{\edef\ItsSquareRoot{\xintiiSqrt \TheNumber}% |
| 10605 |
\xintFor ##1 in {\xintintegers [3+2]}\do |
| 10606 |
{\ifnumgreater {##1}{\ItsSquareRoot} |
| 10607 |
{\def#1{1}\xintBreakFor} |
| 10608 |
{}% |
| 10609 |
\ifnumequal {\TheNumber}{(\TheNumber/##1)*##1} |
| 10610 |
{\def#1{0}\xintBreakFor } |
| 10611 |
{}% |
| 10612 |
}} |
| 10613 |
{\def#1{0}}}% 1 is not prime |
| 10614 |
{\ifnumequal {\TheNumber}{2}{\def#1{1}}{\def#1{0}}}% |
| 10615 |
}% |
| 10616 |
|
| 10617 |
\everb|@ |
| 10618 |
\def\IsPrime #1#2% """color[named]{PineGreen}#1=\Result, #2=tested number (assumed >0).;! |
| 10619 |
{\edef\TheNumber {\the\numexpr #2}%"""color[named]{PineGreen} hence #2 may be a count or \numexpr.;! |
| 10620 |
\ifnumodd {\TheNumber} |
| 10621 |
{\ifnumgreater {\TheNumber}{1} |
| 10622 |
{\edef\ItsSquareRoot{\xintiiSqrt \TheNumber}% |
| 10623 |
\xintFor """color{red}##1;! in {"""color{red}\xintintegers;! [3+2]}\do |
| 10624 |
{\ifnumgreater {"""color{red}##1;!}{\ItsSquareRoot} """color[named]{PineGreen}% "textcolor{red}{##1} is a \numexpr.;! |
| 10625 |
{\def#1{1}\xintBreakFor} |
| 10626 |
{}% |
| 10627 |
\ifnumequal {\TheNumber}{(\TheNumber/##1)*##1} |
| 10628 |
{\def#1{0}\xintBreakFor } |
| 10629 |
{}% |
| 10630 |
}} |
| 10631 |
{\def#1{0}}}% 1 is not prime |
| 10632 |
{\ifnumequal {\TheNumber}{2}{\def#1{1}}{\def#1{0}}}% |
| 10633 |
} |
| 10634 |
| |
| 10635 |
|
| 10636 |
As we used \csbxint{For} inside a macro we had to double the |#| in its |#1| |
| 10637 |
parameter. Here is now the code which creates the prime table (the table has |
| 10638 |
been put in a \hyperref[primes]{float}, which should be found on page |
| 10639 |
\pageref{primes}): |
| 10640 |
|
| 10641 |
\everb?@ |
| 10642 |
\newcounter{primecount} |
| 10643 |
\newcounter{cellcount} |
| 10644 |
\begin{figure*}[ht!] |
| 10645 |
\centering |
| 10646 |
\begin{tabular}{|*{7}c|} |
| 10647 |
\hline |
| 10648 |
\setcounter{primecount}{0}\setcounter{cellcount}{0}% |
| 10649 |
\xintFor """color{red}#1;! in {"""color{red}\xintintegers;! [12345+2]} \do |
| 10650 |
"""color[named]{PineGreen}% "textcolor{red}{#1} is a \numexpr.;! |
| 10651 |
{\IsPrime\Result{#1}% |
| 10652 |
\ifnumgreater{\Result}{0} |
| 10653 |
{\stepcounter{primecount}% |
| 10654 |
\stepcounter{cellcount}% |
| 10655 |
\ifnumequal {\value{cellcount}}{7} |
| 10656 |
{"""color{red}\the#1;! \\\setcounter{cellcount}{0}} |
| 10657 |
{"""color{red}\the#1;! &}} |
| 10658 |
{}% |
| 10659 |
\ifnumequal {\value{primecount}}{50} |
| 10660 |
{\xintBreakForAndDo |
| 10661 |
{\multicolumn {6}{l|}{These are the first 50 primes after 12345.}\\}} |
| 10662 |
{}% |
| 10663 |
}\hline |
| 10664 |
\end{tabular} |
| 10665 |
\end{figure*} |
| 10666 |
? |
| 10667 |
|
| 10668 |
\begin{figure*}[ht!] |
| 10669 |
\centering\phantomsection\label{primes} |
| 10670 |
\begin{tabular}{|*{7}c|} |
| 10671 |
\hline |
| 10672 |
\setcounter{primecount}{0}\setcounter{cellcount}{0}% |
| 10673 |
\xintFor #1 in {\xintintegers [12345+2]} \do |
| 10674 |
{\IsPrime\Result{#1}% |
| 10675 |
\ifnumgreater{\Result}{0} |
| 10676 |
{\stepcounter{primecount}% |
| 10677 |
\stepcounter{cellcount}% |
| 10678 |
\ifnumequal {\value{cellcount}}{7} |
| 10679 |
{\the#1 \\\setcounter{cellcount}{0}} |
| 10680 |
{\the#1 &}} |
| 10681 |
{}% |
| 10682 |
\ifnumequal {\value{primecount}}{50} |
| 10683 |
{\xintBreakForAndDo |
| 10684 |
{\multicolumn {6}{l|}{These are the first 50 primes after 12345.}\\}} |
| 10685 |
{}% |
| 10686 |
}\hline |
| 10687 |
\end{tabular} |
| 10688 |
\end{figure*} |
| 10689 |
|
| 10690 |
\subsection{Factorizing again} |
| 10691 |
\label{ssec:factorize} |
| 10692 |
|
| 10693 |
Here is an \fexpan dable macro which computes the factors of an integer. It |
| 10694 |
uses the \xintname macros only. |
| 10695 |
\begin{everbatim*} |
| 10696 |
\catcode`\@ 11 |
| 10697 |
\let\factorize\relax |
| 10698 |
\newcommand\Factorize [1] |
| 10699 |
{\romannumeral0\expandafter\factorize\expandafter{\romannumeral-`0#1}}% |
| 10700 |
\newcommand\factorize [1]{\xintiiifOne{#1}{ 1}{\factors@a #1.{#1};}}% |
| 10701 |
\def\factors@a #1.{\xintiiifOdd{#1} |
| 10702 |
{\factors@c 3.#1.}% |
| 10703 |
{\expandafter\factors@b \expandafter1\expandafter.\romannumeral0\xinthalf{#1}.}}% |
| 10704 |
\def\factors@b #1.#2.{\xintiiifOne{#2} |
| 10705 |
{\factors@end {2, #1}}% |
| 10706 |
{\xintiiifOdd{#2}{\factors@c 3.#2.{2, #1}}% |
| 10707 |
{\expandafter\factors@b \the\numexpr #1+\@ne\expandafter.% |
| 10708 |
\romannumeral0\xinthalf{#2}.}}% |
| 10709 |
}% |
| 10710 |
\def\factors@c #1.#2.{% |
| 10711 |
\expandafter\factors@d\romannumeral0\xintiidivision {#2}{#1}{#1}{#2}% |
| 10712 |
}% |
| 10713 |
\def\factors@d #1#2#3#4{\xintiiifNotZero{#2} |
| 10714 |
{\xintiiifGt{#3}{#1} |
| 10715 |
{\factors@end {#4, 1}}% ultimate quotient is a prime with power 1 |
| 10716 |
{\expandafter\factors@c\the\numexpr #3+\tw@.#4.}}% |
| 10717 |
{\factors@e 1.#3.#1.}% |
| 10718 |
}% |
| 10719 |
\def\factors@e #1.#2.#3.{\xintiiifOne{#3} |
| 10720 |
{\factors@end {#2, #1}}% |
| 10721 |
{\expandafter\factors@f\romannumeral0\xintiidivision {#3}{#2}{#1}{#2}{#3}}% |
| 10722 |
}% |
| 10723 |
\def\factors@f #1#2#3#4#5{\xintiiifNotZero{#2} |
| 10724 |
{\expandafter\factors@c\the\numexpr #4+\tw@.#5.{#4, #3}}% |
| 10725 |
{\expandafter\factors@e\the\numexpr #3+\@ne.#4.#1.}% |
| 10726 |
}% |
| 10727 |
\def\factors@end #1;{\xintlistwithsep{, }{\xintRevWithBraces {#1}}}% |
| 10728 |
\catcode`@ 12 |
| 10729 |
\end{everbatim*} |
| 10730 |
The macro will be acceptably efficient only with numbers having somewhat small |
| 10731 |
prime factors. |
| 10732 |
\begin{everbatim} |
| 10733 |
\Factorize{16246355912554185673266068721806243461403654781833} |
| 10734 |
\end{everbatim} |
| 10735 |
\begingroup\fdef\Z |
| 10736 |
{\Factorize{16246355912554185673266068721806243461403654781833}} |
| 10737 |
\noindent{\small\dtt{\Z}} |
| 10738 |
|
| 10739 |
|
| 10740 |
It puts a little stress on the input save stack in order |
| 10741 |
not be bothered with previously gathered things.\footnote{2015/11/18 I have |
| 10742 |
not revisited this code for a long time, and perhaps I could improve it now |
| 10743 |
with some new techniques.} |
| 10744 |
|
| 10745 |
Its output is a comma separated list with the number first, then its prime |
| 10746 |
factors with multiplicity. Let's produce something prettier: |
| 10747 |
\begin{everbatim*} |
| 10748 |
\catcode`_ 11 |
| 10749 |
\def\ShowFactors #1{\expandafter |
| 10750 |
\ShowFactors_a\romannumeral-`0\Factorize{#1},\relax,\relax,} |
| 10751 |
\def\ShowFactors_a #1,{#1=\ShowFactors_b} |
| 10752 |
\def\ShowFactors_b #1,#2,{\if\relax#1\else#1^{#2}\expandafter\ShowFactors_b\fi} |
| 10753 |
\catcode`_ 8 |
| 10754 |
\end{everbatim*} |
| 10755 |
\begin{everbatim} |
| 10756 |
$$\ShowFactors{16246355912554185673266068721806243461403654781833}$$ |
| 10757 |
\end{everbatim} |
| 10758 |
$$\csname ShowFactors_a\expandafter\endcsname\Z,\relax,\relax,$$ |
| 10759 |
\endgroup |
| 10760 |
|
| 10761 |
If we only considered small integers, we could write pure |\numexpr| methods |
| 10762 |
which would be very much faster (especially if we had a table of small primes |
| 10763 |
prepared first) but still ridiculously slow compared to any non expandable |
| 10764 |
implementation, not to mention use of programming languages directly accessing |
| 10765 |
the CPU registers\dots |
| 10766 |
|
| 10767 |
\subsection{The Quick Sort algorithm illustrated}\label{ssec:quicksort} |
| 10768 |
|
| 10769 |
First a completely expandable macro which sorts a comma separated list of |
| 10770 |
numbers.% |
| 10771 |
% |
| 10772 |
\footnote{The code in earlier versions of this manual handled inputs composed |
| 10773 |
of braced items. I have switched to comma separated inputs on the occasion |
| 10774 |
of (link removed) |
| 10775 |
The version here is like |
| 10776 |
|code 3| on |
| 10777 |
(link removed) (which is about |3x| faster |
| 10778 |
than the earlier code it replaced in this manual) with a modification to |
| 10779 |
make it more efficient if the data has many repeated values. |
| 10780 |
|
| 10781 |
A faster routine (for sorting hundreds of values) is provided as |code 6| at |
| 10782 |
the link mentioned in the footnote, it is based on Merge Sort, but limited |
| 10783 |
to inputs which one can handle as \TeX{} dimensions.% |
| 10784 |
|
| 10785 |
This |code 6| could be extended to handle more general numbers, as |
| 10786 |
acceptable by \xintfracname. I have also written a non expandable version, |
| 10787 |
which is even faster, but this matters really only when handling hundreds or |
| 10788 |
rather thousands of values.} |
| 10789 |
% |
| 10790 |
|
| 10791 |
The |\QSx| macro expands its list argument, which may thus be a macro; its |
| 10792 |
comma separated items must expand to integers or decimal numbers or fractions |
| 10793 |
or scientific notation as acceptable to \xintfracname, but if an item is |
| 10794 |
itself some (expandable) macro, this macro will be expanded each time the item |
| 10795 |
is considered in a comparison test! This is actually good if the macro expands |
| 10796 |
in one step to the digits, and there are many many digits, but bad if the macro |
| 10797 |
needs to do many computations. Thus |\QSx| should be used with either explicit |
| 10798 |
numbers or with items being macros expanding in one step to the numbers |
| 10799 |
(particularly if these numbers are very big). |
| 10800 |
|
| 10801 |
If the interest is only in \TeX{} integers, then one should replace the |
| 10802 |
|\xintifCmp| macro with a suitable conditional, possibly helped by tools such as |
| 10803 |
|\ifnumgreater|, |\ifnumequal| and |\ifnumless| from |
| 10804 |
\href{http://ctan.org/pkg/etoolbox}{etoolbox} (\LaTeX{} only; I didn't see a |
| 10805 |
direct equivalent to |\xintifCmp|.) Or, if we are dealing with decimal numbers |
| 10806 |
with at most four+four digits, then one should use suitable |\ifdim| tests. |
| 10807 |
Naturally this will boost consequently the speed, from having skipped all the |
| 10808 |
overhead in parsing fractions and scientific numbers as are acceptable by |
| 10809 |
\xintfracname macros, and subsequent treatment. |
| 10810 |
|
| 10811 |
\begin{everbatim*} |
| 10812 |
% THE QUICK SORT ALGORITHM EXPANDABLY |
| 10813 |
% \usepackage{xintfrac} in the preamble (latex) |
| 10814 |
\makeatletter |
| 10815 |
% use extra safe delimiters |
| 10816 |
\catcode`! 3 \catcode`? 3 |
| 10817 |
\def\QSx {\romannumeral0\qsx }% |
| 10818 |
% first we check if empty list (else \qsx@finish will not find a comma) |
| 10819 |
\def\qsx #1{\expandafter\qsx@a\romannumeral-`0#1,!,?}% |
| 10820 |
\def\qsx@a #1{\ifx,#1\expandafter\qsx@abort\else |
| 10821 |
\expandafter\qsx@start\fi #1}% |
| 10822 |
\def\qsx@abort #1?{ }% |
| 10823 |
\def\qsx@start {\expandafter\qsx@finish\romannumeral0\qsx@b,}% |
| 10824 |
\def\qsx@finish ,#1{ #1}% |
| 10825 |
% |
| 10826 |
% we check if empty of single and if not pick up the first as Pivot: |
| 10827 |
\def\qsx@b ,#1#2,#3{\ifx?#3\xintdothis\qsx@empty\fi |
| 10828 |
\ifx!#3\xintdothis\qsx@single\fi |
| 10829 |
\xintorthat\qsx@separate {#1#2}{}{}{#1#2}#3}% |
| 10830 |
\def\qsx@empty #1#2#3#4#5{ }% |
| 10831 |
\def\qsx@single #1#2#3#4#5?{, #4}% |
| 10832 |
\def\qsx@separate #1#2#3#4#5#6,% |
| 10833 |
{% |
| 10834 |
\ifx!#5\expandafter\qsx@separate@done\fi |
| 10835 |
\xintifCmp {#5#6}{#4}% |
| 10836 |
\qsx@separate@appendtosmaller |
| 10837 |
\qsx@separate@appendtoequal |
| 10838 |
\qsx@separate@appendtogreater {#5#6}{#1}{#2}{#3}{#4}% |
| 10839 |
}% |
| 10840 |
% |
| 10841 |
\def\qsx@separate@appendtoequal #1#2{\qsx@separate {#2,#1}}% |
| 10842 |
\def\qsx@separate@appendtogreater #1#2#3{\qsx@separate {#2}{#3,#1}}% |
| 10843 |
\def\qsx@separate@appendtosmaller #1#2#3#4{\qsx@separate {#2}{#3}{#4,#1}}% |
| 10844 |
% |
| 10845 |
\def\qsx@separate@done\xintifCmp #1% |
| 10846 |
\qsx@separate@appendtosmaller |
| 10847 |
\qsx@separate@appendtoequal |
| 10848 |
\qsx@separate@appendtogreater #2#3#4#5#6#7?% |
| 10849 |
{% |
| 10850 |
\expandafter\qsx@f\expandafter {\romannumeral0\qsx@b #4,!,?}{\qsx@b #5,!,?}{#3}% |
| 10851 |
}% |
| 10852 |
% |
| 10853 |
\def\qsx@f #1#2#3{#2, #3#1}% |
| 10854 |
% |
| 10855 |
\catcode`! 12 \catcode`? 12 |
| 10856 |
\makeatother |
| 10857 |
|
| 10858 |
% EXAMPLE |
| 10859 |
\begingroup |
| 10860 |
\edef\z {\QSx {1.0, 0.5, 0.3, 1.5, 1.8, 2.0, 1.7, 0.4, 1.2, 1.4, |
| 10861 |
1.3, 1.1, 0.7, 1.6, 0.6, 0.9, 0.8, 0.2, 0.1, 1.9}} |
| 10862 |
\meaning\z |
| 10863 |
|
| 10864 |
\def\a {3.123456789123456789}\def\b {3.123456789123456788} |
| 10865 |
\def\c {3.123456789123456790}\def\d {3.123456789123456787} |
| 10866 |
\oodef\z {\QSx { \a, \b, \c, \d}}% |
| 10867 |
% The space before \a to let it not be expanded during the conversion from CSV |
| 10868 |
% values to List. The \oodef expands exactly twice (via a bunch of \expandafter's) |
| 10869 |
\meaning\z |
| 10870 |
\endgroup |
| 10871 |
\end{everbatim*} (the spaces after \string\d, etc...\@{} come from the use of the |
| 10872 |
|\meaning| primitive.) |
| 10873 |
|
| 10874 |
The choice of pivot as first element is bad if the list is already almost |
| 10875 |
sorted. Let's add a variant which will pick up the pivot index randomly. The |
| 10876 |
previous routine worked also internally with comma separated lists, but for a |
| 10877 |
change this one will use internally lists of braced items (the initial |
| 10878 |
conversion via \csbxint{CSVtoList} handles all potential spurious space |
| 10879 |
problems). |
| 10880 |
|
| 10881 |
\unless\ifxetex % pour tester compilation de xint.dtx avec xetex qui n'a pas |
| 10882 |
% \pdfuniformdeviate |
| 10883 |
\begin{everbatim*} |
| 10884 |
% QuickSort expandably on comma separated values with random choice of pivots |
| 10885 |
% ====> Requires availability of \pdfuniformdeviate <==== |
| 10886 |
% \usepackage{xintfrac, xinttools} in preamble |
| 10887 |
\makeatletter |
| 10888 |
\def\QSx {\romannumeral0\qsx }% This is a f-expandable macro. |
| 10889 |
% This converts from comma separated values on input and back on output. |
| 10890 |
% **** NOTE: these steps (and the other ones too, actually) are costly if input |
| 10891 |
% has thousands of items. |
| 10892 |
\def\qsx #1{\xintlistwithsep{, }% |
| 10893 |
{\expandafter\qsx@sort@a\expandafter{\romannumeral0\xintcsvtolist{#1}}}}% |
| 10894 |
% |
| 10895 |
% we check if empty or single or double and if not pick up the first as Pivot: |
| 10896 |
\def\qsx@sort@a #1% |
| 10897 |
{\expandafter\qsx@sort@b\expandafter{\romannumeral0\xintlength{#1}}{#1}}% |
| 10898 |
\def\qsx@sort@b #1{\ifcase #1 |
| 10899 |
\expandafter\qsx@sort@empty |
| 10900 |
\or\expandafter\qsx@sort@single |
| 10901 |
\or\expandafter\qsx@sort@double |
| 10902 |
\else\expandafter\qsx@sort@c\fi {#1}}% |
| 10903 |
\def\qsx@sort@empty #1#2{ }% |
| 10904 |
\def\qsx@sort@single #1#2{#2}% |
| 10905 |
\catcode`_ 11 |
| 10906 |
\def\qsx@sort@double #1#2{\xintifGt #2{\xint_exchangetwo_keepbraces}{}#2}% |
| 10907 |
\catcode`_ 8 |
| 10908 |
\def\qsx@sort@c #1#2{% |
| 10909 |
\expandafter\qsx@sort@sep@a\expandafter |
| 10910 |
{\romannumeral0\xintnthelt{\pdfuniformdeviate #1+\@ne}{#2}}#2?}% |
| 10911 |
\def\qsx@sort@sep@a #1{\qsx@sort@sep@loop {}{}{}{#1}}% |
| 10912 |
\def\qsx@sort@sep@loop #1#2#3#4#5% |
| 10913 |
{% |
| 10914 |
\ifx?#5\expandafter\qsx@sort@sep@done\fi |
| 10915 |
\xintifCmp {#5}{#4}% |
| 10916 |
\qsx@sort@sep@appendtosmaller |
| 10917 |
\qsx@sort@sep@appendtoequal |
| 10918 |
\qsx@sort@sep@appendtogreater {#5}{#1}{#2}{#3}{#4}% |
| 10919 |
}% |
| 10920 |
% |
| 10921 |
\def\qsx@sort@sep@appendtoequal #1#2{\qsx@sort@sep@loop {#2{#1}}}% |
| 10922 |
\def\qsx@sort@sep@appendtogreater #1#2#3{\qsx@sort@sep@loop {#2}{#3{#1}}}% |
| 10923 |
\def\qsx@sort@sep@appendtosmaller #1#2#3#4{\qsx@sort@sep@loop {#2}{#3}{#4{#1}}}% |
| 10924 |
% |
| 10925 |
\def\qsx@sort@sep@done\xintifCmp #1% |
| 10926 |
\qsx@sort@sep@appendtosmaller |
| 10927 |
\qsx@sort@sep@appendtoequal |
| 10928 |
\qsx@sort@sep@appendtogreater #2#3#4#5#6% |
| 10929 |
{% |
| 10930 |
\expandafter\qsx@sort@recurse\expandafter |
| 10931 |
{\romannumeral0\qsx@sort@a {#4}}{\qsx@sort@a {#5}}{#3}% |
| 10932 |
}% |
| 10933 |
% |
| 10934 |
\def\qsx@sort@recurse #1#2#3{#2#3#1}% |
| 10935 |
% |
| 10936 |
\makeatother |
| 10937 |
|
| 10938 |
% EXAMPLES |
| 10939 |
\begingroup |
| 10940 |
\edef\z {\QSx {1.0, 0.5, 0.3, 1.5, 1.8, 2.0, 1.7, 0.4, 1.2, 1.4, |
| 10941 |
1.3, 1.1, 0.7, 1.6, 0.6, 0.9, 0.8, 0.2, 0.1, 1.9}} |
| 10942 |
\meaning\z |
| 10943 |
|
| 10944 |
\def\a {3.123456789123456789}\def\b {3.123456789123456788} |
| 10945 |
\def\c {3.123456789123456790}\def\d {3.123456789123456787} |
| 10946 |
\oodef\z {\QSx { \a, \b, \c, \d}}% |
| 10947 |
% The space before \a to let it not be expanded during the conversion from CSV |
| 10948 |
% values to List. The \oodef expands exactly twice (via a bunch of \expandafter's) |
| 10949 |
\meaning\z |
| 10950 |
|
| 10951 |
\def\somenumbers{% |
| 10952 |
3997.6421, 8809.9358, 1805.4976, 5673.6478, 3179.1328, 1425.4503, 4417.7691, |
| 10953 |
2166.9040, 9279.7159, 3797.6992, 8057.1926, 2971.9166, 9372.2699, 9128.4052, |
| 10954 |
1228.0931, 3859.5459, 8561.7670, 2949.6929, 3512.1873, 1698.3952, 5282.9359, |
| 10955 |
1055.2154, 8760.8428, 7543.6015, 4934.4302, 7526.2729, 6246.0052, 9512.4667, |
| 10956 |
7423.1124, 5601.8436, 4433.5361, 9970.4849, 1519.3302, 7944.4953, 4910.7662, |
| 10957 |
3679.1515, 8167.6824, 2644.4325, 8239.4799, 4595.1908, 1560.2458, 6098.9677, |
| 10958 |
3116.3850, 9130.5298, 3236.2895, 3177.6830, 5373.1193, 5118.4922, 2743.8513, |
| 10959 |
8008.5975, 4189.2614, 1883.2764, 9090.9641, 2625.5400, 2899.3257, 9157.1094, |
| 10960 |
8048.4216, 3875.6233, 5684.3375, 8399.4277, 4528.5308, 6926.7729, 6941.6278, |
| 10961 |
9745.4137, 1875.1205, 2755.0443, 9161.1524, 9491.1593, 8857.3519, 4290.0451, |
| 10962 |
2382.4218, 3678.2963, 5647.0379, 1528.7301, 2627.8957, 9007.9860, 1988.5417, |
| 10963 |
2405.1911, 5065.8063, 5856.2141, 8989.8105, 9349.7840, 9970.3013, 8105.4062, |
| 10964 |
3041.7779, 5058.0480, 8165.0721, 9637.7196, 1795.0894, 7275.3838, 5997.0429, |
| 10965 |
7562.6481, 8084.0163, 3481.6319, 8078.8512, 2983.7624, 3925.4026, 4931.5812, |
| 10966 |
1323.1517, 6253.0945}% |
| 10967 |
|
| 10968 |
\oodef\z {\QSx \somenumbers}% produced as a comma+space separated list |
| 10969 |
% black magic as workaround to the shrinkability of spaces in last line... |
| 10970 |
\hsize 87\fontcharwd\font`0 |
| 10971 |
\lccode`~=32 |
| 10972 |
\lowercase{\def~}{\discretionary{}{}{\kern\fontcharwd\font`0}}\catcode32 13 |
| 10973 |
\noindent\phantom{00}\scantokens\expandafter{\meaning\z}\par |
| 10974 |
\endgroup |
| 10975 |
\end{everbatim*} |
| 10976 |
\fi % fin de si pas xetex |
| 10977 |
|
| 10978 |
|
| 10979 |
All the previous examples were with numbers which could have been handled via |
| 10980 |
|\ifdim| tests rather than the \csbxint{ifCmp} macro from \xintfracname; using |
| 10981 |
|\ifdim| tests would naturally be faster. Even faster routine is |code 6| at |
| 10982 |
(link removed) which uses |\pdfescapestring| and a |
| 10983 |
Merge Sort algorithm. |
| 10984 |
|
| 10985 |
We then turn to a graphical illustration of the algorithm.% |
| 10986 |
% |
| 10987 |
\footnote{I have rewritten (2015/11/21) the routine to do only once (and not thrice) the |
| 10988 |
needed calls to \csa{xintifCmp}, up to the price of one additional |\edef|, |
| 10989 |
although due to the context execution time on our side is not an issue and |
| 10990 |
moreover is anyhow overwhelmed by the TikZ's activities. Simultaneously I |
| 10991 |
have updated the code. |
| 10992 |
The |
| 10993 |
variant with the choice of pivot on the right has more overhead: the reason |
| 10994 |
is simply that we do not convert the data into an array, but maintain a list |
| 10995 |
of tokens with self-reorganizing delimiters.} |
| 10996 |
% |
| 10997 |
For simplicity the pivot is always chosen as the first list item. Then we also |
| 10998 |
give a variant which picks up the last item as pivot. |
| 10999 |
\begin{everbatim*} |
| 11000 |
% in LaTeX preamble: |
| 11001 |
% \usepackage{xintfrac, xinttools} |
| 11002 |
% \usepackage{color} |
| 11003 |
% or, when using Plain TeX: |
| 11004 |
% \input xintfrac.sty \input xinttools.sty |
| 11005 |
% \input color.tex |
| 11006 |
% |
| 11007 |
% Color definitions |
| 11008 |
\definecolor{LEFT}{RGB}{216,195,88} |
| 11009 |
\definecolor{RIGHT}{RGB}{208,231,153} |
| 11010 |
\definecolor{INERT}{RGB}{199,200,194} |
| 11011 |
\definecolor{INERTpiv}{RGB}{237,237,237} |
| 11012 |
\definecolor{PIVOT}{RGB}{109,8,57} |
| 11013 |
% Start of macro defintions |
| 11014 |
\makeatletter |
| 11015 |
% \catcode`? 3 % a bit too paranoid. Normal ? will do. |
| 11016 |
% |
| 11017 |
% argument will never be empty |
| 11018 |
\def\QS@cmp@a #1{\QS@cmp@b #1??}% |
| 11019 |
\def\QS@cmp@b #1{\noexpand\QS@sep@A\@ne{#1}\QS@cmp@d {#1}}% |
| 11020 |
\def\QS@cmp@d #1#2{\ifx ?#2\expandafter\QS@cmp@done\fi |
| 11021 |
\xintifCmp {#1}{#2}\tw@\@ne\z@{#2}\QS@cmp@d {#1}}% |
| 11022 |
\def\QS@cmp@done #1?{?}% |
| 11023 |
% |
| 11024 |
\def\QS@sep@A #1?{\QSLr\QS@sep@L #1\thr@@?#1\thr@@?#1\thr@@?}% |
| 11025 |
\def\QS@sep@L #1#2{\ifcase #1{#2}\or\or\else |
| 11026 |
\expandafter\QS@sep@I@start\fi \QS@sep@L}% |
| 11027 |
\def\QS@sep@I@start\QS@sep@L {\noexpand\empty?\QSIr\QS@sep@I}% |
| 11028 |
\def\QS@sep@I #1#2{\ifcase#1\or{#2}\or\else\expandafter\QS@sep@R@start\fi\QS@sep@I}% |
| 11029 |
\def\QS@sep@R@start\QS@sep@I {\noexpand\empty?\QSRr\QS@sep@R}% |
| 11030 |
\def\QS@sep@R #1#2{\ifcase#1\or\or{#2}\else\expandafter\QS@sep@done\fi\QS@sep@R}% |
| 11031 |
\def\QS@sep@done\QS@sep@R {\noexpand\empty?}% |
| 11032 |
% |
| 11033 |
\def\QS@loop {% |
| 11034 |
\xintloop |
| 11035 |
% pivot phase |
| 11036 |
\def\QS@pivotcount{0}% |
| 11037 |
\let\QSLr\DecoLEFTwithPivot \let\QSIr \DecoINERT |
| 11038 |
\let\QSRr\DecoRIGHTwithPivot \let\QSIrr\DecoINERT |
| 11039 |
\centerline{\QS@list}% |
| 11040 |
% sorting phase |
| 11041 |
\ifnum\QS@pivotcount>\z@ |
| 11042 |
\def\QSLr {\QS@cmp@a}\def\QSRr {\QS@cmp@a}% |
| 11043 |
\def\QSIr {\QSIrr}\let\QSIrr\relax |
| 11044 |
\edef\QS@list{\QS@list}% compare |
| 11045 |
\let\QSLr\relax\let\QSRr\relax\let\QSIr\relax |
| 11046 |
\edef\QS@list{\QS@list}% separate |
| 11047 |
\def\QSLr ##1##2?{\ifx\empty##1\else\noexpand \QSLr {{##1}##2}\fi}% |
| 11048 |
\def\QSIr ##1##2?{\ifx\empty##1\else\noexpand \QSIr {{##1}##2}\fi}% |
| 11049 |
\def\QSRr ##1##2?{\ifx\empty##1\else\noexpand \QSRr {{##1}##2}\fi}% |
| 11050 |
\edef\QS@list{\QS@list}% gather |
| 11051 |
\let\QSLr\DecoLEFT \let\QSRr\DecoRIGHT |
| 11052 |
\let\QSIr\DecoINERTwithPivot \let\QSIrr\DecoINERT |
| 11053 |
\centerline{\QS@list}% |
| 11054 |
\repeat }% |
| 11055 |
% |
| 11056 |
% \xintFor* loops handle gracefully empty lists. |
| 11057 |
\def\DecoLEFT #1{\xintFor* ##1 in {#1} \do {\colorbox{LEFT}{##1}}}% |
| 11058 |
\def\DecoINERT #1{\xintFor* ##1 in {#1} \do {\colorbox{INERT}{##1}}}% |
| 11059 |
\def\DecoRIGHT #1{\xintFor* ##1 in {#1} \do {\colorbox{RIGHT}{##1}}}% |
| 11060 |
\def\DecoPivot #1{\begingroup |
| 11061 |
\color{PIVOT}\advance\fboxsep-\fboxrule\fbox{#1}\endgroup}% |
| 11062 |
% |
| 11063 |
\def\DecoLEFTwithPivot #1{\xdef\QS@pivotcount{\the\numexpr\QS@pivotcount+\@ne}% |
| 11064 |
\xintFor* ##1 in {#1} \do |
| 11065 |
{\xintifForFirst {\DecoPivot {##1}}{\colorbox{LEFT}{##1}}}}% |
| 11066 |
\def\DecoINERTwithPivot #1{\xdef\QS@pivotcount{\the\numexpr\QS@pivotcount+\@ne}% |
| 11067 |
\xintFor* ##1 in {#1} \do |
| 11068 |
{\xintifForFirst {\colorbox{INERTpiv}{##1}}{\colorbox{INERT}{##1}}}}% |
| 11069 |
\def\DecoRIGHTwithPivot #1{\xdef\QS@pivotcount{\the\numexpr\QS@pivotcount+\@ne}% |
| 11070 |
\xintFor* ##1 in {#1} \do |
| 11071 |
{\xintifForFirst {\DecoPivot {##1}}{\colorbox{RIGHT}{##1}}}}% |
| 11072 |
% |
| 11073 |
\def\QuickSort #1{% warning: not compatible with empty #1. |
| 11074 |
% initialize, doing conversion from comma separated values |
| 11075 |
% to a list of braced items |
| 11076 |
\edef\QS@list{\noexpand\QSRr{\xintCSVtoList{#1}}}% |
| 11077 |
% may \edef's are to follow anyhow |
| 11078 |
% earlier I did a first drawing of the list, here with the color of RIGHT elements, |
| 11079 |
% but the color should have been for example white, anyway I drop this first line |
| 11080 |
%\let\QSRr\DecoRIGHT |
| 11081 |
%\par\centerline{\QS@list}% |
| 11082 |
% |
| 11083 |
% loop as many times as needed |
| 11084 |
\QS@loop }% |
| 11085 |
% |
| 11086 |
% \catcode`? 12 % in case we had used a funny ? as delimiter. |
| 11087 |
\makeatother |
| 11088 |
%% End of macro definitions. |
| 11089 |
%% Start of Example |
| 11090 |
\begingroup\offinterlineskip |
| 11091 |
\small |
| 11092 |
% \QuickSort {1.0, 0.5, 0.3, 1.5, 1.8, 2.0, 1.7, 0.4, 1.2, 1.4, |
| 11093 |
% 1.3, 1.1, 0.7, 1.6, 0.6, 0.9, 0.8, 0.2, 0.1, 1.9} |
| 11094 |
% \medskip |
| 11095 |
% with repeated values |
| 11096 |
\QuickSort {1.0, 0.5, 0.3, 0.8, 1.5, 1.8, 2.0, 1.7, 0.4, 1.2, 1.4, |
| 11097 |
1.3, 1.1, 0.7, 0.3, 1.6, 0.6, 0.3, 0.8, 0.2, 0.8, 0.7, 1.2} |
| 11098 |
\endgroup |
| 11099 |
\end{everbatim*} |
| 11100 |
|
| 11101 |
Here is the variant which always picks the pivot as the rightmost element. |
| 11102 |
|
| 11103 |
\begin{everbatim*} |
| 11104 |
\makeatletter |
| 11105 |
% |
| 11106 |
\def\QS@cmp@a #1{\noexpand\QS@sep@A\expandafter\QS@cmp@d\expandafter |
| 11107 |
{\romannumeral0\xintnthelt{-1}{#1}}#1??}% |
| 11108 |
% |
| 11109 |
\def\DecoLEFTwithPivot #1{\xdef\QS@pivotcount{\the\numexpr\QS@pivotcount+\@ne}% |
| 11110 |
\xintFor* ##1 in {#1} \do |
| 11111 |
{\xintifForLast {\DecoPivot {##1}}{\colorbox{LEFT}{##1}}}} |
| 11112 |
\def\DecoINERTwithPivot #1{\xdef\QS@pivotcount{\the\numexpr\QS@pivotcount+\@ne}% |
| 11113 |
\xintFor* ##1 in {#1} \do |
| 11114 |
{\xintifForLast {\colorbox{INERTpiv}{##1}}{\colorbox{INERT}{##1}}}} |
| 11115 |
\def\DecoRIGHTwithPivot #1{\xdef\QS@pivotcount{\the\numexpr\QS@pivotcount+\@ne}% |
| 11116 |
\xintFor* ##1 in {#1} \do |
| 11117 |
{\xintifForLast {\DecoPivot {##1}}{\colorbox{RIGHT}{##1}}}} |
| 11118 |
\def\QuickSort #1{% |
| 11119 |
% initialize, doing conversion from comma separated values |
| 11120 |
% to a list of braced items |
| 11121 |
\edef\QS@list{\noexpand\QSLr {\xintCSVtoList{#1}}}% |
| 11122 |
% many \edef's are to follow anyhow |
| 11123 |
% |
| 11124 |
% loop as many times as needed |
| 11125 |
\QS@loop }% |
| 11126 |
\makeatother |
| 11127 |
\begingroup\offinterlineskip |
| 11128 |
\small |
| 11129 |
% \QuickSort {1.0, 0.5, 0.3, 1.5, 1.8, 2.0, 1.7, 0.4, 1.2, 1.4, |
| 11130 |
% 1.3, 1.1, 0.7, 1.6, 0.6, 0.9, 0.8, 0.2, 0.1, 1.9} |
| 11131 |
% \medskip |
| 11132 |
% with repeated values |
| 11133 |
\QuickSort {1.0, 0.5, 0.3, 0.8, 1.5, 1.8, 2.0, 1.7, 0.4, 1.2, 1.4, |
| 11134 |
1.3, 1.1, 0.7, 0.3, 1.6, 0.6, 0.3, 0.8, 0.2, 0.8, 0.7, 1.2} |
| 11135 |
\endgroup |
| 11136 |
\end{everbatim*} |
| 11137 |
|
| 11138 |
The choice of the first or last item as pivot is not a good one as nearly |
| 11139 |
ordered lists will take quadratic time. But for explaining the algorithm via a |
| 11140 |
graphical interpretation, it is not that bad. If one wanted to pick up the |
| 11141 |
pivot randomly, the routine would have to be substantially rewritten: in |
| 11142 |
particular the |\Deco..withPivot| macros need to know where the pivot is, and |
| 11143 |
currently this is implemented by using either |\xintifForFirst| or |
| 11144 |
|\xintifForLast|. |
| 11145 |
|
| 11146 |
\clearpage |
| 11147 |
|
| 11148 |
\expandafter\let\csname ExamplesnameUp\endcsname\undefined |
| 11149 |
|
| 11150 |
\csname xintbundlenameUp\endcsname |
| 11151 |
|
| 11152 |
\def\xintRunningHeader{{\inheadertrue\catcode`,12\relax |
| 11153 |
\DOCxintfrontpage, |
| 11154 |
\xintbundlename, |
| 11155 |
\xintkernelname, |
| 11156 |
\xintcorename, |
| 11157 |
\xintname, |
| 11158 |
\xintfracname, |
| 11159 |
\xintbinhexname, |
| 11160 |
\xintgcdname, |
| 11161 |
\xintseriesname, |
| 11162 |
\xintcfracname}} |
| 11163 |
\markboth{\makebox[0pt]{\xintRunningHeader}}{\makebox[0pt]{\xintRunningHeader}} |
| 11164 |
|
| 11165 |
\etocdepthtag.toc {macros} |
| 11166 |
\addtocontents{toc}{\gdef\string\tocstylesectionbracedcolor{{tocstylebundlesectioncolor}}} |
| 11167 |
|
| 11168 |
\part{The macro layer for expandable computations: \xintcorename, \xintname, |
| 11169 |
\xintfracname, and some extras} |
| 11170 |
\RaisedLabel[15]{sec:bundle} |
| 11171 |
|
| 11172 |
|
| 11173 |
\begin{framed} |
| 11174 |
WARNING ! |
| 11175 |
|
| 11176 |
The documentation is getting old, and is in need of rewrites for many |
| 11177 |
sections, particularly for examples. |
| 11178 |
|
| 11179 |
We do try to keep updated the description of macros |
| 11180 |
provided by the packages. |
| 11181 |
\end{framed} |
| 11182 |
|
| 11183 |
\etocsetnexttocdepth{section} |
| 11184 |
\localtableofcontents |
| 11185 |
|
| 11186 |
\section{The \xintbundlename} |
| 11187 |
|
| 11188 |
\localtableofcontents |
| 11189 |
|
| 11190 |
\subsection{Characteristics} |
| 11191 |
|
| 11192 |
\begin{framed} |
| 11193 |
The main characteristics are: |
| 11194 |
\begin{enumerate} |
| 11195 |
\item exact algebra on ``big numbers'', integers as well as |
| 11196 |
fractions, |
| 11197 |
\item floating point variants with user-chosen precision, |
| 11198 |
\item the computational macros are compatible with expansion-only context, |
| 11199 |
\item the bundle comes with parsers (integer-only, or handling fractions, or |
| 11200 |
doing floating point computations) of infix operations implementing |
| 11201 |
beyond infix operations extra features such as dummy variables. |
| 11202 |
\end{enumerate} |
| 11203 |
|
| 11204 |
|
| 11205 |
Since |1.2| ``big numbers'' must have less than about \dtt{19950} digits: |
| 11206 |
the maximal number of digits for addition is at \dtt{19968} digits, and it |
| 11207 |
is \dtt{19959} for multiplication. The reasonable range of use of the |
| 11208 |
package is with numbers of up to a few hundred digits.\footnotemark |
| 11209 |
|
| 11210 |
\TeX\ does not know off-hand how to print on the page such very long |
| 11211 |
numbers, see \autoref{ssec:printnumber}. |
| 11212 |
\end{framed} |
| 11213 |
\footnotetext{For example multiplication of integers having from \dtt{50} to |
| 11214 |
\dtt{100} digits takes roughly of the order of the millisecond on a 2012 |
| 11215 |
desktop computer. I compared this to using Python3: using timeit module on a |
| 11216 |
wrapper defined as |return w*z| with random integers of \dtt{100} digits, I |
| 11217 |
observe on the same computer a computation time of roughly $4.10^{-7}$s per |
| 11218 |
call. And with |return str(w*z)| then this becomes more like $16.10^{-7}$s |
| 11219 |
per call. And with |return str(int(W)*int(Z))| where |W| and |Z| are |
| 11220 |
strings, this becomes about $26.10^{-7}$s (I am deliberately ignoring |
| 11221 |
Python's Decimal module here...) Anyway, my sentence from earlier version of |
| 11222 |
this documentation: \emph{this is, I guess, at least about 1000 times slower |
| 11223 |
than what can be expected with any reasonable programming language,} is |
| 11224 |
about right. I then added: \emph{nevertheless as compilation of a typical |
| 11225 |
\LaTeX\ document already takes of the order of seconds and even dozens of |
| 11226 |
seconds for long ones, this leaves room for reasonably many computations |
| 11227 |
via \xintexprname or via direct use of the macros of |
| 11228 |
\xintname/\xintfracname.}} |
| 11229 |
|
| 11230 |
Integers with only $10$ digits and starting with a $3$ already exceed the |
| 11231 |
\TeX{} bound; and \TeX{} does not have a native processing of floating point |
| 11232 |
numbers (multiplication by a decimal number of a dimension register is allowed |
| 11233 |
--- this is used for example by the |
| 11234 |
\href{http://mirrors.ctan.org/graphics/pgf/base}{pgf} basic math engine.) |
| 11235 |
|
| 11236 |
\TeX{} elementary operations on numbers are done via the non-expandable |
| 11237 |
\emph{\char92advance, \char92multiply, \emph{and} \char92divide} assignments. |
| 11238 |
This was changed with \eTeX{}'s |\numexpr| which does expandable computations |
| 11239 |
using standard infix notations with \TeX{} integers. But \eTeX{} did not |
| 11240 |
modify the \TeX{} bound on acceptable integers, and did not add floating point |
| 11241 |
support. |
| 11242 |
|
| 11243 |
The \ctanpackage{bigintcalc} package by |
| 11244 |
\textsc{Heiko Oberdiek} provided expandable macros (using some of |\numexpr| |
| 11245 |
possibilities, when available) on arbitrarily big integers, beyond the \TeX{} |
| 11246 |
bound. It does not provide an expression parser.% |
| 11247 |
% |
| 11248 |
\footnote{One can currently use package |
| 11249 |
\ctanpackage{bnumexpr} to associate the |bigintcalc| |
| 11250 |
macros with an expression parser. This may be unavailable in future if |
| 11251 |
|bnumexpr| becomes more tightly associated with future evolutions or |
| 11252 |
variants of \xintcorename. EDIT: still possible as of \ctanpackage{bnumexpr} |
| 11253 |
|1.6| |2025/09/01|.} |
| 11254 |
% |
| 11255 |
\xintname did it again using more of |\numexpr| for higher speed, and in a |
| 11256 |
later evolution added handling of exact fractions, of scientific numbers, and |
| 11257 |
an expression parser. Arbitrary precision floating points operations were |
| 11258 |
added as a derivative, and not part of the initial design goal. |
| 11259 |
|
| 11260 |
The concept of signed infinities, signed zeroes, |NaN|'s, error |
| 11261 |
traps\dots,\footnote{The latter exist as work-in-progress for some time in the |
| 11262 |
source code.} have not been implemented, only the notion of `scientific |
| 11263 |
notation with a given number of significant figures'.% |
| 11264 |
% |
| 11265 |
\footnote{Multiplication of two floats with |P=\xinttheDigits| digits is |
| 11266 |
first done exactly then rounded to |P| digits, rather than using a |
| 11267 |
specially tailored multiplication for floating point numbers which |
| 11268 |
would be more efficient (it is a waste to evaluate fully the |
| 11269 |
multiplication result with |2P| or |2P-1| digits.)} |
| 11270 |
|
| 11271 |
The \LaTeX3 project has implemented expandably floating-point computations with |
| 11272 |
\dtt{16} significant figures |
| 11273 |
(\href{https://ctan.org/pkg/l3kernel}{l3fp}), including |
| 11274 |
functions such as exp, log, sine and cosine.\footnote{at the time of writing (2014/10/28) the |
| 11275 |
\href{https://ctan.org/pkg/l3kernel}{l3fp} (exactly represented) floating |
| 11276 |
point numbers have their exponents limited to $\pm$\dtt{9999}.} |
| 11277 |
% |
| 11278 |
|
| 11279 |
More directly related to the \xintbundlename there is the \liiibigint{} |
| 11280 |
package, also devoted to big integers and in development a.t.t.o.w (2015/10/09, |
| 11281 |
no division yet). It is part of the experimental trunk of the |
| 11282 |
\href{http://latex-project.org}{\LaTeX3 Project} and provides an expression |
| 11283 |
parser for expandable arithmetic with big integers. Its author Bruno |
| 11284 |
\textsc{Le Floch} succeeded brilliantly into implementing expandably the |
| 11285 |
Karatsuba multiplication algorithm and he achieves \emph{sub-quadratic growth |
| 11286 |
for the computation time}. This shows up very clearly with numbers having |
| 11287 |
thousands of digits, up to the maximum which a.t.t.o.w is at $8192$ digits. |
| 11288 |
|
| 11289 |
|
| 11290 |
The \liiibigint{} multiplication from late |2015| is observed to be roughly |
| 11291 |
|3x--4x| faster than the one from \csbxint{iiexpr} in the range of \dtt{4000} |
| 11292 |
to \dtt{5000} digits integers, and isn't far from being |9x| faster at |
| 11293 |
\dtt{8000} digits. On the other hand \csbxint{iiexpr}'s multiplication is |
| 11294 |
found to be on average roughly |2.5x| faster than \liiibigint's for numbers up |
| 11295 |
to \dtt{100} digits and the two packages achieve about the same speed at |
| 11296 |
\dtt{900} digits: but each such multiplication of numbers of \dtt{900} digits |
| 11297 |
costs about one or two tenths of a second on a 2012 desktop computer, whereas |
| 11298 |
the order of magnitude is rather the |ms| for numbers with \dtt{50--100} |
| 11299 |
digits.\footnote{I have tested this again on |2016/12/19|, but the macros have |
| 11300 |
not changed on the \liiibigint{} side and barely on the \xintcorename side, |
| 11301 |
hence I got again the same results\dots} |
| 11302 |
|
| 11303 |
Even with the superior \liiibigint{} Karatsuba multiplication it takes about |
| 11304 |
|3.5s| on this 2012 desktop computer for a single multiplication of two |
| 11305 |
\dtt{5000}-digits numbers. Hence it is not possible to do routinely such |
| 11306 |
computations in a document. I have long been thinking that without the |
| 11307 |
expandability constraint much higher speeds could be achieved, but perhaps I |
| 11308 |
have not given enough thought to sustain that optimistic stance.\footnote{The |
| 11309 |
\ctanpackage{apnum} package implements |
| 11310 |
(non-expandably) arbitrary precision fixed point algebra and (v1.6) |
| 11311 |
functions exp, log, sqrt, the trigonometrical direct and inverse functions.} |
| 11312 |
|
| 11313 |
I remain of the opinion that if one really wants to do computations with |
| 11314 |
\emph{thousands} of digits, one should drop the expandability requirement. |
| 11315 |
Indeed, as clearly demonstrated long ago by the |
| 11316 |
\href{https://ctan.org/pkg/pi}{pi computing file} by \textsc{D. Roegel} one |
| 11317 |
can program \TeX{} to compute with many digits at a much higher speed than |
| 11318 |
what \xintname achieves: but, direct access to memory storage in one form or |
| 11319 |
another seems a necessity for this kind of speed and one has to renounce at |
| 11320 |
the complete expandability.% |
| 11321 |
% |
| 11322 |
\footnote{The Lua\TeX{} project possibly makes endeavours such as \xintname |
| 11323 |
appear even more insane that they are, in truth: \xintname is able to handle |
| 11324 |
fast enough computations involving numbers with less than one hundred digits |
| 11325 |
and brings this to all engines.} |
| 11326 |
|
| 11327 |
\subsection{Floating point evaluations} |
| 11328 |
\label{ssec:floatingpoint} |
| 11329 |
|
| 11330 |
Floating point macros are provided by package \xintfracname to work with a |
| 11331 |
given arbitrary precision |P|. The default value is $P=16$ meaning that the |
| 11332 |
significands of the produced (non-zero) numbers have \dtt{16} decimal digits. |
| 11333 |
The syntax to set the precision to |P| is |
| 11334 |
% |
| 11335 |
\centeredline{|\xintDigits:=P\relax|} |
| 11336 |
% |
| 11337 |
The value is local to the group or environment (if using \LaTeX). To query the |
| 11338 |
current value use \csbxint{theDigits}. |
| 11339 |
|
| 11340 |
Most floating point macros accept an optional first argument |[P]| which then |
| 11341 |
sets the target precision and replaces the |\xintDigits| assigned value (the |
| 11342 |
|[P]| must be repeated if the arguments are themselves \xintfracname macros |
| 11343 |
with arguments of their own.) In this section |P| refers to the prevailing |
| 11344 |
|\xinttheDigits| float precision or to the target precision set in this way as |
| 11345 |
an optional argument. |
| 11346 |
|
| 11347 |
\csbxint{floatexpr}|[Q]...\relax| also admits an optional argument |[Q]| but |
| 11348 |
it has an altogether different meaning: the computations are always done with |
| 11349 |
the prevailing |\xinttheDigits| precision and the optional argument |Q| is |
| 11350 |
used for the final rounding. This makes sense only if |Q<\xinttheDigits| and |
| 11351 |
is intended to clean up the result from dubious last digits (when |Q<0| it |
| 11352 |
indicates rather by how many digits one should reduce the mantissa lengths via a |
| 11353 |
final rounding). |
| 11354 |
|
| 11355 |
|
| 11356 |
|
| 11357 |
|
| 11358 |
|
| 11359 |
|
| 11360 |
|
| 11361 |
\begin{framed} |
| 11362 |
The |IEEE 754|\footnotemark\ requirement of \emph{correct rounding} for |
| 11363 |
addition, subtraction, multiplication, division and square root is achieved |
| 11364 |
(in arbitrary precision) by the macros of \xintfracname hence also by the |
| 11365 |
infix operators |+|, |-|, |*|, |/|. |
| 11366 |
|
| 11367 |
This means that for operands given with at most |P| significant digits |
| 11368 |
(and arbitrary exponents) the output coincides exactly with the rounding |
| 11369 |
of the exact theoretical result (barring overflow or underflow). |
| 11370 |
|
| 11371 |
|
| 11372 |
{\footnotesize Due to a typographical oversight, this documentation |
| 11373 |
(up to |1.2j|) adjoined |^| and |**| to the above list of |
| 11374 |
infix operators. But as |
| 11375 |
is explained in \autoref{xintFloatPower}, what is guaranteed regarding |
| 11376 |
integer powers is an error of at most |0.52ulp|, not the correct rounding. |
| 11377 |
Half-integer powers are computed as square roots of integer powers.\par }% |
| 11378 |
|
| 11379 |
The rounding mode is ``round to nearest, ties away from zero''. |
| 11380 |
It is not customizable. |
| 11381 |
|
| 11382 |
Currently \xintfracname has no notion of |NaN|s or signed infinities or signed |
| 11383 |
zeroes, but this is intended for the future. |
| 11384 |
\end{framed} |
| 11385 |
% |
| 11386 |
\footnotetext{The |IEEE 754-1985| standard was for hardware implementations of |
| 11387 |
binary floating-point arithmetic with a specific value for the precision |
| 11388 |
($24$ bits for single precision, $53$ bits for double precision). The newer |
| 11389 |
{\texttt{IEEE 754-2008}} |
| 11390 |
(\url{https://en.wikipedia.org/wiki/IEEE_floating_point}) normalizes five |
| 11391 |
basic formats, three binaries and two decimals ($16$ and $34$ decimal |
| 11392 |
digits) and discusses extended formats with higher precision. These |
| 11393 |
standards are only indirectly relevant to libraries like \xintname dealing |
| 11394 |
with arbitrary precision.% |
| 11395 |
} |
| 11396 |
|
| 11397 |
|
| 11398 |
Since release |
| 11399 |
|1.2f|, square root extraction achieves correct rounding in arbitrary |
| 11400 |
precision. |
| 11401 |
|
| 11402 |
See \xintlogname for fractional powers and \xinttrigname for trigonometrical |
| 11403 |
functions. |
| 11404 |
|
| 11405 |
|
| 11406 |
The maximal floating point decimal exponent is currently |
| 11407 |
\dtt{\number"7FFFFFFF} which is the maximal number handled by \TeX. The |
| 11408 |
minimal exponent is its opposite. But this means that overflow or underflow |
| 11409 |
are detected only via low-level |\numexpr| arithmetic overflows which are |
| 11410 |
basically un-recoverable. Besides there are some border effects as the |
| 11411 |
routines need to add or subtract lengths of numbers from exponents, possibly |
| 11412 |
triggering the low-level overflows. In the future not only the Precision but |
| 11413 |
also the maximal and minimal exponents |Emin| and |Emax| will be specifiable |
| 11414 |
by the user. |
| 11415 |
|
| 11416 |
Since |1.2f|, the float macros round their inputs to the target precision |P| |
| 11417 |
before further processing. Formerly, the initial rounding was done to |P+2| |
| 11418 |
digits (and at least |P+3| for the power operation.) |
| 11419 |
|
| 11420 |
The more ambitious model would be for the computing macros to obey the |
| 11421 |
intrinsic precision of their inputs, i.e.\@{} to compute the correct rounding to |
| 11422 |
|P| digits of the exact mathematical result corresponding to inputs allowed to |
| 11423 |
have their own higher precision.% |
| 11424 |
% |
| 11425 |
\footnote{The |MPFR| library |
| 11426 |
\url{http://www.mpfr.org/} implements this but it does not know fractions!} |
| 11427 |
% |
| 11428 |
This would be feasible by \xintfracname which after all knows how to compute |
| 11429 |
exactly, but I have for the time being decided that for reasons of efficiency, |
| 11430 |
the chosen model is the one of rounding inputs to the target precision first. |
| 11431 |
|
| 11432 |
The float macros of \xintfracname have to handle inputs which |
| 11433 |
not only may have much more digits than the target float precision, but may |
| 11434 |
even be fractions: in a way this means infinite precision. |
| 11435 |
|
| 11436 |
From releases |1.08a| to |1.2j| a fraction input $AeM/BeN$ had its numerator |
| 11437 |
and denominator $A$ and $B$ truncated to |Q+2| digits of precision, then the |
| 11438 |
substituted fraction was correctly rounded to |Q| digits of precision (usually |
| 11439 |
with |Q| set to |P+2|) and then the operation was implemented on such rounded |
| 11440 |
inputs. But this meant that two fractions representing the same rational |
| 11441 |
number could end up being rounded differently (with a difference of one unit |
| 11442 |
in the last place), if it had numerators and denominators with at least |Q+3| |
| 11443 |
digits. |
| 11444 |
|
| 11445 |
Starting with release |1.2k| a fractional input $AeM/BeN$ is handled |
| 11446 |
intrinsically: the fraction, independently of its representation $AeM/BeN$, is |
| 11447 |
\emph{correctly rounded} to |P| digits during the input parsing. Hence the |
| 11448 |
output depends only on its arguments as mathematical fractions and not on |
| 11449 |
their representatives as quotients. |
| 11450 |
|
| 11451 |
Notice that in float expressions, the |/| is treated as operator, and is |
| 11452 |
applied to arguments which are generally already |P|-floats, hence the above |
| 11453 |
discussion becomes relevant in this context only for the special input form |
| 11454 |
|qfloat(A/B)| or when using a sub-expression |\xintexpr A/B\relax| embedded in |
| 11455 |
the float expression with |A| or |B| having more digits than the prevailing |
| 11456 |
float precision |P|. |
| 11457 |
|
| 11458 |
|
| 11459 |
|
| 11460 |
|
| 11461 |
|
| 11462 |
|
| 11463 |
\subsection{Expansion matters} |
| 11464 |
|
| 11465 |
\subsubsection{Full expansion of the first token} |
| 11466 |
\label{ssec:expansions} |
| 11467 |
|
| 11468 |
The whole business of \xintname is to build upon |\numexpr| and handle |
| 11469 |
arbitrarily large numbers. Each basic operation is thus done via a macro: |
| 11470 |
\csbxint{iiAdd}, \csbxint{iiSub}, \csbxint{iiMul}, \csbxint{iiDivision}. In |
| 11471 |
order to handle more complex operations, it must be possible to nest these |
| 11472 |
macros. |
| 11473 |
% |
| 11474 |
An expandable macro can not execute a |\def| or an |\edef|. But the macro must |
| 11475 |
expand its arguments to find the digits it is supposed to manipulate. \TeX{} |
| 11476 |
provides a tool to do the job of (expandable !) repeated expansion of the |
| 11477 |
first token found until hitting something non expandable, such as a digit, a |
| 11478 |
|\def| token, a brace, a |\count| token, etc...\@{} is found. A space token also |
| 11479 |
will stop the expansion (and be swallowed, contrarily to the non-expandable |
| 11480 |
tokens). |
| 11481 |
|
| 11482 |
By convention in this manual \fexpan sion (``full expansion'' or ``full first |
| 11483 |
expansion'') will be this \TeX{} process of expanding repeatedly the first |
| 11484 |
token seen. For those familiar with \LaTeX3 (which is not used by \xintname) |
| 11485 |
this is what is called in its documentation full expansion, whereas expansion |
| 11486 |
inside |\edef| would be described I think as ``exhaustive'' expansion |
| 11487 |
and will be referred too in this manual as \xexpan sion. |
| 11488 |
|
| 11489 |
Most of the package macros, and all those dealing with computations% |
| 11490 |
% |
| 11491 |
\footnote{except \csbxint{XTrunc}.}, |
| 11492 |
% |
| 11493 |
are expandable in the strong sense that they expand to their final result via |
| 11494 |
this \fexpan sion. This will be signaled in their descriptions via a |
| 11495 |
\etype{}star in the margin. |
| 11496 |
|
| 11497 |
These macros not only have this property of \fexpan dability, they all begin |
| 11498 |
by first applying \fexpan sion to their arguments. Again from \LaTeX3's |
| 11499 |
conventions this will be signaled by a% |
| 11500 |
% |
| 11501 |
\ntype{{\setbox0 \hbox{\Ff}\hbox to \wd0 {\hss f\hss}}} |
| 11502 |
% |
| 11503 |
margin annotation next to the description of the arguments. |
| 11504 |
|
| 11505 |
\subsubsection{Summary of important expandability aspects} |
| 11506 |
|
| 11507 |
\begin{enumerate} |
| 11508 |
\item the macros \fexpan d their arguments, this means that they expand the |
| 11509 |
first token seen (for each argument), then expand, etc..., until something |
| 11510 |
un-expandable such as a\strut{} digit or a brace is hit against. This |
| 11511 |
example |
| 11512 |
% |
| 11513 |
\leftedline{|\def\x{98765}\def\y{43210}| |\xintiiAdd {\x}{\x\y}|} |
| 11514 |
% |
| 11515 |
is \emph{not} a legal construct, as the |\y| will remain untouched by |
| 11516 |
expansion and not get converted into the digits which are expected by the |
| 11517 |
sub-routines of |\xintiiAdd|. It is a |\numexpr| which will expand it and an |
| 11518 |
arithmetic overflow will arise as |9876543210| exceeds the \TeX{} bounds. |
| 11519 |
The same would hold for |\xintAdd|. |
| 11520 |
|
| 11521 |
\begingroup\slshape |
| 11522 |
To the contrary \csbxint{theiiexpr} and others have no issues with |
| 11523 |
things such as |\xinttheiiexpr \x+\x\y\relax|.\hfill |
| 11524 |
\endgroup |
| 11525 |
|
| 11526 |
\item\label{fn:expansions} using |\if...\fi| constructs \emph{inside} the |
| 11527 |
package macro arguments requires suitably mastering \TeX niques |
| 11528 |
(|\expandafter|'s and/or swapping techniques) to ensure that the \fexpan sion |
| 11529 |
will indeed absorb the \csa{else} or closing \csa{fi}, else some error will |
| 11530 |
arise in further processing. Therefore it is highly recommended to use the |
| 11531 |
package provided conditionals such as \csbxint{ifEq}, \csbxint{ifGt}, |
| 11532 |
\csbxint{ifSgn},\dots\ or, for \LaTeX{} users and when dealing |
| 11533 |
with short integers the |
| 11534 |
\ctanpackage{etoolbox}% |
| 11535 |
% |
| 11536 |
\footnote{\url{https://ctan.org/pkg/etoolbox}} |
| 11537 |
expandable conditionals (for small integers only) such as \texttt{\char92 |
| 11538 |
ifnumequal}, \texttt{\char92 ifnumgreater}, \dots . Use of |
| 11539 |
\emph{non-expandable} things such as \csa{ifthenelse} is impossible inside the |
| 11540 |
arguments of \xintname macros. |
| 11541 |
|
| 11542 |
\begingroup\slshape |
| 11543 |
One can use naive |\if..\fi| things inside an \csbxint{theexpr}-ession |
| 11544 |
and cousins, as long as the test is |
| 11545 |
expandable, for example\upshape |
| 11546 |
% |
| 11547 |
\leftedline{|\xinttheiexpr\ifnum3>2 143\else 33\fi |
| 11548 |
0^2\relax|$\to$\dtt{\xinttheiexpr \ifnum3>2 143\else 33\fi 0^2\relax |
| 11549 |
=1430\char`\^2}} |
| 11550 |
% |
| 11551 |
\endgroup |
| 11552 |
|
| 11553 |
\item after the definition |\def\x {12}|, one can not use |
| 11554 |
{\color{blue}|-\x|} as input to one of the package macros: the \fexpan sion |
| 11555 |
will act only on the minus sign, hence do nothing. The only way is to use the |
| 11556 |
\csbxint{Opp} macro (or \csbxint{iiOpp} which is integer only) |
| 11557 |
which obtains the opposite of a given number. |
| 11558 |
|
| 11559 |
\begingroup\slshape |
| 11560 |
Again, this is otherwise inside an \csbxint{theexpr}-ession or |
| 11561 |
\csbxint{thefloatexpr}-ession. There, the |
| 11562 |
minus sign may prefix macros which will expand to numbers (or parentheses |
| 11563 |
etc...) |
| 11564 |
\endgroup |
| 11565 |
|
| 11566 |
\def\x {12}% |
| 11567 |
\def\AplusBC #1#2#3{\xintAdd {#1}{\xintMul {#2}{#3}}}% |
| 11568 |
|
| 11569 |
\item \label{item:xpxp} With the definition |
| 11570 |
% |
| 11571 |
\leftedline{|\def\AplusBC #1#2#3{\xintAdd {#1}{\xintMul {#2}{#3}}}|} |
| 11572 |
% |
| 11573 |
one obtains an |
| 11574 |
expandable macro producing the expected result, not in two, but rather in |
| 11575 |
three steps: a first expansion is consumed by the macro expanding to its |
| 11576 |
definition. As the package macros expand their arguments until no more is |
| 11577 |
possible (regarding what comes first), this |\AplusBC| may be used inside |
| 11578 |
them: {|\xintAdd {\AplusBC {1}{2}{3}}{4}|} does work and returns |
| 11579 |
\dtt{\xintAdd {\AplusBC {1}{2}{3}}{4}}. |
| 11580 |
|
| 11581 |
If, for some reason, it is important to create a macro expanding in two steps |
| 11582 |
to its final value, one may either do: |
| 11583 |
% |
| 11584 |
\smallskip |
| 11585 |
% |
| 11586 |
\leftedline {|\def\AplusBC #1#2#3{\romannumeral-`0\xintAdd {#1}{\xintMul |
| 11587 |
{#2}{#3}}}|} |
| 11588 |
% |
| 11589 |
or use the \emph{lowercase} form of \csa{xintAdd}: |
| 11590 |
% |
| 11591 |
\smallskip |
| 11592 |
% |
| 11593 |
\leftedline {|\def\AplusBC #1#2#3{\romannumeral0\xintadd {#1}{\xintMul |
| 11594 |
{#2}{#3}}}|} |
| 11595 |
|
| 11596 |
and then \csa{AplusBC} will share the same properties as do the |
| 11597 |
other \xintname `primitive' macros. |
| 11598 |
|
| 11599 |
\item |
| 11600 |
The |\romannumeral0| and |\romannumeral-`0| things above look like an invitation |
| 11601 |
to hacker's territory; if it is not important that the macro expands in two |
| 11602 |
steps only, there is no reason to follow these guidelines. Just chain |
| 11603 |
arbitrarily the package macros, and the new ones will be completely expandable |
| 11604 |
and usable one within the other. |
| 11605 |
|
| 11606 |
Since release |1.07| the \csbxint{NewExpr} macro automatizes the creation of |
| 11607 |
such expandable macros: |
| 11608 |
% |
| 11609 |
\leftedline{|\xintNewExpr\AplusBC[3]{#1+#2*#3}|} |
| 11610 |
% |
| 11611 |
creates the |\AplusBC| macro doing the above and expanding in two expansion |
| 11612 |
steps. |
| 11613 |
|
| 11614 |
\item In the expression parsers of \xintexprname such as |
| 11615 |
\csbxint{expr}|..\relax|, \csbxint{floatexpr}|..\relax| the contents are |
| 11616 |
expanded completely from left to right until the ending |\relax| is found |
| 11617 |
and swallowed, and spaces and even (to some extent) catcodes do not matter. |
| 11618 |
|
| 11619 |
\item For all variants, prefixing with \csbxint{the} allows to print the |
| 11620 |
result or use it in other contexts. Shortcuts \csbxint{theexpr}, |
| 11621 |
\csbxint{thefloatexpr}, \csbxint{theiiexpr}, \dots\ are available. |
| 11622 |
|
| 11623 |
\end{enumerate} |
| 11624 |
|
| 11625 |
\subsection {Input formats for macros}\label{ssec:inputs} |
| 11626 |
|
| 11627 |
Macros can have different types of arguments (we do not consider here the |
| 11628 |
\csbxint{expr}-parsers but only the macros of |
| 11629 |
\xintcorename/\xintname/\xintfracname). In a macro description, a |
| 11630 |
margin annotation signals what is the argument type. |
| 11631 |
\begin{enumerate} |
| 11632 |
\item \TeX\ integers\ntype{\numx} are handled inside a |\numexpr..\relax| |
| 11633 |
hence may be count registers or variables. Beware that |-(1+1)| is not legal |
| 11634 |
and raises an error, but |0-(1+1)| is. Also |2\cnta| with |\cnta| a |\count| |
| 11635 |
isn't legal. Integers must be kept less than \dtt{\number "7FFFFFFF} in |
| 11636 |
absolute value, although the \emph{scaling} operation |(a*b)/c| computes the |
| 11637 |
intermediate product with twice as many bits. |
| 11638 |
|
| 11639 |
The slash |/| does a \fbox{rounded} division which is a fact of life of |
| 11640 |
|\numexpr| which I have found very annoying in at least nine cases out of |
| 11641 |
ten, not to say ninety-nine cases out of one hundred. Besides, it is at odds |
| 11642 |
with \TeX's |\divide| which does a truncated division (non-expandably). |
| 11643 |
|
| 11644 |
But to follow-suit |/| also does rounded integer division in |
| 11645 |
\csbxint{iiexpr}|..\relax|, and the operator |//| does there the truncated |
| 11646 |
division. |
| 11647 |
|
| 11648 |
\item the strict format\ntype{f} applies to macros handling big integers but |
| 11649 |
only \fexpan ding their arguments. After this \fexpan sion the input should |
| 11650 |
be a string of digits, optionally preceded by a unique minus sign. The first |
| 11651 |
digit can be zero only if it is the only digit. A plus sign is not accepted. |
| 11652 |
|-0| is not legal in the strict format. Macros of \xintname with a double |
| 11653 |
|ii| require this `strict' format for the inputs. |
| 11654 |
|
| 11655 |
\item the extended integer format\ntype{\Numf} applies when the macro parses |
| 11656 |
its arguments via \csbxint{Num}. The input may then have arbitrarily many |
| 11657 |
leading minus and plus signs, followed by leading zeroes, and further |
| 11658 |
digits. With \xintfracname loaded, \csbxint{Num} is extended to |
| 11659 |
accept fractions and its action is to truncate them to integers. |
| 11660 |
|
| 11661 |
\item the fraction input format\ntype{\Ff} applies to the arguments of |
| 11662 |
\xintfracname macros handling genuine fractions. It allows two types |
| 11663 |
of inputs: general and restricted. The restricted type is parsed faster, |
| 11664 |
but...\@{} is restricted. |
| 11665 |
\begin{description} |
| 11666 |
\item[general:] inputs of the shape |A.BeC/D.EeF|. Example: |
| 11667 |
\begin{everbatim*} |
| 11668 |
\noindent\xintRaw{+--0367.8920280e17/-++278.289287e-15}\newline |
| 11669 |
\xintRaw{+--+1253.2782e++--3/---0087.123e---5}\par |
| 11670 |
\end{everbatim*} |
| 11671 |
The input parser does not reduce fractions to smallest terms. |
| 11672 |
Here are the rules of this general fraction format: |
| 11673 |
\begin{itemize} |
| 11674 |
\item everything is optional, absent numbers are treated as zero, here are |
| 11675 |
some extreme cases: |
| 11676 |
\begin{everbatim*} |
| 11677 |
\xintRaw{}, \xintRaw{.}, \xintRaw{./1.e}, \xintRaw{-.e}, \xintRaw{e/-1} |
| 11678 |
\end{everbatim*} |
| 11679 |
\item |AB| and |DE| may start with pluses and minuses, then leading |
| 11680 |
zeroes, then digits. |
| 11681 |
\item |C| and |F| will be given to |\numexpr| and can be anything |
| 11682 |
recognized as such and not provoking arithmetic overflow (the lengths of |
| 11683 |
|B| and |E| will also intervene to build the final exponent naturally |
| 11684 |
which must obey the \TeX{} bound). |
| 11685 |
\item the |/|, |.| (numerator and/or denominator) and |e| |
| 11686 |
(numerator and/or denominator) are all optional components. |
| 11687 |
\item each of |A|, |B|, |C|, |D|, |E| and |F| may arise from \fexpan sion |
| 11688 |
of a macro. |
| 11689 |
\item the whole thing may arise from \fexpan sion, however the |/|, |.|, |
| 11690 |
and |e| should all come from this initial expansion. The |e| of |
| 11691 |
scientific notation is mandatorily lowercased. |
| 11692 |
\end{itemize} |
| 11693 |
\item[restricted:] inputs either of the shape |A[N]| or |A/B[N]|, which |
| 11694 |
represents the fraction |A/B| times |10^N|. The whole thing or |
| 11695 |
each of |A|, |B|, |N| (but then not |/| or |[|) may arise from \fexpan |
| 11696 |
sion, |A| (after expansion) \emph{must} have a unique optional minus sign |
| 11697 |
and no leading zeroes, |B| (after expansion) if present \emph{must} be a |
| 11698 |
positive integer with no signs and no leading zeroes, |[N]| if present |
| 11699 |
will be given to |\numexpr|. Any deviation from the rules above will |
| 11700 |
result in errors. |
| 11701 |
\end{description} |
| 11702 |
Notice that |*|, |+| and |-| contrarily to the |/| (which is treated simply |
| 11703 |
as a kind of delimiter) are not acceptable within arguments of this |
| 11704 |
type\ntype{\Ff} (see \autoref{sec:useofcount} |
| 11705 |
for some exceptions to this.) |
| 11706 |
\end{enumerate} |
| 11707 |
|
| 11708 |
Generally speaking, there should be no spaces among the digits in the inputs |
| 11709 |
(in arguments to the package macros). Although most would be harmless in most |
| 11710 |
macros, there are some cases where spaces could break havoc.% |
| 11711 |
\footnote{The \csbxint{Num} macro does not remove spaces between digits beyond |
| 11712 |
the first non zero ones; however this should not really alter the subsequent |
| 11713 |
functioning of the arithmetic macros, and besides, since \xintcorename 1.2 |
| 11714 |
there is an initial parsing of the entire number, during which spaces will |
| 11715 |
be gobbled. However I have not done a complete review of the legacy code to |
| 11716 |
be certain of all possibilities after |1.2| release. One thing to be aware |
| 11717 |
of is that \csa{numexpr} stops on spaces between digits (although it |
| 11718 |
provokes an expansion to see if an infix operator follows); the exponent for |
| 11719 |
\csbxint{iiPow} or the argument of the factorial \csbxint{iiFac} are only |
| 11720 |
subjected to such a \csa{numexpr} (there are a few other macros with such |
| 11721 |
input types in \xintname). If the input is given as, say |1 2\x| where |
| 11722 |
\csa{x} is a macro, the macro \csa{x} will not be expanded by the |
| 11723 |
\csa{numexpr}, and this will surely cause problems afterwards. Perhaps a |
| 11724 |
later \xintname will force \csa{numexpr} to expand beyond spaces, but I |
| 11725 |
decided that was not really worth the effort. Another immediate cause of |
| 11726 |
problems is an input of the type |\xintiiAdd{<space>\x}{\y}|, because the |
| 11727 |
space will stop the initial expansion; this will most certainly cause an |
| 11728 |
arithmetic overflow later when the \csa{x} will be expanded in a |
| 11729 |
\csa{numexpr}. Thus in conclusion, damages due to spaces are unlikely if |
| 11730 |
only explicit digits are involved in the inputs, or arguments are single |
| 11731 |
macros with no preceding space.} |
| 11732 |
So the best is to avoid them entirely. |
| 11733 |
|
| 11734 |
This is entirely otherwise inside an |\xintexpr|-ession, where spaces are |
| 11735 |
ignored (except when they occur inside arguments to some macros, thus |
| 11736 |
escaping the |\xintexpr| parser). See the \autoref{sec:expr}. |
| 11737 |
|
| 11738 |
There are also some slighly more obscure expansion types: in particular, the |
| 11739 |
\csbxint{ApplyInline} and \csbxint{For*} macros from \xinttoolsname apply a |
| 11740 |
special iterated \fexpan sion, which gobbles spaces, to the non-braced items |
| 11741 |
(braced items are submitted to no expansion because the opening brace stops |
| 11742 |
it) coming from their list argument; this is denoted by a special |
| 11743 |
symbol\ntype{{\lowast f}} in the margin. Some other macros such as |
| 11744 |
\csbxint{Sum} from \xintfracname first do an \fexpan sion, then treat each |
| 11745 |
found (braced or not) item (skipping spaces between such items) via the |
| 11746 |
general fraction input parsing, this is signaled as |
| 11747 |
here\ntype{f{$\to$}{\lowast\Ff}} in the margin where the signification of the |
| 11748 |
\lowast{} is thus a bit different from the previous case. |
| 11749 |
|
| 11750 |
A few macros from \xinttoolsname do not expand, or expand only once their |
| 11751 |
argument\ntype{n{{\color{black}\upshape, resp.}} o}. This is also |
| 11752 |
signaled in the margin with notations \`a la \LaTeX3. |
| 11753 |
|
| 11754 |
|
| 11755 |
\subsection{Output formats of macros} |
| 11756 |
\label{ssec:outputs} |
| 11757 |
|
| 11758 |
We do not consider here the \csbxint{expr}-parsers but only the macros from \xintcorename, \xintname and \xintfracname. Macros of other |
| 11759 |
components of the bundle may have their own output formats, for example for |
| 11760 |
continuous fractions with \xintcfracname. |
| 11761 |
There are mainly three types of outputs:% |
| 11762 |
|
| 11763 |
\begin{itemize}[nosep,listparindent=\leftmarginiii] |
| 11764 |
\item arithmetic macros from \xintcorename/\xintname deliver integers |
| 11765 |
in the strict format as described in the previous section. |
| 11766 |
\item arithmetic macros from \xintfracname produce on output the strict |
| 11767 |
fraction format |A/B[N]|, which stands for |(A/B)|$\times$|10^N|, where |A| |
| 11768 |
and |B| are integers, |B| is positive, and |N| is a ``short'' integer. The |
| 11769 |
output is not reduced to smallest terms. The |A| and |B| may end with zeroes |
| 11770 |
(\emph{i.e}, |N| does not represent all powers of ten). The denominator |B| is |
| 11771 |
always strictly positive. There is no |+| sign. The |-| is always first if |
| 11772 |
present (i.e.\@{} the denominator on output is always positive.) The output will |
| 11773 |
be expressed as such a fraction even if the inputs are both integers and the |
| 11774 |
mathematical result is an integer. The |B=1| is not removed.% |
| 11775 |
% |
| 11776 |
\footnote{refer to the documentation of \csbxint{PRaw} for an alternative.} |
| 11777 |
\item macros from \xintfracname having |Float| in their names deliver a number |
| 11778 |
in the scientific notation as described in the documentation of |
| 11779 |
\csbxint{Float}. |
| 11780 |
|
| 11781 |
The exception is \csbxint{PFloat} which does some customizable pretty |
| 11782 |
printing of the result. |
| 11783 |
\end{itemize} |
| 11784 |
|
| 11785 |
\subsection{Count registers and variables}\label{sec:useofcount} |
| 11786 |
|
| 11787 |
Inside |\xintexpr..\relax| and its variants, a count register or count control |
| 11788 |
sequence is automatically unpacked using |\number|, with tacit multiplication: |
| 11789 |
|1.23\counta| is like |1.23*\number\counta|. There |
| 11790 |
is a subtle difference between count \emph{registers} and count |
| 11791 |
\emph{variables}. In |1.23*\counta| the unpacked |\counta| variable defines a |
| 11792 |
complete operand thus |1.23*\counta 7| is a syntax error. But |1.23*\count0| |
| 11793 |
just replaces |\count0| by |\number\count0| hence |1.23*\count0 7| is like |
| 11794 |
|1.23*57| if |\count0| contains the integer value |5|. |
| 11795 |
|
| 11796 |
Regarding now the package macros, there is first the case of arguments having to |
| 11797 |
be short integers: this means that they are fed to a |\numexpr...\relax|, hence |
| 11798 |
submitted to a \emph{complete expansion} which must deliver an integer, and |
| 11799 |
count registers and even algebraic expressions with them like |
| 11800 |
|\mycountA+\mycountB*17-\mycountC/12+\mycountD| are admissible arguments (the |
| 11801 |
slash stands here for the rounded integer division done by |\numexpr|). This |
| 11802 |
applies in particular to the number of digits to truncate or round with, to the |
| 11803 |
indices of a series partial sum, \dots |
| 11804 |
|
| 11805 |
The macros allowing the extended format for long numbers or dealing with |
| 11806 |
fractions will \emph{to some extent} allow the direct use of count |
| 11807 |
registers and even infix algebra inside their arguments: a count |
| 11808 |
register |\mycountA| or |\count 255| is admissible as numerator or also as |
| 11809 |
denominator, with no need to be prefixed by |\the| or |\number|. It is possible |
| 11810 |
to have as argument an algebraic expression as would be acceptable by a |
| 11811 |
|\numexpr...\relax|, under this condition: \emph{each of the numerator and |
| 11812 |
denominator is expressed with at most \emph{nine} |
| 11813 |
tokens}.% |
| 11814 |
% |
| 11815 |
\footnote{The |1.2k| and earlier versions manual claimed up to 8 |
| 11816 |
tokens, but low-level TeX error arose if the |\numexpr...\relax| occupied |
| 11817 |
exactly 8 tokens \emph{and} evaluated to zero. With |1.2l| and later, up to |
| 11818 |
9 tokens are always safe and one may even drop the ending |\relax|. But |
| 11819 |
well, all these explanations are somewhat silly because prefixing by |\the| |
| 11820 |
or |\number| is always working with arbitrarily many tokens.} |
| 11821 |
% |
| 11822 |
% |
| 11823 |
\footnote{Attention! in the \LaTeX{} context a |
| 11824 |
\csa{value}\texttt{\{countername\}} will behave ok only if it is first in |
| 11825 |
the input, if not it will not get expanded, and braces around the name will |
| 11826 |
be removed and chaos\IMPORTANT{} will ensue inside a \csa{numexpr}. One |
| 11827 |
should enclose the whole input in \csa{the}\csa{numexpr}|...|\csa{relax} in |
| 11828 |
such cases.} |
| 11829 |
% |
| 11830 |
Important: a slash for rounded division in a |\numexpr| should be written with |
| 11831 |
braces |{/}| to not be confused with the \xintfracname delimiter between |
| 11832 |
numerator and denominator (braces will be removed internally and the slash |
| 11833 |
will count for one token). Example: |
| 11834 |
|\mycountA+\mycountB{/}17/1+\mycountA*\mycountB|, or |\count 0+\count |
| 11835 |
2{/}17/1+\count 0*\count 2|. |
| 11836 |
% |
| 11837 |
\leftedline{|\cnta 10 \cntb 35 \xintRaw |
| 11838 |
{\cnta+\cntb{/}17/1+\cnta*\cntb}|\dtt{->\cnta 10 \cntb 35 \xintRaw |
| 11839 |
{\cnta+\cntb{/}17/1+\cnta*\cntb}}} |
| 11840 |
% |
| 11841 |
For longer algebraic expressions using |
| 11842 |
count registers, there are two possibilities: |
| 11843 |
\begin{enumerate}[nosep] |
| 11844 |
\item let the numerator and the denominator be presented as |\the\numexpr...\relax|, |
| 11845 |
\item or as |\numexpr {...}\relax| (the braces are removed during processing; |
| 11846 |
they are not legal for |\numexpr...\relax| syntax.) |
| 11847 |
\end{enumerate} |
| 11848 |
\everb|@ |
| 11849 |
\cnta 100 \cntb 10 \cntc 1 |
| 11850 |
\xintPRaw {\numexpr {\cnta*\cnta+\cntb*\cntb+\cntc*\cntc+ |
| 11851 |
2*\cnta*\cntb+2*\cnta*\cntc+2*\cntb*\cntc}\relax/% |
| 11852 |
\numexpr {\cnta*\cnta+\cntb*\cntb+\cntc*\cntc}\relax } |
| 11853 |
| |
| 11854 |
\cnta 100 \cntb 10 \cntc 1 |
| 11855 |
% |
| 11856 |
\leftedline{\dtt{\xintPRaw {\numexpr |
| 11857 |
{\cnta*\cnta+\cntb*\cntb+\cntc*\cntc+ |
| 11858 |
2*\cnta*\cntb+2*\cnta*\cntc+2*\cntb*\cntc}\relax/% |
| 11859 |
\numexpr {\cnta*\cnta+\cntb*\cntb+\cntc*\cntc}\relax }}} |
| 11860 |
|
| 11861 |
\subsection{Dimension registers and variables} |
| 11862 |
\label{sec:Dimensions} |
| 11863 |
|
| 11864 |
\meta{dimen} variables can be converted into (short) integers suitable for the |
| 11865 |
\xintname macros by prefixing them with |\number|. This transforms a dimension |
| 11866 |
into an explicit short integer which is its value in terms of the |sp| unit |
| 11867 |
($1/65536$\,|pt|). |
| 11868 |
When |\number| is applied to a \meta{glue} variable, the stretch and shrink |
| 11869 |
components are lost. |
| 11870 |
|
| 11871 |
For \LaTeX{} users: a length is a \meta{glue} variable, prefixing a |
| 11872 |
length macro defined by \csa{newlength} with \csa{number} will thus discard |
| 11873 |
the |plus| and |minus| glue components and return the dimension component as |
| 11874 |
described above, and usable in the \xintbundlename macros. |
| 11875 |
|
| 11876 |
This conversion is done automatically inside an |
| 11877 |
|\xintexpr|-essions, with tacit multiplication implied if prefixed by some |
| 11878 |
(integral or decimal) number. |
| 11879 |
|
| 11880 |
One may thus compute areas or volumes with no limitations, in units of |sp^2| |
| 11881 |
respectively |sp^3|, do arithmetic with them, compare them, etc..., and possibly |
| 11882 |
express some final result back in another unit, with the suitable conversion |
| 11883 |
factor and a rounding to a given number of decimal places. |
| 11884 |
|
| 11885 |
A \hyperref[tableofdimensions]{table of dimensions} illustrates that the |
| 11886 |
internal values used by \TeX{} do not correspond always to the closest |
| 11887 |
rounding. For example a millimeter exact value in terms of |sp| units is |
| 11888 |
\dtt{72.27/10/2.54*65536=\xinttheexpr trunc(72.27/10/2.54*65536,3)\relax ...} |
| 11889 |
and \TeX{} uses internally \dtt{\number\dimexpr 1mm\relax}|sp| (\TeX{} |
| 11890 |
truncates to get an integral multiple of the |sp| unit; see at the end of this |
| 11891 |
section the exact rules applied internally by \TeX). |
| 11892 |
|
| 11893 |
\begin{figure*}[ht!] |
| 11894 |
\phantomsection\label{tableofdimensions} |
| 11895 |
\begingroup\let\ignorespaces\empty |
| 11896 |
\let\unskip\empty |
| 11897 |
\def\T{\expandafter\TT\number\dimexpr} |
| 11898 |
\def\TT#1!{\gdef\tempT{#1}} |
| 11899 |
\def\E{\expandafter\expandafter\expandafter |
| 11900 |
\EE\xintexpr reduce(} |
| 11901 |
\def\EE#1!{\gdef\tempE{#1}} |
| 11902 |
\centeredline{\begin{tabular}{% |
| 11903 |
>{\bfseries\strut}c% |
| 11904 |
c% |
| 11905 |
>{\E}c<{)\relax!}@{}% |
| 11906 |
>{\xintthe\tempE}r@{${}={}$}% |
| 11907 |
>{\xinttheexpr trunc(\tempE,3)\relax...}l% |
| 11908 |
>{\T}c<{!}@{}% |
| 11909 |
>{\tempT}r% |
| 11910 |
>{\xinttheexpr round(100*(\tempT-\tempE)/\tempE,4)\relax\%}c} |
| 11911 |
\hline |
| 11912 |
Unit&% |
| 11913 |
definition&% |
| 11914 |
\omit &% |
| 11915 |
\multicolumn{2}{c}{Exact value in \texttt{sp} units\strut}&% |
| 11916 |
\omit &% |
| 11917 |
\omit\parbox{2cm}{\centering\strut\TeX's value in \texttt{sp} units\strut}&% |
| 11918 |
\omit\parbox{2cm}{\centering\strut Relative error\strut}\\\hline |
| 11919 |
cm&0.01 m&72.27/2.54*65536&&&1cm&&\\ |
| 11920 |
mm&0.001 m&72.27/10/2.54*65536&&&1mm&&\\ |
| 11921 |
in&2.54 cm&72.27*65536&&&1in&&\\ |
| 11922 |
pc&12 pt&12*65536&&&1pc&&\\ |
| 11923 |
pt&1/72.27 in&65536&&&1pt&&\\ |
| 11924 |
bp&1/72 in&72.27*65536/72&&&1bp&&\\ |
| 11925 |
\omit\hfil\llap{3}bp\strut\hfil&1/24 in&72.27*65536/24&&&3bp&&\\ |
| 11926 |
\omit\hfil\llap{12}bp\strut\hfil&1/6 in&72.27*65536/6&&&12bp&&\\ |
| 11927 |
\omit\hfil\llap{72}bp\strut\hfil&1 in&72.27*65536&&&72bp&&\\ |
| 11928 |
dd&1238/1157 pt&1238/1157*65536&&&1dd&&\\ |
| 11929 |
\omit\hfil\llap{11}dd\strut\hfil&11*1238/1157 pt&11*1238/1157*65536&&&11dd&&\\ |
| 11930 |
\omit\hfil\llap{12}dd\strut\hfil&12*1238/1157 pt&12*1238/1157*65536&&&12dd&&\\ |
| 11931 |
sp&1/65536 pt&1&&&1sp&&\\\hline |
| 11932 |
\multicolumn{8}{c}{\bfseries\large\TeX{} \strut dimensions}\\\hline |
| 11933 |
\end{tabular}} |
| 11934 |
\endgroup |
| 11935 |
\end{figure*} |
| 11936 |
|
| 11937 |
There is something quite amusing with the Didot point. According to the \TeX |
| 11938 |
Book, $1157$\,|dd|=$1238$\,|pt|. The actual internal value of $1$\,|dd| in \TeX{} is $70124$\,|sp|. We can use \xintcfracname to display the list of |
| 11939 |
centered convergents of the fraction $70124/65536$: |
| 11940 |
% |
| 11941 |
\leftedline{|\xintListWithSep{, }{\xintFtoCCv{70124/65536}}|} |
| 11942 |
% |
| 11943 |
\xintFor* #1 in {\xintFtoCCv{70124/65536}}\do {$\printnumber{#1}$, }% |
| 11944 |
and we don't find |
| 11945 |
$1238/1157$ therein, but another approximant $1452/1357$! |
| 11946 |
|
| 11947 |
And indeed multiplying $70124/65536$ by $1157$, and respectively $1357$, we find |
| 11948 |
the approximations (wait for more, later): |
| 11949 |
% |
| 11950 |
\leftedline{``$1157$\,|dd|''\dtt{=\xinttheexpr trunc(1157\dimexpr |
| 11951 |
1dd\relax/\dimexpr 1pt\relax,12)\relax}\dots|pt|} |
| 11952 |
% |
| 11953 |
\leftedline{``$1357$\,|dd|''\dtt{=\xinttheexpr trunc(1357\dimexpr |
| 11954 |
1dd\relax/\dimexpr 1pt\relax,12)\relax}\dots|pt|} |
| 11955 |
% |
| 11956 |
and we seemingly discover that $1357$\,|dd|=$1452$\,|pt| is \emph{far more |
| 11957 |
accurate} than |
| 11958 |
the \TeX Book formula $1157$\,|dd|=$1238$\,|pt|~! |
| 11959 |
The formula to compute $N$\,|dd| was |
| 11960 |
% |
| 11961 |
\leftedline{|\xinttheexpr trunc(N\dimexpr 1dd\relax/\dimexpr |
| 11962 |
1pt\relax,12)\relax}|} |
| 11963 |
% |
| 11964 |
|
| 11965 |
What's the catch? The catch is that \TeX{} \emph{does not} compute $1157$\,|dd| |
| 11966 |
like we just did:% |
| 11967 |
% |
| 11968 |
\leftedline{$1157$\,|dd|=|\number\dimexpr 1157dd\relax/65536|% |
| 11969 |
\dtt{=\xintTrunc{12}{\number\dimexpr 1157dd\relax/65536}}\dots|pt|} |
| 11970 |
% |
| 11971 |
\leftedline{$1357$\,|dd|=|\number\dimexpr 1357dd\relax/65536|% |
| 11972 |
\dtt{=\xintTrunc{12}{\number\dimexpr 1357dd\relax/65536}}\dots|pt|} |
| 11973 |
% |
| 11974 |
We thus discover that \TeX{} (or rather here, e-\TeX{}, but one can check that |
| 11975 |
this works the same in \TeX82), uses $1238/1157$ as a conversion |
| 11976 |
factor (and necessarily intermediate computations simulate higher precision |
| 11977 |
than a priori available with integers less than $2^{31}$ or rather $2^{30}$ for |
| 11978 |
dimensions). Hence the $1452/1357$ ratio is irrelevant, an artefact |
| 11979 |
of the rounding (or rather, as we see, truncating) for one |dd| to be |
| 11980 |
expressed as an integral number of |sp|'s. |
| 11981 |
|
| 11982 |
Let us now |
| 11983 |
use |\xintexpr| to compute the value of the Didot point in millimeters, if |
| 11984 |
the above rule is exactly verified: |
| 11985 |
% |
| 11986 |
\leftedline{|\xinttheexpr |
| 11987 |
trunc(1238/1157*25.4/72.27,12)\relax|% |
| 11988 |
\dtt{=\xinttheexpr trunc(1238/1157*25.4/72.27,12)\relax}|...mm|} |
| 11989 |
% |
| 11990 |
This fits very well with the possible values of the Didot point as listed in |
| 11991 |
the |
| 11992 |
\href{http://en.wikipedia.org/wiki/Point_%28typography%29#Didot}{Wikipedia Article}. |
| 11993 |
% |
| 11994 |
The value $0.376065$\,|mm| is said to be \emph{the traditional value in |
| 11995 |
European printers' offices}. So the $1157$\,|dd|=$1238$\,|pt| rule refers to |
| 11996 |
this Didot point, or more precisely to the \emph{conversion factor} to be used |
| 11997 |
between this Didot and \TeX{} points. |
| 11998 |
|
| 11999 |
The actual value in millimeters of exactly one Didot point as implemented in |
| 12000 |
\TeX{} is |
| 12001 |
% |
| 12002 |
\leftedline {|\xinttheexpr trunc(\dimexpr |
| 12003 |
1dd\relax/65536/72.27*25.4,12)\relax|} |
| 12004 |
% |
| 12005 |
\leftedline{\dtt{=\xinttheexpr trunc(\dimexpr |
| 12006 |
1dd\relax/65536/72.27*25.4,12)\relax}|...mm|} |
| 12007 |
% |
| 12008 |
The difference of circa $5$\AA\ is arguably tiny! |
| 12009 |
|
| 12010 |
% 543564351/508000000 |
| 12011 |
|
| 12012 |
By the way the \emph{European printers' offices \emph{(dixit Wikipedia)} |
| 12013 |
Didot} is thus exactly |
| 12014 |
% |
| 12015 |
\leftedline{|\xinttheexpr reduce(.376065/(25.4/72.27))\relax|% |
| 12016 |
\dtt{=\xinttheexpr reduce(.376065/(25.4/72.27))\relax}\,|pt|} |
| 12017 |
% |
| 12018 |
and the centered convergents of this fraction are \xintFor* #1 in |
| 12019 |
{\xintFtoCCv{543564351/508000000}}\do {\dtt{\printnumber{#1}}\xintifForLast{.}{, }} We do |
| 12020 |
recover the $1238/1157$ therein! |
| 12021 |
|
| 12022 |
\begin{framed} |
| 12023 |
Here is how \TeX\ converts |abc.xyz...<unit>|. First the decimal is |
| 12024 |
\emph{rounded} to the nearest integral multiple of |1/65536|, say |X/65536|. |
| 12025 |
The |<unit>| is associated to a ratio |N/D|, which represents |<unit>/pt|. |
| 12026 |
For the Didot point the ratio is indeed |1238/1157|. \TeX\ \emph{truncates} |
| 12027 |
the fraction |XN/D| to an integer |M|. The dimension is represented by |M |
| 12028 |
sp|. |
| 12029 |
|
| 12030 |
\end{framed} |
| 12031 |
|
| 12032 |
|
| 12033 |
\subsection{\csh{ifcase}, \csh{ifnum}, \texorpdfstring{...\@}{...} constructs}\label{sec:ifcase} |
| 12034 |
|
| 12035 |
When using things such as |\ifcase \xintSgn{\A}| one has to make sure to leave |
| 12036 |
a space after the closing brace for \TeX{} to |
| 12037 |
stop its scanning for a number: once \TeX{} has finished expanding |
| 12038 |
|\xintSgn{\A}| and has so far obtained either |1|, |0|, or |-1|, a |
| 12039 |
space (or something `unexpandable') must stop it looking for more |
| 12040 |
digits. Using |\ifcase\xintSgn\A| without the braces is very dangerous, |
| 12041 |
because the blanks (including the end of line) following |\A| will be |
| 12042 |
skipped and not serve to stop the number which |\ifcase| is looking for. |
| 12043 |
% |
| 12044 |
\begin{everbatim*} |
| 12045 |
\begin{enumerate}[nosep]\def\A{1} |
| 12046 |
\item \ifcase \xintSgn\A 0\or OK\else ERROR\fi |
| 12047 |
\item \ifcase \xintSgn\A\space 0\or OK\else ERROR\fi |
| 12048 |
\item \ifcase \xintSgn{\A} 0\or OK\else ERROR\fi |
| 12049 |
\end{enumerate} |
| 12050 |
\end{everbatim*} |
| 12051 |
|
| 12052 |
In order to use successfully |\if...\fi| constructions either as arguments to |
| 12053 |
the \xintbundlename expandable macros, or when building up a completely |
| 12054 |
expandable macro of one's own, one needs some \TeX nical expertise (see also |
| 12055 |
\autoref{fn:expansions} on page~\pageref{fn:expansions}). |
| 12056 |
|
| 12057 |
It is thus much to be recommended to use the expandable branching macros, |
| 12058 |
provided by \xintfracname succh as \csbxint{ifSgn}, \csbxint{ifZero}, |
| 12059 |
\csbxint{ifOne}, \csbxint{ifNotZero}, \csbxint{ifTrueAelseB}, \csbxint{ifCmp}, |
| 12060 |
\csbxint{ifGt}, \csbxint{ifLt}, \csbxint{ifEq}, |
| 12061 |
\csbxint{ifInt}... See their respective documentations. All these conditionals |
| 12062 |
always have either two or three branches, and empty brace pairs |{}| for |
| 12063 |
unused branches should not be forgotten. |
| 12064 |
|
| 12065 |
If these tests are to be applied to standard \TeX{} short integers, it is more |
| 12066 |
efficient to use (under \LaTeX{}) the equivalent conditional tests from the |
| 12067 |
\ctanpackage{etoolbox}% |
| 12068 |
% |
| 12069 |
\footnote{\url{https://ctan.org/pkg/etoolbox}} |
| 12070 |
package. |
| 12071 |
|
| 12072 |
\subsection{No variable declarations are needed} |
| 12073 |
|
| 12074 |
There is no notion of a \emph{declaration of a variable}. |
| 12075 |
|
| 12076 |
To do a computation and assign its result to some macro |\z|, the user will employ the |\def|, |\edef|, or |\newcommand| (in \LaTeX) |
| 12077 |
as usual, keeping in mind that two expansion steps are needed, thus |\edef| |
| 12078 |
is initially the main tool: |
| 12079 |
% |
| 12080 |
\begin{everbatim*} |
| 12081 |
\def\x{1729728} \def\y{352827927} \edef\z{\xintiiMul {\x}{\y}} |
| 12082 |
\meaning\z |
| 12083 |
\end{everbatim*} |
| 12084 |
|
| 12085 |
As an alternative to |\edef| the package provides |\oodef| which expands |
| 12086 |
exactly twice the replacement text, and |\fdef| which applies \fexpan sion to |
| 12087 |
the replacement text during the definition. |
| 12088 |
\begin{everbatim*} |
| 12089 |
\def\x{1729728}\def\y{352827927} |
| 12090 |
\oodef\w {\xintiiMul\x\y} \fdef\z{\xintiiMul {\x}{\y}} |
| 12091 |
\meaning\w, \meaning\z |
| 12092 |
\end{everbatim*} |
| 12093 |
|
| 12094 |
In practice |\oodef| is slower than |\edef|, except for computations ending in |
| 12095 |
very big final replacement texts (thousands of digits). On the other hand |
| 12096 |
|\fdef|\IMPORTANT{} appears to be slightly faster than |\edef| already in the |
| 12097 |
case of expansions leading to only a few dozen digits. |
| 12098 |
|
| 12099 |
\xintexprname does provide an interface to declare and assign values to |
| 12100 |
identifiers which can then be used in expressions: \autoref{xintdefvar}. |
| 12101 |
|
| 12102 |
|
| 12103 |
\subsection{Possible syntax errors to avoid} |
| 12104 |
|
| 12105 |
\edef\x{\xintMul {3}{5}/\xintMul{7}{9}} |
| 12106 |
|
| 12107 |
Here is a list of imaginable input errors. Some will cause compilation errors, |
| 12108 |
others are more annoying as they may pass through unsignaled. |
| 12109 |
\begin{itemize} |
| 12110 |
\item using |-| to prefix some macro: |-\xintiiSqr{35}/271|.% |
| 12111 |
% |
| 12112 |
\footnote{to the |
| 12113 |
contrary, this \emph{is} |
| 12114 |
allowed inside an |\xintexpr|-ession.} |
| 12115 |
\item using one pair of braces too many |\xintIrr{{\xintiiPow {3}{13}}/243}| (the |
| 12116 |
computation goes through with no error signaled, but the result is completely |
| 12117 |
wrong). |
| 12118 |
\item things like |\xintiiAdd { \x}{\y}| as the space will cause \csa{x} to be |
| 12119 |
expanded later, most probably within a |\numexpr| thus provoking possibly an |
| 12120 |
arithmetic overflow. |
| 12121 |
\item using |[]| and decimal points at the same time |1.5/3.5[2]|, or with a |
| 12122 |
sign in the denominator |3/-5[7]|. The scientific notation has no such |
| 12123 |
restriction, the two inputs |1.5/-3.5e-2| and |-1.5e2/3.5| are equivalent: |
| 12124 |
|\xintRaw{1.5/-3.5e-2}|\dtt{=\xintRaw{1.5/-3.5e-2}}, |
| 12125 |
|\xintRaw{-1.5e2/3.5}|\dtt{=\xintRaw{-1.5e2/3.5}}. |
| 12126 |
\item generally speaking, using in a context expecting an integer (possibly |
| 12127 |
restricted to the \TeX{} bound) a macro or expression which returns a |
| 12128 |
fraction: |\xinttheexpr 4/2\relax| outputs \dtt{\xinttheexpr 4/2\relax}, |
| 12129 |
not $2$. Use |\xintNum {\xinttheexpr 4/2\relax}| or |\xinttheiexpr 4/2\relax| |
| 12130 |
(which rounds the result to the nearest integer, here, the result is already |
| 12131 |
an integer) or |\xinttheiiexpr 4/2\relax|. Or, divide in your head |4| by |
| 12132 |
|2| and insert the result directly in the \TeX{} source. |
| 12133 |
\end{itemize} |
| 12134 |
|
| 12135 |
\subsection{Error messages} |
| 12136 |
|
| 12137 |
In situations such as division by zero, the \TeX{} run will be interrupted |
| 12138 |
with some error message. It conveys some short information on |
| 12139 |
the cause of the problem,% |
| 12140 |
% |
| 12141 |
\footnote{The wording of these messages has been last modified at |1.4m|.\CHANGED{1.4m}} |
| 12142 |
% |
| 12143 |
then an optimistic statement about a possible |
| 12144 |
recovery if the user (in interactive mode) simply hits the |<return>| key. |
| 12145 |
% |
| 12146 |
In non-interactive (|nonstopmode|) the \TeX{} run goes on uninterrupted and |
| 12147 |
the error data will be found in the compilation log. Often, \xintname will |
| 12148 |
fall-back to using a zero value. This is still an experimental feature.% |
| 12149 |
% |
| 12150 |
\footnote{Customizable handlers, error traps, error flags are implemented |
| 12151 |
in embryonic form but without user interface since |1.2l| release. This is |
| 12152 |
not ready yet.} |
| 12153 |
% |
| 12154 |
\footnote{The |1.4g| new formatting implementation benefited from a May 2021 |
| 12155 |
thread at the \LaTeX3 site where expandable error messages were discussed, |
| 12156 |
with in particular contributions of |@blefloch| and |@Skillmon|.} |
| 12157 |
|
| 12158 |
|
| 12159 |
The encouragements will be slightly better formatted if the run is with |
| 12160 |
\LaTeX\ compared to Plain \eTeX: Plain by default does not set the |
| 12161 |
|\newlinechar| which allows to issue linebreaks in messages at chosen |
| 12162 |
locations. In the examples here, \ctanpackage{xintsession} is used, and it |
| 12163 |
loads \xintname in a way activating the nicer |\newlinechar| formatted |
| 12164 |
messages, even though it runs (a priori, but not necessarily) under Plain |
| 12165 |
\eTeX. |
| 12166 |
\begin{everbatim} |
| 12167 |
>>> 1/0; |
| 12168 |
Runaway argument? |
| 12169 |
! xint error: Division by zero: 1/0. |
| 12170 |
! Paragraph ended before \xint<...> is done, but will resume: |
| 12171 |
hit <return> at the ? prompt to try fixing the error above |
| 12172 |
which has been encountered before expansion was complete. |
| 12173 |
<to be read again> |
| 12174 |
\par |
| 12175 |
... |
| 12176 |
l.602 \xintsession |
| 12177 |
\endinput%^^M |
| 12178 |
? |
| 12179 |
@_1 0 |
| 12180 |
>>> (-1)^3.2; |
| 12181 |
Runaway argument? |
| 12182 |
! xint error: Fractional power 32/1[-1] of negative -1[0]. |
| 12183 |
! Paragraph ended before \xint<...> is done, but will resume: |
| 12184 |
hit <return> at the ? prompt to try fixing the error above |
| 12185 |
which has been encountered before expansion was complete. |
| 12186 |
<to be read again> |
| 12187 |
\par |
| 12188 |
... |
| 12189 |
l.602 \xintsession |
| 12190 |
\endinput%^^M |
| 12191 |
? |
| 12192 |
@_2 0 |
| 12193 |
>>> cos 1); |
| 12194 |
Runaway argument? |
| 12195 |
! xint error: `cos1' unknown, say `Isome_var' or I use 0. |
| 12196 |
! Paragraph ended before \xint<...> is done, but will resume: |
| 12197 |
hit <return> at the ? prompt to try fixing the error above |
| 12198 |
which has been encountered before expansion was complete. |
| 12199 |
<to be read again> |
| 12200 |
\par |
| 12201 |
... |
| 12202 |
l.602 \xintsession |
| 12203 |
\endinput%^^M |
| 12204 |
? |
| 12205 |
Runaway argument? |
| 12206 |
! xint error: Extra ) removed. Hit <return>, fingers crossed. |
| 12207 |
! Paragraph ended before \xint<...> is done, but will resume: |
| 12208 |
hit <return> at the ? prompt to try fixing the error above |
| 12209 |
which has been encountered before expansion was complete. |
| 12210 |
<to be read again> |
| 12211 |
\par |
| 12212 |
... |
| 12213 |
l.602 \xintsession |
| 12214 |
\endinput%^^M |
| 12215 |
? |
| 12216 |
@_3 0 |
| 12217 |
>>> 3=4; |
| 12218 |
Runaway argument? |
| 12219 |
! xint error: Expected an operator but got `='. Ignoring. |
| 12220 |
! Paragraph ended before \xint<...> is done, but will resume: |
| 12221 |
hit <return> at the ? prompt to try fixing the error above |
| 12222 |
which has been encountered before expansion was complete. |
| 12223 |
<to be read again> |
| 12224 |
\par |
| 12225 |
... |
| 12226 |
l.602 \xintsession |
| 12227 |
\endinput%^^M |
| 12228 |
? |
| 12229 |
@_4 12 |
| 12230 |
>>> &bye |
| 12231 |
\end{everbatim} |
| 12232 |
|
| 12233 |
In the last example, tacit multiplication was applied as \xintexprname was |
| 12234 |
looking for an operator, got some invalid input and then a number. |
| 12235 |
|
| 12236 |
Some constructs in \xintexprname-essions use delimited macros and there is |
| 12237 |
thus possibility in case of an ill-formed expression to end up beyond the |
| 12238 |
|\relax| end-marker. Such a situation can also occur from |\relax| being |
| 12239 |
swallowed by a non-terminated |
| 12240 |
|\numexpr|: |
| 12241 |
\begin{everbatim} |
| 12242 |
\xintexpr 3 + \numexpr 5+4\relax followed by some LaTeX code... |
| 12243 |
\end{everbatim} |
| 12244 |
The correct input is |
| 12245 |
\begin{everbatim} |
| 12246 |
\xintexpr 3 + \numexpr 5+4\relax\relax |
| 12247 |
\end{everbatim} |
| 12248 |
But people in their right mind will have done |
| 12249 |
\begin{everbatim} |
| 12250 |
\xintexpr 3 + 5 + 4\relax |
| 12251 |
\end{everbatim} |
| 12252 |
A few will have done the computation in their heads. |
| 12253 |
|
| 12254 |
In such cases low-level errors will arise and may |
| 12255 |
lead to very cryptic messages; but nothing unusual or especially traumatizing |
| 12256 |
for the daring experienced \TeX/\LaTeX\ user, whose has seen zillions of |
| 12257 |
un-helpful error messages already in her daily practice of |
| 12258 |
\TeX/\LaTeX. |
| 12259 |
|
| 12260 |
|
| 12261 |
\subsection{Package namespace, catcodes} |
| 12262 |
|
| 12263 |
|
| 12264 |
This section reviews (probably with some omissions) important |
| 12265 |
miscellany regarding control sequence names and catcode matters and is |
| 12266 |
basically in its entirety a |
| 12267 |
\begin{TeXnote} |
| 12268 |
\begin{itemize} |
| 12269 |
\item The bundle packages |
| 12270 |
force the |\space| and |\empty| |
| 12271 |
control sequences into having their default meanings as in Plain \TeX{} or |
| 12272 |
\LaTeX2e formats. |
| 12273 |
\item Private macros (or internally used |\count| registers, and one private |
| 12274 |
|\toks|) have names starting with |\xint_| or |\XINT_|. Some, for legacy or |
| 12275 |
technical reasons, have |\xint| or |\XINT| prefix with no underscore. |
| 12276 |
\item All public macros have their names starting with |\xint| except for: |
| 12277 |
the \xintkernelname provided \hyperref[odef]{|\odef|}, |
| 12278 |
\hyperref[oodef]{|\oodef|}, \hyperref[fdef]{|\fdef|}. If macros with |
| 12279 |
these names already exist \xinttoolsname will not overwrite them. Their |
| 12280 |
meanings are also available under the names \csbxint{odef}, \csbxint{oodef}, |
| 12281 |
etc... |
| 12282 |
|
| 12283 |
\item For the \xintfracname macros to be able to parse their inputs, standard |
| 12284 |
catcodes in the argument are assumed for the digits (of course), the plus |
| 12285 |
and minus signs, the dot, the letter |e|, the forward slash, the square |
| 12286 |
brackets. Spaces should be avoided although they may go unnoticed |
| 12287 |
sometimes. |
| 12288 |
|
| 12289 |
\item For the \xintexprname expressions there is more leeway: the digit |
| 12290 |
tokens must have their standard catcodes, the letters must have their |
| 12291 |
standard catcodes for variable and function names to be recognized, |
| 12292 |
but other characters may mostly have unusual (but not extreme like |
| 12293 |
catcode zero or one) catcodes. Active characters will be |
| 12294 |
expanded and should usually be prefixed with |\string|. But, |
| 12295 |
if activated via Babel\NewWith{1.4n} this is not needed. |
| 12296 |
|
| 12297 |
A few syntax elements are implemented via delimited macros. So the |
| 12298 |
comma, the equal sign and the closing parenthesis must have their |
| 12299 |
normal catcodes for these syntax elements to work. |\string| won't do. |
| 12300 |
|
| 12301 |
Spaces are gobbled. The |e| of scientific notation may be |E| on |
| 12302 |
input, \xintfracname macros on the other hand will not recognize the |
| 12303 |
|E|. |
| 12304 |
|
| 12305 |
\item |
| 12306 |
\csbxint{defvar} and \csbxint{deffunc} as they use automatically |
| 12307 |
\csbxint{exprSafeCatcodes} and \csbxint{exprRestoreCatcodes} to temporarily |
| 12308 |
set catcodes to safe values. |
| 12309 |
|
| 12310 |
\item \csbxint{exprSafeCatcodes} and \csbxint{exprRestoreCatcodes} can be |
| 12311 |
employed at user level too. |
| 12312 |
|
| 12313 |
\item |
| 12314 |
At loading time the |
| 12315 |
catcode configuration may be arbitrary as long as it satisfies the following |
| 12316 |
requirements: |
| 12317 |
\begin{itemize}[nosep] |
| 12318 |
\item \dtt{\%} has its normal category code, |
| 12319 |
\item \dtt{\char92} has its normal category code, |
| 12320 |
\item Latin letters have their normal category code "letter", |
| 12321 |
\item Digits have their normal category code "other". |
| 12322 |
\end{itemize} |
| 12323 |
Nothing more is assumed, for example |{| and |}| may have unusual catcodes |
| 12324 |
at package loading time. This will be admittedly unusual especially in |
| 12325 |
\LaTeX\ as |\usepackage{xintexpr}| would then have had to be replaced by |
| 12326 |
something such as |\usepackage<xintexpr>|... |
| 12327 |
|
| 12328 |
\item Loading the packages causes no insertion of space tokens. |
| 12329 |
|
| 12330 |
\item The previous two items also apply to usage of \csbxint{reloadxintlog} |
| 12331 |
and of \csbxint{reloadxinttrig}. |
| 12332 |
\end{itemize} |
| 12333 |
\end{TeXnote} |
| 12334 |
|
| 12335 |
\subsection{Origins of the package} |
| 12336 |
\label{ssec:origins} |
| 12337 |
|
| 12338 |
|2013/03/28.| Package |bigintcalc| by \textsc{Heiko Oberdiek} already |
| 12339 |
provides expandable arithmetic operations on \myenquote{big integers}, i.e. integers |
| 12340 |
beyond the \TeX\ bound $2^{31}-1$, so why another% |
| 12341 |
% |
| 12342 |
\footnote{this section was written before the \xintfracname package; the |
| 12343 |
author is not aware of another package allowing expandable |
| 12344 |
computations with arbitrarily big fractions.} |
| 12345 |
% |
| 12346 |
one? |
| 12347 |
|
| 12348 |
I got started on this in early March 2013, via a thread on the |
| 12349 |
|c.t.tex| usenet group, where \textsc{Ulrich D\,i\,e\,z} used the |
| 12350 |
previously cited package together with a macro (|\ReverseOrder|) |
| 12351 |
which I had contributed to another thread.% |
| 12352 |
% |
| 12353 |
\footnote{the \csa{ReverseOrder} could be avoided in that circumstance, |
| 12354 |
but it does play a crucial r\^ole here.} |
| 12355 |
% |
| 12356 |
What I had learned in this |
| 12357 |
other thread thanks to interaction with \textsc{Ulrich D\,i\,e\,z} and |
| 12358 |
\textsc{GL} on expandable manipulations of tokens motivated me to |
| 12359 |
try my hands at addition and multiplication. |
| 12360 |
|
| 12361 |
I wrote macros \csa{bigMul} and \csa{bigAdd} which I posted to the |
| 12362 |
newsgroup; they appeared to work comparatively fast. These first |
| 12363 |
versions did not use the \eTeX{} \csa{numexpr} primitive, they worked |
| 12364 |
one digit at a time, having previously stored carry-arithmetic in |
| 12365 |
1200 macros. |
| 12366 |
|
| 12367 |
I noticed that the |bigintcalc| package used \csa{numexpr} |
| 12368 |
if available, but (as far as I could tell) not |
| 12369 |
to do computations many digits at a time. Using \csa{numexpr} for |
| 12370 |
one digit at a time for \csa{bigAdd} and \csa{bigMul} slowed them |
| 12371 |
a tiny bit but avoided cluttering \TeX{} memory with the 1200 |
| 12372 |
macros storing pre-computed digit arithmetic. I wondered if some speed |
| 12373 |
could be gained by using \csa{numexpr} to do four digits at a time |
| 12374 |
for elementary multiplications (as the maximal admissible number |
| 12375 |
for \csa{numexpr} has ten digits). |
| 12376 |
|
| 12377 |
|2013/04/14|.\@{} This initial \xintname was followed by \xintfracname which |
| 12378 |
handled exactly fractions and decimal numbers. |
| 12379 |
|
| 12380 |
|2013/05/25|.\@{} Later came \xintexprname and at the same time \xintfracname got |
| 12381 |
extended to handle floating point numbers. |
| 12382 |
|
| 12383 |
|2013/11/22|.\@{} Later, \xinttoolsname was detached. |
| 12384 |
|
| 12385 |
|2014/10/28|.\@{} Release |1.1| significantly extended the \xintexprname parsers. |
| 12386 |
|
| 12387 |
|2015/10/10|.\@{} Release |1.2| rewrote the core integer routines which had |
| 12388 |
remained essentially unmodified, apart from a slight improvement of division |
| 12389 |
early 2014. |
| 12390 |
|
| 12391 |
This |1.2| release also got its impulse from a fast |
| 12392 |
``reversing'' macro, which I wrote after my interest got awakened again as a |
| 12393 |
result of correspondence with Bruno \textsc{Le Floch} during September 2015: |
| 12394 |
this new reverse uses a \TeX nique which \emph{requires} the tokens to be |
| 12395 |
digits. I wrote a routine which works (expandably) in quasi-linear time, but a |
| 12396 |
less fancy |O(N^2)| variant which I developed concurrently proved to be faster |
| 12397 |
all the way up to perhaps $7000$ digits, thus I dropped the quasi-linear one. |
| 12398 |
The less fancy variant has the advantage that \xintname can handle numbers |
| 12399 |
with more than $19900$ digits (but not much more than $19950$). This is with |
| 12400 |
the current common values of the input save stack and maximal expansion depth: |
| 12401 |
$5000$ and $10000$ respectively. |
| 12402 |
|
| 12403 |
\clearpage |
| 12404 |
\let\xintbundlenameUp\undefined |
| 12405 |
\csname xintkernelnameUp\endcsname |
| 12406 |
\section{Macros of the \xintkernelname package} |
| 12407 |
\RaisedLabel{sec:kernel} |
| 12408 |
|
| 12409 |
\localtableofcontents |
| 12410 |
|
| 12411 |
The \xintkernelname package contains mainly the common code base for handling |
| 12412 |
the load-order of the bundle packages, the management of catcodes at loading |
| 12413 |
time, definition of common constants and macro utilities which are used |
| 12414 |
throughout the code etc ...\@{} it is automatically loaded by all packages of the |
| 12415 |
bundle. |
| 12416 |
|
| 12417 |
It provides a few macros possibly useful in other contexts. |
| 12418 |
|
| 12419 |
\subsection{\csh{odef}, \csh{oodef}, \csh{fdef}} |
| 12420 |
\label{odef} |
| 12421 |
\label{oodef} |
| 12422 |
\label{fdef} |
| 12423 |
\label{xintodef} |
| 12424 |
\label{xintoodef} |
| 12425 |
\label{xintfdef} |
| 12426 |
|
| 12427 |
\csa{oodef}|\controlsequence {<stuff>}| does |
| 12428 |
\everb|@ |
| 12429 |
\expandafter\expandafter\expandafter\def |
| 12430 |
\expandafter\expandafter\expandafter\controlsequence |
| 12431 |
\expandafter\expandafter\expandafter{<stuff>} |
| 12432 |
| |
| 12433 |
|
| 12434 |
This works only for a single |
| 12435 |
|\controlsequence|, with no parameter text, even without parameters. An |
| 12436 |
alternative would be: |
| 12437 |
\everb|@ |
| 12438 |
\def\oodef #1#{\def\oodefparametertext{#1}% |
| 12439 |
\expandafter\expandafter\expandafter\expandafter |
| 12440 |
\expandafter\expandafter\expandafter\def |
| 12441 |
\expandafter\expandafter\expandafter\oodefparametertext |
| 12442 |
\expandafter\expandafter\expandafter } |
| 12443 |
| |
| 12444 |
|
| 12445 |
\noindent |
| 12446 |
but it does not allow |\global| as prefix, and, besides, would have anyhow its |
| 12447 |
use (almost) limited to parameter texts without macro parameter tokens |
| 12448 |
(except if the expanded thing does not see them, or is designed to deal with |
| 12449 |
them). |
| 12450 |
|
| 12451 |
There is a similar macro |\odef| with only one expansion of the replacement text |
| 12452 |
|<stuff>|, and |\fdef| which expands fully |<stuff>| using |\romannumeral-`0|. |
| 12453 |
|
| 12454 |
They can be prefixed with |\global|. It appears than |\fdef| is generally a bit |
| 12455 |
faster than |\edef| when expanding macros from the \xintbundlename, when the |
| 12456 |
result has a few dozens of digits. |\oodef| needs thousands of digits it seems |
| 12457 |
to become competitive. |
| 12458 |
|
| 12459 |
\xintkernelname will not define these macros if the control sequence names |
| 12460 |
already exist. It provides them always under the names |\xintodef|, |
| 12461 |
|\xintoodef| and |\xintfdef| respectively. |
| 12462 |
|
| 12463 |
\subsection{\csh{xintReverseOrder}}\label{xintReverseOrder} |
| 12464 |
|
| 12465 |
\csa{xintReverseOrder}\marg{list}\etype{n} does not do any expansion of its |
| 12466 |
argument and just reverses the order of the tokens in the \meta{list}. Braces |
| 12467 |
are removed once and the enclosed material, now unbraced, does not get |
| 12468 |
reversed. Unprotected spaces (of any character code) are gobbled. |
| 12469 |
% |
| 12470 |
\leftedline{|\xintReverseOrder{\xintDigitsOf\xintiiPow {2}{100}\to\Stuff}|} |
| 12471 |
% |
| 12472 |
\leftedline{gives: |
| 12473 |
\ttfamily{\string\Stuff\string\to1002\string\xintiiPow\string\xintDigitsOf}} |
| 12474 |
|
| 12475 |
\xinttoolsname provides a variant \csbxint{RevWithBraces} which keeps brace |
| 12476 |
pairs in the output, and \fexpan ds its input first. |
| 12477 |
|
| 12478 |
For inputs consisting only digit tokens, see \csbxint{ReverseDigits} from |
| 12479 |
\xintname. |
| 12480 |
|
| 12481 |
\subsection{\csh{xintLength}} |
| 12482 |
\label{xintLength} |
| 12483 |
|
| 12484 |
\csa{xintLength}\marg{list}\etype{n} counts how many tokens (or braced items) |
| 12485 |
there are (possibly none). It does no expansion of its argument, so to use it |
| 12486 |
to count things in the replacement text of a macro |\x| one should do |
| 12487 |
|\expandafter\xintLength\expandafter{\x}|. Blanks between items are not |
| 12488 |
counted. See also \csbxint{NthElt}|{0}| (from \xinttoolsname) |
| 12489 |
which first \fexpan ds its argument and then applies the same code. |
| 12490 |
% |
| 12491 |
\leftedline{|\xintLength {\xintiiPow {2}{100}}|\dtt{=\xintLength |
| 12492 |
{\xintiiPow{2}{100}}}} |
| 12493 |
% |
| 12494 |
\leftedline{${}\neq{}$|\xintLen {\xintiiPow {2}{100}}|\dtt{=\xintLen |
| 12495 |
{\xintiiPow{2}{100}}}} |
| 12496 |
|
| 12497 |
The maximal input size is limited by \TeX{} main memory (it seems to be |
| 12498 |
about half of the \TeX Live |main_memory| setting from file |texmf.cnf|. |
| 12499 |
Because \TeX{} main memory is also where the used format is stored, as |
| 12500 |
well as all additional defined macros, it will for example be |
| 12501 |
higher if compiling with |etex| (PDF\TeX{} in dvi mode) than with |
| 12502 |
|pdftex|. Testing expansion inside an |\edef| with |etex| the author |
| 12503 |
obtained with \TeX Live 2025 a limit of \dtt{2492667} tokens with |1.4n|. |
| 12504 |
|
| 12505 |
\subsection{\csh{xintFirstItem}} |
| 12506 |
\label{xintFirstItem} |
| 12507 |
|
| 12508 |
\csa{xintFirstItem}\marg{list}\etype{n} returns the first item of its |
| 12509 |
argument, one pair of braces removed. If the list has no items the output is |
| 12510 |
empty. |
| 12511 |
|
| 12512 |
It does no expansion. For this and the next similar ones, see |
| 12513 |
|xintsource.pdf| for comments on limitations. |
| 12514 |
|
| 12515 |
\subsection{\csh{xintLastItem}} |
| 12516 |
\label{xintLastItem} |
| 12517 |
|
| 12518 |
Added at |1.2i|. |
| 12519 |
|
| 12520 |
\csa{xintLastItem}\marg{list}\etype{n} returns the last item |
| 12521 |
of its argument, one pair of braces removed. If the list has no items the |
| 12522 |
output is empty. |
| 12523 |
|
| 12524 |
It does no expansion, which should be obtained via suitable |\expandafter|'s. |
| 12525 |
See also \csbxint{NthElt}|{-1}| from \xinttoolsname which obtains the same |
| 12526 |
result (but with another code) after having however \fexpan ded its |
| 12527 |
argument first. |
| 12528 |
|
| 12529 |
\subsection{\csh{xintFirstOne}} |
| 12530 |
\label{xintFirstOne} |
| 12531 |
|
| 12532 |
\csa{xintFirstOne}\marg{list}\etype{n} returns the first item as a braced |
| 12533 |
item. i.e.\@{} if it was braced the braces are kept, else the braces are added. |
| 12534 |
It looks like using \csbxint{FirstItem} within braces, but the difference is |
| 12535 |
when the input was empty. Then the output is empty. |
| 12536 |
|
| 12537 |
It does no expansion, which should be obtained via suitable |\expandafter|'s. |
| 12538 |
|
| 12539 |
\subsection{\csh{xintLastOne}} |
| 12540 |
\label{xintLastOne} |
| 12541 |
|
| 12542 |
\csa{xintLastOne}\marg{list}\etype{n} returns the last item as a braced |
| 12543 |
item. i.e.\@{} if it was braced the braces are kept, else the braces are added. |
| 12544 |
It looks like using \csbxint{LastItem} within braces, but the |
| 12545 |
difference is when the input was empty. Then the output is empty. |
| 12546 |
|
| 12547 |
It does no expansion, which should be obtained via suitable |\expandafter|'s. |
| 12548 |
|
| 12549 |
\subsection{\csh{xintReplicate}, \csh{xintreplicate}} |
| 12550 |
\label{xintreplicate} |
| 12551 |
\label{xintReplicate} |
| 12552 |
|
| 12553 |
\csa{romannumeral}\csa{xintreplicate}|{x}|\marg{stuff}\etype{\numx n} is simply |
| 12554 |
copied over from \LaTeX3's |\prg_replicate:nn| with some minor changes.% |
| 12555 |
% |
| 12556 |
\footnote{I started with the code from Joseph \textsc{Wright} |
| 12557 |
available on an online site.} |
| 12558 |
|
| 12559 |
And \csa{xintReplicate}|{x}| integrates the |
| 12560 |
\csa{romannumeral} prefix. |
| 12561 |
|
| 12562 |
It |
| 12563 |
does not do any expansion of its second argument but inserts it in the upcoming |
| 12564 |
token stream precisely |x| times. Using it with a negative |x| raises no error |
| 12565 |
and does nothing.% |
| 12566 |
% |
| 12567 |
\footnote{This behaviour may change in future.} |
| 12568 |
|
| 12569 |
|
| 12570 |
|
| 12571 |
\subsection{\csh{xintGobble}, \csh{xintgobble}} |
| 12572 |
\label{xintgobble} |
| 12573 |
\label{xintGobble} |
| 12574 |
|
| 12575 |
\csa{romannumeral}\csa{xintgobble}|{x}|\etype{\numx} is a Gobbling macro |
| 12576 |
written in the spirit of \LaTeX3's |\prg_replicate:nn| (which I cloned as |
| 12577 |
\csbxint{replicate}.) It gobbles |x| tokens upstream, with |x| allowed to be |
| 12578 |
as large as \dtt{531440}. Don't use it with |x<0|. |
| 12579 |
|
| 12580 |
And \csa{xintGobble}|{x}| integrates the \csa{romannumeral}. |
| 12581 |
|
| 12582 |
|
| 12583 |
\csbxint{gobble} looks as if it must be related to \csbxint{Trim} from |
| 12584 |
\xinttoolsname, but the latter uses different code (using directly |
| 12585 |
\csbxint{gobble} is not possible because one must make sure not to gobble more |
| 12586 |
than the number of available items; and counting available items first is an |
| 12587 |
overhead which \csbxint{Trim} avoids.) It is rather\csbxint{Keep} with a |
| 12588 |
negative first argument which hands over to \csbxint{gobble} (because in that |
| 12589 |
case it is needed to count anyhow beforehand the number of items, hence |
| 12590 |
\csbxint{gobble} can then be used safely.) |
| 12591 |
|
| 12592 |
I wrote an \csa{xintcount} in the same spirit as \csa{xintreplicate} and |
| 12593 |
\csa{xintgobble}. But it needs to be counting hundreds of tokens to be worth |
| 12594 |
its salt compared to \csbxint{Length}. |
| 12595 |
|
| 12596 |
\subsection{(WIP) \csh{xintUniformDeviate}} |
| 12597 |
\label{xintUniformDeviate} |
| 12598 |
|
| 12599 |
\csa{xintUniformDeviate}|{x}|\etype{\numx} is based upon the engine |
| 12600 |
|\pdfuniformdeviate| (PDF\TeX) or |\uniformdeviate| (Xe\TeX{}, Lua\TeX{}).% |
| 12601 |
% |
| 12602 |
\footnote{The |\uniformdeviate| primitive was added to Xe\TeX\ |
| 12603 |
for the \TeX Live 2019 release.} |
| 12604 |
|
| 12605 |
The argument is expanded in |\numexpr| and the macro itself needs two |
| 12606 |
expansion steps. It produces like the engine primitive an integer (digit |
| 12607 |
tokens) with minimal value \dtt{0} and maximal one \dtt{x-1} if |x| is |
| 12608 |
positive, or minimal value \dtt{x+1} and maximal value \dtt{0} if |x| is |
| 12609 |
negative. For the discussion next, |x| is supposed positive as this |
| 12610 |
avoids having to insert absolute values in formulas. |
| 12611 |
|
| 12612 |
The underlying engine primitive accesses a random number generator (RNG) |
| 12613 |
originally embedded into MetaPost and described in \emph{The Art of |
| 12614 |
Computer Programming, Vol. 2}. During discussions with Bruno Le Floch |
| 12615 |
in May 2018, when he was adding to \LaTeX3 interface for randomness, the |
| 12616 |
author became aware of some limitations, some of them surprising, in the |
| 12617 |
randomness of the numbers produced by this RNG. For example, the values |
| 12618 |
produced by |\pdfuniformdeviate 201326592| and reduction modulo three |
| 12619 |
are in the proportion |1:1:2|, not |1:1:1|. |
| 12620 |
|
| 12621 |
Let's count how many 0's, 1's, and 2's we get from reducing modulo 3 |
| 12622 |
the output of |\pdfuniformdeviate 201326592|: |
| 12623 |
\begin{everbatim*} |
| 12624 |
\pdfsetrandomseed 87654321 |
| 12625 |
\def\A{0}\def\B{0}\def\C{0} |
| 12626 |
\xintReplicate{504}{\ifcase\xinteval{(\pdfuniformdeviate 201326592)/:3} |
| 12627 |
\edef\A{\the\numexpr\A+1}\or |
| 12628 |
\edef\B{\the\numexpr\B+1}\or |
| 12629 |
\edef\C{\the\numexpr\C+1}\fi |
| 12630 |
} |
| 12631 |
We found \A{} 0's, \B{} 1's and \C{} 2's among 504 trials. |
| 12632 |
\end{everbatim*} |
| 12633 |
|
| 12634 |
In contrast, here is what happens if using \csbxint{UniformDeviate}: |
| 12635 |
\begin{everbatim*} |
| 12636 |
\pdfsetrandomseed 87654321 |
| 12637 |
\def\A{0}\def\B{0}\def\C{0} |
| 12638 |
\xintReplicate{504}{\ifcase\xinteval{\xintUniformDeviate{201326592}/:3} |
| 12639 |
\edef\A{\the\numexpr\A+1}\or |
| 12640 |
\edef\B{\the\numexpr\B+1}\or |
| 12641 |
\edef\C{\the\numexpr\C+1}\fi |
| 12642 |
} |
| 12643 |
We found \A{} 0's, \B{} 1's and \C{} 2's among 504 trials. |
| 12644 |
\end{everbatim*} |
| 12645 |
|
| 12646 |
\begin{TeXnote} |
| 12647 |
The RNG works with 28-bits integers. To output a supposedly uniform |
| 12648 |
random integer in a given range \dtt{0..x-1}, it first produces a |
| 12649 |
supposedly uniform integer in the range \dtt{0..$2^{28}-1$} (where |
| 12650 |
\dtt{$2^{28}=268435456$}) then rescales (with rounding) to the target |
| 12651 |
range. |
| 12652 |
% |
| 12653 |
Note that with \dtt{$x=2^{29}$} this means in particular that all produced |
| 12654 |
``random numbers'' in the \dtt{0..x-1} range will be even... |
| 12655 |
|
| 12656 |
But even with \dtt{$x=2^{28}$} there are some more serious defects of |
| 12657 |
the RNG: two seeds sharing the same low |k| bits generate sequences of |
| 12658 |
28-bits integers which are identical one-to-one modulo |2^k|! In |
| 12659 |
particular after setting the seed, there are only 2 distinct sequences |
| 12660 |
for the parity bits for the integers generated by |\pdfuniformdeviate |
| 12661 |
268435456|. |
| 12662 |
|
| 12663 |
Let's define the non-uniformity of |\pdfuniformdeviate x| to be the |
| 12664 |
maximum, taken over all |y|'s from \dtt{0} to |x-1|, of $\string|x\times |
| 12665 |
\mathrm{Prob}($|\pdfuniformdeviate x|${}=y) - 1\string|$. For a general |
| 12666 |
|x|, the engine primitive guarantees only a \dtt{$x/2^{28}$} relative |
| 12667 |
non-uniformity for the outputs of |\pdfuniformdeviate x|. |
| 12668 |
|
| 12669 |
\csbxint{UniformDeviate} improves this by a factor of |
| 12670 |
\dtt{|2^{28}=|\number"10000000}: \emph{the relative non-uniformity now |
| 12671 |
is guaranteed to be bounded above by \fbox{\dtt{$x/2^{56}$}}}. With |
| 12672 |
such a small non-uniformity, modulo phenomena as mentioned earlier are |
| 12673 |
not observable in reasonable computing time. |
| 12674 |
|
| 12675 |
% |
| 12676 |
% These estimates assume that the engine RNG underlying stream of |
| 12677 |
% 28-bits integers can be considered uniform; it is known that the |
| 12678 |
% parity bits of these 28-bits integers have a period of |55(2^{55}-1)| and |
| 12679 |
% that after that many draws the count of 1s has only an excess of 55 compared |
| 12680 |
% to the count of 0s, so the scale seems to be an intrinsic non-uniformity of |
| 12681 |
% |2^{-55}| but it is not obvious if it applies to much shorter ranges. At any |
| 12682 |
% rate we assumed that the non-uniformity for |x| a power of two less than |
| 12683 |
% |2^{28}| is negligible in comparison to |2^{-28}|. Bigger powers of 2 |
| 12684 |
% produce only even integers because the output is rescaled by |
| 12685 |
% factor |x/2^{28}|! |
| 12686 |
% |
| 12687 |
|
| 12688 |
The implementation of \csbxint{UniformDeviate} consumes exactly 5 |
| 12689 |
calls to the engine primitive at each execution; the improved |x/2^{56}| |
| 12690 |
non-uniformity could be obtained with only 2 calls, but paranoïa about the |
| 12691 |
phenonemon of seeds with common bits has led me to accept the overhead of |
| 12692 |
using the 7 high bits of 4 random 28-bits integers, rather than one single |
| 12693 |
28-bits integer, or two, or three. |
| 12694 |
|
| 12695 |
Timings indicate that one \csbxint{UniformDeviate} has a time cost about 13 |
| 12696 |
times the one for one call to the engine primitive (and not only 5, as the |
| 12697 |
extra arithmetic expressions add overhead which is more costly than the |
| 12698 |
primitive itself). Except if the code using the pseudo-random number is very |
| 12699 |
short, this time penalty will prove in practice much less severe (and this is |
| 12700 |
one important reason why we opted for obtaining 28bits via the 7 high bits of |
| 12701 |
4 successive pseudo random numbers from the engine primitive). |
| 12702 |
|
| 12703 |
For example |
| 12704 |
let's raise 100 times a random integer in the \dtt{0..99999999} range to the tenth power:% |
| 12705 |
% |
| 12706 |
\InputIfFileExists{JFBUORDI}{}{}% |
| 12707 |
\ifdefined\JFBUORDI |
| 12708 |
\footnote{% |
| 12709 |
\if0\xintstrcmp{IMAC}{\JFBUORDI}Timings done during dvi build on a |
| 12710 |
computer with a |2.8GHz| % |
| 12711 |
%quadri-core |
| 12712 |
cpu, old but still kicking, and with a locally compiled |latex| binary.\else |
| 12713 |
\if0\xintstrcmp{MBA}{\JFBUORDI}Timings done during dvi build on a |
| 12714 |
computer with a |2GHz| % |
| 12715 |
%dual-core |
| 12716 |
cpu, old but still kicking, and with a locally compiled |latex| binary.\else |
| 12717 |
\if0\xintstrcmp{MBA-M4}{\JFBUORDI}Timings done during dvi build on an Apple laptop with M4 architecture.\else |
| 12718 |
\if0\xintstrcmp{MINI}{\JFBUORDI}Timings done during dvi build on an Apple desktop with M4 Pro architecture.\else |
| 12719 |
DOCUMENTATION SEEMINGLY BUILT NOT ON AN AUTHOR-OWNED SYSTEM, BUT \string\JFBUORDI\space IS DEFINED, WEIRD!\fi\fi\fi\fi |
| 12720 |
} |
| 12721 |
\else |
| 12722 |
\footnote{These timings are done during a build on a computer not belonging to the author.} |
| 12723 |
\fi |
| 12724 |
% |
| 12725 |
\begin{everbatim*} |
| 12726 |
\pdfsetrandomseed 12345678 |
| 12727 |
\xintresettimer |
| 12728 |
\xintReplicate{100}{\edef\foo{\xintiiPow{\xintUniformDeviate{100000000}}{10}}}% |
| 12729 |
\xinttheseconds s (if using \string\xintUniformDeviate)\newline |
| 12730 |
\pdfsetrandomseed 12345678 |
| 12731 |
\xintresettimer |
| 12732 |
\xintReplicate{100}{\edef\foo{\xintiiPow{\pdfuniformdeviate 100000000}{10}}}% |
| 12733 |
\xinttheseconds s (if using \string\pdfuniformdeviate)\par |
| 12734 |
\end{everbatim*} |
| 12735 |
|
| 12736 |
The macros \csbxint{RandomDigits} or \csbxint{iiRandRange}, and their |
| 12737 |
variants, as well as the supporting macros for \func{random} generate random |
| 12738 |
decimal digits eight by eight as if using |
| 12739 |
\csbxint{UniformDeviate}|{100000000}|, but via a direct optimized call made |
| 12740 |
possibly by the range being a power of 10. |
| 12741 |
\end{TeXnote} |
| 12742 |
|
| 12743 |
\clearpage |
| 12744 |
\let\xintkernelnameUp\undefined |
| 12745 |
\csname xintcorenameUp\endcsname |
| 12746 |
\def\n{|{N}|} |
| 12747 |
\def\m{|{M}|} |
| 12748 |
\def\x{|{x}|} |
| 12749 |
\section{Macros of the \xintcorename package} |
| 12750 |
\RaisedLabel{sec:core} |
| 12751 |
|
| 12752 |
\localtableofcontents |
| 12753 |
|
| 12754 |
Package \xintcorename is automatically loaded by \xintname. |
| 12755 |
|
| 12756 |
\xintcorename provides for big integers the four basic arithmetic operations |
| 12757 |
(addition, subtraction, multiplication, division), as well as powers and |
| 12758 |
factorials. |
| 12759 |
|
| 12760 |
In the descriptions of the macros \texttt{\n} and \texttt{\m} stand |
| 12761 |
for (big) integers or macros \hyperref[ssec:expansions]{\fexpan ding} to |
| 12762 |
such big integers in strict format as described in \autoref{ssec:inputs}. |
| 12763 |
|
| 12764 |
All macros require strict integer format on input and produce |
| 12765 |
strict integer format on output, except:\IMPORTANT |
| 12766 |
\begin{itemize}[nosep] |
| 12767 |
\item \csbxint{iNum} which converts to strict integer format an input in |
| 12768 |
\emph{extended} integer format, i.e.\@{} admitting multiple leading plus or |
| 12769 |
minus signs, then possibly leading zeroes, then digits, |
| 12770 |
\item and \csbxint{Num} which is an alias for the former, which gets redefined by |
| 12771 |
\xintfracname to accept more generally also decimal numbers or fractions as |
| 12772 |
input and which truncates them to integers. |
| 12773 |
\end{itemize} |
| 12774 |
|
| 12775 |
The |ii| in the names of the macros such as \csbxint{iiAdd} serves to stress |
| 12776 |
that they accept only strict integers as input (this is signaled by the margin |
| 12777 |
annotation \textcolor[named]{PineGreen}{\emph{f}}), or macros \fexpan ding to |
| 12778 |
such strict format (big) integers and that they produce strict integers as |
| 12779 |
output. |
| 12780 |
|
| 12781 |
Other macros, such as \csbxint{Double}, lack the |ii|, but this is only a |
| 12782 |
legacy of the history of the package and they have the same requirements for |
| 12783 |
input and format of output as the |ii|-macros. |
| 12784 |
|
| 12785 |
The letter \texttt{x} (with margin annotation |
| 12786 |
\smash{\textcolor[named]{PineGreen}{\numx}}) stands for an argument which will |
| 12787 |
be handled embedded in |\numexpr..\relax|. It will thus be completely expanded |
| 12788 |
and must give an integer obeying the \TeX{} bounds. See also |
| 12789 |
\autoref{sec:useofcount}. This is the case for the argument of \csbxint{iiFac} |
| 12790 |
or the exponent argument of \csbxint{iiPow}. |
| 12791 |
|
| 12792 |
The {\color[named]{PineGreen}$\star$}'s in the margin are there to remind of |
| 12793 |
the complete expandability, even \fexpan dability of the macros, as discussed |
| 12794 |
in \autoref{ssec:expansions}. |
| 12795 |
|
| 12796 |
\autoref{tab:maxsizes} summarizes the maximal allowed sizes for the four |
| 12797 |
operations. The first column is the tested macro (it is expanded in an |
| 12798 |
\csa{edef}; if deeper nested, the maximal admissible input sizes may |
| 12799 |
actually prove lower than stated). The second column gives |
| 12800 |
the maximal |N| such that the macro does not raise an error on both |
| 12801 |
inputs having |N| digits (for division, |
| 12802 |
the used test divisors had |N/4|, |N/2| and |3N/4| digits). |
| 12803 |
|
| 12804 |
These maximal |N|'s depend on the values of \TeX\ parameters such as |
| 12805 |
input stack size and expansion depth. The last column gives the \TeX\ |
| 12806 |
parameter cited in the error message when trying with |N+1| digits. |
| 12807 |
|
| 12808 |
The table was last updated in July 2025, using |1.4m 2022/06/10| and |
| 12809 |
TeXLive 2025 default settings which are: input stack size at |
| 12810 |
\dtt{10000}, expansion depth at \dtt{10000}, parameter stack size at |
| 12811 |
\dtt{20000}. |
| 12812 |
|
| 12813 |
|
| 12814 |
\begin{table}[htbp] |
| 12815 |
\capstart |
| 12816 |
\centering |
| 12817 |
\def\E#1#2!{\edef\F{\the\numexpr(#1-\xintLength{#2})/2}% |
| 12818 |
\relax\romannumeral\xintreplicate{\F}{ }#2% |
| 12819 |
\romannumeral\xintreplicate{#1-\F-\xintLength{#2}}{ }\relax}% |
| 12820 |
% non satisfactory because depends on #1 oddness, but well. Temporary destined |
| 12821 |
% to stay... |
| 12822 |
\begin{tabular}{r>{\E{19}}c<{!}r} |
| 12823 |
\hline |
| 12824 |
&Max\ length\ of\ inputs&Limiting factor\\ |
| 12825 |
\csbxint{iiAdd}&26648&expansion depth=10000\\ |
| 12826 |
\csbxint{iiSub}&26632&expansion depth=10000\\ |
| 12827 |
\csbxint{iiMul}&13320&expansion depth=10000\\ |
| 12828 |
\csbxint{iiDivision}&26609&expansion depth=10000\\ |
| 12829 |
\hline |
| 12830 |
\end{tabular} |
| 12831 |
\caption{Maximal sizes of inputs (using TeXLive 2025) for core arithmetic}\label{tab:maxsizes} |
| 12832 |
\end{table} |
| 12833 |
|
| 12834 |
\subsection{\csh{xintiNum}}\label{xintiNum} |
| 12835 |
|
| 12836 |
|\xintiNum|\n\etype{f} removes chains of plus or minus signs, followed by |
| 12837 |
zeroes. |
| 12838 |
\begin{everbatim*} |
| 12839 |
\xintiNum{+---++----+--000000000367941789479} |
| 12840 |
\end{everbatim*} |
| 12841 |
|
| 12842 |
\subsection{\csh{xintDouble}}\label{xintDouble} |
| 12843 |
|
| 12844 |
|\xintDouble|\n\etype{f} computes |2N|. |
| 12845 |
|
| 12846 |
\subsection{\csh{xintHalf}}\label{xintHalf} |
| 12847 |
|
| 12848 |
|\xintHalf|\n\etype{f} computes |N/2| |
| 12849 |
truncated towards zero. |
| 12850 |
|
| 12851 |
\subsection{\csh{xintInc}}\label{xintInc} |
| 12852 |
|
| 12853 |
|\xintInc|\n\etype{f} evaluates |N+1|. |
| 12854 |
|
| 12855 |
\subsection{\csh{xintDec}}\label{xintDec} |
| 12856 |
|
| 12857 |
|\xintDec|\n\etype{f} evaluates |N-1|. |
| 12858 |
|
| 12859 |
\subsection{\csh{xintDSL}}\label{xintDSL} |
| 12860 |
|
| 12861 |
|\xintDSL|\n\etype{f} is decimal shift left, \emph{i.e.\@} multiplication by |
| 12862 |
ten. |
| 12863 |
|
| 12864 |
\subsection{\csh{xintDSR}}\label{xintDSR} |
| 12865 |
|
| 12866 |
|\xintDSR|\n\etype{f} is truncated decimal shift right, \emph{i.e.\@} it is the |
| 12867 |
truncation of |N/10| towards zero. |
| 12868 |
|
| 12869 |
\subsection{\csh{xintDSRr}}\label{xintDSRr} |
| 12870 |
|
| 12871 |
|\xintDSRr|\n\etype{f} is rounded decimal shift right, \emph{i.e.\@} it is the |
| 12872 |
rounding of |N/10| away from zero. It is needed in \xintcorename for use by |
| 12873 |
\csbxint{iiDivRound}. |
| 12874 |
|
| 12875 |
\subsection{\csh{xintFDg}}\label{xintFDg} |
| 12876 |
|
| 12877 |
|\xintFDg|\n\etype{f} outputs the first digit (most significant) of the |
| 12878 |
number. |
| 12879 |
|
| 12880 |
\subsection{\csh{xintLDg}}\label{xintLDg} |
| 12881 |
|
| 12882 |
|\xintLDg|\n\etype{f} outputs the least significant digit. When the number |
| 12883 |
is positive, this is the same as the remainder in the Euclidean division by |
| 12884 |
ten. |
| 12885 |
|
| 12886 |
\subsection{\csh{xintiiSgn}}\label{xintiiSgn} |
| 12887 |
|
| 12888 |
|\xintiiSgn|\n\etype{f} returns 1 if the number is positive, 0 if it is zero |
| 12889 |
and -1 if it is negative. |
| 12890 |
|
| 12891 |
\subsection{\csh{xintiiOpp}}\label{xintiiOpp} |
| 12892 |
|
| 12893 |
|\xintiiOpp|\n\etype{f} outputs the opposite |-N| of the number |N|. |
| 12894 |
|
| 12895 |
Important note: an input such as |-\foo| is not legal, generally speaking, as |
| 12896 |
argument to the macros of the \xintbundlename (except, naturally in |
| 12897 |
\csbxint{expr}-essions). The reason is that the minus sign stops the \fexpan |
| 12898 |
sion done during parsing of the inputs. One must use the syntax |
| 12899 |
|\xintiiOpp{\foo}| if one wants to pass |-\foo| as |
| 12900 |
argument to other macros. |
| 12901 |
|
| 12902 |
\subsection{\csh{xintiiAbs}}\label{xintiiAbs} |
| 12903 |
|
| 12904 |
|\xintiiAbs|\n\etype{f} outputs the absolute value of the number. |
| 12905 |
|
| 12906 |
\subsection{\csh{xintiiAdd}}\label{xintiiAdd} |
| 12907 |
|
| 12908 |
|\xintiiAdd|\n\m\etype{ff} computes the sum of the two (big) integers. |
| 12909 |
|
| 12910 |
\subsection{\csh{xintiiCmp}}\label{xintiiCmp} |
| 12911 |
|
| 12912 |
|\xintiiCmp|\n\m\etype{ff} produces \dtt{1} if |N>M|, \dtt{0} if |N=M|, |
| 12913 |
and \dtt{-1} if |N<M|. |
| 12914 |
|
| 12915 |
At |1.2l| this macro was moved from package \xintname to \xintcorename. |
| 12916 |
|
| 12917 |
\subsection{\csh{xintiiSub}}\label{xintiiSub} |
| 12918 |
|
| 12919 |
|\xintiiSub|\n\m\etype{ff} computes the difference |N-M|. |
| 12920 |
|
| 12921 |
\subsection{\csh{xintiiMul}}\label{xintiiMul} |
| 12922 |
|
| 12923 |
|\xintiiMul|\n\m\etype{ff} computes the product of two (big) integers. |
| 12924 |
|
| 12925 |
\subsection{\csh{xintiiSqr}}\label{xintiiSqr} |
| 12926 |
|
| 12927 |
|\xintiiSqr|\n\etype{f} produces the square. |
| 12928 |
|
| 12929 |
\subsection{\csh{xintiiPow}}\label{xintiiPow} |
| 12930 |
|
| 12931 |
|\xintiiPow|\n\x\etype{f\numx} computes |N^x|. For |x=0|, this is 1. For |N=0| |
| 12932 |
and |x<0|, or if \verb+|N|>1+ and |x<0|, an error is raised. There will also |
| 12933 |
be an error if |x| exceeds the maximal \eTeX{} number \dtt{\number"7FFFFFFF}, |
| 12934 |
but the real limit for exponents comes from either the computation time or the |
| 12935 |
settings of some \TeX\ memory parameters. |
| 12936 |
|
| 12937 |
Generally speaking the computation will end in an error if the output goes |
| 12938 |
beyond what addition could accept on input, i.e.\@ (with \TeX Live 2025 default |
| 12939 |
settings) has more than about \dtt{26600} digits. |
| 12940 |
|
| 12941 |
For example the maximal power of $2$ which \csbxint{iiPow} is able to compute |
| 12942 |
(with \TeX Live 2025 default memory parameters) is $2^{88470}$ which has |
| 12943 |
\dtt{26633} digits. I.e.\@ |\edef\z{\xintiiPow{2}{88470}}| succeeds (if you |
| 12944 |
are patient enough to wait) but |\edef\z{\xintiiPow{2}{88471}}| fails. |
| 12945 |
|
| 12946 |
\subsection{\csh{xintiiFac}}\label{xintiiFac} |
| 12947 |
|
| 12948 |
|\xintiiFac|\x\etype{\numx} computes the factorial. |
| 12949 |
|
| 12950 |
The (theoretically) allowable range is $0\leqslant x\leqslant10000$. |
| 12951 |
|
| 12952 |
However the maximal possible computation depends on the values of some memory |
| 12953 |
parameters of the \eTeX{} executable: |
| 12954 |
with \xintcorename at |1.4m| and using \TeX Live 2025, the maximal |
| 12955 |
(within an |\edef|) computable one is \dtt{7712!}\@ which has |
| 12956 |
\dtt{26631} decimal digits. |
| 12957 |
With the input stack size set at 10000, the limiting factor here is the |
| 12958 |
expansion depth at 10000. |
| 12959 |
|
| 12960 |
|
| 12961 |
|
| 12962 |
|
| 12963 |
The \func{factorial} function, or equivalently \func{!} as post-fix operator is |
| 12964 |
available in the three parsers: |
| 12965 |
\begin{everbatim*} |
| 12966 |
\xinttheiiexpr factorial(30)\relax\par |
| 12967 |
\printnumber{\xinteval{200!}}\par |
| 12968 |
\end{everbatim*} |
| 12969 |
Within \csbxint{floateval}, the macro \csbxint{FloatFac} from package \xintfracname is used. |
| 12970 |
\begin{everbatim*} |
| 12971 |
\xintfloateval{200!}\par |
| 12972 |
\end{everbatim*} |
| 12973 |
\begin{everbatim*} |
| 12974 |
\xintfloateval{2000!}\par |
| 12975 |
\end{everbatim*} |
| 12976 |
See its documentation for more. |
| 12977 |
|
| 12978 |
|
| 12979 |
|
| 12980 |
\subsection{\csh{xintiiDivision}}\label{xintiiDivision} |
| 12981 |
|
| 12982 |
|
| 12983 |
|\xintiiDivision|\m\n\etype{ff} produces |{quotient}{remainder}|, in the sense |
| 12984 |
of (mathematical) Euclidean division: |M = QN + R|, |
| 12985 |
|0|${}\leq{}$\verb+R < |N|+. So the remainder is always non-negative and the |
| 12986 |
formula |M = QN + R| always holds independently of the signs of |N| or |M|. |
| 12987 |
Division by zero is an error (even if |M| vanishes) and returns |{0}{0}|. |
| 12988 |
|
| 12989 |
\subsection{\csh{xintiiQuo}}\label{xintiiQuo} |
| 12990 |
|
| 12991 |
|\xintiiQuo|\m\n\etype{ff} computes the quotient from the Euclidean division. |
| 12992 |
|
| 12993 |
\subsection{\csh{xintiiRem}}\label{xintiiRem} |
| 12994 |
|
| 12995 |
|\xintiiRem|\m\n\etype{ff} computes the remainder from the Euclidean |
| 12996 |
division. |
| 12997 |
|
| 12998 |
\subsection{\csh{xintiiDivRound}}\label{xintiiDivRound} |
| 12999 |
|
| 13000 |
|\xintiiDivRound|\m\n\etype{ff} returns the rounded value of the algebraic |
| 13001 |
quotient $M/N$ of two big integers. The rounding is ``away from zero.'' |
| 13002 |
\begin{everbatim*} |
| 13003 |
\xintiiDivRound {100}{3}, \xintiiDivRound {101}{3} |
| 13004 |
\end{everbatim*} |
| 13005 |
|
| 13006 |
\subsection{\csh{xintiiDivTrunc}}\label{xintiiDivTrunc} |
| 13007 |
|
| 13008 |
|\xintiiDivTrunc|\m\n\etype{ff} computes $trunc(M/N)$. For positive arguments |
| 13009 |
$M,N>0$ it is the same as the Euclidean quotient \csbxint{iiQuo}. |
| 13010 |
\begin{everbatim*} |
| 13011 |
\xintiiQuo{1000}{57} (Euclidean), \xintiiDivTrunc{1000}{57} (truncated), |
| 13012 |
\xintiiDivRound{1000}{57} (rounded)\newline |
| 13013 |
\xintiiQuo{-1000}{57}, \xintiiDivTrunc{-1000}{57} (t), \xintiiDivRound{-1000}{57} (r) |
| 13014 |
\newline |
| 13015 |
\xintiiQuo{1000}{-57}, \xintiiDivTrunc{1000}{-57} (t), \xintiiDivRound{1000}{-57} (r) |
| 13016 |
\newline |
| 13017 |
\xintiiQuo{-1000}{-57}, \xintiiDivTrunc{-1000}{-57} (t), \xintiiDivRound{-1000}{-57} (r) |
| 13018 |
\par |
| 13019 |
\end{everbatim*} |
| 13020 |
|
| 13021 |
\subsection{\csh{xintiiDivFloor}}\label{xintiiDivFloor} |
| 13022 |
|
| 13023 |
|\xintiiDivFloor|\m\n\etype{ff} computes $floor(M/N)$. For positive divisor |
| 13024 |
$N>0$ and arbitrary dividend $M$ it is the same as the Euclidean quotient |
| 13025 |
\csbxint{iiQuo}. |
| 13026 |
\begin{everbatim*} |
| 13027 |
\xintiiQuo{1000}{57} (Euclidean), \xintiiDivFloor{1000}{57} (floored)\newline |
| 13028 |
\xintiiQuo{-1000}{57}, \xintiiDivFloor{-1000}{57}\newline |
| 13029 |
\xintiiQuo{1000}{-57}, \xintiiDivFloor{1000}{-57}\newline |
| 13030 |
\xintiiQuo{-1000}{-57}, \xintiiDivFloor{-1000}{-57}\par |
| 13031 |
\end{everbatim*} |
| 13032 |
|
| 13033 |
\subsection{\csh{xintiiMod}}\label{xintiiMod} |
| 13034 |
|
| 13035 |
|\xintiiMod|\m\n\etype{ff} computes $M - N*floor(M/N)$. For positive divisor |
| 13036 |
$N>0$ and arbitrary dividend $M$ it is the same as the Euclidean remainder |
| 13037 |
\csbxint{iiRem}. |
| 13038 |
|
| 13039 |
Formerly, this macro computed $M - N*trunc(M/N)$. The former meaning is |
| 13040 |
retained as \csa{xintiiModTrunc}. |
| 13041 |
\begin{everbatim*} |
| 13042 |
\xintiiRem {1000}{57} (Euclidean), \xintiiMod {1000}{57} (floored), |
| 13043 |
\xintiiModTrunc {1000}{57} (truncated)\newline |
| 13044 |
\xintiiRem {-1000}{57}, \xintiiMod {-1000}{57}, \xintiiModTrunc {-1000}{57}\newline |
| 13045 |
\xintiiRem {1000}{-57}, \xintiiMod {1000}{-57}, \xintiiModTrunc {1000}{-57}\newline |
| 13046 |
\xintiiRem {-1000}{-57}, \xintiiMod {-1000}{-57}, \xintiiModTrunc {-1000}{-57}\par |
| 13047 |
\end{everbatim*} |
| 13048 |
|
| 13049 |
\subsection{\csh{xintNum}}\label{xintNum} |
| 13050 |
|
| 13051 |
|\xintNum|\etype{f} is originally an alias for \csbxint{iNum}. But with |
| 13052 |
\xintfracname loaded its meaning is \hyperref[xintNumFrac]{modified} to accept |
| 13053 |
more general inputs. It then becomes an alias to \csbxint{TTrunc} which |
| 13054 |
truncates the general input to an integer in strict format. |
| 13055 |
|
| 13056 |
\clearpage |
| 13057 |
\let\xintcorenameUp\undefined |
| 13058 |
\csname xintnameUp\endcsname |
| 13059 |
\def\n{|{N}|} |
| 13060 |
\def\m{|{M}|} |
| 13061 |
\def\x{|{x}|} |
| 13062 |
\section{Macros of the \xintname package} |
| 13063 |
\RaisedLabel{sec:xint} |
| 13064 |
|
| 13065 |
\etocsetnexttocdepth{subsubsection} |
| 13066 |
\localtableofcontents |
| 13067 |
|
| 13068 |
This package loads automatically \xintcorename (and \xintkernelname) hence |
| 13069 |
all macros described in \autoref{sec:core} are still available. |
| 13070 |
|
| 13071 |
This is \texttt{\xintbndlversion} of |
| 13072 |
\texttt{\xintbndldate}. |
| 13073 |
|
| 13074 |
Version |1.0| was released |2013/03/28|. |
| 13075 |
Since |1.1 2014/10/28| the core arithmetic macros have been moved to a separate |
| 13076 |
package \xintcorename, which is automatically loaded by \xintname. |
| 13077 |
Only the \csbxint{iiSum}, \csbxint{iiPrd}, \csbxint{iiSquareRoot}, |
| 13078 |
\csbxint{iiSqrt}, \csbxint{iiSqrtR}, |
| 13079 |
\csbxint{iiPFactorial}, \csbxint{iiBinomial} genuinely add to the arithmetic |
| 13080 |
macros from \xintcorename. (\csbxint{iiFac} which computes factorials is |
| 13081 |
already in \xintcorename.) |
| 13082 |
|
| 13083 |
With the exception of \csbxint{Len}, of the \myenquote{Boolean logic macros} (see |
| 13084 |
next paragraphs) all macros require inputs being integers in strict format, see \autoref{ssec:inputs}.% |
| 13085 |
% |
| 13086 |
\footnote{of |
| 13087 |
course for conditionals such as \csbxint{iiifCmp} this constraint applies only |
| 13088 |
to the first two arguments.} |
| 13089 |
% |
| 13090 |
The |ii| in the macro names is here as a reminder of that fact. The output is |
| 13091 |
an integer in strict format, or a pair of two braced such integers for |
| 13092 |
\csbxint{iiSquareRoot}, with the exception of \csbxint{iiE} which may produce |
| 13093 |
strings of zero's if its first argument is zero. |
| 13094 |
|
| 13095 |
Macros \csbxint{DecSplit} and \csbxint{ReverseDigits} are non-arithmetic and |
| 13096 |
have their own specific rules. |
| 13097 |
|
| 13098 |
For all macros described here for which it makes sense, package \xintfracname |
| 13099 |
defines a similar one without |ii| in its name. This will handle more general |
| 13100 |
inputs: decimal, scientific numbers, fractions. The |ii| macros provided here |
| 13101 |
by \xintname can be nested inside macros of \xintfracname but the opposite |
| 13102 |
does not apply, because the output format of the \xintfracname macros, even |
| 13103 |
for representing integers, is not understood by the |ii| macros. The \myenquote{Boolean |
| 13104 |
macros} \csbxint{AND} etc...\@{} are exceptions though, they work fine if served |
| 13105 |
as inputs some \xintfracname output, despite doing only \fexpan |
| 13106 |
sion. Prior to |1.2o|, these macros did apply the \csbxint{Num} |
| 13107 |
or the more general \xintfracname general parsing, but this overhead was |
| 13108 |
deemed superfluous as it serves only to handle hand-written input and is not |
| 13109 |
needed if the input is obtained as a nested chain of \xintfracname macros for |
| 13110 |
example. |
| 13111 |
|
| 13112 |
Prior to release |1.2o|, \xintname defined additional macros which applied |
| 13113 |
\csbxint{Num} to their input arguments. All these macros were deprecated at |
| 13114 |
|1.2o| and have been removed at |1.3|. |
| 13115 |
|
| 13116 |
At |1.3d| macros \csbxint{iiGCD} and \csbxint{iiLCM} from package \xintgcdname |
| 13117 |
are also available from loading \xintname only. They are support macros for |
| 13118 |
the (multi-arguments) functions \func{gcd} and \func{lcm} in \csbxint{iiexpr}. |
| 13119 |
|
| 13120 |
See \autoref{ssec:expansions} for the significance of the |
| 13121 |
\textcolor[named]{PineGreen}{\Numf}, \textcolor[named]{PineGreen}{\emph{f}}, |
| 13122 |
\textcolor[named]{PineGreen}{\numx} and \textcolor[named]{PineGreen}{$\star$} |
| 13123 |
margin annotations. |
| 13124 |
|
| 13125 |
|
| 13126 |
|
| 13127 |
|
| 13128 |
|
| 13129 |
\subsection{\csh{xintiLen}}\label{xintiLen} |
| 13130 |
|
| 13131 |
|\xintiLen|\n\etype{\Numf} returns the length of the number, after its parsing |
| 13132 |
via \csbxint{iNum}. The count does not include the sign. |
| 13133 |
\begin{everbatim*} |
| 13134 |
\xintiLen{-12345678901234567890123456789} |
| 13135 |
\end{everbatim*} |
| 13136 |
|
| 13137 |
Prior to |1.2o|, the package defined only \csbxint{Len}, which is extended by |
| 13138 |
\xintfracname to fractions or decimal numbers, hence acquires a bit more |
| 13139 |
overhead then. |
| 13140 |
|
| 13141 |
\subsection{\csh{xintReverseDigits}} \label{xintReverseDigits} |
| 13142 |
|
| 13143 |
\the\dp\strutbox, \the\ht\strutbox, \the\baselineskip |
| 13144 |
|
| 13145 |
|\xintReverseDigits|\n\etype{f} will reverse the order of the digits of the |
| 13146 |
number. \csa{xintRev} is the former denomination and is kept as an alias. |
| 13147 |
Leading zeroes resulting from the operation are not removed. Contrarily to |
| 13148 |
\csbxint{ReverseOrder} this macro \fexpan ds its argument; it is only usable |
| 13149 |
with digit tokens. It does \emph{not} apply \csbxint{Num} to its argument (so |
| 13150 |
this must be done explicitely if the argument is an integer produced from some |
| 13151 |
\xintfracname macros). It does accept a leading minus sign which will be left |
| 13152 |
upfront in the output. |
| 13153 |
|
| 13154 |
\begingroup |
| 13155 |
\begin{everbatim*} |
| 13156 |
\oodef\x{\xintReverseDigits |
| 13157 |
{98765432109876543210987654321098765432109876543210}}\meaning\x\par |
| 13158 |
\noindent\oodef\x{\xintReverseDigits {\xintReverseDigits |
| 13159 |
{98765432109876543210987654321098765432109876543210}}}\meaning\x\par |
| 13160 |
\end{everbatim*} |
| 13161 |
\endgroup |
| 13162 |
|
| 13163 |
\subsection{\csh{xintDecSplit}} |
| 13164 |
\label{xintDecSplit} |
| 13165 |
|
| 13166 |
|\xintDecSplit|\x\n\etype{\numx f} cuts the |N| (a list of digits) into two |
| 13167 |
pieces |L| and |R|: it outputs |{L}{R}| where the original |N| |
| 13168 |
is the concatenation |LR|. These two pieces are decided according to |x|: |
| 13169 |
\begin{itemize}[nosep] |
| 13170 |
\item for |x>0|, |R| coincides with the |x| least significant digits. If |x| |
| 13171 |
equals or exceeds the length of |N| the first piece |L| will thus be |
| 13172 |
\emph{empty}, |
| 13173 |
\item for |x=0|, |R| is empty, and |L| is all of |N|, |
| 13174 |
\item for |x<0|, the first piece |L| consists of the \verb+|x|+ most |
| 13175 |
significant digits and the second piece |R| gets the remaining ones. If |x| |
| 13176 |
equals or exceeds the length of |N| the second piece |R| will thus be |
| 13177 |
\emph{empty}. |
| 13178 |
\end{itemize} |
| 13179 |
|
| 13180 |
This macro provides public interface to some functionality which is primarily |
| 13181 |
of internal interest. It operates only (after \fexpan sion) on ``strings'' of |
| 13182 |
digits tokens: leading zeroes are allowed but a leading sign (even a minus |
| 13183 |
sign) will provoke an error. |
| 13184 |
|
| 13185 |
Breaking change with |1.2i|: formerly |N<0| was replaced by its |
| 13186 |
absolute value. Now, a sign (positive or negative) will create an error. |
| 13187 |
|
| 13188 |
|
| 13189 |
\subsection{\csh{xintDecSplitL}, \csh{xintDecSplitR}} |
| 13190 |
\label{xintDecSplitL} |
| 13191 |
\label{xintDecSplitR} |
| 13192 |
|
| 13193 |
|\xintDecSplitL|\x\n\etype{\numx f} returns the first piece (unbraced) from |
| 13194 |
the \csa{xintDecSplit} output. |
| 13195 |
|
| 13196 |
\noindent|\xintDecSplitR|\x\n\etype{\numx f} returns the second piece |
| 13197 |
(unbraced) from the \csa{xintDecSplit} output. |
| 13198 |
|
| 13199 |
\subsection{\csh{xintiiE}}\label{xintiiE} |
| 13200 |
|
| 13201 |
|\xintiiE|\n\x\etype{f\numx } serves to extend |N| with |x| zeroes. The |
| 13202 |
parameter |x| must be non-negative. The same output would be obtained via |
| 13203 |
\csbxint{DSH}|{-x}{N}|, except for |N=0|, as |\xintDSH{-x}{N}| multiplies |N| |
| 13204 |
by |10^x| hence produces |0| if |N=0| whereas |
| 13205 |
|\xintiiE{0}{x}| produces |x+1| zeros. |
| 13206 |
\begin{everbatim*} |
| 13207 |
\xintiiE {0}{91}\par |
| 13208 |
\end{everbatim*} |
| 13209 |
|
| 13210 |
\subsection{\csh{xintDSH}}\label{xintDSH} |
| 13211 |
|
| 13212 |
|\xintDSH|\x\n\etype{\numx f} is parametrized decimal shift. When |x| is |
| 13213 |
negative, it is like iterating \csbxint{DSL} \verb+|x|+ times (\emph{i.e.\@} |
| 13214 |
multiplication by $10^{-x}$). When |x| positive, it is like iterating |
| 13215 |
\csbxint{DSR} |x| times (and is more efficient), and for a non-negative |N| |
| 13216 |
this is thus the same as the quotient from the Euclidean division by |10^x|. |
| 13217 |
|
| 13218 |
\subsection{\csh{xintDSHr}, \csh{xintDSx}}\label{xintDSHr}\label{xintDSx} |
| 13219 |
|
| 13220 |
|\xintDSHr|\x\n\etype{\numx f} expects |x| to be zero or positive and it |
| 13221 |
returns then a value |R| which is correlated to the value |Q| returned by |
| 13222 |
\csbxint{DSH}\x\n{} in the following manner: |
| 13223 |
\begin{itemize} |
| 13224 |
\item if |N| is |
| 13225 |
positive or zero, |Q| and |R| are the quotient and remainder in |
| 13226 |
the Euclidean division by |10^x| (obtained in a more efficient |
| 13227 |
manner than using \csa{xintiiDivision}), |
| 13228 |
\item if |N| is negative let |
| 13229 |
|Q1| and |R1| be the quotient and remainder in the Euclidean |
| 13230 |
division by |10^x| of the absolute value of |N|. If |Q1| |
| 13231 |
does not vanish, then |Q=-Q1| and |R=R1|. If |Q1| vanishes, then |
| 13232 |
|Q=0| and |R=-R1|. |
| 13233 |
\item for |x=0|, |Q=N| and |R=0|. |
| 13234 |
\end{itemize} |
| 13235 |
So one has |N = 10^x Q + R| if |Q| turns out to be zero or |
| 13236 |
positive, and |N = 10^x Q - R| if |Q| turns out to be negative, |
| 13237 |
which is exactly the case when |N| is at most |-10^x|. |
| 13238 |
|
| 13239 |
|\xintDSx|\x\n\etype{\numx f} for |x| negative is exactly as |
| 13240 |
|\xintDSH|\x\n, \emph{i.e.\@} multiplication by $10^{-\text{|x|}}$. For |x| zero or |
| 13241 |
positive it returns the two numbers |{Q}{R}| described above, each one within |
| 13242 |
braces. So |Q| is |\xintDSH|\x\n, and |R| is |\xintDSHr|\x\n, but computed |
| 13243 |
simultaneously. |
| 13244 |
|
| 13245 |
\subsection{\csh{xintiiEq}}\label{xintiiEq} |
| 13246 |
|
| 13247 |
|\xintiiEq|\n\m\etype{ff} returns 1 if |N=M|, 0 otherwise. |
| 13248 |
|
| 13249 |
\subsection{\csh{xintiiNotEq}}\label{xintiiNotEq} |
| 13250 |
|
| 13251 |
|\xintiiNotEq|\n\m\etype{ff} returns 0 if |N=M|, 1 otherwise. |
| 13252 |
|
| 13253 |
\subsection{\csh{xintiiGeq}}\label{xintiiGeq} |
| 13254 |
|
| 13255 |
|\xintiiGeq|\n\m\etype{ff} returns 1 if the \emph{absolute value} |
| 13256 |
of the first number is at least equal to the absolute value of the second |
| 13257 |
number. If \verb+|N|<|M|+ it returns 0. |
| 13258 |
|
| 13259 |
Important: the macro compares \emph{absolute values}. |
| 13260 |
|
| 13261 |
\subsection{\csh{xintiiGt}}\label{xintiiGt} |
| 13262 |
|
| 13263 |
|\xintiiGt|\n\m\etype{ff} returns 1 if |N|$>$|M|, 0 otherwise. |
| 13264 |
|
| 13265 |
\subsection{\csh{xintiiLt}}\label{xintiiLt} |
| 13266 |
|
| 13267 |
|\xintiiLt|\n\m\etype{ff} returns 1 if |N|$<$|M|, 0 otherwise. |
| 13268 |
|
| 13269 |
\subsection{\csh{xintiiGtorEq}}\label{xintiiGxstorEq} |
| 13270 |
|
| 13271 |
|\xintiiGtorEq|\n\m\etype{ff} returns 1 if |N|$\geqslant$|M|, 0 otherwise. |
| 13272 |
Extended by \xintfracname to fractions. |
| 13273 |
|
| 13274 |
\subsection{\csh{xintiiLtorEq}}\label{xintiiLtorEq} |
| 13275 |
|
| 13276 |
|\xintiiLtorEq|\n\m\etype{ff} returns 1 if |N|$\leqslant$|M|, 0 otherwise. |
| 13277 |
|
| 13278 |
\subsection{\csh{xintiiIsZero}}\label{xintiiIsZero} |
| 13279 |
|
| 13280 |
|\xintiiIsZero|\n\etype{f} returns 1 if |N=0|, 0 otherwise. |
| 13281 |
|
| 13282 |
\subsection{\csh{xintiiIsNotZero}}\label{xintiiIsNotZero} |
| 13283 |
|
| 13284 |
|\xintiiIsNotZero|\n\etype{f} returns 1 if |N!=0|, 0 otherwise. |
| 13285 |
|
| 13286 |
\subsection{\csh{xintiiIsOne}}\label{xintiiIsOne} |
| 13287 |
|
| 13288 |
|\xintiiIsOne|\n\etype{f} returns 1 if |N=1|, 0 otherwise. |
| 13289 |
|
| 13290 |
\subsection{\csh{xintiiOdd}}\label{xintiiOdd} |
| 13291 |
|
| 13292 |
|\xintiiOdd|\n\etype{f} is 1 if the number is odd and 0 otherwise. |
| 13293 |
|
| 13294 |
\subsection{\csh{xintiiEven}}\label{xintiiEven} |
| 13295 |
|
| 13296 |
|\xintiiEven|\n\etype{f} is 1 if the number is even and 0 otherwise. |
| 13297 |
|
| 13298 |
\subsection{\csh{xintiiMON}}\label{xintiiMON} |
| 13299 |
|
| 13300 |
|\xintiiMON|\n\etype{f} computes |(-1)^N|. |
| 13301 |
\begin{everbatim*} |
| 13302 |
\xintiiMON {-280914019374101929} |
| 13303 |
\end{everbatim*} |
| 13304 |
|
| 13305 |
\subsection{\csh{xintiiMMON}}\label{xintiiMMON} |
| 13306 |
|
| 13307 |
|\xintiiMMON|\n\etype{f} computes |(-1)^{N-1}|. |
| 13308 |
\begin{everbatim*} |
| 13309 |
\xintiiMMON {280914019374101929} |
| 13310 |
\end{everbatim*} |
| 13311 |
|
| 13312 |
\subsection{\csh{xintiiifSgn}}\label{xintiiifSgn} |
| 13313 |
|
| 13314 |
\csh{xintiiifSgn}\marg{N}\marg{A}\marg{B}\marg{C}\etype{fnnn} executes either |
| 13315 |
the \meta{A}, \meta{B} or \meta{C} code, depending on its first argument being |
| 13316 |
respectively negative, zero, or positive. |
| 13317 |
|
| 13318 |
\subsection{\csh{xintiiifZero}}\label{xintiiifZero} |
| 13319 |
|
| 13320 |
\csa{xintiiifZero}\marg{N}\marg{IsZero}\marg{IsNotZero}\etype{fnn} expandably |
| 13321 |
checks if the first mandatory argument |N| (a number, possibly a fraction if |
| 13322 |
\xintfracname is loaded, or a macro expanding to one such) is zero or not. It |
| 13323 |
then either executes the first or the second branch. |
| 13324 |
|
| 13325 |
Beware that both branches must be present. |
| 13326 |
|
| 13327 |
\subsection{\csh{xintiiifNotZero}}\label{xintiiifNotZero} |
| 13328 |
|
| 13329 |
\csa{xintiiifNotZero}\marg{N}\marg{IsNotZero}\marg{IsZero}\etype{fnn} |
| 13330 |
expandably checks if the first mandatory argument |N| is not |
| 13331 |
zero or is zero. It then either executes the first or the second branch. |
| 13332 |
|
| 13333 |
Beware that both branches must be present. |
| 13334 |
|
| 13335 |
\subsection{\csh{xintiiifOne}}\label{xintiiifOne} |
| 13336 |
|
| 13337 |
\csa{xintiiifOne}\marg{N}\marg{IsOne}\marg{IsNotOne}\etype{fnn} expandably |
| 13338 |
checks if the first mandatory argument |N| is one or not one. It |
| 13339 |
then either executes the first or the second branch. Beware that both branches |
| 13340 |
must be present. |
| 13341 |
|
| 13342 |
\subsection{\csh{xintiiifCmp}}\label{xintiiifCmp} |
| 13343 |
|
| 13344 |
\csa{xintiiifCmp}\marg{A}\marg{B}\marg{A<B}\marg{A=B}\marg{A>B}\etype{ffnnn} |
| 13345 |
compares its first two arguments and chooses accordingly the correct branch. |
| 13346 |
|
| 13347 |
\subsection{\csh{xintiiifEq}}\label{xintiiifEq} |
| 13348 |
|
| 13349 |
\csa{xintiiifEq}\marg{A}\marg{B}\marg{A=B}\marg{not(A=B)}\etype{ffnn} checks |
| 13350 |
equality of its two first arguments and executes the corresponding branch. |
| 13351 |
|
| 13352 |
\subsection{\csh{xintiiifGt}}\label{xintiiifGt} |
| 13353 |
|
| 13354 |
\csa{xintiiifGt}\marg{A}\marg{B}\marg{A>B}\marg{not(A>B)}\etype{ffnn} |
| 13355 |
checks if $A>B$ and executes the corresponding branch. |
| 13356 |
|
| 13357 |
\subsection{\csh{xintiiifLt}}\label{xintiiifLt} |
| 13358 |
|
| 13359 |
\csa{xintiiifLt}\marg{A}\marg{B}\marg{A<B}\marg{not(A<B)}\etype{ffnn} |
| 13360 |
checks if $A<B$ and executes the corresponding branch. |
| 13361 |
|
| 13362 |
\subsection{\csh{xintiiifOdd}}\label{xintiiifOdd} |
| 13363 |
|
| 13364 |
\csa{xintiiifOdd}\marg{A}\marg{A odd}\marg{A even}\etype{fnn} checks if $A$ is |
| 13365 |
and odd integer and executes the corresponding branch. |
| 13366 |
|
| 13367 |
\subsection{\csh{xintiiSum}}\label{xintiiSum} |
| 13368 |
|
| 13369 |
\csa{xintiiSum}\marg{braced things}\etype{{\lowast f}} after expanding its |
| 13370 |
argument expects to find a sequence of tokens (or braced material). Each is |
| 13371 |
\fexpan ded, and the sum of all these numbers is returned. |
| 13372 |
\begin{everbatim*} |
| 13373 |
\xintiiSum{{123}{-98763450}{\xintiiFac{7}}{\xintiiMul{3347}{591}}}\newline |
| 13374 |
\xintiiSum{1234567890}\newline |
| 13375 |
\xintiiSum{1234}\newline |
| 13376 |
\xintiiSum{} |
| 13377 |
\end{everbatim*} |
| 13378 |
|
| 13379 |
A sum with only one term returns that |
| 13380 |
number: |\xintiiSum {{-1234}}|\dtt{=\xintiiSum {{-1234}}}. |
| 13381 |
Attention that |\xintiiSum {-1234}| is not legal input and would make the |
| 13382 |
\TeX{} run fail. |
| 13383 |
|
| 13384 |
\subsection{\csh{xintiiPrd}}\label{xintiiPrd} |
| 13385 |
|
| 13386 |
\csa{xintiiPrd}\marg{braced things}\etype{{\lowast f}} after expanding its |
| 13387 |
argument expects to find a sequence of (of braced items or unbraced |
| 13388 |
single tokens). Each is |
| 13389 |
expanded (with the usual meaning), and the product of all these numbers is |
| 13390 |
returned. |
| 13391 |
\begin{everbatim*} |
| 13392 |
\xintiiPrd{{-9876}{\xintiiFac{7}}{\xintiiMul{3347}{591}}}\newline |
| 13393 |
\xintiiPrd{123456789123456789}\newline |
| 13394 |
\xintiiPrd {1234}\newline |
| 13395 |
\xintiiPrd{} |
| 13396 |
\end{everbatim*} |
| 13397 |
|
| 13398 |
Attention that |\xintiiPrd {-1234}| is not legal input and would make the \TeX{} |
| 13399 |
compilation fail. |
| 13400 |
\begin{everbatim*} |
| 13401 |
$2^{200}3^{100}7^{100}=\printnumber |
| 13402 |
{\xintiiPrd {{\xintiiPow {2}{200}}{\xintiiPow {3}{100}}{\xintiiPow {7}{100}}}}$ |
| 13403 |
\end{everbatim*} |
| 13404 |
|
| 13405 |
With \xintexprname, the syntax is the natural one: |
| 13406 |
\begin{everbatim*} |
| 13407 |
$2^{200}3^{100}7^{100}=\printnumber{\xinttheiiexpr 2^200 * 3^100 * 7^100\relax}$ |
| 13408 |
\end{everbatim*} |
| 13409 |
|
| 13410 |
\subsection{\csh{xintiiSquareRoot}} |
| 13411 |
\label{xintiiSquareRoot} |
| 13412 |
|
| 13413 |
|\xintiiSquareRoot|\n\etype{f} returns two braced integers |{M}{d}| which |
| 13414 |
satisfy |d>0| and |M^2-d=N| with |
| 13415 |
|M| the smallest (hence if |N=k^2| is a perfect square then |M=k+1|, |d=2k+1|). |
| 13416 |
|
| 13417 |
\begin{everbatim*} |
| 13418 |
\xintAssign\xintiiSquareRoot {17000000000000000000000000}\to\A\B |
| 13419 |
\xintiiSub{\xintiiSqr\A}\B=\A\string^2-\B |
| 13420 |
\end{everbatim*} |
| 13421 |
|
| 13422 |
A rational approximation to $\sqrt{\text{|N|}}$ is |
| 13423 |
$\text{|M|}-\frac{\text{|d|}}{\text{|2M|}}$ which is a majorant and the error |
| 13424 |
is at most |1/2M| (if |N| is a perfect square |k^2| this gives |k+1/(2k+2)|, |
| 13425 |
not |k|.) |
| 13426 |
|
| 13427 |
Package \xintfracname has \csbxint{FloatSqrt} for square roots of floating |
| 13428 |
point numbers. |
| 13429 |
|
| 13430 |
\subsection{\csh{xintiiSqrt}, \csh{xintiiSqrtR}} |
| 13431 |
\label{xintiiSqrt}\label{xintiiSqrtR} |
| 13432 |
|
| 13433 |
\noindent|\xintiiSqrt|\n\ computes the largest integer whose square |
| 13434 |
is at most equal to |N|.\etype{f} |\xintiiSqrtR| |
| 13435 |
produces the rounded, not truncated, square root.\etype{f} |
| 13436 |
\begin{everbatim*} |
| 13437 |
\begin{itemize}[nosep] |
| 13438 |
\item \xintiiSqrt {3000000000000000000000000000000000000} |
| 13439 |
\item \xintiiSqrtR {3000000000000000000000000000000000000} |
| 13440 |
\item \xintiiSqrt {\xintiiE {3}{100}} |
| 13441 |
\end{itemize} |
| 13442 |
\end{everbatim*} |
| 13443 |
|
| 13444 |
\subsection{\csh{xintiiBinomial}}\label{xintiiBinomial} |
| 13445 |
|
| 13446 |
|\xintiiBinomial{x}{y}|\etype{\numx\numx} computes binomial coefficients. |
| 13447 |
|
| 13448 |
If |x<0| an out-of-range error is raised. Else, if |y<0| or if |x<y| the macro |
| 13449 |
evaluates to \dtt{\xintiiBinomial{1}{-1}}. |
| 13450 |
|
| 13451 |
|
| 13452 |
%\begin{framed} |
| 13453 |
The allowable range is $0\leqslant x\leqslant99999999$. |
| 13454 |
%\end{framed} |
| 13455 |
% Thus the maximal computable value is ${9999 \choose 5000}$ which turns out |
| 13456 |
% to have \dtt{3008} digits. |
| 13457 |
But this theoretical range includes binomial coefficients with more than the |
| 13458 |
roughly 19950 digits that the arithmetics of \xintname can handle. In such |
| 13459 |
cases, the computation will end up in a low-level \TeX{} error after a |
| 13460 |
long time. |
| 13461 |
|
| 13462 |
% |
| 13463 |
It turns out that ${65000 \choose 32500}$ has \dtt{19565} digits and |
| 13464 |
${64000 \choose 32000}$ has \dtt{19264} digits. The latter can be evaluated |
| 13465 |
(this takes a long long time) but presumably not the former (I didn't try). |
| 13466 |
Reasonable feasible evaluations are with binomial coefficients not exceeding |
| 13467 |
about one thousand digits. |
| 13468 |
|
| 13469 |
|
| 13470 |
% |
| 13471 |
The |binomial| function is available in the \xintexprname parsers. |
| 13472 |
\begin{everbatim*} |
| 13473 |
\xinttheiiexpr seq(binomial(100,i), i=47..53)\relax |
| 13474 |
\end{everbatim*} |
| 13475 |
|
| 13476 |
See \csbxint{FloatBinomial} from package \xintfracname for the float variant, |
| 13477 |
used in \csbxint{floatexpr}. |
| 13478 |
|
| 13479 |
|
| 13480 |
In order to |
| 13481 |
evaluate binomial coefficients ${x \choose y}$ with $x>99999999$, or even |
| 13482 |
$x\geqslant 2^{31}$, but $y$ is not too large, one may use an ad hoc function |
| 13483 |
definition such as: |
| 13484 |
\begin{everbatim*} |
| 13485 |
\xintdeffunc mybigbinomial(x,y):=`*`(x-y+1..[1]..x)//y!;% |
| 13486 |
% without [1], x would have been limited to < 2^31 |
| 13487 |
\printnumber{\xinttheexpr mybigbinomial(98765432109876543210,10)\relax} |
| 13488 |
\end{everbatim*} |
| 13489 |
|
| 13490 |
|
| 13491 |
To get this functionality in macro form, one can do: |
| 13492 |
\begin{everbatim*} |
| 13493 |
\xintNewIIExpr\MyBigBinomial [2]{`*`(#1-#2+1..[1]..#1)//#2!} |
| 13494 |
\printnumber{\MyBigBinomial {98765432109876543210}{10}} |
| 13495 |
\end{everbatim*} |
| 13496 |
|
| 13497 |
As we used \csa{xintNewIIExpr}, this macro will only accept strict integers. |
| 13498 |
Had we used \csa{xintNewExpr} the |\MyBigBinomial| would have accepted general |
| 13499 |
fractions or decimal numbers, and computed the product at the numerator |
| 13500 |
without truncating them to integers; but the factorial at the denominator |
| 13501 |
would truncate its argument. |
| 13502 |
|
| 13503 |
\subsection{\csh{xintiiPFactorial}}\label{xintiiPFactorial} |
| 13504 |
|
| 13505 |
|\xintiiPFactorial{a}{b}|\etype{\numx\numx} computes the partial factorial |
| 13506 |
|(a+1)(a+2)...b|. For |a=b| the product is considered empty hence returns |1|. |
| 13507 |
|
| 13508 |
%\begin{framed} |
| 13509 |
The allowed range |
| 13510 |
% |
| 13511 |
% |
| 13512 |
% |
| 13513 |
is $-100000000\leqslant a, b\leqslant99999999$. |
| 13514 |
The |
| 13515 |
rule is to interpret the formula as the product of the |
| 13516 |
$j$'s such that $a<j\leqslant b$, hence in particular if $a\geqslant b$ the |
| 13517 |
product is empty and the macro evaluates to |1|. |
| 13518 |
|
| 13519 |
Only for $0\leqslant a\leqslant b$ is the behaviour to be considered |
| 13520 |
stable. For $a>b$ or negative arguments, the definitive rules have not yet |
| 13521 |
been fixed. |
| 13522 |
|
| 13523 |
\begin{everbatim*} |
| 13524 |
\xintiiPFactorial {100}{130} |
| 13525 |
\end{everbatim*} |
| 13526 |
%\end{framed} |
| 13527 |
|
| 13528 |
This theoretical range allows computations whose result values would have more |
| 13529 |
than the roughly 19950 digits that the arithmetics of \xintname can handle. In |
| 13530 |
such cases, the computation will end up in a low-level \TeX{} error after a |
| 13531 |
long time. |
| 13532 |
|
| 13533 |
The |pfactorial| function is available in the \xintexprname parsers. |
| 13534 |
\begin{everbatim*} |
| 13535 |
\xinttheiiexpr pfactorial(100,130)\relax |
| 13536 |
\end{everbatim*} |
| 13537 |
|
| 13538 |
See \csbxint{FloatPFactorial} from package \xintfracname for the float |
| 13539 |
variant, used in \csbxint{floatexpr}. |
| 13540 |
|
| 13541 |
|
| 13542 |
In case values are needed with $b>99999999$, or even $b\geqslant 2^{31}$, but |
| 13543 |
$b-a$ is not too large, one may use an ad hoc function definition such as: |
| 13544 |
\begin{everbatim*} |
| 13545 |
\xintdeffunc mybigpfac(a,b):=`*`(a+1..[1]..b);% |
| 13546 |
% without [1], b would have been limited to < 2^31 |
| 13547 |
\printnumber{\xinttheexpr mybigpfac(98765432100,98765432120)\relax} |
| 13548 |
\end{everbatim*} |
| 13549 |
|
| 13550 |
\subsection{\csh{xintiiMax}}\label{xintiiMax} |
| 13551 |
|
| 13552 |
|\xintiiMax|\n\m\etype{ff} returns the largest of the two in the sense |
| 13553 |
of the order structure on the relative integers (\emph{i.e.\@} the right-most |
| 13554 |
number if they are put on a line with positive numbers on the right): |
| 13555 |
|\xintiiMax {-5}{-6}|\dtt{=\xintiiMax{-5}{-6}}. |
| 13556 |
|
| 13557 |
\subsection{\csh{xintiiMin}}\label{xintiiMin} |
| 13558 |
|
| 13559 |
|\xintiiMin|\n\m\etype{ff} returns the smallest of the two in the sense of the |
| 13560 |
order structure on the relative integers (\emph{i.e.\@} the left-most number if |
| 13561 |
they are put on a line with positive numbers on the right): |\xintiiMin |
| 13562 |
{-5}{-6}|\dtt{=\xintiiMin{-5}{-6}}. |
| 13563 |
|
| 13564 |
\subsection{\csh{xintiiMaxof}}\label{xintiiMaxof} |
| 13565 |
|
| 13566 |
\csa{xintiiMaxof}|{{a}{b}{c}...}|\etype{f{$\to$}\lowast f} returns the |
| 13567 |
maximum. The list argument may be a macro, it is \fexpan ded first. |
| 13568 |
|
| 13569 |
\subsection{\csh{xintiiMinof}}\label{xintiiMinof} |
| 13570 |
|
| 13571 |
\csa{xintiiMinof}|{{a}{b}{c}...}|\etype{f{$\to$}\lowast f} returns the |
| 13572 |
minimum. The list argument may be a macro, it is \fexpan ded first. |
| 13573 |
|
| 13574 |
\subsection{\csh{xintifTrueAelseB}} |
| 13575 |
\label{xintifTrueAelseB} |
| 13576 |
|
| 13577 |
\csa{xintifTrueAelseB}\marg{f}\marg{true branch}\marg{false branch}\etype{fnn} |
| 13578 |
is a synonym for \csbxint{iiifNotZero}. |
| 13579 |
|
| 13580 |
{\small |
| 13581 |
\noindent |\xintiiifnotzero| is lowercase companion macro.\par } |
| 13582 |
|
| 13583 |
Note 1: as it does only \fexpan sion on its argument it fails with inputs such |
| 13584 |
as |--0|. But with \xintfracname loaded, it does work fine if nested with |
| 13585 |
other \xintfracname macros, because the output format of such macros is fine |
| 13586 |
as input to \csbxint{iiifNotZero}. This remark applies to all other \myenquote{Boolean |
| 13587 |
logic} macros next. |
| 13588 |
|
| 13589 |
Note 2: prior to |1.2o| this macro was using \csbxint{ifNotZero} which applies |
| 13590 |
\csbxint{Num} to its argument (or gets redefined by \xintfracname to handle |
| 13591 |
general decimal numbers or fractions). Hence it would have |
| 13592 |
worked with input such as |--0|. But it was decided at |1.2o| that the |
| 13593 |
overhead was not worth it. The same remark applies to the other \myenquote{Boolean |
| 13594 |
logic} type macros next. |
| 13595 |
|
| 13596 |
\subsection{\csh{xintifFalseAelseB}} |
| 13597 |
\label{xintifFalseAelseB} |
| 13598 |
|
| 13599 |
\csa{xintifFalseAelseB}\marg{f}\marg{false branch}\marg{true |
| 13600 |
branch}\etype{fnn} is a synonym for \csbxint{iiifZero}. |
| 13601 |
|
| 13602 |
{\small |
| 13603 |
\noindent |\xintiiifzero| is lowercase companion macro.\par } |
| 13604 |
|
| 13605 |
\subsection{\csh{xintNOT}}\label{xintNOT} |
| 13606 |
|
| 13607 |
\csa{xintNOT}\etype{f} is a synonym for \csa{xintiiIsZero}. |
| 13608 |
|
| 13609 |
{\small |\xintiiiszero| serves as lowercase companion macro.\par} |
| 13610 |
|
| 13611 |
\subsection{\csh{xintAND}}\label{xintAND} |
| 13612 |
|
| 13613 |
|\xintAND{f}{g}|\etype{ff} returns \dtt{1} if |f!=0| and |g!=0| and \dtt{0} |
| 13614 |
otherwise. |
| 13615 |
|
| 13616 |
\subsection{\csh{xintOR}}\label{xintOR} |
| 13617 |
|
| 13618 |
|\xintOR{f}{g}|\etype{ff} returns \dtt{1} if |f!=0| or |g!=0| and \dtt{0} |
| 13619 |
otherwise. |
| 13620 |
|
| 13621 |
\subsection{\csh{xintXOR}}\label{xintXOR} |
| 13622 |
|
| 13623 |
|\xintXOR{f}{g}|\etype{ff} returns \dtt{1} if exactly one of |f| or |g| |
| 13624 |
is true (i.e.\@{} non-zero), else \dtt{0}. |
| 13625 |
|
| 13626 |
\subsection{\csh{xintANDof}}\label{xintANDof} |
| 13627 |
|
| 13628 |
\csa{xintANDof}|{{a}{b}{c}...}|\etype{f{$\to$}\lowast f} returns \dtt{1} if |
| 13629 |
all are true (i.e.\@{} non zero) and \dtt{0} otherwise. The list argument may be a |
| 13630 |
macro, it (or rather its first token) is \fexpan ded first to deliver its |
| 13631 |
items. |
| 13632 |
|
| 13633 |
\subsection{\csh{xintORof}}\label{xintORof} |
| 13634 |
|
| 13635 |
\csa{xintORof}|{{a}{b}{c}...}|\etype{f{$\to$}\lowast f} returns \dtt{1} if at |
| 13636 |
least one is true (i.e.\@{} does not vanish), else it produces \dtt{0}. The list |
| 13637 |
argument may be a macro, it is \fexpan ded first. |
| 13638 |
|
| 13639 |
\subsection{\csh{xintXORof}}\label{xintXORof} |
| 13640 |
|
| 13641 |
\csa{xintXORof}|{{a}{b}{c}...}|\etype{f{$\to$}\lowast f} returns \dtt{1} if an |
| 13642 |
odd number of them are true (i.e.\@{} do not vanish), else it produces \dtt{0}. |
| 13643 |
The list argument may be a macro, it is \fexpan ded first. |
| 13644 |
|
| 13645 |
\subsection{\csh{xintiiGCD}} |
| 13646 |
\label{xintiiGCD} |
| 13647 |
|
| 13648 |
|\xintiiGCD|\n\m\etype{ff} computes the greatest common divisor. It is |
| 13649 |
positive, except when both |N| and |M| vanish, in which case the macro returns |
| 13650 |
zero. |
| 13651 |
% |
| 13652 |
\leftedline{\csa{xintiiGCD}|{10000}{1113}|\dtt{=\xintiiGCD{10000}{1113}}} |
| 13653 |
% |
| 13654 |
\leftedline{|\xintiiGCD{123456789012345}{9876543210321}=|\dtt |
| 13655 |
{\xintiiGCD{123456789012345}{9876543210321}}} |
| 13656 |
|
| 13657 |
At |1.3d|, this macro (which is used by the \func{gcd} function in |
| 13658 |
\csbxint{iiexpr}) was copied over to \xintname, thus removing a partial |
| 13659 |
dependency of \xintexprname on \xintgcdname. |
| 13660 |
|
| 13661 |
At |1.4| \xintgcdname requires \xintname and the latter is thus the one |
| 13662 |
providing the macro. |
| 13663 |
|
| 13664 |
\subsection{\csh{xintiiLCM}} |
| 13665 |
\label{xintiiLCM} |
| 13666 |
|
| 13667 |
|\xintiiLCM|\n\m\etype{ff} computes the least common multiple. It is positive, |
| 13668 |
except if one of |N| or |M| vanish, in which case the macro returns zero. |
| 13669 |
% |
| 13670 |
\leftedline{\csa{xintiiLCM}|{10000}{1113}|\dtt{=\xintiiLCM{10000}{1113}}} |
| 13671 |
% |
| 13672 |
\leftedline{|\xintiiLCM{123456789012345}{9876543210321}=|\dtt |
| 13673 |
{\xintiiLCM{123456789012345}{9876543210321}}} |
| 13674 |
|
| 13675 |
At |1.3d|, this macro (which is used by the \func{lcm} function in |
| 13676 |
\csbxint{iiexpr}) was copied over to \xintname, thus removing a partial |
| 13677 |
dependency of \xintexprname on \xintgcdname. |
| 13678 |
|
| 13679 |
At |1.4| \xintgcdname requires \xintname and the latter is thus the one |
| 13680 |
providing the macro. |
| 13681 |
|
| 13682 |
\subsection{\csh{xintiiGCDof}}\label{xintiiGCDof} |
| 13683 |
|
| 13684 |
\csa{xintiiGCDof}|{{a}{b}{c}...}|\etype{f{$\to$}{\lowast f}} computes the |
| 13685 |
greatest common divisor of the integers |a|, |b|, \dots{}. It is a support |
| 13686 |
macro for the |gcd()| function of the \csbxint{iiexpr} parser. |
| 13687 |
|
| 13688 |
It replaces the \csbxint{GCDof} which was formerly provided by \xintgcdname |
| 13689 |
and is now available via \xintfracname in a version handling also |
| 13690 |
fractions. |
| 13691 |
|
| 13692 |
|
| 13693 |
\subsection{\csh{xintiiLCMof}}\label{xintiiLCMof} |
| 13694 |
|
| 13695 |
\csa{xintiiLCMof}|{{a}{b}{c}...}|\etype{f{$\to$}{\lowast f}} computes the |
| 13696 |
least common multiple of the integers |a|, |b|, \dots{}. It is a support |
| 13697 |
macro for the |lcm()| function of the \csbxint{iiexpr} parser. |
| 13698 |
|
| 13699 |
It replaces the \csbxint{LCMof} which was formerly provided by \xintgcdname |
| 13700 |
and is now available via \xintfracname in a version handling also |
| 13701 |
fractions. |
| 13702 |
|
| 13703 |
\subsection{\csh{xintLen}}\label{xintLen} |
| 13704 |
|
| 13705 |
|\xintLen|\etype{\Numf} is originally an alias for \csbxint{iLen}. But with |
| 13706 |
\xintfracname loaded its meaning is \hyperref[xintLenFrac]{modified} to accept |
| 13707 |
more general inputs. |
| 13708 |
|
| 13709 |
\subsection{(WIP) \csh{xintRandomDigits}}\label{xintRandomDigits} |
| 13710 |
|
| 13711 |
\begin{framed} |
| 13712 |
All randomness related macros are Work-In-Progress: implementation and user |
| 13713 |
interface may change. They work only if the \TeX\ engine provides the |
| 13714 |
\csa{uniformdeviate} or \csa{pdfuniformdeviate} primitive. See |
| 13715 |
\csbxint{UniformDeviate} for additional information. |
| 13716 |
\end{framed} |
| 13717 |
|
| 13718 |
|\xintRandomDigits{N}|\etype{\numx} expands in two steps to |N| random decimal |
| 13719 |
digits. The argument must be non-negative and is limited by \TeX\ memory |
| 13720 |
parameters. |
| 13721 |
On \TeX Live 2018 with input save stack size at \dtt{5000} the |
| 13722 |
maximal allowed |N| is at most \dtt{19984} (tested within a |\write| to an |
| 13723 |
auxiliary file, the macro context may cause a reduced maximum). |
| 13724 |
\begin{everbatim*} |
| 13725 |
\pdfsetrandomseed 271828182 |
| 13726 |
\xintRandomDigits{92} |
| 13727 |
\end{everbatim*} |
| 13728 |
|
| 13729 |
\begin{TeXnote} |
| 13730 |
the digits are produced eight by eight by the same method which would result |
| 13731 |
from \csbxint{UniformDeviate}|{100000000}| but with less overhead. |
| 13732 |
\end{TeXnote} |
| 13733 |
|
| 13734 |
% \subsection{\csh{\xintOneRandomDigit}}\label{xintOneRandomDigit} |
| 13735 |
|
| 13736 |
\subsection{(WIP) \csh{xintXRandomDigits}}\label{xintXRandomDigits} |
| 13737 |
|
| 13738 |
|\xintXRandomDigits{N}|\xtype{\numx} expands under exhaustive expansion |
| 13739 |
(|\edef|, |\write|, |\csname| ...) to |N| random decimal |
| 13740 |
digits. The argument must be non-negative. |
| 13741 |
For example: |
| 13742 |
\begin{everbatim} |
| 13743 |
\newwrite\out |
| 13744 |
\immediate\openout\out=\jobname-out.txt |
| 13745 |
\immediate\write\out{\xintXRandomDigits{4500000}} |
| 13746 |
\immediate\closeout\out |
| 13747 |
\end{everbatim} |
| 13748 |
creates a \dtt{4500001} bytes file (it ends with a line feed character). |
| 13749 |
Trying with \dtt{5000000} raises this error: |
| 13750 |
\begin{everbatim} |
| 13751 |
Runaway text? |
| 13752 |
588875947168511582764514135070217555354479805240439407753451354223283\ETC. |
| 13753 |
! TeX capacity exceeded, sorry [main memory size=5000000]. |
| 13754 |
<inserted text> 666515098 |
| 13755 |
|
| 13756 |
l.15 ...ate\write\out{\xintXRandomDigits{5000000}} |
| 13757 |
|
| 13758 |
No pages of output. |
| 13759 |
Transcript written on temp.log. |
| 13760 |
\end{everbatim} |
| 13761 |
This can be lifted by increasing the \TeX\ memory settings (installation |
| 13762 |
dependent). |
| 13763 |
|
| 13764 |
\begin{TeXnote} |
| 13765 |
the digits are produced eight by eight by the same method which would result |
| 13766 |
from \csbxint{UniformDeviate}|{100000000}| but with less overhead. |
| 13767 |
\end{TeXnote} |
| 13768 |
|
| 13769 |
\subsection{(WIP) \csh{xintiiRandRange}}\label{xintiiRandRange} |
| 13770 |
|
| 13771 |
|\xintiiRandRange{A}|\etype{f} expands to a random (big) integer |N| |
| 13772 |
such that |0<=N<A|. It is a supporting macro for \func{randrange}. As with |
| 13773 |
Python's function of the same name, it is an error if |A<=0|. |
| 13774 |
\begin{everbatim*} |
| 13775 |
\pdfsetrandomseed 271828314 |
| 13776 |
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\newline |
| 13777 |
\xintiiRandRange{\xintNum{1e40}}\newline |
| 13778 |
\pdfsetrandomseed 271828314 |
| 13779 |
\xinttheiiexpr randrange(num(1e40))\relax\newline |
| 13780 |
% bare 1e40 not understood by \xintiiexpr |
| 13781 |
\pdfsetrandomseed 271828314 |
| 13782 |
\xinttheexpr randrange(1e40)\relax |
| 13783 |
\end{everbatim*} |
| 13784 |
|
| 13785 |
Of course, keeping in mind that the set of seeds is of cardinality |2^{28}|, |
| 13786 |
randomness is a bit illusory here say with |A=10^N|, |N>8|, if we proceed |
| 13787 |
immediately after having set the seed. If we add some entropy in any way, then |
| 13788 |
it is slightly more credible; but I think that for each seed the period is |
| 13789 |
something like |2^{27}(2^{55}-1)55|,% |
| 13790 |
% |
| 13791 |
\footnote{Compare the result of exercise 3.2.2-30 in TAOCP, vol II.} |
| 13792 |
% |
| 13793 |
so we expect at most about |2^{110}55| |
| 13794 |
``points in time'', and this is already small compared to the |10^40| |
| 13795 |
from example above. Thus already we are very far from being intrinsically |
| 13796 |
able to generate all numbers with forty digits as random numbers, and this |
| 13797 |
makes the previous section about usage of \csbxint{XRandomDigits} to generate |
| 13798 |
millions of digits a bit comical... |
| 13799 |
|
| 13800 |
\begin{TeXnote} |
| 13801 |
the digits are produced eight by eight by the same method which would result |
| 13802 |
from \csbxint{UniformDeviate}|{100000000}| but with less overhead. |
| 13803 |
\end{TeXnote} |
| 13804 |
|
| 13805 |
\subsection{(WIP) \csh{xintiiRandRangeAtoB}}\label{xintiiRandRangeAtoB} |
| 13806 |
|
| 13807 |
|\xintiiRandRangeAtoB{A}{B}|\etype{ff} expands to a random (big) integer |N| |
| 13808 |
such that |A<=N<B|. It is a supporting macro for \func{randrange}. As with |
| 13809 |
Python's function of the same name, it is an error if |B<=A|. |
| 13810 |
\begin{everbatim*} |
| 13811 |
\pdfsetrandomseed 271828314 |
| 13812 |
12345678911111111111111111111\newline |
| 13813 |
\xintiiRandRangeAtoB{12345678911111111111111111111}{12345678922222222222222222222}% |
| 13814 |
\newline |
| 13815 |
\pdfsetrandomseed 271828314 |
| 13816 |
\def\test{% |
| 13817 |
\xinttheiiexpr |
| 13818 |
randrange(12345678911111111111111111111,12345678922222222222222222222) |
| 13819 |
\relax}% |
| 13820 |
\romannumeral\xintreplicate{10}{\test\newline}% |
| 13821 |
12345678922222222222222222222 |
| 13822 |
\end{everbatim*} |
| 13823 |
|
| 13824 |
\begin{TeXnote} |
| 13825 |
the digits are produced eight by eight by the same method which would result |
| 13826 |
from \csbxint{UniformDeviate}|{100000000}| but with less overhead. |
| 13827 |
\end{TeXnote} |
| 13828 |
|
| 13829 |
\clearpage |
| 13830 |
\let\xintnameUp\undefined |
| 13831 |
\csname xintfracnameUp\endcsname |
| 13832 |
\def\n{|{N}|} |
| 13833 |
\def\m{|{M}|} |
| 13834 |
\def\x{|{x}|} |
| 13835 |
\section{Macros of the \xintfracname package} |
| 13836 |
\RaisedLabel{sec:frac} |
| 13837 |
|
| 13838 |
\localtableofcontents |
| 13839 |
|
| 13840 |
First version of this package was in release |1.03| (|2013/04/14|) of the |
| 13841 |
\xintbundlename. |
| 13842 |
|
| 13843 |
At release |1.3| (|2018/02/28|) the behaviour of \csbxint{Add} (and of |
| 13844 |
\csbxint{Sub}) was modified: when adding |a/b| and |c/d| they |
| 13845 |
will use always the least common multiple of the denominators. This helps |
| 13846 |
limit the build-up of denominators, but the author still hesitates if the |
| 13847 |
fraction should be reduced to smallest terms. The current method allows (for |
| 13848 |
example when multiplying two polynomials) to keep a well-predictable |
| 13849 |
denominator among various terms, even though some may be reducible. |
| 13850 |
|
| 13851 |
\xintfracname loads automatically \xintcorename and \xintname and inherits |
| 13852 |
their macro definitions. Only these two are redefined: |
| 13853 |
\hyperref[xintNumFrac]{\string\xintNum} and |
| 13854 |
\hyperref[xintLenFrac]{\string\xintLen}. As explained in \autoref{ssec:inputs} |
| 13855 |
and \autoref{ssec:outputs} the interchange format for the \xintfracname |
| 13856 |
macros, i.e.\@{} |A/B[N]|, is not understood by the |ii|-named macros of |
| 13857 |
\xintcorename/\xintname which expect the so-called strict integer format. |
| 13858 |
Hence, to use such an |ii|-macro with an output from an \xintfracname macro, |
| 13859 |
an extra \csbxint{Num} wrapper is required. But macros already defined by |
| 13860 |
\xintfracname cover most use cases hence this should be a rarely needed. |
| 13861 |
|
| 13862 |
In the macro descriptions, the variable |f|\ntype{\Ff} and the margin |
| 13863 |
indicator stand for the \xintfracname input format for integers, scientific |
| 13864 |
numbers, and fractions as described in \autoref{ssec:inputs}. |
| 13865 |
|
| 13866 |
As in the \hyperref[sec:xint]{xint.sty} documentation, |x|\ntype{\numx} stands |
| 13867 |
for something which internally will be handled in a \csa{numexpr}. It may thus |
| 13868 |
be an expression as understood by \csa{numexpr} but its evaluation and |
| 13869 |
intermediate steps must obey the \TeX\ bound. |
| 13870 |
|
| 13871 |
The output format for most macros is the |A/B[N]| format but naturally the |
| 13872 |
float macros use the scientific notation on output. And some macros are |
| 13873 |
special, for example \csbxint{Trunc} produces decimal numbers, \csbxint{Irr} |
| 13874 |
produces an |A/B| with no |[N]|, \csbxint{iTrunc} and \csbxint{iRound} produce |
| 13875 |
integers without trailing |[N]| either, etc\dots |
| 13876 |
|
| 13877 |
At |1.4g|, old legacy typesetting macros |\xintFrac|, |\xintSignedFrac|, |
| 13878 |
|\xintFwOver| and |\xintSignedFwOver| were renamed into \csbxint{TeXFrac}, |
| 13879 |
\csbxint{TeXsignedFrac}, \csbxint{TeXOver}, \csbxint{TeXsignedOver}. The old |
| 13880 |
names will raise errors\CHANGED{1.4m} and will be removed completely soon. |
| 13881 |
|
| 13882 |
\subsection{\csh{xintTeXFromSci}}\label{xintTeXFromSci} |
| 13883 |
|
| 13884 |
Experimental.\xtype{} This typesetting math-mode-only macro expects an input |
| 13885 |
which is already in, or will expand to, decimal or scientific |
| 13886 |
notation. A trailing |/B| is accepted and will be handled |
| 13887 |
differently according to whether it follows some scientific exponent |eN| |
| 13888 |
part or not. |
| 13889 |
|
| 13890 |
It was formerly |\xintTeXfromSci|. Old name deprecated at |1.4l|. Also it used |
| 13891 |
to be \fexpan dable but is now only \xexpan dable. Use |\expanded| if |
| 13892 |
needed. |
| 13893 |
|
| 13894 |
This macro can be used as a typesetting wrapper for \csbxint{eval} or |
| 13895 |
\csbxint{floateval} output: it expects its input (after expansion) to |
| 13896 |
have been already \myenquote{prettified} for example via the removal of trailing |
| 13897 |
zeros, usage of fixed point notation if scientific exponent is small, |
| 13898 |
etc\dots\ |
| 13899 |
% |
| 13900 |
It simply transforms the |e<exponent>| part, if actually present, into |
| 13901 |
|\cdot 10^{exponent}|. A fractional part |/B| if found in the expansion |
| 13902 |
of the input must be last and will be tranformed into |\cdot B^{-1}| if |
| 13903 |
there was a scientific part, else the output will be using |\frac{A}{B}| |
| 13904 |
(or the \TeX\ equivalent in place of |\frac|) with |A| the numerator. |
| 13905 |
|
| 13906 |
\begin{TeXnote} |
| 13907 |
\begin{itemize} |
| 13908 |
\item I am hesitating whether the |\frac{A}{B}| branch choice should |
| 13909 |
require |A| to be an integer, or will also, as currently, be done |
| 13910 |
with |A| being a number in decimal notation. Please advise. |
| 13911 |
\item The package does: |
| 13912 |
\begin{everbatim} |
| 13913 |
\ifdefined\frac |
| 13914 |
\protected\def\xintTeXFromScifracmacro#1#2{\frac{#2}{#1}}% |
| 13915 |
\else |
| 13916 |
\protected\def\xintTeXFromScifracmacro#1#2{{#2\over#1}}% |
| 13917 |
\fi |
| 13918 |
\end{everbatim} |
| 13919 |
Customize as desired. Notice the interversion of arguments. |
| 13920 |
\end{itemize} |
| 13921 |
\end{TeXnote} |
| 13922 |
|
| 13923 |
Example: |
| 13924 |
\begin{everbatim*} |
| 13925 |
$\xintTeXFromSci{\xintfloateval{1.1^10000/5}}$, |
| 13926 |
$\xintTeXFromSci{\xinteval{1.1^10000/5}}$\par |
| 13927 |
\end{everbatim*} |
| 13928 |
|
| 13929 |
The above examples are in the case of a single numerical value. To |
| 13930 |
handle more complex outputs from \csbxint{eval} or \csbxint{floateval} |
| 13931 |
one will need to proceed via a redefinition of |
| 13932 |
\csbxint{floatexprPrintOne} and/or \csbxint{exprPrintOne} like this: |
| 13933 |
\begin{everbatim*} |
| 13934 |
\[\def\xintfloatexprPrintOne[#1]#2{\xintTeXFromSci{\xintPFloat[#1]{#2}}} |
| 13935 |
\xintfloateval[10]{2^100, 3^100, 13^100}\] |
| 13936 |
\end{everbatim*} |
| 13937 |
\par\vskip-\belowdisplayskip |
| 13938 |
\begin{everbatim*} |
| 13939 |
\[\def\xintexprPrintOne#1{\xintTeXFromSci{\xintFracToSci{#1}}} |
| 13940 |
\xinteval{sqrt(2^101,60), 355/113, 6.02e23/1000}\] |
| 13941 |
\end{everbatim*}% attention à l'espace TeX est en mode horizontal après display |
| 13942 |
This will however make then impossible, due to the added \TeX\ mark-up in the |
| 13943 |
output, the nesting of \csbxint{floateval}/\csbxint{eval} inside one another. |
| 13944 |
The core \csbxint{expr}|...\relax| syntax remains usable and is anyhow the |
| 13945 |
recommended way for such nesting as it is more efficient. |
| 13946 |
|
| 13947 |
Some similar effect is also possible without \csbxint{TeXFromSci}, |
| 13948 |
simply by a customization of \csbxint{PFloatE} like this: |
| 13949 |
\begin{everbatim*} |
| 13950 |
\begingroup |
| 13951 |
\def\xintPFloatE#1.{\cdot10^{#1}.}% |
| 13952 |
$\xintfloateval{1.1^10000/5}$, $\xinteval{1.1^10000/5}$ |
| 13953 |
\endgroup\newline |
| 13954 |
\end{everbatim*}% |
| 13955 |
This method is simpler-minded but will leave the trailing |/B|'s \myenquote{as |
| 13956 |
is}, even if the numerator has no scientific exponent part. The |
| 13957 |
presence of extra \TeX\ mark-up in the output has the consequences |
| 13958 |
on nesting which were mentioned above. |
| 13959 |
|
| 13960 |
\subsection{\csh{xintTeXFrac}}\label{xintTeXFrac} |
| 13961 |
|
| 13962 |
This is a typesetting \LaTeX{} only macro\etype{\Ff}, math mode only as it |
| 13963 |
expands to |\frac{A}{B}10^n| for an input which ends up parsed into raw |
| 13964 |
format |A/B[n]|. |
| 13965 |
|
| 13966 |
If the denominator |B| is \dtt{1}, the output is |A\cdot 10^n|. If the |
| 13967 |
exponent |n| is \dtt{0}, the |[\cdot]10^n| part is omitted. |
| 13968 |
\begin{everbatim*} |
| 13969 |
$\xintTeXFrac {178.000/25600000}$, $\xintTeXFrac {178.000/1}$, |
| 13970 |
$\xintTeXFrac {3.5/5.7}$\newline |
| 13971 |
\end{everbatim*}% |
| 13972 |
The input, if in a fraction form, is not simplified in any way, except for |
| 13973 |
transforming numerator and denominator into integers, separating a power of |
| 13974 |
ten part. Macros such as \csbxint{Irr}, \csbxint{PIrr}, \csbxint{REZ} can be |
| 13975 |
inserted to wrap the input and help simplify it. The minus sign ends up in |
| 13976 |
the numerator. |
| 13977 |
|
| 13978 |
It is the new name since |1.4g| of |\xintFrac|. The old name now raises |
| 13979 |
a \TeX{} error.\CHANGED{1.4m} |
| 13980 |
|
| 13981 |
\subsection{\csh{xintTeXsignedFrac}}\label{xintTeXsignedFrac} |
| 13982 |
|
| 13983 |
|
| 13984 |
This is as \csbxint{TeXFrac}\etype{\Ff} except that a negative fraction has the |
| 13985 |
sign ending up in front, not in the numerator. |
| 13986 |
\begin{everbatim*} |
| 13987 |
$\xintTeXFrac {-355/113}=\xintTeXsignedFrac {-355/113}$\newline |
| 13988 |
\end{everbatim*}% |
| 13989 |
It is the new name since |1.4g| of |\xintSignedFrac|. The old name now raises |
| 13990 |
a \TeX{} error.\CHANGED{1.4m} |
| 13991 |
|
| 13992 |
\subsection{\csh{xintTeXOver}}\label{xintTeXOver} |
| 13993 |
|
| 13994 |
This does the same as \csa{xintTeXFrac}\etype{\Ff} except that the \csa{over} |
| 13995 |
primitive is used for the fraction (in case the denominator is not one; and a |
| 13996 |
pair of braces contains the |A\over B| part). |
| 13997 |
\begin{everbatim*} |
| 13998 |
$\xintTeXOver {178.000/25600000}$, $\xintTeXOver {178.000/1}$, |
| 13999 |
$\xintTeXOver {3.5/5.7}$\newline |
| 14000 |
\end{everbatim*}% |
| 14001 |
It is the new name since |1.4g| of |\xintFwOver|. The old name now raises |
| 14002 |
a \TeX{} error.\CHANGED{1.4m} |
| 14003 |
|
| 14004 |
\subsection{\csh{xintTeXsignedOver}}\label{xintTeXsignedOver} |
| 14005 |
|
| 14006 |
This is as \csbxint{TeXOver}\etype{\Ff} except that a negative fraction has the |
| 14007 |
sign put in front, not in the numerator. |
| 14008 |
\begin{everbatim*} |
| 14009 |
$\xintTeXOver{-355/113}=\xintTeXsignedOver{-355/113}$\newline |
| 14010 |
\end{everbatim*}% |
| 14011 |
It is the new name since |1.4g| of |\xintSignedFwOver|. The old name now raises |
| 14012 |
a \TeX{} error.\CHANGED{1.4m} |
| 14013 |
|
| 14014 |
\subsection{\csh{xintLen}}\label{xintLenFrac} |
| 14015 |
|
| 14016 |
The \csbxint{Len} macro\etype{\Ff} from \xintname is extended to accept a fraction |
| 14017 |
on input: the length of |A/B[n]| is the length of |A| plus the length of |B| |
| 14018 |
plus the absolute value of |n| and minus one (an integer input as |N| is |
| 14019 |
internally represented in a form equivalent to |N/1[0]| so the minus one means |
| 14020 |
that the extended \csa{xintLen} behaves the same as the original for |
| 14021 |
integers). |
| 14022 |
\begin{everbatim*} |
| 14023 |
\xintLen{201710/298219}=\xintLen{201710}+\xintLen{298219}-1\newline |
| 14024 |
\xintLen{1234/1}=\xintLen{1234}=\xintLen{1234[0]}=\xintiLen{1234}\newline |
| 14025 |
\xintLen{-1e3/5.425} (\xintRaw {-1e3/5.425})\par |
| 14026 |
\end{everbatim*} |
| 14027 |
The length is computed on the |A/B[n]| which would have been returned by |
| 14028 |
\csbxint{Raw}, as illustrated by the last example above. |
| 14029 |
|
| 14030 |
|\xintLen| is only for use with such (scientific) numbers or fractions. See |
| 14031 |
also \csbxint{NthElt} from \xinttoolsname. See also \csbxint{Length} (which |
| 14032 |
however does not expand its argument) from \xintkernelname for counting more |
| 14033 |
general tokens (or rather braced items). |
| 14034 |
|
| 14035 |
\subsection{\csh{xintNum}}\label{xintNumFrac} |
| 14036 |
|
| 14037 |
The \csbxint{Num} \etype{\Ff} from \xintname is transformed into a synonym to |
| 14038 |
\csbxint{TTrunc}. |
| 14039 |
|
| 14040 |
Attention that for example |\xintNum{1e100000}| expands to the needed |
| 14041 |
\dtt{100001} digits... |
| 14042 |
|
| 14043 |
The original \hyperref[xintiNum]{\string\xintNum} from \xintcorename which |
| 14044 |
does not understand the fraction slash or the scientific notation is still |
| 14045 |
available under the name \csbxint{iNum}. |
| 14046 |
|
| 14047 |
\subsection{\csh{xintRaw}}\label{xintRaw} |
| 14048 |
|
| 14049 |
This macro `prints' the\etype{\Ff} |
| 14050 |
fraction |f| as it is received by the package after its parsing and |
| 14051 |
expansion, in a form |A/B[N]| equivalent to the internal |
| 14052 |
representation: the denominator |B| is always strictly positive and is |
| 14053 |
printed even if it has value |1|. |
| 14054 |
\begin{everbatim*} |
| 14055 |
\xintRaw{\the\numexpr 571*987\relax.123e-10/\the\numexpr-201+59\relax e-7} |
| 14056 |
\end{everbatim*} |
| 14057 |
|
| 14058 |
No simplification is done, not even of common zeroes between numerator and |
| 14059 |
denominator: |
| 14060 |
\begin{everbatim*} |
| 14061 |
\xintRaw {178000/25600000} |
| 14062 |
\end{everbatim*} |
| 14063 |
|
| 14064 |
\subsection{\csh{xintRawBraced}}\label{xintRawBraced} |
| 14065 |
|
| 14066 |
This macro expands and parses its input\etype{\Ff} |f| as all |
| 14067 |
\xintfracname macros and produces as output |{N}{A}{B}| (with \TeX\ |
| 14068 |
braces) where \csbxint{Raw} would have returned |A/B[N]|. |
| 14069 |
|
| 14070 |
\subsection{\csh{xintNumerator}}\label{xintNumerator} |
| 14071 |
|
| 14072 |
The input data\etype{\Ff} is parsed as if by \csbxint{Raw} into |A/B[N]| |
| 14073 |
and then |A| is returned if |N<=0|, or |A| extended by |N| zeroes if |N>0|. |
| 14074 |
\begin{everbatim*} |
| 14075 |
\xintNumerator {178000/25600000[17]}\newline |
| 14076 |
\xintNumerator {312.289001/20198.27}\newline |
| 14077 |
\xintNumerator {178000e-3/256e5}\newline |
| 14078 |
\xintNumerator {178.000/25600000} |
| 14079 |
\end{everbatim*} |
| 14080 |
|
| 14081 |
\subsection{\csh{xintDenominator}}\label{xintDenominator} |
| 14082 |
|
| 14083 |
The input data\etype{\Ff} is parsed as if by \csbxint{Raw} into |A/B[N]| |
| 14084 |
and then |B| is returned if |N>0|, or |B| extended by \verb+|N|+ zeroes if |N<=0|. |
| 14085 |
\begin{everbatim*} |
| 14086 |
\xintDenominator {178000/25600000[17]}\newline |
| 14087 |
\xintDenominator {312.289001/20198.27}\newline |
| 14088 |
\xintDenominator {178000e-3/256e5}\newline |
| 14089 |
\xintDenominator {178.000/25600000} |
| 14090 |
\end{everbatim*} |
| 14091 |
|
| 14092 |
\subsection{\csh{xintRawWithZeros}}\label{xintRawWithZeros} |
| 14093 |
|
| 14094 |
This macro parses the input\etype{\Ff} and outputs |A'/B'|, with |A'| |
| 14095 |
as would be returned by \csa{xintNumerator}|{f}| and |B'| as would be returned by |
| 14096 |
\csa{xintDenominator}|{f}|. |
| 14097 |
\begin{everbatim*} |
| 14098 |
\xintRawWithZeros{178000/25600000[17]}\newline |
| 14099 |
\xintRawWithZeros{312.289001/20198.27}\newline |
| 14100 |
\xintRawWithZeros{178000e-3/256e5}\newline |
| 14101 |
\xintRawWithZeros{178.000/25600000}\newline |
| 14102 |
\xintRawWithZeros{\the\numexpr 571*987\relax.123e-10/\the\numexpr-201+59\relax e-7} |
| 14103 |
\end{everbatim*} |
| 14104 |
|
| 14105 |
\subsection{\csh{xintREZ}}\label{xintREZ} |
| 14106 |
|
| 14107 |
The input\etype{\Ff} is first parsed into |A/B[N]| as by \csbxint{Raw}, then |
| 14108 |
trailing zeroes of |A| and |B| are suppressed and |N| is accordingly adjusted. |
| 14109 |
\begin{everbatim*} |
| 14110 |
\xintREZ {178000/25600000[17]} |
| 14111 |
\end{everbatim*} |
| 14112 |
|
| 14113 |
|
| 14114 |
\subsection{\csh{xintIrr}}\label{xintIrr} |
| 14115 |
|
| 14116 |
This puts the fraction\etype{\Ff} into its unique irreducible form: |
| 14117 |
\begin{everbatim*} |
| 14118 |
\xintIrr {178.256/256.1780}, \xintIrr {178000/25600000[17]} |
| 14119 |
\end{everbatim*} |
| 14120 |
|
| 14121 |
The current implementation does not cleverly first factor powers of |
| 14122 |
2 and 5, and |\xintIrr {2/3[100]}| will execute the |
| 14123 |
Euclidean division of |2|\raisebox{.5ex}{|.|}|10^{100}| by |3|, which is a bit |
| 14124 |
stupid as it could have known that the \dtt{100} trailing zeros can not bring |
| 14125 |
any divisibility by \dtt{3}. |
| 14126 |
|
| 14127 |
Starting with release |1.08|, \csa{xintIrr} does not remove the trailing |/1| |
| 14128 |
when the output is an integer. This was deemed better for various (questionable?) |
| 14129 |
reasons, anyway the output format is since \emph{always} |A/B| with |B>0|, even |
| 14130 |
in cases where it turns out that |B=1|. |
| 14131 |
Use \csbxint{PRaw} on top of \csa{xintIrr} if it is needed to get rid of such a |
| 14132 |
trailing |/1|. |
| 14133 |
|
| 14134 |
\subsection{\csh{xintPIrr}}\label{xintPIrr} |
| 14135 |
|
| 14136 |
This puts the fraction\etype{\Ff} into irreducible form, |
| 14137 |
\emph{keeping as is the |
| 14138 |
decimal part} |[N]| from raw internal |A/B[N]| format. |
| 14139 |
(|P| stands here for \emph{Partial}) |
| 14140 |
\begin{everbatim*} |
| 14141 |
\xintPIrr {178.256/256.1780}, \xintPIrr {178000/25600000[17]} |
| 14142 |
\end{everbatim*} |
| 14143 |
|
| 14144 |
Notice that the output always has the ending |[N]|, which is exactly the |
| 14145 |
opposite of \csbxint{Irr}'s behaviour. The interest of this macro is mainly in |
| 14146 |
handling fractions which somehow acquired a big |[N]| (perhaps from input in |
| 14147 |
scientific notation) and for which the reduced fraction would have a very |
| 14148 |
large number of digits. This large number of digits can considerably slow-down |
| 14149 |
computations done afterwards. |
| 14150 |
|
| 14151 |
For example package \href{http://ctan.org/pkg/polexpr}{polexpr} uses |
| 14152 |
\csa{xintPIrr} when differentiating a polynomial, or in setting up a Sturm |
| 14153 |
chain for localization of the real roots of a polynomial. This is relevant to |
| 14154 |
polynomials whose coefficients were input in decimal notation, as this |
| 14155 |
automatically creates internally some |[N]|. Keeping and combining those |
| 14156 |
|[N]|'s during computations significantly increases their speed. |
| 14157 |
|
| 14158 |
\subsection{\csh{xintJrr}}\label{xintJrr} |
| 14159 |
|
| 14160 |
This also puts the fraction\etype{\Ff} into its unique irreducible form: |
| 14161 |
\begin{everbatim*} |
| 14162 |
\xintJrr {178.256/256.178} |
| 14163 |
\end{everbatim*} |
| 14164 |
|
| 14165 |
This is (supposedly, not tested for ages) faster than \csa{xintIrr} for |
| 14166 |
fractions having some big common factor in the numerator and the denominator. |
| 14167 |
\begin{everbatim*} |
| 14168 |
\xintJrr {\xintiiPow{\xintiiFac {15}}{3}/% |
| 14169 |
\xintiiPrd{{\xintiiFac{10}}{\xintiiFac{30}}{\xintiiFac{5}}}} |
| 14170 |
\end{everbatim*} |
| 14171 |
|
| 14172 |
But to notice the difference one would need computations with much bigger |
| 14173 |
numbers than in this example. As \csbxint{Irr}, \csa{xintJrr} does not remove |
| 14174 |
the trailing |/1| from a fraction reduced to an integer. |
| 14175 |
|
| 14176 |
\subsection{\csh{xintPRaw}}\label{xintPRaw} |
| 14177 |
|
| 14178 |
|PRaw|\etype{\Ff} stands for ``pretty raw''. It does like \csbxint{Raw} apart |
| 14179 |
from removing the |[N]| part if |N=0| and removing the |B| if |B=1|. |
| 14180 |
\begin{everbatim*} |
| 14181 |
\xintPRaw {123e10/321e10}, \xintPRaw {123e9/321e10}, \xintPRaw {\xintIrr{861/123}} |
| 14182 |
\end{everbatim*} |
| 14183 |
|
| 14184 |
\subsection{\csh{xintDecToStringREZ}}\label{xintDecToStringREZ} |
| 14185 |
|
| 14186 |
\csa{xintDecToStringREZ}\etype{\Ff} uses fixed point (decimal) notation |
| 14187 |
for the output. The |REZ| means that it trims (REmoves) trailing Zeros. The name |
| 14188 |
is a bit strange, because it its not limited to |
| 14189 |
\emph{decimal numbers} but accepts the same kind of inputs as most other |
| 14190 |
\xintfracname macros. The parsing of this input transforms it first |
| 14191 |
into an internal format having a numerator |A|, a denominator |B| and a |
| 14192 |
power of ten exponent |N|, standing for the fraction |A/B| times |
| 14193 |
\dtt{10} to the power |N|. Then the following recipe applies: |
| 14194 |
\begin{itemize}[noitemsep] |
| 14195 |
\item the zero value is printed as \dtt{\xintDecToStringREZ{0}} (no decimal point). |
| 14196 |
\item trailing zeros of |A| and |B| are removed and |N| is adjusted, |
| 14197 |
\item if the new |B| is not \dtt{1}, it will appear in the output as |/B|, |
| 14198 |
\item fixed point decimal notation is used for |AeN|: |
| 14199 |
\begin{itemize}[noitemsep] |
| 14200 |
\item if |N| is non-negative, the output is an integer with |N| trailing |
| 14201 |
zeros (and no decimal mark) |
| 14202 |
\item if |N| is negative a decimal point is used, and if |AeN| is less than |
| 14203 |
one in absolute value, output will start with \dtt{0.} (i.e. a decimal mark). |
| 14204 |
\end{itemize} |
| 14205 |
\end{itemize} |
| 14206 |
The following should be noted: |
| 14207 |
\begin{enumerate}[noitemsep] |
| 14208 |
\item the fraction |AeN/B| or even |A/B| is not pre-reduced into lowest terms, |
| 14209 |
\item the macro does not check if |B| contains only powers of \dtt{2} and |
| 14210 |
\dtt{5}, so |1/2| is printed as \dtt{\xintDecToString{1/2}}, not as \dtt{0.5}. |
| 14211 |
\end{enumerate} |
| 14212 |
The definitive behaviour remains to be decided regarding these last two points. |
| 14213 |
\begin{everbatim*} |
| 14214 |
\xintDecToStringREZ{0}, \xintDecToStringREZ{1/2}, \xintDecToStringREZ{0.5000}\newline |
| 14215 |
\xintDecToStringREZ{1.23456789e5}, \xintDecToStringREZ {1.23456789e-3}\newline |
| 14216 |
\xintDecToStringREZ{12345e-1}, \xintDecToStringREZ {12345e-2}, |
| 14217 |
\xintDecToStringREZ{12345e-3}\newline |
| 14218 |
\xintDecToStringREZ{12345e-4}, \xintDecToStringREZ {12345e-5}, |
| 14219 |
\xintDecToStringREZ{12345e-6}\newline |
| 14220 |
\xintDecToStringREZ{1.234567890000e12}, \xintDecToStringREZ{1.23456000e-5/10}\newline |
| 14221 |
\xintDecToStringREZ{70/14} % is not reduced to lowest terms |
| 14222 |
\end{everbatim*} |
| 14223 |
|
| 14224 |
See \csbxint{FloatToDecimal} for a variant which first rounds the input |
| 14225 |
to some given number of significant digits. |
| 14226 |
|
| 14227 |
\subsection{\csh{xintDecToString}}\label{xintDecToString} |
| 14228 |
|
| 14229 |
\csa{xintDecToString}\etype{\Ff} uses fixed point notation for the output. |
| 14230 |
Is behaviour remains |
| 14231 |
somewhat undecided in so far as whether it should identify inputs |
| 14232 |
which correspond to decimal numbers (i.e. fractions with only powers of |
| 14233 |
two and five in their denominator, once reduced to lowest terms). |
| 14234 |
|
| 14235 |
As with \csbxint{DecToStringREZ}, the name is a bit strange as inputs are in no |
| 14236 |
way limited to decimal numbers but are of the most general type accepted by |
| 14237 |
the \xintfracname macros. |
| 14238 |
|
| 14239 |
It is the same macro as \csbxint{DecToStringREZ} except that it does not |
| 14240 |
remove trailing zeros, in fact \csbxint{DecToStringREZ}|{f}| is defined as |
| 14241 |
\csbxint{DecToString}|{|\csbxint{REZ}|{f}}|. |
| 14242 |
|
| 14243 |
\begin{everbatim*} |
| 14244 |
\xintDecToString{0}, \xintDecToString{1/2}, \xintDecToString{0.5000}\newline |
| 14245 |
\xintDecToString{1.23456789e5}, \xintDecToString {1.23456789e-3}\newline |
| 14246 |
\xintDecToString{12345e-1}, \xintDecToString {12345e-2}, \xintDecToString{12345e-3}% |
| 14247 |
\newline |
| 14248 |
\xintDecToString{12345e-4}, \xintDecToString {12345e-5}, \xintDecToString{12345e-6}% |
| 14249 |
\newline |
| 14250 |
\xintDecToString{1.234567890000e12}, \xintDecToString{1.23456000e-5/10}\newline |
| 14251 |
\xintDecToString{70/14} |
| 14252 |
\end{everbatim*} |
| 14253 |
|
| 14254 |
Since |1.4e|, \csbxint{DecToString} is the default for |
| 14255 |
\csbxint{iexprPrintOne}, which governs the \csbxint{ieval} output format: in |
| 14256 |
this use case there is never a |/B| fractional part and the output is always |
| 14257 |
either an integer (if \csbxint{ieval} was used without optional argument) or a |
| 14258 |
decimal string |
| 14259 |
\begin{everbatim} |
| 14260 |
\def\xintiexprPrintOne{\xintDecToString} |
| 14261 |
\end{everbatim} |
| 14262 |
|
| 14263 |
Any replacement of \csbxint{DecToString} as the expansion of |
| 14264 |
\csbxint{iexprPrintOne} should obey the following blueprint: |
| 14265 |
\begin{itemize}[noitemsep] |
| 14266 |
\item to\xtype{} be expandable, but not necessarily \fexpan dable, |
| 14267 |
\item to accept on input |A| or |A[N]|. |
| 14268 |
\end{itemize} |
| 14269 |
|
| 14270 |
\subsection{\csh{xintFracToSci}}\label{xintFracToSci} |
| 14271 |
|
| 14272 |
\csa{xintFracToSci}\etype{\Ff} was initially at |1.4| a private macro |
| 14273 |
which served as default customization of \csbxint{exprPrintOne} and, |
| 14274 |
despite being documented in the user manual, was not supposed to be used |
| 14275 |
at user level (not being \fexpan dable it could not be nested within |
| 14276 |
macros of \xintfracname, and besides accepted a limited range of |
| 14277 |
inputs). |
| 14278 |
|
| 14279 |
It has been upgraded at |1.4l| to behave like all other \xintfracname |
| 14280 |
macros. |
| 14281 |
|
| 14282 |
Here is what it does: |
| 14283 |
\begin{itemize}[noitemsep,nosep] |
| 14284 |
\item it first parses the input like any other \xintfracname macro and |
| 14285 |
convert it into the ``raw'' |A/B[N]| format, |
| 14286 |
\item it then produces this output: |A/B| if |N=0| (and |/B| is omitted |
| 14287 |
if not |1|), and for |N| not zero, the |
| 14288 |
output numerator will be |AeN| written in scientific notation exactly like it |
| 14289 |
would by \csbxint{PFloat} but without of course prior rounding to a |
| 14290 |
given number of digits; the trailing zeros in the |
| 14291 |
significand will be removed always (the \csbxint{PFloatMinTrimmed} |
| 14292 |
configuration is ignored). Then this value in scientific notation (or |
| 14293 |
in decimal fixed point notation if the scientific exponent is in the |
| 14294 |
\csbxint{PFloatNoSciEmin} to \csbxint{PFloatNoSciEmax} range) will be |
| 14295 |
attached to a trailing denominator |/B| (omitted if it is |/1|). |
| 14296 |
\end{itemize} |
| 14297 |
Please note: |
| 14298 |
\begin{itemize} |
| 14299 |
\item there is no reduction of the fraction |A/B| to lowest terms, |
| 14300 |
\item trailing zeros in the integer denominator |B| are not moved and |
| 14301 |
incorporated into the final scientific exponent, |
| 14302 |
\item no attempt is made to check if |B| is a product of only |2|'s and |
| 14303 |
|5|'s and thus could be integrated into some pure decimal notation for |
| 14304 |
the numerator or at least its significand. |
| 14305 |
\end{itemize} |
| 14306 |
Changes of \csbxint{PFloat} at |1.4k| have an impact here. |
| 14307 |
In particular the zero value will give \dtt{0} whether the input was |
| 14308 |
some |0|, |0e-5|, |0/3|, |0.00|, etc\dots, whereas at |1.4e| it would |
| 14309 |
have been \dtt{0.0} for cases triggering some \csbxint{PFloat} |
| 14310 |
subroutine. |
| 14311 |
|
| 14312 |
The general blueprint is still to be considered \emph{unstable}. |
| 14313 |
|
| 14314 |
The output routine of \csbxint{eval} is customizable via redefining |
| 14315 |
\csbxint{exprPrintOne} whose current default is (equivalent to): |
| 14316 |
\begin{everbatim} |
| 14317 |
\def\xintexprPrintOne{\xintFracToSci} |
| 14318 |
\end{everbatim} |
| 14319 |
|
| 14320 |
\subsection{\csh{xintFracToDecimal}} |
| 14321 |
\label{xintFracToDecimal} |
| 14322 |
|
| 14323 |
\csa{xintFracToDecimal}\etype{\Ff} is a variant of \csbxint{FracToSci} which |
| 14324 |
differs from it in so far as it outputs a numerator using decimal notation, |
| 14325 |
i.e. with as many zeros as are needed (and no more) and no scientific |
| 14326 |
exponent. The denominator goes through ``as is'' except if it is |1|, then it |
| 14327 |
is omitted. |
| 14328 |
|
| 14329 |
In other terms its behaviour is currently intermediate between |
| 14330 |
\csbxint{DecToString} and \csbxint{DecToStringREZ}, as it does not |
| 14331 |
remove trailing zeros of the denominator. Consider its behaviour as |
| 14332 |
\emph{unstable}. |
| 14333 |
|
| 14334 |
It can be used to customize \csbxint{exprPrintOne}: |
| 14335 |
\begin{everbatim} |
| 14336 |
\def\xintexprPrintOne{\xintFracToDecimal} |
| 14337 |
\end{everbatim} |
| 14338 |
|
| 14339 |
It was initially at |1.4k| a private macro which served as an alternative to |
| 14340 |
\csb{xintFracToSci} default customization of \csbxint{exprPrintOne} and, |
| 14341 |
despite being documented in the user manual, was not supposed to be used at |
| 14342 |
user level (not being \fexpan dable it could not be nested within macros of |
| 14343 |
\xintfracname, and besides accepted a limited range of inputs). |
| 14344 |
|
| 14345 |
It has been upgraded at |1.4l| to behave like all other \xintfracname |
| 14346 |
macros. |
| 14347 |
|
| 14348 |
|
| 14349 |
\subsection{\csh{xintTrunc}}\label{xintTrunc} |
| 14350 |
|
| 14351 |
\csa{xintTrunc}|{x}{f}|\etype{\numx\Ff} returns the start of the decimal |
| 14352 |
expansion of the fraction |f|, truncated to: |
| 14353 |
\begin{itemize} |
| 14354 |
\item if |x>0|, |x| digits after the decimal mark, |
| 14355 |
\item if |x=0|, an integer, |
| 14356 |
\item if |x<0|, an integer multiple of |10^{-x}| (in scientific notation). |
| 14357 |
\end{itemize} |
| 14358 |
The output is the sole digit token \dtt{0} if and only if the input was exactly |
| 14359 |
zero; else it contains always either a decimal mark (even if |x=0|) or a |
| 14360 |
scientific part and it conserves the sign of |f| (even if the truncated value |
| 14361 |
represents the zero value). |
| 14362 |
|
| 14363 |
Truncation is done towards zero. |
| 14364 |
\begin{everbatim*} |
| 14365 |
\begin{multicols}{2} |
| 14366 |
\noindent\xintFor* #1 in {\xintSeq[-1]{7}{-14}}:{\xintTrunc{#1}{-11e12/7}\newline}% |
| 14367 |
\xintTrunc{10}{1e-11}\newline \xintTrunc{10}{1/65536}\par |
| 14368 |
\end{multicols} |
| 14369 |
\end{everbatim*} |
| 14370 |
|
| 14371 |
\begin{framed} |
| 14372 |
\textbf{Warning:} \emph{it is not yet decided is the current behaviour is |
| 14373 |
definitive.} |
| 14374 |
|
| 14375 |
Currently \xintfracname has no notion of a positive zero or a negative zero. |
| 14376 |
Hence transitivity of \csbxint{Trunc} is broken for the case where the first |
| 14377 |
truncation gives on output \dtt{0.00...0} or \dtt{-0.00...0}: a second |
| 14378 |
truncation to less digits will then output \dtt{0}, whereas if it had been |
| 14379 |
applied directly to the initial input it would have produced \dtt{0.00...0} |
| 14380 |
or respectively \dtt{-0.00...0} (with less zeros after decimal mark). |
| 14381 |
|
| 14382 |
If \xintfracname distinguished zero, positive zero, and |
| 14383 |
negative zero then it would be possible to maintain transitivity. |
| 14384 |
|
| 14385 |
The problem would also be fixed, even without distinguishing a negative zero |
| 14386 |
on input, if \csbxint{Trunc} always produced \dtt{0.00...0} (with no sign) |
| 14387 |
when the mathematical result is zero, discarding the information on original |
| 14388 |
input being positive, zero, or negative. |
| 14389 |
|
| 14390 |
I have multiple times hesitated about what to do and must postpone again |
| 14391 |
final decision. |
| 14392 |
\end{framed} |
| 14393 |
|
| 14394 |
\subsection{\csh{xintXTrunc}}\label{xintXTrunc} |
| 14395 |
|
| 14396 |
|
| 14397 |
\csa{xintXTrunc}|{x}{f}|\xtype{\numx\Ff} is similar to \csbxint{Trunc} with |
| 14398 |
the following important differences: |
| 14399 |
\begin{itemize}[nosep] |
| 14400 |
\item it is completely expandable but not |
| 14401 |
\fexpan dable, as is indicated by the hollow star in the margin, |
| 14402 |
\item hence it can not be used as argument to the other package macros, but as |
| 14403 |
it \fexpan ds its |{f}| argument, it accepts arguments expressed with other |
| 14404 |
\xintfracname macros, |
| 14405 |
\item it requires |x>0|, |
| 14406 |
\item contrarily to \csbxint{Trunc} the number of digits on output is not |
| 14407 |
limited to about \dtt{19950} and may go well beyond \dtt{100000} (this is |
| 14408 |
mainly useful for outputting a decimal expansion to a file), |
| 14409 |
\item when the mathematical result is zero, it always prints it as |
| 14410 |
\dtt{0.00...0} or \dtt{-0.00...0} with |x| zeros after the decimal mark. |
| 14411 |
\end{itemize} |
| 14412 |
|
| 14413 |
\textbf{Warning:} |
| 14414 |
transitivity is broken too (see discussion of \csbxint{Trunc}), due to the |
| 14415 |
sign in the last item. Hence \emph{the definitive policy is yet to be fixed.} |
| 14416 |
|
| 14417 |
Transitivity is here in the sense of using a first |\edef| and then a second |
| 14418 |
one, because it is not possible to nest \csb{xintXTrunc} directly as argument |
| 14419 |
to itself. Besides, although the number of digits on output isn't limited, |
| 14420 |
nevertheless |x| should be less than about |19970| when the number of digits |
| 14421 |
of the input (assuming it is expressed as a decimal number) is even bigger: |
| 14422 |
|\xintXTrunc{30000}{\Z}| after |\edef\Z{\xintXTrunc{60000}{1/66049}| raises an |
| 14423 |
error in contrast with a direct |\xintXTrunc{30000}{1/66049}|. But |
| 14424 |
|\xintXTrunc{30000}{123.456789}| works, because here the number of digits |
| 14425 |
originally present is smaller than what is asked for, thus the routine only |
| 14426 |
has to add trailing zeros, and this has no limitation (apart from \TeX\ main |
| 14427 |
memory). |
| 14428 |
|
| 14429 |
\csbxint{XTrunc} will expand fully in an |\edef| or a |\write| (|\message|, |
| 14430 |
|\wlog|, \dots) or in an \csbxint{expr}-ession, or as list argument to |
| 14431 |
\csbxint{For*}. |
| 14432 |
|
| 14433 |
Here is an example session where the |
| 14434 |
user checks that the decimal expansion of $1/66049=1/257^2$ has the maximal |
| 14435 |
period length $257*256=65792$ (this period length must be a divisor of |
| 14436 |
$\phi(66049)$ and to check it is the maximal one it is enough to show that |
| 14437 |
neither $32896$ nor $256$ are periods.) |
| 14438 |
|
| 14439 |
\begingroup\small |
| 14440 |
\everb|@ |
| 14441 |
$ rlwrap etex -jobname worksheet-66049 |
| 14442 |
This is pdfTeX, Version 3.14159265-2.6-1.40.17 (TeX Live 2016) (preloaded format=etex) |
| 14443 |
restricted \write18 enabled. |
| 14444 |
**xintfrac.sty |
| 14445 |
entering extended mode |
| 14446 |
(/usr/local/texlive/2016/texmf-dist/tex/generic/xint/xintfrac.sty |
| 14447 |
(/usr/local/texlive/2016/texmf-dist/tex/generic/xint/xint.sty |
| 14448 |
(/usr/local/texlive/2016/texmf-dist/tex/generic/xint/xintcore.sty |
| 14449 |
(/usr/local/texlive/2016/texmf-dist/tex/generic/xint/xintkernel.sty)))) |
| 14450 |
*% we load xinttools for \xintKeep, etc... \xintXTrunc itself has no more |
| 14451 |
|
| 14452 |
*% any dependency on xinttools.sty since 1.2i |
| 14453 |
|
| 14454 |
*\input xinttools.sty |
| 14455 |
(/usr/local/texlive/2016/texmf-dist/tex/generic/xint/xinttools.sty) |
| 14456 |
*\def\m#1;{\message{#1}} |
| 14457 |
|
| 14458 |
*\m \the\numexpr 257*257\relax; |
| 14459 |
66049 |
| 14460 |
*\m \the\numexpr 257*256\relax; |
| 14461 |
65792 |
| 14462 |
*% Thus 1/66049 will have a period length dividing 65792. |
| 14463 |
|
| 14464 |
*% Let us first check it is indeed periodical. |
| 14465 |
|
| 14466 |
*\edef\Z{\xintXTrunc{66000}{1/66049}} |
| 14467 |
|
| 14468 |
*% Let's display the first decimal digits. |
| 14469 |
|
| 14470 |
*\m \xintXTrunc{208}{\Z}; |
| 14471 |
|
| 14472 |
0.00001514027464458205271843631243470756559523989765174340262532362337052794137 |
| 14473 |
6856576178291874214598252812306015231116292449545034746930309315810988811337037 |
| 14474 |
6538630410755651107511090251177156353616254598858423 |
| 14475 |
*% let's now fetch the trailing digits |
| 14476 |
|
| 14477 |
*\m \xintKeep{65792-66000}{\Z};% 208 trailing digits |
| 14478 |
|
| 14479 |
0000151402746445820527184363124347075655952398976517434026253236233705279413768 |
| 14480 |
5657617829187421459825281230601523111629244954503474693030931581098881133703765 |
| 14481 |
38630410755651107511090251177156353616254598858423 |
| 14482 |
*% yes they match! we now check that 65792/2 and 65792/257=256 aren't periods. |
| 14483 |
|
| 14484 |
*\m \xintXTrunc{256}{\Z}; |
| 14485 |
|
| 14486 |
0.00001514027464458205271843631243470756559523989765174340262532362337052794137 |
| 14487 |
6856576178291874214598252812306015231116292449545034746930309315810988811337037 |
| 14488 |
6538630410755651107511090251177156353616254598858423291798513225029902042423049 |
| 14489 |
554118911717058547442 |
| 14490 |
*\m \xintXTrunc{256+256}{\Z}; |
| 14491 |
|
| 14492 |
0.00001514027464458205271843631243470756559523989765174340262532362337052794137 |
| 14493 |
6856576178291874214598252812306015231116292449545034746930309315810988811337037 |
| 14494 |
6538630410755651107511090251177156353616254598858423291798513225029902042423049 |
| 14495 |
5541189117170585474420505987978621932201850141561567926842192917379521264515738 |
| 14496 |
3154930430438008145467758785144362518736089872670290239064936637950612424109373 |
| 14497 |
3440324607488379839210283274538600130206361943405653378552286938485064119063119 |
| 14498 |
8049932625777831609865402958409665551333 |
| 14499 |
*% now with 65792/2=32896. Problem: we can't do \xintXTrunc{32896+100}{\Z} |
| 14500 |
|
| 14501 |
*% but only direct \xintXTrunc{32896+100}{1/66049}. Anyway we want to nest it |
| 14502 |
|
| 14503 |
*% hence let's do it all with (slower) \xintKeep, \xintKeepUnbraced. |
| 14504 |
|
| 14505 |
*\m \xintKeep {-100}{\xintKeepUnbraced{2+65792/2+100}{\Z}}; |
| 14506 |
|
| 14507 |
9999848597253554179472815636875652924344047601023482565973746763766294720586231 |
| 14508 |
434238217081257854017 |
| 14509 |
*% This confirms 32896 isn't a period length. |
| 14510 |
|
| 14511 |
*% To conclude let's write the 66000 digits to the log. |
| 14512 |
|
| 14513 |
*\wlog{\Z} |
| 14514 |
|
| 14515 |
*% We want always more digits: |
| 14516 |
|
| 14517 |
*\wlog{\xintXTrunc{150000}{1/66049}} |
| 14518 |
|
| 14519 |
*\bye |
| 14520 |
| |
| 14521 |
\endgroup % $ à cause de fontification de AUCTeX. |
| 14522 |
|
| 14523 |
The acute observer will have noticed that there is something funny when one |
| 14524 |
compares the first digits with those after the middle-period: |
| 14525 |
\begin{everbatim} |
| 14526 |
0000151402746445820527184363124347075655952398976517434026253236233705279413768... |
| 14527 |
9999848597253554179472815636875652924344047601023482565973746763766294720586231... |
| 14528 |
\end{everbatim} |
| 14529 |
Mathematical exercise: can you explain why the two indeed add to |9999...9999|? |
| 14530 |
|
| 14531 |
You can try your hands at this simpler one: |
| 14532 |
\begin{everbatim*} |
| 14533 |
1/49=\xintTrunc{42+5}{1/49}...\newline |
| 14534 |
\xintTrim{2}{\xintTrunc{21}{1/49}}\newline |
| 14535 |
\xintKeep{-21}{\xintTrunc{42}{1/49}} |
| 14536 |
\end{everbatim*} |
| 14537 |
|
| 14538 |
This was again an example of the type |1/N| with |N| the square of a prime. |
| 14539 |
One can also find counter-examples within this class: |1/31^2| and |1/37^2| |
| 14540 |
have an odd period length (|465| and respectively |111|) hence they can not |
| 14541 |
exhibit the symmetry. |
| 14542 |
|
| 14543 |
\begin{framed} |
| 14544 |
Mathematical challenge: prove generally that if the period length of the |
| 14545 |
decimal expansion of |1/p^r| (with |p| a prime distinct from |2| and |5| and |
| 14546 |
|r| a positive exponent) is even, then the previously observed symmetry |
| 14547 |
about the two halves of the period adding to a string of nine's applies. |
| 14548 |
\end{framed} |
| 14549 |
|
| 14550 |
|
| 14551 |
|
| 14552 |
\subsection{\csh{xintTFrac}}\label{xintTFrac} |
| 14553 |
|
| 14554 |
\csa{xintTFrac}|{f}|\etype{\Ff} returns the fractional part, |
| 14555 |
|f=trunc(f)+frac(f)|. Thus if |f<0|, then |-1<frac(f)<=0| and if |f>0| one has |
| 14556 |
|0<= frac(f)<1|. The |T| stands for `Trunc', and there should exist also |
| 14557 |
similar macros associated respectively with `Round', `Floor', and `Ceil', each |
| 14558 |
type of rounding to an integer deserving arguably to be associated with a |
| 14559 |
fractional ``modulo''. By sheer laziness, the package currently implements |
| 14560 |
only the ``modulo'' associated with `Truncation'. Other types of modulo may be |
| 14561 |
obtained more cumbersomely via a combination of the rounding with a subsequent |
| 14562 |
subtraction from |f|. |
| 14563 |
|
| 14564 |
Notice that the result is filtered through \csbxint{REZ}, and will thus be of |
| 14565 |
the form |A/B[N]|, where neither |A| nor |B| has trailing zeros. But the |
| 14566 |
output fraction is not reduced to smallest terms. |
| 14567 |
|
| 14568 |
The function call in expressions (\csbxint{expr}, \csbxint{floatexpr}) is |
| 14569 |
|frac|. Inside |\xintexpr..\relax|, the function |frac| is mapped to |
| 14570 |
\csa{xintTFrac}. Inside |\xintfloatexpr..\relax|, |frac| first applies |
| 14571 |
\csa{xintTFrac} to its argument (which may be an exact fraction with more |
| 14572 |
digits than the floating point precision) and only in a second stage makes the |
| 14573 |
conversion to a floating point number with the precision as set by |\xintDigits| |
| 14574 |
(default is \dtt{16}). |
| 14575 |
\begin{everbatim*} |
| 14576 |
\xintTFrac {1235/97}, \xintTFrac {-1235/97}\newline |
| 14577 |
\xintTFrac {1235.973}, \xintTFrac {-1235.973}\newline |
| 14578 |
\xintTFrac {1.122435727e5}\par |
| 14579 |
\end{everbatim*} |
| 14580 |
|
| 14581 |
\subsection{\csh{xintRound}}\label{xintRound} |
| 14582 |
|
| 14583 |
\csa{xintRound}|{x}{f}|\etype{\numx\Ff} returns the start of the decimal |
| 14584 |
expansion of the fraction |f|, rounded to: |
| 14585 |
\begin{itemize} |
| 14586 |
\item if |x>0|, |x| digits after the decimal mark, |
| 14587 |
\item if |x=0|, an integer, |
| 14588 |
\item if |x<0|, an integer multiple of |10^{-x}| (in scientific notation). |
| 14589 |
\end{itemize} |
| 14590 |
The output is the sole digit token \dtt{0} if and only if the input was |
| 14591 |
exactly zero; else it contains always either a decimal mark (even if |x=0|) or |
| 14592 |
a scientific part and it conserves the sign of |f| (even if the rounded value |
| 14593 |
represents the zero value). |
| 14594 |
\begin{everbatim*} |
| 14595 |
\begin{multicols}{2} |
| 14596 |
\noindent\xintFor* #1 in {\xintSeq[-1]{7}{-14}}:{\xintRound{#1}{-11e12/7}\newline}% |
| 14597 |
\xintRound{10}{1e-11}\newline \xintRound{10}{1/65536}\newline |
| 14598 |
\end{multicols} |
| 14599 |
\end{everbatim*}% |
| 14600 |
Rounding is done with half-way numbers going towards infinity of |
| 14601 |
the same sign. |
| 14602 |
|
| 14603 |
\subsection{\csh{xintFloor}}\label{xintFloor} |
| 14604 |
|
| 14605 |
|\xintFloor {f}|\etype{\Ff} returns the largest relative integer |N| with |
| 14606 |
|N|${}\leqslant{}$|f|. |
| 14607 |
\begin{everbatim*} |
| 14608 |
\xintFloor {-2.13}, \xintFloor {-2}, \xintFloor {2.13} |
| 14609 |
\end{everbatim*} |
| 14610 |
Note the trailing |[0]|, see \csbxint{iFloor} if it is not desired. |
| 14611 |
|
| 14612 |
\subsection{\csh{xintCeil}}\label{xintCeil} |
| 14613 |
|
| 14614 |
|\xintCeil {f}|\etype{\Ff} returns the smallest relative integer |N| with |
| 14615 |
|N|${}>{}$|f|. |
| 14616 |
\begin{everbatim*} |
| 14617 |
\xintCeil {-2.13}, \xintCeil {-2}, \xintCeil {2.13} |
| 14618 |
\end{everbatim*} |
| 14619 |
|
| 14620 |
\subsection{\csh{xintiTrunc}}\label{xintiTrunc} |
| 14621 |
|
| 14622 |
\csa{xintiTrunc}|{x}{f}|\etype{\numx\Ff} returns the integer equal to |10^x| |
| 14623 |
times what \csa{xintTrunc}|{x}{f}| would produce. Attention that leading zeros |
| 14624 |
are automatically removed: the output is in strict integer format. |
| 14625 |
\begin{everbatim*} |
| 14626 |
\begin{multicols}{2} |
| 14627 |
\noindent\xintFor* #1 in {\xintSeq[-1]{7}{-14}}:{\xintiTrunc{#1}{-11e12/7}\newline}% |
| 14628 |
\xintiTrunc{10}{1e-11}\newline \xintiTrunc{10}{1/65536}\par |
| 14629 |
\end{multicols} |
| 14630 |
\end{everbatim*} |
| 14631 |
|
| 14632 |
\subsection{\csh{xintTTrunc}}\label{xintTTrunc} |
| 14633 |
|
| 14634 |
\csa{xintTTrunc}|{f}|\etype{\Ff} truncates to an integer (truncation towards |
| 14635 |
zero). This is the same as |\xintiTrunc {0}{f}| and also the same as |
| 14636 |
\csbxint{Num}. |
| 14637 |
|
| 14638 |
\subsection{\csh{xintiRound}}\label{xintiRound} |
| 14639 |
|
| 14640 |
\csa{xintiRound}|{x}{f}|\etype{\numx\Ff} returns the integer equal to |10^x| |
| 14641 |
times what \csa{xintRound}|{x}{f}| would return. The output has no leading |
| 14642 |
zeroes, it is always in strict integer format. |
| 14643 |
\begin{everbatim*} |
| 14644 |
\begin{multicols}{2} |
| 14645 |
\noindent\xintFor* #1 in {\xintSeq[-1]{7}{-14}}:{\xintiRound{#1}{-11e12/7}\newline}% |
| 14646 |
\xintiRound{10}{1e-11}\newline \xintiRound{10}{1/65536}\par |
| 14647 |
\end{multicols} |
| 14648 |
\end{everbatim*} |
| 14649 |
|
| 14650 |
\subsection{\csh{xintiFloor}}\label{xintiFloor} |
| 14651 |
|
| 14652 |
|\xintiFloor {f}|\etype{\Ff} does the same as \csbxint{Floor} but without the |
| 14653 |
trailing |/1[0]|. |
| 14654 |
\begin{everbatim*} |
| 14655 |
\xintiFloor {-2.13}, \xintiFloor {-2}, \xintiFloor {2.13} |
| 14656 |
\end{everbatim*} |
| 14657 |
|
| 14658 |
\subsection{\csh{xintiCeil}}\label{xintiCeil} |
| 14659 |
|
| 14660 |
|\xintiCeil {f}|\etype{\Ff} does the same as \csbxint{Ceil} but its output is |
| 14661 |
without the |/1[0]|. |
| 14662 |
\begin{everbatim*} |
| 14663 |
\xintiCeil {-2.13}, \xintiCeil {-2}, \xintiCeil {2.13} |
| 14664 |
\end{everbatim*} |
| 14665 |
|
| 14666 |
\subsection{\csh{xintE}}\label{xintE} |
| 14667 |
|
| 14668 |
|\xintE {f}{x}|\etype{\Ff\numx} multiplies the fraction |f| by $10^x$. The |
| 14669 |
\emph{second} argument |x| must obey the \TeX{} bounds. Example: |
| 14670 |
\begin{everbatim*} |
| 14671 |
\count 255 123456789 \xintE {10}{\count 255} |
| 14672 |
\end{everbatim*} |
| 14673 |
Don't feed this example to \csbxint{Num}! |
| 14674 |
|
| 14675 |
\subsection{\csh{xintCmp}}\label{xintCmp} |
| 14676 |
|
| 14677 |
This\etype{\Ff\Ff} compares two fractions |F| and |G| and produces |
| 14678 |
|-1|, |0|, or |1| according to |F<G|, |F=G|, |F>G|. |
| 14679 |
|
| 14680 |
For choosing branches according to the result of comparing |f| and |g|, see |
| 14681 |
\csbxint{ifCmp}. |
| 14682 |
|
| 14683 |
\subsection{\csh{xintEq}}\label{xintEq} |
| 14684 |
|
| 14685 |
|\xintEq{f}{g}|\etype{\Ff\Ff} returns 1 if |f=g|, 0 otherwise. |
| 14686 |
|
| 14687 |
\subsection{\csh{xintNotEq}}\label{xintNotEq} |
| 14688 |
|
| 14689 |
|\xintNotEq{f}{g}|\etype{\Ff\Ff} returns 0 if |f=g|, 1 otherwise. |
| 14690 |
|
| 14691 |
\subsection{\csh{xintGeq}}\label{xintGeq} |
| 14692 |
|
| 14693 |
This\etype{\Ff\Ff} compares the \emph{absolute values} of two |
| 14694 |
fractions. |
| 14695 |
|\xintGeq{f}{g}| outputs |1| if {\catcode`| 12 $|f|\geqslant|g|$} and |0| |
| 14696 |
if not. |
| 14697 |
|
| 14698 |
Important: the macro compares \emph{absolute values}. |
| 14699 |
|
| 14700 |
\subsection{\csh{xintGt}}\label{xintGt} |
| 14701 |
|
| 14702 |
|\xintGt{f}{g}|\etype{\Ff\Ff} returns \dtt{1} if |f|$>$|g|, \dtt{0} otherwise. |
| 14703 |
|
| 14704 |
\subsection{\csh{xintLt}}\label{xintLt} |
| 14705 |
|
| 14706 |
|\xintLt{f}{g}|\etype{\Ff\Ff} returns \dtt{1} if |f|$<$|g|, \dtt{0} otherwise. |
| 14707 |
|
| 14708 |
\subsection{\csh{xintGtorEq}}\label{xintGxstorEq} |
| 14709 |
|
| 14710 |
|\xintGtorEq{f}{g}|\etype{\Ff\Ff} returns \dtt{1} if |f|$\geqslant$|g|, \dtt{0} otherwise. |
| 14711 |
Extended by \xintfracname to fractions. |
| 14712 |
|
| 14713 |
\subsection{\csh{xintLtorEq}}\label{xintLtorEq} |
| 14714 |
|
| 14715 |
|\xintLtorEq{f}{g}|\etype{\Ff\Ff} returns \dtt{1} if |f|$\leqslant$|g|, \dtt{0} otherwise. |
| 14716 |
|
| 14717 |
\subsection{\csh{xintIsZero}}\label{xintIsZero} |
| 14718 |
|
| 14719 |
|\xintIsZero{f}|\etype{f} returns \dtt{1} if |f=0|, \dtt{0} otherwise. |
| 14720 |
|
| 14721 |
\subsection{\csh{xintIsNotZero}}\label{xintIsNotZero} |
| 14722 |
|
| 14723 |
|\xintIsNotZero{f}|\etype{f} returns \dtt{1} if |f!=0|, \dtt{0} otherwise. |
| 14724 |
|
| 14725 |
\subsection{\csh{xintIsOne}}\label{xintIsOne} |
| 14726 |
|
| 14727 |
|\xintIsOne{f}|\etype{f} returns \dtt{1} if |f=1|, \dtt{0} otherwise. |
| 14728 |
|
| 14729 |
\subsection{\csh{xintOdd}}\label{xintOdd} |
| 14730 |
|
| 14731 |
|\xintOdd{f}|\etype{f} returns \dtt{1} if the integer obtained by truncation is |
| 14732 |
odd, and \dtt{0} otherwise. |
| 14733 |
|
| 14734 |
\subsection{\csh{xintEven}}\label{xintEven} |
| 14735 |
|
| 14736 |
|\xintEven{f}|\etype{f} returns \dtt{1} if the integer obtained by truncation is |
| 14737 |
even, and \dtt{0} otherwise. |
| 14738 |
|
| 14739 |
\subsection{\csh{xintifSgn}}\label{xintifSgn} |
| 14740 |
|
| 14741 |
\csh{xintifSgn}\marg{f}\marg{A}\marg{B}\marg{C}\etype{\Ff nnn} executes either the |
| 14742 |
\meta{A}, \meta{B} or \meta{C} code, depending on its first argument being |
| 14743 |
respectively negative, zero, or positive. |
| 14744 |
|
| 14745 |
\subsection{\csh{xintifZero}}\label{xintifZero} |
| 14746 |
|
| 14747 |
\csa{xintifZero}\marg{f}\marg{IsZero}\marg{IsNotZero}\etype{\Ff nn} expandably |
| 14748 |
checks if the first mandatory argument |N| (a number, possibly a fraction if |
| 14749 |
\xintfracname is loaded, or a macro expanding to one such) is zero or not. It |
| 14750 |
then either executes the first or the second branch. |
| 14751 |
|
| 14752 |
Beware that both branches must be present. |
| 14753 |
|
| 14754 |
\subsection{\csh{xintifNotZero}}\label{xintifNotZero} |
| 14755 |
|
| 14756 |
\csa{xintifNotZero}\marg{N}\marg{IsNotZero}\marg{IsZero}\etype{\Ff nn} |
| 14757 |
expandably checks if the first mandatory argument |f| is not |
| 14758 |
zero or is zero. It then either executes the first or the second branch. |
| 14759 |
|
| 14760 |
Beware that both branches must be present. |
| 14761 |
|
| 14762 |
\subsection{\csh{xintifOne}}\label{xintifOne} |
| 14763 |
|
| 14764 |
\csa{xintifOne}\marg{N}\marg{IsOne}\marg{IsNotOne}\etype{\Ff nn} expandably |
| 14765 |
checks if the first mandatory argument |f| is one or not one. It |
| 14766 |
then either executes the first or the second branch. Beware that both branches |
| 14767 |
must be present. |
| 14768 |
|
| 14769 |
\subsection{\csh{xintifOdd}}\label{xintifOdd} |
| 14770 |
|
| 14771 |
\csa{xintifOdd}\marg{N}\marg{odd}\marg{not odd}\etype{\Ff nn} expandably |
| 14772 |
checks if the first mandatory argument |f|, after truncation to an integer, is |
| 14773 |
odd or even. It then executes accordingly the first or the second branch. |
| 14774 |
Beware that both branches must be present. |
| 14775 |
|
| 14776 |
\subsection{\csh{xintifCmp}}\label{xintifCmp} |
| 14777 |
|
| 14778 |
\csa{xintifCmp}\marg{f}\marg{g}\marg{if f<g}\marg{if f=g}\marg{if |
| 14779 |
f>g}\etype{\Ff\Ff nnn} compares its first two arguments and chooses accordingly |
| 14780 |
the correct branch. |
| 14781 |
|
| 14782 |
\subsection{\csh{xintifEq}}\label{xintifEq} |
| 14783 |
|
| 14784 |
\csa{xintifEq}\marg{f}\marg{g}\marg{YES}\marg{NO}\etype{\Ff\Ff nn} checks |
| 14785 |
equality of its two first arguments and executes accordingly the |YES| or the |
| 14786 |
|NO| branch. |
| 14787 |
|
| 14788 |
\subsection{\csh{xintifGt}}\label{xintifGt} |
| 14789 |
|
| 14790 |
\csa{xintifGt}\marg{f}\marg{g}\marg{YES}\marg{NO}\etype{\Ff\Ff nn} |
| 14791 |
checks if $f>g$ and in that case executes the |YES| branch. |
| 14792 |
|
| 14793 |
\subsection{\csh{xintifLt}}\label{xintifLt} |
| 14794 |
|
| 14795 |
\csa{xintifLt}\marg{f}\marg{g}\marg{YES}\marg{NO}\etype{\Ff\Ff nn} |
| 14796 |
checks if $f<g$ and in that case executes the |YES| branch. |
| 14797 |
|
| 14798 |
\subsection{\csh{xintifInt}}\label{xintifInt} |
| 14799 |
|
| 14800 |
\csa{xintifInt}|{f}{YES branch}{NO branch}|\etype{\Ff nn} expandably chooses |
| 14801 |
the |YES| branch if |f| reveals itself after expansion and simplification to |
| 14802 |
be an integer. |
| 14803 |
|
| 14804 |
\subsection{\csh{xintSgn}}\label{xintSgn} |
| 14805 |
|
| 14806 |
The sign of a fraction.\etype{\Ff} |
| 14807 |
|
| 14808 |
\subsection{\csh{xintSignBit}}\label{xintSignBit} |
| 14809 |
|
| 14810 |
Expands to \dtt{1} for negative input, to \dtt{0} else.\etype{\Ff} |
| 14811 |
|
| 14812 |
Added at |1.4l|. |
| 14813 |
|
| 14814 |
\subsection{\csh{xintOpp}}\label{xintOpp} |
| 14815 |
|
| 14816 |
The opposite of a fraction.\etype{\Ff} |
| 14817 |
Note that |\xintOpp {3}| produces \dtt{\xintOpp |
| 14818 |
{3}} whereas |\xintiiOpp {3}| produces \dtt{\xintiiOpp {3}}. |
| 14819 |
|
| 14820 |
\subsection{\csh{xintAbs}}\label{xintAbs} |
| 14821 |
|
| 14822 |
The absolute value\etype{\Ff}. Note that |\xintAbs {-2}|\dtt{=\xintAbs {-2}} |
| 14823 |
where |\xintiiAbs {-2}| outputs \dtt{=\xintiiAbs {-2}}. |
| 14824 |
|
| 14825 |
\subsection{\csh{xintAdd}}\label{xintAdd} |
| 14826 |
|
| 14827 |
Computes the addition\etype{\Ff\Ff} of two fractions. |
| 14828 |
|
| 14829 |
Since |1.3| always uses the least common multiple of the |
| 14830 |
denominators. |
| 14831 |
|
| 14832 |
\subsection{\csh{xintSub}}\label{xintSub} |
| 14833 |
|
| 14834 |
Computes the difference\etype{\Ff\Ff} of two fractions (|\xintSub{F}{G}| |
| 14835 |
computes |F-G|). |
| 14836 |
|
| 14837 |
Since |1.3| always uses the least common multiple of the |
| 14838 |
denominators. |
| 14839 |
|
| 14840 |
\subsection{\csh{xintMul}}\label{xintMul} |
| 14841 |
|
| 14842 |
Computes the product\etype{\Ff\Ff} of two fractions. |
| 14843 |
|
| 14844 |
Output is not reduced to smallest terms. |
| 14845 |
|
| 14846 |
\subsection{\csh{xintDiv}}\label{xintDiv} |
| 14847 |
|
| 14848 |
Computes the quotient \etype{\Ff\Ff} of two fractions. |
| 14849 |
(|\xintDiv{F}{G}| computes |F/G|). |
| 14850 |
|
| 14851 |
Output is not reduced to smallest terms. |
| 14852 |
|
| 14853 |
\subsection{\csh{xintDivFloor}} |
| 14854 |
\label{xintDivFloor} |
| 14855 |
|
| 14856 |
Computes the quotient \etype{\Ff\Ff} of two arguments then apply floor |
| 14857 |
function to get an integer (in strict format). This macro was defined at |1.1| |
| 14858 |
(but was left not documented until |1.3a|...) and changed at |1.2p|, formerly |
| 14859 |
it appended |/1[0]| to output. |
| 14860 |
\begin{everbatim*} |
| 14861 |
\xintDivFloor{-170/3}{23/2} |
| 14862 |
\end{everbatim*} |
| 14863 |
|
| 14864 |
\subsection{\csh{xintMod}} |
| 14865 |
\label{xintMod} |
| 14866 |
|
| 14867 |
Computes the remainder associated to the floored division\etype{\Ff\Ff} |
| 14868 |
\csbxint{DivFloor}. Prior to |1.2p| the meaning was the one of |
| 14869 |
\csbxint{ModTrunc}. Was left undocumented until |1.3a|. |
| 14870 |
\begin{everbatim*} |
| 14871 |
\xintMod{-170/3}{23/2} |
| 14872 |
\end{everbatim*} |
| 14873 |
|
| 14874 |
Modified at |1.3| to use a l.c.m. for the denominator of the result. |
| 14875 |
|
| 14876 |
|
| 14877 |
\subsection{\csh{xintDivMod}} |
| 14878 |
\label{xintDivMod} |
| 14879 |
|
| 14880 |
Computes both the floored division and the remainder\etype{\Ff\Ff} |
| 14881 |
\csbxint{DivFloor}. New at |1.2p| and documented at |1.3a|. |
| 14882 |
\begin{everbatim*} |
| 14883 |
\oodef\foo{\xintDivMod{-170/3}{23/2}}\meaning\foo |
| 14884 |
\end{everbatim*} |
| 14885 |
|
| 14886 |
\subsection{\csh{xintDivTrunc}} |
| 14887 |
\label{xintDivTrunc} |
| 14888 |
|
| 14889 |
Computes the quotient \etype{\Ff\Ff} of two arguments then |
| 14890 |
truncates to an integer (in strict format). |
| 14891 |
\begin{everbatim*} |
| 14892 |
\xintDivTrunc{-170/3}{23/2} |
| 14893 |
\end{everbatim*} |
| 14894 |
|
| 14895 |
\subsection{\csh{xintModTrunc}} |
| 14896 |
\label{xintModTrunc} |
| 14897 |
|
| 14898 |
Computes the remainder\etype{\Ff\Ff} associated with the truncated division of |
| 14899 |
two arguments. Prior to |1.2p| it was named \csbxint{Mod}, but the latter then |
| 14900 |
got associated with floored division. |
| 14901 |
\begin{everbatim*} |
| 14902 |
\xintModTrunc{-170/3}{23/2} |
| 14903 |
\end{everbatim*} |
| 14904 |
|
| 14905 |
Modified at |1.3| to use a l.c.m. for the denominator of the result. |
| 14906 |
|
| 14907 |
|
| 14908 |
\subsection{\csh{xintDivRound}} |
| 14909 |
\label{xintDivRound} |
| 14910 |
|
| 14911 |
Computes the quotient \etype{\Ff\Ff} of the two arguments then rounds to an |
| 14912 |
integer (in strict format). |
| 14913 |
\begin{everbatim*} |
| 14914 |
\xintDivRound{-170/3}{23/2} |
| 14915 |
\end{everbatim*} |
| 14916 |
|
| 14917 |
\subsection{\csh{xintSqr}}\label{xintSqr} |
| 14918 |
|
| 14919 |
Computes the square\etype{\Ff} of one fraction. |
| 14920 |
|
| 14921 |
\subsection{\csh{xintPow}}\label{xintPow} |
| 14922 |
|
| 14923 |
\csa{xintPow}{|{f}{x}|}:\etype{\Ff\Numf} computes |f^x| with |f| a fraction |
| 14924 |
and the exponent |x| possibly also, but if only \xintfracname is loaded it |
| 14925 |
will be truncated to an integer. |
| 14926 |
|
| 14927 |
At |1.4e| the behaviour of the macro is enhanced if |
| 14928 |
\xintexprname is loaded, at it then becomes the support macro for powers |
| 14929 |
|a^b|, |a**b| (and the \func{pow} function) in \csbxint{eval}: it now |
| 14930 |
handles also non-integer exponents. Also, if the exponent is an integer, it |
| 14931 |
checks a priori if an exact evaluation |
| 14932 |
would produce more than about \dtt{10000} digits and then does in its place a |
| 14933 |
floating point evaluation. |
| 14934 |
|
| 14935 |
The check whether the exponent is integer is not on the mathematical value but |
| 14936 |
on the format (for reasons of efficiency). So |4/2| will not be recognized as |
| 14937 |
integer and it will thus trigger usage of the floating point evaluations; |
| 14938 |
however |2.0| will be recognized as an integer, as of course |2|. |
| 14939 |
|
| 14940 |
If the exponent is considered an integer it is then checked if it is less than |
| 14941 |
\dtt{10000} (in absolute value) and if the output would contain less than |
| 14942 |
\dtt{10000} digits (separately for numerator and denominator) and only |
| 14943 |
then is the power computed exactly. Else it is computed as by |
| 14944 |
\csbxint{FloatPower} (but the output uses raw |A[N]| format not scientific |
| 14945 |
notation). Use \csbxint{iiPow} (on integers only, not fractions) for exact |
| 14946 |
powers with larger exponents. |
| 14947 |
|
| 14948 |
Also, a check is done whether the exponent is half-integer. Again this check |
| 14949 |
is not on the value but on the format, so |2.5| is an half integer, as is |
| 14950 |
|25e-1|, or |2.50| but |5/2| is not considered an half-integer (for reasons of |
| 14951 |
internal efficiency). If the exponent is half-integer the power |
| 14952 |
is computed by combining suitably \csbxint{FloatPower} with \csbxint{FloatSqrt} |
| 14953 |
(but the output uses raw |A[N]| format not scientific notation). |
| 14954 |
|
| 14955 |
If the exponent is neither an integer nor an half-integer, the power is |
| 14956 |
computed using logarithm and exponential based approach (and uses raw |A[N]| |
| 14957 |
output format). If |Digits| is at most \dtt{8} (which triggers |
| 14958 |
\ctanpackage{poormanlog} usage, for very fast logarithms but only with about |
| 14959 |
\dtt{8} or \dtt{9} accurate fractional digits) this will start being |
| 14960 |
inaccurate in the last digit already with fractional exponents |x > 10|. It |
| 14961 |
is recommended to split then the exponent into an integer or half-integer part |
| 14962 |
and a fractional part. Powers with integer or half-integer exponents, even |
| 14963 |
very big, are always computed accurately, for any value of |Digits|. |
| 14964 |
|
| 14965 |
% Note: in all cases where the macro has been |
| 14966 |
% extended at |1.4e| to proceed via a floating point evaluation, the output is |
| 14967 |
% in raw |A[N]| format. |
| 14968 |
|
| 14969 |
|
| 14970 |
|
| 14971 |
|
| 14972 |
Within an \csbxint{iiexpr}|..\relax| the infix operators |^| and |**| are |
| 14973 |
mapped to \csbxint{iiPow} and powers are always computed exactly even if they |
| 14974 |
would produce more than \dtt{10000} digits and melt your CPU; within an |
| 14975 |
\csbxint{expr}-ession |^| and |**| are mapped to \csbxint{Pow} as described |
| 14976 |
here. |
| 14977 |
|
| 14978 |
\subsection{\csh{xintFac}}\label{xintFac} |
| 14979 |
|
| 14980 |
This is a convenience variant of \csbxint{iiFac} which applies \csbxint{Num} |
| 14981 |
to its argument\etype{\Numf}. Notice however that the output will have a trailing |
| 14982 |
|[0]| according to the \xintfracname format for integers. |
| 14983 |
|
| 14984 |
\subsection{\csh{xintBinomial}}\label{xintBinomial} |
| 14985 |
|
| 14986 |
This is a convenience variant of \csbxint{iiBinomial} which applies |
| 14987 |
\csbxint{Num} to its arguments\etype{\Numf\Numf}. Notice however that the |
| 14988 |
output will have a trailing |[0]| according to the \xintfracname format for |
| 14989 |
integers. |
| 14990 |
|
| 14991 |
\subsection{\csh{xintPFactorial}}\label{xintPFactorial} |
| 14992 |
|
| 14993 |
This is a convenience variant of \csbxint{iiPFactorial} which applies |
| 14994 |
\csbxint{Num} to its arguments\etype{\Numf\Numf}. Notice however that the |
| 14995 |
output will have a trailing |[0]| according to the \xintfracname format for |
| 14996 |
integers. |
| 14997 |
|
| 14998 |
\subsection{\csh{xintMax}}\label{xintMax} |
| 14999 |
|
| 15000 |
The maximum of two fractions.\etype{\Ff\Ff} Beware that |\xintMax {2}{3}| |
| 15001 |
produces \dtt{\xintMax {2}{3}}. The original, for use with |
| 15002 |
integers only with no need of normalization, is available as \csbxint{iiMax}: |
| 15003 |
|\xintiiMax {2}{3}=|\dtt{\xintiiMax {2}{3}}.\etype{ff} |
| 15004 |
|
| 15005 |
\begin{everbatim*} |
| 15006 |
\xintMax {2.5}{7.2} |
| 15007 |
\end{everbatim*} |
| 15008 |
|
| 15009 |
\subsection{\csh{xintMin}}\label{xintMin} |
| 15010 |
|
| 15011 |
The minimum of two fractions.\etype{\Ff\Ff} Beware that |\xintMin {2}{3}| |
| 15012 |
produces \dtt{\xintMin {2}{3}}. The original, for use with |
| 15013 |
integers only with no need of normalization, is available as \csbxint{iiMin}: |
| 15014 |
|\xintiiMin {2}{3}=|\dtt{\xintiiMin {2}{3}}.\etype{ff} |
| 15015 |
|
| 15016 |
\begin{everbatim*} |
| 15017 |
\xintMin {2.5}{7.2} |
| 15018 |
\end{everbatim*} |
| 15019 |
|
| 15020 |
\subsection{\csh{xintMaxof}}\label{xintMaxof} |
| 15021 |
|
| 15022 |
The maximum of any number of fractions, each within braces, and the whole |
| 15023 |
thing within braces. \etype{f{$\to$}{\lowast\Ff}} |
| 15024 |
|
| 15025 |
\begin{everbatim*} |
| 15026 |
\xintMaxof {{1.23}{1.2299}{1.2301}} and \xintMaxof {{-1.23}{-1.2299}{-1.2301}} |
| 15027 |
\end{everbatim*} |
| 15028 |
|
| 15029 |
\subsection{\csh{xintMinof}}\label{xintMinof} |
| 15030 |
|
| 15031 |
The minimum of any number of fractions, each within braces, and the whole |
| 15032 |
thing within braces. \etype{f{$\to$}{\lowast\Ff}} |
| 15033 |
|
| 15034 |
\begin{everbatim*} |
| 15035 |
\xintMinof {{1.23}{1.2299}{1.2301}} and \xintMinof {{-1.23}{-1.2299}{-1.2301}} |
| 15036 |
\end{everbatim*} |
| 15037 |
|
| 15038 |
\subsection{\csh{xintSum}}\label{xintSum} |
| 15039 |
|
| 15040 |
This\etype{f{$\to$}{\lowast\Ff}} computes the sum of fractions. The output |
| 15041 |
will now always be in the form |A/B[n]|. The original, for big integers only |
| 15042 |
(in strict format), is available as \csa{xintiiSum}. |
| 15043 |
|
| 15044 |
\begin{everbatim*} |
| 15045 |
\xintSum {{1282/2196921}{-281710/291927}{4028/28612}} |
| 15046 |
\end{everbatim*} |
| 15047 |
|
| 15048 |
No simplification attempted. |
| 15049 |
|
| 15050 |
\subsection{\csh{xintPrd}}\label{xintPrd} |
| 15051 |
|
| 15052 |
TThis\etype{f{$\to$}{\lowast\Ff}} computes the product of fractions. The output |
| 15053 |
will now always be in the form |A/B[n]|. The original, for big integers only |
| 15054 |
(in strict format), is available as \csa{xintiiPrd}. |
| 15055 |
|
| 15056 |
\begin{everbatim*} |
| 15057 |
\xintPrd {{1282/2196921}{-281710/291927}{4028/28612}} |
| 15058 |
\end{everbatim*} |
| 15059 |
|
| 15060 |
No simplification attempted. |
| 15061 |
|
| 15062 |
\begin{everbatim*} |
| 15063 |
$\xintIsOne {21921379213/21921379213}\neq |
| 15064 |
\xintIsOne {1.00000000000000000000000000000001}$ |
| 15065 |
\end{everbatim*} |
| 15066 |
|
| 15067 |
\subsection{\csh{xintGCD}}\label{xintGCD} |
| 15068 |
|
| 15069 |
The greatest common divisor of its two arguments, which are possibly |
| 15070 |
\emph{fractions}.\etype{\Ff\Ff} |
| 15071 |
|
| 15072 |
Prior to |1.4| a macro of the same name existed in \xintgcdname. But |
| 15073 |
it truncated its two arguments to integers via \csbxint{Num}. |
| 15074 |
|
| 15075 |
See \csbxint{iiGCD} for the integer only variant. |
| 15076 |
|
| 15077 |
\subsection{\csh{xintLCM}}\label{xintLCM} |
| 15078 |
|
| 15079 |
The least common multiple of its two arguments, which are possibly |
| 15080 |
\emph{fractions}.\etype{\Ff\Ff} |
| 15081 |
|
| 15082 |
Prior to |1.4| a macro of the same name existed in \xintgcdname. But |
| 15083 |
it truncated its two arguments to integers via \csbxint{Num}. |
| 15084 |
|
| 15085 |
See \csbxint{iiLCM} for the integer only variant. |
| 15086 |
|
| 15087 |
\subsection{\csh{xintGCDof}}\label{xintGCDof} |
| 15088 |
|
| 15089 |
\csa{xintGCDof}|{{a}{b}{c}...}|\etype{f{$\to$}{\lowast\Ff}} computes the |
| 15090 |
greatest common divisor of |a|, |b|, \dots{}. The arguments are allowed to be |
| 15091 |
\emph{fractions}: the macro produces the non-negative generator of the |
| 15092 |
fractional ideal they generate. The list argument may be a macro as it is |
| 15093 |
\fexpan ded first. If all arguments vanish, then also the output. |
| 15094 |
|
| 15095 |
Prior to |1.4| a macro of the same name existed in \xintgcdname. But |
| 15096 |
it truncated all its arguments to integers via \csbxint{Num} and then |
| 15097 |
proceeded with integer only computations. |
| 15098 |
|
| 15099 |
See \csbxint{iiGCDof} for the integer only variant. |
| 15100 |
|
| 15101 |
% Semble encore vrai à 1.4d |
| 15102 |
% Mais je n'ai testé que sur un exemple... |
| 15103 |
% (which is about |6X| faster than this one for integer arguments). |
| 15104 |
|
| 15105 |
\subsection{\csh{xintLCMof}}\label{xintLCMof} |
| 15106 |
|
| 15107 |
\csa{xintLCMof}|{{a}{b}{c}...}|\etype{f{$\to$}{\lowast\Ff}} computes the least |
| 15108 |
common multiple of |a|, |b|, \dots{}. The arguments are allowed to be |
| 15109 |
\emph{fractions}: the macro produces the non-negative generator of the |
| 15110 |
intersection of the corresponding fractional ideals. The list argument may be |
| 15111 |
a macro, it is \fexpan ded first. If one of the item vanishes, then also the |
| 15112 |
output. |
| 15113 |
|
| 15114 |
Prior to |1.4| a macro of the same name existed in \xintgcdname. But |
| 15115 |
it truncated all its arguments to integers via \csbxint{Num}. |
| 15116 |
|
| 15117 |
See \csbxint{iiLCMof} for the integer only variant. |
| 15118 |
|
| 15119 |
% Avant 1.4d on avait ceci : |
| 15120 |
% (which is about |9X| faster han this one for integer arguments). |
| 15121 |
% mais à 1.4d le lcm des fractions est environ 4X fois plus efficace, |
| 15122 |
% en ce qui concerne son emploi avec des entiers (testé sur un seul exemple) |
| 15123 |
% donc le gain de faire \xintiiexpr n'est plus que 2X ! |
| 15124 |
|
| 15125 |
\subsection{\csh{xintDigits}, \csh{xinttheDigits}} |
| 15126 |
\label{xintDigits} |
| 15127 |
\label{xinttheDigits} |
| 15128 |
|
| 15129 |
The syntax |\xintDigits := N;| or (recommended) |\xintDigits := N\relax| |
| 15130 |
assigns the value of |N| to the number of digits to be used by floating |
| 15131 |
point operations (this uses internally a |\mathchardef| assignement, and |
| 15132 |
|N| stands for (or expands to) a legal \TeX\ number). The default is |
| 15133 |
|16|. The maximal value is |32767|. |
| 15134 |
|
| 15135 |
Accepted syntax includes also |\xintDigits = N;| or |\xintDigits = |
| 15136 |
N\relax|, i.e.\@{} the colon before the equality sign is optional. |
| 15137 |
% |
| 15138 |
\begin{framed} |
| 15139 |
\xintexprname adds\IMPORTANTf{} the variant \csbxint{Digits*} which executes |
| 15140 |
\csbxint{reloadxinttrig} and \csbxint{reloadxintlog}. |
| 15141 |
|
| 15142 |
A priori, you want \csbxint{Digits*}|:=N\relax|. Use |
| 15143 |
|\xintDigits:=N\relax| only if not needing trigonometric or |
| 15144 |
logarithm/exponential functions and wanting to avoid the overhead of |
| 15145 |
reloading their librairies. Perhaps for a local temporary |
| 15146 |
configuration. |
| 15147 |
\end{framed} |
| 15148 |
|
| 15149 |
Spaces do not matter as long as they do not occur in-between digits: |
| 15150 |
\begin{everbatim*} |
| 15151 |
\xintDigits := 24\relax\xinttheDigits, % |
| 15152 |
\xintDigits:=36 \relax\xinttheDigits, % |
| 15153 |
\xintDigits:= 16 \relax and \xinttheDigits. |
| 15154 |
\end{everbatim*} |
| 15155 |
As shown above |\xinttheDigits|\etype{} expands to the stored value. |
| 15156 |
|
| 15157 |
|
| 15158 |
% It has always been the case that an active colon |:| was allowed. |
| 15159 |
|
| 15160 |
An ending active semi-colon |;| is \emph{not} compatible: it can and |
| 15161 |
will cause low-level \TeX{} errors. This is why the alternative syntax |
| 15162 |
\begin{everbatim} |
| 15163 |
\xintDigits:= N\relax |
| 15164 |
\end{everbatim} |
| 15165 |
is recommended (with or without the semi-colon). This is hopefully the |
| 15166 |
syntax now in use in most examples from the documentation. |
| 15167 |
|
| 15168 |
|
| 15169 |
% This |
| 15170 |
% restriction always applied, but never got properly documented prior to |
| 15171 |
% |1.3f| release... It is possible to use |\string;| but then there can not be |
| 15172 |
% any space separating it from the digits. |
| 15173 |
|
| 15174 |
Actually, any non-expanding token can be used in place of the |
| 15175 |
|\relax|. This non-expanding ending token (for example a full stop) will |
| 15176 |
get removed from the token stream. |
| 15177 |
\begin{everbatim*} |
| 15178 |
\xintDigits = 24\def\xinttheDigits, % only for showing it works! don't do that! |
| 15179 |
\xintDigits := 36.\xinttheDigits, % one can use a dot in place of semi-colon |
| 15180 |
\xintDigits = 16\relax and \xinttheDigits.\par % with \relax, even better |
| 15181 |
\end{everbatim*} |
| 15182 |
|
| 15183 |
\subsection{\csh{xintSetDigits}} |
| 15184 |
\label{xintSetDigits} |
| 15185 |
|
| 15186 |
To be used as |\xintSetDigits|\marg{expression}\ntype{\numx} where the |
| 15187 |
expression will be fed to |\numexpr|. It is a shortcut for doing |
| 15188 |
|\xintDigits := \numexpr|\meta{expression}|\relax \relax|. |
| 15189 |
\begin{everbatim*} |
| 15190 |
\xintSetDigits{1+2+3+4+5}The value is now \xinttheDigits. |
| 15191 |
\xintSetDigits{2*8}The value is now \xinttheDigits.\par |
| 15192 |
\end{everbatim*} |
| 15193 |
\begin{framed} |
| 15194 |
The \xintexprname-added variant \csbxint{SetDigits*} is |
| 15195 |
the preferred usage as it does the extra work to update the math |
| 15196 |
functions from \xinttrigname and \xintlogname. |
| 15197 |
\end{framed} |
| 15198 |
|
| 15199 |
\subsection{\csh{xintFloat}} |
| 15200 |
\label{xintFloat} |
| 15201 |
\label{xintFloatZero} |
| 15202 |
|
| 15203 |
|
| 15204 |
The macro |\xintFloat [P]{f}|\etype{{\upshape[\numx]}\Ff} has an optional |
| 15205 |
argument |P| which replaces the current value of |\xinttheDigits|. The |
| 15206 |
fraction |f| is then printed in scientific notation with a rounding to |P| digits. |
| 15207 |
|
| 15208 |
That is, on output: the first digit is from |1| to |9|, it is possibly |
| 15209 |
prefixed by a minus sign and is followed by a dot and |P-1| digits, then a |
| 15210 |
lower case |e| and an exponent |N|. The trailing zeroes are not trimmed. |
| 15211 |
|
| 15212 |
\begin{framed} |
| 15213 |
There is one exception to the general description: the zero value, which |
| 15214 |
gets output as \dtt{\xintFloat{0}}. This was changed at |
| 15215 |
|1.4k|, until then it was using \dtt{0.e0} as output. Customize via |
| 15216 |
\csh{xintFloatZero} whose default definition is: |
| 15217 |
\begin{everbatim} |
| 15218 |
\def\xintFloatZero{0.0e0} |
| 15219 |
\end{everbatim} |
| 15220 |
\end{framed} |
| 15221 |
|
| 15222 |
Starting with |1.2k|, when the input is a fraction |AeN/BeM| |
| 15223 |
the output always is the \emph{correct rounding} to |P| digits. Formerly, this |
| 15224 |
was guaranteed only when |A| and |B| had at most |P+2| digits, or when |B| was |
| 15225 |
|1| and |A| was arbitrary, but in other cases it was only guaranteed that the |
| 15226 |
difference between the original fraction and the rounding was at most |
| 15227 |
\dtt{0.6} unit in the last place (of the output), hence the output could |
| 15228 |
differ in the last digit (and earlier ones in case of chains of zeros or |
| 15229 |
nines) from the correct rounding. |
| 15230 |
|
| 15231 |
Also: for releases |1.2j| and earlier, in the special case when |
| 15232 |
|A/B| ended up being rounded up to the next power of ten, the output was with |
| 15233 |
a mantissa of the shape |10.0...0eN|. However, this worked only for |B=1| or |
| 15234 |
when both |A| and |B| had at most |P+2| digits, because the detection of the |
| 15235 |
rounding-up to next power of ten was done not on original |A/B| but on an |
| 15236 |
approximation |A'/B'|, and it could happen that |A'/B'| was itself being |
| 15237 |
rounded \emph{down} to a power of ten which however was a rounding \emph{up} |
| 15238 |
of original |A/B|. With the |1.2j| refactoring which achieves correct rounding |
| 15239 |
in all cases, it was decided not to add to the code the extra overhead of |
| 15240 |
detecting with 100\% fiability the rounding up to next power of ten (such |
| 15241 |
overhead would necessitate alterations of the algorithm and as a result we |
| 15242 |
would end up with a slightly less efficient one; it would make sense in a |
| 15243 |
model where inputs have their intrinsic precisions which is obeyed by the |
| 15244 |
implementation of the basic operations, but currently the design decision for |
| 15245 |
the floating point macros is that when the target precision is |P| the inputs |
| 15246 |
are rounded first to |P| digits before further processing.) |
| 15247 |
\begin{everbatim*} |
| 15248 |
{\def\x{99999999999999994999999999999999/99999999999999999999999999999999}% |
| 15249 |
\xintFor #1 in {13, 14, 15, 16, 17, 18, 19, 47, 48, 49, 50, 79, 80, 81} |
| 15250 |
\do{#1: \xintFloat[#1]{\x}\xintifForLast{\par}{\newline}}}% |
| 15251 |
\end{everbatim*} |
| 15252 |
As an aside, which is illustrated by the above, rounding is not |
| 15253 |
transitive in the number of kept digits. |
| 15254 |
\begin{everbatim*} |
| 15255 |
{\def\x{137893789173289739179317/13890138013801398}% |
| 15256 |
\xintFor* #1 in {\xintSeq{4}{20}} |
| 15257 |
\do{#1: \xintFloat[#1]{\x}\newline}}% |
| 15258 |
\xintFloat{5/9999999999999999}\newline |
| 15259 |
\xintFloat[32]{5/9999999999999999}\newline |
| 15260 |
\xintFloat[48]{5/9999999999999999}\par |
| 15261 |
\end{everbatim*} |
| 15262 |
|
| 15263 |
|
| 15264 |
|
| 15265 |
\subsection{\csh{xintFloatBraced}} |
| 15266 |
\label{xintFloatBraced} |
| 15267 |
|
| 15268 |
The experimental macro |
| 15269 |
|\xintFloatBraced[P]{f}|\etype{{\upshape[\numx]}\Ff} does like |
| 15270 |
\csbxint{Float} but its output consists of three \TeX-braced groups |
| 15271 |
\centeredline{\marg{sign bit}\marg{scientific exponent}\marg{full width |
| 15272 |
mantissa with decimal point}} It is provided for users |
| 15273 |
knowing how to pick one or the other of these constituents from usage |
| 15274 |
of auxiliary macros. Or one can use \csbxint{Assign}: |
| 15275 |
\begin{everbatim*} |
| 15276 |
\begingroup |
| 15277 |
\xintAssign\xintFloatBraced[7]{-3.1234e-14}\to\A\B\C |
| 15278 |
\string\A\ has meaning \meaning\A\newline |
| 15279 |
\string\B\ has meaning \meaning\B\newline |
| 15280 |
\string\C\ has meaning \meaning\C\par |
| 15281 |
\endgroup |
| 15282 |
\end{everbatim*} |
| 15283 |
Some aspects are undecided: |
| 15284 |
\begin{itemize}[noitemsep] |
| 15285 |
\item should the first item be rather |-1|, |0|, or |1|? or |-|, nothing, nothing? |
| 15286 |
\item in case of zero value the output ignores \csbxint{FloatZero}, it |
| 15287 |
uses a zero exponent and full width fractional mantissa \dtt{\csname |
| 15288 |
xint_gobble_ii\expandafter\endcsname\romannumeral0\xintfloatbraced{0}} |
| 15289 |
(here no |[P]| and \csbxint{theDigits} has value |
| 15290 |
\dtt{\xinttheDigits}), should it be otherwise? |
| 15291 |
\item should the mantissa be without the decimal separator ? should it |
| 15292 |
incorporate the sign ? |
| 15293 |
\item in case the mantissa is without separator, should the exponent be biased to match it? |
| 15294 |
\end{itemize} |
| 15295 |
|
| 15296 |
\subsection{\csh{xintFloatToDecimal}} |
| 15297 |
\label{xintFloatToDecimal} |
| 15298 |
|
| 15299 |
|\xintFloatToDecimal [P]{f}|\etype{{\upshape[\numx]}\Ff} does float rounding |
| 15300 |
on input like \csbxint{Float} then outputs the number using decimal notation, |
| 15301 |
i.e. with as many zeros as are needed (and no more) and no scientific |
| 15302 |
exponent. |
| 15303 |
|
| 15304 |
In other terms it behaves (and is essentially defined) as: |
| 15305 |
\begin{everbatim} |
| 15306 |
\xintDecToStringREZ{\xintFloat[optional P]{<input>}} |
| 15307 |
\end{everbatim} |
| 15308 |
Examples: |
| 15309 |
\begin{everbatim*} |
| 15310 |
\xintFloatToDecimal{6.02e23}\newline |
| 15311 |
\xintFloatToDecimal{6.02000000000000e23}\newline |
| 15312 |
\xintFloatToDecimal[20]{1/7e10}\newline |
| 15313 |
\xintFloatToDecimal[30]{1/7e10} |
| 15314 |
\end{everbatim*} |
| 15315 |
|
| 15316 |
See \csbxint{DecToString}. |
| 15317 |
|
| 15318 |
\subsection{\csh{xintPFloat}} |
| 15319 |
\label{xintPFloat} |
| 15320 |
|
| 15321 |
|\xintPFloat [P]{f}|\etype{{\upshape[\numx]}\Ff} is like \csbxint{Float} but |
| 15322 |
``pretty-prints'' the output. |
| 15323 |
|
| 15324 |
This macro was initially added at |1.1| as a (very primitive) "prettifying |
| 15325 |
printer" for floating point number, and was then somewhat influenced by Maple, |
| 15326 |
for example the zero value was printed as "\dtt{0.}". Then at |1.4e| there was |
| 15327 |
breaking change and the rules became somewhat similar to observed Python |
| 15328 |
behaviour: mantissas trimmed of trailing zeros (whether or not scientific |
| 15329 |
notation was used in the output) and integers printed with a trailing |
| 15330 |
"\dtt{.0}", in particular the zero value was printed as "\dtt{0.0}". |
| 15331 |
|
| 15332 |
|1.4k| brought some breaking changes, which are reversible |
| 15333 |
via customizing macros: |
| 15334 |
\begin{itemize} |
| 15335 |
\item Integers (when scientific notation is dropped according to |
| 15336 |
criteria mentioned next) without a "\dtt{.0}" |
| 15337 |
suffix. |
| 15338 |
\item Same for the zero value, now "\dtt{\xintPFloat{0}}". |
| 15339 |
\item Significands are trimmed of trailing zeros only if that removes at least |
| 15340 |
\dtt{4} zeros. The rationale is that automatic removal of trailing zeros |
| 15341 |
(which was influenced at |1.4e| from practice with Python in interactive |
| 15342 |
mode) proves annoying visually with aligned values in tables, as this |
| 15343 |
creates voids, so we want to do this only when really the |
| 15344 |
presence of trailing zeros is not some kind of numerical fluke. |
| 15345 |
\end{itemize} |
| 15346 |
These changes impact the \csbxint{floateval} output as |
| 15347 |
\csbxint{floatexprPrintOne} defaults to using \csbxint{PFloat}. |
| 15348 |
|
| 15349 |
\begin{framed} |
| 15350 |
In\IMPORTANTf\ this documentation ``trailing zeros'' refers not to how |
| 15351 |
the input looked like, but |
| 15352 |
to the corresponding mantissa of width |P| or \csbxint{theDigits}. |
| 15353 |
\end{framed} |
| 15354 |
|
| 15355 |
|
| 15356 |
The default rules are thus now: |
| 15357 |
\begin{enumerate}[nolistsep] |
| 15358 |
\item The input is float-rounded to either |Digits| or the optional argument. |
| 15359 |
\item zero is printed as \dtt{\xintPFloat{0}}. |
| 15360 |
\item \dtt{x.yz...eN} is printed in decimal fixed point if |
| 15361 |
$-4\leq\text{|N|}\leq+5$ else it is printed in scientific notation. |
| 15362 |
\item Trailing zeros of the mantissa are trimmed if, and only if there are at least \dtt{4} |
| 15363 |
of them. |
| 15364 |
\item In case of fixed point output format, and the value is an integer, the |
| 15365 |
integer is printed with no decimal mark. |
| 15366 |
\item In case of scientific notation output format, and the mantissa has only |
| 15367 |
one digit, no decimal mark is used. |
| 15368 |
\end{enumerate} |
| 15369 |
|
| 15370 |
% The old rules were: |
| 15371 |
% \begin{enumerate}[nosep] |
| 15372 |
% \item The input is float-rounded to either |Digits| or the optional argument, |
| 15373 |
% \item zero is printed as \dtt{0.}, |
| 15374 |
% \item \dtt{x.yz...eN} is printed ``as is'' if the exponent |N| is at least |
| 15375 |
% \dtt{6} or at most \dtt{-6}, |
| 15376 |
% \item else fixed point decimal notation is used, |
| 15377 |
% \item and there is no trimming of trailing zeroes. |
| 15378 |
% \end{enumerate} |
| 15379 |
|
| 15380 |
\begingroup\color{everbatimxfgcolor} |
| 15381 |
\begin{multicols}2 |
| 15382 |
\def\test #1{\item #1${}\to{}$\xintPFloat{#1}}% |
| 15383 |
\string\xintDigits\ at \xinttheDigits |
| 15384 |
\begin{itemize}[nosep,font=\normalcolor] |
| 15385 |
\test {0} |
| 15386 |
\test {1.2340000e-7}\test {1.2340000e-6}\test {1.2340000e-5}\test {1.2340000e-4} |
| 15387 |
\test {1.2340000e-3}\test {1.2340000e-2}\test {1.2340000e-1} |
| 15388 |
\test {1.2340000e0}\test {1.2340000e1}\test {1.2340000e2}\test {1.2340000e3} |
| 15389 |
\test {1.2340000e4}\test {1.2340000e5}\test {1.2340000e6}\test {1.2340000e7} |
| 15390 |
\test {1e-7/7}\test {1e-6/7}\test {1e-5/7}\test {1e-4/7} |
| 15391 |
\test {1e-3/7}\test {1e-2/7}\test {1e-1/7} |
| 15392 |
\test {1e0/7}\test {1e1/7}\test {1e2/7}\test {1e3/7} |
| 15393 |
\test {1e4/7}\test {1e5/7}\test {1e6/7}\test {1e7/7} |
| 15394 |
\end{itemize} |
| 15395 |
\end{multicols} |
| 15396 |
\endgroup |
| 15397 |
|
| 15398 |
\subsubsection{Customizing macros of \csh{xintPFloat}} |
| 15399 |
\label{xintPFloatE} |
| 15400 |
\label{xintPFloatZero} |
| 15401 |
\label{xintPFloatIntSuffix} |
| 15402 |
\label{xintPFloatLengthOneSuffix} |
| 15403 |
\label{xintPFloatNoSciEmin} |
| 15404 |
\label{xintPFloatNoSciEmax} |
| 15405 |
\label{xintPFloatMinTrimmed} |
| 15406 |
|
| 15407 |
A number of macros allow to customize the behaviour of \csbxint{PFloat}: |
| 15408 |
\begin{itemize} |
| 15409 |
\item \csa{xintPFloatE} allows to modify the separator of the |
| 15410 |
scientific notation. Here is its default: |
| 15411 |
% |
| 15412 |
\footnote{For \TeX perts: it is allowed to define |
| 15413 |
\csa{xintPFloatE} as a macro which grabs the exponent as an argument |
| 15414 |
delimited by a dot, and produces \fexpan dably an output also delimited by |
| 15415 |
a dot (it will removed via further internal processing).} |
| 15416 |
% |
| 15417 |
\begin{everbatim} |
| 15418 |
\def\xintPFloatE{e} |
| 15419 |
\end{everbatim} |
| 15420 |
|
| 15421 |
\item \csa{xintPFloatZero} says how to print the zero value. |
| 15422 |
The default: |
| 15423 |
\begin{everbatim} |
| 15424 |
\def\xintPFloatZero{0} |
| 15425 |
\end{everbatim} |
| 15426 |
|
| 15427 |
\item \csa{xintPFloatIntSuffix} is postfixed to integer values |
| 15428 |
(when scientific notation is not used). Its default at |1.4k| is to add |
| 15429 |
nothing. It replaces the formerly hard-coded "\dtt{.0}" from |1.4e| (prior |
| 15430 |
to that trailing zeros from the full significand of |P| or |
| 15431 |
\csbxint{theDigits} digits were not trimmed). |
| 15432 |
\begin{everbatim} |
| 15433 |
\def\xintPFloatIntSuffix{} |
| 15434 |
\end{everbatim} |
| 15435 |
|
| 15436 |
\item \csa{xintPFloatLengthOneSuffix} is postfixed to trimmed |
| 15437 |
mantissas having only one digit, when scientific notation is used. Its |
| 15438 |
default at |1.4k| is to add nothing. It replaces formerly hard-coded |
| 15439 |
"\dtt{.0}". |
| 15440 |
\begin{everbatim} |
| 15441 |
\def\xintPFloatLengthOneSuffix{} |
| 15442 |
\end{everbatim} |
| 15443 |
|
| 15444 |
\item \csa{xintPFloatNoSciEmax} is the maximal scientific exponent |
| 15445 |
which will trigger use of decimal fixed point notation and |
| 15446 |
\csa{xintPFloatNoSciEmin} is the minimal one. Their defaults at |1.4k| are the |
| 15447 |
same as the formerly hard-coded behaviour from |1.4e|: |
| 15448 |
\begin{everbatim} |
| 15449 |
\def\xintPFloatNoSciEmax{5} |
| 15450 |
\def\xintPFloatNoSciEmin{-4} |
| 15451 |
\end{everbatim} |
| 15452 |
For example (with the package default width of \dtt{16} digits for mantissas |
| 15453 |
of floating point numbers): |
| 15454 |
\begin{everbatim*} |
| 15455 |
\begingroup |
| 15456 |
\def\xintPFloatNoSciEmin{-20} |
| 15457 |
\xintPFloat{1e-19/7}\newline |
| 15458 |
\xintPFloat{1e-20/7}\par |
| 15459 |
\def\xintPFloatNoSciEmax{19} |
| 15460 |
\xintPFloat{1e20/7}\newline |
| 15461 |
\xintPFloat{1e21/7}\par |
| 15462 |
\endgroup |
| 15463 |
\end{everbatim*} |
| 15464 |
|
| 15465 |
\item \csa{xintPFloatMinTrimmed} is the minimal number |
| 15466 |
of trailing zeros which have to be present to activate actual trimming. |
| 15467 |
The default definition is: |
| 15468 |
\begin{everbatim} |
| 15469 |
\def\xintPFloatMinTrimmed{4} |
| 15470 |
\end{everbatim} |
| 15471 |
Defining it to expand to \dtt{-1} or \dtt{0} will enable the trimming of |
| 15472 |
trailing zeros always, and setting it to a value at least equal to |P| |
| 15473 |
(or \csbxint{theDigits} if no |[P]|) will prevent it |
| 15474 |
altogether. |
| 15475 |
|
| 15476 |
This setting is ignored for the case of an integer value, if the |
| 15477 |
criteria for using fixed point notation are met, and for the case of a |
| 15478 |
one-digit mantissa in scientific notation. |
| 15479 |
|
| 15480 |
\end{itemize} |
| 15481 |
|
| 15482 |
To mimick approximately the Python behaviour in interactive sessions, |
| 15483 |
one can use the following configuration: |
| 15484 |
\begin{everbatim} |
| 15485 |
\def\xintPFloatZero{0.0}% |
| 15486 |
\def\xintPFloatIntSuffix{.0}% |
| 15487 |
\def\xintPFloatLengthOneSuffix{.0}% |
| 15488 |
\def\xintPFloatNoSciEmax{15}% |
| 15489 |
\def\xintPFloatNoSciEmin{-4}% |
| 15490 |
\def\xintPFloatMinTrimmed{-1}% |
| 15491 |
\end{everbatim} |
| 15492 |
\begingroup\color{everbatimxfgcolor} |
| 15493 |
\def\xintPFloatZero{0.0}% |
| 15494 |
\def\xintPFloatIntSuffix{.0}% |
| 15495 |
\def\xintPFloatLengthOneSuffix{.0}% |
| 15496 |
\def\xintPFloatNoSciEmax{15}% |
| 15497 |
\def\xintPFloatNoSciEmin{-4}% |
| 15498 |
\def\xintPFloatMinTrimmed{-1}% |
| 15499 |
\def\test#1{#1${}\to{}$\xintPFloat{#1}\newline}% |
| 15500 |
\test{0.} |
| 15501 |
\test{1234.} |
| 15502 |
\test{6e100} |
| 15503 |
\test{1234567812345678.12345678} |
| 15504 |
\test{12345678123456781.2345678} |
| 15505 |
\test{12345678.12340} |
| 15506 |
\test{12345678.123400} |
| 15507 |
\test{0.1234567812345678} |
| 15508 |
\test{0.00012345678123456785} |
| 15509 |
\test{0.000012345678123456785}\par |
| 15510 |
\endgroup |
| 15511 |
% |
| 15512 |
The above using the default \csbxint{Digits} setting of \dtt{16} digits. |
| 15513 |
This can not naturally match exactly CPython which uses internally radix |
| 15514 |
|2| not |10|, and has (by default) mantissas with \dtt{53=1+52} bits. |
| 15515 |
|
| 15516 |
Same, but playing with \ctanpackage{xintsession} in its |&fp| mode: |
| 15517 |
\begin{everbatim} |
| 15518 |
>>> &fp |
| 15519 |
fp mode (16 digits) |
| 15520 |
>>> \\def\xintPFloatZero{0.0} |
| 15521 |
(executing \\def\xintPFloatZero {0.0} in background) |
| 15522 |
) |
| 15523 |
Runaway argument? |
| 15524 |
def\xintPFloatZero {0.0}\message { |
| 15525 |
}\xs_fetch_aa \endinput |
| 15526 |
! File ended while scanning use of \\. |
| 15527 |
<inserted text> |
| 15528 |
\par |
| 15529 |
<*> xintsession^^M |
| 15530 |
|
| 15531 |
? S |
| 15532 |
OK, entering \scrollmode... |
| 15533 |
|
| 15534 |
*\xintsession |
| 15535 |
|
| 15536 |
You are back to the xintexpr interactive session! |
| 15537 |
(current mode: fp (Digits=16), with Digits=16) |
| 15538 |
|
| 15539 |
">>> " means central computing is waiting for input |
| 15540 |
"... " means that multi-line input continues. Use `;' to terminate it. |
| 15541 |
|
| 15542 |
Say `&bye' at any time to terminate the session and the TeX run. |
| 15543 |
>>> \def\xintPFloatZero{0.0} |
| 15544 |
(executing \def \xintPFloatZero {0.0} in background) |
| 15545 |
|
| 15546 |
>>> \def\xintPFloatIntSuffix{.0}\def\xintPFloatLengthOneSuffix{.0} |
| 15547 |
|
| 15548 |
(executing \def \xintPFloatIntSuffix {.0}\def \xintPFloatLengthOneSuffix {.0} i |
| 15549 |
n background) |
| 15550 |
|
| 15551 |
>>> \def\xintPFloatNoSciEmax{15}\def\xintPFloatNoSciEmin{-4} |
| 15552 |
|
| 15553 |
(executing \def \xintPFloatNoSciEmax {15}\def \xintPFloatNoSciEmin {-4} in back |
| 15554 |
ground) |
| 15555 |
|
| 15556 |
>>> \def\xintPFloatMinTrimmed{-1} |
| 15557 |
(executing \def \xintPFloatMinTrimmed {-1} in background) |
| 15558 |
|
| 15559 |
>>> 0., 1234., 6e100; |
| 15560 |
@_1 0.0, 1234.0, 6.0e100 |
| 15561 |
>>> 1234567812345678.12345678; |
| 15562 |
@_2 1234567812345678.0 |
| 15563 |
>>> 12345678123456781.2345678; |
| 15564 |
@_3 1.234567812345678e16 |
| 15565 |
>>> 12345678.12340; |
| 15566 |
@_4 12345678.1234 |
| 15567 |
>>> 12345678.123400; |
| 15568 |
@_5 12345678.1234 |
| 15569 |
>>> 0.1234567812345678; |
| 15570 |
@_6 0.1234567812345678 |
| 15571 |
>>> 0.00012345678123456785; |
| 15572 |
@_7 0.0001234567812345679 |
| 15573 |
>>> 0.000012345678123456785; |
| 15574 |
@_8 1.234567812345679e-5 |
| 15575 |
>>> &bye |
| 15576 |
\end{everbatim} |
| 15577 |
This is with version |0.4alpha (2021-11-01)| of |
| 15578 |
\ctanpackage{xintsession}. Probably some ``magic'' shortcuts will be |
| 15579 |
added in future to its interface for this kind of tasks, in place of |
| 15580 |
the |\def|. |
| 15581 |
|
| 15582 |
% \subsection{\csh{xintFloatE}}\label{xintFloatE} |
| 15583 |
% %! {\small New with |1.097|.} |
| 15584 |
|
| 15585 |
% |\xintFloatE [P]{f}{x}|\etype{{\upshape[\numx]}\Ff\numx} multiplies the input |
| 15586 |
% |f| by $10^x$, and |
| 15587 |
% converts it to float format according to the optional first argument or current |
| 15588 |
% value of |\xinttheDigits|. |
| 15589 |
% \begin{everbatim*} |
| 15590 |
% \xintFloatE {1.23e37}{53} |
| 15591 |
% \end{everbatim*} |
| 15592 |
|
| 15593 |
% There is since |1.4b| an unfortunate proximity in name with \csbxint{PFloatE} |
| 15594 |
% despite the two things having absolutely nothing in common. |
| 15595 |
|
| 15596 |
\subsection{\csh{xintFloatAdd}}\label{xintFloatAdd} |
| 15597 |
|
| 15598 |
|
| 15599 |
|\xintFloatAdd [P]{f}{g}|\etype{{\upshape[\numx]}\Ff\Ff} first replaces |f| |
| 15600 |
and |g| with their float approximations |f'| and |g'| to |P| significant |
| 15601 |
places or to the precision from |\xintDigits|. It then produces |
| 15602 |
the sum |f'+g'|, correctly rounded to nearest with the same number of |
| 15603 |
significant places. |
| 15604 |
|
| 15605 |
|
| 15606 |
\subsection{\csh{xintFloatSub}}\label{xintFloatSub} |
| 15607 |
|
| 15608 |
|
| 15609 |
|\xintFloatSub [P]{f}{g}|\etype{{\upshape[\numx]}\Ff\Ff} first replaces |f| |
| 15610 |
and |g| with their float approximations |f'| and |g'| to |P| significant |
| 15611 |
places or to the precision from |\xintDigits|. It then produces |
| 15612 |
the difference |f'-g'| correctly rounded to nearest |P|-float. |
| 15613 |
|
| 15614 |
|
| 15615 |
\subsection{\csh{xintFloatMul}}\label{xintFloatMul} |
| 15616 |
|
| 15617 |
|
| 15618 |
|\xintFloatMul [P]{f}{g}|\etype{{\upshape[\numx]}\Ff\Ff} first replaces |f| |
| 15619 |
and |g| with their float approximations |f'| and |g'| to |P| (or |
| 15620 |
|\xinttheDigits|) significant places. It then correctly rounds |
| 15621 |
the product |f'*g'| to nearest |P|-float. |
| 15622 |
|
| 15623 |
See \autoref{ssec:floatingpoint} for more. |
| 15624 |
|
| 15625 |
\begin{framed} |
| 15626 |
It is obviously much needed that the author improves its algorithms to avoid |
| 15627 |
going through the exact |2P| or |2P-1| digits before |
| 15628 |
throwing to the waste-bin half of those digits ! |
| 15629 |
|
| 15630 |
% \xintname initially was purely an \emph{exact} arbitrary precision |
| 15631 |
% arithmetic machine, and the introduction of floating point numbers was an |
| 15632 |
% after-thought. I got it working in release |1.07 (2013/05/25)| and never had |
| 15633 |
% time to come back to it. |
| 15634 |
\end{framed} |
| 15635 |
|
| 15636 |
\subsection{\csh{xintFloatDiv}}\label{xintFloatDiv} |
| 15637 |
|
| 15638 |
|
| 15639 |
|\xintFloatDiv [P]{f}{g}|\etype{{\upshape[\numx]}\Ff\Ff} first replaces |f| |
| 15640 |
and |g| with their float approximations |f'| and |g'| to |P| (or |
| 15641 |
|\xinttheDigits|) significant places. It then correctly rounds |
| 15642 |
the fraction |f'/g'| to nearest |P|-float. |
| 15643 |
|
| 15644 |
See \autoref{ssec:floatingpoint} for more. |
| 15645 |
|
| 15646 |
Notice in the special situation with |f| and |g| integers that |\xintFloatDiv |
| 15647 |
[P]{f}{g}| will \emph{not necessarily} give the correct rounding of the |
| 15648 |
exact fraction |f/g|. Indeed the macro arguments are each first individually |
| 15649 |
rounded to |P| digits of precision. The correct syntax to get the correctly |
| 15650 |
rounded integer fraction |f/g| is \csbxint{Float}|[P]{f/g}|. |
| 15651 |
|
| 15652 |
\subsection{\csh{xintFloatPow}}\label{xintFloatPow} |
| 15653 |
|
| 15654 |
|\xintFloatPow [P]{f}{x}|\etype{{\upshape[\numx]}\Ff\numx} uses either the |
| 15655 |
optional argument |P| or in its absence the value of |\xinttheDigits|. It |
| 15656 |
computes a floating approximation to |f^x|. |
| 15657 |
|
| 15658 |
The exponent |x| will be handed over to a |\numexpr|, hence count registers are |
| 15659 |
accepted on input for this |x|. And the absolute value \verb+|x|+ must obey the |
| 15660 |
\TeX{} bound. |
| 15661 |
|
| 15662 |
The argument |f| is first rounded to |P| significant places to give |
| 15663 |
|f'|. The output |Z| is such that the exact |f'^x| differs from |
| 15664 |
|Z| by an absolute error less than |0.52 ulp(Z)|. |
| 15665 |
\begin{everbatim*} |
| 15666 |
\xintFloatPow [8]{3.1415}{1234567890} |
| 15667 |
\end{everbatim*} |
| 15668 |
|
| 15669 |
\subsection{\csh{xintFloatPower}}\label{xintFloatPower} |
| 15670 |
|
| 15671 |
\csa{xintFloatPower}|[P]{f}{g}|\etype{{\upshape[\numx]}\Ff\Numf} computes a |
| 15672 |
floating point value |f^g| where the exponent |g| is not constrained to be at |
| 15673 |
most the \TeX{} bound \dtt{\number "7FFFFFFF}. It may even be a fraction |
| 15674 |
|A/B| but will be truncated to an integer. The exponent of the |
| 15675 |
\emph{output} however \emph{must} at any rate obey the \TeX{} bound. |
| 15676 |
|
| 15677 |
The argument |f| is first rounded to |P| significant places to give |
| 15678 |
|f'|. The output |Z| is then such that the exact |f'^g| differs from |
| 15679 |
|Z| by an absolute error less than |0.52 ulp(Z)|. |
| 15680 |
|
| 15681 |
|
| 15682 |
\emph{For integer exponents} this is the support macro which |
| 15683 |
is used for the |^| (or |**|) infix operators in \csbxint{floateval}, or also |
| 15684 |
in \csbxint{eval} for very big integer exponents. It is also used in |
| 15685 |
\csbxint{floateval} and \csbxint{eval} for half-integer exponents, via a |
| 15686 |
combination with the \csbxint{FloatSqrt} square-root extraction. |
| 15687 |
|
| 15688 |
The macro itself was \emph{NOT} modified at |1.4e|: when used directly it |
| 15689 |
still starts by truncating the exponent to an integer... As for other |
| 15690 |
user-level floating-point macros, its output is handled by \csbxint{Float}, |
| 15691 |
i.e. it uses scientific notation. |
| 15692 |
|
| 15693 |
The |0.52 ulp(Z)| guaranteed error bound applies also to the |
| 15694 |
\csbxint{floateval} evaluations for the half-integer exponent case. It is |
| 15695 |
valid only when |f| already had a mantissa of at most |P| digits and was |
| 15696 |
not modified by the initial rounding done by the macro to reduce |f| to |P| |
| 15697 |
digits. |
| 15698 |
|
| 15699 |
The integer exponent |g| may have more than |P| (or |Digits|) digits, it is |
| 15700 |
handled exactly. And as said above its absolute value may exceed the \TeX\ bound. |
| 15701 |
|
| 15702 |
% Notice that this is a bound on the distance from |
| 15703 |
% |f'^g| to |Z|, where |f'| is the rounded value of the original input |f|; |
| 15704 |
% the distance from |f^g| to |Z| can be much worse if |g| is very |
| 15705 |
% large. Roughly, when |g| is negligible compared to |10^P|, we get an extra |
| 15706 |
% difference of up to about |50g ulp(Z)| which completely dwarfs the |0.52 |
| 15707 |
% ulp(Z)|. Thus, if |f| has strictly more than |P| digits, then the computation |
| 15708 |
% must be done with an elevated working precision |P'|. For example with |
| 15709 |
% |g=1000| we should use |P'=P+6| to achieve a total error at worst slightly |
| 15710 |
% bigger than |0.55 ulp(Z)| after the final rounding from |P'| to |P| digits to |
| 15711 |
% get |Z|. |
| 15712 |
|
| 15713 |
% Examples:% |
| 15714 |
% % |
| 15715 |
% \footnote{|\np| is formatting macro from the \url{http://ctan.org/pkg/numprint} |
| 15716 |
% package.} |
| 15717 |
% % |
| 15718 |
% \begin{everbatim*} |
| 15719 |
% \np{\xintFloatPower [8]{3.1415}{3e9}}\newline% Notice that 3e9>2^31 |
| 15720 |
% \np{\xintFloatPower [48]{1.1547}{\xintiiPow {2}{35}}}\newline |
| 15721 |
% \end{everbatim*}% |
| 15722 |
% $2^{35}=\xintiiPow {2}{35}$ exceeds \TeX's bound, but what |
| 15723 |
% counts is the exponent of the result which, while dangerously close to |
| 15724 |
% $2^{31}$ is not quite there yet. |
| 15725 |
|
| 15726 |
% With expressions: |
| 15727 |
% \begin{everbatim*} |
| 15728 |
% {\xintDigits:=48\relax \np{\xintthefloatexpr 1.1547^2^35\relax}} |
| 15729 |
% \end{everbatim*} |
| 15730 |
|
| 15731 |
% There is a subtlety here that the |2^35| will be evaluated as a floating point |
| 15732 |
% number but fortunately it only has \dtt{11} digits, hence the final evaluation |
| 15733 |
% is done with a correct exponent. It would have been safer, and also more |
| 15734 |
% efficient to code the above rather as: |
| 15735 |
% \begin{everbatim} |
| 15736 |
% \xintthefloatexpr 1.1547^\xintiiexpr 2^35\relax\relax |
| 15737 |
% \end{everbatim} |
| 15738 |
|
| 15739 |
% Here is an example with |
| 15740 |
% |12^16| as exponent, which has $18$ digits (\dtt{={\xintiiPow{12}{16}}}). |
| 15741 |
% \begin{everbatim*} |
| 15742 |
% {\xintDigits:=12\relax \np{\xintthefloatexpr (1+1e-8)^\xintiiexpr 12^16\relax\relax}}\newline |
| 15743 |
% \np{\xintthefloatexpr (1+1e-8)^\xintiiexpr 12^16\relax\relax}\newline |
| 15744 |
% {\xintDigits:=27\relax \np{\xintthefloatexpr (1+1e-8)^12^16\relax}}\newline |
| 15745 |
% {\xintDigits:=48\relax \np{\xintthefloatexpr (1+1e-8)^12^16\relax}} |
| 15746 |
% \end{everbatim*} |
| 15747 |
|
| 15748 |
% There is an important difference between |\xintFloatPower[Q]{X}{Y}| and |
| 15749 |
% |\xintthefloatexpr[Q] X^Y\relax|: in the former case the computation is done |
| 15750 |
% with |Q| digits or precision,% |
| 15751 |
% % |
| 15752 |
% \footnote{if |X| and |Y| themselves stand for some |
| 15753 |
% floating point macros with arguments, their respective evaluations obey the |
| 15754 |
% precision |\xinttheDigits| or as set optionally in the macro calls |
| 15755 |
% themselves.} |
| 15756 |
% % |
| 15757 |
% whereas with \csbxint{thefloatexpr}|[Q]| the evaluation of the |
| 15758 |
% expression proceeds with |\xinttheDigits| digits of precision, and the final |
| 15759 |
% result is then rounded to |Q| digits: thus this makes real sense only if used |
| 15760 |
% with |Q<\xinttheDigits|. |
| 15761 |
|
| 15762 |
\subsection{\csh{xintFloatSqrt}}\label{xintFloatSqrt} |
| 15763 |
|
| 15764 |
\csa{xintFloatSqrt}|[P]{f}|\etype{{\upshape[\numx]}\Ff} computes a floating |
| 15765 |
point approximation of $\sqrt{\text{|f|}}$, either using the optional precision |P| or |
| 15766 |
the value of |\xinttheDigits|. |
| 15767 |
|
| 15768 |
More precisely since |1.2f| the macro achieves so-called \emph{correct |
| 15769 |
rounding}:\IMPORTANT{} the produced value is the rounding to |P| significant |
| 15770 |
places of the abstract exact value, \emph{if the input has itself at most |P| |
| 15771 |
digits} (and an arbitrary exponent). |
| 15772 |
\begin{everbatim*} |
| 15773 |
\xintFloatSqrt [89]{10}\newline |
| 15774 |
\xintFloatSqrt [89]{100}\newline |
| 15775 |
\xintFloatSqrt [89]{123456789}\par |
| 15776 |
\end{everbatim*} |
| 15777 |
|
| 15778 |
And now some tests to check that correct rounding applies correctly (sic): |
| 15779 |
\begin{everbatim*} |
| 15780 |
The argument has 16 digits, hence escapes initial rounding:\newline |
| 15781 |
\xintFloatSqrt {5625000075000001}\newline |
| 15782 |
This one gets rounded hence same value is computed:\newline |
| 15783 |
\xintFloatSqrt {5625000075000001.4}\newline |
| 15784 |
but actual value is more like:\newline |
| 15785 |
\xintFloatSqrt [24]{5625000075000001.4}\newline |
| 15786 |
\xintFloatSqrt [32]{5625000075000001.4}\newline |
| 15787 |
The argument has 48 digits, hence escapes initial rounding:\newline |
| 15788 |
\xintFloatSqrt [48]{562500000000000000000000750000000000000000000001}\newline |
| 15789 |
\xintFloatSqrt [64]{562500000000000000000000750000000000000000000001}\newline |
| 15790 |
\xintFloatSqrt [80]{562500000000000000000000750000000000000000000001}\newline |
| 15791 |
\end{everbatim*} |
| 15792 |
(we observe in passing illustrations that rounding to nearest is not |
| 15793 |
transitive.)\par |
| 15794 |
|
| 15795 |
|
| 15796 |
|
| 15797 |
|
| 15798 |
|
| 15799 |
|
| 15800 |
\subsection{\csh{xintFloatFac}}\label{xintFloatFac} |
| 15801 |
|
| 15802 |
\csa{xintFloatFac}|[P]{f}|\etype{{\upshape[\numx]}\Numf} returns the |
| 15803 |
factorial with either \csa{xinttheDigits} or |P| digits of precision. |
| 15804 |
|
| 15805 |
|
| 15806 |
|
| 15807 |
The exact theoretical value differs from the calculated one |Y| by an absolute |
| 15808 |
error strictly less than |0.6 ulp(Y)|. |
| 15809 |
|
| 15810 |
\begin{everbatim*} |
| 15811 |
$1000!\approx{}$\xintFloatFac [30]{1000} |
| 15812 |
\end{everbatim*} |
| 15813 |
The computation proceeds via doing explicitely the product.% |
| 15814 |
% |
| 15815 |
\footnote{An approach based upon the Stirling formula could not be |
| 15816 |
done at time of implementation because of lack of exponential and |
| 15817 |
logarithm. This is now supported via package \xintlogname. So perhaps |
| 15818 |
at some point in future Gamma function will be implemented.} |
| 15819 |
% |
| 15820 |
|
| 15821 |
The maximal allowed argument is $99999999$, but already $100000!$ currently |
| 15822 |
takes, for \dtt{16} digits of precision, a few seconds on my laptop (it |
| 15823 |
returns \dtt{2.824229407960348e456573}). |
| 15824 |
|
| 15825 |
The |factorial| function is available in \csbxint{floatexpr}: |
| 15826 |
\begin{everbatim*} |
| 15827 |
\xintthefloatexpr factorial(1000)\relax % same as 1000! |
| 15828 |
\end{everbatim*} |
| 15829 |
|
| 15830 |
\subsection{\csh{xintFloatBinomial}}\label{xintFloatBinomial} |
| 15831 |
|
| 15832 |
\csa{xintFloatBinomial}|[P]{x}{y}|\etype{{\upshape[\numx]}\Numf\Numf} computes |
| 15833 |
binomial coefficients with either \csa{xinttheDigits} or |P| digits of |
| 15834 |
precision. |
| 15835 |
|
| 15836 |
When |x<0| an out-of-range error is raised. Else if |y<0| or if |x<y| the |
| 15837 |
macro evaluates to \dtt{\xintFloatBinomial{1}{-1}}. |
| 15838 |
The exact theoretical value differs from the calculated one |Y| by an absolute |
| 15839 |
error strictly less than |0.6 ulp(Y)|. |
| 15840 |
|
| 15841 |
\begin{everbatim*} |
| 15842 |
${3000\choose 1500}\approx{}$\xintFloatBinomial [24]{3000}{1500} |
| 15843 |
\end{everbatim*} |
| 15844 |
|
| 15845 |
% \begin{everbatim*} |
| 15846 |
% ${9999\choose 5000}\approx{}$\xintFloatBinomial [24]{9999}{5000} |
| 15847 |
% \end{everbatim*} |
| 15848 |
|
| 15849 |
% 2015/11/28 |
| 15850 |
% 7.95895131766219474168799e3007 |
| 15851 |
% aparté: (testé avec Maple 16, 2015/11/28) |
| 15852 |
% > binomial (9999.,5000.); |
| 15853 |
% 3008 |
| 15854 |
% 0.795895131768 10 |
| 15855 |
% |
| 15856 |
% > Digits:=32; |
| 15857 |
% Digits := 32 |
| 15858 |
% |
| 15859 |
% > binomial (9999.,5000.); |
| 15860 |
% 3008 |
| 15861 |
% 0.795895131768 10 |
| 15862 |
% apparemment le binomial de Maple ne sait pas calculer avec plus de |
| 15863 |
% précision! |
| 15864 |
% et son dernier chiffre est faux! Pourtant GAMMA(9999.) fonctionne. Sauf si |
| 15865 |
% je n'ai pas compris quelque chose il me semble donc que le binomial de Maple |
| 15866 |
% est bogué...binomial(100.,50.); marche lui et binomial(4999.,2000.); aussi, |
| 15867 |
% bon clairement on a un bug de Maple ! oui binomial(8999.,5000.); ainsi que |
| 15868 |
% binomial(10999.,5000.); fonctionnent avec Digits:=32 mais **pas** |
| 15869 |
% binomial(9999.,5000.)... binomial(10000.,5000.); et binomial(9998.,5000.); |
| 15870 |
% sont OK. Est-ce qu'on gagne quelque chose pour un bug report ? |
| 15871 |
% > binomial(9999.,5000.); |
| 15872 |
% 3008 |
| 15873 |
% 0.795895131768 10 |
| 15874 |
% > binomial(10000.,5000.); |
| 15875 |
% 3009 |
| 15876 |
% 0.1591790263532438948337597273641521 10 |
| 15877 |
% > binomial(9998.,5000.); |
| 15878 |
% 3008 |
| 15879 |
% 0.3979077671466477799149739359402922 10 |
| 15880 |
% en plus je lui demande 32 chiffres et il m'en sort 34. |
| 15881 |
|
| 15882 |
The associated function in \csbxint{floatexpr} is \func{binomial}: |
| 15883 |
\begin{everbatim*} |
| 15884 |
\xintthefloatexpr binomial(3000,1500)\relax |
| 15885 |
\end{everbatim*} |
| 15886 |
|
| 15887 |
The computation is based on the formula |(x-y+1)...x/y!| (here one arranges |
| 15888 |
|y<=x-y| naturally). |
| 15889 |
|
| 15890 |
|
| 15891 |
\subsection{\csh{xintFloatPFactorial}}\label{xintFloatPFactorial} |
| 15892 |
|
| 15893 |
\csa{xintFloatPFactorial}|[P]{x}{y}|\etype{{\upshape[\numx]}\Numf\Numf} |
| 15894 |
computes the product |(x+1)...y|. |
| 15895 |
|
| 15896 |
|
| 15897 |
|
| 15898 |
|
| 15899 |
The arguments must be integers (they are expanded inside |\numexpr|) |
| 15900 |
and the allowed range is $-100000000\leqslant x, y\leqslant99999999$. If |
| 15901 |
$x\geqslant y$ the product is considered empty hence returns one (as a |
| 15902 |
floating point value). |
| 15903 |
See also \csbxint{iiPFactorial}. |
| 15904 |
|
| 15905 |
|
| 15906 |
The exact theoretical value differs from the calculated one |Y| by an absolute |
| 15907 |
error strictly less than |0.6 ulp(Y)|. |
| 15908 |
|
| 15909 |
The associated function in \csbxint{floatexpr} is \func{pfactorial}: |
| 15910 |
\begin{everbatim*} |
| 15911 |
\xintthefloatexpr pfactorial(2500,5000)\relax |
| 15912 |
\end{everbatim*} |
| 15913 |
|
| 15914 |
\xintDigits:=16\relax |
| 15915 |
|
| 15916 |
|
| 15917 |
\clearpage |
| 15918 |
\let\xintfracnameUp\undefined |
| 15919 |
\csname xintbinhexnameUp\endcsname |
| 15920 |
\def\n{|{N}|} |
| 15921 |
\def\m{|{M}|} |
| 15922 |
\def\x{|{x}|} |
| 15923 |
\section{Macros of the \xintbinhexname package} |
| 15924 |
\RaisedLabel{sec:binhex} |
| 15925 |
|
| 15926 |
\localtableofcontents |
| 15927 |
|
| 15928 |
This package provides expandable conversions of (big) integers between |
| 15929 |
the hexadecimal, decimal, octal (since |1.4n|) and binary bases. |
| 15930 |
|
| 15931 |
First version of this package was in the |1.08| (|2013/06/07|) release |
| 15932 |
of \xintname. Its routines remained unmodified until their complete |
| 15933 |
rewrite at release |1.2m| (|2017/07/31|). Macros became faster, but the |
| 15934 |
inputs got limited to a few thousand digits, whereas the |1.08| versions |
| 15935 |
could handle (slowly...) tens of thousands of digits. At |1.4n| some |
| 15936 |
internals were refactored to use the \cs{expanded} primitive (which was |
| 15937 |
not available in 2017).\NewWith{1.4n} The maximal sizes got increased, see |
| 15938 |
\autoref{ssec:binhexsizes}. More significant probably, the octal radix |
| 15939 |
was added to the ones covered. |
| 15940 |
|
| 15941 |
|
| 15942 |
For each provided conversion macro, its argument is first \fexpan |
| 15943 |
ded. This expansion is supposed to give a sequence of digits, with |
| 15944 |
perhaps a (unique) leading minus sign, which gets prepended to output |
| 15945 |
(note that \csbxint{DecToHex}|{-0}| thus expands to \dtt{\xintDecToHex{-0}}). |
| 15946 |
|
| 15947 |
Let's insist that inputs can not start (after expansion) with a |0b|, |
| 15948 |
|0o|, |0x|, |#x|, |"|, |'|, or similar prefix notation: they must |
| 15949 |
consist only of digits as fitting to the binary, octal, decimal, or |
| 15950 |
hexadecimal radix. Situation is different if using \xintexprname-essions, |
| 15951 |
see \autoref{ssec:exprbinhex} next. |
| 15952 |
|
| 15953 |
Low-level unrecoverable errors will occur if for |
| 15954 |
example an octal input contains the decimal digit |8| (more instructive |
| 15955 |
errors are raised if inside an \xintexprname-ession). |
| 15956 |
|
| 15957 |
Hexadecimal digits in input must be uppercased. Category codes for |
| 15958 |
them may be indifferently \emph{letter} or \emph{other}. In output they |
| 15959 |
are of category \emph{letter} (and uppercased). |
| 15960 |
|
| 15961 |
Leading zeroes in the input are allowed, and depending on the macro may |
| 15962 |
show up or not in the output. Note in particular: |
| 15963 |
\begin{itemize}[noitemsep] |
| 15964 |
\item Inputs with no leading zeros give outputs with no leading zeros. |
| 15965 |
|
| 15966 |
\item All rules have (deliberate) exceptions, check the docs of |
| 15967 |
\csbxint{CHexToBin} and |
| 15968 |
\csbxint{COctToBin} which are variants of \csbxint{HexToBin} and |
| 15969 |
\csbxint{OctToBin}. |
| 15970 |
|
| 15971 |
\item Outputs (if non vanishing) from \csbxint{DecToHex} or \csbxint{DecToOct} |
| 15972 |
have no leading zeros whether or not the inputs had some. |
| 15973 |
|
| 15974 |
\item \csbxint{BinToHex} and \csbxint{BinToOct} always use the minimal number of |
| 15975 |
hexadecimal resp.\@ octal digits as needed to represent the original binary digits, |
| 15976 |
inclusive of their leading zeroes. For example |
| 15977 |
\csbxint{BinToHex}|{0000001}| outputs \dtt{\xintBinToHex{0000001}} and |
| 15978 |
\csbxint{BinToOct}|{0000001}| outputs \dtt{\xintBinToOct{0000001}}. |
| 15979 |
\end{itemize} |
| 15980 |
|
| 15981 |
|
| 15982 |
\subsection{\xintexprname-essions} |
| 15983 |
\label{ssec:exprbinhex} |
| 15984 |
|
| 15985 |
Inside \xintexprname-essions,\NewWith{1.4n} hexadecimal can be input |
| 15986 |
using either |"| or |0x| prefixes, octal using either |'| or |0o|, and |
| 15987 |
binary using |0b|. Prior to |1.4n| only |"| was implemented and it was |
| 15988 |
needed to load \xintbinhexname additionally to \xintexprname. This is |
| 15989 |
now done automatically. |
| 15990 |
|
| 15991 |
Hexadecimal letters must be uppercased. In both of \csbxint{eval} and |
| 15992 |
\csbxint{floateval} a ``fractional part'' after the full stop as |
| 15993 |
separator is allowed for all three bases. Here is an example using the |
| 15994 |
three non-decimal bases: |
| 15995 |
\begin{everbatim*} |
| 15996 |
\xinteval{subsm({x, y, x==y}, x="FF.FF * '777.777 * 0b11111.11111; |
| 15997 |
y=(16^2-16^-2)(8^3-8^-3)(2^5-2^-5);)} |
| 15998 |
\end{everbatim*} |
| 15999 |
|
| 16000 |
The |
| 16001 |
|p| postfix notation from some programming languages, which stands for |
| 16002 |
an extra power of two, is however not implemented so far. |
| 16003 |
|
| 16004 |
With \csbxint{iieval}\NewWith{1.4n}, which handles only integers, there |
| 16005 |
is an optional parameter |[h]|, |[o]|, or |[b]| for automatic conversion |
| 16006 |
of the output (this works also with comma separated inputs and even |
| 16007 |
nested bracketed inputs). Here is an example illustrating the new |
| 16008 |
more condensed syntax: |
| 16009 |
\begin{everbatim*} |
| 16010 |
\xintiieval[b]{0b1011100101001110 * 0b111100011} |
| 16011 |
\end{everbatim*} |
| 16012 |
|
| 16013 |
Compare with how one would have had to input it prior to |1.4n|: |
| 16014 |
\begin{everbatim*} |
| 16015 |
\xintDecToBin{\xintiieval{\xintBinToDec{1011100101001110}*\xintBinToDec{111100011}}} |
| 16016 |
\end{everbatim*} |
| 16017 |
|
| 16018 |
|
| 16019 |
\subsection{\csh{xintHexToDec}}\label{xintHexToDec} |
| 16020 |
|
| 16021 |
Converts from hexadecimal to decimal.\etype{f} |
| 16022 |
|
| 16023 |
\texttt{\string\xintHexToDec |
| 16024 |
\string{\printnumber{11A9397C66949A97051F7D0A817914E3E0B17C41B11C48BAEF2B5760BB38D272F46DCE46C6032936BF37DAC918814C63}\string}}\endgraf\noindent |
| 16025 |
\dtt{->\printnumber{\xintHexToDec{11A9397C66949A97051F7D0A817914E3E0B17C41B11C48BAEF2B5760BB38D272F46DCE46C6032936BF37DAC918814C63}}} |
| 16026 |
|
| 16027 |
\subsection{\csh{xintHexToOct}}\label{xintHexToOct} |
| 16028 |
|
| 16029 |
Converts from hexadecimal to octal.\etype{f} |
| 16030 |
|
| 16031 |
\mbox{}\NewWith{1.4n}% |
| 16032 |
\texttt{\string\xintHexToOct |
| 16033 |
\string{\printnumber{11A9397C66949A97051F7D0A817914E3E0B17C41B11C48BAEF2B5760BB38D272F46DCE46C6032936BF37DAC918814C63}\string}}\endgraf\noindent |
| 16034 |
\dtt{->\printnumber{\xintHexToOct{11A9397C66949A97051F7D0A817914E3E0B17C41B11C48BAEF2B5760BB38D272F46DCE46C6032936BF37DAC918814C63}}} |
| 16035 |
|
| 16036 |
\subsection{\csh{xintHexToBin}}\label{xintHexToBin} |
| 16037 |
|
| 16038 |
Converts from hexadecimal to binary. Up to three leading zeroes of the binary output |
| 16039 |
are trimmed.\etype{f} |
| 16040 |
|
| 16041 |
\texttt{\string\xintHexToBin |
| 16042 |
\string{\printnumber{11A9397C66949A97051F7D0A817914E3E0B17C41B11C48BAEF2B5760BB38D272F46DCE46C6032936BF37DAC918814C63}\string}}\endgraf\noindent |
| 16043 |
\dtt{->\printnumber{\xintHexToBin{11A9397C66949A97051F7D0A817914E3E0B17C41B11C48BAEF2B5760BB38D272F46DCE46C6032936BF37DAC918814C63}}} |
| 16044 |
|
| 16045 |
\subsection{\csh{xintCHexToBin}}\label{xintCHexToBin} |
| 16046 |
|
| 16047 |
Converts from hexadecimal to binary.\etype{f} Same as \csbxint{HexToBin}, but |
| 16048 |
an input with |N| hexadecimal digits will give an output with exactly |4N| |
| 16049 |
binary digits, leading zeroes are not trimmed. |
| 16050 |
|
| 16051 |
\texttt{\string\xintCHexToBin |
| 16052 |
\string{\printnumber{11A9397C66949A97051F7D0A817914E3E0B17C41B11C48BAEF2B5760BB38D272F46DCE46C6032936BF37DAC918814C63}\string}}\endgraf\noindent |
| 16053 |
\dtt{->\printnumber{\xintCHexToBin{11A9397C66949A97051F7D0A817914E3E0B17C41B11C48BAEF2B5760BB38D272F46DCE46C6032936BF37DAC918814C63}}} |
| 16054 |
|
| 16055 |
This can be combined with \csbxint{BinToHex} for round-trips preserving |
| 16056 |
leading zeroes for |4N| binary digits numbers, whereas using |
| 16057 |
\csbxint{HexToBin} gives reproducing round-trips only for |4N| binary numbers |
| 16058 |
numbers not starting with |0000|. |
| 16059 |
\begin{everbatim*} |
| 16060 |
\xintBinToHex{0001111}\par |
| 16061 |
\end{everbatim*} |
| 16062 |
Chaining, we end up with 4N-3 digits, as three binary zeroes are trimmed: |
| 16063 |
\begin{everbatim*} |
| 16064 |
\xintHexToBin{\xintBinToHex{0001111}}\par |
| 16065 |
\end{everbatim*} |
| 16066 |
But the next will always reproduce the initial input zero-filled to length 4N: |
| 16067 |
\begin{everbatim*} |
| 16068 |
\xintCHexToBin{\xintBinToHex{0001111}}\par |
| 16069 |
\end{everbatim*} |
| 16070 |
Another example (visible space characters manually inserted):\newline |
| 16071 |
$000000001111101001010001\xrightarrow{\text{\string\xintBinToHex}}%$ |
| 16072 |
\xintBinToHex{000000001111101001010001}\xrightarrow{\text{\string\xintHexToBin\hphantom{X}}} |
| 16073 |
\text{\textvisiblespace\textvisiblespace\textvisiblespace} |
| 16074 |
\xintHexToBin{\xintBinToHex{000000001111101001010001}}$\newline%$ |
| 16075 |
$000000001111101001010001\xrightarrow{\text{\string\xintBinToHex}}%$ |
| 16076 |
\xintBinToHex{000000001111101001010001}\xrightarrow{\text{\string\xintCHexToBin}} |
| 16077 |
\xintCHexToBin{\xintBinToHex{000000001111101001010001}}$%$ |
| 16078 |
\par |
| 16079 |
|
| 16080 |
\subsection{\csh{xintDecToHex}}\label{xintDecToHex} |
| 16081 |
|
| 16082 |
Converts from decimal to hexadecimal.\etype{f} |
| 16083 |
|
| 16084 |
\texttt{\string\xintDecToHex \string{\printnumber{2718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427427466391932003}\string}}\endgraf\noindent\dtt{->\printnumber{\xintDecToHex{2718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427427466391932003}}} |
| 16085 |
|
| 16086 |
\subsection{\csh{xintDecToOct}}\label{xintDecToOct} |
| 16087 |
|
| 16088 |
Converts from decimal to octal.\etype{f} |
| 16089 |
|
| 16090 |
\mbox{}\NewWith{1.4n}\texttt{\string\xintDecToOct \string{\printnumber{2718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427427466391932003}\string}}\endgraf\noindent\dtt{->\printnumber{\xintDecToOct{2718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427427466391932003}}} |
| 16091 |
|
| 16092 |
\subsection{\csh{xintDecToBin}}\label{xintDecToBin} |
| 16093 |
|
| 16094 |
Converts from decimal to binary.\etype{f} |
| 16095 |
|
| 16096 |
\texttt{\string\xintDecToBin \string{\printnumber{2718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427427466391932003}\string}}\endgraf\noindent\dtt{->\printnumber{\xintDecToBin{2718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427427466391932003}}} |
| 16097 |
|
| 16098 |
\subsection{\csh{xintOctToHex}}\label{xintOctToHex} |
| 16099 |
|
| 16100 |
Converts from octal to hexadecimal.\etype{f} |
| 16101 |
|
| 16102 |
\mbox{}\NewWith{1.4n}% |
| 16103 |
\texttt{\string\xintOctToHex |
| 16104 |
\string{\printnumber{4324471370632244651340507676412402744247076026137040661070442727362552730135470644713643334710661401451155374676654443040246143}\string}}\endgraf\noindent |
| 16105 |
\dtt{->\printnumber{\xintOctToHex{4324471370632244651340507676412402744247076026137040661070442727362552730135470644713643334710661401451155374676654443040246143}}} |
| 16106 |
|
| 16107 |
\subsection{\csh{xintOctToDec}}\label{xintOctToDec} |
| 16108 |
|
| 16109 |
Converts from octal to decimal.\etype{f} |
| 16110 |
|
| 16111 |
\mbox{}\NewWith{1.4n}% |
| 16112 |
\texttt{\string\xintOctToDec |
| 16113 |
\string{\printnumber{4324471370632244651340507676412402744247076026137040661070442727362552730135470644713643334710661401451155374676654443040246143}\string}}\endgraf\noindent |
| 16114 |
\dtt{->\printnumber{\xintOctToDec{4324471370632244651340507676412402744247076026137040661070442727362552730135470644713643334710661401451155374676654443040246143}}} |
| 16115 |
|
| 16116 |
\subsection{\csh{xintOctToBin}}\label{xintOctToBin} |
| 16117 |
|
| 16118 |
Converts from octal to binary.\etype{f} Up to two leading zeroes of the |
| 16119 |
binary output are trimmed. |
| 16120 |
|
| 16121 |
\mbox{}\NewWith{1.4n}% |
| 16122 |
\texttt{\string\xintOctToBin |
| 16123 |
\string{\printnumber{14324471370632244651340507676412402744247076026137040661070442727362552730135470644713643334710661401451155374676654443040246143}\string}}\endgraf\noindent |
| 16124 |
\dtt{->\printnumber{\xintOctToBin{14324471370632244651340507676412402744247076026137040661070442727362552730135470644713643334710661401451155374676654443040246143}}} |
| 16125 |
|
| 16126 |
\subsection{\csh{xintCOctToBin}}\label{xintCOctToBin} |
| 16127 |
|
| 16128 |
Converts from octal to binary.\etype{f} |
| 16129 |
|
| 16130 |
Same as \csbxint{OctToBin}, except that an input with |N| |
| 16131 |
octal digits will give an output with exactly |3N| binary digits, |
| 16132 |
leading zeroes are not trimmed. |
| 16133 |
|
| 16134 |
\mbox{}\NewWith{1.4n}% |
| 16135 |
\texttt{\string\xintCOctToBin |
| 16136 |
\string{\printnumber{14324471370632244651340507676412402744247076026137040661070442727362552730135470644713643334710661401451155374676654443040246143}\string}}\endgraf\noindent |
| 16137 |
\dtt{->\printnumber{\xintCOctToBin{14324471370632244651340507676412402744247076026137040661070442727362552730135470644713643334710661401451155374676654443040246143}}} |
| 16138 |
|
| 16139 |
\subsection{\csh{xintBinToHex}}\label{xintBinToHex} |
| 16140 |
|
| 16141 |
Converts from binary to hexadecimal.\etype{f} |
| 16142 |
|
| 16143 |
The input is first extended if need-be by leading zeros in order to have |
| 16144 |
|4N| binary digits, then the output will have |N| hexadecimal digits |
| 16145 |
(thus, if the input did not have a leading zero, the output will not either). |
| 16146 |
|
| 16147 |
\texttt{\string\xintBinToHex |
| 16148 |
\string{\printnumber{100011010100100111001011111000110011010010100100110101001011100000101000111110111110100001010100000010111100100010100111000111110000010110001011111000100000110110001000111000100100010111010111011110010101101010111011000001011101100111000110100100111001011110100011011011100111001000110110001100000001100101001001101101011111100110111110110101100100100011000100000010100110001100011}\string}}\endgraf\noindent |
| 16149 |
\dtt{->\printnumber{\xintBinToHex{100011010100100111001011111000110011010010100100110101001011100000101000111110111110100001010100000010111100100010100111000111110000010110001011111000100000110110001000111000100100010111010111011110010101101010111011000001011101100111000110100100111001011110100011011011100111001000110110001100000001100101001001101101011111100110111110110101100100100011000100000010100110001100011}}} |
| 16150 |
|
| 16151 |
\subsection{\csh{xintBinToDec}}\label{xintBinToDec} |
| 16152 |
|
| 16153 |
Converts from binary to decimal.\etype{f} |
| 16154 |
|
| 16155 |
\texttt{\string\xintBinToDec |
| 16156 |
\string{\printnumber{100011010100100111001011111000110011010010100100110101001011100000101000111110111110100001010100000010111100100010100111000111110000010110001011111000100000110110001000111000100100010111010111011110010101101010111011000001011101100111000110100100111001011110100011011011100111001000110110001100000001100101001001101101011111100110111110110101100100100011000100000010100110001100011}\string}}\endgraf\noindent |
| 16157 |
\dtt{->\printnumber{\xintBinToDec{100011010100100111001011111000110011010010100100110101001011100000101000111110111110100001010100000010111100100010100111000111110000010110001011111000100000110110001000111000100100010111010111011110010101101010111011000001011101100111000110100100111001011110100011011011100111001000110110001100000001100101001001101101011111100110111110110101100100100011000100000010100110001100011}}} |
| 16158 |
|
| 16159 |
\subsection{\csh{xintBinToOct}}\label{xintBinToOct} |
| 16160 |
|
| 16161 |
Converts from binary to octal.\etype{f} |
| 16162 |
|
| 16163 |
The input is first extended if need-be by leading zeros in order to have |
| 16164 |
|3N| binary digits, then the output will have |N| octal digits |
| 16165 |
(thus, if the input did not have a leading zero, the output will not either). |
| 16166 |
|
| 16167 |
\mbox{}\NewWith{1.4n}% |
| 16168 |
\texttt{\string\xintBinToOct |
| 16169 |
\string{\printnumber{100011010100100111001011111000110011010010100100110101001011100000101000111110111110100001010100000010111100100010100111000111110000010110001011111000100000110110001000111000100100010111010111011110010101101010111011000001011101100111000110100100111001011110100011011011100111001000110110001100000001100101001001101101011111100110111110110101100100100011000100000010100110001100011}\string}}\endgraf\noindent |
| 16170 |
\dtt{->\printnumber{\xintBinToOct{100011010100100111001011111000110011010010100100110101001011100000101000111110111110100001010100000010111100100010100111000111110000010110001011111000100000110110001000111000100100010111010111011110010101101010111011000001011101100111000110100100111001011110100011011011100111001000110110001100000001100101001001101101011111100110111110110101100100100011000100000010100110001100011}}} |
| 16171 |
|
| 16172 |
\subsection{Maximal sizes of inputs}\label{ssec:binhexsizes} |
| 16173 |
|
| 16174 |
\autoref{tab:binhexsizes} recapitulates the maximal allowed sizes, as |
| 16175 |
found out with the \TeX{} installation of the author. The tests are done |
| 16176 |
putting the macro inside an \cs{edef} and compiling with the |etex| binary. |
| 16177 |
|
| 16178 |
The value in the second column is the maximal |N| such that the macro |
| 16179 |
does not raise an error on an input with |N| digits (if nested in |
| 16180 |
another macro, the maximal input size may become lower than stated). |
| 16181 |
The third column gives the corresponding maximal size of the output. |
| 16182 |
|
| 16183 |
These maximal sizes depend on \TeX\ parameters such as input stack size, |
| 16184 |
expansion depth, and parameter stack size. The fourth column gives the |
| 16185 |
\TeX\ parameter cited in the error message when trying with |N+1| |
| 16186 |
digits. When the limiting parameter is the main memory size, the upper |
| 16187 |
limits depend on external factors such as how many macros are loaded in |
| 16188 |
\TeX{} memory (for example they would be lower in a \LaTeX{} document or |
| 16189 |
if \xintexprname is loaded), so they are here given simply as |
| 16190 |
indications. They are so large anyhow that basically in practice, this |
| 16191 |
means no real limitation. |
| 16192 |
|
| 16193 |
Regarding the conversions to and from decimal radix, they allow a more |
| 16194 |
limited range, but are still able to handle inputs with ten thousand |
| 16195 |
digits, one can thus consider in practice that their size limitations |
| 16196 |
are also only of theoretical interest. |
| 16197 |
|
| 16198 |
\medskip |
| 16199 |
\begingroup |
| 16200 |
\makeatletter\def\@captype{table}\capstart |
| 16201 |
\centering |
| 16202 |
\begin{tabular}{rrrr} |
| 16203 |
\hline |
| 16204 |
&Max\ length\ of\ input&->\ length\ of\ output&Limiting factor\\ |
| 16205 |
\csbxint{DecToHex}&16042&13323&expansion depth=10000\\ |
| 16206 |
\csbxint{DecToOct}&15040&16654&expansion depth=10000\\ |
| 16207 |
\csbxint{DecToBin}&16042&53291&expansion depth=10000\\ |
| 16208 |
\csbxint{HexToDec}&11072&13333&expansion depth=10000\\ |
| 16209 |
\csbxint{OctToDec}&14763&13333&expansion depth=10000\\ |
| 16210 |
\csbxint{BinToDec}&44290&13333&expansion depth=10000\\ |
| 16211 |
\csbxint{HexToOct}&553514&738019&main memory size=5000000\\ |
| 16212 |
\csbxint{HexToBin}&553514&\the\numexpr4*553514\relax&main memory size=5000000\\ |
| 16213 |
\csbxint{OctToHex}&711660&533745&main memory size=5000000\\ |
| 16214 |
\csbxint{OctToBin}&711660&2134980&main memory size=5000000\\ |
| 16215 |
\csbxint{BinToHex}&1992650&498163&main memory size=5000000\\ |
| 16216 |
\csbxint{BinToOct}&1868109&622703&main memory size=5000000\\ |
| 16217 |
%\csbxint{CHexToBin}&553513&2214052&main memory size=5000000.\\ |
| 16218 |
%\csbxint{COctToBin}&711660&2134980&main memory size=5000000.\\ |
| 16219 |
\hline |
| 16220 |
\end{tabular} |
| 16221 |
\captionof{table}{Maximal sizes for \xintbinhexname 1.4n macros with TeXLive 2025}\label{tab:binhexsizes} |
| 16222 |
\endgroup |
| 16223 |
|
| 16224 |
% \medskip |
| 16225 |
|
| 16226 |
% These sizes are larger (and very significantly so for the |bin<->hex| |
| 16227 |
% conversions) than with the previous release. For comparison |
| 16228 |
% \autoref{tab:binhexsizes14m} was computed using |1.4m 2022/06/10| and |
| 16229 |
% TeXLive 2025 with its default memory settings which are: input stack |
| 16230 |
% size at \dtt{10000}, expansion depth at \dtt{10000}, parameter stack |
| 16231 |
% size at \dtt{20000}. The previous last update to that table in this |
| 16232 |
% documentation had been done using \xintbinhexname |1.2n| and TeXLive |
| 16233 |
% 2021, the input stack size was only at \dtt{5000} and it was then the |
| 16234 |
% limiting factor in all cases and the maximal input sizes in 2021 were |
| 16235 |
% (in almost all cases) about half of the displayed values. |
| 16236 |
|
| 16237 |
% %! (except for |
| 16238 |
% %! \csbxint{HexToDec} maximal input size which was at \dtt{8298} digits). |
| 16239 |
|
| 16240 |
% \medskip |
| 16241 |
% \begingroup |
| 16242 |
% \makeatletter\def\@captype{table}\capstart |
| 16243 |
% \centering |
| 16244 |
% \begin{tabular}{rrrr} |
| 16245 |
% \hline |
| 16246 |
% &Max\ length\ of\ input&->\ length\ of\ output&Limiting factor\\ |
| 16247 |
% \csbxint{DecToHex}&12035&9995&input stack size=10000\\ |
| 16248 |
% \csbxint{DecToBin}&12035&39980&input stack size=10000\\ |
| 16249 |
% \csbxint{HexToDec}&11072&13333&expansion depth=10000\\ |
| 16250 |
% \csbxint{BinToDec}&39984&12037&expansion depth=10000\\ |
| 16251 |
% \csbxint{HexToBin}&9996&39984&expansion depth=10000\\ |
| 16252 |
% % \csbxint{CHexToBin}&9996&39984&expansion depth=10000\\ |
| 16253 |
% \csbxint{BinToHex}&39984&9996&expansion depth=10000\\ |
| 16254 |
% \hline |
| 16255 |
% \end{tabular} |
| 16256 |
% \captionof{table}{Maximal sizes for \xintbinhexname 1.4m 2022/06/10, |
| 16257 |
% but with TeXLive 2025 memory settings}\label{tab:binhexsizes14m} |
| 16258 |
% \endgroup |
| 16259 |
|
| 16260 |
|
| 16261 |
\clearpage |
| 16262 |
\let\xintbinhexnameUp\undefined |
| 16263 |
\csname xintgcdnameUp\endcsname |
| 16264 |
\def\n{|{N}|} |
| 16265 |
\def\m{|{M}|} |
| 16266 |
\def\x{|{x}|} |
| 16267 |
\section{Macros of the \xintgcdname package} |
| 16268 |
\RaisedLabel{sec:gcd} |
| 16269 |
|
| 16270 |
\localtableofcontents |
| 16271 |
|
| 16272 |
This package was included in the original release |1.0| (|2013/03/28|) of the |
| 16273 |
\xintbundlename. |
| 16274 |
|
| 16275 |
|
| 16276 |
|
| 16277 |
At |1.3d| macros \csbxint{iiGCD} and \csbxint{iiLCM} are copied over to |
| 16278 |
\xintname, hence \func{gcd} and \func{lcm} functions in \csbxint{iiexpr} were |
| 16279 |
available simply from loading only \xintexprname, and the \xintgcdname dependency |
| 16280 |
got removed. |
| 16281 |
|
| 16282 |
\begin{framed} |
| 16283 |
From |1.1| to |1.3f| the package loaded only \xintcorename, |
| 16284 |
not \xintname and neither \xinttoolsname. |
| 16285 |
|
| 16286 |
But at |1.4| it loads automatically both \xintname and \xinttoolsname (the |
| 16287 |
latter being a requirement since |1.09h| of the \csbxint{TypesetEuclideAlgorithm} and |
| 16288 |
\csbxint{TypesetBezoutAlgorithm} macros). |
| 16289 |
|
| 16290 |
The macros \csbxint{iiGCD} and \csbxint{iiLCM} got relocated into |
| 16291 |
\xintname. \IMPORTANTf The macros \csbxint{GCD}, \csbxint{LCM}, |
| 16292 |
\csbxint{GCDof}, and \csbxint{LCMof} are \emph{removed}: |
| 16293 |
\xintfracname provides under these names more powerful macros handling |
| 16294 |
general fractions and not only integers. |
| 16295 |
\end{framed} |
| 16296 |
|
| 16297 |
\subsection{\csh{xintBezout}}\label{xintBezout} |
| 16298 |
|
| 16299 |
|\xintBezout|\n\m\etype{\Numf\Numf} returns three numbers |U|, |V|, |
| 16300 |
|D| within braces where |D| is the (non-negative) GCD, and \dtt{UN + VM = D}. |
| 16301 |
\begin{everbatim*} |
| 16302 |
\oodef\X{\xintBezout {10000}{1113}}\meaning\X\par |
| 16303 |
\xintAssign {\xintBezout {10000}{1113}}\to\U\V\D |
| 16304 |
U: \meaning\U, V: \meaning\V, D: \meaning\D\par |
| 16305 |
AU+BV: \xinttheiiexpr 10000*\U+1113*\V\relax\par |
| 16306 |
\noindent\oodef\X{\xintBezout {123456789012345}{9876543210321}}\meaning\X\par |
| 16307 |
\xintAssign \X\to\U\V\D |
| 16308 |
U: \meaning\U, V: \meaning\V, D: \meaning\D\par |
| 16309 |
AU+BV: \xinttheiiexpr 123456789012345*\U+9876543210321*\V\relax |
| 16310 |
\end{everbatim*} |
| 16311 |
|
| 16312 |
\subsection{\csh{xintEuclideAlgorithm}}\label{xintEuclideAlgorithm} |
| 16313 |
|
| 16314 |
|\xintEuclideAlgorithm|\n\m\etype{\Numf\Numf} applies the Euclide algorithm |
| 16315 |
and keeps a copy of all quotients and remainders. |
| 16316 |
\begin{everbatim*} |
| 16317 |
\edef\X{\xintEuclideAlgorithm {10000}{1113}}\meaning\X |
| 16318 |
\end{everbatim*} |
| 16319 |
|
| 16320 |
The first item is the number of steps, the second is |N|, the |
| 16321 |
third is the GCD, the fourth is |M| then the first quotient and |
| 16322 |
remainder, the second quotient and remainder, \dots until the |
| 16323 |
final quotient and last (zero) remainder. |
| 16324 |
|
| 16325 |
\subsection{\csh{xintBezoutAlgorithm}}\label{xintBezoutAlgorithm} |
| 16326 |
|
| 16327 |
|\xintBezoutAlgorithm|\n\m\etype{\Numf\Numf} applies the Euclide algorithm |
| 16328 |
and keeps a copy of all quotients and remainders. Furthermore it computes the |
| 16329 |
entries of the successive products of the 2 by 2 matrices |
| 16330 |
$\left(\vcenter{\halign {\,#&\,#\cr q & 1 \cr 1 & 0 \cr}}\right)$ formed from |
| 16331 |
the quotients arising in the algorithm. |
| 16332 |
\begin{everbatim*} |
| 16333 |
\edef\X{\xintBezoutAlgorithm {10000}{1113}}\printnumber{\meaning\X} |
| 16334 |
\end{everbatim*} |
| 16335 |
|
| 16336 |
The first item is the number of steps, the second is |N|, then |
| 16337 |
|0|, |1|, the GCD, |M|, |1|, |0|, the first quotient, the first |
| 16338 |
remainder, the top left entry of the first matrix, the bottom left |
| 16339 |
entry, and then these four things at each step until the end. |
| 16340 |
|
| 16341 |
\subsection{\csh{xintTypesetEuclideAlgorithm}}\label{xintTypesetEuclideAlgorithm} |
| 16342 |
|
| 16343 |
This macro is just an example of how to organize the data returned by |
| 16344 |
\csa{xintEuclideAlgorithm}.\ntype{\Numf\Numf} Copy the source code to a new |
| 16345 |
macro and modify it to what is needed. |
| 16346 |
|
| 16347 |
\leftedline{|\xintTypesetEuclideAlgorithm {123456789012345}{9876543210321}|} |
| 16348 |
\xintTypesetEuclideAlgorithm {123456789012345}{9876543210321} |
| 16349 |
|
| 16350 |
\subsection{\csh{xintTypesetBezoutAlgorithm}}% |
| 16351 |
\label{xintTypesetBezoutAlgorithm} |
| 16352 |
|
| 16353 |
This macro is just an example of how to organize the data returned by |
| 16354 |
\csa{xintBezoutAlgorithm}.\ntype{\Numf\Numf} Copy the source code to a new |
| 16355 |
macro and modify it to what is needed. |
| 16356 |
|
| 16357 |
\leftedline{|\xintTypesetBezoutAlgorithm {10000}{1113}|} |
| 16358 |
\xintTypesetBezoutAlgorithm {10000}{1113} |
| 16359 |
|
| 16360 |
\clearpage |
| 16361 |
\let\xintgcdnameUp\undefined |
| 16362 |
\csname xintseriesnameUp\endcsname |
| 16363 |
\def\n{|{N}|} |
| 16364 |
\def\m{|{M}|} |
| 16365 |
\def\x{|{x}|} |
| 16366 |
\section{Macros of the \xintseriesname package} |
| 16367 |
\RaisedLabel{sec:series} |
| 16368 |
|
| 16369 |
\localtableofcontents |
| 16370 |
|
| 16371 |
This package was first released with version |1.03| (|2013/04/14|) of the |
| 16372 |
\xintbundlename. |
| 16373 |
|
| 16374 |
The \Ff{} expansion type of various macro arguments is only a \Numf{} if only |
| 16375 |
\xintname but not \xintfracname is loaded. The macro \csbxint{iSeries} is |
| 16376 |
special and expects summing big integers obeying the strict format, even if |
| 16377 |
\xintfracname is loaded. |
| 16378 |
|
| 16379 |
The arguments serving as indices are of the \numx{} expansion type. |
| 16380 |
|
| 16381 |
In some cases one or two of the macro arguments are only expanded at a later |
| 16382 |
stage not immediately. |
| 16383 |
|
| 16384 |
\begin{framed} |
| 16385 |
Since |1.3|, \csbxint{Add} and \csbxint{Sub} use systematically the least |
| 16386 |
common multiple of the denominators. Some of the comments in this chapter |
| 16387 |
refer to the earlier situation where often the denominators were simply |
| 16388 |
multiplied together. \emph{They have yet to be updated to reflect the new |
| 16389 |
situation brought by the |1.3| release.} Some of these comments may now be |
| 16390 |
off-synced from the actual computation results and thus may be wrong. |
| 16391 |
\end{framed} |
| 16392 |
%% \clearpage |
| 16393 |
|
| 16394 |
\subsection{\csh{xintSeries}}\label{xintSeries} |
| 16395 |
|
| 16396 |
\csa{xintSeries}|{A}{B}{\coeff}|\etype{\numx\numx\Ff} computes |
| 16397 |
$\sum_{\text{|n=A|}}^{\text{|n=B|}}$|\coeff{n}|. The initial and final indices |
| 16398 |
must obey the |\numexpr| constraint of expanding to numbers at most |2^31-1|. |
| 16399 |
The |\coeff| macro must be a one-parameter \fexpan dable macro, taking on |
| 16400 |
input an explicit number |n| and producing some number or fraction |\coeff{n}|; |
| 16401 |
it is expanded at the time it is |
| 16402 |
needed.% |
| 16403 |
% |
| 16404 |
|
| 16405 |
\begin{everbatim*} |
| 16406 |
\def\coeff #1{\xintiiMON{#1}/#1.5} % (-1)^n/(n+1/2) |
| 16407 |
\fdef\w {\xintSeries {0}{50}{\coeff}} % we want to re-use it |
| 16408 |
\fdef\z {\xintJrr {\w}[0]} % the [0] for a microsecond gain. |
| 16409 |
% \xintJrr preferred to \xintIrr: a big common factor is suspected. |
| 16410 |
% But numbers much bigger would be needed to show the greater efficiency. |
| 16411 |
\[ \sum_{n=0}^{n=50} \frac{(-1)^n}{n+\frac12} = \xintTeXFrac\z \] |
| 16412 |
\end{everbatim*} |
| 16413 |
|
| 16414 |
The definition of |\coeff| as |\xintiiMON{#1}/#1.5| is quite suboptimal. It |
| 16415 |
allows |#1| to be a big integer, but anyhow only small integers are accepted |
| 16416 |
as initial and final indices (they are of the \numx{} type). Second, when the |
| 16417 |
\xintfracname parser sees the |#1.5| it will remove the dot hence create a |
| 16418 |
denominator with one digit more. For example |1/3.5| turns internally into |
| 16419 |
|10/35| whereas it would be more efficient to have |2/7|. For info here is the |
| 16420 |
non-reduced |\w|: |
| 16421 |
\[\xintTeXFrac\w\] |
| 16422 |
It would have been bigger still in releases earlier than |1.1|: now, the |
| 16423 |
\xintfracname \csbxint{Add} routine does not multiply blindly denominators |
| 16424 |
anymore, it checks if one is a multiple of the other. However it does not |
| 16425 |
practice systematic reduction to lowest terms. |
| 16426 |
|
| 16427 |
A more efficient way to code |\coeff| is illustrated next. |
| 16428 |
\begin{everbatim*} |
| 16429 |
\def\coeff #1{\the\numexpr\ifodd #1 -2\else2\fi\relax/\the\numexpr 2*#1+1\relax [0]}% |
| 16430 |
% The [0] in \coeff is a tiny optimization: in its presence the \xintfracname parser |
| 16431 |
% sees something which is already in internal format. |
| 16432 |
\fdef\w {\xintSeries {0}{50}{\coeff}} |
| 16433 |
\[\sum_{n=0}^{n=50} \frac{(-1)^n}{n+\frac12}=\xintTeXFrac\w\] |
| 16434 |
\end{everbatim*} |
| 16435 |
The reduced form |\z| as displayed above only differs from this one by a |
| 16436 |
factor of \dtt{\xintNum {\xintDenominator\w/\xintDenominator\z}}. |
| 16437 |
|
| 16438 |
\setlength{\columnsep}{0pt} |
| 16439 |
\everb|@ |
| 16440 |
\def\coeffleibnitz #1{\the\numexpr\ifodd #1 1\else-1\fi\relax/#1[0]} |
| 16441 |
\cnta 1 |
| 16442 |
\loop |
| 16443 |
% in this loop we recompute from scratch each partial sum! |
| 16444 |
% we can afford that, as \xintSeries is fast enough. |
| 16445 |
\noindent\hbox to 2em{\hfil\texttt{\the\cnta.} }% |
| 16446 |
\xintTrunc {12}{\xintSeries {1}{\cnta}{\coeffleibnitz}}\dots |
| 16447 |
\endgraf |
| 16448 |
\ifnum\cnta < 30 \advance\cnta 1 \repeat |
| 16449 |
| |
| 16450 |
|
| 16451 |
\begin{multicols}{3} |
| 16452 |
\def\coeffleibnitz #1{\the\numexpr\ifodd #1 1\else-1\fi\relax/#1[0]} \cnta 1 |
| 16453 |
\loop |
| 16454 |
\noindent\hbox to 2em{\hfil\dtt{\the\cnta.} }% |
| 16455 |
\xintTrunc {12}{\xintSeries {1}{\cnta}{\coeffleibnitz}}\dots |
| 16456 |
\endgraf |
| 16457 |
\ifnum\cnta < 30 \advance\cnta 1 \repeat |
| 16458 |
\end{multicols} |
| 16459 |
|
| 16460 |
\subsection{\csh{xintiSeries}}\label{xintiSeries} |
| 16461 |
|
| 16462 |
\def\coeff #1{\xintiTrunc {40} |
| 16463 |
{\the\numexpr\ifodd #1 -2\else2\fi\relax/\the\numexpr 2*#1+1\relax [0]}}% |
| 16464 |
|
| 16465 |
\csa{xintiSeries}|{A}{B}{\coeff}|\etype{\numx\numx f} computes |
| 16466 |
$\sum_{\text{|n=A|}}^{\text{|n=B|}}$|\coeff{n}| where |\coeff{n}| |
| 16467 |
must \fexpan d to a (possibly long) integer in the strict format. |
| 16468 |
\everb|@ |
| 16469 |
\def\coeff #1{\xintiTrunc {40}{\xintiiMON{#1}/#1.5}}% |
| 16470 |
% better: |
| 16471 |
\def\coeff #1{\xintiTrunc {40} |
| 16472 |
{\the\numexpr 2*\xintiiMON{#1}\relax/\the\numexpr 2*#1+1\relax [0]}}% |
| 16473 |
% better still: |
| 16474 |
\def\coeff #1{\xintiTrunc {40} |
| 16475 |
{\the\numexpr\ifodd #1 -2\else2\fi\relax/\the\numexpr 2*#1+1\relax [0]}}% |
| 16476 |
% (-1)^n/(n+1/2) times 10^40, truncated to an integer. |
| 16477 |
\[ \sum_{n=0}^{n=50} \frac{(-1)^n}{n+\frac12} \approx |
| 16478 |
\xintTrunc {40}{\xintiSeries {0}{50}{\coeff}[-40]}\dots\] |
| 16479 |
| |
| 16480 |
|
| 16481 |
\[ \sum_{n=0}^{n=50} \frac{(-1)^n}{n+\frac12} \approx \xintTrunc |
| 16482 |
{40}{\xintiSeries {0}{50}{\coeff}[-40]}\] |
| 16483 |
|
| 16484 |
We should have cut out at |
| 16485 |
least the last two digits: truncating errors originating with the first |
| 16486 |
coefficients of the sum will never go away, and each truncation |
| 16487 |
introduces an uncertainty in the last digit, so as we have 40 terms, we |
| 16488 |
should trash the last two digits, or at least round at 38 digits. It is |
| 16489 |
interesting to compare with the computation where rounding rather than |
| 16490 |
truncation is used, and with the decimal |
| 16491 |
expansion of the exactly computed partial sum of the series: |
| 16492 |
\everb|@ |
| 16493 |
\def\coeff #1{\xintiRound {40} % rounding at 40 |
| 16494 |
{\the\numexpr\ifodd #1 -2\else2\fi\relax/\the\numexpr 2*#1+1\relax [0]}}% |
| 16495 |
% (-1)^n/(n+1/2) times 10^40, rounded to an integer. |
| 16496 |
\[ \sum_{n=0}^{n=50} \frac{(-1)^n}{n+\frac12} \approx |
| 16497 |
\xintTrunc {40}{\xintiSeries {0}{50}{\coeff}[-40]}\] |
| 16498 |
\def\exactcoeff #1% |
| 16499 |
{\the\numexpr\ifodd #1 -2\else2\fi\relax/\the\numexpr 2*#1+1\relax [0]}% |
| 16500 |
\[ \sum_{n=0}^{n=50} \frac{(-1)^n}{n+\frac12} |
| 16501 |
= \xintTrunc {50}{\xintSeries {0}{50}{\exactcoeff}}\dots\] |
| 16502 |
| |
| 16503 |
|
| 16504 |
\def\coeff #1{\xintiRound {40} |
| 16505 |
{\the\numexpr\ifodd #1 -2\else2\fi\relax/\the\numexpr 2*#1+1\relax [0]}}% |
| 16506 |
% (-1)^n/(n+1/2) times 10^40, rounded to an integer. |
| 16507 |
\[ \sum_{n=0}^{n=50} \frac{(-1)^n}{n+\frac12} \approx |
| 16508 |
\xintTrunc {40}{\xintiSeries {0}{50}{\coeff}[-40]}\] |
| 16509 |
\def\exactcoeff #1% |
| 16510 |
{\the\numexpr\ifodd #1 -2\else2\fi\relax/\the\numexpr 2*#1+1\relax [0]}% |
| 16511 |
\[ \sum_{n=0}^{n=50} \frac{(-1)^n}{n+\frac12} |
| 16512 |
= \xintTrunc {50}{\xintSeries {0}{50}{\exactcoeff}}\dots\] |
| 16513 |
This shows indeed that our sum of truncated terms |
| 16514 |
estimated wrongly the 39th and 40th digits of the exact result% |
| 16515 |
% |
| 16516 |
\footnote{as the series is alternating, we can roughly expect an error |
| 16517 |
of $\sqrt{40}$ and the last two digits are off by 4 units, which is |
| 16518 |
not contradictory to our expectations.} |
| 16519 |
% |
| 16520 |
and that the sum of rounded terms fared a bit better. |
| 16521 |
|
| 16522 |
\subsection{\csh{xintRationalSeries}}\label{xintRationalSeries} |
| 16523 |
|
| 16524 |
|
| 16525 |
\noindent \csa{xintRationalSeries}|{A}{B}{f}{\ratio}|\etype{\numx\numx\Ff\Ff} |
| 16526 |
evaluates $\sum_{\text{|n=A|}}^{\text{|n=B|}}$|F(n)|, where |F(n)| is specified |
| 16527 |
indirectly via the data of |f=F(A)| and the one-parameter macro |\ratio| which |
| 16528 |
must be such that |\macro{n}| expands to |F(n)/F(n-1)|. The name indicates that |
| 16529 |
\csa{xintRationalSeries} was designed to be useful in the cases where |
| 16530 |
|F(n)/F(n-1)| is a rational function of |n| but it may be anything expanding to |
| 16531 |
a fraction. The macro |\ratio| must be an expandable-only compatible macro and |
| 16532 |
expand to its value after iterated full expansion of its first item. |A| and |
| 16533 |
|B| are fed to a |\numexpr| hence may be count registers or arithmetic |
| 16534 |
expressions built with such; they must obey the \TeX{} bound. The initial term |
| 16535 |
|f| may be a macro |\f|, it will be expanded to its value representing |F(A)|. |
| 16536 |
|
| 16537 |
\begin{everbatim*} |
| 16538 |
\def\ratio #1{2/#1[0]}% 2/n, to compute exp(2) |
| 16539 |
\cnta 0 % previously declared count |
| 16540 |
\begin{quote} |
| 16541 |
\loop \fdef\z {\xintRationalSeries {0}{\cnta}{1}{\ratio }}% |
| 16542 |
\noindent$\sum_{n=0}^{\the\cnta} \frac{2^n}{n!}= |
| 16543 |
\xintTrunc{12}\z\dots= |
| 16544 |
\xintTeXFrac\z=\xintTeXFrac{\xintIrr\z}$\vtop to 5pt{}\par |
| 16545 |
\ifnum\cnta<20 \advance\cnta 1 \repeat |
| 16546 |
\end{quote} |
| 16547 |
\end{everbatim*} |
| 16548 |
|
| 16549 |
\begin{everbatim*} |
| 16550 |
\def\ratio #1{-1/#1[0]}% -1/n, comes from the series of exp(-1) |
| 16551 |
\cnta 0 % previously declared count |
| 16552 |
\begin{quote} |
| 16553 |
\loop |
| 16554 |
\fdef\z {\xintRationalSeries {0}{\cnta}{1}{\ratio }}% |
| 16555 |
\noindent$\sum_{n=0}^{\the\cnta} \frac{(-1)^n}{n!}= |
| 16556 |
\xintTrunc{20}\z\dots=\xintTeXFrac{\z}=\xintTeXFrac{\xintIrr\z}$% |
| 16557 |
\vtop to 5pt{}\par |
| 16558 |
\ifnum\cnta<20 \advance\cnta 1 \repeat |
| 16559 |
\end{quote} |
| 16560 |
\end{everbatim*} |
| 16561 |
|
| 16562 |
|
| 16563 |
\def\ratioexp #1#2{\xintDiv{#1}{#2}}% #1/#2 |
| 16564 |
|
| 16565 |
\medskip We can incorporate an indeterminate if we define |\ratio| to be |
| 16566 |
a macro with two parameters: |\def\ratioexp |
| 16567 |
#1#2{\xintDiv{#1}{#2}}|\texttt{\%}| x/n: x=#1, n=#2|. |
| 16568 |
Then, if |\x| expands to some fraction |x|, the |
| 16569 |
macro % |
| 16570 |
% |
| 16571 |
\leftedline{|\xintRationalSeries {0}{b}{1}{\ratioexp{\x}}|} |
| 16572 |
will compute $\sum_{n=0}^{n=b} x^n/n!$:\par |
| 16573 |
\begin{everbatim*} |
| 16574 |
\cnta 0 |
| 16575 |
\def\ratioexp #1#2{\xintDiv{#1}{#2}}% #1/#2 |
| 16576 |
\loop |
| 16577 |
\noindent |
| 16578 |
$\sum_{n=0}^{\the\cnta} (.57)^n/n! = \xintTrunc {50} |
| 16579 |
{\xintRationalSeries {0}{\cnta}{1}{\ratioexp{.57}}}\dots$ |
| 16580 |
\vtop to 5pt {}\endgraf |
| 16581 |
\ifnum\cnta<50 \advance\cnta 10 \repeat |
| 16582 |
\end{everbatim*} |
| 16583 |
|
| 16584 |
Observe that in this last example the |x| was directly inserted; if it |
| 16585 |
had been a more complicated explicit fraction it would have been |
| 16586 |
worthwile to use |\ratioexp\x| with |\x| defined to expand to its value. |
| 16587 |
In the further situation where this fraction |x| is not explicit but |
| 16588 |
itself defined via a complicated, and time-costly, formula, it should be |
| 16589 |
noted that \csa{xintRationalSeries} will do again the evaluation of |\x| |
| 16590 |
for each term of the partial sum. The easiest is thus when |x| can be |
| 16591 |
defined as an |\edef|. If however, you are in an expandable-only context |
| 16592 |
and cannot store in a macro like |\x| the value to be used, a variant of |
| 16593 |
\csa{xintRationalSeries} is needed which will first evaluate this |\x| and then |
| 16594 |
use this result without recomputing it. This is \csbxint{RationalSeriesX}, |
| 16595 |
documented next. |
| 16596 |
|
| 16597 |
Here is a slightly more complicated evaluation: |
| 16598 |
\begin{everbatim*} |
| 16599 |
\cnta 1 |
| 16600 |
\begin{multicols}{2} |
| 16601 |
\loop \fdef\z {\xintRationalSeries |
| 16602 |
{\cnta} |
| 16603 |
{2*\cnta-1} |
| 16604 |
{\xintiiPow {\the\cnta}{\cnta}/\xintiiFac{\cnta}} |
| 16605 |
{\ratioexp{\the\cnta}}}% |
| 16606 |
\fdef\w {\xintRationalSeries {0}{2*\cnta-1}{1}{\ratioexp{\the\cnta}}}% |
| 16607 |
\noindent |
| 16608 |
$\sum_{n=\the\cnta}^{\the\numexpr 2*\cnta-1\relax} \frac{\the\cnta^n}{n!}/% |
| 16609 |
\sum_{n=0}^{\the\numexpr 2*\cnta-1\relax} \frac{\the\cnta^n}{n!} = |
| 16610 |
\xintTrunc{8}{\xintDiv\z\w}\dots$ \vtop to 5pt{}\endgraf |
| 16611 |
\ifnum\cnta<20 \advance\cnta 1 \repeat |
| 16612 |
\end{multicols} |
| 16613 |
\end{everbatim*} |
| 16614 |
|
| 16615 |
|
| 16616 |
\subsection{\csh{xintRationalSeriesX}}\label{xintRationalSeriesX} |
| 16617 |
|
| 16618 |
|
| 16619 |
\noindent\csa{xintRationalSeriesX}|{A}{B}{\first}{\ratio}{\g}|% |
| 16620 |
\etype{\numx\numx\Ff\Ff f} is a parametrized version of \csa{xintRationalSeries} |
| 16621 |
where |\first| is now a one-parameter macro such that |\first{\g}| gives the |
| 16622 |
initial term and |\ratio| is a two-parameter macro such that |\ratio{n}{\g}| |
| 16623 |
represents the ratio of one term to the previous one. The parameter |\g| is |
| 16624 |
evaluated only once at the beginning of the computation, and can thus itself be |
| 16625 |
the yet unevaluated result of a previous computation. |
| 16626 |
|
| 16627 |
Let |\ratio| be such a two-parameter macro; note the subtle differences |
| 16628 |
between% |
| 16629 |
% |
| 16630 |
\leftedline{|\xintRationalSeries {A}{B}{\first}{\ratio{\g}}|} |
| 16631 |
% |
| 16632 |
\leftedline{and |\xintRationalSeriesX {A}{B}{\first}{\ratio}{\g}|.} First the |
| 16633 |
location of braces differ...\@{} then, in the former case |\first| is a |
| 16634 |
\emph{no-parameter} macro expanding to a fractional number, and in the latter, |
| 16635 |
it is a |
| 16636 |
\emph{one-parameter} macro which will use |\g|. Furthermore the |X| variant |
| 16637 |
will expand |\g| at the very beginning whereas the former non-|X| former variant |
| 16638 |
will evaluate it each time it needs it (which is bad if this |
| 16639 |
evaluation is time-costly, but good if |\g| is a big explicit fraction |
| 16640 |
encapsulated in a macro). |
| 16641 |
|
| 16642 |
The example will use the macro \csbxint{PowerSeries} which computes |
| 16643 |
efficiently exact partial sums of power series, and is discussed in the |
| 16644 |
next section. |
| 16645 |
\begin{everbatim*} |
| 16646 |
\def\firstterm #1{1[0]}% first term of the exponential series |
| 16647 |
% although it is the constant 1, here it must be defined as a |
| 16648 |
% one-parameter macro. Next comes the ratio function for exp: |
| 16649 |
\def\ratioexp #1#2{\xintDiv {#1}{#2}}% x/n |
| 16650 |
% These are the (-1)^{n-1}/n of the log(1+h) series: |
| 16651 |
\def\coefflog #1{\the\numexpr\ifodd #1 1\else-1\fi\relax/#1[0]}% |
| 16652 |
% Let L(h) be the first 10 terms of the log(1+h) series and |
| 16653 |
% let E(t) be the first 10 terms of the exp(t) series. |
| 16654 |
% The following computes E(L(a/10)) for a=1,...,12. |
| 16655 |
\begin{multicols}{3}\raggedcolumns |
| 16656 |
\cnta 0 |
| 16657 |
\loop |
| 16658 |
\noindent\xintTrunc {18}{% |
| 16659 |
\xintRationalSeriesX {0}{9}{\firstterm}{\ratioexp} |
| 16660 |
{\xintPowerSeries{1}{10}{\coefflog}{\the\cnta[-1]}}}\dots |
| 16661 |
\endgraf |
| 16662 |
\ifnum\cnta < 12 \advance \cnta 1 \repeat |
| 16663 |
\end{multicols} |
| 16664 |
\end{everbatim*} |
| 16665 |
|
| 16666 |
|
| 16667 |
These completely exact operations rapidly create numbers with many digits. Let |
| 16668 |
us print in full the raw fractions created by the operation illustrated above: |
| 16669 |
|
| 16670 |
\fdef\z{\xintRationalSeriesX {0}{9}{\firstterm} |
| 16671 |
{\ratioexp}{\xintPowerSeries{1}{10}{\coefflog}{1[-1]}}} |
| 16672 |
|
| 16673 |
|E(L(1[-1]))=|\dtt{\printnumber{\z}} (length of numerator: |
| 16674 |
\xintLen {\xintNumerator \z}) |
| 16675 |
|
| 16676 |
\fdef\z{\xintRationalSeriesX {0}{9}{\firstterm} |
| 16677 |
{\ratioexp}{\xintPowerSeries{1}{10}{\coefflog}{12[-2]}}} |
| 16678 |
|
| 16679 |
|E(L(12[-2]))=|\dtt{\printnumber{\z}} (length of numerator: |
| 16680 |
\xintLen {\xintNumerator \z}) |
| 16681 |
|
| 16682 |
\fdef\z{\xintRationalSeriesX {0}{9}{\firstterm} |
| 16683 |
{\ratioexp}{\xintPowerSeries{1}{10}{\coefflog}{123[-3]}}} |
| 16684 |
|
| 16685 |
|E(L(123[-3]))=|\dtt{\printnumber{\z}} (length of numerator: |
| 16686 |
\xintLen {\xintNumerator \z}) |
| 16687 |
|
| 16688 |
We see that the denominators here remain the same, as our input only had various |
| 16689 |
powers of ten as denominators, and \xintfracname efficiently assemble (some |
| 16690 |
only, as we can see) powers of ten. Notice that 1 more digit in an input |
| 16691 |
denominator seems to mean 90 more in the raw output. We can check that with some |
| 16692 |
other test cases: |
| 16693 |
|
| 16694 |
\fdef\z{\xintRationalSeriesX {0}{9}{\firstterm} |
| 16695 |
{\ratioexp}{\xintPowerSeries{1}{10}{\coefflog}{1/7}}} |
| 16696 |
|
| 16697 |
|E(L(1/7))=|\dtt{\printnumber{\z}} (length of numerator: |
| 16698 |
\xintLen {\xintNumerator \z}; length of denominator: |
| 16699 |
\xintLen {\xintDenominator \z}) |
| 16700 |
|
| 16701 |
\fdef\z{\xintRationalSeriesX {0}{9}{\firstterm} |
| 16702 |
{\ratioexp}{\xintPowerSeries{1}{10}{\coefflog}{1/71}}} |
| 16703 |
|
| 16704 |
|E(L(1/71))=|\dtt{\printnumber{\z}} (length of numerator: |
| 16705 |
\xintLen {\xintNumerator \z}; length of denominator: |
| 16706 |
\xintLen {\xintDenominator \z}) |
| 16707 |
|
| 16708 |
\fdef\z{\xintRationalSeriesX {0}{9}{\firstterm} |
| 16709 |
{\ratioexp}{\xintPowerSeries{1}{10}{\coefflog}{1/712}}} |
| 16710 |
|
| 16711 |
|E(L(1/712))=|\dtt{\printnumber{\z}} (length of numerator: |
| 16712 |
\xintLen {\xintNumerator \z}; length of denominator: |
| 16713 |
\xintLen {\xintDenominator \z}) |
| 16714 |
|
| 16715 |
|
| 16716 |
Thus |
| 16717 |
decimal numbers such as |0.123| (equivalently |
| 16718 |
|123[-3]|) give less computing intensive tasks than fractions such as |1/712|: |
| 16719 |
in the case of decimal numbers the (raw) denominators originate in the |
| 16720 |
coefficients of the series themselves, powers of ten of the input within |
| 16721 |
brackets being treated separately. And even then the |
| 16722 |
numerators will grow with the size of the input in a sort of linear way, the |
| 16723 |
coefficient being given by the order of series: here 10 from the log and 9 from |
| 16724 |
the exp, so 90. One more digit in the input means 90 more digits in the |
| 16725 |
numerator of the output: obviously we can not go on composing such partial sums |
| 16726 |
of series and hope that \xintname will joyfully do all at the speed of light! |
| 16727 |
|
| 16728 |
Hence, truncating the output (or better, rounding) is the only way to go if one |
| 16729 |
needs a general calculus of special functions. This is why the package |
| 16730 |
\xintseriesname provides, besides \csbxint{Series}, \csbxint{RationalSeries}, or |
| 16731 |
\csbxint{PowerSeries} which compute \emph{exact} sums, |
| 16732 |
\csbxint{FxPtPowerSeries} for fixed-point computations and a (tentative naive) |
| 16733 |
\csbxint{FloatPowerSeries}. |
| 16734 |
|
| 16735 |
\subsection{\csh{xintPowerSeries}}\label{xintPowerSeries} |
| 16736 |
|
| 16737 |
\csa{xintPowerSeries}|{A}{B}{\coeff}{f}|\etype{\numx\numx\Ff\Ff} |
| 16738 |
evaluates the sum |
| 16739 |
$\sum_{\text{|n=A|}}^{\text{|n=B|}}$|\coeff{n}|${}\cdot \text{|f|}^{\text{|n|}}$. The |
| 16740 |
initial and final indices are given to a |\numexpr| expression. The |\coeff| |
| 16741 |
macro (which, as argument to \csa{xintPowerSeries} is expanded only at the time |
| 16742 |
|\coeff{n}| is needed) should be defined as a one-parameter expandable macro, |
| 16743 |
its input will be an explicit number. |
| 16744 |
|
| 16745 |
The |f| can be either a fraction directly input or a macro |\f| expanding to |
| 16746 |
such a fraction. It is actually more efficient to encapsulate an explicit |
| 16747 |
fraction |f| in such a macro, if it has big numerators and denominators (`big' |
| 16748 |
means hundreds of digits) as it will then take less space in the processing |
| 16749 |
until being (repeatedly) used. |
| 16750 |
|
| 16751 |
This macro computes the \emph{exact} result (one can use it also for |
| 16752 |
polynomial evaluation), using a Horner scheme which helps avoiding a |
| 16753 |
denominator build-up (this problem however, even if using a naive additive |
| 16754 |
approach, is much less acute since release |1.1| and its new policy regarding |
| 16755 |
\csbxint{Add}). |
| 16756 |
|
| 16757 |
\begin{everbatim*} |
| 16758 |
\def\geom #1{1[0]} % the geometric series |
| 16759 |
\def\f {5/17[0]} |
| 16760 |
\[ \sum_{n=0}^{n=20} \Bigl(\frac 5{17}\Bigr)^n |
| 16761 |
=\xintTeXFrac{\xintIrr{\xintPowerSeries {0}{20}{\geom}{\f}}} |
| 16762 |
=\xintTeXFrac{\xinttheexpr (17^21-5^21)/12/17^20\relax}\] |
| 16763 |
\end{everbatim*} |
| 16764 |
|
| 16765 |
\begin{everbatim*} |
| 16766 |
\def\coefflog #1{1/#1[0]}% 1/n |
| 16767 |
\def\f {1/2[0]}% |
| 16768 |
\[ \log 2 \approx \sum_{n=1}^{20} \frac1{n\cdot 2^n} |
| 16769 |
= \xintTeXFrac {\xintIrr {\xintPowerSeries {1}{20}{\coefflog}{\f}}}\] |
| 16770 |
\[ \log 2 \approx \sum_{n=1}^{50} \frac1{n\cdot 2^n} |
| 16771 |
= \xintTeXFrac {\xintIrr {\xintPowerSeries {1}{50}{\coefflog}{\f}}}\] |
| 16772 |
\end{everbatim*} |
| 16773 |
|
| 16774 |
|
| 16775 |
\begin{everbatim*} |
| 16776 |
\setlength{\columnsep}{0pt} |
| 16777 |
\begin{multicols}{3} |
| 16778 |
\cnta 1 % previously declared count |
| 16779 |
\loop % in this loop we recompute from scratch each partial sum! |
| 16780 |
% we can afford that, as \xintPowerSeries is fast enough. |
| 16781 |
\noindent\hbox to 2em{\hfil\texttt{\the\cnta.} }% |
| 16782 |
\xintTrunc {12} |
| 16783 |
{\xintPowerSeries {1}{\cnta}{\coefflog}{\f}}\dots |
| 16784 |
\endgraf |
| 16785 |
\ifnum \cnta < 30 \advance\cnta 1 \repeat |
| 16786 |
\end{multicols} |
| 16787 |
\end{everbatim*} |
| 16788 |
|
| 16789 |
|
| 16790 |
\begin{everbatim*} |
| 16791 |
\def\coeffarctg #1{1/\the\numexpr\ifodd #1 -2*#1-1\else2*#1+1\fi\relax }% |
| 16792 |
% the above gives (-1)^n/(2n+1). The sign being in the denominator, |
| 16793 |
% **** no [0] should be added ****, |
| 16794 |
% else nothing is guaranteed to work (even if it could by sheer luck) |
| 16795 |
% Notice in passing this aspect of \numexpr: |
| 16796 |
% **** \numexpr -(1)\relax is ilegal !!! **** |
| 16797 |
\def\f {1/25[0]}% 1/5^2 |
| 16798 |
\[\mathrm{Arctg}(\frac15)\approx \frac15\sum_{n=0}^{15} \frac{(-1)^n}{(2n+1)25^n} |
| 16799 |
= \xintTeXFrac{\xintIrr {\xintDiv {\xintPowerSeries {0}{15}{\coeffarctg}{\f}}{5}}}\] |
| 16800 |
\end{everbatim*} |
| 16801 |
|
| 16802 |
|
| 16803 |
\subsection{\csh{xintPowerSeriesX}}\label{xintPowerSeriesX} |
| 16804 |
|
| 16805 |
%{\small\hspace*{\parindent}New with release |1.04|.\par} |
| 16806 |
|
| 16807 |
\noindent This is the same as \csbxint{PowerSeries}\ntype{\numx\numx\Ff\Ff} |
| 16808 |
apart |
| 16809 |
from the fact that the last parameter |f| is expanded once and for all before |
| 16810 |
being then used repeatedly. If the |f| parameter is to be an explicit big |
| 16811 |
fraction with many (dozens) digits, rather than using it directly it is slightly |
| 16812 |
better to have some macro |\g| defined to expand to the explicit fraction and |
| 16813 |
then use \csbxint{PowerSeries} with |\g|; but if |f| has not yet been evaluated |
| 16814 |
and will be the output of a complicated expansion of some |\f|, and if, due to |
| 16815 |
an expanding only context, doing |\edef\g{\f}| is no option, then |
| 16816 |
\csa{xintPowerSeriesX} should be used with |\f| as last parameter. |
| 16817 |
% |
| 16818 |
\begin{everbatim*} |
| 16819 |
\def\ratioexp #1#2{\xintDiv {#1}{#2}}% x/n |
| 16820 |
% These are the (-1)^{n-1}/n of the log(1+h) series: |
| 16821 |
\def\coefflog #1{\the\numexpr\ifodd #1 1\else-1\fi\relax/#1[0]}% |
| 16822 |
% Let L(h) be the first 10 terms of the log(1+h) series and |
| 16823 |
% let E(t) be the first 10 terms of the exp(t) series. |
| 16824 |
% The following computes L(E(a/10)-1) for a=1,..., 12. |
| 16825 |
\begin{multicols}{3}\raggedcolumns |
| 16826 |
\cnta 1 |
| 16827 |
\loop |
| 16828 |
\noindent\xintTrunc {18}{% |
| 16829 |
\xintPowerSeriesX {1}{10}{\coefflog} |
| 16830 |
{\xintSub |
| 16831 |
{\xintRationalSeries {0}{9}{1[0]}{\ratioexp{\the\cnta[-1]}}} |
| 16832 |
{1}}}\dots |
| 16833 |
\endgraf |
| 16834 |
\ifnum\cnta < 12 \advance \cnta 1 \repeat |
| 16835 |
\end{multicols} |
| 16836 |
\end{everbatim*} |
| 16837 |
|
| 16838 |
|
| 16839 |
\subsection{\csh{xintFxPtPowerSeries}}\label{xintFxPtPowerSeries} |
| 16840 |
|
| 16841 |
\csa{xintFxPtPowerSeries}|{A}{B}{\coeff}{f}{D}|\etype{\numx\numx} |
| 16842 |
computes |
| 16843 |
$\sum_{\text{|n=A|}}^{\text{|n=B|}}$|\coeff{n}|${}\cdot \text{|f|}^{\,\text{|n|}}$ with each |
| 16844 |
term of the series truncated to |D| digits\etype{\Ff\Ff\numx} |
| 16845 |
after the decimal point. As |
| 16846 |
usual, |A| and |B| are completely expanded through their inclusion in a |
| 16847 |
|\numexpr| expression. Regarding |D| it will be similarly be expanded each |
| 16848 |
time it is used inside an \csa{xintTrunc}. The one-parameter macro |\coeff| |
| 16849 |
is similarly expanded at the time it is used inside the |
| 16850 |
computations. Idem for |f|. If |f| itself is some complicated macro it is |
| 16851 |
thus better to use the variant \csbxint{FxPtPowerSeriesX} which expands it |
| 16852 |
first and then uses the result of that expansion. |
| 16853 |
|
| 16854 |
The current (|1.04|) implementation is: the first power |f^A| is |
| 16855 |
computed exactly, then \emph{truncated}. Then each successive power is |
| 16856 |
obtained from the previous one by multiplication by the exact value of |
| 16857 |
|f|, and truncated. And |\coeff{n}|\raisebox{.5ex}{|.|}|f^n| is obtained |
| 16858 |
from that by multiplying by |\coeff{n}| (untruncated) and then |
| 16859 |
truncating. Finally the sum is computed exactly. Apart from that |
| 16860 |
\csa{xintFxPtPowerSeries} (where |FxPt| means `fixed-point') is like |
| 16861 |
\csa{xintPowerSeries}. |
| 16862 |
|
| 16863 |
There should be a variant for things of the type $\sum c_n \frac {f^n}{n!}$ to |
| 16864 |
avoid having to compute the factorial from scratch at each coefficient, the same |
| 16865 |
way \csa{xintFxPtPowerSeries} does not compute |f^n| from scratch at each |n|. |
| 16866 |
Perhaps in the next package release. |
| 16867 |
|
| 16868 |
\def\coeffexp #1{1/\xintiiFac {#1}[0]}% [0] for faster parsing |
| 16869 |
\def\f {-1/2[0]}% |
| 16870 |
\newcount\cnta |
| 16871 |
|
| 16872 |
\edef\foo{\the\multicolsep} |
| 16873 |
\setlength{\multicolsep}{0pt} |
| 16874 |
|
| 16875 |
\begin{multicols}{3}[% |
| 16876 |
\centeredline{$e^{-\frac12}\approx{}$}]% |
| 16877 |
\cnta 0 |
| 16878 |
\noindent\loop |
| 16879 |
$\xintFxPtPowerSeries {0}{\cnta}{\coeffexp}{\f}{20}$\\ |
| 16880 |
\ifnum\cnta<19 |
| 16881 |
\advance\cnta 1 |
| 16882 |
\repeat\par |
| 16883 |
\end{multicols} |
| 16884 |
\multicolsep\foo\relax |
| 16885 |
|
| 16886 |
\everb|@ |
| 16887 |
\def\coeffexp #1{1/\xintiiFac {#1}[0]}% 1/n! |
| 16888 |
\def\f {-1/2[0]}% [0] for faster input parsing |
| 16889 |
\cnta 0 % previously declared \count register |
| 16890 |
\noindent\loop |
| 16891 |
$\xintFxPtPowerSeries {0}{\cnta}{\coeffexp}{\f}{20}$\\ |
| 16892 |
\ifnum\cnta<19 \advance\cnta 1 \repeat\par |
| 16893 |
| |
| 16894 |
|
| 16895 |
|
| 16896 |
% |
| 16897 |
\leftedline{|\xintFxPtPowerSeries {0}{19}{\coeffexp}{\f}{25}=| |
| 16898 |
\dtt{\xintFxPtPowerSeries {0}{19}{\coeffexp}{\f}{25}}} |
| 16899 |
\fdef\z{\xintIrr {\xintPowerSeries {0}{19}{\coeffexp}{\f}}} |
| 16900 |
% |
| 16901 |
|
| 16902 |
\texttt{\hyphenchar\font45 }% |
| 16903 |
It is no difficulty for \xintfracname to compute exactly, with the help |
| 16904 |
of \csa{xintPowerSeries}, the nineteenth partial sum, and to then give |
| 16905 |
(the start of) its exact decimal expansion: |
| 16906 |
% |
| 16907 |
\leftedline{|\xintPowerSeries {0}{19}{\coeffexp}{\f}| ${}= |
| 16908 |
\displaystyle\xintTeXFrac{\z}$% |
| 16909 |
\vphantom{\vrule height 20pt depth 12pt}}% |
| 16910 |
% |
| 16911 |
\leftedline{${}=\xintTrunc {30}{\z}\dots$} Thus, one should always |
| 16912 |
estimate a priori how many ending digits are not reliable: if there are |
| 16913 |
|N| terms and |N| has |k| digits, then digits up to but excluding the |
| 16914 |
last |k| may usually be trusted. If we are optimistic and the series is |
| 16915 |
alternating we may even replace |N| with $\sqrt{\text{|N|}}$ to get the number |k| |
| 16916 |
of digits possibly of dubious significance. |
| 16917 |
|
| 16918 |
\subsection{\csh{xintFxPtPowerSeriesX}}\label{xintFxPtPowerSeriesX} |
| 16919 |
|
| 16920 |
|
| 16921 |
\noindent\csa{xintFxPtPowerSeriesX}|{A}{B}{\coeff}{\f}{D}|% |
| 16922 |
\ntype{\numx\numx} |
| 16923 |
computes, exactly as |
| 16924 |
\csa{xintFxPtPowerSeries}, the sum of |
| 16925 |
|\coeff{n}|\raisebox{.5ex}{|.|}|\f^n|\etype{\Ff\Ff\numx} from |n=A| to |n=B| with each term |
| 16926 |
of the series being \emph{truncated} to |D| digits after the decimal |
| 16927 |
point. The sole difference is that |\f| is first expanded and it |
| 16928 |
is the result of this which is used in the computations. |
| 16929 |
|
| 16930 |
|
| 16931 |
Let us illustrate this on the numerical exploration of the identity |
| 16932 |
% |
| 16933 |
\leftedline{|log(1+x) = -log(1/(1+x))|} |
| 16934 |
% |
| 16935 |
Let |L(h)=log(1+h)|, and |D(h)=L(h)+L(-h/(1+h))|. Theoretically thus, |
| 16936 |
|D(h)=0| but we shall evaluate |L(h)| and |-h/(1+h)| keeping only 10 |
| 16937 |
terms of their respective series. We will assume $\text{|h|}<0.5$. With only |
| 16938 |
ten terms kept in the power series we do not have quite 3 digits |
| 16939 |
precision as $2^{10}=1024$. So it wouldn't make sense to evaluate things |
| 16940 |
more precisely than, say circa 5 digits after the decimal points. |
| 16941 |
\begin{everbatim*} |
| 16942 |
\cnta 0 |
| 16943 |
\def\coefflog #1{\the\numexpr\ifodd#1 1\else-1\fi\relax/#1[0]}% (-1)^{n-1}/n |
| 16944 |
\def\coeffalt #1{\the\numexpr\ifodd#1 -1\else1\fi\relax [0]}% (-1)^n |
| 16945 |
\begin{multicols}2 |
| 16946 |
\loop |
| 16947 |
\noindent \hbox to 2.5cm {\hss\texttt{D(\the\cnta/100): }}% |
| 16948 |
\xintAdd {\xintFxPtPowerSeriesX {1}{10}{\coefflog}{\the\cnta [-2]}{5}} |
| 16949 |
{\xintFxPtPowerSeriesX {1}{10}{\coefflog} |
| 16950 |
{\xintFxPtPowerSeriesX {1}{10}{\coeffalt}{\the\cnta [-2]}{5}} |
| 16951 |
{5}}\endgraf |
| 16952 |
\ifnum\cnta < 49 \advance\cnta 7 \repeat |
| 16953 |
\end{multicols} |
| 16954 |
\end{everbatim*} |
| 16955 |
|
| 16956 |
|
| 16957 |
Let's say we evaluate functions on |[-1/2,+1/2]| with values more or less also |
| 16958 |
in |[-1/2,+1/2]| and we want to keep 4 digits of precision. So, roughly we need |
| 16959 |
at least 14 terms in series like the geometric or log series. Let's make this |
| 16960 |
15. Then it doesn't make sense to compute intermediate summands with more than 6 |
| 16961 |
digits precision. So we compute with 6 digits |
| 16962 |
precision but return only 4 digits (rounded) after the decimal point. |
| 16963 |
This result with 4 post-decimal points precision is then used as input |
| 16964 |
to the next evaluation. |
| 16965 |
\begin{everbatim*} |
| 16966 |
\begin{multicols}2 |
| 16967 |
\loop |
| 16968 |
\noindent \hbox to 2.5cm {\hss\texttt{D(\the\cnta/100): }}% |
| 16969 |
\dtt{\xintRound{4} |
| 16970 |
{\xintAdd {\xintFxPtPowerSeriesX {1}{15}{\coefflog}{\the\cnta [-2]}{6}} |
| 16971 |
{\xintFxPtPowerSeriesX {1}{15}{\coefflog} |
| 16972 |
{\xintRound {4}{\xintFxPtPowerSeriesX {1}{15}{\coeffalt} |
| 16973 |
{\the\cnta [-2]}{6}}} |
| 16974 |
{6}}% |
| 16975 |
}}\endgraf |
| 16976 |
\ifnum\cnta < 49 \advance\cnta 7 \repeat |
| 16977 |
\end{multicols} |
| 16978 |
\end{everbatim*} |
| 16979 |
|
| 16980 |
Not bad... I have cheated a bit: the `four-digits precise' numeric |
| 16981 |
evaluations were left unrounded in the final addition. However the inner |
| 16982 |
rounding to four digits worked fine and made the next step faster than |
| 16983 |
it would have been with longer inputs. The morale is that one should not |
| 16984 |
use the raw results of \csa{xintFxPtPowerSeriesX} with the |D| digits |
| 16985 |
with which it was computed, as the last are to be considered garbage. |
| 16986 |
Rather, one should keep from the output only some smaller number of |
| 16987 |
digits. This will make further computations faster and not less precise. |
| 16988 |
I guess there should be some macro to do this final truncating, or |
| 16989 |
better, rounding, at a given number |D'<D| of digits. Maybe for the next |
| 16990 |
release. |
| 16991 |
|
| 16992 |
\subsection{\csh{xintFloatPowerSeries}}\label{xintFloatPowerSeries} |
| 16993 |
|
| 16994 |
|
| 16995 |
\noindent\csa{xintFloatPowerSeries}|[P]{A}{B}{\coeff}{f}|% |
| 16996 |
\ntype{{\upshape[\numx]}\numx\numx} |
| 16997 |
computes |
| 16998 |
$\sum_{\text{|n=A|}}^{\text{|n=B|}}$|\coeff{n}|${}\cdot \text{|f|}^{\,\text{|n|}}$ |
| 16999 |
with a floating point |
| 17000 |
precision given by the optional parameter |P| or by the current setting of |
| 17001 |
|\xintDigits|.\etype{\Ff\Ff} |
| 17002 |
|
| 17003 |
In the current, preliminary, version, no attempt has been made to try to |
| 17004 |
guarantee to the final result the precision |P|. Rather, |P| is used for all |
| 17005 |
intermediate floating point evaluations. So |
| 17006 |
rounding errors will make some of the last printed digits invalid. The |
| 17007 |
operations done are first the evaluation of |f^A| using \csa{xintFloatPow}, then |
| 17008 |
each successive power is obtained from this first one by multiplication by |f| |
| 17009 |
using \csa{xintFloatMul}, then again with \csa{xintFloatMul} this is multiplied |
| 17010 |
with |\coeff{n}|, and the sum is done adding one term at a time with |
| 17011 |
\csa{xintFloatAdd}. To sum up, this is just the naive transformation of |
| 17012 |
\csa{xintFxPtPowerSeries} from fixed point to floating point. |
| 17013 |
|
| 17014 |
\def\coefflog #1{\the\numexpr\ifodd#1 1\else-1\fi\relax/#1[0]}% |
| 17015 |
|
| 17016 |
\everb+@ |
| 17017 |
\def\coefflog #1{\the\numexpr\ifodd#1 1\else-1\fi\relax/#1[0]}% |
| 17018 |
\xintFloatPowerSeries [8]{1}{30}{\coefflog}{-1/2[0]} |
| 17019 |
+ |
| 17020 |
|
| 17021 |
% |
| 17022 |
\leftedline{\dtt{\xintFloatPowerSeries [8]{1}{30}{\coefflog}{-1/2[0]}}} |
| 17023 |
|
| 17024 |
\subsection{\csh{xintFloatPowerSeriesX}}\label{xintFloatPowerSeriesX} |
| 17025 |
|
| 17026 |
|
| 17027 |
\noindent\csa{xintFloatPowerSeriesX}|[P]{A}{B}{\coeff}{f}|% |
| 17028 |
\ntype{{\upshape[\numx]}\numx\numx} |
| 17029 |
is like |
| 17030 |
\csa{xintFloatPowerSeries} with the difference that |f| is |
| 17031 |
expanded once\etype{\Ff\Ff} |
| 17032 |
and for all at the start of the computation, thus allowing |
| 17033 |
efficient chaining of such series evaluations. |
| 17034 |
\def\coefflog #1{\the\numexpr\ifodd#1 1\else-1\fi\relax/#1[0]}% |
| 17035 |
|
| 17036 |
\everb+@ |
| 17037 |
\def\coeffexp #1{1/\xintiiFac {#1}[0]}% 1/n! (exact, not float) |
| 17038 |
\def\coefflog #1{\the\numexpr\ifodd#1 1\else-1\fi\relax/#1[0]}% |
| 17039 |
\xintFloatPowerSeriesX [8]{0}{30}{\coeffexp} |
| 17040 |
{\xintFloatPowerSeries [8]{1}{30}{\coefflog}{-1/2[0]}} |
| 17041 |
+ |
| 17042 |
|
| 17043 |
% |
| 17044 |
\leftedline{\dtt{\xintFloatPowerSeriesX [8]{0}{30}{\coeffexp} |
| 17045 |
{\xintFloatPowerSeries [8]{1}{30}{\coefflog}{-1/2[0]}}}} |
| 17046 |
|
| 17047 |
\subsection{Computing \texorpdfstring{$\log 2$}{log(2)} and \texorpdfstring{$\pi$}{pi}}\label{ssec:Machin} |
| 17048 |
|
| 17049 |
In this final section, the use of \csbxint{FxPtPowerSeries} (and |
| 17050 |
\csbxint{PowerSeries}) will be |
| 17051 |
illustrated on the (expandable...\@{} why make things simple when it is so easy to |
| 17052 |
make them difficult!) computations of the first digits of the decimal expansion |
| 17053 |
of the familiar constants $\log 2$ and $\pi$. |
| 17054 |
|
| 17055 |
Let us start with $\log 2$. We will get it from this formula (which is |
| 17056 |
left as an exercise): % |
| 17057 |
% |
| 17058 |
\leftedline{\dtt{log(2)=-2\,log(1-13/256)-% |
| 17059 |
5\,log(1-1/9)}} |
| 17060 |
% |
| 17061 |
The number of terms to be kept in the log series, for a desired |
| 17062 |
precision of |10^{-D}| was roughly estimated without much theoretical |
| 17063 |
analysis. Computing exactly the partial sums with \csa{xintPowerSeries} |
| 17064 |
and then printing the truncated values, from |D=0| up to |D=100| showed |
| 17065 |
that it worked in terms of quality of the approximation. Because of |
| 17066 |
possible strings of zeroes or nines in the exact decimal expansion (in |
| 17067 |
the present case of $\log 2$, strings of zeroes around the fourtieth and |
| 17068 |
the sixtieth decimals), this |
| 17069 |
does not mean though that all digits printed were always exact. In |
| 17070 |
the end one always end up having to compute at some higher level of |
| 17071 |
desired precision to validate the earlier result. |
| 17072 |
|
| 17073 |
Then we tried with \csa{xintFxPtPowerSeries}: this is worthwile only for |
| 17074 |
|D|'s at least 50, as the exact evaluations are faster (with these |
| 17075 |
short-length |f|'s) for a lower |
| 17076 |
number of digits. And as expected the degradation in the quality of |
| 17077 |
approximation was in this range of the order of two or three digits. |
| 17078 |
This meant roughly that the 3+1=4 ending digits were wrong. Again, we ended |
| 17079 |
up having to compute with five more digits and compare with the earlier |
| 17080 |
value to validate it. We use truncation rather than rounding because our |
| 17081 |
goal is not to obtain the correct rounded decimal expansion but the |
| 17082 |
correct exact truncated one. |
| 17083 |
|
| 17084 |
% 693147180559945309417232121458176568075500134360255254120680009493 |
| 17085 |
|
| 17086 |
\begin{everbatim*} |
| 17087 |
\def\coefflog #1{1/#1[0]}% 1/n |
| 17088 |
\def\xa {13/256[0]}% we will compute log(1-13/256) |
| 17089 |
\def\xb {1/9[0]}% we will compute log(1-1/9) |
| 17090 |
\def\LogTwo #1{% |
| 17091 |
% get log(2)=-2log(1-13/256)- 5log(1-1/9) |
| 17092 |
\romannumeral0\expandafter\logtwo |
| 17093 |
% number of terms for 1/9: |
| 17094 |
\the\numexpr #1*150/143\expandafter.% |
| 17095 |
% number of Terms for 13/256: |
| 17096 |
\the\numexpr #1*100/129\expandafter.% |
| 17097 |
% We print #1 digits, but we know the ending ones are garbage |
| 17098 |
% Use \numexpr to allow a \count as #1 |
| 17099 |
\the\numexpr #1.% |
| 17100 |
}% |
| 17101 |
\def\logtwo #1.#2.#3.{% |
| 17102 |
% #1=nb of terms for 1/9, |
| 17103 |
% #2=nb of terms for 13/256, |
| 17104 |
% #3=nb of digits for computations, also used for printing |
| 17105 |
\xinttrunc {#3}% will terminate the \romannumeral0 |
| 17106 |
{\xintAdd |
| 17107 |
{\xintMul {2}{\xintFxPtPowerSeries {1}{#2}{\coefflog}{\xa}{#3}}} |
| 17108 |
{\xintMul {5}{\xintFxPtPowerSeries {1}{#1}{\coefflog}{\xb}{#3}}}% |
| 17109 |
}% |
| 17110 |
}% |
| 17111 |
\noindent $\log 2 \approx \LogTwo {60}\dots$\endgraf |
| 17112 |
\noindent\phantom{$\log 2$}${}\approx{}$\printnumber{\LogTwo {65}}\dots\endgraf |
| 17113 |
\noindent\phantom{$\log 2$}${}\approx{}$\printnumber{\LogTwo {70}}\dots\endgraf |
| 17114 |
\end{everbatim*} |
| 17115 |
|
| 17116 |
Here is the code doing an exact evaluation of the partial sums. We have |
| 17117 |
added a |+1| to the number of digits for estimating the number of terms |
| 17118 |
to keep from the log series: we experimented that this gets exactly the |
| 17119 |
first |D| digits, for all values from |D=0| to |D=100|, except in one |
| 17120 |
case (|D=40|) where the last digit is wrong. For values of |D| |
| 17121 |
higher than |100| it is more efficient to use the code using |
| 17122 |
\csa{xintFxPtPowerSeries}. |
| 17123 |
\everb|@ |
| 17124 |
\def\coefflog #1{1/#1[0]}% 1/n |
| 17125 |
\def\xa {13/256[0]}% we will compute log(1-13/256) |
| 17126 |
\def\xb {1/9[0]}% we will compute log(1-1/9) |
| 17127 |
\def\LogTwo #1{% get log(2)=-2log(1-13/256)- 5log(1-1/9) |
| 17128 |
\romannumeral0\expandafter\logtwo |
| 17129 |
\the\numexpr (#1+1)*150/143\expandafter.% |
| 17130 |
\the\numexpr (#1+1)*100/129\expandafter.% |
| 17131 |
\the\numexpr #1.% |
| 17132 |
}% |
| 17133 |
\def\logtwo #1.#2.#3.{% #3=nb of digits for truncating an EXACT partial sum |
| 17134 |
\xinttrunc {#3}% will terminate the \romannumeral0 |
| 17135 |
{\xintAdd |
| 17136 |
{\xintMul {2}{\xintPowerSeries {1}{#2}{\coefflog}{\xa}}} |
| 17137 |
{\xintMul {5}{\xintPowerSeries {1}{#1}{\coefflog}{\xb}}}% |
| 17138 |
}% |
| 17139 |
}% |
| 17140 |
| |
| 17141 |
|
| 17142 |
Let us turn now to Pi, computed with the Machin formula (but see also the |
| 17143 |
approach via the \hyperlink{BrentSalamin}{Brent-Salamin algorithm} with |
| 17144 |
\csa{xintfloatexpr}) Again the numbers of terms to keep in the two |arctg| |
| 17145 |
series were roughly estimated, and some experimentations showed that removing |
| 17146 |
the last three digits was enough (at least for |D=0-100| range). And the |
| 17147 |
algorithm does print the correct digits when used with |D=1000| (to be |
| 17148 |
convinced of that one needs to run it for |D=1000| and again, say for |
| 17149 |
|D=1010|.) A theoretical analysis could help confirm that this algorithm |
| 17150 |
always gets better than |10^{-D}| precision, but again, strings of zeroes or |
| 17151 |
nines encountered in the decimal expansion may falsify the ending digits, |
| 17152 |
nines may be zeroes (and the last non-nine one should be increased) and zeroes |
| 17153 |
may be nine (and the last non-zero one should be decreased). |
| 17154 |
|
| 17155 |
\hypertarget{MachinCode}{} |
| 17156 |
\begin{everbatim*} |
| 17157 |
\def\coeffarctg #1{\the\numexpr\ifodd#1 -1\else1\fi\relax |
| 17158 |
/\the\numexpr 2*#1+1\relax [0]}% |
| 17159 |
%\def\coeffarctg #1{\romannumeral0\xintmon{#1}/\the\numexpr 2*#1+1\relax }% |
| 17160 |
\def\xa {1/25[0]}% 1/5^2, the [0] for faster parsing |
| 17161 |
\def\xb {1/57121[0]}% 1/239^2, the [0] for faster parsing |
| 17162 |
\def\Machin #1{% #1 may be a count register |
| 17163 |
\romannumeral0\expandafter\machin |
| 17164 |
% number of terms for arctg(1/5): |
| 17165 |
\the\numexpr (#1+3)*5/7\expandafter.% |
| 17166 |
% number of terms for arctg(1/239): |
| 17167 |
\the\numexpr (#1+3)*10/45\expandafter.% |
| 17168 |
% do the computations with 3 additional digits: |
| 17169 |
\the\numexpr #1+3\expandafter.% |
| 17170 |
% allow #1 to be a count register: |
| 17171 |
\the\numexpr #1.% |
| 17172 |
}% |
| 17173 |
\def\machin #1.#2.#3.#4.{% |
| 17174 |
\xinttrunc {#4}% will terminate the \romannumeral0 |
| 17175 |
{\xintSub |
| 17176 |
{\xintMul {16/5}{\xintFxPtPowerSeries {0}{#1}{\coeffarctg}{\xa}{#3}}} |
| 17177 |
{\xintMul{4/239}{\xintFxPtPowerSeries {0}{#2}{\coeffarctg}{\xb}{#3}}}% |
| 17178 |
}% |
| 17179 |
}% |
| 17180 |
\begin{framed} |
| 17181 |
\[ \pi = \Machin{60}\dots \] |
| 17182 |
\end{framed} |
| 17183 |
\end{everbatim*} |
| 17184 |
|
| 17185 |
Here is a variant|\MachinBis|, |
| 17186 |
which evaluates the partial sums \emph{exactly} using |
| 17187 |
\csa{xintPowerSeries}, before their final truncation. No need for a |
| 17188 |
``|+3|'' then. |
| 17189 |
\begin{everbatim*} |
| 17190 |
\def\MachinBis #1{% #1 may be a count register, |
| 17191 |
% the final result will be truncated to #1 digits post decimal point |
| 17192 |
\romannumeral0\expandafter\machinbis |
| 17193 |
% number of terms for arctg(1/5): |
| 17194 |
\the\numexpr #1*5/7\expandafter.% |
| 17195 |
% number of terms for arctg(1/239): |
| 17196 |
\the\numexpr #1*10/45\expandafter.% |
| 17197 |
% allow #1 to be a count register: |
| 17198 |
\the\numexpr #1.% |
| 17199 |
}% |
| 17200 |
\def\machinbis #1.#2.#3.{% |
| 17201 |
\xinttrunc {#3}% will terminate the \romannumeral0 |
| 17202 |
{\xintSub |
| 17203 |
{\xintMul {16/5}{\xintPowerSeries {0}{#1}{\coeffarctg}{\xa}}} |
| 17204 |
{\xintMul{4/239}{\xintPowerSeries {0}{#2}{\coeffarctg}{\xb}}}% |
| 17205 |
}% |
| 17206 |
}% |
| 17207 |
\end{everbatim*} |
| 17208 |
|
| 17209 |
Let us use this variant for a loop showing the build-up of digits: |
| 17210 |
\begin{everbatim*} |
| 17211 |
\begin{multicols}{2} |
| 17212 |
\cnta 0 % previously declared \count register |
| 17213 |
\loop \noindent |
| 17214 |
\centeredline{\dtt{\MachinBis{\cnta}}}% |
| 17215 |
\ifnum\cnta < 30 |
| 17216 |
\advance\cnta 1 \repeat |
| 17217 |
\end{multicols} |
| 17218 |
\end{everbatim*} |
| 17219 |
|
| 17220 |
\hypertarget{Machin1000}{} |
| 17221 |
% |
| 17222 |
You want more digits and have some time? Save the following to a file, |
| 17223 |
it is the \hyperlink{MachinCode}{|\Machin|} code. Compile with |etex| |
| 17224 |
(or |pdftex| or |xetex| or |luatex|): |
| 17225 |
% |
| 17226 |
\everb|@ |
| 17227 |
% Compile with e-TeX extensions enabled (etex, pdftex, ...) |
| 17228 |
\input xintfrac.sty |
| 17229 |
\input xintseries.sty |
| 17230 |
% pi = 16 Arctg(1/5) - 4 Arctg(1/239) (John Machin's formula) |
| 17231 |
\def\coeffarctg #1{\the\numexpr\ifodd#1 -1\else1\fi\relax |
| 17232 |
/\the\numexpr 2*#1+1\relax [0]}% |
| 17233 |
\def\xa {1/25[0]}% |
| 17234 |
\def\xb {1/57121[0]}% |
| 17235 |
\def\Machin #1{% |
| 17236 |
\romannumeral0\expandafter\machin |
| 17237 |
\the\numexpr (#1+3)*5/7\expandafter.% |
| 17238 |
\the\numexpr (#1+3)*10/45\expandafter.% |
| 17239 |
\the\numexpr #1+3\expandafter.% |
| 17240 |
\the\numexpr #1.% |
| 17241 |
}% |
| 17242 |
\def\machin #1.#2.#3.#4.{% |
| 17243 |
\xinttrunc {#4}% will terminate the \romannumeral0 |
| 17244 |
{\xintSub |
| 17245 |
{\xintMul {16/5}{\xintFxPtPowerSeries {0}{#1}{\coeffarctg}{\xa}{#3}}} |
| 17246 |
{\xintMul{4/239}{\xintFxPtPowerSeries {0}{#2}{\coeffarctg}{\xb}{#3}}}% |
| 17247 |
}% |
| 17248 |
}% |
| 17249 |
\xintresettimer |
| 17250 |
\edef\Z {\Machin {1000}} |
| 17251 |
\edef\W {\xinttheseconds} |
| 17252 |
\immediate\write128{1000 places of pi via Machin formula (took \W s):} |
| 17253 |
\immediate\write128{\Z} |
| 17254 |
\bye |
| 17255 |
| |
| 17256 |
|
| 17257 |
This will log the first 1000 digits of $\pi$ after the decimal point. On my |
| 17258 |
laptop (a 2012 model) this took about $5.05$ seconds last time I tried.% |
| 17259 |
% |
| 17260 |
\footnote{With \texttt{1.09i} and earlier \xintname, this used to be \dtt{42} |
| 17261 |
seconds; starting with \texttt{1.09j}, and prior to \texttt{1.2}, it was |
| 17262 |
\dtt{16} seconds (this was probably due to a more efficient division with |
| 17263 |
denominators at most $9999$). The |1.2| \xintcorename achieved a further |
| 17264 |
gain at \dtt{5.6} seconds.} |
| 17265 |
% |
| 17266 |
\footnote{With |\xintDigits:=1001\relax|, the non-optimized implementation with the |
| 17267 |
|iter| of \xintexprname fame using the |
| 17268 |
\hyperlink{BrentSalamin}{Brent-Salamin algorithm}, took, last time I tried |
| 17269 |
(1.2i), about \dtt{7} seconds on my laptop (the last two digits were wrong, |
| 17270 |
which is ok as they serve as guard digits), and for obtaining about |
| 17271 |
\dtt{500} digits, it was about \dtt{1.7}s. This is not bad, taking into |
| 17272 |
account that the syntax is almost free rolling speech, contrarily to the |
| 17273 |
code above for the Machin formula computation; we would like to use the |
| 17274 |
quadratically convergent Brent-Salamin algorithm for more digits, but with |
| 17275 |
such computations with numbers of one thousand digits we are beyond the |
| 17276 |
border of the reasonable range for \xintname. Innocent people not knowing |
| 17277 |
what it means to compute with \TeX, and with the extra constraint of |
| 17278 |
expandability will wonder why this is at least thousands of times slower |
| 17279 |
than with any other language (with a little Python program using the |
| 17280 |
|Decimal| library, I timed the Brent-Salamin algorithm to \dtt{4.4ms} for |
| 17281 |
about |1000| digits and \dtt{1.14ms} for |500| digits.) I will just say that |
| 17282 |
for example digits are represented and manipulated via their ascii-code ! |
| 17283 |
all computations must convert from ascii-code to cpu words; furthermore |
| 17284 |
nothing can be stored away. And there is no memory storage with |O(1)| time |
| 17285 |
access...\@{} if expandability is to be verified.} |
| 17286 |
% |
| 17287 |
|
| 17288 |
|
| 17289 |
As mentioned in the |
| 17290 |
introduction, the file \href{https://ctan.org/pkg/pi}{pi.tex} by \textsc{D. |
| 17291 |
Roegel} shows that orders of magnitude faster computations are possible within |
| 17292 |
\TeX{}, but recall our constraints of complete expandability and be merciful, |
| 17293 |
please. |
| 17294 |
|
| 17295 |
\textbf{Why truncating rather than rounding?} One of our main competitors |
| 17296 |
on the market of scientific computing, a canadian product (not |
| 17297 |
encumbered with expandability constraints, and having barely ever heard |
| 17298 |
of \TeX{} ;-), prints numbers rounded in the last digit. Why didn't we |
| 17299 |
follow suit in the macros \csa{xintFxPtPowerSeries} and |
| 17300 |
\csa{xintFxPtPowerSeriesX}? To round at |D| digits, and excluding a |
| 17301 |
rewrite or cloning of the division algorithm which anyhow would add to |
| 17302 |
it some overhead in its final steps, \xintfracname needs to truncate at |
| 17303 |
|D+1|, then round. And rounding loses information! So, with more time |
| 17304 |
spent, we obtain a worst result than the one truncated at |D+1| (one |
| 17305 |
could imagine that additions and so on, done with only |D| digits, cost |
| 17306 |
less; true, but this is a negligeable effect per summand compared to the |
| 17307 |
additional cost for this term of having been truncated at |D+1| then |
| 17308 |
rounded). Rounding is the way to go when setting up algorithms to |
| 17309 |
evaluate functions destined to be composed one after the other: exact |
| 17310 |
algebraic operations with many summands and an |f| variable which is a |
| 17311 |
fraction are costly and create an even bigger fraction; replacing |f| |
| 17312 |
with a reasonable rounding, and rounding the result, is necessary to |
| 17313 |
allow arbitrary chaining. |
| 17314 |
|
| 17315 |
But, for the |
| 17316 |
computation of a single constant, we are really interested in the exact |
| 17317 |
decimal expansion, so we truncate and compute more terms until the |
| 17318 |
earlier result gets validated. Finally if we do want the rounding we can |
| 17319 |
always do it on a value computed with |D+1| truncation. |
| 17320 |
|
| 17321 |
\clearpage |
| 17322 |
\let\xintseriesnameUp\undefined |
| 17323 |
\csname xintcfracnameUp\endcsname |
| 17324 |
\def\n{|{N}|} |
| 17325 |
\def\m{|{M}|} |
| 17326 |
\def\x{|{x}|} |
| 17327 |
\section{Macros of the \xintcfracname package} |
| 17328 |
\RaisedLabel{sec:cfrac} |
| 17329 |
|
| 17330 |
\localtableofcontents |
| 17331 |
|
| 17332 |
First version of this package was included in release |1.04| (|2013/04/25|) of the |
| 17333 |
\xintbundlename. It was kept almost unchanged until |1.09m| of |2014/02/26| |
| 17334 |
which brought some new macros: \csbxint{FtoC}, \csbxint{CtoF}, \csbxint{CtoCv}, |
| 17335 |
dealing with sequences of braced partial quotients rather than comma separated |
| 17336 |
ones, \csbxint{FGtoC} which is to produce ``guaranteed'' coefficients of some |
| 17337 |
real number known approximately, and \csbxint{GGCFrac} for displaying arbitrary |
| 17338 |
material as a continued fraction; also, some changes to existing macros: |
| 17339 |
\csbxint{FtoCs} and \csbxint{CntoCs} insert spaces after the commas, |
| 17340 |
\csbxint{CstoF} and \csbxint{CstoCv} authorize spaces in the input also before |
| 17341 |
the commas. |
| 17342 |
|
| 17343 |
\csbxint{CstoF} and \csbxint{CstoCv} create a partial dependency on |
| 17344 |
\xinttoolsname as they use its \csbxint{CSVtoList}. Starting at |1.4n| |
| 17345 |
the loading of \xinttoolsname is done automatically, formerly it was up |
| 17346 |
to user to do it. |
| 17347 |
|
| 17348 |
% This section contains: |
| 17349 |
% \begin{enumerate} |
| 17350 |
% \item an \hyperref[ssec:cfracoverview]{overview} of the package functionalities, |
| 17351 |
% \item a description of each one of the package macros, |
| 17352 |
% \item further illustration of their use via the study of the |
| 17353 |
% \hyperref[ssec:e-convergents]{convergents of $e$}. |
| 17354 |
% \end{enumerate} |
| 17355 |
|
| 17356 |
\subsection{Package overview}\label{ssec:cfracoverview} |
| 17357 |
|
| 17358 |
The package computes partial quotients and convergents of a fraction, or |
| 17359 |
conversely start from coefficients and obtain the corresponding fraction; three |
| 17360 |
macros \csbxint {CFrac}, \csbxint {GCFrac} and \csbxint {GGCFrac} are |
| 17361 |
for typesetting, the others |
| 17362 |
can be nested (if applicable) or see their outputs further processed by other |
| 17363 |
macros from the \xintbundlename, particularly the macros of \xinttoolsname |
| 17364 |
dealing with sequences of braced items or comma separated lists. |
| 17365 |
|
| 17366 |
A \emph{simple} continued fraction has coefficients |
| 17367 |
|[c0,c1,...,cN]| (usually called partial quotients, but I |
| 17368 |
dislike this entrenched terminology), where |c0| is a positive or |
| 17369 |
negative integer and the others are positive integers. |
| 17370 |
|
| 17371 |
Typesetting is usually done via the |amsmath| macro |\cfrac|: |
| 17372 |
\begin{everbatim*} |
| 17373 |
\[ c_0 + \cfrac{1}{c_1+\cfrac1{c_2+\cfrac1{c_3+\cfrac1{\ddots}}}}\] |
| 17374 |
\end{everbatim*} |
| 17375 |
|
| 17376 |
Here is a concrete example: |
| 17377 |
\begin{everbatim*} |
| 17378 |
\[ \xintTeXFrac {208341/66317}=\xintCFrac {208341/66317}\]% |
| 17379 |
\end{everbatim*} |
| 17380 |
But it is the macro \csbxint{CFrac} which did all the work of \emph{computing} |
| 17381 |
the continued fraction \emph{and} using |\cfrac| from |amsmath| to typeset |
| 17382 |
it. |
| 17383 |
|
| 17384 |
A \emph{generalized} continued fraction has the same structure but the |
| 17385 |
numerators are not restricted to be $1$, and numbers used in the continued |
| 17386 |
fraction may be arbitrary, also fractions, irrationals, complex, |
| 17387 |
indeterminates.% |
| 17388 |
% |
| 17389 |
\footnote{\xintcfracname may be used with indeterminates, |
| 17390 |
for basic conversions from one inline format to another, but not for |
| 17391 |
actual computations. See \csbxint{GGCFrac}.} |
| 17392 |
% |
| 17393 |
The \emph{centered} continued fraction is an |
| 17394 |
example: |
| 17395 |
\begin{everbatim*} |
| 17396 |
\[ \xintTeXFrac {915286/188421}=\xintGCFrac {5+-1/7+1/39+-1/53+-1/13} |
| 17397 |
=\xintCFrac {915286/188421}\] |
| 17398 |
\end{everbatim*} |
| 17399 |
|
| 17400 |
The macro \csbxint{GCFrac}, contrarily to |
| 17401 |
\csbxint{CFrac}, does not compute anything, it just typesets starting from a |
| 17402 |
generalized continued fraction in inline format, which in this example |
| 17403 |
was input literally. We also used \csa{xintCFrac} |
| 17404 |
for comparison of the two types of continued fractions. |
| 17405 |
|
| 17406 |
To let \TeX{} compute the centered continued fraction of |f| there is |
| 17407 |
\csbxint{FtoCC}: |
| 17408 |
\begin{everbatim*} |
| 17409 |
\[\xintTeXFrac {915286/188421}\to\xintFtoCC {915286/188421}\] |
| 17410 |
\end{everbatim*} |
| 17411 |
The package macros are expandable and may be nested (naturally \csa{xintCFrac} |
| 17412 |
and \csa{xintGCFrac} must be at the top level, as they deal with typesetting). |
| 17413 |
\begin{everbatim*} |
| 17414 |
\[\xintGCFrac {\xintFtoCC{915286/188421}}\] |
| 17415 |
\end{everbatim*} |
| 17416 |
|
| 17417 |
The `inline' format expected on input by \csbxint{GCFrac} is |
| 17418 |
% |
| 17419 |
\leftedline{$a_0+b_0/a_1+b_1/a_2+b_2/a_3+\cdots+b_{n-2}/a_{n-1}+b_{n-1}/a_n$} |
| 17420 |
% |
| 17421 |
Fractions among the coefficients are allowed but they must be enclosed |
| 17422 |
within braces. Signed integers may be left without braces (but the |+| |
| 17423 |
signs are mandatory). No spaces are allowed around the plus and fraction |
| 17424 |
symbols. The coefficients may themselves be macros, as long as these |
| 17425 |
macros are \fexpan dable. |
| 17426 |
\begin{everbatim*} |
| 17427 |
\[ \xintTeXFrac{\xintGCtoF {1+-1/57+\xintPow {-3}{7}/\xintiiQuo {132}{25}}} |
| 17428 |
= \xintGCFrac {1+-1/57+\xintPow {-3}{7}/\xintiiQuo {132}{25}}\] |
| 17429 |
\end{everbatim*} |
| 17430 |
To compute the actual fraction one has \csbxint{GCtoF}: |
| 17431 |
\begin{everbatim*} |
| 17432 |
\[\xintTeXFrac{\xintGCtoF {1+-1/57+\xintPow {-3}{7}/\xintiiQuo {132}{25}}}\] |
| 17433 |
\end{everbatim*} |
| 17434 |
For non-numeric input there is \csbxint{GGCFrac}. |
| 17435 |
\begin{everbatim*} |
| 17436 |
\[\xintGGCFrac {a_0+b_0/a_1+b_1/a_2+b_2/\ddots+\ddots/a_{n-1}+b_{n-1}/a_n}\] |
| 17437 |
\end{everbatim*} |
| 17438 |
For regular continued fractions, there is a simpler comma separated format: |
| 17439 |
\begin{everbatim*} |
| 17440 |
\[-7,6,19,1,33\to\xintTeXFrac{\xintCstoF{-7,6,19,1,33}}= |
| 17441 |
\xintCFrac{\xintCstoF{-7,6,19,1,33}}\] |
| 17442 |
\end{everbatim*} |
| 17443 |
The macro \csbxint{FtoCs} produces from a fraction |f| the comma separated |
| 17444 |
list of its coefficients. |
| 17445 |
\begin{everbatim*} |
| 17446 |
\[\xintTeXFrac{1084483/398959}=[\xintFtoCs{1084483/398959}]\] |
| 17447 |
\end{everbatim*} |
| 17448 |
If one prefers other separators, one can use the two arguments macros |
| 17449 |
\csbxint{FtoCx} whose first argument is the separator (which may consist of more |
| 17450 |
than one token) which is to be used. |
| 17451 |
\begin{everbatim*} |
| 17452 |
\[\xintTeXFrac{2721/1001}=\xintFtoCx {+1/(}{2721/1001})\cdots)\] |
| 17453 |
\end{everbatim*} |
| 17454 |
This allows under Plain \TeX{} with |amstex| to obtain the same effect |
| 17455 |
as with \LaTeX{}+|\amsmath|+\csbxint{CFrac}: |
| 17456 |
% |
| 17457 |
\leftedline{|$$\xintTeXOver{2721/1001}=\xintFtoCx {+\cfrac1\\ }{2721/1001}\endcfrac$$|} |
| 17458 |
|
| 17459 |
As a shortcut to \csa{xintFtoCx} with separator |1+/|, there is |
| 17460 |
\csbxint{FtoGC}: |
| 17461 |
\begin{everbatim*} |
| 17462 |
2721/1001=\xintFtoGC {2721/1001} |
| 17463 |
\end{everbatim*} |
| 17464 |
Let us compare in that case with the output of \csbxint{FtoCC}: |
| 17465 |
\begin{everbatim*} |
| 17466 |
2721/1001=\xintFtoCC {2721/1001} |
| 17467 |
\end{everbatim*} |
| 17468 |
To obtain the coefficients as a sequence of braced numbers, there is |
| 17469 |
\csbxint{FtoC} (this is a shortcut for |\xintFtoCx {}|). This list |
| 17470 |
(sequence) may then be manipulated using the various macros of \xinttoolsname |
| 17471 |
such as the non-expandable macro \csbxint{AssignArray} or the expandable |
| 17472 |
\csbxint{Apply} and \csbxint{ListWithSep}. |
| 17473 |
|
| 17474 |
Conversely to go from such a sequence of braced coefficients to the |
| 17475 |
corresponding fraction there is \csbxint{CtoF}. |
| 17476 |
|
| 17477 |
The `|\printnumber|' (\autoref{ssec:printnumber}) macro which we use in this |
| 17478 |
document to print long numbers can also be useful on long continued fractions. |
| 17479 |
% |
| 17480 |
\begin{everbatim*} |
| 17481 |
\printnumber{\xintFtoCC {35037018906350720204351049/244241737886197404558180}} |
| 17482 |
\end{everbatim*} |
| 17483 |
% |
| 17484 |
If we apply \csbxint{GCtoF} to this generalized continued fraction, we |
| 17485 |
discover that the original fraction was reducible: |
| 17486 |
% |
| 17487 |
\leftedline{|\xintGCtoF |
| 17488 |
{143+1/2+...+-1/9}|\dtt{=\xintGCtoF{143+1/2+1/5+-1/4+-1/4+-1/4+-1/3+1/2+1/2+1/6+-1/22+1/2+1/10+-1/5+-1/11+-1/3+1/4+-1/2+1/2+1/4+-1/2+1/23+1/3+1/8+-1/6+-1/9}}} |
| 17489 |
|
| 17490 |
\def\mymacro #1{$\xintTeXFrac{#1}=[\xintFtoCs{#1}]$\vtop to 6pt{}} |
| 17491 |
|
| 17492 |
\begingroup |
| 17493 |
\catcode`^\active |
| 17494 |
\def^#1^{\hbox{#1}}% |
| 17495 |
|
| 17496 |
When a generalized continued fraction is built with integers, and |
| 17497 |
numerators are only |1|'s or |-1|'s, the produced fraction is |
| 17498 |
irreducible. And if we compute it again with the last sub-fraction |
| 17499 |
omitted we get another irreducible fraction related to the bigger one by |
| 17500 |
a Bézout identity. Doing this here we get: |
| 17501 |
% |
| 17502 |
\leftedline{|\xintGCtoF {143+1/2+...+-1/6}|\dtt{=\xintGCtoF{143+1/2+1/5+-1/4+-1/4+-1/4+-1/3+1/2+1/2+1/6+-1/22+1/2+1/10+-1/5+-1/11+-1/3+1/4+-1/2+1/2+1/4+-1/2+1/23+1/3+1/8+-1/6}}} |
| 17503 |
and indeed: |
| 17504 |
\[\begin{vmatrix} |
| 17505 |
^2897319801297630107^ & ^328124887710626729^\\ |
| 17506 |
^20197107104701740^ & ^2287346221788023^ |
| 17507 |
\end{vmatrix} = \mbox{\dtt{\xintiiSub {\xintiiMul {2897319801297630107}{2287346221788023}}{\xintiiMul{20197107104701740}{328124887710626729}}}}\] |
| 17508 |
|
| 17509 |
\endgroup |
| 17510 |
|
| 17511 |
The various fractions obtained from the truncation of a continued fraction to |
| 17512 |
its initial terms are called the convergents. The macros of \xintcfracname |
| 17513 |
such as \csbxint{FtoCv}, \csbxint{FtoCCv}, and others which compute such |
| 17514 |
convergents, return them as a list of braced items, with no separator (as does |
| 17515 |
\csbxint {FtoC} for the partial quotients). Here is an example: |
| 17516 |
|
| 17517 |
\begin{everbatim*} |
| 17518 |
\[\xintTeXFrac{915286/188421}\to |
| 17519 |
\xintListWithSep{,}{\xintApply\xintTeXFrac{\xintFtoCv{915286/188421}}}\] |
| 17520 |
\end{everbatim*} |
| 17521 |
\begin{everbatim*} |
| 17522 |
\[\xintTeXFrac{915286/188421}\to |
| 17523 |
\xintListWithSep{,}{\xintApply\xintTeXFrac{\xintFtoCCv{915286/188421}}}\] |
| 17524 |
\end{everbatim*} |
| 17525 |
% |
| 17526 |
We thus see that the `centered convergents' obtained with \csbxint{FtoCCv} are |
| 17527 |
among the fuller list of convergents as returned by \csbxint{FtoCv}. |
| 17528 |
|
| 17529 |
Here is a more complicated use of \csa{xintApply} |
| 17530 |
and \csa{xintListWithSep}. We first define a macro which will be applied to each |
| 17531 |
convergent:% |
| 17532 |
% |
| 17533 |
\leftedline{|\newcommand{\mymacro}[1]{$\xintTeXFrac{#1}=[\xintFtoCs{#1}]$\vtop to 6pt{}}|} |
| 17534 |
% |
| 17535 |
Next, we use the following code: |
| 17536 |
% |
| 17537 |
\leftedline{|$\xintTeXFrac{49171/18089}\to{}$|} |
| 17538 |
% |
| 17539 |
\leftedline{|\xintListWithSep {, |
| 17540 |
}{\xintApply{\mymacro}{\xintFtoCv{49171/18089}}}|} |
| 17541 |
It produces:\par |
| 17542 |
\noindent$ \xintTeXFrac{49171/18089}\to {}$\xintListWithSep {, |
| 17543 |
}{\xintApply{\mymacro}{\xintFtoCv{49171/18089}}}. |
| 17544 |
|
| 17545 |
The macro \csbxint{CntoF} allows to specify the coefficients as a function given |
| 17546 |
by a one-parameter macro. The produced values do not have to be integers. |
| 17547 |
\begin{everbatim*} |
| 17548 |
\def\cn #1{\xintiiPow {2}{#1}}% 2^n |
| 17549 |
\[\xintTeXFrac{\xintCntoF {6}{\cn}}=\xintCFrac [l]{\xintCntoF {6}{\cn}}\] |
| 17550 |
\end{everbatim*} |
| 17551 |
|
| 17552 |
Notice the use of the optional argument |[l]| to \csa{xintCFrac}. Other |
| 17553 |
possibilities are |[r]| and (default) |[c]|. |
| 17554 |
\begin{everbatim*} |
| 17555 |
\def\cn #1{\xintPow {2}{-#1}}% |
| 17556 |
\[\xintTeXFrac{\xintCntoF {6}{\cn}}=\xintGCFrac [r]{\xintCntoGC {6}{\cn}}= |
| 17557 |
[\xintFtoCs {\xintCntoF {6}{\cn}}]\] |
| 17558 |
\end{everbatim*} |
| 17559 |
We used \csbxint{CntoGC} as we wanted to display also the continued fraction and |
| 17560 |
not only the fraction returned by \csa{xintCntoF}. |
| 17561 |
|
| 17562 |
There are also \csbxint{GCntoF} and \csbxint{GCntoGC} which allow the same for |
| 17563 |
generalized fractions. An initial portion of a generalized continued |
| 17564 |
fraction for $\pi$ is obtained like this |
| 17565 |
\begin{everbatim*} |
| 17566 |
\def\an #1{\the\numexpr 2*#1+1\relax }% |
| 17567 |
\def\bn #1{\the\numexpr (#1+1)*(#1+1)\relax }% |
| 17568 |
\[\xintTeXFrac{\xintDiv {4}{\xintGCntoF {5}{\an}{\bn}}} = |
| 17569 |
\cfrac{4}{\xintGCFrac{\xintGCntoGC {5}{\an}{\bn}}} = |
| 17570 |
\xintTrunc {10}{\xintDiv {4}{\xintGCntoF {5}{\an}{\bn}}}\dots\] |
| 17571 |
\end{everbatim*} |
| 17572 |
|
| 17573 |
We see that the quality of approximation is not fantastic compared to the simple |
| 17574 |
continued fraction of $\pi$ with about as many terms: |
| 17575 |
\begin{everbatim*} |
| 17576 |
\[\xintTeXFrac{\xintCstoF{3,7,15,1,292,1,1}}= |
| 17577 |
\xintGCFrac{3+1/7+1/15+1/1+1/292+1/1+1/1}= |
| 17578 |
\xintTrunc{10}{\xintCstoF{3,7,15,1,292,1,1}}\dots\] |
| 17579 |
\end{everbatim*} |
| 17580 |
|
| 17581 |
When studying the continued fraction of some real number, there is always |
| 17582 |
some doubt about how many terms are valid, when computed starting from some |
| 17583 |
approximation. If $f\leqslant x\leqslant g$ and $f, g$ both have the |
| 17584 |
same first $K$ partial quotients, then $x$ also has the same first $K$ quotients |
| 17585 |
and convergents. The macro \csbxint{FGtoC} outputs as a sequence of braced items |
| 17586 |
the common partial quotients of its two arguments. We can thus use it to produce |
| 17587 |
a sure list of valid convergents of $\pi$ for example, starting from some proven |
| 17588 |
lower and upper bound: |
| 17589 |
\begin{everbatim*} |
| 17590 |
$$\pi\to [\xintListWithSep{,} |
| 17591 |
{\xintFGtoC {3.14159265358979323}{3.14159265358979324}}, \dots]$$ |
| 17592 |
\noindent$\pi\to\xintListWithSep{,\allowbreak\;} |
| 17593 |
{\xintApply{\xintTeXFrac} |
| 17594 |
{\xintCtoCv{\xintFGtoC {3.14159265358979323}{3.14159265358979324}}}}, \dots$ |
| 17595 |
\end{everbatim*} |
| 17596 |
|
| 17597 |
|
| 17598 |
\subsection{\csh{xintCFrac}}\label{xintCFrac} |
| 17599 |
|
| 17600 |
\csa{xintCFrac}|{f}|\ntype{\Ff} is a math-mode only, \LaTeX{} with |amsmath| |
| 17601 |
only, macro which first computes then displays with the help of |\cfrac| the |
| 17602 |
simple continued fraction corresponding to the given fraction. It admits an |
| 17603 |
optional argument which may be |[l]|, |[r]| or (the default) |[c]| to specify |
| 17604 |
the location of the one's in the numerators of the sub-fractions. |
| 17605 |
This macro is \fexpan dable in the sense that it prepares expandably |
| 17606 |
the whole expression with the multiple |\cfrac|'s, but it is not completely |
| 17607 |
expandable naturally as |\cfrac| isn't. |
| 17608 |
|
| 17609 |
\subsection{\csh{xintGCFrac}}\label{xintGCFrac} |
| 17610 |
|
| 17611 |
\csa{xintGCFrac}|{a+b/c+d/e+f/g+h/...+x/y}|\ntype{f} uses similarly |\cfrac| |
| 17612 |
to prepare the typesetting with the |amsmath| |\cfrac| (\LaTeX{}) of a |
| 17613 |
generalized continued fraction given in inline format (or as macro which |
| 17614 |
will \fexpan d to it). It admits the |
| 17615 |
same optional argument as \csa{xintCFrac}. Plain \TeX{} with |amstex| |
| 17616 |
users, see \csbxint{GCtoGCx}. |
| 17617 |
\begin{everbatim*} |
| 17618 |
\[\xintGCFrac {1+\xintPow{1.5}{3}/{1/7}+{-3/5}/\xintiiFac {6}}\] |
| 17619 |
\end{everbatim*} |
| 17620 |
This is mostly a typesetting macro, although it does trigger the |
| 17621 |
expansion of the coefficients. See \csbxint{GCtoF} if you are impatient |
| 17622 |
to see this specific fraction computed. |
| 17623 |
|
| 17624 |
It admits an optional argument within square brackets which may be |
| 17625 |
either |[l]|, |[c]| or |[r]|. Default is |[c]| (numerators are centered). |
| 17626 |
|
| 17627 |
Numerators and denominators are made arguments to the \csbxint{TeXFrac} |
| 17628 |
macro. This allows them to be themselves fractions or anything \fexpan |
| 17629 |
dable giving numbers or fractions, but also means however that they can |
| 17630 |
not be arbitrary material, they can not contain color changing macros |
| 17631 |
for example. One of the reasons is that \csa{xintGCFrac} tries to |
| 17632 |
determine the signs of the numerators and chooses accordingly to use |
| 17633 |
$+$ or $-$. |
| 17634 |
|
| 17635 |
\subsection{\csh{xintGGCFrac}}\label{xintGGCFrac} |
| 17636 |
|
| 17637 |
\csa{xintGGCFrac}|{a+b/c+d/e+f/g+h/...+x/y}|\ntype{f} is a clone of |
| 17638 |
\csbxint{GCFrac}, hence again \LaTeX{} specific with package |
| 17639 |
|amsmath|. |
| 17640 |
It does not assume the coefficients to be numbers as understood by |
| 17641 |
\xintfracname. The macro can be used for displaying arbitrary content as |
| 17642 |
a continued fraction with |\cfrac|, using only plus signs though. Note |
| 17643 |
though that it will first \fexpan d its argument, which may be thus be |
| 17644 |
one of the \xintcfracname macros producing a (general) continued |
| 17645 |
fraction in inline format, see \csbxint{FtoCx} for an example. If this |
| 17646 |
expansion is not wished, it is enough to start the argument with a |
| 17647 |
space. |
| 17648 |
\begin{everbatim*} |
| 17649 |
\[\xintGGCFrac {1+q/1+q^2/1+q^3/1+q^4/1+q^5/\ddots}\] |
| 17650 |
\end{everbatim*} |
| 17651 |
|
| 17652 |
\subsection{\csh{xintGCtoGCx}}\label{xintGCtoGCx} |
| 17653 |
%{\small New with release |1.05|.\par} |
| 17654 |
|
| 17655 |
\csa{xintGCtoGCx}|{sepa}{sepb}{a+b/c+d/e+f/...+x/y}|\etype{nnf} returns the list |
| 17656 |
of the coefficients of the generalized continued fraction of |f|, each one |
| 17657 |
within a pair of braces, and separated with the help of |sepa| and |sepb|. Thus |
| 17658 |
% |
| 17659 |
\leftedline{|\xintGCtoGCx :;{1+2/3+4/5+6/7}| gives \xintGCtoGCx |
| 17660 |
:;{1+2/3+4/5+6/7}} |
| 17661 |
% |
| 17662 |
The following can be used byt Plain \TeX{}+|amstex| users to obtain an |
| 17663 |
output similar as the ones produced by \csbxint{GCFrac} and |
| 17664 |
\csbxint{GGCFrac}:\par |
| 17665 |
\everb|@ |
| 17666 |
$$\xintGCtoGCx {+\cfrac}{\\}{a+b/...}\endcfrac$$ |
| 17667 |
$$\xintGCtoGCx {+\cfrac\xintTeXOver}{\\\xintTeXOver}{a+b/...}\endcfrac$$ |
| 17668 |
| |
| 17669 |
|
| 17670 |
\subsection{\csh{xintFtoC}}\label{xintFtoC} |
| 17671 |
|
| 17672 |
\csa{xintFtoC}|{f}|\etype{\Ff} computes the |
| 17673 |
coefficients of the simple continued fraction of |f| and returns them as a list |
| 17674 |
(sequence) of braced items. |
| 17675 |
|
| 17676 |
\begin{everbatim*} |
| 17677 |
\fdef\test{\xintFtoC{-5262046/89233}}\texttt{\meaning\test} |
| 17678 |
\end{everbatim*} |
| 17679 |
|
| 17680 |
\subsection{\csh{xintFtoCs}}\label{xintFtoCs} |
| 17681 |
|
| 17682 |
\csa{xintFtoCs}|{f}|\etype{\Ff} returns the comma separated list of the |
| 17683 |
coefficients of the simple continued fraction of |f|. Notice that starting with |
| 17684 |
|1.09m| a space follows each comma (mainly for usage in text mode, as in math |
| 17685 |
mode spaces are produced in the typeset output by \TeX{} itself). |
| 17686 |
\begin{everbatim*} |
| 17687 |
\[ \xintTeXsignedFrac{-5262046/89233} \to [\xintFtoCs{-5262046/89233}]\] |
| 17688 |
\end{everbatim*} |
| 17689 |
|
| 17690 |
\subsection{\csh{xintFtoCx}}\label{xintFtoCx} |
| 17691 |
|
| 17692 |
\csa{xintFtoCx}|{sep}{f}|\etype{n\Ff} returns the list of the |
| 17693 |
coefficients of the simple continued fraction of |f| separated with the |
| 17694 |
help of |sep|, which may be anything (and is kept unexpanded). For |
| 17695 |
example, with Plain \TeX{} and |amstex|, |
| 17696 |
% |
| 17697 |
\leftedline{|$$\xintFtoCx {+\cfrac1\\ }{-5262046/89233}\endcfrac$$|} |
| 17698 |
% |
| 17699 |
will display the continued fraction using |
| 17700 |
|\cfrac|. Each coefficient is inside a brace pair \hbox{|{ }|}, allowing |
| 17701 |
a macro to end the separator and fetch it as argument, |
| 17702 |
for example, again with Plain \TeX{} and |amstex|: |
| 17703 |
\everb|@ |
| 17704 |
\def\highlight #1{\ifnum #1>200 \textcolor{red}{#1}\else #1\fi} |
| 17705 |
$$\xintFtoCx {+\cfrac1\\ \highlight}{104348/33215}\endcfrac$$ |
| 17706 |
| |
| 17707 |
|
| 17708 |
Due to the different and extremely cumbersome syntax of |\cfrac| under |
| 17709 |
\LaTeX{} it proves a bit tortuous to obtain there the same effect. |
| 17710 |
Actually, it is partly for this purpose that |1.09m| added \csbxint |
| 17711 |
{GGCFrac}. We thus use \csa{xintFtoCx} with a suitable separator, and\; |
| 17712 |
then the whole thing as argument to \csbxint{GGCFrac}: |
| 17713 |
\begin{everbatim*} |
| 17714 |
\def\highlight #1{\ifnum #1>200 \fcolorbox{blue}{white}{\boldmath\color{red}$#1$}% |
| 17715 |
\else #1\fi} |
| 17716 |
\[\xintGGCFrac {\xintFtoCx {+1/\highlight}{208341/66317}}\] |
| 17717 |
\end{everbatim*} |
| 17718 |
|
| 17719 |
\subsection{\csh{xintFtoGC}}\label{xintFtoGC} |
| 17720 |
|
| 17721 |
\csa{xintFtoGC}|{f}|\etype{\Ff} does the same as \csa{xintFtoCx}|{+1/}{f}|. Its |
| 17722 |
output may thus be used in the package macros expecting such an `inline |
| 17723 |
format'. |
| 17724 |
% This continued fraction is a \emph{simple} one, not a |
| 17725 |
% \emph{generalized} one, but as it is produced in the format used for |
| 17726 |
% user input of generalized continued fractions, the macro was called |
| 17727 |
% \csa{xintFtoGC} rather than \csa{xintFtoC} for example. |
| 17728 |
% |
| 17729 |
\begin{everbatim*} |
| 17730 |
566827/208524=\xintFtoGC {566827/208524} |
| 17731 |
\end{everbatim*} |
| 17732 |
|
| 17733 |
\subsection{\csh{xintFGtoC}}\label{xintFGtoC} |
| 17734 |
|
| 17735 |
\csa{xintFGtoC}|{f}{g}|\etype{\Ff\Ff} computes the common initial coefficients |
| 17736 |
to |
| 17737 |
two given fractions |f| and |g|. Notice that any real number |f<x<g| or |f>x>g| |
| 17738 |
will then necessarily share with |f| and |g| these common initial coefficients |
| 17739 |
for its regular continued fraction. The coefficients are output as a sequence of |
| 17740 |
braced numbers. This list can then be manipulated via macros from |
| 17741 |
\xinttoolsname, or other macros of \xintcfracname. |
| 17742 |
|
| 17743 |
\begin{everbatim*} |
| 17744 |
\fdef\test{\xintFGtoC{-5262046/89233}{-5314647/90125}}\texttt{\meaning\test} |
| 17745 |
\end{everbatim*} |
| 17746 |
\begin{everbatim*} |
| 17747 |
\fdef\test{\xintFGtoC{3.141592653}{3.141592654}}\texttt{\meaning\test} |
| 17748 |
\end{everbatim*} |
| 17749 |
\begin{everbatim*} |
| 17750 |
\fdef\test{\xintFGtoC{3.1415926535897932384}{3.1415926535897932385}}\meaning\test |
| 17751 |
\end{everbatim*} |
| 17752 |
\begin{everbatim*} |
| 17753 |
\xintRound {30}{\xintCstoF{\xintListWithSep{,}{\test}}} |
| 17754 |
\end{everbatim*} |
| 17755 |
\begin{everbatim*} |
| 17756 |
\xintRound {30}{\xintCtoF{\test}} |
| 17757 |
\end{everbatim*} |
| 17758 |
\begin{everbatim*} |
| 17759 |
\fdef\test{\xintFGtoC{1.41421356237309}{1.4142135623731}}\meaning\test |
| 17760 |
\end{everbatim*} |
| 17761 |
|
| 17762 |
\subsection{\csh{xintFtoCC}}\label{xintFtoCC} |
| 17763 |
|
| 17764 |
\csa{xintFtoCC}|{f}|\etype{\Ff} returns the `centered' continued fraction of |
| 17765 |
|f|, in `inline format'. % |
| 17766 |
\begin{everbatim*} |
| 17767 |
566827/208524=\xintFtoCC {566827/208524} |
| 17768 |
\end{everbatim*} |
| 17769 |
\begin{everbatim*} |
| 17770 |
\[\xintTeXFrac{566827/208524} = \xintGCFrac{\xintFtoCC{566827/208524}}\] |
| 17771 |
\end{everbatim*} |
| 17772 |
|
| 17773 |
\subsection{\csh{xintCstoF}}\label{xintCstoF} |
| 17774 |
|
| 17775 |
\csa{xintCstoF}|{a,b,c,d,...,z}|\etype{f} computes the fraction corresponding to |
| 17776 |
the coefficients, which may be fractions or even macros expanding to such |
| 17777 |
fractions. The final fraction may then be highly reducible. |
| 17778 |
|
| 17779 |
Starting with |
| 17780 |
release |1.09m| spaces before commas are allowed and trimmed automatically |
| 17781 |
(spaces after commas were already silently handled in earlier releases). |
| 17782 |
\begin{everbatim*} |
| 17783 |
\[\xintGCFrac {-1+1/3+1/-5+1/7+1/-9+1/11+1/-13}= |
| 17784 |
\xintTeXsignedFrac{\xintCstoF {-1,3,-5,7,-9,11,-13}}=\xintTeXsignedFrac{\xintGCtoF |
| 17785 |
{-1+1/3+1/-5+1/7+1/-9+1/11+1/-13}}\] |
| 17786 |
\end{everbatim*} |
| 17787 |
\begin{everbatim*} |
| 17788 |
\[\xintGCFrac{{1/2}+1/{1/3}+1/{1/4}+1/{1/5}}= |
| 17789 |
\xintTeXFrac{\xintCstoF {1/2,1/3,1/4,1/5}}\] |
| 17790 |
\end{everbatim*} |
| 17791 |
% |
| 17792 |
A generalized continued fraction may produce a reducible fraction |
| 17793 |
(\csa{xintCstoF} tries its best not to accumulate in a silly way superfluous |
| 17794 |
factors but will not do simplifications which would be obvious to a human, like |
| 17795 |
simplification by 3 in the result above). |
| 17796 |
|
| 17797 |
\subsection{\csh{xintCtoF}}\label{xintCtoF} |
| 17798 |
|
| 17799 |
\csa{xintCtoF}|{{a}{b}{c}...{z}}|\etype{f} computes the fraction corresponding |
| 17800 |
to the coefficients, which may be fractions or even macros. |
| 17801 |
\begin{everbatim*} |
| 17802 |
\xintCtoF {\xintApply {\xintiiPow 3}{\xintSeq {1}{5}}} |
| 17803 |
\end{everbatim*} |
| 17804 |
\begin{everbatim*} |
| 17805 |
\[ \xintTeXFrac{14946960/4805083}=\xintCFrac {14946960/4805083}\] |
| 17806 |
\end{everbatim*} |
| 17807 |
In the example above the power of $3$ was already pre-computed via the expansion |
| 17808 |
done by |\xintApply|, but if we try with |\xintApply { \xintiiPow 3}| where the |
| 17809 |
space will stop this expansion, we can check that |\xintCtoF| will itself |
| 17810 |
provoke the needed coefficient expansion.% ok |
| 17811 |
|
| 17812 |
\subsection{\csh{xintGCtoF}}\label{xintGCtoF} |
| 17813 |
|
| 17814 |
\csa{xintGCtoF}|{a+b/c+d/e+f/g+......+v/w+x/y}|\etype{f} computes the fraction |
| 17815 |
defined by the inline generalized continued fraction. Coefficients may be |
| 17816 |
fractions but must then be put within braces. They can be macros. The plus signs |
| 17817 |
are mandatory. |
| 17818 |
\begin{everbatim*} |
| 17819 |
\[\xintGCFrac {1+\xintPow{1.5}{3}/{1/7}+{-3/5}/\xintiiFac {6}} = |
| 17820 |
\xintTeXFrac{\xintGCtoF {1+\xintPow{1.5}{3}/{1/7}+{-3/5}/\xintiiFac {6}}} = |
| 17821 |
\xintTeXFrac{\xintIrr{\xintGCtoF |
| 17822 |
{1+\xintPow{1.5}{3}/{1/7}+{-3/5}/\xintiiFac {6}}}}\] |
| 17823 |
\end{everbatim*} |
| 17824 |
|
| 17825 |
\begin{everbatim*} |
| 17826 |
\[ \xintGCFrac{{1/2}+{2/3}/{4/5}+{1/2}/{1/5}+{3/2}/{5/3}} = |
| 17827 |
\xintTeXFrac{\xintGCtoF {{1/2}+{2/3}/{4/5}+{1/2}/{1/5}+{3/2}/{5/3}}} \] |
| 17828 |
\end{everbatim*} |
| 17829 |
|
| 17830 |
The macro tries its best not to accumulate superfluous factor in the |
| 17831 |
denominators, but doesn't reduce the fraction to irreducible form before |
| 17832 |
returning it and does not do simplifications which would be obvious to a human. |
| 17833 |
|
| 17834 |
\subsection{\csh{xintCstoCv}}\label{xintCstoCv} |
| 17835 |
|
| 17836 |
\csa{xintCstoCv}|{a,b,c,d,...,z}|\etype{f} returns the sequence of the |
| 17837 |
corresponding convergents, each one within braces. |
| 17838 |
|
| 17839 |
It is allowed to use fractions as coefficients (the computed |
| 17840 |
convergents have then no reason to be the real convergents of the final |
| 17841 |
fraction). When the coefficients are integers, the convergents are irreducible |
| 17842 |
fractions, but otherwise it is not necessarily the case. |
| 17843 |
\begin{everbatim*} |
| 17844 |
\xintListWithSep:{\xintCstoCv{1,2,3,4,5,6}} |
| 17845 |
\end{everbatim*} |
| 17846 |
\begin{everbatim*} |
| 17847 |
\xintListWithSep:{\xintCstoCv{1,1/2,1/3,1/4,1/5,1/6}} |
| 17848 |
\end{everbatim*} |
| 17849 |
\begin{everbatim*} |
| 17850 |
\[\xintListWithSep{\to}{\xintApply\xintTeXFrac{\xintCstoCv {\xintPow |
| 17851 |
{-.3}{-5},7.3/4.57,\xintCstoF{3/4,9,-1/3}}}}\] |
| 17852 |
\end{everbatim*} |
| 17853 |
|
| 17854 |
\subsection{\csh{xintCtoCv}}\label{xintCtoCv} |
| 17855 |
|
| 17856 |
\csa{xintCtoCv}|{{a}{b}{c}...{z}}|\etype{f} returns the sequence of the |
| 17857 |
corresponding convergents, each one within braces. |
| 17858 |
\begin{everbatim*} |
| 17859 |
\fdef\test{\xintCtoCv {11111111111}}\texttt{\meaning\test} |
| 17860 |
\end{everbatim*} |
| 17861 |
|
| 17862 |
\subsection{\csh{xintGCtoCv}}\label{xintGCtoCv} |
| 17863 |
|
| 17864 |
\csa{xintGCtoCv}|{a+b/c+d/e+f/g+......+v/w+x/y}|\etype{f} returns the list of |
| 17865 |
the corresponding convergents. The coefficients may be fractions, but must then |
| 17866 |
be inside braces. Or they may be macros, too. |
| 17867 |
|
| 17868 |
The convergents will in the general case be reducible. To put them into |
| 17869 |
irreducible form, one needs one more step, for example it can be done |
| 17870 |
with |\xintApply\xintIrr|. |
| 17871 |
\begin{everbatim*} |
| 17872 |
\[\xintListWithSep{,}{\xintApply\xintTeXFrac |
| 17873 |
{\xintGCtoCv{3+{-2}/{7/2}+{3/4}/12+{-56}/3}}}\] |
| 17874 |
\[\xintListWithSep{,}{\xintApply\xintTeXFrac{\xintApply\xintIrr |
| 17875 |
{\xintGCtoCv{3+{-2}/{7/2}+{3/4}/12+{-56}/3}}}}\] |
| 17876 |
\end{everbatim*} |
| 17877 |
|
| 17878 |
|
| 17879 |
\subsection{\csh{xintFtoCv}}\label{xintFtoCv} |
| 17880 |
|
| 17881 |
\csa{xintFtoCv}|{f}|\etype{\Ff} returns the list of the (braced) convergents of |
| 17882 |
|f|, with no separator. To be treated with \csbxint{AssignArray} or |
| 17883 |
\csbxint{ListWithSep}. |
| 17884 |
\begin{everbatim*} |
| 17885 |
\[\xintListWithSep{\to}{\xintApply\xintTeXFrac{\xintFtoCv{5211/3748}}}\] |
| 17886 |
\end{everbatim*} |
| 17887 |
|
| 17888 |
\subsection{\csh{xintFtoCCv}}\label{xintFtoCCv} |
| 17889 |
|
| 17890 |
\csa{xintFtoCCv}|{f}|\etype{\Ff} returns the list of the (braced) centered |
| 17891 |
convergents of |f|, with no separator. To be treated with \csbxint{AssignArray} |
| 17892 |
or \csbxint{ListWithSep}. |
| 17893 |
\begin{everbatim*} |
| 17894 |
\[\xintListWithSep{\to}{\xintApply\xintTeXFrac{\xintFtoCCv{5211/3748}}}\] |
| 17895 |
\end{everbatim*} |
| 17896 |
|
| 17897 |
\subsection{\csh{xintCntoF}}\label{xintCntoF} |
| 17898 |
|
| 17899 |
|
| 17900 |
\csa{xintCntoF}|{N}{\macro}|\etype{\numx f} computes the fraction |f| having |
| 17901 |
coefficients |c(j)=\macro{j}| for |j=0,1,...,N|. The |N| parameter is given to a |
| 17902 |
|\numexpr|. The values of the coefficients, as returned by |\macro| do not have |
| 17903 |
to be positive, nor integers, and it is thus not necessarily the case that the |
| 17904 |
original |c(j)| are the true coefficients of the final |f|. |
| 17905 |
\begin{everbatim*} |
| 17906 |
\def\macro #1{\the\numexpr 1+#1*#1\relax} \xintCntoF {5}{\macro} |
| 17907 |
\end{everbatim*} |
| 17908 |
|
| 17909 |
This example shows that the fraction is output with a trailing number in square |
| 17910 |
brackets (representing a power of ten), this is for consistency with what do |
| 17911 |
most macros of \xintfracname, and does not have to be always this annoying |[0]| |
| 17912 |
as the coefficients may for example be numbers in scientific notation. To avoid |
| 17913 |
these trailing square brackets, for example if the coefficients are known to be integers, there is always the possibility to filter the output via |
| 17914 |
\csbxint{PRaw}, or \csbxint{Irr} (the latter is overkill in the case of integer |
| 17915 |
coefficients, as the fraction is guaranteed to be irreducible then). |
| 17916 |
|
| 17917 |
\subsection{\csh{xintGCntoF}}\label{xintGCntoF} |
| 17918 |
|
| 17919 |
\csa{xintGCntoF}|{N}{\macroA}{\macroB}|\etype{\numx ff} returns the fraction |f| |
| 17920 |
corresponding to the inline generalized continued fraction |
| 17921 |
|a0+b0/a1+b1/a2+....+b(N-1)/aN|, with |a(j)=\macroA{j}| and |b(j)=\macroB{j}|. |
| 17922 |
The |N| parameter is given to a |\numexpr|. |
| 17923 |
\begin{everbatim*} |
| 17924 |
\def\coeffA #1{\the\numexpr #1+4-3*((#1+2)/3)\relax }% |
| 17925 |
\def\coeffB #1{\the\numexpr \ifodd #1 -\fi 1\relax }% (-1)^n |
| 17926 |
\[\xintGCFrac{\xintGCntoGC {6}{\coeffA}{\coeffB}} = |
| 17927 |
\xintTeXFrac{\xintGCntoF {6}{\coeffA}{\coeffB}}\] |
| 17928 |
\end{everbatim*} |
| 17929 |
There is also \csbxint{GCntoGC} to get the `inline format' continued |
| 17930 |
fraction. |
| 17931 |
|
| 17932 |
\subsection{\csh{xintCntoCs}}\label{xintCntoCs} |
| 17933 |
|
| 17934 |
\csa{xintCntoCs}|{N}{\macro}|\etype{\numx f} produces the comma separated list |
| 17935 |
of the corresponding coefficients, from |n=0| to |n=N|. The |N| is given to a |
| 17936 |
|\numexpr|. % |
| 17937 |
\begin{everbatim*} |
| 17938 |
\xintCntoCs {5}{\macro} |
| 17939 |
\end{everbatim*} |
| 17940 |
\begin{everbatim*} |
| 17941 |
\[ \xintTeXFrac{\xintCntoF{5}{\macro}}=\xintCFrac{\xintCntoF {5}{\macro}}\] |
| 17942 |
\end{everbatim*} |
| 17943 |
|
| 17944 |
\subsection{\csh{xintCntoGC}}\label{xintCntoGC} |
| 17945 |
|
| 17946 |
% |
| 17947 |
\csa{xintCntoGC}|{N}{\macro}|\etype{\numx f} evaluates the |c(j)=\macro{j}| from |
| 17948 |
|j=0| to |j=N| and returns a continued fraction written in inline format: |
| 17949 |
|{c(0)}+1/{c(1)}+1/...+1/{c(N)}|. The parameter |N| is given to a |\numexpr|. |
| 17950 |
The coefficients, after expansion, are, as shown, being enclosed in an added |
| 17951 |
pair of braces, they may thus be fractions. |
| 17952 |
\begin{everbatim*} |
| 17953 |
\def\macro #1{\the\numexpr\ifodd#1 -1-#1\else1+#1\fi\relax/\the\numexpr 1+#1*#1\relax} |
| 17954 |
\fdef\x{\xintCntoGC {5}{\macro}}\meaning\x |
| 17955 |
\[\xintGCFrac{\xintCntoGC {5}{\macro}}\] |
| 17956 |
\end{everbatim*} |
| 17957 |
|
| 17958 |
\subsection{\csh{xintGCntoGC}}\label{xintGCntoGC} |
| 17959 |
|
| 17960 |
\csa{xintGCntoGC}|{N}{\macroA}{\macroB}|\etype{\numx ff} evaluates the |
| 17961 |
coefficients and then returns the corresponding |
| 17962 |
|{a0}+{b0}/{a1}+{b1}/{a2}+...+{b(N-1)}/{aN}| inline generalized fraction. |N| is |
| 17963 |
givent to a |\numexpr|. The coefficients are enclosed into pairs |
| 17964 |
of braces, and may thus be fractions, the fraction slash will not be |
| 17965 |
confused in further processing by the continued fraction slashes. |
| 17966 |
% |
| 17967 |
\begin{everbatim*} |
| 17968 |
\def\an #1{\the\numexpr #1*#1*#1+1\relax}% |
| 17969 |
\def\bn #1{\the\numexpr \ifodd#1 -\fi 1*(#1+1)\relax}% |
| 17970 |
$\xintGCntoGC {5}{\an}{\bn}=\xintGCFrac {\xintGCntoGC {5}{\an}{\bn}} = |
| 17971 |
\displaystyle\xintTeXFrac {\xintGCntoF {5}{\an}{\bn}}$\par |
| 17972 |
\end{everbatim*} |
| 17973 |
|
| 17974 |
\subsection{\csh{xintCstoGC}}\label{xintCstoGC} |
| 17975 |
|
| 17976 |
\csa{xintCstoGC}|{a,b,..,z}|\etype{f} transforms a comma separated list (or |
| 17977 |
something expanding to such a list) into an `inline format' continued fraction |
| 17978 |
|{a}+1/{b}+1/...+1/{z}|. The coefficients are just copied and put within braces, |
| 17979 |
without expansion. The output can then be used in \csbxint{GCFrac} for example. |
| 17980 |
\begin{everbatim*} |
| 17981 |
\[\xintGCFrac {\xintCstoGC {-1,1/2,-1/3,1/4,-1/5}}=\xintTeXsignedFrac{\xintCstoF {-1,1/2,-1/3,1/4,-1/5}}\] |
| 17982 |
\end{everbatim*} |
| 17983 |
\subsection{\csh{xintiCstoF}, \csh{xintiGCtoF}, \csh{xintiCstoCv}, \csh{xintiGCtoCv}}\label{xintiCstoF} |
| 17984 |
\label{xintiGCtoF} |
| 17985 |
\label{xintiCstoCv} |
| 17986 |
\label{xintiGCtoCv} |
| 17987 |
|
| 17988 |
Essentially\etype{f} the same as the corresponding macros without the |
| 17989 |
`i', but for integer-only input. Infinitesimally faster, mainly for |
| 17990 |
internal use by the package. |
| 17991 |
|
| 17992 |
\subsection{\csh{xintGCtoGC}}\label{xintGCtoGC} |
| 17993 |
|
| 17994 |
\csa{xintGCtoGC}|{a+b/c+d/e+f/g+......+v/w+x/y}|\etype{f} expands (with the |
| 17995 |
usual meaning) each one of the coefficients and returns an inline continued |
| 17996 |
fraction of the same type, each expanded coefficient being enclosed within |
| 17997 |
braces. |
| 17998 |
% |
| 17999 |
\begin{everbatim*} |
| 18000 |
\fdef\x {\xintGCtoGC {1+\xintPow{1.5}{3}/{1/7}+{-3/5}/% |
| 18001 |
\xintiiFac {6}+\xintCstoF {2,-7,-5}/16}} \meaning\x |
| 18002 |
\end{everbatim*} |
| 18003 |
|
| 18004 |
To be honest I have forgotten for which purpose I wrote this macro in the first |
| 18005 |
place. |
| 18006 |
|
| 18007 |
\subsection{Euler's number \texorpdfstring{$e$}{e}}\label{ssec:e-convergents} |
| 18008 |
|
| 18009 |
Let us explore |
| 18010 |
the convergents of Euler's number $e$. |
| 18011 |
\smallskip The volume of computation is kept minimal by the following steps: |
| 18012 |
\begin{itemize} |
| 18013 |
\item a comma separated list of the first 36 coefficients is produced by |
| 18014 |
\csbxint{CntoCs}, |
| 18015 |
\item this is then given to \csbxint{iCstoCv} which produces the list of the |
| 18016 |
convergents (there is also \csbxint{CstoCv}, but our |
| 18017 |
coefficients being integers we used the infinitesimally |
| 18018 |
faster \csbxint{iCstoCv}), |
| 18019 |
\item then the whole list was converted into a sequence of one-line paragraphs, |
| 18020 |
each convergent becomes the argument to a macro printing it |
| 18021 |
together with its decimal expansion with 30 digits after the decimal point. |
| 18022 |
\item A count register |\cnta| was used to give a line count serving as a visual |
| 18023 |
aid: we could also have done that in an expandable way, but well, let's relax |
| 18024 |
from time to time\dots |
| 18025 |
\end{itemize} |
| 18026 |
|
| 18027 |
\begin{everbatim*} |
| 18028 |
\def\cn #1{\the\numexpr\ifcase \numexpr #1+3-3*((#1+2)/3)\relax |
| 18029 |
1\or1\or2*(#1/3)\fi\relax } |
| 18030 |
% produces the pattern 1,1,2,1,1,4,1,1,6,1,1,8,... which are the |
| 18031 |
% coefficients of the simple continued fraction of e-1. |
| 18032 |
\cnta 0 |
| 18033 |
\def\mymacro #1{\advance\cnta by 1 |
| 18034 |
\noindent |
| 18035 |
\hbox to 3em {\hfil\small\dtt{\the\cnta.} }% |
| 18036 |
$\xintTrunc {30}{\xintAdd {1[0]}{#1}}\dots= |
| 18037 |
\xintTeXFrac{\xintAdd {1[0]}{#1}}$}% |
| 18038 |
\xintListWithSep{\vtop to 6pt{}\vbox to 12pt{}\par} |
| 18039 |
{\xintApply\mymacro{\xintiCstoCv{\xintCntoCs {35}{\cn}}}} |
| 18040 |
\end{everbatim*} |
| 18041 |
|
| 18042 |
|
| 18043 |
\smallskip |
| 18044 |
|
| 18045 |
% The actual computation of the list of all 36 convergents accounts for |
| 18046 |
% only 8\% of the total time (total time equal to about 5 hundredths of a second |
| 18047 |
% in my testing, on my laptop): another 80\% is occupied with the computation of |
| 18048 |
% the truncated decimal expansions (and the addition of 1 to everything as the |
| 18049 |
% formula gives the continued fraction of $e-1$). |
| 18050 |
|
| 18051 |
One can with no problem compute |
| 18052 |
much bigger convergents. Let's get the 200th convergent. It turns out to |
| 18053 |
have the same first 268 digits after the decimal point as $e-1$. Higher |
| 18054 |
convergents get more and more digits in proportion to their index: the 500th |
| 18055 |
convergent already gets 799 digits correct! To allow speedy compilation of the |
| 18056 |
source of this document when the need arises, I limit here to the 200th |
| 18057 |
convergent. |
| 18058 |
% (getting the 500th took about 1.2s on my laptop last time I tried, |
| 18059 |
% and the 200th convergent is obtained ten times faster). |
| 18060 |
\begin{everbatim*} |
| 18061 |
\fdef\z {\xintCntoF {199}{\cn}}% |
| 18062 |
\begingroup\parindent 0pt \leftskip 2.5cm |
| 18063 |
\indent\llap {Numerator = }\printnumber{\xintNumerator\z}\par |
| 18064 |
\indent\llap {Denominator = }\printnumber{\xintDenominator\z}\par |
| 18065 |
\indent\llap {Expansion = }\printnumber{\xintTrunc{268}\z}\dots\par\endgroup |
| 18066 |
\end{everbatim*} |
| 18067 |
|
| 18068 |
|
| 18069 |
One can also use a centered continued fraction: we get more digits but there are |
| 18070 |
also more computations as the numerators may be either |
| 18071 |
$1$ or $-1$. |
| 18072 |
|
| 18073 |
\ifnum\NoSourceCode=1 |
| 18074 |
\clearpage |
| 18075 |
\def\xintRunningHeader{{\inheadertrue\catcode`,12\relax |
| 18076 |
\DOCxintfrontpage, |
| 18077 |
\DOCxintexprintro, |
| 18078 |
\xintbundlename}} |
| 18079 |
|
| 18080 |
\part{The \xintexprname and allied packages source code (not |
| 18081 |
included, see \textcolor{verbcolor}{\texttt{xintsource.pdf}})} |
| 18082 |
|
| 18083 |
\markboth{\makebox[0pt]{\xintRunningHeader}}{\makebox[0pt]{\xintRunningHeader}} |
| 18084 |
\vspace{1cm} |
| 18085 |
|
| 18086 |
\begin{framed} |
| 18087 |
%\small % not now that there is the Part which is rather large |
| 18088 |
|
| 18089 |
This documentation has been compiled without including the |
| 18090 |
commented source code, which is available in the separate file |
| 18091 |
|xintsource.pdf|, |
| 18092 |
and will open in a PDF viewer via: |
| 18093 |
% |
| 18094 |
\centeredline{|texdoc xintsource.pdf|} |
| 18095 |
|
| 18096 |
|
| 18097 |
To produce a file |xint.pdf| including both the user |
| 18098 |
documentation and the source code: |
| 18099 |
\begin{itemize} |
| 18100 |
\item acquire |xint.dtx| from |
| 18101 |
\centeredline{\url{https://www.ctan.org/tex-archive/macros/generic/xint}} |
| 18102 |
\item execute |latex xint.dtx| sufficiently many times (at least three), then |
| 18103 |
|dvipdfmx|, or use |pdflatex|. |
| 18104 |
\end{itemize} |
| 18105 |
|
| 18106 |
For those on Unix-like systems, you can (recommended) alternatively also |
| 18107 |
download a file |Makefile| from the above location then execute |
| 18108 |
|make xint-all.pdf|. This requires |latexmk| and will do automatically |
| 18109 |
the needed number of passes. |
| 18110 |
|
| 18111 |
Without the |Makefile| one can first execute |etex| on |xint.dtx| to |
| 18112 |
extract files then run \centeredline{|make --file=Makefile.mk xint-all.pdf|} |
| 18113 |
|
| 18114 |
Other |make| targets include |xint.pdf| (without implementation part) |
| 18115 |
and |xintsource.pdf|. Run |make help| for help. Further build |
| 18116 |
alternatives are explained in extracted file |xint-all.tex|. |
| 18117 |
|
| 18118 |
The file\NewWithf{1.4m} with both user manual and implementation (i.e. |
| 18119 |
either |xint.pdf| from direct runs of |(pdf)latex| on |xint.dtx| or |
| 18120 |
|xint-all.pdf| if using |make|) will contain hyperlinks from the user |
| 18121 |
documentation to the implementation part and back. And the macros |
| 18122 |
inside the code lines are hyperlinked to the location of their |
| 18123 |
definition. |
| 18124 |
\end{framed} |
| 18125 |
\fi |
| 18126 |
\clearpage |
| 18127 |
\let\xintcfracnameUp\undefined |
| 18128 |
\ifnum\doxintsource=1 |
| 18129 |
+fi |
| 18130 |
+catcode`\ 0 |
| 18131 |
\catcode0 15 % retour à la normale, peu importe |
| 18132 |
\catcode`\+ 12 |
| 18133 |
\makeatletter |
| 18134 |
\@gobble\fi |
| 18135 |
\StopEventually{\end{document}\endinput} |
| 18136 |
\makeatletter |
| 18137 |
\let\csh\cshnolabel |
| 18138 |
% \clearpage |
| 18139 |
% \newgeometry{%hmarginratio=4:3, |
| 18140 |
% hscale=0.7,vscale=0.75}% ATTENTION \newgeometry fait |
| 18141 |
% % un reset de vscale si on ne le |
| 18142 |
% % précise pas ici !!! |
| 18143 |
|
| 18144 |
\AddToHook{env/macrocode/before}{\par@beforemacrocode} |
| 18145 |
\def\par@beforemacrocode{\par} |
| 18146 |
|
| 18147 |
% for \csbxint etc... |
| 18148 |
\let\xintlabelprefix\xintimplabelprefix |
| 18149 |
|
| 18150 |
\def\xintdocMacrocodeFallbackColorCmd{\normalcolor} |
| 18151 |
\def\xintdocPrivateColorCmd{\color{privatecommentcolor}}% |
| 18152 |
\def\xintdocPublicColorCmd{\normalcolor} |
| 18153 |
|
| 18154 |
% stuff going to .toc file (and hence possibly impacting all TOCs regarding the looks |
| 18155 |
% of titles originating in the implementation part) |
| 18156 |
\etocdepthtag.toc {implementation} |
| 18157 |
\addtocontents{toc}{\gdef\string\tocstylesectionbracedcolor{{tocstylesectionimpcolor}}} |
| 18158 |
|
| 18159 |
\etocignoredepthtags |
| 18160 |
\inmanualmaintocfalse % already the case anyhow |
| 18161 |
\etocsetnexttocdepth{section} |
| 18162 |
% make room for some small text on TOC page under the TOC |
| 18163 |
\def\tocstylesectionVSKIP{\vskip\medskipamount} |
| 18164 |
|
| 18165 |
\etocsettocstyle {}{} |
| 18166 |
\ifnum\doxintsource=1 % xintsource.pdf |
| 18167 |
\medskip |
| 18168 |
\tableofcontents |
| 18169 |
\else |
| 18170 |
\ifnum\NoSourceCode=0 % xint-all.pdf |
| 18171 |
% this one needs to be reset as it is modified for the TOCs of the user |
| 18172 |
% manual. This way TOCs of Part III will be in xint-all.pdf as in |
| 18173 |
% xintsource.pdf |
| 18174 |
\let\etoctoclineleaders\orig@etoctoclineleaders |
| 18175 |
\fi |
| 18176 |
|
| 18177 |
\bookmark[dest=imp,level=part]{Implementation} |
| 18178 |
|
| 18179 |
\begin{minipage}[t][8\baselineskip][c]{\linewidth} |
| 18180 |
\RaisedTarget{imp} |
| 18181 |
\part{The \xintexprnameimp and allied packages source code} |
| 18182 |
\RaisedLabel[15]{partiii} |
| 18183 |
\end{minipage} |
| 18184 |
%! ne fonctionne pas ici |
| 18185 |
%! \RaisedLabel[15]{partiii} |
| 18186 |
%! |
| 18187 |
%! \smash n'est pas \long... mais \smash<space> l'est mais \makesm@sh ne l'est pas |
| 18188 |
%! bon de tout façon plus de \par ici |
| 18189 |
%! \protected à cause du \smash sinon |
| 18190 |
%! ! TeX capacity exceeded, sorry [input stack size=10000]. |
| 18191 |
%! <inserted text> |
| 18192 |
%! \protect \foreignlanguage {english}{\protect \bbl@restore@ac... |
| 18193 |
%! l.97 ...er}}{\makebox[0pt]{\xintImpRunningHeader}} |
| 18194 |
%! |
| 18195 |
%! Not using \hypersetup with linkcolor because a few pages are with |
| 18196 |
%! a TOC à cheval on two pages, and my eTOCs are configured to do |
| 18197 |
%! \hypersetup{hidelinks} |
| 18198 |
\protected\def\DOCxintfrontpage |
| 18199 |
{\smash{\vbox{\hbox{\perhapshyperref[frontpage]{{\color{xintnamecolor}TOC}}}% |
| 18200 |
\kern1ex |
| 18201 |
\hbox{\perhapshyperref[partiii]{{\color{xintnameimpcolor}TOC}}}}}}% |
| 18202 |
\medskip |
| 18203 |
|
| 18204 |
\localtableofcontents |
| 18205 |
\fi |
| 18206 |
\medskip |
| 18207 |
\def\etocaftertochook{\addvspace{\bigskipamount}} |
| 18208 |
|
| 18209 |
\etocsettocdepth{subsubsection}% 2015/09/15 |
| 18210 |
% this is a parameter of the custom tocstyling for sections which we |
| 18211 |
% set to this value only after having typeset the main TOC of xintsource.pdf |
| 18212 |
% or TOC of Part III of xint-all.pdf |
| 18213 |
\def\tocstyleMARGEPAGENO{1.25em} |
| 18214 |
|
| 18215 |
% modify the page headers |
| 18216 |
\def\xintImpRunningHeader{{\inheadertrue\catcode`,12\relax |
| 18217 |
\DOCxintfrontpage, |
| 18218 |
\xintkernelnameimp, |
| 18219 |
\xinttoolsnameimp, |
| 18220 |
\xintcorenameimp, |
| 18221 |
\xintnameimp, |
| 18222 |
\xintbinhexnameimp, |
| 18223 |
\xintgcdnameimp, |
| 18224 |
\xintfracnameimp, |
| 18225 |
\xintseriesnameimp, |
| 18226 |
\xintcfracnameimp, |
| 18227 |
\xintexprnameimp, |
| 18228 |
\xinttrignameimp, \xintlognameimp}} |
| 18229 |
\markboth{\makebox[0pt]{\xintImpRunningHeader}}{\makebox[0pt]{\xintImpRunningHeader}} |
| 18230 |
|
| 18231 |
\clearpage |
| 18232 |
\section{An introduction and a brief timeline} |
| 18233 |
|
| 18234 |
This is \expandafter|\xintbndlversion| of \expandafter|\xintbndldate|. |
| 18235 |
|
| 18236 |
The |xintchanges.md| file, included in the |
| 18237 |
\href{https://ctan.org/pkg/xint}{CTAN} upload, contains the complete list of |
| 18238 |
changes relevant to user level since the initial release of the package: |
| 18239 |
% |
| 18240 |
\centeredline{|texdoc xintchanges.md|} |
| 18241 |
|
| 18242 |
It exists in HTML format at the package web page: |
| 18243 |
\centeredline{\url{https://jfbu.github.io/xint/CHANGES.html}} |
| 18244 |
|
| 18245 |
|
| 18246 |
\edef\foo{\columnsep\the\columnsep} |
| 18247 |
\columnsep5\fontcharwd\font`X\relax |
| 18248 |
\begin{multicols}{2}\small\raggedcolumns\columnsep9\fontcharwd\font`X\relax |
| 18249 |
At |1.4m| I added hyperlinks to the macro code. Each instance of a macro |
| 18250 |
in the code is linked with target the location of its definition (via |\def| |
| 18251 |
or |\let| or variants). This has been done via a heist on \ctanpackage{doc} |
| 18252 |
(|v2| version) automated indexing which has been transformed here into |
| 18253 |
automated hyperlinking. |
| 18254 |
Furthermore the codeline where the macro is defined will link to its |
| 18255 |
description in the user manual part of |xint.pdf|. In (optional build) |
| 18256 |
|xintsource.pdf| the link is more |
| 18257 |
modestly targeting the sectioning heading referencing the macro name, if |
| 18258 |
available. In |xint.pdf| the macros documented in the user manual |
| 18259 |
are marked with a \emph{source} link on top of them, targeting their |
| 18260 |
source code. |
| 18261 |
|
| 18262 |
The sad truth however is that my code is poorly documented. The comments |
| 18263 |
\begin{itemize}[nosep] |
| 18264 |
\item are often too scarce, |
| 18265 |
\item have occasional excessive verbosity, |
| 18266 |
\item and are generally inadequate or irrelevant. |
| 18267 |
\end{itemize} |
| 18268 |
The macro comments have had a distinct tendency to record the changes across |
| 18269 |
releases or even those occurring during pre-release development phase, |
| 18270 |
rather than explaining the interface, or perhaps an algorithm. As I am |
| 18271 |
aware of that, I have a mechanism of \myenquote{private comments} which are |
| 18272 |
removed by the |dtx| build script. But then I sometimes use it en masse as |
| 18273 |
it would be too much work to clean-up the existing comments, and as a result |
| 18274 |
the code is not commented at all anymore... A typical example is with |
| 18275 |
\csbxint{iiSquareRoot} which is amply documented in the private sources but |
| 18276 |
only 10\% of it could be of any value to any other reader than myself and it |
| 18277 |
would be simply the description of what |#1|, |#2|, ... stand for. As a |
| 18278 |
result I converted at some point everything into |
| 18279 |
private comments. Extracting the useful parts describing the macro |
| 18280 |
parameters and checking they are actually still valid would be very |
| 18281 |
time-consuming. The real problem here is that the actual underlying |
| 18282 |
algorithms are rarely if ever described. |
| 18283 |
\end{multicols} |
| 18284 |
\foo |
| 18285 |
|
| 18286 |
%\normalsize |
| 18287 |
|
| 18288 |
\begin{itemize} |
| 18289 |
\item Release |1.4n| of |2025/09/05| is mainly a maintenance release, after |
| 18290 |
a few years in a dormant state. The long expected overhaul of floating point |
| 18291 |
is again postponed. |
| 18292 |
\begin{itemize}[nosep] |
| 18293 |
\item \xintbinhexname handles the octal base, and can manage (much) larger inputs, |
| 18294 |
\item |0x|, |0o|, and |0b| prefixes, and |'| added to the \csbxint{eval} syntax, |
| 18295 |
\item |[h]|, |[o]|, |[b]| optional parameter of \csbxint{iieval}, |
| 18296 |
\item Babel active characters are auto-tamed in \csbxint{eval} (hotfix at |1.4o| |
| 18297 |
|2025/09/06| as the feature was only true with \csbxint{iieval}), |
| 18298 |
\item Compatibility with Op\TeX{}, |
| 18299 |
\item Compatibility with Con\TeX t (only |mkxl|). |
| 18300 |
\end{itemize} |
| 18301 |
The |
| 18302 |
extensive hyperlinking added in 2022 to the docs is better shown to user |
| 18303 |
because xint.pdf now (again) contains both the user manual and the commented |
| 18304 |
source code. The packaging was trimmed. |
| 18305 |
\item Release |1.4m| of |2022/06/09| is mainly a documentation upgrade, which |
| 18306 |
added hyperlinks inside the commented macro code, as well as from the user |
| 18307 |
manual to the source code (in |xint-all.pdf|, which is an optional |
| 18308 |
build). It adds compatibility with \ctanpackage{miniltx}. It also |
| 18309 |
inaugurates usage of the engine string comparison primitive. |
| 18310 |
\item Release |1.4i| of |2021/06/11|: extension of the |
| 18311 |
«simultaneous assignments» concept (backwards compatible). |
| 18312 |
\item Release |1.4g| of |2021/05/25|: |
| 18313 |
powers are now parsed in a right associative way. Removal of the |
| 18314 |
single-character operators |&|, \verb=|=, and |=| (deprecated at |1.1|). |
| 18315 |
Reformatted expandable error messages. |
| 18316 |
\item Release |1.4e| of |2021/05/05|: logarithms and exponentials up to 62 |
| 18317 |
digits, trigonometry still mainly done at high level but with guard digits |
| 18318 |
so all digits up to the last one included can be trusted for faithful |
| 18319 |
rounding and high probability of correct rounding. |
| 18320 |
\item Release |1.4| of |2020/01/31|: \xintexprnameimp overhaul to use |
| 18321 |
|\expanded| based expansion control. Many new features, in particular |
| 18322 |
support for input and output of nested structures. Breaking changes, main |
| 18323 |
ones being the (provisory) drop of |x*[a, b,...]|, |x+[a, b,...]| et al.\@ |
| 18324 |
syntax and the requirement of |\expanded| primitive (currently required only |
| 18325 |
by \xintexprnameimp). |
| 18326 |
\item Release |1.3e| of |2019/04/05|: packages \xinttrignameimp, \xintlognameimp; |
| 18327 |
\csa{xintdefefunc} ``non-protected'' variant of \csbxint{deffunc} (at |1.4| |
| 18328 |
the two got merged and \csa{xintdefefunc} became a deprecated alias for |
| 18329 |
\csbxint{deffunc}). |
| 18330 |
Indices removed from |xintsource.pdf|. |
| 18331 |
% Their functionality is advantageously |
| 18332 |
% made available via the search function in PDF viewers. Already the local |
| 18333 |
% tables of contents are useful enough most of the time. |
| 18334 |
\item Release |1.3d| of |2019/01/06|: fix of |1.2p| bug for division with a |
| 18335 |
zero dividend and a one-digit divisor, \csbxint{eval} et al. wrappers, |
| 18336 |
|gcd()| and |lcm()| work with fractions. |
| 18337 |
\item Release |1.3c| of |2018/06/17|: documentation better hyperlinked, |
| 18338 |
indices added to |xintsource.pdf|. Colon in |:=| now optional for |
| 18339 |
\csbxint{defvar} and \csbxint{deffunc}. |
| 18340 |
\item Release |1.3b| of |2018/05/18|: randomness related additions (still WIP). |
| 18341 |
\item Release |1.3a| of |2018/03/07|: efficiency fix of the mechanism for |
| 18342 |
recursive functions. |
| 18343 |
\item Release |1.3| of |2018/03/01|: addition and subtraction use |
| 18344 |
systematically least common multiple of denominators. Extensive |
| 18345 |
under-the-hood refactoring of \csbxint{NewExpr} and \csbxint{deffunc} which |
| 18346 |
now allow recursive definitions. Removal of |1.2o| deprecated macros. |
| 18347 |
\item Release |1.2q| of |2018/02/06|: fix of |1.2l| subtraction bug |
| 18348 |
in special situation; tacit multiplication extended to cases such as |
| 18349 |
|10!20!30!|. |
| 18350 |
\item Release |1.2p| of |2017/12/05|: maps |//| and |/:| to the floored, not |
| 18351 |
truncated, division. Simultaneous assignments possible with \csbxint{defvar}. |
| 18352 |
Efficiency improvements in \xinttoolsnameimp. |
| 18353 |
\item Release |1.2o| of |2017/08/29|: massive deprecations of those macros |
| 18354 |
from \xintcorenameimp and \xintnameimp which filtered their arguments via |
| 18355 |
\csbxint{Num}. |
| 18356 |
\item Release |1.2n| of |2017/08/06|: improvements of \xintbinhexnameimp. |
| 18357 |
\item Release |1.2m| of |2017/07/31|: rewrite of \xintbinhexnameimp in the |
| 18358 |
style of the |1.2| techniques. |
| 18359 |
\item Release |1.2l| of |2017/07/26|: under the hood efficiency improvements |
| 18360 |
in the style of the |1.2| techniques; subtraction refactored. Compatibility |
| 18361 |
of most \xintfracnameimp macros with arguments using non-delimited |
| 18362 |
|\the\numexpr| or |\the\mathcode| etc... |
| 18363 |
\item Release |1.2i| of |2016/12/13|: under the hood efficiency improvements |
| 18364 |
in the style of the |1.2| techniques. |
| 18365 |
\item Release |1.2| of |2015/10/10|: complete refactoring of the core |
| 18366 |
arithmetic macros and faster \csbxint{expr} parser. |
| 18367 |
\item Release |1.1| of |2014/10/28|: extensive changes in \xintexprnameimp. |
| 18368 |
Addition and subtraction do not multiply denominators blindly but sometimes |
| 18369 |
produce smaller ones. Also with that release, packages \xintkernelnameimp |
| 18370 |
and \xintcorenameimp got extracted from \xinttoolsnameimp and \xintnameimp. |
| 18371 |
\item Release |1.09g| of |2013/11/22|: the \xinttoolsnameimp package is |
| 18372 |
extracted from \xintnameimp; addition of \csbxint{loop} and \csbxint{iloop}. |
| 18373 |
\item Release |1.09c| of |2013/10/09|: \csbxint{For}, \csa{xintNewNumExpr} |
| 18374 |
(ancestor of \csbxint{NewExpr}/\csbxint{deffunc} mechanism). |
| 18375 |
\item Release |1.09a| of |2013/09/24|: support for functions by \xintexprnameimp. |
| 18376 |
\item Release |1.08| of |2013/06/07|: the \xintbinhexnameimp package. |
| 18377 |
\item Release |1.07| of |2013/05/25|: support for floating point numbers |
| 18378 |
added to \xintfracnameimp and first release of the \xintexprnameimp package |
| 18379 |
(provided |
| 18380 |
\csbxint{expr} and \csbxint{floatexpr}). |
| 18381 |
\item Release |1.04| of |2013/04/25|: the \xintcfracnameimp package. |
| 18382 |
\item Release |1.03| of |2013/04/14|: the \xintfracnameimp and |
| 18383 |
\xintseriesnameimp packages. |
| 18384 |
\item Release |1.0| of |2013/03/28|: initial release of the \xintnameimp and |
| 18385 |
\xintgcdnameimp packages. |
| 18386 |
\end{itemize} |
| 18387 |
|
| 18388 |
%\clearpage |
| 18389 |
|
| 18390 |
|
| 18391 |
% \macrocode |
| 18392 |
% ========== |
| 18393 |
|
| 18394 |
% 2014/11/04 did some hack with active characters à la upquote for straight |
| 18395 |
% quotes, but this is now irrelevant as we use suitable font from newtxtt with |
| 18396 |
% straight quotes. |
| 18397 |
|
| 18398 |
% doc.sty does \AtBeginDocument{\let\macro@font\MacroFont} and formerly I |
| 18399 |
% overwrote \macro@font to use a newtxtt font with a slashed 0 in the |
| 18400 |
% implementation part. |
| 18401 |
|
| 18402 |
% 2022/05/17 removes this, but I still need to redefine \macro@font to remove some |
| 18403 |
% stuff I formerly added to \MacroFont and which is only useful for the user manual. |
| 18404 |
\def\macro@font {\ttfamily } |
| 18405 |
|
| 18406 |
% no problem as * is not "special" so the active catcode will not be reset |
| 18407 |
\AddToHook{env/macrocode/begin}{\makestarlowast} |
| 18408 |
|
| 18409 |
\AddToHook{env/macrocode/after}{\@nobreakfalse} |
| 18410 |
\AddToHook{env/macrocode/begin}{\partopsep0pt\relax} |
| 18411 |
|
| 18412 |
\begingroup |
| 18413 |
\catcode`\|=\z@ \catcode`\[=\@ne \catcode`\]=\tw@ |
| 18414 |
\catcode`\{=12 \catcode`\}=12 |
| 18415 |
% Let % be active to use a color for it and gray-out |
| 18416 |
% comments left in code (there are few) |
| 18417 |
\catcode`\%=13 \catcode`\ =\active \catcode`\\=\active |
| 18418 |
|gdef|xmacro@code#1% \end{macrocode}[#1|end[macrocode]] |
| 18419 |
|endgroup |
| 18420 |
|
| 18421 |
\begingroup\catcode`\%=\active\catcode`\^^M 13 |
| 18422 |
\gdef%{\begingroup\color{macrocodecommentcolor}\@percentchar\odef |
| 18423 |
{\expandafter\endgroup |
| 18424 |
}}\endgroup |
| 18425 |
|
| 18426 |
|
| 18427 |
|
| 18428 |
\def\xintMakePrivateLetters{\catcode`: 11 \catcode`? 11 \catcode`@ 11 |
| 18429 |
\catcode`^ 11 \catcode`_ 11 } |
| 18430 |
\def\xintexprMakePrivateLetters{\xintMakePrivateLetters \catcode`! 11 } |
| 18431 |
\let\MakePrivateLetters\xintMakePrivateLetters |
| 18432 |
|
| 18433 |
\odef\init@crossref{\init@crossref% |
| 18434 |
\everypar{\refstepcounter{CodelineNo}% |
| 18435 |
\llap{{\xintdocMacrocodeFallbackColorCmd\theCodelineNo}\ |
| 18436 |
\hskip\@totalleftmargin}% |
| 18437 |
}% |
| 18438 |
\catcode`\%\active |
| 18439 |
}% |
| 18440 |
\def\scan@macro{% |
| 18441 |
% we do not insert it yet |
| 18442 |
% \special@escape@char |
| 18443 |
\step@checksum |
| 18444 |
% \ifscan@allowed |
| 18445 |
\let\macro@namepart\@empty |
| 18446 |
% we need this for reasons explained below |
| 18447 |
\let\macro@spacepart\@empty |
| 18448 |
\def\next{\futurelet\next\macro@switch}% |
| 18449 |
% \else \let\next\@empty \fi |
| 18450 |
\next |
| 18451 |
} |
| 18452 |
% unchanged: |
| 18453 |
% \def\macro@switch{\ifcat\noexpand\next a% |
| 18454 |
% \let\next\macro@name |
| 18455 |
% \else \let\next\short@macro \fi |
| 18456 |
% \next} |
| 18457 |
\def\short@macro#1{\special@escape@char#1} |
| 18458 |
% \def\macro@name#1{\edef\macro@namepart{\macro@namepart#1}% |
| 18459 |
% \futurelet\next\more@macroname} |
| 18460 |
% \def\more@macroname{\ifcat\noexpand\next a% |
| 18461 |
% \let\next\macro@name |
| 18462 |
% \else \let\next\macro@finish \fi |
| 18463 |
% \next} |
| 18464 |
\def\more@macroname{\ifcat\noexpand\next a% |
| 18465 |
\expandafter\macro@name |
| 18466 |
% we keep the \next for usage later and start filtering out of the way spaces |
| 18467 |
% this is caused by necessity of handling things such as \let<space>\foo\bar |
| 18468 |
% but also not be fooled by \let<space>#6\macro |
| 18469 |
\else \expandafter\macro@gatherspaces \fi |
| 18470 |
} |
| 18471 |
\def\macro@gatherspaces{% |
| 18472 |
\ifx\next\@xobeysp |
| 18473 |
\expandafter\macro@gatherspaces@i |
| 18474 |
\else |
| 18475 |
\expandafter\macro@finish |
| 18476 |
\fi}% |
| 18477 |
\def\macro@gatherspaces@i#1{% |
| 18478 |
\odef\macro@spacepart{\macro@spacepart#1}% #1 = active space |
| 18479 |
\futurelet\next\macro@gatherspaces}% |
| 18480 |
\newif\iflabelmacro@allowed |
| 18481 |
\newcounter{xintMacroCnt} |
| 18482 |
\def\xintimplabelprefix{src-} |
| 18483 |
\let\xintdoclabelprefix\empty |
| 18484 |
\let\xintlabelprefix\xintimplabelprefix |
| 18485 |
\catcode`_ 11 |
| 18486 |
\def\macro@finish{% |
| 18487 |
\iflabelmacro@allowed |
| 18488 |
\expandafter\in@\expandafter{\expandafter.\macro@namepart,}% |
| 18489 |
{.csname,.expandafter,.noexpand,.else,% |
| 18490 |
.t,.w,.x,.y,.z,.XINT_x,.XINT_y,% |
| 18491 |
.XINT_tmpa,.XINT_tmpb,.XINT_tmpc,.XINT_tmpd,.XINT_tmpe,% _ is letter here |
| 18492 |
.XINT_expr_defbin_b,.XINT_expr_defbin_c,.XINT_expr_defbin_d,% |
| 18493 |
.empty,.space,}% |
| 18494 |
\ifin@ |
| 18495 |
{\xintdocMacrocodeFallbackColorCmd\special@escape@char\macro@namepart}% |
| 18496 |
\else |
| 18497 |
\ifcsname alreadydefined-\macro@namepart\endcsname |
| 18498 |
\hyperref[xintmacro-\macro@namepart]{\special@escape@char\macro@namepart}% |
| 18499 |
\else |
| 18500 |
% this will make a rather large number of macro names in the string pool... |
| 18501 |
\global\expandafter\let\csname alreadydefined-\macro@namepart\endcsname\@empty |
| 18502 |
\label{xintmacro-\macro@namepart}% |
| 18503 |
\stepcounter{xintMacroCnt}% |
| 18504 |
% try to link to a labeled reference in the user documentation (xint-all.pdf) |
| 18505 |
\ifcsname r@\xintdoclabelprefix\macro@namepart\endcsname |
| 18506 |
{\hypersetup{linkcolor=macrocodelinktouserdoccolor}% |
| 18507 |
\hyperref[\xintdoclabelprefix\macro@namepart]% |
| 18508 |
{\textbf{\special@escape@char\macro@namepart}}}% |
| 18509 |
\else |
| 18510 |
% try to link to a labeled section in implementation part |
| 18511 |
\ifcsname r@\xintimplabelprefix\macro@namepart\endcsname |
| 18512 |
{\hypersetup{linkcolor=macrocodelinktosectioncolor}% |
| 18513 |
\hyperref[\xintimplabelprefix\macro@namepart]% |
| 18514 |
{\textbf{\special@escape@char\macro@namepart}}}% |
| 18515 |
\else |
| 18516 |
\textcolor{macrocodenewmacrocolor}{\special@escape@char\macro@namepart}% |
| 18517 |
\fi\fi |
| 18518 |
\fi |
| 18519 |
\fi |
| 18520 |
\labelmacro@allowedfalse |
| 18521 |
\expandafter\in@\expandafter{\expandafter.\macro@namepart,}{.expandafter,}% |
| 18522 |
\ifin@ |
| 18523 |
\ifx\next\scan@macro\labelmacro@allowedtrue\fi |
| 18524 |
\fi |
| 18525 |
\else % end of labelmacro@allowedtrue branch |
| 18526 |
\ifx\next\scan@macro |
| 18527 |
\expandafter\in@\expandafter{\expandafter.\macro@namepart,}% |
| 18528 |
{.def,.edef,.let,.gdef,.xdef,.odef,.oodef,.fdef,}% |
| 18529 |
\ifin@\labelmacro@allowedtrue\fi |
| 18530 |
\fi |
| 18531 |
\ifcsname r@xintmacro-\macro@namepart\endcsname |
| 18532 |
\hyperref[xintmacro-\macro@namepart]{\special@escape@char\macro@namepart}% |
| 18533 |
\else |
| 18534 |
{\xintdocMacrocodeFallbackColorCmd\special@escape@char\macro@namepart}% |
| 18535 |
\fi |
| 18536 |
\fi |
| 18537 |
% \ifnot@excluded |
| 18538 |
% \edef\@tempa{\noexpand\SpecialIndex{\bslash\macro@namepart}}% |
| 18539 |
% \@tempa |
| 18540 |
% \fi |
| 18541 |
\macro@spacepart |
| 18542 |
}% |
| 18543 |
\catcode`_ 8 |
| 18544 |
|
| 18545 |
{\sbox0{\color{macrocodenoncscolor}\xdef\foo{\current@color}}} |
| 18546 |
\ifpdf |
| 18547 |
\ifluatex |
| 18548 |
\edef\xintdoc@macrocode@pushcolor |
| 18549 |
{\pdfextension colorstack\noexpand\@pdfcolorstack push{\foo}\relax} |
| 18550 |
\def\xintdoc@macrocode@popcolor |
| 18551 |
{\pdfextension colorstack\@pdfcolorstack pop\relax} |
| 18552 |
\else |
| 18553 |
\edef\xintdoc@macrocode@pushcolor |
| 18554 |
{\pdfcolorstack\noexpand\@pdfcolorstack push{\foo}\relax} |
| 18555 |
\def\xintdoc@macrocode@popcolor{\pdfcolorstack\@pdfcolorstack pop\relax} |
| 18556 |
\fi |
| 18557 |
\else |
| 18558 |
\ifxetex |
| 18559 |
\edef\xintdoc@macrocode@pushcolor{\special{color push \foo}} |
| 18560 |
\def\xintdoc@macrocode@popcolor{\special{color pop}} |
| 18561 |
\else |
| 18562 |
\ifnum\Withdvipdfmx=1 |
| 18563 |
\edef\xintdoc@macrocode@pushcolor{\special{color push \foo}} |
| 18564 |
\def\xintdoc@macrocode@popcolor{\special{color pop}} |
| 18565 |
\fi |
| 18566 |
\fi |
| 18567 |
\fi |
| 18568 |
\AddToHook{env/macrocode/before}{\xintdoc@macrocode@pushcolor} |
| 18569 |
\AddToHook{env/macrocode/end}{\xintdoc@macrocode@popcolor} |
| 18570 |
% let's use some more quiet color for links inside the code |
| 18571 |
\AddToHook{env/macrocode/begin}{\hypersetup{linkcolor=macrocodelinktocodelinecolor}} |
| 18572 |
% let code line numbers really be fully in the margin |
| 18573 |
\MacroIndent\z@ |
| 18574 |
% HACK OF \@sect |
| 18575 |
% ============== |
| 18576 |
% goal is to add labels but without having to modify currently |
| 18577 |
% existing mark-up in sources. But KOMA makes an extra step needed. |
| 18578 |
% 2018/06/11 |
| 18579 |
\let\original@sect\@sect |
| 18580 |
\def\@sect#1#2#3#4#5#6[#7]#8{\original@sect{#1}{#2}{#3}{#4}{#5}{#6}[{#7}]% |
| 18581 |
{\begingroup |
| 18582 |
%not possible because of KOMA wrappers |
| 18583 |
%\def\csh##1{\csa{##1}\label{\xintdoclabelprefix\detokenize{##1}}}% |
| 18584 |
\let\csh\cshintitle |
| 18585 |
\let\cshn\cshnintitle |
| 18586 |
#8% |
| 18587 |
\endgroup}% |
| 18588 |
}% |
| 18589 |
\def\cshintitle#1{\csa{#1}% |
| 18590 |
\label{\xintlabelprefix\detokenize{#1}}% |
| 18591 |
%\expandafter\DescribeMacro\csname#1\endcsname |
| 18592 |
} |
| 18593 |
% \csan: no backslash |
| 18594 |
\def\cshnintitle#1{\csan{#1}\label{\xintlabelprefix\detokenize{#1}}} |
| 18595 |
\def\storedlinecounts {} |
| 18596 |
\def\StoreCodelineNo #1{% |
| 18597 |
\edef\storedlinecounts{\storedlinecounts |
| 18598 |
{{#1}{\the\c@CodelineNo}{\the\c@xintMacroCnt}}% |
| 18599 |
}% |
| 18600 |
\global\c@CodelineNo \z@ |
| 18601 |
\global\c@xintMacroCnt \z@ |
| 18602 |
} |
| 18603 |
\def\FixInterMacrocodeVspace{% |
| 18604 |
\def\par@beforemacrocode{\gdef\par@beforemacrocode{\par}}% |
| 18605 |
\edef\xintdoc@macrocode@pushcolor{\xdef\noexpand\xintdoc@macrocode@pushcolor |
| 18606 |
{\xintdoc@macrocode@pushcolor}}% |
| 18607 |
\def\macro@font{\ttfamily\unskip\unskip\unskip\unskip\unskip\unskip |
| 18608 |
\global\def\macro@font{\ttfamily}% |
| 18609 |
\xintdoc@macrocode@pushcolor % ai hésité à le mettre au début de \@item |
| 18610 |
}% |
| 18611 |
\let\saved@@item\@item |
| 18612 |
\def\@item[##1]{\let\saved@addpenalty\addpenalty |
| 18613 |
\let\addpenalty\@gobble |
| 18614 |
\saved@@item[{##1}]% |
| 18615 |
\let\addpenalty\saved@addpenalty |
| 18616 |
\global\let\@item\saved@@item}% |
| 18617 |
}% |
| 18618 |
|
| 18619 |
% This is obsolete it is when I was issueing at top level a \color not black. |
| 18620 |
% This is executed in a group |
| 18621 |
%\renewcommand\etocbeforetitlehook{\normalcolor} |
| 18622 |
|
| 18623 |
% lverb environment (formerly \lverb|...|) |
| 18624 |
% ================= |
| 18625 |
% |
| 18626 |
% This started as "long \verb" with same syntax, to be used in the code |
| 18627 |
% comments and spare endless hassle of adding mark-up for verbatim stuff. It |
| 18628 |
% also used \MicroFont like the custom \verb mainly used in user manual but |
| 18629 |
% also in xintsource for parts written "normally" (but using anyhow monospace |
| 18630 |
% font with variable space and hyphenation) which use |...| mark-up. |
| 18631 |
% |
| 18632 |
% It was turned into an environment June 3, 2022 (1.4m) and a mechanism with |
| 18633 |
% active backslash was added to identify control sequence names and add |
| 18634 |
% hyperlinks if available (labels are autogenerated from sectioning headings). |
| 18635 |
% |
| 18636 |
% lverb is a verbatim environment with free flowing of whitespace. |
| 18637 |
% It MUST be used with % characters at start of lines: |
| 18638 |
% |
| 18639 |
%\begin{lverb} |
| 18640 |
% all lines start with % and preferably with %<space> |
| 18641 |
%\end{lverb} |
| 18642 |
% |
| 18643 |
% There must not be a space between % and \end{lverb} |
| 18644 |
% |
| 18645 |
% Inside the environment: |
| 18646 |
% - % is active and must be exclusively located at start of lines |
| 18647 |
|
| 18648 |
% - \ is active and identifies control sequence names, with the _, :, ^, ?, |
| 18649 |
% and @ as letters. The \ should not follow immediately the %, except for |
| 18650 |
% the end of the environment %\end{lverb} |
| 18651 |
% |
| 18652 |
% It would arguably be better to have used specific mark-up in source but |
| 18653 |
% * then we need some way to have catcode 1 and 2 characters |
| 18654 |
% * well, I added no mark-up. I could spend one hour |
| 18655 |
% TeX-programming to reconstruct the source with mark-up |
| 18656 |
% but... |
| 18657 |
% - $ is a catcode 0 escape |
| 18658 |
% - space and end of lines are normal, text flows normally and uses the |
| 18659 |
% newtxttz font currently |
| 18660 |
% - & serves as comment character |
| 18661 |
% - (, :, and ) serve to enter, continue, and exit a sub-mode which does obey |
| 18662 |
% spaces and lines. One can use & at end of a line to let it flow with the |
| 18663 |
% next one if desired. They must immediately follow the % at start of line. |
| 18664 |
% - A dash after the % (%-) inserts a \par |
| 18665 |
% - also the * is active via \makestarlowast Apart from %, \, $, and & special |
| 18666 |
% characters are like in verbatim. So a macro \oneargcs is defined if one |
| 18667 |
% needs an escape for a macro with one parameter: |
| 18668 |
\catcode`_ 11 |
| 18669 |
\def\oneargcs{\catcode`{1\catcode`}2 \onearg_cs} |
| 18670 |
\def\onearg_cs#1#2{#1{#2}\catcode`{12\catcode`}12\relax} |
| 18671 |
% This \oneargcs is to be used as $oneargcs$<cs name>{<arg>} |
| 18672 |
{\catcode32\active% |
| 18673 |
\gdef\myobeyspaces{\catcode32\active\def {\leavevmode\kern\fontcharwd\font`X}}} |
| 18674 |
% |
| 18675 |
% Let \ fetch control sequences names in lverb environments. |
| 18676 |
% For this the characters _, ^, : and ? are considered letters. |
| 18677 |
% \XINT_sptoken is defined in xinttools which is loaded here |
| 18678 |
% even if only typesetting xintsource.pdf |
| 18679 |
% \xint_dothis/\xint_orthat in xintkernel loaded by xinttools |
| 18680 |
\def\lverbbackslash{\bgroup\toks@{}\futurelet\lverb_token\lverb_bs}% |
| 18681 |
\def\lverb_bs{% |
| 18682 |
\ifx\lverb_token\XINT_sptoken\xint_dothis{\lverb_bs_end}\fi |
| 18683 |
% \ifx\lverb_token\lverbpercent should never happen |
| 18684 |
\ifcat\noexpand\lverb_token\relax\xint_dothis{\lverb_bs_end}\fi |
| 18685 |
\ifcat\lverb_token a\xint_dothis{\lverb_bs_i}\fi |
| 18686 |
\if\lverb_token _\xint_dothis{\lverb_bs_i}\fi |
| 18687 |
\if\lverb_token ^\xint_dothis{\lverb_bs_i}\fi |
| 18688 |
% TODO quel mark-up pour autoriser : and ? sans espace pour ponctuation |
| 18689 |
% TODO anglo-saxonne ? |
| 18690 |
% A bit cumbersome but $null or $empty can be used if : is used for |
| 18691 |
% punctuation and not as last letter of a cs, such as \foo$empty: |
| 18692 |
% I checked all instances with : and ? as last character found |
| 18693 |
% by this and added $empty in sources (June 3, 2022). |
| 18694 |
\if\lverb_token :\xint_dothis{\lverb_bs_i}\fi |
| 18695 |
\if\lverb_token ?\xint_dothis{\lverb_bs_i}\fi |
| 18696 |
\xint_orthat{\lverb_bs_end}% |
| 18697 |
}% |
| 18698 |
\def\lverb_bs_i#1{\toks@\expandafter{\the\toks@#1}\futurelet\lverb_token\lverb_bs}% |
| 18699 |
\def\lverb_bs_end{\expandafter\lverbcs\expandafter{\the\toks@}\egroup}% |
| 18700 |
\let\lverbcs\cs |
| 18701 |
|
| 18702 |
% The % is active in the environment |
| 18703 |
% Some complications to change color of private lines and then restore |
| 18704 |
% (the ^^M is not active), so we split into two steps _a and _b |
| 18705 |
\newif\ifprivatecolorison |
| 18706 |
\def\lverbpercent {\catcode32\active\lverbpercent_a}% |
| 18707 |
\def\lverbpercent_a #1{% |
| 18708 |
\if\XINT_sptoken\detokenize{#1}\xint_dothis{% |
| 18709 |
\catcode32 10 |
| 18710 |
\ifprivatecolorison\xintdocPublicColorCmd\fi |
| 18711 |
\privatecolorisonfalse |
| 18712 |
}\fi |
| 18713 |
% The %! mark-up is used for private things which are trimmed by the |
| 18714 |
% build-script out of the dtx. |
| 18715 |
\if!\detokenize{#1}\xint_dothis{% |
| 18716 |
\ifprivatecolorison |
| 18717 |
\else |
| 18718 |
\xintdocPrivateColorCmd |
| 18719 |
\privatecolorisontrue |
| 18720 |
\fi |
| 18721 |
\lverbpercent_b |
| 18722 |
}\fi |
| 18723 |
\xint_orthat{\lverbpercent_b{#1}}% |
| 18724 |
}% |
| 18725 |
\def\lverbpercent_b#1{% |
| 18726 |
\if\XINT_sptoken\detokenize{#1}\xint_dothis{\catcode32 10 }\fi |
| 18727 |
% Special mark-up after % to control linewrap |
| 18728 |
% %- says to start a new paragraph |
| 18729 |
\if-\detokenize{#1}\xint_dothis{\par #1}\fi |
| 18730 |
% %( start an obeylines+obeyspaces context |
| 18731 |
\if(\detokenize{#1}\xint_dothis{\par\bgroup\myobeyspaces\obeylines}\fi |
| 18732 |
\if:\detokenize{#1}\xint_dothis{}\fi |
| 18733 |
% I don't remember why this, it seems I want to kill next indentation |
| 18734 |
% after the obeylines context |
| 18735 |
\if)\detokenize{#1}\xint_dothis{\egroup\everypar{\hskip-\parindent\everypar{}}}\fi |
| 18736 |
% Introduce a \par token if we have two empty commented-out lines |
| 18737 |
% Or if we have a % at the end of the input line |
| 18738 |
\ifx#1\lverbpercent\xint_dothis{\catcode32 10 \par #1}\fi |
| 18739 |
% For tranformation of lverb into environment mark-up 2022/06/03 |
| 18740 |
% The reason for the \detokenize{#1} upfront is that in original |
| 18741 |
% private sources there might a wrapper environment which has made |
| 18742 |
% the % alias to \lverbpercent already but not made the \ active |
| 18743 |
% and then %\begin{lverb} may be encountered with a |
| 18744 |
% catcode 0 backslash. If I did \if\@backslashchar\detokenize{#1} |
| 18745 |
% there would be trouble. This test identifies %\end in a |
| 18746 |
% somewhat fragile way but by convention my mark-up will never |
| 18747 |
% have %\ except for %\end{lverb} |
| 18748 |
\if\detokenize{#1}\@backslashchar\xint_dothis{\lverb@end}\fi |
| 18749 |
\xint_orthat{\catcode32 10 #1}% |
| 18750 |
} |
| 18751 |
\catcode`_ 8 |
| 18752 |
% \long\def\lverb |
| 18753 |
\def\lverb@end end#1lverb#2{\end{lverb}} |
| 18754 |
\newenvironment{lverb} |
| 18755 |
{% |
| 18756 |
\sfcode`!=1000 |
| 18757 |
\relax\ifhanged\else\par\smallskip\fi |
| 18758 |
\let\do\do@noligs \verbatim@nolig@list |
| 18759 |
\let\do\@makeother \dospecials |
| 18760 |
\catcode32 10 \catcode`\& 14 \catcode`\$ 0 |
| 18761 |
\catcode`\% \active |
| 18762 |
\begingroup\lccode`\~`\%\lowercase{\endgroup\let~\lverbpercent}% |
| 18763 |
\catcode`\\ \active |
| 18764 |
\begingroup\lccode`\~`\\\lowercase{\endgroup\let~\lverbbackslash}% |
| 18765 |
\LverbFont |
| 18766 |
\ignorespaces |
| 18767 |
}{\par} |
| 18768 |
% This \@lverb was used before conversion into an environment |
| 18769 |
% \def\@lverb #1{\catcode`#1\active |
| 18770 |
% \lccode`\~`#1\lowercase{\def~}{\egroup\par}}% |
| 18771 |
\def\LverbFont {% |
| 18772 |
% pas concluant \itshape (June 3, 2022) |
| 18773 |
% pas concluant \bfseries |
| 18774 |
%\xintdocPublicColorCmd |
| 18775 |
\makestarlowast |
| 18776 |
} |
| 18777 |
|
| 18778 |
% privatecodecomments |
| 18779 |
% =================== |
| 18780 |
|
| 18781 |
% This is used in the xint*sty files (before being embedded in dtx) |
| 18782 |
% with %! lines. Those lines are removed from public xint.dtx before |
| 18783 |
% upload to CTAN. |
| 18784 |
\newenvironment{privatecodecomments} |
| 18785 |
{\par \textbf{\textcolor{red}{COMMENTAIRES PRIVÉS.}}\par |
| 18786 |
\makestarlowast |
| 18787 |
\begingroup\lccode`\~`\%\lowercase{\endgroup\let~\lverbpercent}% |
| 18788 |
\catcode`\%\active} |
| 18789 |
{\par \textbf{\textcolor{red}{FIN DES COMMENTAIRES PRIVÉS.}}\par} |
| 18790 |
|
| 18791 |
% \changed |
| 18792 |
% ======== |
| 18793 |
|
| 18794 |
% updated 2021/05/29 to use \xintreleasedate (always) and put |
| 18795 |
% second argument if non empty within square brackets. |
| 18796 |
% 2022/06/05 now says "Modified at", and does not display the optional |
| 18797 |
% argument, which contains actual date of the comment. |
| 18798 |
% I wonder if I should keep displaying release date. |
| 18799 |
% 2022/06/10 adds the \ifinchanged |
| 18800 |
\newif\ifhanged |
| 18801 |
\newcommand\changed[2][]{% |
| 18802 |
\par\smallskip\noindent |
| 18803 |
\textbf{Modified at #2\space(\xintreleasedate{#2})%\if\relax\detokenize{#1}\relax |
| 18804 |
%\else\space[commented #1]\fi |
| 18805 |
.}% |
| 18806 |
\hangindent\parindent |
| 18807 |
\hangedtrue |
| 18808 |
% This is absolutely NOT robust. By the way I added a hook to env/macrocode/before |
| 18809 |
% to do \par. |
| 18810 |
\everypar\expandafter\expandafter\expandafter |
| 18811 |
{\expandafter\the\expandafter\everypar |
| 18812 |
\expandafter\everypar\expandafter{\the\everypar}% |
| 18813 |
\hangedfalse}% |
| 18814 |
} |
| 18815 |
|
| 18816 |
% \added |
| 18817 |
% ====== |
| 18818 |
|
| 18819 |
% new 2022/05/16 |
| 18820 |
\newcommand\added[2][]{% |
| 18821 |
\par\smallskip\noindent |
| 18822 |
\textbf{Added at #2\space(\xintreleasedate{#2})\if\relax\detokenize{#1}\relax |
| 18823 |
\else\space[on #1]\fi.}% |
| 18824 |
\hangindent\parindent |
| 18825 |
\hangedtrue |
| 18826 |
% This is absolutely NOT robust. By the way I added a hook to env/macrocode/before |
| 18827 |
% to do \par. |
| 18828 |
\everypar\expandafter\expandafter\expandafter |
| 18829 |
{\expandafter\the\expandafter\everypar |
| 18830 |
\expandafter\everypar\expandafter{\the\everypar}% |
| 18831 |
\hangedfalse}% |
| 18832 |
} |
| 18833 |
% hoping the \hangedfalse will not accumulate |
| 18834 |
|
| 18835 |
% \xintreleasedate |
| 18836 |
% ================ |
| 18837 |
|
| 18838 |
% added 2021/05/29 |
| 18839 |
% xint-dates.txt is produced from CHANGES.md by grep via Makefile rule |
| 18840 |
% 1.09 (2013/09/23) aajouté manuellement car pas dans CHANGES.md |
| 18841 |
% (il y avait un bug "a stray underscore in a code line of xintexpr.sty must |
| 18842 |
% be removed" et CTAN a annoncé seulement 1.09a) |
| 18843 |
% |
| 18844 |
\begingroup\endlinechar-1 |
| 18845 |
\catcode`\`=\active |
| 18846 |
\def`#1 (#2)`{\expandafter\gdef\csname xintreleasedate_#1\endcsname{#2}} |
| 18847 |
`1.09 (2013/09/23)`% pas dans CHANGES.md car remplacé immédiatement par 1.09a |
| 18848 |
\@@input xint-dates.txt |
| 18849 |
\endgroup |
| 18850 |
|
| 18851 |
\def\xintreleasedate#1{% |
| 18852 |
\ifcsname xintreleasedate_#1\endcsname |
| 18853 |
\csname xintreleasedate_#1\endcsname |
| 18854 |
\else |
| 18855 |
\immediate\write128{Pas de date pour #1 en ligne \the\inputlineno}% |
| 18856 |
\error |
| 18857 |
\fi |
| 18858 |
} |
| 18859 |
|
| 18860 |
\expandafter\edef\csname xintreleasedate_\xintbndlversion\endcsname{\xintbndldate} |
| 18861 |
|
| 18862 |
%% END OF MACRO DEFINITIONS FOR XINTSOURCE |
| 18863 |
\MakePercentIgnore |
| 18864 |
%\def\gardesactifs {^^A |
| 18865 |
%\catcode`\<=0 \catcode`\>=11 \catcode`\*=11 \catcode`\/=11 } |
| 18866 |
%\def\gardesinactifs {^^A |
| 18867 |
%\catcode`\<=12 \catcode`\>=12 \catcode`\*=12 \catcode`\/=12 } |
| 18868 |
%\gardesactifs |
| 18869 |
%\let</dtx>\relax |
| 18870 |
%\let<*xintkernel>\gardesinactifs |
| 18871 |
%</dtx>^^A-------------------------------------------------------- |
| 18872 |
%<*xintkernel>^^A------------------------------------------------- |
| 18873 |
%^^A -*- coding: utf-8; mode: doctex; fill-column: 78; sentence-end-double-space: t; eval: (auto-fill-mode -1); fill-paragraph-function: nil; -*- |
| 18874 |
% \clearpage\csname xintkernelnameUp\endcsname |
| 18875 |
% \let\MakePrivateLetters\xintMakePrivateLetters |
| 18876 |
% \section {Package \xintkernelnameimp implementation} |
| 18877 |
% \RaisedLabel{sec:kernelimp} |
| 18878 |
% |
| 18879 |
% \localtableofcontents |
| 18880 |
% |
| 18881 |
% This package provides the common minimal code base for loading management |
| 18882 |
% and catcode control and also a few programming utilities. With |1.2| a few |
| 18883 |
% more helper macros and all |\chardef|'s have been moved here. The package is |
| 18884 |
% loaded by both |xintcore.sty| and |xinttools.sty| hence by all other |
| 18885 |
% packages. |
| 18886 |
% |
| 18887 |
% \changed{1.1} |
| 18888 |
% Separated package. |
| 18889 |
% |
| 18890 |
% \changed{1.2i} |
| 18891 |
% \csbxint{replicate}, \csbxint{gobble}, \csbxint{LengthUpTo} |
| 18892 |
% and \csbxint{LastItem}, and faster \csbxint{Length}. |
| 18893 |
% |
| 18894 |
% \changed{1.3b} |
| 18895 |
% \csbxint{UniformDeviate}. |
| 18896 |
% |
| 18897 |
% \changed[2020/01/11]{1.4} |
| 18898 |
% \csbxint{Replicate}, \csbxint{Gobble}, \csbxint{LastOne}, \csbxint{FirstOne}. |
| 18899 |
% |
| 18900 |
% \changed{1.4l} |
| 18901 |
% Fix the |1.4| added bug that |\XINTrestorecatcodes| forgot to restore |
| 18902 |
% the catcode of |^||^A| which is set to |3| by |\XINTsetcatcodes|. |
| 18903 |
% |
| 18904 |
% \changed{1.4m} |
| 18905 |
% Fix incompatibility under \eTeX{} with \ctanpackage{miniltx}, if latter was |
| 18906 |
% loaded before \xintexprnameimp. The fix happens here because it relates to |
| 18907 |
% matters of |\ProvidesPackage|. |
| 18908 |
% |
| 18909 |
% \subsection{Catcodes, \protect\eTeX{} and reload detection} |
| 18910 |
% |
| 18911 |
% The code for reload detection was initially copied from \textsc{Heiko |
| 18912 |
% Oberdiek}'s packages, then modified. |
| 18913 |
% |
| 18914 |
% The method for catcodes was also initially directly inspired by these |
| 18915 |
% packages. |
| 18916 |
% |
| 18917 |
%\begin{lverb} |
| 18918 |
% 1.4l replaces Info level user messages issued in case of problems |
| 18919 |
% such as \numexpr not being available with Warning level messages (in the |
| 18920 |
% LaTeX terminolgy). Should arguably be Error level in that case. |
| 18921 |
% |
| 18922 |
% xintkernel.sty was the only xint package emitting such an Info, now Warning |
| 18923 |
% in case of being loaded twice (via \input in non-LaTeX). This was probably |
| 18924 |
% a left-over from initial development stage of the loading architecture for |
| 18925 |
% debugging. Starting with 1.4l, it will abort input silently in such case. |
| 18926 |
% |
| 18927 |
% Also at 1.4l I refactored a bit the loading code in the xint*sty files for |
| 18928 |
% no real reason other than losing time. |
| 18929 |
%\end{lverb} |
| 18930 |
% \begin{macrocode} |
| 18931 |
\begingroup\catcode61\catcode48\catcode32=10\relax% |
| 18932 |
\catcode13=5 % ^^M |
| 18933 |
\endlinechar=13 % |
| 18934 |
\catcode123=1 % { |
| 18935 |
\catcode125=2 % } |
| 18936 |
\catcode44=12 % , |
| 18937 |
\catcode46=12 % . |
| 18938 |
\catcode58=12 % : |
| 18939 |
\catcode94=7 % ^ |
| 18940 |
\def\space{ }\newlinechar10 |
| 18941 |
\let\z\relax |
| 18942 |
\expandafter\ifx\csname numexpr\endcsname\relax |
| 18943 |
\expandafter\ifx\csname PackageWarningNoLine\endcsname\relax |
| 18944 |
\immediate\write128{^^JPackage xintkernel Warning:^^J% |
| 18945 |
\space\space\space\space |
| 18946 |
\numexpr not available, aborting input.^^J}% |
| 18947 |
\else |
| 18948 |
\PackageWarningNoLine{xintkernel}{\numexpr not available, aborting input}% |
| 18949 |
\fi |
| 18950 |
\def\z{\endgroup\endinput}% |
| 18951 |
\else |
| 18952 |
\expandafter\ifx\csname XINTsetupcatcodes\endcsname\relax |
| 18953 |
\else |
| 18954 |
\def\z{\endgroup\endinput}% |
| 18955 |
\fi |
| 18956 |
\fi |
| 18957 |
\ifx\z\relax\else\expandafter\z\fi% |
| 18958 |
% \end{macrocode} |
| 18959 |
% \subsubsection{\csh{XINTrestorecatcodes}, \csh{XINTsetcatcodes}, |
| 18960 |
% \csh{XINTrestorecatcodesendinput}} |
| 18961 |
% \changed{1.4e} |
| 18962 |
%\begin{lverb} |
| 18963 |
% Renamed \XINT{set,restore}catcodes |
| 18964 |
% to be without underscores, to facilitate the reloading process |
| 18965 |
% for xintlog.sty and xinttrig.sty in uncontrolled contexts. |
| 18966 |
%\end{lverb} |
| 18967 |
% \changed{1.4l} |
| 18968 |
%\begin{lverb} |
| 18969 |
% Fix the 1.4 bug of omission of \catcode1 restore. |
| 18970 |
% |
| 18971 |
% Reordered all catcodes assignements for easier maintenance and dropped most |
| 18972 |
% disparate indications of which packages make use of which settings. |
| 18973 |
% |
| 18974 |
% The \XINTrestorecatcodes is somewhat misnamed as it is more a template |
| 18975 |
% to be used in an \edef to help define actual catcode restoring macros. |
| 18976 |
% |
| 18977 |
% However \edef needs usually { and } so there is a potential difficulty with |
| 18978 |
% telling people to do \edef\myrestore{\XINTrestorecatcodes}, and I almost |
| 18979 |
% added at 1.4l some \XINTsettorestore$empty:#1->\edef#1{\XINTrestorecatcodes} but |
| 18980 |
% well, this is not public interface anyhow. The reloading method of |
| 18981 |
% xintlog.sty and xinttrig.sty does protect itself though against such irreal |
| 18982 |
% usage possibility with non standard { or }. |
| 18983 |
% |
| 18984 |
% Removed at 1.4l the \XINT_setcatcodes and \XINT_restorecatcodes not used |
| 18985 |
% anywhere now. Used by old version of xintsession.tex, but not anymore since |
| 18986 |
% a while. |
| 18987 |
%\end{lverb} |
| 18988 |
% \changed{1.4n} |
| 18989 |
% Compatibility with Op\TeX. It has a cactode 11 letter, but \cs{abc_} or |
| 18990 |
% \cs{abc_d} will be interpreted un expectedly (but not \cs{abc_de}). So we |
| 18991 |
% must make sure this is deactivated during the whole duration of loading the |
| 18992 |
% \xintnameimp modules (perhaps it is mainly \xinttoolsnameimp which uses |
| 18993 |
% \cs{XINT_x}, \cs{XINT_y}, which is problematic). |
| 18994 |
% |
| 18995 |
% We need catcode letter |_| for tokenization of \cs{PrepareCatcodes} to let |
| 18996 |
% it define \csbXINT{restorecatcodes} conveniently for its usage in an |
| 18997 |
% \cs{edef} to query at that time the |_| status in Op\TeX. |
| 18998 |
% \begin{macrocode} |
| 18999 |
\catcode95=11 % _ |
| 19000 |
\def\PrepareCatcodes |
| 19001 |
{% |
| 19002 |
\endgroup |
| 19003 |
\def\XINTrestorecatcodes |
| 19004 |
{% prepared for use in \edef |
| 19005 |
\catcode0=\the\catcode0 % ^^@ |
| 19006 |
\catcode1=\the\catcode1 % ^^A |
| 19007 |
\catcode13=\the\catcode13 % ^^M |
| 19008 |
\catcode32=\the\catcode32 % <space> |
| 19009 |
\catcode33=\the\catcode33 % ! |
| 19010 |
\catcode34=\the\catcode34 % " |
| 19011 |
\catcode35=\the\catcode35 % # |
| 19012 |
\catcode36=\the\catcode36 % $ |
| 19013 |
\catcode38=\the\catcode38 % & |
| 19014 |
\catcode39=\the\catcode39 % ' |
| 19015 |
\catcode40=\the\catcode40 % ( |
| 19016 |
\catcode41=\the\catcode41 % ) |
| 19017 |
\catcode42=\the\catcode42 % * |
| 19018 |
\catcode43=\the\catcode43 % + |
| 19019 |
\catcode44=\the\catcode44 % , |
| 19020 |
\catcode45=\the\catcode45 % - |
| 19021 |
\catcode46=\the\catcode46 % . |
| 19022 |
\catcode47=\the\catcode47 % / |
| 19023 |
\catcode58=\the\catcode58 % : |
| 19024 |
\catcode59=\the\catcode59 % ; |
| 19025 |
\catcode60=\the\catcode60 % < |
| 19026 |
\catcode61=\the\catcode61 % = |
| 19027 |
\catcode62=\the\catcode62 % > |
| 19028 |
\catcode63=\the\catcode63 % ? |
| 19029 |
\catcode64=\the\catcode64 % @ |
| 19030 |
\catcode91=\the\catcode91 % [ |
| 19031 |
\catcode93=\the\catcode93 % ] |
| 19032 |
\catcode94=\the\catcode94 % ^ |
| 19033 |
\catcode95=\the\catcode95 % _ |
| 19034 |
\catcode96=\the\catcode96 % ` |
| 19035 |
\catcode123=\the\catcode123 % { |
| 19036 |
\catcode124=\the\catcode124 % | |
| 19037 |
\catcode125=\the\catcode125 % } |
| 19038 |
\catcode126=\the\catcode126 % ~ |
| 19039 |
\endlinechar=\the\endlinechar\relax |
| 19040 |
\ifdefined\_ifmathsb\_ifmathsb\noexpand\_mathsbon\_fi\fi % |
| 19041 |
}% |
| 19042 |
% \end{macrocode} |
| 19043 |
%\begin{lverb} |
| 19044 |
% The \noexpand here before \endinput is required. This feels to me a bit |
| 19045 |
% surprising, but is a fact, and the source of this must be in the \edef |
| 19046 |
% implementation but I have not checked it out at this time. |
| 19047 |
%\end{lverb} |
| 19048 |
% |
| 19049 |
% \changed{1.4n} |
| 19050 |
% Compatibility with Op\TeX. |
| 19051 |
% \begin{macrocode} |
| 19052 |
\edef\XINTrestorecatcodesendinput |
| 19053 |
{% |
| 19054 |
\XINTrestorecatcodes\noexpand\endinput % |
| 19055 |
}% |
| 19056 |
\def\XINTsetcatcodes |
| 19057 |
{% standard settings with a few xint*sty specific ones |
| 19058 |
\catcode0=12 % for \romannumeral`&&@ |
| 19059 |
\catcode1=3 % for safe separator &&A |
| 19060 |
\catcode13=5 % ^^M |
| 19061 |
\catcode32=10 % <space> |
| 19062 |
\catcode33=12 % ! but used as LETTER inside xintexpr.sty |
| 19063 |
\catcode34=12 % " |
| 19064 |
\catcode35=6 % # |
| 19065 |
\catcode36=3 % $ |
| 19066 |
\catcode38=7 % & SUPERSCRIPT for && as replacement of ^^ |
| 19067 |
\catcode39=12 % ' |
| 19068 |
\catcode40=12 % ( |
| 19069 |
\catcode41=12 % ) |
| 19070 |
\catcode42=12 % * |
| 19071 |
\catcode43=12 % + |
| 19072 |
\catcode44=12 % , |
| 19073 |
\catcode45=12 % - |
| 19074 |
\catcode46=12 % . |
| 19075 |
\catcode47=12 % / |
| 19076 |
\catcode58=11 % : LETTER |
| 19077 |
\catcode59=12 % ; |
| 19078 |
\catcode60=12 % < |
| 19079 |
\catcode61=12 % = |
| 19080 |
\catcode62=12 % > |
| 19081 |
\catcode63=11 % ? LETTER |
| 19082 |
\catcode64=11 % @ LETTER |
| 19083 |
\catcode91=12 % [ |
| 19084 |
\catcode93=12 % ] |
| 19085 |
\catcode94=11 % ^ LETTER |
| 19086 |
\catcode95=11 % _ LETTER |
| 19087 |
\catcode96=12 % ` |
| 19088 |
\catcode123=1 % { |
| 19089 |
\catcode124=12 % | |
| 19090 |
\catcode125=2 % } |
| 19091 |
\catcode126=3 % ~ MATH SHIFT |
| 19092 |
\endlinechar=13 % |
| 19093 |
\ifdefined\_mathsboff\_mathsboff\fi % Compatibility with OpTeX |
| 19094 |
}% |
| 19095 |
\XINTsetcatcodes |
| 19096 |
}% |
| 19097 |
\PrepareCatcodes |
| 19098 |
% \end{macrocode} |
| 19099 |
% Other modules could possibly be loaded under a different catcode regime. |
| 19100 |
% (or with a different status of |_| under Op\TeX). |
| 19101 |
% \begin{macrocode} |
| 19102 |
\def\XINTsetupcatcodes {% for use by other modules |
| 19103 |
\edef\XINTrestorecatcodesendinput |
| 19104 |
{% |
| 19105 |
\XINTrestorecatcodes\noexpand\endinput % |
| 19106 |
}% |
| 19107 |
\XINTsetcatcodes |
| 19108 |
}% |
| 19109 |
% \end{macrocode} |
| 19110 |
% \subsection{Package identification} |
| 19111 |
% |
| 19112 |
% Inspired from \textsc{Heiko Oberdiek}'s packages.% |
| 19113 |
% \changed{1.09b} |
| 19114 |
% Re-usability in the other modules. Also I assume now that if |\ProvidesPackage| |
| 19115 |
% exists it then does define |\ver@<pkgname>.sty|, code of |HO| for some reason |
| 19116 |
% escaping me (compatibility with LaTeX 2.09 or other things ??) seems to set |
| 19117 |
% extra precautions. [nine years later I understood my mistake, see below]. |
| 19118 |
% |
| 19119 |
% \changed{1.09c} |
| 19120 |
% Usage of \eTeX{} |\ifdefined|. |
| 19121 |
% |
| 19122 |
% \changed[2022/06/09]{1.4m} |
| 19123 |
% Nine years too late, I understand that the |HO| \myenquote{extra |
| 19124 |
% precautions} were there for some respectable reasons including |
| 19125 |
% |etex+miniltx| and surely other things I can not imagine. So let's now make |
| 19126 |
% sure |\[email protected]| and friends get defined on load, even if |
| 19127 |
% |\ProvidesPackage| exists! However I remain careless in using |\ifdefined| |
| 19128 |
% which could be fooled if some previous macro file ended up testing for |
| 19129 |
% |\ProvidesPackage| in a way letting it to |\relax|. I do not test for that. |
| 19130 |
% If I fixed that carelessness here I would have to fix it in other places |
| 19131 |
% where I use similarly |\ifdefined\RequirePackage| or |
| 19132 |
% |\ifdefined\PackageWarning| or whatever. |
| 19133 |
% \begin{macrocode} |
| 19134 |
\ifdefined\ProvidesPackage |
| 19135 |
\def\XINT_providespackage\ProvidesPackage#1[#2]{% |
| 19136 |
\ProvidesPackage{#1}[{#2}]% |
| 19137 |
\expandafter\ifx\csname ver@#1.sty\endcsname\relax |
| 19138 |
\expandafter\xdef\csname ver@#1.sty\endcsname{#2}% |
| 19139 |
\fi |
| 19140 |
}% |
| 19141 |
\else |
| 19142 |
\def\XINT_providespackage\ProvidesPackage#1[#2]{% |
| 19143 |
\immediate\write-1{Package: #1 #2}% |
| 19144 |
\expandafter\xdef\csname ver@#1.sty\endcsname{#2}% |
| 19145 |
}% |
| 19146 |
\fi |
| 19147 |
\XINT_providespackage |
| 19148 |
\ProvidesPackage {xintkernel}% |
| 19149 |
[2025/09/06 v1.4o Paraphernalia for the xint packages (JFB)]% |
| 19150 |
% \end{macrocode} |
| 19151 |
% \subsection{Constants} |
| 19152 |
% \begin{macrocode} |
| 19153 |
\chardef\xint_c_ 0 |
| 19154 |
\chardef\xint_c_i 1 |
| 19155 |
\chardef\xint_c_ii 2 |
| 19156 |
\chardef\xint_c_iii 3 |
| 19157 |
\chardef\xint_c_iv 4 |
| 19158 |
\chardef\xint_c_v 5 |
| 19159 |
\chardef\xint_c_vi 6 |
| 19160 |
\chardef\xint_c_vii 7 |
| 19161 |
\chardef\xint_c_viii 8 |
| 19162 |
\chardef\xint_c_ix 9 |
| 19163 |
\chardef\xint_c_x 10 |
| 19164 |
\chardef\xint_c_xii 12 |
| 19165 |
\chardef\xint_c_xiv 14 |
| 19166 |
\chardef\xint_c_xvi 16 |
| 19167 |
\chardef\xint_c_xvii 17 |
| 19168 |
\chardef\xint_c_xviii 18 |
| 19169 |
\chardef\xint_c_xx 20 |
| 19170 |
\chardef\xint_c_xxii 22 |
| 19171 |
\chardef\xint_c_ii^v 32 |
| 19172 |
\chardef\xint_c_ii^vi 64 |
| 19173 |
\chardef\xint_c_ii^vii 128 |
| 19174 |
\mathchardef\xint_c_ii^viii 256 |
| 19175 |
\mathchardef\xint_c_ii^ix 512 |
| 19176 |
\mathchardef\xint_c_ii^xii 4096 |
| 19177 |
% \end{macrocode} |
| 19178 |
% Some of these usages of \cs{newcount} were in \xintcorenameimp or in |
| 19179 |
% \xintnameimp or in \xintbinhexnameimp possibly conditionally on whether |
| 19180 |
% (pdf)\cs{uniformdeviate} is available. At |1.4n|, let's not bother with |
| 19181 |
% outdated restrictions of \TeX. |
| 19182 |
% \begin{macrocode} |
| 19183 |
\ifdefined\m@ne\let\xint_c_mone\m@ne |
| 19184 |
\else\csname newcount\endcsname\xint_c_mone \xint_c_mone -1 % |
| 19185 |
\fi |
| 19186 |
\mathchardef\xint_c_x^iv 10000 |
| 19187 |
\newcount\xint_c_x^v \xint_c_x^v 100000 |
| 19188 |
\newcount\xint_c_x^viii \xint_c_x^viii 100000000 |
| 19189 |
\newcount\xint_c_x^ix \xint_c_x^ix 1000000000 |
| 19190 |
\newcount\xint_c_x^viii_mone \xint_c_x^viii_mone 99999999 |
| 19191 |
\newcount\xint_c_nine_x^viii \xint_c_nine_x^viii 900000000 |
| 19192 |
\newcount\xint_c_xi_e_viii_mone \xint_c_xi_e_viii_mone 1099999999 |
| 19193 |
\newcount\xint_c_xii_e_viii \xint_c_xii_e_viii 1200000000 |
| 19194 |
% \end{macrocode} |
| 19195 |
% \changed{1.4n} |
| 19196 |
% For some reason this next one used to be defined by \cs{newcount} |
| 19197 |
% but \cs{mathchardef} is ok. |
| 19198 |
% \begin{macrocode} |
| 19199 |
\mathchardef\xint_c_ii^xiv 16384 % "4000, 2**14 |
| 19200 |
\newcount\xint_c_ii^xv \xint_c_ii^xv 32768 % 2**15 |
| 19201 |
\newcount\xint_c_ii^xvi \xint_c_ii^xvi 65536 % 2**16 |
| 19202 |
\newcount\xint_c_ii^xxi \xint_c_ii^xxi 2097152 % "200000, 2**21 |
| 19203 |
% \end{macrocode} |
| 19204 |
% \subsection{Token management utilities} |
| 19205 |
% \added{1.2} |
| 19206 |
% Check if \cs{empty} and \cs{space} have their standard meanings |
| 19207 |
% and raise a warning if not. |
| 19208 |
% \changed{1.4} |
| 19209 |
% Warn user if needed, and force then \cs{empty} and \cs{space} to have |
| 19210 |
% their standard meanings. This will be triggered even if the sole |
| 19211 |
% difference is that they are \cs{long}. |
| 19212 |
% \changed{1.4n} |
| 19213 |
% The Warning used to be emitted only to the log file, make it go to |
| 19214 |
% console output as well. But why do I spend time on such silly things. |
| 19215 |
% \begin{macrocode} |
| 19216 |
\def\XINT_tmpa { }% |
| 19217 |
\ifx\XINT_tmpa\space\else |
| 19218 |
\immediate\write128{Package xintkernel Warning:}% |
| 19219 |
\immediate\write128{The \string\space\XINT_tmpa macro does not have its |
| 19220 |
meaning as in Plain or LaTeX, but is:}% |
| 19221 |
\immediate\write128{\XINT_tmpa\XINT_tmpa\XINT_tmpa\XINT_tmpa\meaning\space.}% |
| 19222 |
\let\space\XINT_tmpa |
| 19223 |
\immediate\write128{Forcing it to be the usual one. Fingers crossed.}% |
| 19224 |
\fi |
| 19225 |
\def\XINT_tmpa {}% |
| 19226 |
\ifx\XINT_tmpa\empty\else |
| 19227 |
\immediate\write128{Package xintkernel Warning:}% |
| 19228 |
\immediate\write128{The \string\empty\space macro does not have its |
| 19229 |
meaning as in Plain or LaTeX, but is:}% |
| 19230 |
\immediate\write128{\space\space\space\space\meaning\empty.}% |
| 19231 |
\let\empty\XINT_tmpa |
| 19232 |
\immediate\write128{Forcing it to be the usual one. Fingers crossed.}% |
| 19233 |
\fi |
| 19234 |
\let\XINT_tmpa\relax |
| 19235 |
\let\xint_gobble_\empty |
| 19236 |
\long\def\xint_gobble_i #1{}% |
| 19237 |
\long\def\xint_gobble_ii #1#2{}% |
| 19238 |
\long\def\xint_gobble_iii #1#2#3{}% |
| 19239 |
\long\def\xint_gobble_iv #1#2#3#4{}% |
| 19240 |
\long\def\xint_gobble_v #1#2#3#4#5{}% |
| 19241 |
\long\def\xint_gobble_vi #1#2#3#4#5#6{}% |
| 19242 |
\long\def\xint_gobble_vii #1#2#3#4#5#6#7{}% |
| 19243 |
\long\def\xint_gobble_viii #1#2#3#4#5#6#7#8{}% |
| 19244 |
% \end{macrocode} |
| 19245 |
% \changed{1.3b} |
| 19246 |
% Moved here |\xint_gobandstop_...| macros because this is handy for |
| 19247 |
% \csbxint{RandomDigits}. |
| 19248 |
% |
| 19249 |
% For legacy reasons most top level macros use |\romannumeral0| trigger. This |
| 19250 |
% is stopped by a space token. Later in the history of the package |
| 19251 |
% |\romanumeral`&&@| was used with |&| of catcode 7. Also there are a few |
| 19252 |
% instances of |\romannumeral| ended by |\z@|. But |\romannumeral0| remains |
| 19253 |
% the publicly documented one, with CamelCase macros using it as prefix to |
| 19254 |
% lowercased macros. |
| 19255 |
% \begin{macrocode} |
| 19256 |
\let\xint_gob_andstop_\space |
| 19257 |
\long\def\xint_gob_andstop_i #1{ }% |
| 19258 |
\long\def\xint_gob_andstop_ii #1#2{ }% |
| 19259 |
\long\def\xint_gob_andstop_iii #1#2#3{ }% |
| 19260 |
\long\def\xint_gob_andstop_iv #1#2#3#4{ }% |
| 19261 |
\long\def\xint_gob_andstop_v #1#2#3#4#5{ }% |
| 19262 |
\long\def\xint_gob_andstop_vi #1#2#3#4#5#6{ }% |
| 19263 |
\long\def\xint_gob_andstop_vii #1#2#3#4#5#6#7{ }% |
| 19264 |
\long\def\xint_gob_andstop_viii #1#2#3#4#5#6#7#8{ }% |
| 19265 |
\let\xint_stop_aftergobble\xint_gob_andstop_i |
| 19266 |
\long\def\xint_firstofone #1{#1}% |
| 19267 |
\long\def\xint_firstoftwo #1#2{#1}% |
| 19268 |
\long\def\xint_secondoftwo #1#2{#2}% |
| 19269 |
\long\def\xint_stop_atfirstofone #1{ #1}% |
| 19270 |
\long\def\xint_stop_atfirstoftwo #1#2{ #1}% |
| 19271 |
\long\def\xint_stop_atsecondoftwo #1#2{ #2}% |
| 19272 |
\long\def\xint_exchangetwo_keepbraces #1#2{{#2}{#1}}% |
| 19273 |
% \end{macrocode} |
| 19274 |
% Moved here from \xintnameimp at |1.4n|. |
| 19275 |
% \begin{macrocode} |
| 19276 |
\long\def\xint_firstofthree #1#2#3{#1}% |
| 19277 |
\long\def\xint_secondofthree #1#2#3{#2}% |
| 19278 |
\long\def\xint_thirdofthree #1#2#3{#3}% |
| 19279 |
\long\def\xint_stop_atfirstofthree #1#2#3{ #1}% |
| 19280 |
\long\def\xint_stop_atsecondofthree #1#2#3{ #2}% |
| 19281 |
\long\def\xint_stop_atthirdofthree #1#2#3{ #3}% |
| 19282 |
% \end{macrocode} |
| 19283 |
% \subsection{``gob til'' macros and UD style fork} |
| 19284 |
% \begin{macrocode} |
| 19285 |
\long\def\xint_gob_til_R #1\R {}% |
| 19286 |
\long\def\xint_gob_til_W #1\W {}% |
| 19287 |
\long\def\xint_gob_til_Z #1\Z {}% |
| 19288 |
\long\def\xint_gob_til_zero #10{}% |
| 19289 |
\long\def\xint_gob_til_one #11{}% |
| 19290 |
\long\def\xint_gob_til_zeros_iii #1000{}% |
| 19291 |
\long\def\xint_gob_til_zeros_iv #10000{}% |
| 19292 |
\long\def\xint_gob_til_eightzeroes #100000000{}% |
| 19293 |
\long\def\xint_gob_til_dot #1.{}% |
| 19294 |
\long\def\xint_gob_til_G #1G{}% |
| 19295 |
\long\def\xint_gob_til_minus #1-{}% |
| 19296 |
\long\def\xint_UDzerominusfork #10-#2#3\krof {#2}% |
| 19297 |
\long\def\xint_UDzerofork #10#2#3\krof {#2}% |
| 19298 |
\long\def\xint_UDsignfork #1-#2#3\krof {#2}% |
| 19299 |
\long\def\xint_UDwfork #1\W#2#3\krof {#2}% |
| 19300 |
\long\def\xint_UDXINTWfork #1\XINT_W#2#3\krof {#2}% |
| 19301 |
\long\def\xint_UDzerosfork #100#2#3\krof {#2}% |
| 19302 |
\long\def\xint_UDonezerofork #110#2#3\krof {#2}% |
| 19303 |
\long\def\xint_UDsignsfork #1--#2#3\krof {#2}% |
| 19304 |
\let\xint:\char |
| 19305 |
\long\def\xint_gob_til_xint:#1\xint:{}% |
| 19306 |
\long\def\xint_gob_til_^#1^{}% |
| 19307 |
\def\xint_bracedstopper{\xint:}% |
| 19308 |
\long\def\xint_gob_til_exclam #1!{}% This ! has catcode 12 |
| 19309 |
\long\def\xint_gob_til_sc #1;{}% |
| 19310 |
% \end{macrocode} |
| 19311 |
% \subsection{\csh{xint_afterfi}} |
| 19312 |
% \begin{macrocode} |
| 19313 |
\long\def\xint_afterfi #1#2\fi {\fi #1}% |
| 19314 |
% \end{macrocode} |
| 19315 |
% \subsection{\csh{xint_bye}, \csh{xint_Bye}} |
| 19316 |
% \changed{1.09} |
| 19317 |
% |\xint_bye| |
| 19318 |
% \changed{1.2i} |
| 19319 |
%^^A test de lverb |
| 19320 |
%\begin{lverb} |
| 19321 |
% \xint_Bye for \xintDSRr and \xintRound. Also \xint_stop_afterbye. |
| 19322 |
%\end{lverb} |
| 19323 |
% \begin{macrocode} |
| 19324 |
\long\def\xint_bye #1\xint_bye {}% |
| 19325 |
\long\def\xint_Bye #1\xint_bye {}% |
| 19326 |
\long\def\xint_stop_afterbye #1\xint_bye { }% |
| 19327 |
% \end{macrocode} |
| 19328 |
% \subsection{\csh{xintdothis}, \csh{xintorthat}} |
| 19329 |
% \changed{1.1} |
| 19330 |
% \changed{1.2} Names without underscores. |
| 19331 |
% |
| 19332 |
% To be used this way: |
| 19333 |
%\begin{lverb} |
| 19334 |
%( \if..\xint_dothis{..}\fi |
| 19335 |
%: \if..\xint_dothis{..}\fi |
| 19336 |
%: \if..\xint_dothis{..}\fi |
| 19337 |
%: ...more such... |
| 19338 |
%: \xint_orthat{...} |
| 19339 |
%) |
| 19340 |
%\end{lverb} |
| 19341 |
% Ancient testing indicated it is more efficient to list first the more |
| 19342 |
% improbable clauses. |
| 19343 |
% \begin{macrocode} |
| 19344 |
\long\def\xint_dothis #1#2\xint_orthat #3{\fi #1}% 1.1 |
| 19345 |
\let\xint_orthat \xint_firstofone |
| 19346 |
\long\def\xintdothis #1#2\xintorthat #3{\fi #1}% |
| 19347 |
\let\xintorthat \xint_firstofone |
| 19348 |
% \end{macrocode} |
| 19349 |
% \subsection{\csh{xint_zapspaces}} |
| 19350 |
% \changed{1.1} |
| 19351 |
% This little (quite fragile in the normal sense i.e. non robust in the normal |
| 19352 |
% sense of programming lingua) utility zaps leading, intermediate, trailing, |
| 19353 |
% spaces in completely expanding context (|\edef|, |\csname...\endcsname|). |
| 19354 |
% \centeredline{Usage: |\xint_zapspaces foo<space>\xint_gobble_i|} |
| 19355 |
% |
| 19356 |
% Explanation: if there are leading spaces, then the first |#1| will be empty, |
| 19357 |
% and the first |#2| being undelimited will be stripped from all the remaining |
| 19358 |
% leading spaces, if there was more than one to start with. Of course |
| 19359 |
% brace-stripping may occur. And this iterates: each time a |#2| is removed, |
| 19360 |
% either we then have spaces and next |#1| will be empty, or we have no spaces |
| 19361 |
% and |#1| will end at the first space. Ultimately |#2| will be |
| 19362 |
% |\xint_gobble_i|. |
| 19363 |
% |
| 19364 |
% The |
| 19365 |
% |\zap@spaces| of LaTeX2e handles unexpectedly things such as |
| 19366 |
% \centeredline{|\zap@spaces 1 {22} 3 4 \@empty|} (spaces are not all |
| 19367 |
% removed). This does not happen with |\xint_zapspaces|. |
| 19368 |
% |
| 19369 |
% But for example |\foo{aa} {bb} {cc}| where |\foo| is a macro with three |
| 19370 |
% non-delimited arguments breaks expansion, as expansion of |\foo| will happen |
| 19371 |
% with |\xint_zapspaces| still around, and even if it wasn't it would have |
| 19372 |
% stripped the braces around |{bb}|, certainly breaking other things. |
| 19373 |
% |
| 19374 |
% Despite such obvious shortcomings it is enough for our purposes. It is |
| 19375 |
% currently used by \xintexprnameimp at various locations e.g. cleaning up |
| 19376 |
% optional argument of |\xintiexpr| and |\xintfloatexpr|; maybe in future |
| 19377 |
% internal usage will drop this in favour of a more robust utility. |
| 19378 |
% |
| 19379 |
% \changed{1.2e} |\xint_zapspaces_o|. |
| 19380 |
% |
| 19381 |
% \changed{1.2i} Made |\long|. |
| 19382 |
% |
| 19383 |
% ATTENTION THAT \xinttoolsnameimp HAS AN |\xintzapspaces| WHICH SHOULD NOT |
| 19384 |
% GET CONFUSED WITH THIS ONE. |
| 19385 |
% \begin{macrocode} |
| 19386 |
\long\def\xint_zapspaces #1 #2{#1#2\xint_zapspaces }% 1.1 |
| 19387 |
\long\def\xint_zapspaces_o #1{\expandafter\xint_zapspaces#1 \xint_gobble_i}% |
| 19388 |
% \end{macrocode} |
| 19389 |
% \subsection{\csh{odef}, \csh{oodef}, \csh{fdef}} |
| 19390 |
% May be prefixed with |\global|. No parameter text. |
| 19391 |
% \begin{macrocode} |
| 19392 |
\def\xintodef #1{\expandafter\def\expandafter#1\expandafter }% |
| 19393 |
\def\xintoodef #1{\expandafter\expandafter\expandafter\def |
| 19394 |
\expandafter\expandafter\expandafter#1% |
| 19395 |
\expandafter\expandafter\expandafter }% |
| 19396 |
\def\xintfdef #1#2% |
| 19397 |
{\expandafter\def\expandafter#1\expandafter{\romannumeral`&&@#2}}% |
| 19398 |
\ifdefined\odef\else\let\odef\xintodef\fi |
| 19399 |
\ifdefined\oodef\else\let\oodef\xintoodef\fi |
| 19400 |
\ifdefined\fdef\else\let\fdef\xintfdef\fi |
| 19401 |
% \end{macrocode} |
| 19402 |
% \subsection{\csh{xintMessage}, \csh{ifxintverbose}} |
| 19403 |
% \changed{1.2c} For use by \csbxint{defvar} and \csbxint{deffunc} of |
| 19404 |
% \xintexprnameimp. |
| 19405 |
% |
| 19406 |
% \changed{1.2e} Uses |\write128| rather than |\write16| for compatibility |
| 19407 |
% with future extended range of output streams, in Lua\TeX{} in particular. |
| 19408 |
% |
| 19409 |
% \changed{1.3e} Set the |\newlinechar|. |
| 19410 |
% \begin{macrocode} |
| 19411 |
\edef\XINT_fourspaces{\space\space\space\space}% |
| 19412 |
\def\xintMessage #1#2#3{% |
| 19413 |
\edef\XINT_newlinechar{\the\newlinechar}% |
| 19414 |
\newlinechar10 |
| 19415 |
\immediate\write128{Package #1 #2: (on line \the\inputlineno)}% |
| 19416 |
\immediate\write128{\XINT_fourspaces#3}% |
| 19417 |
\newlinechar\XINT_newlinechar\space |
| 19418 |
}% |
| 19419 |
\newif\ifxintverbose |
| 19420 |
% \end{macrocode} |
| 19421 |
% \subsection{\csh{ifxintglobaldefs}, \csh{XINT_global}} |
| 19422 |
% \changed{1.3c} |
| 19423 |
% \begin{macrocode} |
| 19424 |
\newif\ifxintglobaldefs |
| 19425 |
\def\XINT_global{\ifxintglobaldefs\global\fi}% |
| 19426 |
% \end{macrocode} |
| 19427 |
% \subsection{(WIP) Expandable error message} |
| 19428 |
% \changed[2017/07/26]{1.2l} But really belongs to next major release beyond |1.3|. |
| 19429 |
% Basically copied over from l3kernel code. Using |\ ! /| control sequence, |
| 19430 |
% which must be left undefined. |\xintError:| would be 6 letters more. |
| 19431 |
% |
| 19432 |
% \changed[2020/01/25]{1.4} Finally rather than |\ ! /| I use |\xint/|. |
| 19433 |
% |
| 19434 |
% \changed[2021/05/19]{1.4g} Rewrote to use not an undefined control |
| 19435 |
% sequence but trigger "Use of |\xint/| doesn't match its definition." message. |
| 19436 |
% |
| 19437 |
% \changed[2021/05/20]{1.4g} Things evolve fast and I switch to a third |
| 19438 |
% method which will exploit "Paragraph ended before |\foo| was complete" style |
| 19439 |
% error. See |
| 19440 |
% \centeredline{\url{https://github.com/latex3/latex3/issues/931#issuecomment-845367201}} |
| 19441 |
% However I can not fully exploit this because xint may be used with |
| 19442 |
% Plain etex which does not set |\newlinechar|. |
| 19443 |
% I can only use a poorman version with no usage of |^^J|. Also |
| 19444 |
% \ctanpackage{xintsession} could use the |^^J|, maybe I will integrate it |
| 19445 |
% there. |
| 19446 |
% |
| 19447 |
% \def\xintsession{\ctanpackage{xintsession}} |
| 19448 |
% |
| 19449 |
%\begin{lverb} |
| 19450 |
% I. Explanations on 2021/05/19 and 2021/05/20 before final change |
| 19451 |
% |
| 19452 |
% First I tried out things with undefined control sequence such as |
| 19453 |
%(\ an error was reported by xint ... % |
| 19454 |
%) |
| 19455 |
% whose output produces a nice symmetrical display with no \, and with ... both |
| 19456 |
% on left and right but this reduces drastically the available |
| 19457 |
% space for the actual error context. No go. But see 2021/05/20 update below! |
| 19458 |
% |
| 19459 |
% Having replaced \xint/ by "\xint ", I next opted provisorily for "\Hit |
| 19460 |
% RET at ?" control sequence, despite it being quite longer. And then I |
| 19461 |
% thought about using "\ xint error", possibly with an included ^^J in the name, |
| 19462 |
% or in the context. |
| 19463 |
% |
| 19464 |
% I experimented with ^^J in the context. But the context size is much |
| 19465 |
% constrained, and when \errorcontextlines is at its default value of 5 for |
| 19466 |
% etex, not -1 as done by LaTeX, having the info shifted to the right makes it |
| 19467 |
% actually more visible. (however I have now updated $xintsession$ to 0.2b which |
| 19468 |
% sets \errorcontextlines to 0) |
| 19469 |
% |
| 19470 |
% So I was finally back here to square one, apart from having replaced "\xint/" |
| 19471 |
% by the more longish "\ xint error", hesitating with "\xinterrupt"... |
| 19472 |
% |
| 19473 |
% Then I had the idea to replace the undefined control sequence method by a |
| 19474 |
% method with a macro \foo defined as \def\foo.{} but used as \foo<space> for |
| 19475 |
% example. This gives something like this (the first line will be otherwise |
| 19476 |
% if engine is run with -file-line-error): |
| 19477 |
%( ! Use of \xint/ doesn't match its definition. |
| 19478 |
%: <argument> \xint/ |
| 19479 |
%: Ooops, looks like we are missing a ] (hit RET) |
| 19480 |
%) |
| 19481 |
% \xint/<space> (where the space is the unexpected token, the definition |
| 19482 |
% expecting rather a full stop) makes for 7 characters |
| 19483 |
% to compare to \ xint error which had 12, so I gained back 5. |
| 19484 |
% |
| 19485 |
% Back to ^^J: I had overlooked that TeX in the first part of the error |
| 19486 |
% message will display \macro fully, so inserting ^^J in its name allows |
| 19487 |
% arbitrarily long expandable error messages... as pointed out by BLF in |
| 19488 |
% latex3/issues#931 as I read on the morning of 2021/05/20. This is very nice |
| 19489 |
% but requires to predefine control sequences for each message, and also the |
| 19490 |
% actual arguments #1, #2, ... values can appear only in the context. |
| 19491 |
% |
| 19492 |
% And the situation with ^^J is somewhat complicated: |
| 19493 |
% |
| 19494 |
% $xintsession$ sets the \newlinechar to 10, but this is not the case with bare |
| 19495 |
% usage of xintexpr with etex. And this matters. To discuss ^^J we have to |
| 19496 |
% separate two locations: |
| 19497 |
%(- it appears in the control sequence name, |
| 19498 |
%:- or in the context (which itself has two parts) |
| 19499 |
%) |
| 19500 |
% |
| 19501 |
% 1) When in the context, what happens with ^^J is independent of the setting of |
| 19502 |
% \newlinechar, and with TeXLive pdflatex the ^^J will induce a linebreak, but |
| 19503 |
% with xelatex it must be used with option -8bit. |
| 19504 |
% |
| 19505 |
% $noindent2) When in the control sequence name the behaviour in log/terminal of ^^J is |
| 19506 |
% influenced by the setting of \newlinechar. Although with pdflatex it will |
| 19507 |
% always induce a linebreak, the actual count of characters where TeX will |
| 19508 |
% forcefully break is influenced by whether ^^J is or not \newlinechar. And |
| 19509 |
% with xelatex if it is \newlinechar, it does not depend then if -8bit or not, |
| 19510 |
% but if not \newlinechar then it does and TeX forceful breaks also change |
| 19511 |
% as for pdflatex. |
| 19512 |
% |
| 19513 |
% So, the control sequence name trick can be used to obtain arbitrarily |
| 19514 |
% long messages, but the \newlinechar must be set. |
| 19515 |
% |
| 19516 |
% And in the context, we can try to insert some ^^J but this would need |
| 19517 |
% with xetex the -8bit option, and anyhow the context size is limited, |
| 19518 |
% and there is apparently no trick to get it larger. |
| 19519 |
% |
| 19520 |
% So, in view of all the above I decided not to use ^^J (rather $&$&J |
| 19521 |
% here) at all, whether here in the control sequence or the context or |
| 19522 |
% inserted in \XINT_signalcondition in the context! |
| 19523 |
% |
| 19524 |
% I also have a problem with usage from bnumexpr or polexpr for example, |
| 19525 |
% they would need their own to avoid perhaps displaying \xint/ or analogous. |
| 19526 |
% |
| 19527 |
% II. Finally I modified again the method (completely, and no more need for |
| 19528 |
% funny catcode 7 space as delimiter) as this allows a longer context message, |
| 19529 |
% starting at start of line, and which obeys ^^J if \newlinechar is set to |
| 19530 |
% it. It also allows to incorporate non-limited generic explanations as a |
| 19531 |
% postfix, with linebreaks if \newlinechar is known. |
| 19532 |
% |
| 19533 |
% But as $xintexprnameimp can be used with Plain+etex which does not set the |
| 19534 |
% \newlinechar, I can't use ^^J out of thee box. I can in $xintsession. |
| 19535 |
% What I decided finally is to make a conditional definition here. |
| 19536 |
% |
| 19537 |
% In both cases I include the "hit RET" (how rather "hit <return>") in the |
| 19538 |
% control sequence name serving to both provide extra information and trigger |
| 19539 |
% the error from being defined short and finding a \par. |
| 19540 |
% |
| 19541 |
% The maximal size was increased from 48 characters (method with \xint/ being |
| 19542 |
% badly delimited), to now 55 characters (using "! xint error:<^^J or space>" |
| 19543 |
% as prefix to the message). Longer messages are truncated at 56 characters |
| 19544 |
% with an appended "\ETC.". |
| 19545 |
% |
| 19546 |
% As it is late on this 2021/05/20, and in order to not have to change all |
| 19547 |
% usages, I keep \XINT_signalcondition (in $xintcorenameimp) as a one argument |
| 19548 |
% macro for time being, so will not include a more specific module name. |
| 19549 |
% |
| 19550 |
% The \par token has a special role here, and can't be (I)nserted without |
| 19551 |
% damage, but who would want to insert it in an expandable computation |
| 19552 |
% anyhow... and I don't need it in my custom error messages for sure. |
| 19553 |
% |
| 19554 |
% On 2021/05/21 I add a test about \newlinechar at time of package loading, |
| 19555 |
% and make two distinct definitions: one using ^^J in the control sequence, |
| 19556 |
% the other not using it. |
| 19557 |
% |
| 19558 |
% The -file-line-error toggle makes it impossible to control if the |
| 19559 |
% line-break on first line will match next lines. In the ^^J branch I insert |
| 19560 |
% "| " (no, finally "$ $ " with two spaces) at start of continuation lines. |
| 19561 |
% Also I preferred to ensure a good-looking first line break for the case it |
| 19562 |
% starts with a "! Paragraph ended ..." because a priori error messages will |
| 19563 |
% be read if -file-line-error was emitted only a fortiori (this toggle |
| 19564 |
% suggests some IDE launched TeX and probably -interaction=nonstopmode). |
| 19565 |
% |
| 19566 |
% I will perhaps make another definition in $xintsession$ (it currently loads |
| 19567 |
% xintexpr prior to having set the \newlinechar, so the no ^^J definition will |
| 19568 |
% be used, if nothing else is modified there). |
| 19569 |
% |
| 19570 |
% With some hesitation I do not insert a ^^J after "! xint error:", as |
| 19571 |
% Emacs/AucTeX will display only the first line prominently and then the rest |
| 19572 |
% (which is in file:line:error mode) in one block under "--- TeX said ---". I |
| 19573 |
% use the ^^J only in the generic helper message embedded in the control |
| 19574 |
% sequence. The cases with or without \newlinechar being 10 diverge a bit, as |
| 19575 |
% in the latter case I had to ensure acceptable linebreaks at 79 chars, and I |
| 19576 |
% did that first and then had spent enough time on the matter not to add more |
| 19577 |
% to backport the latest ^^J style message. |
| 19578 |
%\end{lverb} |
| 19579 |
% \changed[2022/06/05]{1.4m} |
| 19580 |
% Shorten the error message. I am always too verbose initially. |
| 19581 |
% |
| 19582 |
% \changed[2025/08/09]{1.4n} |
| 19583 |
% Let not use explicit \cs{par} token as delimiter, but implicit one |
| 19584 |
% from empty line. This is for compatibility with Op\TeX. |
| 19585 |
% Indeed, I observed that with Op\TeX, |{\foo\par}| wuth \cs{foo} being |
| 19586 |
% short reports an extra |}| rather than saying |
| 19587 |
% ``Paragraph ended before \cs{foo} was complete.''. |
| 19588 |
% \begin{macrocode} |
| 19589 |
\ifnum\newlinechar=10 |
| 19590 |
\expandafter\def\csname |
| 19591 |
xint<...> is done, but will resume:&&J \space |
| 19592 |
hit <return> at the ? prompt to try fixing the error above&&J \space |
| 19593 |
which has been encountered before expansion\endcsname |
| 19594 |
#1\xint:{}% |
| 19595 |
\def\XINT_expandableerror#1{% |
| 19596 |
\def\XINT_expandableerror##1{% |
| 19597 |
\expandafter |
| 19598 |
\XINT_expandableerrorcontinue |
| 19599 |
#1! xint error: ##1% |
| 19600 |
|
| 19601 |
}}\expandafter\XINT_expandableerror\csname |
| 19602 |
xint<...> is done, but will resume:&&J \space |
| 19603 |
hit <return> at the ? prompt to try fixing the error above&&J \space |
| 19604 |
which has been encountered before expansion\endcsname |
| 19605 |
\else |
| 19606 |
\expandafter\def\csname |
| 19607 |
xint<...> is done, but will resume: hit <return> at \space |
| 19608 |
the ? prompt to try fixing the error encountered before expansion\endcsname |
| 19609 |
#1\xint:{}% |
| 19610 |
\def\XINT_expandableerror#1{% |
| 19611 |
\def\XINT_expandableerror##1{% |
| 19612 |
\expandafter |
| 19613 |
\XINT_expandableerrorcontinue |
| 19614 |
#1! xint error: ##1% |
| 19615 |
|
| 19616 |
}}\expandafter\XINT_expandableerror\csname |
| 19617 |
xint<...> is done, but will resume: hit <return> at \space |
| 19618 |
the ? prompt to try fixing the error encountered before expansion\endcsname |
| 19619 |
\fi |
| 19620 |
\def\XINT_expandableerrorcontinue#1% |
| 19621 |
|
| 19622 |
{#1}% |
| 19623 |
% \end{macrocode} |
| 19624 |
% \subsection{\csh{xint_noxpd} (for \texttt{contex-mkxl} compatibility)} |
| 19625 |
% \added{1.4n} |
| 19626 |
% |
| 19627 |
% The \LaTeX3 code (in |l3names.dtx|) uses Con\TeX t's \cs{normalunexpanded} |
| 19628 |
% and \cs{normalexpanded} which appear to be available both in Mark~II and |
| 19629 |
% Mark~IV. But I will not do any testing with earlier |context|, so here I |
| 19630 |
% shall assume the \cs{expanded} behaves as expected and I can use |
| 19631 |
% \cs{notexpanded} for \cs{unexpanded}. This is abstracted into an alias |
| 19632 |
% \csbxint{_noxpd}. |
| 19633 |
% |
| 19634 |
% I don't know if there is mode of running |context| where the \cs{errhelp} |
| 19635 |
% tokens will be shown (trying |context --mkII| was not conclusive; by the way |
| 19636 |
% \cs{errmessage} in e-\TeX{} adds a full stop which is missing with |
| 19637 |
% |context|). |
| 19638 |
% |
| 19639 |
% About the \cs{let} primitive I am not sure it behaves fully as in other |
| 19640 |
% engines. |
| 19641 |
% |
| 19642 |
% Note that this uses \csbxint{Message} in case of old Con\TeX t so we had |
| 19643 |
% to have it defined first. |
| 19644 |
% \begin{macrocode} |
| 19645 |
\let\xint_noxpd\unexpanded |
| 19646 |
\ifdefined\contextversion |
| 19647 |
\let\xint_noxpd\notexpanded |
| 19648 |
\ifdefined\notexpanded |
| 19649 |
\else |
| 19650 |
\xintMessage{xintkernel}{Error}{This ConTeXt appears to be too old.} |
| 19651 |
\errhelp{xint only supports the ConTeXt-LMTX as of 2025/09/05.}% |
| 19652 |
\errmessage{The \noexpand\notexpanded primitive does not exist.}% |
| 19653 |
\fi |
| 19654 |
\fi |
| 19655 |
% \end{macrocode} |
| 19656 |
% \subsection{\csh{xintstrcmp}} |
| 19657 |
% \added[2022/06/05]{1.4m} |
| 19658 |
% For the \LuaTeX{} engine the code is copied over from |l3names.dtx|. I also |
| 19659 |
% looked at Heiko Oberdiek's |pdftexcmds.sty| and |pdftexcmds.lua|, but I |
| 19660 |
% removed |\luaescapestring| and used |token.scan_string()| as seen in |
| 19661 |
% |l3names.dtx| (and I did try to inform myself about this in the \LuaTeX{} |
| 19662 |
% manual, with limited success). I am not sure about the syntax below with the |
| 19663 |
% |local|'s. Should I use |\directlua0|? Testing was minimal. |
| 19664 |
% Memo: even with |pdftex|'s \cs{pdfstrcmp}, braces around the arguments |
| 19665 |
% are mandatory. |
| 19666 |
% \begin{macrocode} |
| 19667 |
\ifdefined\strcmp\let\xintstrcmp\strcmp |
| 19668 |
\else\ifdefined\pdfstrcmp\let\xintstrcmp\pdfstrcmp |
| 19669 |
\else\ifdefined\directlua\directlua{% |
| 19670 |
xintkernel = xintkernel or {} |
| 19671 |
local minus_tok = token.new(string.byte'-', 12) |
| 19672 |
local zero_tok = token.new(string.byte'0', 12) |
| 19673 |
local one_tok = token.new(string.byte'1', 12) |
| 19674 |
function xintkernel.strcmp() |
| 19675 |
local A = token.scan_string() |
| 19676 |
local B = token.scan_string() |
| 19677 |
if A < B then |
| 19678 |
tex.write(minus_tok, one_tok) |
| 19679 |
else |
| 19680 |
tex.write(A == B and zero_tok or one_tok) |
| 19681 |
end |
| 19682 |
end |
| 19683 |
}\def\xintstrcmp{% |
| 19684 |
\directlua{xintkernel.strcmp()}% |
| 19685 |
}% |
| 19686 |
\else |
| 19687 |
\xintMessage{xintkernel}{Error}{Could not set-up \string\xintstrcmp.}% |
| 19688 |
\errhelp{What kind of format are you using? Perhaps write the author? Bye now}% |
| 19689 |
\errmessage{Sorry, could not find or define string comparison primitive}\fi\fi\fi |
| 19690 |
% \end{macrocode} |
| 19691 |
% \subsection{\csh{xintresettimer}, \csh{xintelapsedtime}, \csh{xinttheseconds}} |
| 19692 |
% \added{1.4n} |
| 19693 |
% If |\resettimer| is defined, the code assumes |
| 19694 |
% |\elapsedtime| is, too. |
| 19695 |
% |
| 19696 |
% I completely forgot at release time to document these engine-agnostic |
| 19697 |
% utilities in the manual. They were originally in the |xint.dtx| preamble, |
| 19698 |
% to allow building the documentation also with the Unicode engines. They are |
| 19699 |
% used only once there, for the example with |\xintUniformDeviate|. Also in |
| 19700 |
% the preamble is the needed aliasing of |\pdfsetrandomseed| into |
| 19701 |
% |\setrandomseed| for the Unicode engines, but I completely forgot to |
| 19702 |
% transfer this too here and provide |\xintsetrandomseed|, which actually was |
| 19703 |
% more important because the package provides already utilities related with |
| 19704 |
% randomness. |
| 19705 |
% |
| 19706 |
% Perhaps I should for Lua\TeX{} copy the l3kernel code (here the code was |
| 19707 |
% picked from some |tex.sx| answer and was in my files for years) but I am not |
| 19708 |
% Lua-proficient enough to do this confidently... probably their |// 1| and |
| 19709 |
% |math.tointeger()| is more efficient than the |math.floor()| and there must |
| 19710 |
% be a reason why they use |gettimeofday()|, while |os.clock()| is only used |
| 19711 |
% to set the ``epoch''. |
| 19712 |
% |
| 19713 |
% I have been using for years the underlying syntax trick here for |
| 19714 |
% |\xinttheseconds|, and I usually never bother actually removing the catcode |
| 19715 |
% 12 |pt|, but well let's do it here. |
| 19716 |
% |
| 19717 |
% I hesitate whether with Lua\TeX{} I should avoid the scaled seconds |
| 19718 |
% intermediate in favor of the raw |os.clock()-basetime| data but I would have |
| 19719 |
% to waste time seeing what happens with |tex.write()| then. And it would not |
| 19720 |
% help really in comparing with PDF\TeX{} or Xe\TeX{}. |
| 19721 |
% |
| 19722 |
% \changed{1.4o} |
| 19723 |
% |
| 19724 |
% |xinttimer| replaces in the Lua code |xintelapsedtimer|, which was silly |
| 19725 |
% name used when I adopted in a haste at |1.4n| while improving the user |
| 19726 |
% manual on \csbxint{UniformDeviate}. |
| 19727 |
% \begin{macrocode} |
| 19728 |
\ifdefined\resettimer |
| 19729 |
\let\xintresettimer\resettimer \let\xintelapsedtime\elapsedtime |
| 19730 |
\else |
| 19731 |
\ifdefined\pdfresettimer |
| 19732 |
\let\xintresettimer\pdfresettimer\let\xintelapsedtime\pdfelapsedtime |
| 19733 |
\else |
| 19734 |
\ifdefined\directlua |
| 19735 |
\directlua{xinttimer_basetime=0}% |
| 19736 |
\def\xintresettimer{\directlua{xinttimer_basetime = os.clock()}}% |
| 19737 |
\def\xintelapsedtime{\numexpr |
| 19738 |
\directlua{tex.print(math.floor((os.clock()-xinttimer_basetime)*65536+0.5))}% |
| 19739 |
\relax}% |
| 19740 |
\fi\fi\fi |
| 19741 |
\def\xintstrippt{\expandafter\XINT_strippt\the}% |
| 19742 |
\expanded{\xint_noxpd{\def\XINT_strippt#1}\detokenize{pt}}{#1}% |
| 19743 |
\def\xinttheseconds{\xintstrippt\dimexpr\xintelapsedtime sp\relax}% |
| 19744 |
% \end{macrocode} |
| 19745 |
% \subsection{\csh{xintReverseOrder}} |
| 19746 |
% \changed{1.0} Does not expand its argument. The whole of xint codebase now |
| 19747 |
% contains only two calls to |\XINT_rord_main| (in \xintgcdnameimp). |
| 19748 |
% |
| 19749 |
% Attention: removes brace pairs (and swallows spaces). |
| 19750 |
% |
| 19751 |
% For digit tokens a faster reverse macro is provided by (|1.2|) |
| 19752 |
% \csbxint{ReverseDigits} in \xintnameimp. |
| 19753 |
% |
| 19754 |
% For comma separated items, |1.2g| has \csbxint{CSVReverse} in |
| 19755 |
% \xinttoolsnameimp. |
| 19756 |
% \begin{macrocode} |
| 19757 |
\def\xintReverseOrder {\romannumeral0\xintreverseorder }% |
| 19758 |
\long\def\xintreverseorder #1% |
| 19759 |
{% |
| 19760 |
\XINT_rord_main {}#1% |
| 19761 |
\xint: |
| 19762 |
\xint_bye\xint_bye\xint_bye\xint_bye |
| 19763 |
\xint_bye\xint_bye\xint_bye\xint_bye |
| 19764 |
\xint: |
| 19765 |
}% |
| 19766 |
\long\def\XINT_rord_main #1#2#3#4#5#6#7#8#9% |
| 19767 |
{% |
| 19768 |
\xint_bye #9\XINT_rord_cleanup\xint_bye |
| 19769 |
\XINT_rord_main {#9#8#7#6#5#4#3#2#1}% |
| 19770 |
}% |
| 19771 |
\def\XINT_rord_cleanup #1{% |
| 19772 |
\long\def\XINT_rord_cleanup\xint_bye\XINT_rord_main ##1##2\xint: |
| 19773 |
{% |
| 19774 |
\expandafter#1\xint_gob_til_xint: ##1% |
| 19775 |
}}\XINT_rord_cleanup { }% |
| 19776 |
% \end{macrocode} |
| 19777 |
% \subsection{\csh{xintLength}} |
| 19778 |
% \changed{1.0} Does not expand its argument. See \csbxint{NthElt}|{0}| from |
| 19779 |
% \xinttoolsnameimp which f-expands its argument. |
| 19780 |
% |
| 19781 |
% \changed{1.2g} Added \csbxint{CSVLength} to \xinttoolsnameimp. |
| 19782 |
% |
| 19783 |
% \changed{1.2i} Rewrote this venerable macro. New code about 40\% |
| 19784 |
% faster across all lengths. Syntax with |\romannumeral0| adds some |
| 19785 |
% slight (negligible) overhead; it is done to fit some general |
| 19786 |
% principles of structure of the xint package macros but maybe |
| 19787 |
% at some point I should drop it. And in fact it is often called |
| 19788 |
% directly via the |\numexpr| access point. (bad coding...) |
| 19789 |
% |
| 19790 |
% Remark: the argument may contain \cs{par} tokens. But generally |
| 19791 |
% speaking most other macros of the \xintnameimp bundle are not declared |
| 19792 |
% \cs{long}. As \csbxint{Length} produces a numeric quantity it is |
| 19793 |
% conceivable that it could serve in the input of some of the |
| 19794 |
% \xintnameimp macros. For example something such as |
| 19795 |
% |\xinteval{\xintLength{\par\par}^3}| or |
| 19796 |
% |\xintiiMul{\xintLength{\par\par\par}}{17}|. They both fail. I have |
| 19797 |
% known this issue for many years. It is only needed to make long those |
| 19798 |
% macros which grab the argument and \fexpan d it. After expansion, of |
| 19799 |
% course no \cs{par} tokens is admissible as numerical input. Still |
| 19800 |
% this is quite some work due to size of the codebase. Waiting for a |
| 19801 |
% real-life bug report... (\LaTeX3 people have fixed that on their side |
| 19802 |
% by making all declarations \cs{long} per default, and this may also |
| 19803 |
% perhaps increase slightly the efficiency, not checked). |
| 19804 |
% \begin{macrocode} |
| 19805 |
\def\xintLength {\romannumeral0\xintlength }% |
| 19806 |
\def\xintlength #1{% |
| 19807 |
\long\def\xintlength ##1% |
| 19808 |
{% |
| 19809 |
\expandafter#1\the\numexpr\XINT_length_loop |
| 19810 |
##1\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint: |
| 19811 |
\xint_c_viii\xint_c_vii\xint_c_vi\xint_c_v |
| 19812 |
\xint_c_iv\xint_c_iii\xint_c_ii\xint_c_i\xint_c_\xint_bye |
| 19813 |
\relax |
| 19814 |
}}\xintlength{ }% |
| 19815 |
\long\def\XINT_length_loop #1#2#3#4#5#6#7#8#9% |
| 19816 |
{% |
| 19817 |
\xint_gob_til_xint: #9\XINT_length_finish_a\xint: |
| 19818 |
\xint_c_ix+\XINT_length_loop |
| 19819 |
}% |
| 19820 |
\def\XINT_length_finish_a\xint:\xint_c_ix+\XINT_length_loop |
| 19821 |
#1#2#3#4#5#6#7#8#9% |
| 19822 |
{% |
| 19823 |
#9\xint_bye |
| 19824 |
}% |
| 19825 |
% \end{macrocode} |
| 19826 |
% \subsection{\csh{xintLastItem}} |
| 19827 |
% \changed[2016/12/10]{1.2i} |
| 19828 |
% One level |
| 19829 |
% of braces removed in output. Output empty if input empty. Attention! |
| 19830 |
% This means |
| 19831 |
% that an empty input or an input ending with a {} empty brace pair |
| 19832 |
% both give same output. |
| 19833 |
% |
| 19834 |
% The |\xint:| token must not be among items. |\xintFirstItem| added |
| 19835 |
% at 1.4 for usage in xintexpr. It must contain neither |\xint:| |
| 19836 |
% nor |\xint_bye| in its first item. |
| 19837 |
% |
| 19838 |
% \begin{macrocode} |
| 19839 |
\def\xintLastItem {\romannumeral0\xintlastitem }% |
| 19840 |
\long\def\xintlastitem #1% |
| 19841 |
{% |
| 19842 |
\XINT_last_loop {}.#1% |
| 19843 |
{\xint:\XINT_last_loop_enda}{\xint:\XINT_last_loop_endb}% |
| 19844 |
{\xint:\XINT_last_loop_endc}{\xint:\XINT_last_loop_endd}% |
| 19845 |
{\xint:\XINT_last_loop_ende}{\xint:\XINT_last_loop_endf}% |
| 19846 |
{\xint:\XINT_last_loop_endg}{\xint:\XINT_last_loop_endh}\xint_bye |
| 19847 |
}% |
| 19848 |
\long\def\XINT_last_loop #1.#2#3#4#5#6#7#8#9% |
| 19849 |
{% |
| 19850 |
\xint_gob_til_xint: #9% |
| 19851 |
{#8}{#7}{#6}{#5}{#4}{#3}{#2}{#1}\xint: |
| 19852 |
\XINT_last_loop {#9}.% |
| 19853 |
}% |
| 19854 |
\long\def\XINT_last_loop_enda #1#2\xint_bye{ #1}% |
| 19855 |
\long\def\XINT_last_loop_endb #1#2#3\xint_bye{ #2}% |
| 19856 |
\long\def\XINT_last_loop_endc #1#2#3#4\xint_bye{ #3}% |
| 19857 |
\long\def\XINT_last_loop_endd #1#2#3#4#5\xint_bye{ #4}% |
| 19858 |
\long\def\XINT_last_loop_ende #1#2#3#4#5#6\xint_bye{ #5}% |
| 19859 |
\long\def\XINT_last_loop_endf #1#2#3#4#5#6#7\xint_bye{ #6}% |
| 19860 |
\long\def\XINT_last_loop_endg #1#2#3#4#5#6#7#8\xint_bye{ #7}% |
| 19861 |
\long\def\XINT_last_loop_endh #1#2#3#4#5#6#7#8#9\xint_bye{ #8}% |
| 19862 |
% \end{macrocode} |
| 19863 |
% \subsection{\csh{xintFirstItem}} |
| 19864 |
%\begin{lverb} |
| 19865 |
% 1.4. There must be neither \xint: |
| 19866 |
% nor \xint_bye in its first item. |
| 19867 |
%\end{lverb} |
| 19868 |
% \begin{macrocode} |
| 19869 |
\def\xintFirstItem {\romannumeral0\xintfirstitem }% |
| 19870 |
\long\def\xintfirstitem #1{\XINT_firstitem #1{\xint:\XINT_firstitem_end}\xint_bye}% |
| 19871 |
\long\def\XINT_firstitem #1#2\xint_bye{\xint_gob_til_xint: #1\xint:\space #1}% |
| 19872 |
\def\XINT_firstitem_end\xint:{ }% |
| 19873 |
% \end{macrocode} |
| 19874 |
% \subsection{\csh{xintLastOne}} |
| 19875 |
%\begin{lverb} |
| 19876 |
% |
| 19877 |
% As xintexpr 1.4 uses {c1}{c2}....{cN} storage when gathering comma separated |
| 19878 |
% values we need to not handle identically an empty list and a list with an |
| 19879 |
% empty item (as the above allows hierarchical structures). But \xintLastItem |
| 19880 |
% removed one level of brace pair so it is anadequate for the last() function. |
| 19881 |
% |
| 19882 |
% By the way it is logical to interpret «item» as meaning {cj} inclusive of |
| 19883 |
% the braces; but legacy xint user manual was not written in this spirit. And thus |
| 19884 |
% \xintLastItem did brace stripping, thus we need another name for maintaining |
| 19885 |
% backwards compatibility (although the cardinality of users is small). |
| 19886 |
% |
| 19887 |
% The \xint: token must not be found (visible) among the item contents. |
| 19888 |
% |
| 19889 |
%\end{lverb} |
| 19890 |
% \begin{macrocode} |
| 19891 |
\def\xintLastOne {\romannumeral0\xintlastone }% |
| 19892 |
\long\def\xintlastone #1% |
| 19893 |
{% |
| 19894 |
\XINT_lastone_loop {}.#1% |
| 19895 |
{\xint:\XINT_lastone_loop_enda}{\xint:\XINT_lastone_loop_endb}% |
| 19896 |
{\xint:\XINT_lastone_loop_endc}{\xint:\XINT_lastone_loop_endd}% |
| 19897 |
{\xint:\XINT_lastone_loop_ende}{\xint:\XINT_lastone_loop_endf}% |
| 19898 |
{\xint:\XINT_lastone_loop_endg}{\xint:\XINT_lastone_loop_endh}\xint_bye |
| 19899 |
}% |
| 19900 |
\long\def\XINT_lastone_loop #1.#2#3#4#5#6#7#8#9% |
| 19901 |
{% |
| 19902 |
\xint_gob_til_xint: #9% |
| 19903 |
{#8}{#7}{#6}{#5}{#4}{#3}{#2}{#1}\xint: |
| 19904 |
\XINT_lastone_loop {{#9}}.% |
| 19905 |
}% |
| 19906 |
\long\def\XINT_lastone_loop_enda #1#2\xint_bye{{#1}}% |
| 19907 |
\long\def\XINT_lastone_loop_endb #1#2#3\xint_bye{{#2}}% |
| 19908 |
\long\def\XINT_lastone_loop_endc #1#2#3#4\xint_bye{{#3}}% |
| 19909 |
\long\def\XINT_lastone_loop_endd #1#2#3#4#5\xint_bye{{#4}}% |
| 19910 |
\long\def\XINT_lastone_loop_ende #1#2#3#4#5#6\xint_bye{{#5}}% |
| 19911 |
\long\def\XINT_lastone_loop_endf #1#2#3#4#5#6#7\xint_bye{{#6}}% |
| 19912 |
\long\def\XINT_lastone_loop_endg #1#2#3#4#5#6#7#8\xint_bye{{#7}}% |
| 19913 |
\long\def\XINT_lastone_loop_endh #1#2#3#4#5#6#7#8#9\xint_bye{ #8}% |
| 19914 |
% \end{macrocode} |
| 19915 |
% \subsection{\csh{xintFirstOne}} |
| 19916 |
%\begin{lverb} |
| 19917 |
% For xintexpr 1.4 too. Jan 3, 2020. |
| 19918 |
% |
| 19919 |
% This is an experimental macro, don't use it. If input is nil (empty set) it |
| 19920 |
% expands to nil, if not it fetches first item and braces it. Fetching will |
| 19921 |
% have stripped one brace pair if item was braced to start with, which is |
| 19922 |
% the case in non-symbolic xintexpr data objects. |
| 19923 |
% |
| 19924 |
% I have not given much thought to this (make it shorter, allow all tokens, |
| 19925 |
% (we could first test if empty via combination with \detokenize), etc...) |
| 19926 |
% as I need to get xint 1.4 out soon. So in particular attention that |
| 19927 |
% the macro assumes the \xint: token is absent from first item of input. |
| 19928 |
%\end{lverb} |
| 19929 |
% \begin{macrocode} |
| 19930 |
\def\xintFirstOne {\romannumeral0\xintfirstone }% |
| 19931 |
\long\def\xintfirstone #1{\XINT_firstone #1{\xint:\XINT_firstone_empty}\xint:}% |
| 19932 |
\long\def\XINT_firstone #1#2\xint:{\xint_gob_til_xint: #1\xint:{#1}}% |
| 19933 |
\def\XINT_firstone_empty\xint:#1{ }% |
| 19934 |
% \end{macrocode} |
| 19935 |
% \subsection{\csh{xintLengthUpTo}} |
| 19936 |
% \changed{1.2i} For use by \csbxint{Keep} and \csbxint{Trim} |
| 19937 |
% (\xinttoolsnameimp). The argument N **must be non-negative**. |
| 19938 |
% |
| 19939 |
% |\xintLengthUpTo{N}{List}| produces |-0| if length(List)>N, else it returns |
| 19940 |
% N-length(List). Hence subtracting it from N always computes min(N,length(List)). |
| 19941 |
% \changed{1.2j} Changed ending and interface to core loop. |
| 19942 |
% \begin{macrocode} |
| 19943 |
\def\xintLengthUpTo {\romannumeral0\xintlengthupto}% |
| 19944 |
\long\def\xintlengthupto #1#2% |
| 19945 |
{% |
| 19946 |
\expandafter\XINT_lengthupto_loop |
| 19947 |
\the\numexpr#1.#2\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint: |
| 19948 |
\xint_c_vii\xint_c_vi\xint_c_v\xint_c_iv |
| 19949 |
\xint_c_iii\xint_c_ii\xint_c_i\xint_c_\xint_bye.% |
| 19950 |
}% |
| 19951 |
\def\XINT_lengthupto_loop_a #1% |
| 19952 |
{% |
| 19953 |
\xint_UDsignfork |
| 19954 |
#1\XINT_lengthupto_gt |
| 19955 |
-\XINT_lengthupto_loop |
| 19956 |
\krof #1% |
| 19957 |
}% |
| 19958 |
\long\def\XINT_lengthupto_gt #1\xint_bye.{-0}% |
| 19959 |
\long\def\XINT_lengthupto_loop #1.#2#3#4#5#6#7#8#9% |
| 19960 |
{% |
| 19961 |
\xint_gob_til_xint: #9\XINT_lengthupto_finish_a\xint:% |
| 19962 |
\expandafter\XINT_lengthupto_loop_a\the\numexpr #1-\xint_c_viii.% |
| 19963 |
}% |
| 19964 |
\def\XINT_lengthupto_finish_a\xint:\expandafter\XINT_lengthupto_loop_a |
| 19965 |
\the\numexpr #1-\xint_c_viii.#2#3#4#5#6#7#8#9% |
| 19966 |
{% |
| 19967 |
\expandafter\XINT_lengthupto_finish_b\the\numexpr #1-#9\xint_bye |
| 19968 |
}% |
| 19969 |
\def\XINT_lengthupto_finish_b #1#2.% |
| 19970 |
{% |
| 19971 |
\xint_UDsignfork |
| 19972 |
#1{-0}% |
| 19973 |
-{ #1#2}% |
| 19974 |
\krof |
| 19975 |
}% |
| 19976 |
% \end{macrocode} |
| 19977 |
% \subsection{\csh{xintreplicate}, \csh{xintReplicate}} |
| 19978 |
% \changed{1.2i} |
| 19979 |
% This is cloned from LaTeX3's |\prg_replicate:nn|, see Joseph's post |
| 19980 |
% at |
| 19981 |
% \centeredline{http://tex.stackexchange.com/questions/16189/repeat-command-n-times} |
| 19982 |
% I |
| 19983 |
% posted there an alternative not using the chained |\csname|'s but it is a bit |
| 19984 |
% less efficient (except perhaps for thousands of repetitions). |
| 19985 |
% The code in Joseph's post does |abs(#1)| replications when input |#1| is negative |
| 19986 |
% and then activates an error triggering macro; here we simply do nothing when |
| 19987 |
% |#1| is negative. |
| 19988 |
% \centeredline{Usage: |\romannumeral\xintreplicate{N}{stuff}|} |
| 19989 |
% |
| 19990 |
% When |N| is already explicit digits (even |N=0|, but non-negative) one can |
| 19991 |
% call the macro as |
| 19992 |
% \centeredline{|\romannumeral\XINT_rep N\endcsname {foo}|} |
| 19993 |
% to skip the |\numexpr|. |
| 19994 |
% |
| 19995 |
% \changed[2020/01/11]{1.4} |
| 19996 |
% Added |\xintReplicate| ! The reason I did not before is that the prevailing |
| 19997 |
% habits in xint source code was to trigger with |\romannumeral0| not |
| 19998 |
% |\romannumeral| which is the lowercased named macros. Thus adding the |
| 19999 |
% camelcase one creates a couple |\xintReplicate/\xintreplicate| not obeying |
| 20000 |
% the general mold. |
| 20001 |
% \begin{macrocode} |
| 20002 |
\def\xintReplicate{\romannumeral\xintreplicate}% |
| 20003 |
\def\xintreplicate#1% |
| 20004 |
{\expandafter\XINT_replicate\the\numexpr#1\endcsname}% |
| 20005 |
\def\XINT_replicate #1{\xint_UDsignfork |
| 20006 |
#1\XINT_rep_neg |
| 20007 |
-\XINT_rep |
| 20008 |
\krof #1}% |
| 20009 |
\long\def\XINT_rep_neg #1\endcsname #2{\xint_c_}% |
| 20010 |
\def\XINT_rep #1{\csname XINT_rep_f#1\XINT_rep_a}% |
| 20011 |
\def\XINT_rep_a #1{\csname XINT_rep_#1\XINT_rep_a}% |
| 20012 |
\def\XINT_rep_\XINT_rep_a{\endcsname}% |
| 20013 |
\long\expandafter\def\csname XINT_rep_0\endcsname #1% |
| 20014 |
{\endcsname{#1#1#1#1#1#1#1#1#1#1}}% |
| 20015 |
\long\expandafter\def\csname XINT_rep_1\endcsname #1% |
| 20016 |
{\endcsname{#1#1#1#1#1#1#1#1#1#1}#1}% |
| 20017 |
\long\expandafter\def\csname XINT_rep_2\endcsname #1% |
| 20018 |
{\endcsname{#1#1#1#1#1#1#1#1#1#1}#1#1}% |
| 20019 |
\long\expandafter\def\csname XINT_rep_3\endcsname #1% |
| 20020 |
{\endcsname{#1#1#1#1#1#1#1#1#1#1}#1#1#1}% |
| 20021 |
\long\expandafter\def\csname XINT_rep_4\endcsname #1% |
| 20022 |
{\endcsname{#1#1#1#1#1#1#1#1#1#1}#1#1#1#1}% |
| 20023 |
\long\expandafter\def\csname XINT_rep_5\endcsname #1% |
| 20024 |
{\endcsname{#1#1#1#1#1#1#1#1#1#1}#1#1#1#1#1}% |
| 20025 |
\long\expandafter\def\csname XINT_rep_6\endcsname #1% |
| 20026 |
{\endcsname{#1#1#1#1#1#1#1#1#1#1}#1#1#1#1#1#1}% |
| 20027 |
\long\expandafter\def\csname XINT_rep_7\endcsname #1% |
| 20028 |
{\endcsname{#1#1#1#1#1#1#1#1#1#1}#1#1#1#1#1#1#1}% |
| 20029 |
\long\expandafter\def\csname XINT_rep_8\endcsname #1% |
| 20030 |
{\endcsname{#1#1#1#1#1#1#1#1#1#1}#1#1#1#1#1#1#1#1}% |
| 20031 |
\long\expandafter\def\csname XINT_rep_9\endcsname #1% |
| 20032 |
{\endcsname{#1#1#1#1#1#1#1#1#1#1}#1#1#1#1#1#1#1#1#1}% |
| 20033 |
\long\expandafter\def\csname XINT_rep_f0\endcsname #1% |
| 20034 |
{\xint_c_}% |
| 20035 |
\long\expandafter\def\csname XINT_rep_f1\endcsname #1% |
| 20036 |
{\xint_c_ #1}% |
| 20037 |
\long\expandafter\def\csname XINT_rep_f2\endcsname #1% |
| 20038 |
{\xint_c_ #1#1}% |
| 20039 |
\long\expandafter\def\csname XINT_rep_f3\endcsname #1% |
| 20040 |
{\xint_c_ #1#1#1}% |
| 20041 |
\long\expandafter\def\csname XINT_rep_f4\endcsname #1% |
| 20042 |
{\xint_c_ #1#1#1#1}% |
| 20043 |
\long\expandafter\def\csname XINT_rep_f5\endcsname #1% |
| 20044 |
{\xint_c_ #1#1#1#1#1}% |
| 20045 |
\long\expandafter\def\csname XINT_rep_f6\endcsname #1% |
| 20046 |
{\xint_c_ #1#1#1#1#1#1}% |
| 20047 |
\long\expandafter\def\csname XINT_rep_f7\endcsname #1% |
| 20048 |
{\xint_c_ #1#1#1#1#1#1#1}% |
| 20049 |
\long\expandafter\def\csname XINT_rep_f8\endcsname #1% |
| 20050 |
{\xint_c_ #1#1#1#1#1#1#1#1}% |
| 20051 |
\long\expandafter\def\csname XINT_rep_f9\endcsname #1% |
| 20052 |
{\xint_c_ #1#1#1#1#1#1#1#1#1}% |
| 20053 |
% \end{macrocode} |
| 20054 |
% \subsection{\csh{xintgobble}, \csh{xintGobble}} |
| 20055 |
% \changed{1.2i} |
| 20056 |
% I hesitated about allowing as many as |9^6-1=531440| tokens to gobble, but |
| 20057 |
% |9^5-1=59058| is too low for playing with long decimal expansions. |
| 20058 |
% \centeredline{Usage: |\romannumeral\xintgobble{N}...|} |
| 20059 |
% |
| 20060 |
% \changed[2020/01/11]{1.4} |
| 20061 |
% Added |\xintGobble|. |
| 20062 |
% \begin{macrocode} |
| 20063 |
\def\xintGobble{\romannumeral\xintgobble}% |
| 20064 |
\def\xintgobble #1% |
| 20065 |
{\csname xint_c_\expandafter\XINT_gobble_a\the\numexpr#1.0}% |
| 20066 |
\def\XINT_gobble #1.{\csname xint_c_\XINT_gobble_a #1.0}% |
| 20067 |
\def\XINT_gobble_a #1{\xint_gob_til_zero#1\XINT_gobble_d0\XINT_gobble_b#1}% |
| 20068 |
\def\XINT_gobble_b #1.#2% |
| 20069 |
{\expandafter\XINT_gobble_c |
| 20070 |
\the\numexpr (#1+\xint_c_v)/\xint_c_ix-\xint_c_i\expandafter.% |
| 20071 |
\the\numexpr #2+\xint_c_i.#1.}% |
| 20072 |
\def\XINT_gobble_c #1.#2.#3.% |
| 20073 |
{\csname XINT_g#2\the\numexpr#3-\xint_c_ix*#1\relax\XINT_gobble_a #1.#2}% |
| 20074 |
\def\XINT_gobble_d0\XINT_gobble_b0.#1{\endcsname}% |
| 20075 |
\expandafter\let\csname XINT_g10\endcsname\endcsname |
| 20076 |
\long\expandafter\def\csname XINT_g11\endcsname#1{\endcsname}% |
| 20077 |
\long\expandafter\def\csname XINT_g12\endcsname#1#2{\endcsname}% |
| 20078 |
\long\expandafter\def\csname XINT_g13\endcsname#1#2#3{\endcsname}% |
| 20079 |
\long\expandafter\def\csname XINT_g14\endcsname#1#2#3#4{\endcsname}% |
| 20080 |
\long\expandafter\def\csname XINT_g15\endcsname#1#2#3#4#5{\endcsname}% |
| 20081 |
\long\expandafter\def\csname XINT_g16\endcsname#1#2#3#4#5#6{\endcsname}% |
| 20082 |
\long\expandafter\def\csname XINT_g17\endcsname#1#2#3#4#5#6#7{\endcsname}% |
| 20083 |
\long\expandafter\def\csname XINT_g18\endcsname#1#2#3#4#5#6#7#8{\endcsname}% |
| 20084 |
\expandafter\let\csname XINT_g20\endcsname\endcsname |
| 20085 |
\long\expandafter\def\csname XINT_g21\endcsname #1#2#3#4#5#6#7#8#9% |
| 20086 |
{\endcsname}% |
| 20087 |
\long\expandafter\edef\csname XINT_g22\endcsname #1#2#3#4#5#6#7#8#9% |
| 20088 |
{\expandafter\noexpand\csname XINT_g21\endcsname}% |
| 20089 |
\long\expandafter\edef\csname XINT_g23\endcsname #1#2#3#4#5#6#7#8#9% |
| 20090 |
{\expandafter\noexpand\csname XINT_g22\endcsname}% |
| 20091 |
\long\expandafter\edef\csname XINT_g24\endcsname #1#2#3#4#5#6#7#8#9% |
| 20092 |
{\expandafter\noexpand\csname XINT_g23\endcsname}% |
| 20093 |
\long\expandafter\edef\csname XINT_g25\endcsname #1#2#3#4#5#6#7#8#9% |
| 20094 |
{\expandafter\noexpand\csname XINT_g24\endcsname}% |
| 20095 |
\long\expandafter\edef\csname XINT_g26\endcsname #1#2#3#4#5#6#7#8#9% |
| 20096 |
{\expandafter\noexpand\csname XINT_g25\endcsname}% |
| 20097 |
\long\expandafter\edef\csname XINT_g27\endcsname #1#2#3#4#5#6#7#8#9% |
| 20098 |
{\expandafter\noexpand\csname XINT_g26\endcsname}% |
| 20099 |
\long\expandafter\edef\csname XINT_g28\endcsname #1#2#3#4#5#6#7#8#9% |
| 20100 |
{\expandafter\noexpand\csname XINT_g27\endcsname}% |
| 20101 |
\expandafter\let\csname XINT_g30\endcsname\endcsname |
| 20102 |
\long\expandafter\edef\csname XINT_g31\endcsname #1#2#3#4#5#6#7#8#9% |
| 20103 |
{\expandafter\noexpand\csname XINT_g28\endcsname}% |
| 20104 |
\long\expandafter\edef\csname XINT_g32\endcsname #1#2#3#4#5#6#7#8#9% |
| 20105 |
{\noexpand\csname XINT_g31\expandafter\noexpand\csname XINT_g28\endcsname}% |
| 20106 |
\long\expandafter\edef\csname XINT_g33\endcsname #1#2#3#4#5#6#7#8#9% |
| 20107 |
{\noexpand\csname XINT_g32\expandafter\noexpand\csname XINT_g28\endcsname}% |
| 20108 |
\long\expandafter\edef\csname XINT_g34\endcsname #1#2#3#4#5#6#7#8#9% |
| 20109 |
{\noexpand\csname XINT_g33\expandafter\noexpand\csname XINT_g28\endcsname}% |
| 20110 |
\long\expandafter\edef\csname XINT_g35\endcsname #1#2#3#4#5#6#7#8#9% |
| 20111 |
{\noexpand\csname XINT_g34\expandafter\noexpand\csname XINT_g28\endcsname}% |
| 20112 |
\long\expandafter\edef\csname XINT_g36\endcsname #1#2#3#4#5#6#7#8#9% |
| 20113 |
{\noexpand\csname XINT_g35\expandafter\noexpand\csname XINT_g28\endcsname}% |
| 20114 |
\long\expandafter\edef\csname XINT_g37\endcsname #1#2#3#4#5#6#7#8#9% |
| 20115 |
{\noexpand\csname XINT_g36\expandafter\noexpand\csname XINT_g28\endcsname}% |
| 20116 |
\long\expandafter\edef\csname XINT_g38\endcsname #1#2#3#4#5#6#7#8#9% |
| 20117 |
{\noexpand\csname XINT_g37\expandafter\noexpand\csname XINT_g28\endcsname}% |
| 20118 |
\expandafter\let\csname XINT_g40\endcsname\endcsname |
| 20119 |
\expandafter\edef\csname XINT_g41\endcsname |
| 20120 |
{\noexpand\csname XINT_g38\expandafter\noexpand\csname XINT_g31\endcsname}% |
| 20121 |
\expandafter\edef\csname XINT_g42\endcsname |
| 20122 |
{\noexpand\csname XINT_g41\expandafter\noexpand\csname XINT_g41\endcsname}% |
| 20123 |
\expandafter\edef\csname XINT_g43\endcsname |
| 20124 |
{\noexpand\csname XINT_g42\expandafter\noexpand\csname XINT_g41\endcsname}% |
| 20125 |
\expandafter\edef\csname XINT_g44\endcsname |
| 20126 |
{\noexpand\csname XINT_g43\expandafter\noexpand\csname XINT_g41\endcsname}% |
| 20127 |
\expandafter\edef\csname XINT_g45\endcsname |
| 20128 |
{\noexpand\csname XINT_g44\expandafter\noexpand\csname XINT_g41\endcsname}% |
| 20129 |
\expandafter\edef\csname XINT_g46\endcsname |
| 20130 |
{\noexpand\csname XINT_g45\expandafter\noexpand\csname XINT_g41\endcsname}% |
| 20131 |
\expandafter\edef\csname XINT_g47\endcsname |
| 20132 |
{\noexpand\csname XINT_g46\expandafter\noexpand\csname XINT_g41\endcsname}% |
| 20133 |
\expandafter\edef\csname XINT_g48\endcsname |
| 20134 |
{\noexpand\csname XINT_g47\expandafter\noexpand\csname XINT_g41\endcsname}% |
| 20135 |
\expandafter\let\csname XINT_g50\endcsname\endcsname |
| 20136 |
\expandafter\edef\csname XINT_g51\endcsname |
| 20137 |
{\noexpand\csname XINT_g48\expandafter\noexpand\csname XINT_g41\endcsname}% |
| 20138 |
\expandafter\edef\csname XINT_g52\endcsname |
| 20139 |
{\noexpand\csname XINT_g51\expandafter\noexpand\csname XINT_g51\endcsname}% |
| 20140 |
\expandafter\edef\csname XINT_g53\endcsname |
| 20141 |
{\noexpand\csname XINT_g52\expandafter\noexpand\csname XINT_g51\endcsname}% |
| 20142 |
\expandafter\edef\csname XINT_g54\endcsname |
| 20143 |
{\noexpand\csname XINT_g53\expandafter\noexpand\csname XINT_g51\endcsname}% |
| 20144 |
\expandafter\edef\csname XINT_g55\endcsname |
| 20145 |
{\noexpand\csname XINT_g54\expandafter\noexpand\csname XINT_g51\endcsname}% |
| 20146 |
\expandafter\edef\csname XINT_g56\endcsname |
| 20147 |
{\noexpand\csname XINT_g55\expandafter\noexpand\csname XINT_g51\endcsname}% |
| 20148 |
\expandafter\edef\csname XINT_g57\endcsname |
| 20149 |
{\noexpand\csname XINT_g56\expandafter\noexpand\csname XINT_g51\endcsname}% |
| 20150 |
\expandafter\edef\csname XINT_g58\endcsname |
| 20151 |
{\noexpand\csname XINT_g57\expandafter\noexpand\csname XINT_g51\endcsname}% |
| 20152 |
\expandafter\let\csname XINT_g60\endcsname\endcsname |
| 20153 |
\expandafter\edef\csname XINT_g61\endcsname |
| 20154 |
{\noexpand\csname XINT_g58\expandafter\noexpand\csname XINT_g51\endcsname}% |
| 20155 |
\expandafter\edef\csname XINT_g62\endcsname |
| 20156 |
{\noexpand\csname XINT_g61\expandafter\noexpand\csname XINT_g61\endcsname}% |
| 20157 |
\expandafter\edef\csname XINT_g63\endcsname |
| 20158 |
{\noexpand\csname XINT_g62\expandafter\noexpand\csname XINT_g61\endcsname}% |
| 20159 |
\expandafter\edef\csname XINT_g64\endcsname |
| 20160 |
{\noexpand\csname XINT_g63\expandafter\noexpand\csname XINT_g61\endcsname}% |
| 20161 |
\expandafter\edef\csname XINT_g65\endcsname |
| 20162 |
{\noexpand\csname XINT_g64\expandafter\noexpand\csname XINT_g61\endcsname}% |
| 20163 |
\expandafter\edef\csname XINT_g66\endcsname |
| 20164 |
{\noexpand\csname XINT_g65\expandafter\noexpand\csname XINT_g61\endcsname}% |
| 20165 |
\expandafter\edef\csname XINT_g67\endcsname |
| 20166 |
{\noexpand\csname XINT_g66\expandafter\noexpand\csname XINT_g61\endcsname}% |
| 20167 |
\expandafter\edef\csname XINT_g68\endcsname |
| 20168 |
{\noexpand\csname XINT_g67\expandafter\noexpand\csname XINT_g61\endcsname}% |
| 20169 |
% \end{macrocode} |
| 20170 |
% \subsection{Random number generation} |
| 20171 |
% \added{1.3b} |
| 20172 |
% |
| 20173 |
% We provide a more random version of the (PDF)\TeX{} \cs{pdfuniformdeviate}. |
| 20174 |
% I discusses the worries with the engine primitive with Bruno Le Floch in |
| 20175 |
% May 2018. Regarding |\pdfuniformdeviate x|: |
| 20176 |
% |
| 20177 |
% \begin{enumerate} |
| 20178 |
% \item with |x=2^{29}| or |x=2^{30}| the engine primitive produces only even |
| 20179 |
% numbers, |
| 20180 |
% \item with |x=3*2^{26}| the integers produced by the RNG when taken modulo |
| 20181 |
% three obey the proportion |1:1:2|, not |1:1:1|, |
| 20182 |
% \item with |x=3*2^{14}| there is analogous although weaker non-uniformity of |
| 20183 |
% the random integers when taken modulo 3, |
| 20184 |
% \item generally speaking pure powers of two should generate uniform random |
| 20185 |
% integers, but when the range is divisible by large powers of |
| 20186 |
% two, the non-uniformity may be amplified in surprising ways by modulo |
| 20187 |
% operations. |
| 20188 |
% \end{enumerate} |
| 20189 |
% |
| 20190 |
% Moreover, two seeds sharing the same low |k| bits generate sequences of |
| 20191 |
% 28-bits integers which are one-to-one identical modulo |2^k|! |
| 20192 |
% |
| 20193 |
% In order to mitigate the issues commented upon in the user manual, |
| 20194 |
% \csbxint{UniformDeviate} currently only uses the |
| 20195 |
% seven high bits from the underlying random stream, using multiple calls to |
| 20196 |
% |\pdfuniformdeviate 128|. From the Birthday Effect, after about |2^{11}| seeds |
| 20197 |
% one will likely pick a new one sharing its 22 low bits with an earlier one. |
| 20198 |
% |
| 20199 |
% \begin{enumerate} |
| 20200 |
% \item but as the final random integer is obtained by additional operations |
| 20201 |
% involving the range |x| (currently a modulo operation), for odd ranges it is |
| 20202 |
% more difficult for bit correlations to be seen, |
| 20203 |
% \item anyway as they are only |
| 20204 |
% |2^{28}| seeds in total, after only |2^{14}| seeds it is likely to encounter |
| 20205 |
% one already explored, and then random integers are identical, however |
| 20206 |
% complicated the RNG's raw output is malaxed, and whatever the target range |
| 20207 |
% |x|. And |2^{14}| is only eight times as large as |2^{11}|. |
| 20208 |
% \end{enumerate} |
| 20209 |
% |
| 20210 |
% It would be nice if the engine provided some user interface for |
| 20211 |
% letting its RNG execute a given number of iterations without the overhead |
| 20212 |
% of replicated executions of |\pdfuniformdeviate|. This could help gain |
| 20213 |
% entropy and would reduce correlations across series from distinct seeds. |
| 20214 |
% |
| 20215 |
% \changed{1.4n} Print a warning immediately if no uniformdeviate is available. |
| 20216 |
% |
| 20217 |
% \subsubsection{\csh{xint_texuniformdeviate}} |
| 20218 |
% \begin{macrocode} |
| 20219 |
\ifdefined\pdfuniformdeviate \let\xint_texuniformdeviate\pdfuniformdeviate\fi |
| 20220 |
\ifdefined\uniformdeviate \let\xint_texuniformdeviate\uniformdeviate \fi |
| 20221 |
\ifx\xint_texuniformdeviate\relax\let\xint_texuniformdeviate\xint_undefined\fi |
| 20222 |
% \end{macrocode} |
| 20223 |
% \subsubsection{\csh{xint_texuniformdeviate_dgts}} |
| 20224 |
% |
| 20225 |
% \added{1.4n} Needed for compatibility with Con\TeX t. |
| 20226 |
% |
| 20227 |
% One finds a macro \cs{randomnumber} |
| 20228 |
% (|/usr/local/texlive/2025/texmf-dist/tex/context/base/mkxl/supp-ran.mkxl|), |
| 20229 |
% which takes two arguments. Fortunately it seems that throughout the |
| 20230 |
% \xintnameimp code base, we use \csbxint{_texuniformdeviate} always with a |
| 20231 |
% chardef or count argument with one sole exception where it is followed with |
| 20232 |
% digits terminated by \cs{xint:}. In order not to change anything to current |
| 20233 |
% code and to support Con\TeX t-LMTX we make here a suitable definition |
| 20234 |
% compatible with these use cases. |
| 20235 |
% |
| 20236 |
% \noindent Warning: I have no idea and will not check now if the RNG has the |
| 20237 |
% same issues for the less significant decimal digits as in PDFTeX, thus I |
| 20238 |
% don't know if the overhead in the definition below of \csbxint{UniformeDeviate} |
| 20239 |
% has any rationale in the LMTX context. |
| 20240 |
% |
| 20241 |
% MEMO: In the code below, I have not checked yet and do not remember (at time |
| 20242 |
% of preparing |1.4n|) if it is possible that the |#1| fetched by |
| 20243 |
% \csbxint{_texuniformdeviate_dgts} has some chance to be zero (as I don't |
| 20244 |
% remember the details of the construction). Attention that |
| 20245 |
% |\randomnumber{0}{-1}| may output |-1|. |
| 20246 |
% |
| 20247 |
% \changed{1.4o} Remove the test whether some uniformdeviate already |
| 20248 |
% exists with Con\TeX t and use unconditionally |\randomnumber| without |
| 20249 |
% checking if it exists. |
| 20250 |
% \begin{macrocode} |
| 20251 |
\ifdefined\contextversion |
| 20252 |
\def\xint_texuniformdeviate#1{\randomnumber{0}{#1-1}}% |
| 20253 |
\def\xint_texuniformdeviate_dgts#1\xint:{\randomnumber{0}{#1-1}\xint:}% |
| 20254 |
\else |
| 20255 |
\let\xint_texuniformdeviate_dgts\xint_texuniformdeviate |
| 20256 |
\fi |
| 20257 |
% \end{macrocode} |
| 20258 |
% \subsubsection{\csh{xintUniformDeviate}} |
| 20259 |
% For negative |#1| the output (as per the doc I wrote in the user manual |
| 20260 |
% some years ago and that I trust) ranges from |#1+1| to zero inclusive. |
| 20261 |
% This is same behaviour as original primitive and the input must be |
| 20262 |
% within the \TeX{} bounds. Note that |\the\numexpr-0\relax| gives |0|. |
| 20263 |
% |
| 20264 |
% We make 5 calls to the primitive and the user doc says that when I tested |
| 20265 |
% the cost was about 13 times the one of the primitive. |
| 20266 |
% \begin{macrocode} |
| 20267 |
\ifdefined\xint_texuniformdeviate |
| 20268 |
\expandafter\xint_firstoftwo |
| 20269 |
\else\expandafter\xint_secondoftwo |
| 20270 |
\fi |
| 20271 |
{% |
| 20272 |
\def\xintUniformDeviate#1% |
| 20273 |
{\the\numexpr\expandafter\XINT_uniformdeviate_sgnfork\the\numexpr#1\xint:}% |
| 20274 |
\def\XINT_uniformdeviate_sgnfork#1% |
| 20275 |
{% |
| 20276 |
\if-#1\XINT_uniformdeviate_neg\fi \XINT_uniformdeviate{}#1% |
| 20277 |
}% |
| 20278 |
\def\XINT_uniformdeviate_neg\fi\XINT_uniformdeviate#1-% |
| 20279 |
{% |
| 20280 |
\fi-\numexpr\XINT_uniformdeviate\relax |
| 20281 |
}% |
| 20282 |
\def\XINT_uniformdeviate#1#2\xint: |
| 20283 |
{%( |
| 20284 |
\expandafter\XINT_uniformdeviate_a\the\numexpr% |
| 20285 |
-\xint_texuniformdeviate\xint_c_ii^vii% |
| 20286 |
-\xint_c_ii^vii*\xint_texuniformdeviate\xint_c_ii^vii% |
| 20287 |
-\xint_c_ii^xiv*\xint_texuniformdeviate\xint_c_ii^vii% |
| 20288 |
-\xint_c_ii^xxi*\xint_texuniformdeviate\xint_c_ii^vii% |
| 20289 |
+\xint_texuniformdeviate_dgts#2\xint:/#2)*#2\xint:+#2\fi\relax#1% |
| 20290 |
}% |
| 20291 |
\def\XINT_uniformdeviate_a #1\xint: |
| 20292 |
{% |
| 20293 |
\expandafter\XINT_uniformdeviate_b\the\numexpr#1-(#1% |
| 20294 |
}% |
| 20295 |
\def\XINT_uniformdeviate_b#1#2\xint:{#1#2\if-#1}% |
| 20296 |
}% |
| 20297 |
{% |
| 20298 |
\xintMessage{xintkernel}{Warning}% |
| 20299 |
{No \string\uniformdeviate like primitive identified, macros producing^^J% |
| 20300 |
\XINT_fourspaces "random numbers" will raise (expandable) errors.}% |
| 20301 |
\def\xintUniformDeviate#1% |
| 20302 |
{% |
| 20303 |
\the\numexpr |
| 20304 |
\XINT_expandableerror{(xintkernel) No uniformdeviate primitive!}% |
| 20305 |
0\relax |
| 20306 |
}% |
| 20307 |
}% |
| 20308 |
\XINTrestorecatcodesendinput% |
| 20309 |
% \end{macrocode} |
| 20310 |
% \StoreCodelineNo {xintkernel} |
| 20311 |
% \cleardoublepage\let\xintkernelnameUp\undefined |
| 20312 |
%\gardesactifs |
| 20313 |
%\let</xintkernel>\relax |
| 20314 |
%\let<*xinttools>\gardesinactifs |
| 20315 |
%</xintkernel>^^A------------------------------------------------- |
| 20316 |
%<*xinttools>^^A-------------------------------------------------- |
| 20317 |
%^^A -*- coding: utf-8; mode: doctex; fill-column: 78; sentence-end-double-space: t; eval: (auto-fill-mode -1); fill-paragraph-function: nil; -*- |
| 20318 |
% \clearpage\csname xinttoolsnameUp\endcsname |
| 20319 |
% \let\MakePrivateLetters\xintMakePrivateLetters |
| 20320 |
% \section{Package \xinttoolsnameimp implementation} |
| 20321 |
% \RaisedLabel{sec:toolsimp} |
| 20322 |
% |
| 20323 |
% \localtableofcontents |
| 20324 |
% |
| 20325 |
% \added{1.09g} Splits off \xinttoolsnameimp from \xintnameimp. |
| 20326 |
% \changed{1.1} \xinttoolsnameimp ceases being loaded automatically by |
| 20327 |
% \xintnameimp. |
| 20328 |
% |
| 20329 |
% \subsection{Catcodes, \protect\eTeX{} and reload detection} |
| 20330 |
% |
| 20331 |
% The code for reload detection was initially copied from \textsc{Heiko |
| 20332 |
% Oberdiek}'s packages, then modified. |
| 20333 |
% |
| 20334 |
% The method for catcodes was also initially directly inspired by these |
| 20335 |
% packages. |
| 20336 |
% |
| 20337 |
% \begin{macrocode} |
| 20338 |
\begingroup\catcode61\catcode48\catcode32=10\relax% |
| 20339 |
\catcode13=5 % ^^M |
| 20340 |
\endlinechar=13 % |
| 20341 |
\catcode123=1 % { |
| 20342 |
\catcode125=2 % } |
| 20343 |
\catcode64=11 % @ |
| 20344 |
\catcode44=12 % , |
| 20345 |
\catcode46=12 % . |
| 20346 |
\catcode58=12 % : |
| 20347 |
\catcode94=7 % ^ |
| 20348 |
\def\empty{}\def\space{ }\newlinechar10 |
| 20349 |
\def\z{\endgroup}% |
| 20350 |
\expandafter\let\expandafter\x\csname [email protected]\endcsname |
| 20351 |
\expandafter\let\expandafter\w\csname [email protected]\endcsname |
| 20352 |
\expandafter\ifx\csname numexpr\endcsname\relax |
| 20353 |
\expandafter\ifx\csname PackageWarningNoLine\endcsname\relax |
| 20354 |
\immediate\write128{^^JPackage xinttools Warning:^^J% |
| 20355 |
\space\space\space\space |
| 20356 |
\numexpr not available, aborting input.^^J}% |
| 20357 |
\else |
| 20358 |
\PackageWarningNoLine{xinttools}{\numexpr not available, aborting input}% |
| 20359 |
\fi |
| 20360 |
\def\z{\endgroup\endinput}% |
| 20361 |
\else |
| 20362 |
\ifx\x\relax % plain-TeX, first loading of xinttools.sty |
| 20363 |
\ifx\w\relax % but xintkernel.sty not yet loaded. |
| 20364 |
\def\z{\endgroup\input xintkernel.sty\relax}% |
| 20365 |
\fi |
| 20366 |
\else |
| 20367 |
\ifx\x\empty % LaTeX, first loading, |
| 20368 |
% variable is initialized, but \ProvidesPackage not yet seen |
| 20369 |
\ifx\w\relax % xintkernel.sty not yet loaded. |
| 20370 |
\def\z{\endgroup\RequirePackage{xintkernel}}% |
| 20371 |
\fi |
| 20372 |
\else |
| 20373 |
\def\z{\endgroup\endinput}% xinttools already loaded. |
| 20374 |
\fi |
| 20375 |
\fi |
| 20376 |
\fi |
| 20377 |
\z% |
| 20378 |
\XINTsetupcatcodes% defined in xintkernel.sty |
| 20379 |
% \end{macrocode} |
| 20380 |
% \subsection{Package identification} |
| 20381 |
% \begin{macrocode} |
| 20382 |
\XINT_providespackage |
| 20383 |
\ProvidesPackage{xinttools}% |
| 20384 |
[2025/09/06 v1.4o Expandable and non-expandable utilities (JFB)]% |
| 20385 |
% \end{macrocode} |
| 20386 |
%\begin{lverb} |
| 20387 |
% \XINT_toks is used in macros such as \xintFor. It is not used |
| 20388 |
% elsewhere in the xint bundle. |
| 20389 |
%\end{lverb} |
| 20390 |
% \begin{macrocode} |
| 20391 |
\newtoks\XINT_toks |
| 20392 |
\xint_firstofone{\let\XINT_sptoken= } %<- space here! |
| 20393 |
% \end{macrocode} |
| 20394 |
% \subsection{\csh{xintgodef}, \csh{xintgoodef}, \csh{xintgfdef}} |
| 20395 |
% \added{1.09i} For use in |\xintAssign|. |
| 20396 |
% \begin{macrocode} |
| 20397 |
\def\xintgodef {\global\xintodef }% |
| 20398 |
\def\xintgoodef {\global\xintoodef }% |
| 20399 |
\def\xintgfdef {\global\xintfdef }% |
| 20400 |
% \end{macrocode} |
| 20401 |
% \subsection{\csh{xintRevWithBraces}} |
| 20402 |
% \added{1.06} Makes the expansion of its argument and then reverses |
| 20403 |
% the resulting tokens or braced tokens, adding a pair of braces to each (thus, |
| 20404 |
% maintaining it when it was already there.) The reason for |
| 20405 |
% |\xint:|, here and in other locations, is in case |#1| expands to nothing, |
| 20406 |
% the |\romannumeral-`0| must be stopped. |
| 20407 |
% \begin{macrocode} |
| 20408 |
\def\xintRevWithBraces {\romannumeral0\xintrevwithbraces }% |
| 20409 |
\def\xintRevWithBracesNoExpand {\romannumeral0\xintrevwithbracesnoexpand }% |
| 20410 |
\long\def\xintrevwithbraces #1% |
| 20411 |
{% |
| 20412 |
\expandafter\XINT_revwbr_loop\expandafter{\expandafter}% |
| 20413 |
\romannumeral`&&@#1\xint:\xint:\xint:\xint:% |
| 20414 |
\xint:\xint:\xint:\xint:\xint_bye |
| 20415 |
}% |
| 20416 |
\long\def\xintrevwithbracesnoexpand #1% |
| 20417 |
{% |
| 20418 |
\XINT_revwbr_loop {}% |
| 20419 |
#1\xint:\xint:\xint:\xint:% |
| 20420 |
\xint:\xint:\xint:\xint:\xint_bye |
| 20421 |
}% |
| 20422 |
\long\def\XINT_revwbr_loop #1#2#3#4#5#6#7#8#9% |
| 20423 |
{% |
| 20424 |
\xint_gob_til_xint: #9\XINT_revwbr_finish_a\xint:% |
| 20425 |
\XINT_revwbr_loop {{#9}{#8}{#7}{#6}{#5}{#4}{#3}{#2}#1}% |
| 20426 |
}% |
| 20427 |
\long\def\XINT_revwbr_finish_a\xint:\XINT_revwbr_loop #1#2\xint_bye |
| 20428 |
{% |
| 20429 |
\XINT_revwbr_finish_b #2\R\R\R\R\R\R\R\Z #1% |
| 20430 |
}% |
| 20431 |
\def\XINT_revwbr_finish_b #1#2#3#4#5#6#7#8\Z |
| 20432 |
{% |
| 20433 |
\xint_gob_til_R |
| 20434 |
#1\XINT_revwbr_finish_c \xint_gobble_viii |
| 20435 |
#2\XINT_revwbr_finish_c \xint_gobble_vii |
| 20436 |
#3\XINT_revwbr_finish_c \xint_gobble_vi |
| 20437 |
#4\XINT_revwbr_finish_c \xint_gobble_v |
| 20438 |
#5\XINT_revwbr_finish_c \xint_gobble_iv |
| 20439 |
#6\XINT_revwbr_finish_c \xint_gobble_iii |
| 20440 |
#7\XINT_revwbr_finish_c \xint_gobble_ii |
| 20441 |
\R\XINT_revwbr_finish_c \xint_gobble_i\Z |
| 20442 |
}% |
| 20443 |
% \end{macrocode} |
| 20444 |
%\begin{lverb} |
| 20445 |
% 1.1c revisited this old code and improved upon the earlier endings. |
| 20446 |
%\end{lverb} |
| 20447 |
% \begin{macrocode} |
| 20448 |
\def\XINT_revwbr_finish_c#1{% |
| 20449 |
\def\XINT_revwbr_finish_c##1##2\Z{\expandafter#1##1}% |
| 20450 |
}\XINT_revwbr_finish_c{ }% |
| 20451 |
% \end{macrocode} |
| 20452 |
% \subsection{\csh{xintZapFirstSpaces}} |
| 20453 |
% \added[2013/11/01]{1.09f} |
| 20454 |
% \changed[2014/10/21]{1.1} To |
| 20455 |
% correct the bug in case of an empty argument, or argument containing only |
| 20456 |
% spaces, which had been forgotten in first version. New version is simpler than |
| 20457 |
% the initial one. This macro does NOT expand its argument. |
| 20458 |
% \begin{macrocode} |
| 20459 |
\def\xintZapFirstSpaces {\romannumeral0\xintzapfirstspaces }% |
| 20460 |
\def\xintzapfirstspaces#1{\long |
| 20461 |
\def\xintzapfirstspaces ##1{\XINT_zapbsp_a #1##1\xint:#1#1\xint:}% |
| 20462 |
}\xintzapfirstspaces{ }% |
| 20463 |
% \end{macrocode} |
| 20464 |
%\begin{lverb} |
| 20465 |
% If the original #1 started with a space, the grabbed #1 is empty. Thus |
| 20466 |
% _again? will see #1=\xint_bye, and hand over control to _again which will loop |
| 20467 |
% back into \XINT_zapbsp_a, with one initial space less. If the original #1 did |
| 20468 |
% not start with a space, or was empty, then the #1 below will be a <sptoken>, |
| 20469 |
% then an extract of the original #1, not empty and not starting with a space, |
| 20470 |
% which contains what was up to the first <sp><sp> present in original #1, or, |
| 20471 |
% if none preexisted, <sptoken> and all of #1 (possibly empty) plus an ending |
| 20472 |
% \xint:. The added initial space will stop later the \romannumeral0. No |
| 20473 |
% brace stripping is possible. Control is handed over to \XINT_zapbsp_b which |
| 20474 |
% strips out the ending \xint:<sp><sp>\xint: |
| 20475 |
%\end{lverb} |
| 20476 |
% \begin{macrocode} |
| 20477 |
\def\XINT_zapbsp_a#1{\long\def\XINT_zapbsp_a ##1#1#1{% |
| 20478 |
\XINT_zapbsp_again?##1\xint_bye\XINT_zapbsp_b ##1#1#1}% |
| 20479 |
}\XINT_zapbsp_a{ }% |
| 20480 |
\long\def\XINT_zapbsp_again? #1{\xint_bye #1\XINT_zapbsp_again }% |
| 20481 |
\xint_firstofone{\def\XINT_zapbsp_again\XINT_zapbsp_b} {\XINT_zapbsp_a }% |
| 20482 |
\long\def\XINT_zapbsp_b #1\xint:#2\xint:{#1}% |
| 20483 |
% \end{macrocode} |
| 20484 |
% \subsection{\csh{xintZapLastSpaces}} |
| 20485 |
% \added[2013/11/01]{1.09f} |
| 20486 |
% \begin{macrocode} |
| 20487 |
\def\xintZapLastSpaces {\romannumeral0\xintzaplastspaces }% |
| 20488 |
\def\xintzaplastspaces#1{\long |
| 20489 |
\def\xintzaplastspaces ##1{\XINT_zapesp_a {}\empty##1#1#1\xint_bye\xint:}% |
| 20490 |
}\xintzaplastspaces{ }% |
| 20491 |
% \end{macrocode} |
| 20492 |
%\begin{lverb} |
| 20493 |
% The \empty from \xintzaplastspaces is to prevent brace removal in the |
| 20494 |
% #2 below. The \expandafter chain removes it. |
| 20495 |
%\end{lverb} |
| 20496 |
% \begin{macrocode} |
| 20497 |
\xint_firstofone {\long\def\XINT_zapesp_a #1#2 } %<- second space here |
| 20498 |
{\expandafter\XINT_zapesp_b\expandafter{#2}{#1}}% |
| 20499 |
% \end{macrocode} |
| 20500 |
%\begin{lverb} |
| 20501 |
% Notice again an \empty added here. This is in preparation for possibly looping |
| 20502 |
% back to \XINT_zapesp_a. If the initial #1 had no <sp><sp>, the stuff however |
| 20503 |
% will not loop, because #3 will already be <some spaces>\xint_bye. Notice |
| 20504 |
% that this macro fetches all way to the ending \xint:. This looks not |
| 20505 |
% very efficient, but how often do we have to strip ending spaces from |
| 20506 |
% something which also has inner stretches of _multiple_ space tokens ?;-). |
| 20507 |
%\end{lverb} |
| 20508 |
% \begin{macrocode} |
| 20509 |
\long\def\XINT_zapesp_b #1#2#3\xint:% |
| 20510 |
{\XINT_zapesp_end? #3\XINT_zapesp_e {#2#1}\empty #3\xint:}% |
| 20511 |
% \end{macrocode} |
| 20512 |
%\begin{lverb} |
| 20513 |
% When we have been over all possible <sp><sp> things, we reach the |
| 20514 |
% ending space tokens, and #3 will be a bunch of spaces (possibly none) |
| 20515 |
% followed by \xint_bye. So the #1 in _end? will be \xint_bye. In all other cases |
| 20516 |
% #1 can not be \xint_bye (assuming naturally this token does nor arise in |
| 20517 |
% original input), hence control falls back to \XINT_zapesp_e which will loop back |
| 20518 |
% to \XINT_zapesp_a. |
| 20519 |
%\end{lverb} |
| 20520 |
% \begin{macrocode} |
| 20521 |
\long\def\XINT_zapesp_end? #1{\xint_bye #1\XINT_zapesp_end }% |
| 20522 |
% \end{macrocode} |
| 20523 |
%\begin{lverb} |
| 20524 |
% We are done. The #1 here has accumulated all the previous material, |
| 20525 |
% and is stripped of its ending spaces, if any. |
| 20526 |
%\end{lverb} |
| 20527 |
% \begin{macrocode} |
| 20528 |
\long\def\XINT_zapesp_end\XINT_zapesp_e #1#2\xint:{ #1}% |
| 20529 |
% \end{macrocode} |
| 20530 |
%\begin{lverb} |
| 20531 |
% We haven't yet reached the end, so we need to re-inject two space |
| 20532 |
% tokens after what we have gotten so far. Then we loop. |
| 20533 |
%\end{lverb} |
| 20534 |
% \begin{macrocode} |
| 20535 |
\def\XINT_zapesp_e#1{% |
| 20536 |
\long\def\XINT_zapesp_e ##1{\XINT_zapesp_a {##1#1#1}}% |
| 20537 |
}\XINT_zapesp_e{ }% |
| 20538 |
% \end{macrocode} |
| 20539 |
% \subsection{\csh{xintZapSpaces}} |
| 20540 |
% \added[2013/11/01]{1.09f} |
| 20541 |
% \changed[2014/10/21]{1.1} It had the |
| 20542 |
% same bug as |\xintZapFirstSpaces|. We in effect do first |\xintZapFirstSpaces|, |
| 20543 |
% then |\xintZapLastSpaces|. |
| 20544 |
% \begin{macrocode} |
| 20545 |
\def\xintZapSpaces {\romannumeral0\xintzapspaces }% |
| 20546 |
\def\xintzapspaces#1{% |
| 20547 |
\long\def\xintzapspaces ##1% like \xintZapFirstSpaces. |
| 20548 |
{\XINT_zapsp_a #1##1\xint:#1#1\xint:}% |
| 20549 |
}\xintzapspaces{ }% |
| 20550 |
\def\XINT_zapsp_a#1{% |
| 20551 |
\long\def\XINT_zapsp_a ##1#1#1% |
| 20552 |
{\XINT_zapsp_again?##1\xint_bye\XINT_zapsp_b##1#1#1}% |
| 20553 |
}\XINT_zapsp_a{ }% |
| 20554 |
\long\def\XINT_zapsp_again? #1{\xint_bye #1\XINT_zapsp_again }% |
| 20555 |
\xint_firstofone{\def\XINT_zapsp_again\XINT_zapsp_b} {\XINT_zapsp_a }% |
| 20556 |
\xint_firstofone{\def\XINT_zapsp_b} {\XINT_zapsp_c }% |
| 20557 |
\def\XINT_zapsp_c#1{% |
| 20558 |
\long\def\XINT_zapsp_c ##1\xint:##2\xint:% |
| 20559 |
{\XINT_zapesp_a{}\empty ##1#1#1\xint_bye\xint:}% |
| 20560 |
}\XINT_zapsp_c{ }% |
| 20561 |
% \end{macrocode} |
| 20562 |
% \subsection{\csh{xintZapSpacesB}} |
| 20563 |
% \added[2013/11/01]{1.09f} Strips up to one pair of braces (but then |
| 20564 |
% does not strip spaces inside). |
| 20565 |
% \begin{macrocode} |
| 20566 |
\def\xintZapSpacesB {\romannumeral0\xintzapspacesb }% |
| 20567 |
\long\def\xintzapspacesb #1{\XINT_zapspb_one? #1\xint:\xint:% |
| 20568 |
\xint_bye\xintzapspaces {#1}}% |
| 20569 |
\long\def\XINT_zapspb_one? #1#2% |
| 20570 |
{\xint_gob_til_xint: #1\XINT_zapspb_onlyspaces\xint:% |
| 20571 |
\xint_gob_til_xint: #2\XINT_zapspb_bracedorone\xint:% |
| 20572 |
\xint_bye {#1}}% |
| 20573 |
\def\XINT_zapspb_onlyspaces\xint:% |
| 20574 |
\xint_gob_til_xint:\xint:\XINT_zapspb_bracedorone\xint:% |
| 20575 |
\xint_bye #1\xint_bye\xintzapspaces #2{ }% |
| 20576 |
\long\def\XINT_zapspb_bracedorone\xint:% |
| 20577 |
\xint_bye #1\xint:\xint_bye\xintzapspaces #2{ #1}% |
| 20578 |
% \end{macrocode} |
| 20579 |
% \subsection{\csh{xintCSVtoList}, \csh{xintCSVtoListNonStripped}} |
| 20580 |
% \added{1.06} |
| 20581 |
%\begin{lverb} \xintCSVtoList transforms a,b,..,z into {a}{b}...{z}. The comma |
| 20582 |
% separated list may be a macro which is first f-expanded. Here, use of \Z |
| 20583 |
% (and \R) perfectly safe. |
| 20584 |
%\end{lverb} |
| 20585 |
% \changed[2013/11/02]{1.09f} Automatically filters items with |
| 20586 |
% |\xintZapSpacesB| to strip away all spaces around commas, and spaces at the start |
| 20587 |
% and end of the list. The original is kept as |\xintCSVtoListNonStripped|, and is |
| 20588 |
% faster. But ... it doesn't strip spaces. |
| 20589 |
% |
| 20590 |
% ATTENTION: if the input is empty the output contains one item (empty, of |
| 20591 |
% course). This means an |\xintFor| loop always executes at least once the |
| 20592 |
% iteration, contrarily to |\xintFor*|. |
| 20593 |
% \begin{macrocode} |
| 20594 |
\def\xintCSVtoList {\romannumeral0\xintcsvtolist }% |
| 20595 |
\long\def\xintcsvtolist #1{\expandafter\xintApply |
| 20596 |
\expandafter\xintzapspacesb |
| 20597 |
\expandafter{\romannumeral0\xintcsvtolistnonstripped{#1}}}% |
| 20598 |
\def\xintCSVtoListNoExpand {\romannumeral0\xintcsvtolistnoexpand }% |
| 20599 |
\long\def\xintcsvtolistnoexpand #1{\expandafter\xintApply |
| 20600 |
\expandafter\xintzapspacesb |
| 20601 |
\expandafter{\romannumeral0\xintcsvtolistnonstrippednoexpand{#1}}}% |
| 20602 |
\def\xintCSVtoListNonStripped {\romannumeral0\xintcsvtolistnonstripped }% |
| 20603 |
\def\xintCSVtoListNonStrippedNoExpand |
| 20604 |
{\romannumeral0\xintcsvtolistnonstrippednoexpand }% |
| 20605 |
\long\def\xintcsvtolistnonstripped #1% |
| 20606 |
{% |
| 20607 |
\expandafter\XINT_csvtol_loop_a\expandafter |
| 20608 |
{\expandafter}\romannumeral`&&@#1% |
| 20609 |
,\xint_bye,\xint_bye,\xint_bye,\xint_bye |
| 20610 |
,\xint_bye,\xint_bye,\xint_bye,\xint_bye,\Z |
| 20611 |
}% |
| 20612 |
\long\def\xintcsvtolistnonstrippednoexpand #1% |
| 20613 |
{% |
| 20614 |
\XINT_csvtol_loop_a |
| 20615 |
{}#1,\xint_bye,\xint_bye,\xint_bye,\xint_bye |
| 20616 |
,\xint_bye,\xint_bye,\xint_bye,\xint_bye,\Z |
| 20617 |
}% |
| 20618 |
\long\def\XINT_csvtol_loop_a #1#2,#3,#4,#5,#6,#7,#8,#9,% |
| 20619 |
{% |
| 20620 |
\xint_bye #9\XINT_csvtol_finish_a\xint_bye |
| 20621 |
\XINT_csvtol_loop_b {#1}{{#2}{#3}{#4}{#5}{#6}{#7}{#8}{#9}}% |
| 20622 |
}% |
| 20623 |
\long\def\XINT_csvtol_loop_b #1#2{\XINT_csvtol_loop_a {#1#2}}% |
| 20624 |
\long\def\XINT_csvtol_finish_a\xint_bye\XINT_csvtol_loop_b #1#2#3\Z |
| 20625 |
{% |
| 20626 |
\XINT_csvtol_finish_b #3\R,\R,\R,\R,\R,\R,\R,\Z #2{#1}% |
| 20627 |
}% |
| 20628 |
% \end{macrocode} |
| 20629 |
%\begin{lverb} |
| 20630 |
% 1.1c revisits this old code and improves upon the earlier endings. |
| 20631 |
% But as the _d.. macros have already nine parameters, I needed the |
| 20632 |
% \expandafter and \xint_gob_til_Z in finish_b (compare \XINT_keep_endb, or |
| 20633 |
% also \XINT_RQ_end_b). |
| 20634 |
%\end{lverb} |
| 20635 |
% \begin{macrocode} |
| 20636 |
\def\XINT_csvtol_finish_b #1,#2,#3,#4,#5,#6,#7,#8\Z |
| 20637 |
{% |
| 20638 |
\xint_gob_til_R |
| 20639 |
#1\expandafter\XINT_csvtol_finish_dviii\xint_gob_til_Z |
| 20640 |
#2\expandafter\XINT_csvtol_finish_dvii \xint_gob_til_Z |
| 20641 |
#3\expandafter\XINT_csvtol_finish_dvi \xint_gob_til_Z |
| 20642 |
#4\expandafter\XINT_csvtol_finish_dv \xint_gob_til_Z |
| 20643 |
#5\expandafter\XINT_csvtol_finish_div \xint_gob_til_Z |
| 20644 |
#6\expandafter\XINT_csvtol_finish_diii \xint_gob_til_Z |
| 20645 |
#7\expandafter\XINT_csvtol_finish_dii \xint_gob_til_Z |
| 20646 |
\R\XINT_csvtol_finish_di \Z |
| 20647 |
}% |
| 20648 |
\long\def\XINT_csvtol_finish_dviii #1#2#3#4#5#6#7#8#9{ #9}% |
| 20649 |
\long\def\XINT_csvtol_finish_dvii #1#2#3#4#5#6#7#8#9{ #9{#1}}% |
| 20650 |
\long\def\XINT_csvtol_finish_dvi #1#2#3#4#5#6#7#8#9{ #9{#1}{#2}}% |
| 20651 |
\long\def\XINT_csvtol_finish_dv #1#2#3#4#5#6#7#8#9{ #9{#1}{#2}{#3}}% |
| 20652 |
\long\def\XINT_csvtol_finish_div #1#2#3#4#5#6#7#8#9{ #9{#1}{#2}{#3}{#4}}% |
| 20653 |
\long\def\XINT_csvtol_finish_diii #1#2#3#4#5#6#7#8#9{ #9{#1}{#2}{#3}{#4}{#5}}% |
| 20654 |
\long\def\XINT_csvtol_finish_dii #1#2#3#4#5#6#7#8#9% |
| 20655 |
{ #9{#1}{#2}{#3}{#4}{#5}{#6}}% |
| 20656 |
\long\def\XINT_csvtol_finish_di\Z #1#2#3#4#5#6#7#8#9% |
| 20657 |
{ #9{#1}{#2}{#3}{#4}{#5}{#6}{#7}}% |
| 20658 |
% \end{macrocode} |
| 20659 |
% \subsection{\csh{xintListWithSep}} |
| 20660 |
% \added{1.04} |
| 20661 |
%\begin{lverb} |
| 20662 |
% \xintListWithSep {\sep}{{a}{b}...{z}} returns a \sep b \sep ....\sep z. It |
| 20663 |
% f-expands its second argument. The 'sep' may be \par's: the macro |
| 20664 |
% \xintlistwithsep etc... are all declared long. 'sep' does not have to be a |
| 20665 |
% single token. It is not expanded. The "list" argument may be empty. |
| 20666 |
% |
| 20667 |
% \xintListWithSepNoExpand does not f-expand its second argument. |
| 20668 |
%\end{lverb} |
| 20669 |
% \changed{1.2p} |
| 20670 |
%\begin{lverb} |
| 20671 |
% This venerable macro from 1.04 remained unchanged for a long time and was |
| 20672 |
% finally refactored at 1.2p for increased speed. Tests done with a list of |
| 20673 |
% identical {\x} items and a sep of \z demonstrated a speed increase of about: |
| 20674 |
%( - 3x for 30 items, |
| 20675 |
%: - 4.5x for 100 items, |
| 20676 |
%: - 7.5x--8x for 1000 items. |
| 20677 |
%) |
| 20678 |
%\end{lverb} |
| 20679 |
% \begin{macrocode} |
| 20680 |
\def\xintListWithSep {\romannumeral0\xintlistwithsep }% |
| 20681 |
\def\xintListWithSepNoExpand {\romannumeral0\xintlistwithsepnoexpand }% |
| 20682 |
\long\def\xintlistwithsep #1#2% |
| 20683 |
{\expandafter\XINT_lws\expandafter {\romannumeral`&&@#2}{#1}}% |
| 20684 |
\long\def\xintlistwithsepnoexpand #1#2% |
| 20685 |
{% |
| 20686 |
\XINT_lws_loop_a {#1}#2{\xint_bye\XINT_lws_e_vi}% |
| 20687 |
{\xint_bye\XINT_lws_e_v}{\xint_bye\XINT_lws_e_iv}% |
| 20688 |
{\xint_bye\XINT_lws_e_iii}{\xint_bye\XINT_lws_e_ii}% |
| 20689 |
{\xint_bye\XINT_lws_e_i}{\xint_bye\XINT_lws_e}% |
| 20690 |
{\xint_bye\expandafter\space}\xint_bye |
| 20691 |
}% |
| 20692 |
\long\def\XINT_lws #1#2% |
| 20693 |
{% |
| 20694 |
\XINT_lws_loop_a {#2}#1{\xint_bye\XINT_lws_e_vi}% |
| 20695 |
{\xint_bye\XINT_lws_e_v}{\xint_bye\XINT_lws_e_iv}% |
| 20696 |
{\xint_bye\XINT_lws_e_iii}{\xint_bye\XINT_lws_e_ii}% |
| 20697 |
{\xint_bye\XINT_lws_e_i}{\xint_bye\XINT_lws_e}% |
| 20698 |
{\xint_bye\expandafter\space}\xint_bye |
| 20699 |
}% |
| 20700 |
\long\def\XINT_lws_loop_a #1#2#3#4#5#6#7#8#9% |
| 20701 |
{% |
| 20702 |
\xint_bye #9\xint_bye |
| 20703 |
\XINT_lws_loop_b {#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}{#9}% |
| 20704 |
}% |
| 20705 |
\long\def\XINT_lws_loop_b #1#2#3#4#5#6#7#8#9% |
| 20706 |
{% |
| 20707 |
\XINT_lws_loop_a {#1}{#2#1#3#1#4#1#5#1#6#1#7#1#8#1#9}% |
| 20708 |
}% |
| 20709 |
\long\def\XINT_lws_e_vi\xint_bye\XINT_lws_loop_b #1#2#3#4#5#6#7#8#9\xint_bye |
| 20710 |
{ #2#1#3#1#4#1#5#1#6#1#7#1#8}% |
| 20711 |
\long\def\XINT_lws_e_v\xint_bye\XINT_lws_loop_b #1#2#3#4#5#6#7#8\xint_bye |
| 20712 |
{ #2#1#3#1#4#1#5#1#6#1#7}% |
| 20713 |
\long\def\XINT_lws_e_iv\xint_bye\XINT_lws_loop_b #1#2#3#4#5#6#7\xint_bye |
| 20714 |
{ #2#1#3#1#4#1#5#1#6}% |
| 20715 |
\long\def\XINT_lws_e_iii\xint_bye\XINT_lws_loop_b #1#2#3#4#5#6\xint_bye |
| 20716 |
{ #2#1#3#1#4#1#5}% |
| 20717 |
\long\def\XINT_lws_e_ii\xint_bye\XINT_lws_loop_b #1#2#3#4#5\xint_bye |
| 20718 |
{ #2#1#3#1#4}% |
| 20719 |
\long\def\XINT_lws_e_i\xint_bye\XINT_lws_loop_b #1#2#3#4\xint_bye |
| 20720 |
{ #2#1#3}% |
| 20721 |
\long\def\XINT_lws_e\xint_bye\XINT_lws_loop_b #1#2#3\xint_bye |
| 20722 |
{ #2}% |
| 20723 |
% \end{macrocode} |
| 20724 |
% \subsection{\csh{xintNthElt}} |
| 20725 |
% \added{1.06} |
| 20726 |
% \changed{1.2j} |
| 20727 |
%\begin{lverb} |
| 20728 |
% Last refactored in 1.2j. |
| 20729 |
% |
| 20730 |
% \xintNthElt {i}{List} returns the i th item from List (one pair of braces |
| 20731 |
% removed). The list is first f-expanded. The \xintNthEltNoExpand does no |
| 20732 |
% expansion of its second argument. Both variants expand i inside \numexpr. |
| 20733 |
% |
| 20734 |
% With i = 0, the number of items is returned using \xintLength but with the |
| 20735 |
% List argument f-expanded first. |
| 20736 |
% |
| 20737 |
% Negative values return the |i|th element from the end. |
| 20738 |
% |
| 20739 |
% When i is out of range, an empty value is returned. |
| 20740 |
%\end{lverb} |
| 20741 |
% \begin{macrocode} |
| 20742 |
\def\xintNthElt {\romannumeral0\xintnthelt }% |
| 20743 |
\def\xintNthEltNoExpand {\romannumeral0\xintntheltnoexpand }% |
| 20744 |
\long\def\xintnthelt #1#2{\expandafter\XINT_nthelt_a\the\numexpr #1\expandafter.% |
| 20745 |
\expandafter{\romannumeral`&&@#2}}% |
| 20746 |
\def\xintntheltnoexpand #1{\expandafter\XINT_nthelt_a\the\numexpr #1.}% |
| 20747 |
\def\XINT_nthelt_a #1% |
| 20748 |
{% |
| 20749 |
\xint_UDzerominusfork |
| 20750 |
#1-\XINT_nthelt_zero |
| 20751 |
0#1\XINT_nthelt_neg |
| 20752 |
0-{\XINT_nthelt_pos #1}% |
| 20753 |
\krof |
| 20754 |
}% |
| 20755 |
\def\XINT_nthelt_zero #1.{\xintlength }% |
| 20756 |
\long\def\XINT_nthelt_neg #1.#2% |
| 20757 |
{% |
| 20758 |
\expandafter\XINT_nthelt_neg_a\the\numexpr\xint_c_i+\XINT_length_loop |
| 20759 |
#2\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint: |
| 20760 |
\xint_c_viii\xint_c_vii\xint_c_vi\xint_c_v |
| 20761 |
\xint_c_iv\xint_c_iii\xint_c_ii\xint_c_i\xint_c_\xint_bye |
| 20762 |
-#1.#2\xint_bye |
| 20763 |
}% |
| 20764 |
\def\XINT_nthelt_neg_a #1% |
| 20765 |
{% |
| 20766 |
\xint_UDzerominusfork |
| 20767 |
#1-\xint_stop_afterbye |
| 20768 |
0#1\xint_stop_afterbye |
| 20769 |
0-{}% |
| 20770 |
\krof |
| 20771 |
\expandafter\XINT_nthelt_neg_b |
| 20772 |
\romannumeral\expandafter\XINT_gobble\the\numexpr-\xint_c_i+#1% |
| 20773 |
}% |
| 20774 |
\long\def\XINT_nthelt_neg_b #1#2\xint_bye{ #1}% |
| 20775 |
\long\def\XINT_nthelt_pos #1.#2% |
| 20776 |
{% |
| 20777 |
\expandafter\XINT_nthelt_pos_done |
| 20778 |
\romannumeral0\expandafter\XINT_trim_loop\the\numexpr#1-\xint_c_x.% |
| 20779 |
#2\xint:\xint:\xint:\xint:\xint:% |
| 20780 |
\xint:\xint:\xint:\xint:\xint:% |
| 20781 |
\xint_bye |
| 20782 |
}% |
| 20783 |
\def\XINT_nthelt_pos_done #1{% |
| 20784 |
\long\def\XINT_nthelt_pos_done ##1##2\xint_bye{% |
| 20785 |
\xint_gob_til_xint:##1\expandafter#1\xint_gobble_ii\xint:#1##1}% |
| 20786 |
}\XINT_nthelt_pos_done{ }% |
| 20787 |
% \end{macrocode} |
| 20788 |
% \subsection{\csh{xintNthOnePy}} |
| 20789 |
% \added{1.4} |
| 20790 |
% See relevant code comments in \xintexprnameimp. |
| 20791 |
% \begin{macrocode} |
| 20792 |
\def\xintNthOnePy {\romannumeral0\xintnthonepy }% |
| 20793 |
\def\xintNthOnePyNoExpand {\romannumeral0\xintnthonepynoexpand }% |
| 20794 |
\long\def\xintnthonepy #1#2{\expandafter\XINT_nthonepy_a\the\numexpr #1\expandafter.% |
| 20795 |
\expandafter{\romannumeral`&&@#2}}% |
| 20796 |
\def\xintnthonepynoexpand #1{\expandafter\XINT_nthonepy_a\the\numexpr #1.}% |
| 20797 |
\def\XINT_nthonepy_a #1% |
| 20798 |
{% |
| 20799 |
\xint_UDsignfork |
| 20800 |
#1\XINT_nthonepy_neg |
| 20801 |
-{\XINT_nthonepy_nonneg #1}% |
| 20802 |
\krof |
| 20803 |
}% |
| 20804 |
\long\def\XINT_nthonepy_neg #1.#2% |
| 20805 |
{% |
| 20806 |
\expandafter\XINT_nthonepy_neg_a\the\numexpr\xint_c_i+\XINT_length_loop |
| 20807 |
#2\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint: |
| 20808 |
\xint_c_viii\xint_c_vii\xint_c_vi\xint_c_v |
| 20809 |
\xint_c_iv\xint_c_iii\xint_c_ii\xint_c_i\xint_c_\xint_bye |
| 20810 |
-#1.#2\xint_bye |
| 20811 |
}% |
| 20812 |
\def\XINT_nthonepy_neg_a #1% |
| 20813 |
{% |
| 20814 |
\xint_UDzerominusfork |
| 20815 |
#1-\xint_stop_afterbye |
| 20816 |
0#1\xint_stop_afterbye |
| 20817 |
0-{}% |
| 20818 |
\krof |
| 20819 |
\expandafter\XINT_nthonepy_neg_b |
| 20820 |
\romannumeral\expandafter\XINT_gobble\the\numexpr-\xint_c_i+#1% |
| 20821 |
}% |
| 20822 |
\long\def\XINT_nthonepy_neg_b #1#2\xint_bye{{#1}}% |
| 20823 |
\long\def\XINT_nthonepy_nonneg #1.#2% |
| 20824 |
{% |
| 20825 |
\expandafter\XINT_nthonepy_nonneg_done |
| 20826 |
\romannumeral0\expandafter\XINT_trim_loop\the\numexpr#1-\xint_c_ix.% |
| 20827 |
#2\xint:\xint:\xint:\xint:\xint:% |
| 20828 |
\xint:\xint:\xint:\xint:\xint:% |
| 20829 |
\xint_bye |
| 20830 |
}% |
| 20831 |
\def\XINT_nthonepy_nonneg_done #1{% |
| 20832 |
\long\def\XINT_nthonepy_nonneg_done ##1##2\xint_bye{% |
| 20833 |
\xint_gob_til_xint:##1\expandafter#1\xint_gobble_ii\xint:{##1}}% |
| 20834 |
}\XINT_nthonepy_nonneg_done{ }% |
| 20835 |
% \end{macrocode} |
| 20836 |
% \subsection{\csh{xintKeep}} |
| 20837 |
% \added{1.09m} |
| 20838 |
%\begin{lverb} |
| 20839 |
% \xintKeep{i}{L} f-expands its second argument L. It then grabs the first i |
| 20840 |
% items from L and discards the rest. |
| 20841 |
% |
| 20842 |
% ATTENTION: **each such kept item is returned inside a brace pair** |
| 20843 |
% Use \xintKeepUnbraced to avoid that. |
| 20844 |
% |
| 20845 |
% For i equal or larger to the number N of items in (expanded) L, the full L |
| 20846 |
% is returned (with braced items). For i=0, the macro returns an empty output. |
| 20847 |
% For i<0, the macro discards the first N-|i| items. No brace pairs added to |
| 20848 |
% the remaining items. For i is less or equal to -N, the full L is returned |
| 20849 |
% (with no braces added.) |
| 20850 |
% |
| 20851 |
% \xintKeepNoExpand does not expand the L argument. |
| 20852 |
%\end{lverb} |
| 20853 |
% \changed{1.2i} |
| 20854 |
%\begin{lverb} |
| 20855 |
% Prior to 1.2i the code proceeded along a loop with no pre-computation of |
| 20856 |
% the length of L, for the i>0 case. The faster 1.2i version takes advantage |
| 20857 |
% of novel \xintLengthUpTo from xintkernel.sty. |
| 20858 |
%\end{lverb} |
| 20859 |
% \begin{macrocode} |
| 20860 |
\def\xintKeep {\romannumeral0\xintkeep }% |
| 20861 |
\def\xintKeepNoExpand {\romannumeral0\xintkeepnoexpand }% |
| 20862 |
\long\def\xintkeep #1#2{\expandafter\XINT_keep_a\the\numexpr #1\expandafter.% |
| 20863 |
\expandafter{\romannumeral`&&@#2}}% |
| 20864 |
\def\xintkeepnoexpand #1{\expandafter\XINT_keep_a\the\numexpr #1.}% |
| 20865 |
\def\XINT_keep_a #1% |
| 20866 |
{% |
| 20867 |
\xint_UDzerominusfork |
| 20868 |
#1-\XINT_keep_keepnone |
| 20869 |
0#1\XINT_keep_neg |
| 20870 |
0-{\XINT_keep_pos #1}% |
| 20871 |
\krof |
| 20872 |
}% |
| 20873 |
\long\def\XINT_keep_keepnone .#1{ }% |
| 20874 |
\long\def\XINT_keep_neg #1.#2% |
| 20875 |
{% |
| 20876 |
\expandafter\XINT_keep_neg_a\the\numexpr |
| 20877 |
#1-\numexpr\XINT_length_loop |
| 20878 |
#2\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint: |
| 20879 |
\xint_c_viii\xint_c_vii\xint_c_vi\xint_c_v |
| 20880 |
\xint_c_iv\xint_c_iii\xint_c_ii\xint_c_i\xint_c_\xint_bye.#2% |
| 20881 |
}% |
| 20882 |
\def\XINT_keep_neg_a #1% |
| 20883 |
{% |
| 20884 |
\xint_UDsignfork |
| 20885 |
#1{\expandafter\space\romannumeral\XINT_gobble}% |
| 20886 |
-\XINT_keep_keepall |
| 20887 |
\krof |
| 20888 |
}% |
| 20889 |
\def\XINT_keep_keepall #1.{ }% |
| 20890 |
\long\def\XINT_keep_pos #1.#2% |
| 20891 |
{% |
| 20892 |
\expandafter\XINT_keep_loop |
| 20893 |
\the\numexpr#1-\XINT_lengthupto_loop |
| 20894 |
#1.#2\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint: |
| 20895 |
\xint_c_vii\xint_c_vi\xint_c_v\xint_c_iv |
| 20896 |
\xint_c_iii\xint_c_ii\xint_c_i\xint_c_\xint_bye.% |
| 20897 |
-\xint_c_viii.{}#2\xint_bye% |
| 20898 |
}% |
| 20899 |
\def\XINT_keep_loop #1#2.% |
| 20900 |
{% |
| 20901 |
\xint_gob_til_minus#1\XINT_keep_loop_end-% |
| 20902 |
\expandafter\XINT_keep_loop |
| 20903 |
\the\numexpr#1#2-\xint_c_viii\expandafter.\XINT_keep_loop_pickeight |
| 20904 |
}% |
| 20905 |
\long\def\XINT_keep_loop_pickeight |
| 20906 |
#1#2#3#4#5#6#7#8#9{{#1{#2}{#3}{#4}{#5}{#6}{#7}{#8}{#9}}}% |
| 20907 |
\def\XINT_keep_loop_end-\expandafter\XINT_keep_loop |
| 20908 |
\the\numexpr-#1-\xint_c_viii\expandafter.\XINT_keep_loop_pickeight |
| 20909 |
{\csname XINT_keep_end#1\endcsname}% |
| 20910 |
\long\expandafter\def\csname XINT_keep_end1\endcsname |
| 20911 |
#1#2#3#4#5#6#7#8#9\xint_bye { #1{#2}{#3}{#4}{#5}{#6}{#7}{#8}}% |
| 20912 |
\long\expandafter\def\csname XINT_keep_end2\endcsname |
| 20913 |
#1#2#3#4#5#6#7#8\xint_bye { #1{#2}{#3}{#4}{#5}{#6}{#7}}% |
| 20914 |
\long\expandafter\def\csname XINT_keep_end3\endcsname |
| 20915 |
#1#2#3#4#5#6#7\xint_bye { #1{#2}{#3}{#4}{#5}{#6}}% |
| 20916 |
\long\expandafter\def\csname XINT_keep_end4\endcsname |
| 20917 |
#1#2#3#4#5#6\xint_bye { #1{#2}{#3}{#4}{#5}}% |
| 20918 |
\long\expandafter\def\csname XINT_keep_end5\endcsname |
| 20919 |
#1#2#3#4#5\xint_bye { #1{#2}{#3}{#4}}% |
| 20920 |
\long\expandafter\def\csname XINT_keep_end6\endcsname |
| 20921 |
#1#2#3#4\xint_bye { #1{#2}{#3}}% |
| 20922 |
\long\expandafter\def\csname XINT_keep_end7\endcsname |
| 20923 |
#1#2#3\xint_bye { #1{#2}}% |
| 20924 |
\long\expandafter\def\csname XINT_keep_end8\endcsname |
| 20925 |
#1#2\xint_bye { #1}% |
| 20926 |
% \end{macrocode} |
| 20927 |
% \subsection{\csh{xintKeepUnbraced}} |
| 20928 |
% \added{1.2a} |
| 20929 |
%\begin{lverb} |
| 20930 |
% Same as \xintKeep but will *not* add (or maintain) brace pairs |
| 20931 |
% around the kept items when length(L)>i>0. |
| 20932 |
% |
| 20933 |
% The name may cause a mis-understanding: for i<0, (i.e. keeping only |
| 20934 |
% trailing items), there is no brace removal at all happening. |
| 20935 |
%\end{lverb} |
| 20936 |
% |
| 20937 |
% \changed{1.2i} As |\xintKeep|. |
| 20938 |
% \begin{macrocode} |
| 20939 |
\def\xintKeepUnbraced {\romannumeral0\xintkeepunbraced }% |
| 20940 |
\def\xintKeepUnbracedNoExpand {\romannumeral0\xintkeepunbracednoexpand }% |
| 20941 |
\long\def\xintkeepunbraced #1#2% |
| 20942 |
{\expandafter\XINT_keepunbr_a\the\numexpr #1\expandafter.% |
| 20943 |
\expandafter{\romannumeral`&&@#2}}% |
| 20944 |
\def\xintkeepunbracednoexpand #1% |
| 20945 |
{\expandafter\XINT_keepunbr_a\the\numexpr #1.}% |
| 20946 |
\def\XINT_keepunbr_a #1% |
| 20947 |
{% |
| 20948 |
\xint_UDzerominusfork |
| 20949 |
#1-\XINT_keep_keepnone |
| 20950 |
0#1\XINT_keep_neg |
| 20951 |
0-{\XINT_keepunbr_pos #1}% |
| 20952 |
\krof |
| 20953 |
}% |
| 20954 |
\long\def\XINT_keepunbr_pos #1.#2% |
| 20955 |
{% |
| 20956 |
\expandafter\XINT_keepunbr_loop |
| 20957 |
\the\numexpr#1-\XINT_lengthupto_loop |
| 20958 |
#1.#2\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint: |
| 20959 |
\xint_c_vii\xint_c_vi\xint_c_v\xint_c_iv |
| 20960 |
\xint_c_iii\xint_c_ii\xint_c_i\xint_c_\xint_bye.% |
| 20961 |
-\xint_c_viii.{}#2\xint_bye% |
| 20962 |
}% |
| 20963 |
\def\XINT_keepunbr_loop #1#2.% |
| 20964 |
{% |
| 20965 |
\xint_gob_til_minus#1\XINT_keepunbr_loop_end-% |
| 20966 |
\expandafter\XINT_keepunbr_loop |
| 20967 |
\the\numexpr#1#2-\xint_c_viii\expandafter.\XINT_keepunbr_loop_pickeight |
| 20968 |
}% |
| 20969 |
\long\def\XINT_keepunbr_loop_pickeight |
| 20970 |
#1#2#3#4#5#6#7#8#9{{#1#2#3#4#5#6#7#8#9}}% |
| 20971 |
\def\XINT_keepunbr_loop_end-\expandafter\XINT_keepunbr_loop |
| 20972 |
\the\numexpr-#1-\xint_c_viii\expandafter.\XINT_keepunbr_loop_pickeight |
| 20973 |
{\csname XINT_keepunbr_end#1\endcsname}% |
| 20974 |
\long\expandafter\def\csname XINT_keepunbr_end1\endcsname |
| 20975 |
#1#2#3#4#5#6#7#8#9\xint_bye { #1#2#3#4#5#6#7#8}% |
| 20976 |
\long\expandafter\def\csname XINT_keepunbr_end2\endcsname |
| 20977 |
#1#2#3#4#5#6#7#8\xint_bye { #1#2#3#4#5#6#7}% |
| 20978 |
\long\expandafter\def\csname XINT_keepunbr_end3\endcsname |
| 20979 |
#1#2#3#4#5#6#7\xint_bye { #1#2#3#4#5#6}% |
| 20980 |
\long\expandafter\def\csname XINT_keepunbr_end4\endcsname |
| 20981 |
#1#2#3#4#5#6\xint_bye { #1#2#3#4#5}% |
| 20982 |
\long\expandafter\def\csname XINT_keepunbr_end5\endcsname |
| 20983 |
#1#2#3#4#5\xint_bye { #1#2#3#4}% |
| 20984 |
\long\expandafter\def\csname XINT_keepunbr_end6\endcsname |
| 20985 |
#1#2#3#4\xint_bye { #1#2#3}% |
| 20986 |
\long\expandafter\def\csname XINT_keepunbr_end7\endcsname |
| 20987 |
#1#2#3\xint_bye { #1#2}% |
| 20988 |
\long\expandafter\def\csname XINT_keepunbr_end8\endcsname |
| 20989 |
#1#2\xint_bye { #1}% |
| 20990 |
% \end{macrocode} |
| 20991 |
% \subsection{\csh{xintTrim}} |
| 20992 |
% \added{1.09m} |
| 20993 |
%\begin{lverb} |
| 20994 |
% \xintTrim{i}{L} f-expands its second argument L. It then removes the first i |
| 20995 |
% items from L and keeps the rest. For i equal or larger to the number N of |
| 20996 |
% items in (expanded) L, the macro returns an empty output. For i=0, the |
| 20997 |
% original (expanded) L is returned. For i<0, the macro proceeds from the |
| 20998 |
% tail. It thus removes the last |i| items, i.e. it keeps the first N-|i| |
| 20999 |
% items. For |i|>= N, the empty list is returned. |
| 21000 |
% |
| 21001 |
% \xintTrimNoExpand does not expand the L argument. |
| 21002 |
%\end{lverb} |
| 21003 |
% \changed{1.2i} |
| 21004 |
%\begin{lverb} |
| 21005 |
% Speed improvements for i<0 branch (which hands over to |
| 21006 |
% \xintKeep). Speed improvements with 1.2j for i>0 branch which gobbles items |
| 21007 |
% nine by nine despite not knowing in advance if it will go too far. |
| 21008 |
%\end{lverb} |
| 21009 |
% \begin{macrocode} |
| 21010 |
\def\xintTrim {\romannumeral0\xinttrim }% |
| 21011 |
\def\xintTrimNoExpand {\romannumeral0\xinttrimnoexpand }% |
| 21012 |
\long\def\xinttrim #1#2{\expandafter\XINT_trim_a\the\numexpr #1\expandafter.% |
| 21013 |
\expandafter{\romannumeral`&&@#2}}% |
| 21014 |
\def\xinttrimnoexpand #1{\expandafter\XINT_trim_a\the\numexpr #1.}% |
| 21015 |
\def\XINT_trim_a #1% |
| 21016 |
{% |
| 21017 |
\xint_UDzerominusfork |
| 21018 |
#1-\XINT_trim_trimnone |
| 21019 |
0#1\XINT_trim_neg |
| 21020 |
0-{\XINT_trim_pos #1}% |
| 21021 |
\krof |
| 21022 |
}% |
| 21023 |
\long\def\XINT_trim_trimnone .#1{ #1}% |
| 21024 |
\long\def\XINT_trim_neg #1.#2% |
| 21025 |
{% |
| 21026 |
\expandafter\XINT_trim_neg_a\the\numexpr |
| 21027 |
#1-\numexpr\XINT_length_loop |
| 21028 |
#2\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint: |
| 21029 |
\xint_c_viii\xint_c_vii\xint_c_vi\xint_c_v |
| 21030 |
\xint_c_iv\xint_c_iii\xint_c_ii\xint_c_i\xint_c_\xint_bye |
| 21031 |
.{}#2\xint_bye |
| 21032 |
}% |
| 21033 |
\def\XINT_trim_neg_a #1% |
| 21034 |
{% |
| 21035 |
\xint_UDsignfork |
| 21036 |
#1{\expandafter\XINT_keep_loop\the\numexpr-\xint_c_viii+}% |
| 21037 |
-\XINT_trim_trimall |
| 21038 |
\krof |
| 21039 |
}% |
| 21040 |
\def\XINT_trim_trimall#1{% |
| 21041 |
\def\XINT_trim_trimall {\expandafter#1\xint_bye}% |
| 21042 |
}\XINT_trim_trimall{ }% |
| 21043 |
% \end{macrocode} |
| 21044 |
%\begin{lverb} |
| 21045 |
% This branch doesn't pre-evaluate the length of the list argument. |
| 21046 |
% Redone again for 1.2j, manages to trim nine by nine. Some non optimal |
| 21047 |
% looking aspect of the code is for allowing sharing with \xintNthElt. |
| 21048 |
%\end{lverb} |
| 21049 |
% \begin{macrocode} |
| 21050 |
\long\def\XINT_trim_pos #1.#2% |
| 21051 |
{% |
| 21052 |
\expandafter\XINT_trim_pos_done\expandafter\space |
| 21053 |
\romannumeral0\expandafter\XINT_trim_loop\the\numexpr#1-\xint_c_ix.% |
| 21054 |
#2\xint:\xint:\xint:\xint:\xint:% |
| 21055 |
\xint:\xint:\xint:\xint:\xint:% |
| 21056 |
\xint_bye |
| 21057 |
}% |
| 21058 |
\def\XINT_trim_loop #1#2.% |
| 21059 |
{% |
| 21060 |
\xint_gob_til_minus#1\XINT_trim_finish-% |
| 21061 |
\expandafter\XINT_trim_loop\the\numexpr#1#2\XINT_trim_loop_trimnine |
| 21062 |
}% |
| 21063 |
\long\def\XINT_trim_loop_trimnine #1#2#3#4#5#6#7#8#9% |
| 21064 |
{% |
| 21065 |
\xint_gob_til_xint: #9\XINT_trim_toofew\xint:-\xint_c_ix.% |
| 21066 |
}% |
| 21067 |
\def\XINT_trim_toofew\xint:{*\xint_c_}% |
| 21068 |
\def\XINT_trim_finish#1{% |
| 21069 |
\def\XINT_trim_finish-% |
| 21070 |
\expandafter\XINT_trim_loop\the\numexpr-##1\XINT_trim_loop_trimnine |
| 21071 |
{% |
| 21072 |
\expandafter\expandafter\expandafter#1% |
| 21073 |
\csname xint_gobble_\romannumeral\numexpr\xint_c_ix-##1\endcsname |
| 21074 |
}}\XINT_trim_finish{ }% |
| 21075 |
\long\def\XINT_trim_pos_done #1\xint:#2\xint_bye {#1}% |
| 21076 |
% \end{macrocode} |
| 21077 |
% \subsection{\csh{xintTrimUnbraced}} |
| 21078 |
% \added{1.2a} |
| 21079 |
% \changed{1.2i} As |\xintTrim|. |
| 21080 |
% \begin{macrocode} |
| 21081 |
\def\xintTrimUnbraced {\romannumeral0\xinttrimunbraced }% |
| 21082 |
\def\xintTrimUnbracedNoExpand {\romannumeral0\xinttrimunbracednoexpand }% |
| 21083 |
\long\def\xinttrimunbraced #1#2% |
| 21084 |
{\expandafter\XINT_trimunbr_a\the\numexpr #1\expandafter.% |
| 21085 |
\expandafter{\romannumeral`&&@#2}}% |
| 21086 |
\def\xinttrimunbracednoexpand #1% |
| 21087 |
{\expandafter\XINT_trimunbr_a\the\numexpr #1.}% |
| 21088 |
\def\XINT_trimunbr_a #1% |
| 21089 |
{% |
| 21090 |
\xint_UDzerominusfork |
| 21091 |
#1-\XINT_trim_trimnone |
| 21092 |
0#1\XINT_trimunbr_neg |
| 21093 |
0-{\XINT_trim_pos #1}% |
| 21094 |
\krof |
| 21095 |
}% |
| 21096 |
\long\def\XINT_trimunbr_neg #1.#2% |
| 21097 |
{% |
| 21098 |
\expandafter\XINT_trimunbr_neg_a\the\numexpr |
| 21099 |
#1-\numexpr\XINT_length_loop |
| 21100 |
#2\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint: |
| 21101 |
\xint_c_viii\xint_c_vii\xint_c_vi\xint_c_v |
| 21102 |
\xint_c_iv\xint_c_iii\xint_c_ii\xint_c_i\xint_c_\xint_bye |
| 21103 |
.{}#2\xint_bye |
| 21104 |
}% |
| 21105 |
\def\XINT_trimunbr_neg_a #1% |
| 21106 |
{% |
| 21107 |
\xint_UDsignfork |
| 21108 |
#1{\expandafter\XINT_keepunbr_loop\the\numexpr-\xint_c_viii+}% |
| 21109 |
-\XINT_trim_trimall |
| 21110 |
\krof |
| 21111 |
}% |
| 21112 |
% \end{macrocode} |
| 21113 |
% \subsection{\csh{xintApply}} |
| 21114 |
% \added{1.04} |
| 21115 |
%\begin{lverb} |
| 21116 |
% \xintApply {\macro}{{a}{b}...{z}} returns {\macro{a}}...{\macro{b}} |
| 21117 |
% where each instance of \macro is f-expanded. The list itself is first |
| 21118 |
% f-expanded and may thus be a macro. |
| 21119 |
%\end{lverb} |
| 21120 |
% \begin{macrocode} |
| 21121 |
\def\xintApply {\romannumeral0\xintapply }% |
| 21122 |
\def\xintApplyNoExpand {\romannumeral0\xintapplynoexpand }% |
| 21123 |
\long\def\xintapply #1#2% |
| 21124 |
{% |
| 21125 |
\expandafter\XINT_apply\expandafter {\romannumeral`&&@#2}% |
| 21126 |
{#1}% |
| 21127 |
}% |
| 21128 |
\long\def\XINT_apply #1#2{\XINT_apply_loop_a {}{#2}#1\xint_bye }% |
| 21129 |
\long\def\xintapplynoexpand #1#2{\XINT_apply_loop_a {}{#1}#2\xint_bye }% |
| 21130 |
\long\def\XINT_apply_loop_a #1#2#3% |
| 21131 |
{% |
| 21132 |
\xint_bye #3\XINT_apply_end\xint_bye |
| 21133 |
\expandafter |
| 21134 |
\XINT_apply_loop_b |
| 21135 |
\expandafter {\romannumeral`&&@#2{#3}}{#1}{#2}% |
| 21136 |
}% |
| 21137 |
\long\def\XINT_apply_loop_b #1#2{\XINT_apply_loop_a {#2{#1}}}% |
| 21138 |
\long\def\XINT_apply_end\xint_bye\expandafter\XINT_apply_loop_b |
| 21139 |
\expandafter #1#2#3{ #2}% |
| 21140 |
% \end{macrocode} |
| 21141 |
% \subsection{\csh{xintApply:x} (WIP, commented-out)} |
| 21142 |
% \added[2020/01/27]{1.4} |
| 21143 |
%\begin{lverb} |
| 21144 |
% For usage in the NumPy-like slicing |
| 21145 |
% routines. Well, actually, in the end I sticked with old-fashioned (quadratic |
| 21146 |
% cost) \xintApply for 1.4 2020/01/31 release. See comments there. |
| 21147 |
% |
| 21148 |
% (Comments mainly from 2020/01/27, but on 2020/02/24 I comment out |
| 21149 |
% the code and add an alternative) |
| 21150 |
% |
| 21151 |
% To expand in \expanded context, and does not need to |
| 21152 |
% do any expansion of its second argument. |
| 21153 |
% |
| 21154 |
% This uses techniques I had developed for 1.2i/1.2j Keep, Trim, Length, |
| 21155 |
% LastItem like macros, and I should revamp venerable \xintApply probably too. |
| 21156 |
% But the latter f-expandability (if it does not have \expanded at disposal) |
| 21157 |
% complicates significantly matters as it has to store material and release at |
| 21158 |
% very end. |
| 21159 |
% |
| 21160 |
% Here it is simpler and I am doing it quickly as I really want to release |
| 21161 |
% 1.4. The \xint: token should not be located in looped over items. I could |
| 21162 |
% use something more exotic like the null char with catcode 3... |
| 21163 |
% |
| 21164 |
%( \long\def\xintApply:x #1#2$% |
| 21165 |
%: {$% |
| 21166 |
%: \XINT_apply:x_loop {#1}#2$% |
| 21167 |
%: {\xint:\XINT_apply:x_loop_enda}{\xint:\XINT_apply:x_loop_endb}$% |
| 21168 |
%: {\xint:\XINT_apply:x_loop_endc}{\xint:\XINT_apply:x_loop_endd}$% |
| 21169 |
%: {\xint:\XINT_apply:x_loop_ende}{\xint:\XINT_apply:x_loop_endf}$% |
| 21170 |
%: {\xint:\XINT_apply:x_loop_endg}{\xint:\XINT_apply:x_loop_endh}\xint_bye |
| 21171 |
%: }$% |
| 21172 |
%: \long\def\XINT_apply:x_loop #1#2#3#4#5#6#7#8#9$% |
| 21173 |
%: {$% |
| 21174 |
%: \xint_gob_til_xint: #9\xint: |
| 21175 |
%: {#1{#2}}{#1{#3}}{#1{#4}}{#1{#5}}{#1{#6}}{#1{#7}}{#1{#8}}{#1{#9}}$% |
| 21176 |
%: \XINT_apply:x_loop {#1}$% |
| 21177 |
%: }$% |
| 21178 |
%: \long\def\XINT_apply:x_loop_endh\xint: #1\xint_bye{}$% |
| 21179 |
%: \long\def\XINT_apply:x_loop_endg\xint: #1#2\xint_bye{{#1}}$% |
| 21180 |
%: \long\def\XINT_apply:x_loop_endf\xint: #1#2#3\xint_bye{{#1}{#2}}$% |
| 21181 |
%: \long\def\XINT_apply:x_loop_ende\xint: #1#2#3#4\xint_bye{{#1}{#2}{#3}}$% |
| 21182 |
%: \long\def\XINT_apply:x_loop_endd\xint: #1#2#3#4#5\xint_bye{{#1}{#2}{#3}{#4}}$% |
| 21183 |
%: \long\def\XINT_apply:x_loop_endc\xint: #1#2#3#4#5#6\xint_bye{{#1}{#2}{#3}{#4}{#5}}$% |
| 21184 |
%: \long\def\XINT_apply:x_loop_endb\xint: #1#2#3#4#5#6#7\xint_bye{{#1}{#2}{#3}{#4}{#5}{#6}}$% |
| 21185 |
%: \long\def\XINT_apply:x_loop_enda\xint: #1#2#3#4#5#6#7#8\xint_bye{{#1}{#2}{#3}{#4}{#5}{#6}{#7}}$% |
| 21186 |
%) |
| 21187 |
% |
| 21188 |
% For small number of items gain with respect to \xintApply is little if any |
| 21189 |
% (might even be a loss). |
| 21190 |
% |
| 21191 |
% Picking one by one is possibly better for small number of items. Like |
| 21192 |
% this for example, the natural simple minded thing: |
| 21193 |
% |
| 21194 |
%(\long\def\xintApply:x #1#2$% |
| 21195 |
%: {$% |
| 21196 |
%: \XINT_apply:x_loop {#1}#2\xint_bye\xint_bye |
| 21197 |
%: }$% |
| 21198 |
%: \long\def\XINT_apply:x_loop #1#2$% |
| 21199 |
%: {$% |
| 21200 |
%: \xint_bye #2\xint_bye {#1{#2}}$% |
| 21201 |
%: \XINT_apply:x_loop {#1}$% |
| 21202 |
%: }$% |
| 21203 |
%) |
| 21204 |
% |
| 21205 |
% Some variant on 2020/02/24 |
| 21206 |
% |
| 21207 |
%( \long\def\xint_Bbye#1\xint_Bye{}$% |
| 21208 |
%: \long\def\xintApply:x #1#2$% |
| 21209 |
%: {$% |
| 21210 |
%: \XINT_apply:x_loop {#1}#2$% |
| 21211 |
%: {\xint_bye}{\xint_bye}{\xint_bye}{\xint_bye}$% |
| 21212 |
%: {\xint_bye}{\xint_bye}{\xint_bye}{\xint_bye}\xint_bye |
| 21213 |
%: }$% |
| 21214 |
%: \long\def\XINT_apply:x_loop #1#2#3#4#5#6#7#8#9$% |
| 21215 |
%: {$% |
| 21216 |
%: \xint_Bye #2\xint_bye {#1{#2}}$% |
| 21217 |
%: \xint_Bye #3\xint_bye {#1{#3}}$% |
| 21218 |
%: \xint_Bye #4\xint_bye {#1{#4}}$% |
| 21219 |
%: \xint_Bye #5\xint_bye {#1{#5}}$% |
| 21220 |
%: \xint_Bye #6\xint_bye {#1{#6}}$% |
| 21221 |
%: \xint_Bye #7\xint_bye {#1{#7}}$% |
| 21222 |
%: \xint_Bye #8\xint_bye {#1{#8}}$% |
| 21223 |
%: \xint_Bye #9\xint_bye {#1{#9}}$% |
| 21224 |
%: \XINT_apply:x_loop {#1}$% |
| 21225 |
%: }$% |
| 21226 |
%) |
| 21227 |
%\end{lverb} |
| 21228 |
% \subsection{\csh{xintApplyUnbraced}} |
| 21229 |
% \added{1.06b} |
| 21230 |
%\begin{lverb} |
| 21231 |
% \xintApplyUnbraced {\macro}{{a}{b}...{z}} returns \macro{a}...\macro{z} |
| 21232 |
% where each instance of \macro is f-expanded using \romannumeral-`0. The second |
| 21233 |
% argument may be a macro as it is itself also f-expanded. No braces |
| 21234 |
% are added: this allows for example a non-expandable \def in \macro, without |
| 21235 |
% having to do \gdef. |
| 21236 |
%\end{lverb} |
| 21237 |
% \begin{macrocode} |
| 21238 |
\def\xintApplyUnbraced {\romannumeral0\xintapplyunbraced }% |
| 21239 |
\def\xintApplyUnbracedNoExpand {\romannumeral0\xintapplyunbracednoexpand }% |
| 21240 |
\long\def\xintapplyunbraced #1#2% |
| 21241 |
{% |
| 21242 |
\expandafter\XINT_applyunbr\expandafter {\romannumeral`&&@#2}% |
| 21243 |
{#1}% |
| 21244 |
}% |
| 21245 |
\long\def\XINT_applyunbr #1#2{\XINT_applyunbr_loop_a {}{#2}#1\xint_bye }% |
| 21246 |
\long\def\xintapplyunbracednoexpand #1#2% |
| 21247 |
{\XINT_applyunbr_loop_a {}{#1}#2\xint_bye }% |
| 21248 |
\long\def\XINT_applyunbr_loop_a #1#2#3% |
| 21249 |
{% |
| 21250 |
\xint_bye #3\XINT_applyunbr_end\xint_bye |
| 21251 |
\expandafter\XINT_applyunbr_loop_b |
| 21252 |
\expandafter {\romannumeral`&&@#2{#3}}{#1}{#2}% |
| 21253 |
}% |
| 21254 |
\long\def\XINT_applyunbr_loop_b #1#2{\XINT_applyunbr_loop_a {#2#1}}% |
| 21255 |
\long\def\XINT_applyunbr_end\xint_bye\expandafter\XINT_applyunbr_loop_b |
| 21256 |
\expandafter #1#2#3{ #2}% |
| 21257 |
% \end{macrocode} |
| 21258 |
% \subsection{\csh{xintApplyUnbraced:x} (WIP, commented-out)} |
| 21259 |
% \added[2020/01/27]{1.4} |
| 21260 |
%\begin{lverb} |
| 21261 |
% For usage in the NumPy-like slicing |
| 21262 |
% routines. |
| 21263 |
% |
| 21264 |
% The items should not contain \xint: and the applied macro should not contain |
| 21265 |
% \empty. |
| 21266 |
% |
| 21267 |
% Finally, xintexpr.sty 1.4 code did not use this macro but the f-expandable |
| 21268 |
% one \xintApplyUnbraced. |
| 21269 |
%\end{lverb} |
| 21270 |
% \changed{1.4b} |
| 21271 |
%\begin{lverb} |
| 21272 |
% For 1.4b I prefer to keep the \xintApplyUnbraced:x code commented out, |
| 21273 |
% and classify it as WIP. |
| 21274 |
%( \long\def\xintApplyUnbraced:x #1#2$% |
| 21275 |
%: {$% |
| 21276 |
%: \XINT_applyunbraced:x_loop {#1}#2$% |
| 21277 |
%: {\xint:\XINT_applyunbraced:x_loop_enda}{\xint:\XINT_applyunbraced:x_loop_endb}$% |
| 21278 |
%: {\xint:\XINT_applyunbraced:x_loop_endc}{\xint:\XINT_applyunbraced:x_loop_endd}$% |
| 21279 |
%: {\xint:\XINT_applyunbraced:x_loop_ende}{\xint:\XINT_applyunbraced:x_loop_endf}$% |
| 21280 |
%: {\xint:\XINT_applyunbraced:x_loop_endg}{\xint:\XINT_applyunbraced:x_loop_endh}\xint_bye |
| 21281 |
%: }$% |
| 21282 |
%: \long\def\XINT_applyunbraced:x_loop #1#2#3#4#5#6#7#8#9$% |
| 21283 |
%: {$% |
| 21284 |
%: \xint_gob_til_xint: #9\xint: |
| 21285 |
%: #1{#2}$% |
| 21286 |
%: \empty#1{#3}$% |
| 21287 |
%: \empty#1{#4}$% |
| 21288 |
%: \empty#1{#5}$% |
| 21289 |
%: \empty#1{#6}$% |
| 21290 |
%: \empty#1{#7}$% |
| 21291 |
%: \empty#1{#8}$% |
| 21292 |
%: \empty#1{#9}$% |
| 21293 |
%: \XINT_applyunbraced:x_loop {#1}$% |
| 21294 |
%: }$% |
| 21295 |
%: \long\def\XINT_applyunbraced:x_loop_endh\xint: #1\xint_bye{}$% |
| 21296 |
%: \long\def\XINT_applyunbraced:x_loop_endg\xint: #1\empty#2\xint_bye{#1}$% |
| 21297 |
%: \long\def\XINT_applyunbraced:x_loop_endf\xint: #1\empty |
| 21298 |
%: #2\empty#3\xint_bye{#1#2}$% |
| 21299 |
%: \long\def\XINT_applyunbraced:x_loop_ende\xint: #1\empty |
| 21300 |
%: #2\empty |
| 21301 |
%: #3\empty#4\xint_bye{#1#2#3}$% |
| 21302 |
%: \long\def\XINT_applyunbraced:x_loop_endd\xint: #1\empty |
| 21303 |
%: #2\empty |
| 21304 |
%: #3\empty |
| 21305 |
%: #4\empty#5\xint_bye{#1#2#3#4}$% |
| 21306 |
%: \long\def\XINT_applyunbraced:x_loop_endc\xint: #1\empty |
| 21307 |
%: #2\empty |
| 21308 |
%: #3\empty |
| 21309 |
%: #4\empty |
| 21310 |
%: #5\empty#6\xint_bye{#1#2#3#4#5}$% |
| 21311 |
%: \long\def\XINT_applyunbraced:x_loop_endb\xint: #1\empty |
| 21312 |
%: #2\empty |
| 21313 |
%: #3\empty |
| 21314 |
%: #4\empty |
| 21315 |
%: #5\empty |
| 21316 |
%: #6\empty#7\xint_bye{#1#2#3#4#5#6}$% |
| 21317 |
%: \long\def\XINT_applyunbraced:x_loop_enda\xint: #1\empty |
| 21318 |
%: #2\empty |
| 21319 |
%: #3\empty |
| 21320 |
%: #4\empty |
| 21321 |
%: #5\empty |
| 21322 |
%: #6\empty |
| 21323 |
%: #7\empty#8\xint_bye{#1#2#3#4#5#6#7}$% |
| 21324 |
%) |
| 21325 |
%\end{lverb} |
| 21326 |
% \subsection{\csh{xintZip} (WIP, not public)} |
| 21327 |
% \added[2020/02/25]{1.4b} |
| 21328 |
%\begin{lverb} |
| 21329 |
% Support for zip(). Requires \expanded. |
| 21330 |
% |
| 21331 |
% The implementation here thus considers the argument is already completely |
| 21332 |
% expanded and is a sequence of nut-ples. I will come back at later date for |
| 21333 |
% more generic macros. |
| 21334 |
% |
| 21335 |
% Consider even the name of the function zip() as WIP. |
| 21336 |
% |
| 21337 |
% As per what this does, it imitates the zip() function. See xint-manual.pdf. |
| 21338 |
% |
| 21339 |
% I use lame terminators. Will think again later on this. I have to be careful |
| 21340 |
% with the used terminators, in particular with the NE context in mind. |
| 21341 |
% |
| 21342 |
% Generally speaking I will think another day about efficiency else I will |
| 21343 |
% never start this. |
| 21344 |
% |
| 21345 |
% OK, done. More compact than I initially thought. Various things should be |
| 21346 |
% commented upon here. Well, actually not so compact in the end as I basically |
| 21347 |
% had to double the whole thing simply to avoid the overhead of having to grab |
| 21348 |
% the final result delimited by some |
| 21349 |
% \xint_bye\xint_bye\xint_bye\xint_bye\empty terminator. Now actually rather |
| 21350 |
% \xint_bye\xint_bye\xint_bye\xint_bye\xint: |
| 21351 |
%\end{lverb} |
| 21352 |
% \begin{macrocode} |
| 21353 |
\def\xintZip #1{\expanded\XINT_zip_A#1\xint_bye\xint_bye}% |
| 21354 |
\def\XINT_zip_A#1% |
| 21355 |
{% |
| 21356 |
\xint_bye#1{\expandafter}\xint_bye |
| 21357 |
\expanded{\xint_noxpd{\XINT_ziptwo_A |
| 21358 |
#1\xint_bye\xint_bye\xint_bye\xint_bye\xint:}\expandafter}% |
| 21359 |
\expanded\XINT_zip_a |
| 21360 |
}% |
| 21361 |
\def\XINT_zip_a#1% |
| 21362 |
{% |
| 21363 |
\xint_bye#1\XINT_zip_terminator\xint_bye |
| 21364 |
\expanded{\xint_noxpd{\XINT_ziptwo_a |
| 21365 |
#1\xint_bye\xint_bye\xint_bye\xint_bye\xint:}\expandafter}% |
| 21366 |
\expanded\XINT_zip_a |
| 21367 |
}% |
| 21368 |
\def\XINT_zip_terminator\xint_bye#1\xint_bye{{}\empty\empty\empty\empty\xint:}% |
| 21369 |
\def\XINT_ziptwo_a #1#2#3#4#5\xint:#6#7#8#9% |
| 21370 |
{% |
| 21371 |
\bgroup |
| 21372 |
\xint_bye #1\XINT_ziptwo_e \xint_bye |
| 21373 |
\xint_bye #6\XINT_ziptwo_e \xint_bye {{#1}#6}% |
| 21374 |
\xint_bye #2\XINT_ziptwo_e \xint_bye |
| 21375 |
\xint_bye #7\XINT_ziptwo_e \xint_bye {{#2}#7}% |
| 21376 |
\xint_bye #3\XINT_ziptwo_e \xint_bye |
| 21377 |
\xint_bye #8\XINT_ziptwo_e \xint_bye {{#3}#8}% |
| 21378 |
\xint_bye #4\XINT_ziptwo_e \xint_bye |
| 21379 |
\xint_bye #9\XINT_ziptwo_e \xint_bye {{#4}#9}% |
| 21380 |
% \end{macrocode} |
| 21381 |
%\begin{lverb} |
| 21382 |
% Attention here that #6 can very well deliver no tokens at all. But |
| 21383 |
% the \ifx will then do the expected thing. Only mentioning! |
| 21384 |
% |
| 21385 |
% By the way, the \xint_bye method means TeX needs to look into tokens |
| 21386 |
% but skipping braced groups. A conditional based method lets TeX look only |
| 21387 |
% at the start but then it has to find \else or \fi so here also it must looks |
| 21388 |
% at tokens, and actually goes into braced groups. But (written 2020/02/26) I |
| 21389 |
% never did serious testing comparing the two, and in xint I have usually |
| 21390 |
% preferred \xint_bye/\xint_gob_til_foo types of methods (they proved superior |
| 21391 |
% than \ifnum to check for 0000 in numerical core context for example, at the |
| 21392 |
% early days when xint used blocks of 4 digits, not 8), or usage of \if/\ifx |
| 21393 |
% only on single tokens, combined with some \xint_dothis/\xint_orthat syntax. |
| 21394 |
%\end{lverb} |
| 21395 |
% \begin{macrocode} |
| 21396 |
\ifx \empty#6\expandafter\XINT_zipone_a\fi |
| 21397 |
\XINT_ziptwo_b #5\xint: |
| 21398 |
}% |
| 21399 |
\def\XINT_zipone_a\XINT_ziptwo_b{\XINT_zipone_b}% |
| 21400 |
\def\XINT_ziptwo_b #1#2#3#4#5\xint:#6#7#8#9% |
| 21401 |
{% |
| 21402 |
\xint_bye #1\XINT_ziptwo_e \xint_bye |
| 21403 |
\xint_bye #6\XINT_ziptwo_e \xint_bye {{#1}#6}% |
| 21404 |
\xint_bye #2\XINT_ziptwo_e \xint_bye |
| 21405 |
\xint_bye #7\XINT_ziptwo_e \xint_bye {{#2}#7}% |
| 21406 |
\xint_bye #3\XINT_ziptwo_e \xint_bye |
| 21407 |
\xint_bye #8\XINT_ziptwo_e \xint_bye {{#3}#8}% |
| 21408 |
\xint_bye #4\XINT_ziptwo_e \xint_bye |
| 21409 |
\xint_bye #9\XINT_ziptwo_e \xint_bye {{#4}#9}% |
| 21410 |
\XINT_ziptwo_b #5\xint: |
| 21411 |
}% |
| 21412 |
\def\XINT_ziptwo_e #1\XINT_ziptwo_b #2\xint:#3\xint: |
| 21413 |
{\iffalse{\fi}\xint_bye\xint_bye\xint_bye\xint_bye\xint:}% |
| 21414 |
\def\XINT_zipone_b #1#2#3#4% |
| 21415 |
{% |
| 21416 |
\xint_bye #1\XINT_zipone_e \xint_bye {{#1}}% |
| 21417 |
\xint_bye #2\XINT_zipone_e \xint_bye {{#2}}% |
| 21418 |
\xint_bye #3\XINT_zipone_e \xint_bye {{#3}}% |
| 21419 |
\xint_bye #4\XINT_zipone_e \xint_bye {{#4}}% |
| 21420 |
\XINT_zipone_b |
| 21421 |
}% |
| 21422 |
\def\XINT_zipone_e #1\XINT_zipone_b #2\xint: |
| 21423 |
{\iffalse{\fi}\xint_bye\xint_bye\xint_bye\xint_bye\empty}% |
| 21424 |
\def\XINT_ziptwo_A #1#2#3#4#5\xint:#6#7#8#9% |
| 21425 |
{% |
| 21426 |
\bgroup |
| 21427 |
\xint_bye #1\XINT_ziptwo_end \xint_bye |
| 21428 |
\xint_bye #6\XINT_ziptwo_end \xint_bye {{#1}#6}% |
| 21429 |
\xint_bye #2\XINT_ziptwo_end \xint_bye |
| 21430 |
\xint_bye #7\XINT_ziptwo_end \xint_bye {{#2}#7}% |
| 21431 |
\xint_bye #3\XINT_ziptwo_end \xint_bye |
| 21432 |
\xint_bye #8\XINT_ziptwo_end \xint_bye {{#3}#8}% |
| 21433 |
\xint_bye #4\XINT_ziptwo_end \xint_bye |
| 21434 |
\xint_bye #9\XINT_ziptwo_end \xint_bye {{#4}#9}% |
| 21435 |
\ifx \empty#6\expandafter\XINT_zipone_A\fi |
| 21436 |
\XINT_ziptwo_B #5\xint: |
| 21437 |
}% |
| 21438 |
\def\XINT_zipone_A\XINT_ziptwo_B{\XINT_zipone_B}% |
| 21439 |
\def\XINT_ziptwo_B #1#2#3#4#5\xint:#6#7#8#9% |
| 21440 |
{% |
| 21441 |
\xint_bye #1\XINT_ziptwo_end \xint_bye |
| 21442 |
\xint_bye #6\XINT_ziptwo_end \xint_bye {{#1}#6}% |
| 21443 |
\xint_bye #2\XINT_ziptwo_end \xint_bye |
| 21444 |
\xint_bye #7\XINT_ziptwo_end \xint_bye {{#2}#7}% |
| 21445 |
\xint_bye #3\XINT_ziptwo_end \xint_bye |
| 21446 |
\xint_bye #8\XINT_ziptwo_end \xint_bye {{#3}#8}% |
| 21447 |
\xint_bye #4\XINT_ziptwo_end \xint_bye |
| 21448 |
\xint_bye #9\XINT_ziptwo_end \xint_bye {{#4}#9}% |
| 21449 |
\XINT_ziptwo_B #5\xint: |
| 21450 |
}% |
| 21451 |
\def\XINT_ziptwo_end #1\XINT_ziptwo_B #2\xint:#3\xint:{\iffalse{\fi}}% |
| 21452 |
\def\XINT_zipone_B #1#2#3#4% |
| 21453 |
{% |
| 21454 |
\xint_bye #1\XINT_zipone_end \xint_bye {{#1}}% |
| 21455 |
\xint_bye #2\XINT_zipone_end \xint_bye {{#2}}% |
| 21456 |
\xint_bye #3\XINT_zipone_end \xint_bye {{#3}}% |
| 21457 |
\xint_bye #4\XINT_zipone_end \xint_bye {{#4}}% |
| 21458 |
\XINT_zipone_B |
| 21459 |
}% |
| 21460 |
\def\XINT_zipone_end #1\XINT_zipone_B #2\xint:#3\xint:{\iffalse{\fi}}% |
| 21461 |
% \end{macrocode} |
| 21462 |
% \subsection{\csh{xintSeq}} |
| 21463 |
% \added{1.09c} |
| 21464 |
% Without the optional argument puts stress on the input stack, |
| 21465 |
% should not be used to generated thousands of terms then. |
| 21466 |
% |
| 21467 |
% \changed{1.4j} |
| 21468 |
% This venerable macro had a brace removal bug in case it produced a single |
| 21469 |
% number: |\xintSeq{10}{10}| expanded to |10| not |{10}|. When I looked at the |
| 21470 |
% code the bug looked almost deliberate to me, but reading the documentation |
| 21471 |
% (which I have not modified), the behaviour is really unexpected. And the |
| 21472 |
% variant with step parameter |\xintSeq[1]{10}{10}| did produce |{10}|, so |
| 21473 |
% yes, definitely it was a bug! |
| 21474 |
% |
| 21475 |
% I take this occasion to do some style (and perhaps efficiency) refactoring |
| 21476 |
% in the coding. I feel there is room for improvement, no time this time. |
| 21477 |
% And I don't touch the variant with step parameter. |
| 21478 |
% |
| 21479 |
% Memo: \xintexprnameimp has some variants, a priori on ultra quick look |
| 21480 |
% they do not look like having similar bug as this one had. |
| 21481 |
% \begin{macrocode} |
| 21482 |
\def\xintSeq {\romannumeral0\xintseq }% |
| 21483 |
\def\xintseq #1{\XINT_seq_chkopt #1\xint_bye }% |
| 21484 |
\def\XINT_seq_chkopt #1% |
| 21485 |
{% |
| 21486 |
\ifx [#1\expandafter\XINT_seq_opt |
| 21487 |
\else\expandafter\XINT_seq_noopt |
| 21488 |
\fi #1% |
| 21489 |
}% |
| 21490 |
\def\XINT_seq_noopt #1\xint_bye #2% |
| 21491 |
{% |
| 21492 |
\expandafter\XINT_seq |
| 21493 |
\the\numexpr#1\expandafter.\the\numexpr #2.% |
| 21494 |
}% |
| 21495 |
\def\XINT_seq #1.#2.% |
| 21496 |
{% |
| 21497 |
\ifnum #1=#2 \xint_dothis\XINT_seq_e\fi |
| 21498 |
\ifnum #2>#1 \xint_dothis\XINT_seq_pa\fi |
| 21499 |
\xint_orthat\XINT_seq_na |
| 21500 |
#2.{#1}{#2}% |
| 21501 |
}% |
| 21502 |
\def\XINT_seq_e#1.#2{}% |
| 21503 |
\def\XINT_seq_pa {\expandafter\XINT_seq_p\the\numexpr-\xint_c_i+}% |
| 21504 |
\def\XINT_seq_na {\expandafter\XINT_seq_n\the\numexpr\xint_c_i+}% |
| 21505 |
\def\XINT_seq_p #1.#2% |
| 21506 |
{% |
| 21507 |
\ifnum #1>#2 |
| 21508 |
\expandafter\XINT_seq_p\the |
| 21509 |
\else |
| 21510 |
\expandafter\XINT_seq_e |
| 21511 |
\fi |
| 21512 |
\numexpr #1-\xint_c_i.{#2}{#1}% |
| 21513 |
}% |
| 21514 |
\def\XINT_seq_n #1.#2% |
| 21515 |
{% |
| 21516 |
\ifnum #1<#2 |
| 21517 |
\expandafter\XINT_seq_n\the |
| 21518 |
\else |
| 21519 |
\expandafter\XINT_seq_e |
| 21520 |
\fi |
| 21521 |
\numexpr #1+\xint_c_i.{#2}{#1}% |
| 21522 |
}% |
| 21523 |
% \end{macrocode} |
| 21524 |
% Note at time of the |1.4j| bug fix : I definitely should improve this branch |
| 21525 |
% and diminish the number of expandafter's but no time this time. |
| 21526 |
% \begin{macrocode} |
| 21527 |
\def\XINT_seq_opt [\xint_bye #1]#2#3% |
| 21528 |
{% |
| 21529 |
\expandafter\XINT_seqo\expandafter |
| 21530 |
{\the\numexpr #2\expandafter}\expandafter |
| 21531 |
{\the\numexpr #3\expandafter}\expandafter |
| 21532 |
{\the\numexpr #1}% |
| 21533 |
}% |
| 21534 |
\def\XINT_seqo #1#2% |
| 21535 |
{% |
| 21536 |
\ifcase\ifnum #1=#2 0\else\ifnum #2>#1 1\else -1\fi\fi\space |
| 21537 |
\expandafter\XINT_seqo_a |
| 21538 |
\or |
| 21539 |
\expandafter\XINT_seqo_pa |
| 21540 |
\else |
| 21541 |
\expandafter\XINT_seqo_na |
| 21542 |
\fi |
| 21543 |
{#1}{#2}% |
| 21544 |
}% |
| 21545 |
\def\XINT_seqo_a #1#2#3{ {#1}}% |
| 21546 |
\def\XINT_seqo_o #1#2#3#4{ #4}% |
| 21547 |
\def\XINT_seqo_pa #1#2#3% |
| 21548 |
{% |
| 21549 |
\ifcase\ifnum #3=\xint_c_ 0\else\ifnum #3>\xint_c_ 1\else -1\fi\fi\space |
| 21550 |
\expandafter\XINT_seqo_o |
| 21551 |
\or |
| 21552 |
\expandafter\XINT_seqo_pb |
| 21553 |
\else |
| 21554 |
\xint_afterfi{\expandafter\space\xint_gobble_iv}% |
| 21555 |
\fi |
| 21556 |
{#1}{#2}{#3}{{#1}}% |
| 21557 |
}% |
| 21558 |
\def\XINT_seqo_pb #1#2#3% |
| 21559 |
{% |
| 21560 |
\expandafter\XINT_seqo_pc\expandafter{\the\numexpr #1+#3}{#2}{#3}% |
| 21561 |
}% |
| 21562 |
\def\XINT_seqo_pc #1#2% |
| 21563 |
{% |
| 21564 |
\ifnum #1>#2 |
| 21565 |
\expandafter\XINT_seqo_o |
| 21566 |
\else |
| 21567 |
\expandafter\XINT_seqo_pd |
| 21568 |
\fi |
| 21569 |
{#1}{#2}% |
| 21570 |
}% |
| 21571 |
\def\XINT_seqo_pd #1#2#3#4{\XINT_seqo_pb {#1}{#2}{#3}{#4{#1}}}% |
| 21572 |
\def\XINT_seqo_na #1#2#3% |
| 21573 |
{% |
| 21574 |
\ifcase\ifnum #3=\xint_c_ 0\else\ifnum #3>\xint_c_ 1\else -1\fi\fi\space |
| 21575 |
\expandafter\XINT_seqo_o |
| 21576 |
\or |
| 21577 |
\xint_afterfi{\expandafter\space\xint_gobble_iv}% |
| 21578 |
\else |
| 21579 |
\expandafter\XINT_seqo_nb |
| 21580 |
\fi |
| 21581 |
{#1}{#2}{#3}{{#1}}% |
| 21582 |
}% |
| 21583 |
\def\XINT_seqo_nb #1#2#3% |
| 21584 |
{% |
| 21585 |
\expandafter\XINT_seqo_nc\expandafter{\the\numexpr #1+#3}{#2}{#3}% |
| 21586 |
}% |
| 21587 |
\def\XINT_seqo_nc #1#2% |
| 21588 |
{% |
| 21589 |
\ifnum #1<#2 |
| 21590 |
\expandafter\XINT_seqo_o |
| 21591 |
\else |
| 21592 |
\expandafter\XINT_seqo_nd |
| 21593 |
\fi |
| 21594 |
{#1}{#2}% |
| 21595 |
}% |
| 21596 |
\def\XINT_seqo_nd #1#2#3#4{\XINT_seqo_nb {#1}{#2}{#3}{#4{#1}}}% |
| 21597 |
% \end{macrocode} |
| 21598 |
% \subsection{\csh{xintloop}, \csh{xintbreakloop}, \csh{xintbreakloopanddo}, |
| 21599 |
% \csh{xintloopskiptonext}} |
| 21600 |
% \added[2013/11/22]{1.09g} |
| 21601 |
% \changed{1.09h} Made |\long|. |
| 21602 |
% \begin{macrocode} |
| 21603 |
\long\def\xintloop #1#2\repeat {#1#2\xintloop_again\fi\xint_gobble_i {#1#2}}% |
| 21604 |
\long\def\xintloop_again\fi\xint_gobble_i #1{\fi |
| 21605 |
#1\xintloop_again\fi\xint_gobble_i {#1}}% |
| 21606 |
\long\def\xintbreakloop #1\xintloop_again\fi\xint_gobble_i #2{}% |
| 21607 |
\long\def\xintbreakloopanddo #1#2\xintloop_again\fi\xint_gobble_i #3{#1}% |
| 21608 |
\long\def\xintloopskiptonext #1\xintloop_again\fi\xint_gobble_i #2{% |
| 21609 |
#2\xintloop_again\fi\xint_gobble_i {#2}}% |
| 21610 |
% \end{macrocode} |
| 21611 |
% \subsection{\csh{xintiloop}, |
| 21612 |
% \csh{xintiloopindex}, |
| 21613 |
% \csh{xintbracediloopindex}, |
| 21614 |
% \csh{xintouteriloopindex}, |
| 21615 |
% \csh{xintbracedouteriloopindex}, |
| 21616 |
% \csh{xintbreakiloop}, |
| 21617 |
% \csh{xintbreakiloopanddo}, |
| 21618 |
% \csh{xintiloopskiptonext}, |
| 21619 |
% \csh{xintiloopskipandredo}} |
| 21620 |
% \added[2013/11/22]{1.09g} |
| 21621 |
% \changed{1.09h} Made |\long|. |
| 21622 |
% \added[2018/04/24]{1.3b} |
| 21623 |
% \myenquote{braced} variants. |
| 21624 |
% \begin{macrocode} |
| 21625 |
\def\xintiloop [#1+#2]{% |
| 21626 |
\expandafter\xintiloop_a\the\numexpr #1\expandafter.\the\numexpr #2.}% |
| 21627 |
\long\def\xintiloop_a #1.#2.#3#4\repeat{% |
| 21628 |
#3#4\xintiloop_again\fi\xint_gobble_iii {#1}{#2}{#3#4}}% |
| 21629 |
\def\xintiloop_again\fi\xint_gobble_iii #1#2{% |
| 21630 |
\fi\expandafter\xintiloop_again_b\the\numexpr#1+#2.#2.}% |
| 21631 |
\long\def\xintiloop_again_b #1.#2.#3{% |
| 21632 |
#3\xintiloop_again\fi\xint_gobble_iii {#1}{#2}{#3}}% |
| 21633 |
\long\def\xintbreakiloop #1\xintiloop_again\fi\xint_gobble_iii #2#3#4{}% |
| 21634 |
\long\def\xintbreakiloopanddo |
| 21635 |
#1.#2\xintiloop_again\fi\xint_gobble_iii #3#4#5{#1}% |
| 21636 |
\long\def\xintiloopindex #1\xintiloop_again\fi\xint_gobble_iii #2% |
| 21637 |
{#2#1\xintiloop_again\fi\xint_gobble_iii {#2}}% |
| 21638 |
\long\def\xintbracediloopindex #1\xintiloop_again\fi\xint_gobble_iii #2% |
| 21639 |
{{#2}#1\xintiloop_again\fi\xint_gobble_iii {#2}}% |
| 21640 |
\long\def\xintouteriloopindex #1\xintiloop_again |
| 21641 |
#2\xintiloop_again\fi\xint_gobble_iii #3% |
| 21642 |
{#3#1\xintiloop_again #2\xintiloop_again\fi\xint_gobble_iii {#3}}% |
| 21643 |
\long\def\xintbracedouteriloopindex #1\xintiloop_again |
| 21644 |
#2\xintiloop_again\fi\xint_gobble_iii #3% |
| 21645 |
{{#3}#1\xintiloop_again #2\xintiloop_again\fi\xint_gobble_iii {#3}}% |
| 21646 |
\long\def\xintiloopskiptonext #1\xintiloop_again\fi\xint_gobble_iii #2#3{% |
| 21647 |
\expandafter\xintiloop_again_b \the\numexpr#2+#3.#3.}% |
| 21648 |
\long\def\xintiloopskipandredo #1\xintiloop_again\fi\xint_gobble_iii #2#3#4{% |
| 21649 |
#4\xintiloop_again\fi\xint_gobble_iii {#2}{#3}{#4}}% |
| 21650 |
% \end{macrocode} |
| 21651 |
% \subsection{\csh{XINT_xflet}} |
| 21652 |
% \added[2013/10/29]{1.09e} |
| 21653 |
% We f-expand unbraced tokens and swallow arising |
| 21654 |
% space tokens until the dust settles. |
| 21655 |
% \begin{macrocode} |
| 21656 |
\def\XINT_xflet #1% |
| 21657 |
{% |
| 21658 |
\def\XINT_xflet_macro {#1}\XINT_xflet_zapsp |
| 21659 |
}% |
| 21660 |
\def\XINT_xflet_zapsp |
| 21661 |
{% |
| 21662 |
\expandafter\futurelet\expandafter\XINT_token |
| 21663 |
\expandafter\XINT_xflet_sp?\romannumeral`&&@% |
| 21664 |
}% |
| 21665 |
\def\XINT_xflet_sp? |
| 21666 |
{% |
| 21667 |
\ifx\XINT_token\XINT_sptoken |
| 21668 |
\expandafter\XINT_xflet_zapsp |
| 21669 |
\else\expandafter\XINT_xflet_zapspB |
| 21670 |
\fi |
| 21671 |
}% |
| 21672 |
\def\XINT_xflet_zapspB |
| 21673 |
{% |
| 21674 |
\expandafter\futurelet\expandafter\XINT_tokenB |
| 21675 |
\expandafter\XINT_xflet_spB?\romannumeral`&&@% |
| 21676 |
}% |
| 21677 |
\def\XINT_xflet_spB? |
| 21678 |
{% |
| 21679 |
\ifx\XINT_tokenB\XINT_sptoken |
| 21680 |
\expandafter\XINT_xflet_zapspB |
| 21681 |
\else\expandafter\XINT_xflet_eq? |
| 21682 |
\fi |
| 21683 |
}% |
| 21684 |
\def\XINT_xflet_eq? |
| 21685 |
{% |
| 21686 |
\ifx\XINT_token\XINT_tokenB |
| 21687 |
\expandafter\XINT_xflet_macro |
| 21688 |
\else\expandafter\XINT_xflet_zapsp |
| 21689 |
\fi |
| 21690 |
}% |
| 21691 |
% \end{macrocode} |
| 21692 |
% \subsection{\csh{xintApplyInline}} |
| 21693 |
% \added{1.09a} |
| 21694 |
%\begin{lverb} |
| 21695 |
% \xintApplyInline\macro{{a}{b}...{z}} has the same effect as |
| 21696 |
% executing \macro{a} and then applying again \xintApplyInline to the shortened |
| 21697 |
% list {{b}...{z}} until nothing is left. This is a non-expandable command |
| 21698 |
% which will result in quicker code than using \xintApplyUnbraced. It f-expands |
| 21699 |
% its second (list) argument first, which may thus be encapsulated in a macro. |
| 21700 |
%\end{lverb} |
| 21701 |
% \changed{1.09c} |
| 21702 |
% Rewritten. Nota bene: uses catcode 3 Z as privated list terminator. |
| 21703 |
% \begin{macrocode} |
| 21704 |
\catcode`Z 3 |
| 21705 |
\long\def\xintApplyInline #1#2% |
| 21706 |
{% |
| 21707 |
\long\expandafter\def\expandafter\XINT_inline_macro |
| 21708 |
\expandafter ##\expandafter 1\expandafter {#1{##1}}% |
| 21709 |
\XINT_xflet\XINT_inline_b #2Z% this Z has catcode 3 |
| 21710 |
}% |
| 21711 |
\def\XINT_inline_b |
| 21712 |
{% |
| 21713 |
\ifx\XINT_token Z\expandafter\xint_gobble_i |
| 21714 |
\else\expandafter\XINT_inline_d\fi |
| 21715 |
}% |
| 21716 |
\long\def\XINT_inline_d #1% |
| 21717 |
{% |
| 21718 |
\long\def\XINT_item{{#1}}\XINT_xflet\XINT_inline_e |
| 21719 |
}% |
| 21720 |
\def\XINT_inline_e |
| 21721 |
{% |
| 21722 |
\ifx\XINT_token Z\expandafter\XINT_inline_w |
| 21723 |
\else\expandafter\XINT_inline_f\fi |
| 21724 |
}% |
| 21725 |
\def\XINT_inline_f |
| 21726 |
{% |
| 21727 |
\expandafter\XINT_inline_g\expandafter{\XINT_inline_macro {##1}}% |
| 21728 |
}% |
| 21729 |
\long\def\XINT_inline_g #1% |
| 21730 |
{% |
| 21731 |
\expandafter\XINT_inline_macro\XINT_item |
| 21732 |
\long\def\XINT_inline_macro ##1{#1}\XINT_inline_d |
| 21733 |
}% |
| 21734 |
\def\XINT_inline_w #1% |
| 21735 |
{% |
| 21736 |
\expandafter\XINT_inline_macro\XINT_item |
| 21737 |
}% |
| 21738 |
% \end{macrocode} |
| 21739 |
% \subsection{\csh{xintFor}, \csh{xintFor*}, \csh{xintBreakFor}, \csh{xintBreakForAndDo}} |
| 21740 |
% \added[2013/10/09]{1.09c} |
| 21741 |
%\begin{lverb} |
| 21742 |
% A new kind of loop which uses macro parameters |
| 21743 |
% #1, #2, #3, #4 rather than macros; while not expandable it survives executing |
| 21744 |
% code closing groups, like what happens in an alignment with the $& character. |
| 21745 |
% When inserted in a macro for later use, the # character must be doubled. |
| 21746 |
% |
| 21747 |
% The non-star variant works on a csv list, which it expands once, the |
| 21748 |
% star variant works on a token list, which it (repeatedly) f-expands. |
| 21749 |
%\end{lverb} |
| 21750 |
% \changed{1.09e} |
| 21751 |
%\begin{lverb} |
| 21752 |
% Adds \XINT_forever with \xintintegers, \xintdimensions, \xintrationals |
| 21753 |
% and \xintBreakFor, \xintBreakForAndDo, \xintifForFirst, \xintifForLast. On |
| 21754 |
% this occasion \xint_firstoftwo and \xint_secondoftwo are made long. |
| 21755 |
%\end{lverb} |
| 21756 |
% \changed[2013/11/03]{1.09f} |
| 21757 |
%\begin{lverb} |
| 21758 |
% Rewrites large parts of \xintFor code in order to filter the comma |
| 21759 |
% separated list via \xintCSVtoList which gets rid of spaces. The #1 in |
| 21760 |
% \XINT_for_forever? has an initial space token which serves two purposes: |
| 21761 |
% preventing brace stripping, and stopping the expansion made by \xintcsvtolist. |
| 21762 |
% If the \XINT_forever branch is taken, the added space will not be a problem |
| 21763 |
% there. |
| 21764 |
% |
| 21765 |
% Now allows all macro parameters |
| 21766 |
% from #1 to #9 in \xintFor, \xintFor*, and \XINT_forever. |
| 21767 |
%\end{lverb} |
| 21768 |
% \changed{1.2i} |
| 21769 |
%\begin{lverb} |
| 21770 |
% Slightly more robust \xintifForFirst/Last in case of nesting. |
| 21771 |
%\end{lverb} |
| 21772 |
% \begin{macrocode} |
| 21773 |
\def\XINT_tmpa #1#2{\ifnum #2<#1 \xint_afterfi {{#########2}}\fi}% |
| 21774 |
\def\XINT_tmpb #1#2{\ifnum #1<#2 \xint_afterfi {{#########2}}\fi}% |
| 21775 |
\def\XINT_tmpc #1% |
| 21776 |
{% |
| 21777 |
\expandafter\edef \csname XINT_for_left#1\endcsname |
| 21778 |
{\xintApplyUnbraced {\XINT_tmpa #1}{123456789}}% |
| 21779 |
\expandafter\edef \csname XINT_for_right#1\endcsname |
| 21780 |
{\xintApplyUnbraced {\XINT_tmpb #1}{123456789}}% |
| 21781 |
}% |
| 21782 |
\xintApplyInline \XINT_tmpc {123456789}% |
| 21783 |
\long\def\xintBreakFor #1Z{}% |
| 21784 |
\long\def\xintBreakForAndDo #1#2Z{#1}% |
| 21785 |
\def\xintFor {\let\xintifForFirst\xint_firstoftwo |
| 21786 |
\let\xintifForLast\xint_secondoftwo |
| 21787 |
\futurelet\XINT_token\XINT_for_ifstar }% |
| 21788 |
\def\XINT_for_ifstar {\ifx\XINT_token*\expandafter\XINT_forx |
| 21789 |
\else\expandafter\XINT_for \fi }% |
| 21790 |
\catcode`U 3 % with numexpr |
| 21791 |
\catcode`V 3 % with xintfrac.sty (xint.sty not enough) |
| 21792 |
\catcode`D 3 % with dimexpr |
| 21793 |
\def\XINT_flet_zapsp |
| 21794 |
{% |
| 21795 |
\futurelet\XINT_token\XINT_flet_sp? |
| 21796 |
}% |
| 21797 |
\def\XINT_flet_sp? |
| 21798 |
{% |
| 21799 |
\ifx\XINT_token\XINT_sptoken |
| 21800 |
\xint_afterfi{\expandafter\XINT_flet_zapsp\romannumeral0}% |
| 21801 |
\else\expandafter\XINT_flet_macro |
| 21802 |
\fi |
| 21803 |
}% |
| 21804 |
\long\def\XINT_for #1#2in#3#4#5% |
| 21805 |
{% |
| 21806 |
\expandafter\XINT_toks\expandafter |
| 21807 |
{\expandafter\XINT_for_d\the\numexpr #2\relax {#5}}% |
| 21808 |
\def\XINT_flet_macro {\expandafter\XINT_for_forever?\space}% |
| 21809 |
\expandafter\XINT_flet_zapsp #3Z% |
| 21810 |
}% |
| 21811 |
\def\XINT_for_forever? #1Z% |
| 21812 |
{% |
| 21813 |
\ifx\XINT_token U\XINT_to_forever\fi |
| 21814 |
\ifx\XINT_token V\XINT_to_forever\fi |
| 21815 |
\ifx\XINT_token D\XINT_to_forever\fi |
| 21816 |
\expandafter\the\expandafter\XINT_toks\romannumeral0\xintcsvtolist {#1}Z% |
| 21817 |
}% |
| 21818 |
\def\XINT_to_forever\fi #1\xintcsvtolist #2{\fi \XINT_forever #2}% |
| 21819 |
\long\def\XINT_forx *#1#2in#3#4#5% |
| 21820 |
{% |
| 21821 |
\expandafter\XINT_toks\expandafter |
| 21822 |
{\expandafter\XINT_forx_d\the\numexpr #2\relax {#5}}% |
| 21823 |
\XINT_xflet\XINT_forx_forever? #3Z% |
| 21824 |
}% |
| 21825 |
\def\XINT_forx_forever? |
| 21826 |
{% |
| 21827 |
\ifx\XINT_token U\XINT_to_forxever\fi |
| 21828 |
\ifx\XINT_token V\XINT_to_forxever\fi |
| 21829 |
\ifx\XINT_token D\XINT_to_forxever\fi |
| 21830 |
\XINT_forx_empty? |
| 21831 |
}% |
| 21832 |
\def\XINT_to_forxever\fi #1\XINT_forx_empty? {\fi \XINT_forever }% |
| 21833 |
\catcode`U 11 |
| 21834 |
\catcode`D 11 |
| 21835 |
\catcode`V 11 |
| 21836 |
\def\XINT_forx_empty? |
| 21837 |
{% |
| 21838 |
\ifx\XINT_token Z\expandafter\xintBreakFor\fi |
| 21839 |
\the\XINT_toks |
| 21840 |
}% |
| 21841 |
\long\def\XINT_for_d #1#2#3% |
| 21842 |
{% |
| 21843 |
\long\def\XINT_y ##1##2##3##4##5##6##7##8##9{#2}% |
| 21844 |
\XINT_toks {{#3}}% |
| 21845 |
\long\edef\XINT_x {\noexpand\XINT_y \csname XINT_for_left#1\endcsname |
| 21846 |
\the\XINT_toks \csname XINT_for_right#1\endcsname }% |
| 21847 |
\XINT_toks {\XINT_x\let\xintifForFirst\xint_secondoftwo |
| 21848 |
\let\xintifForLast\xint_secondoftwo\XINT_for_d #1{#2}}% |
| 21849 |
\futurelet\XINT_token\XINT_for_last? |
| 21850 |
}% |
| 21851 |
\long\def\XINT_forx_d #1#2#3% |
| 21852 |
{% |
| 21853 |
\long\def\XINT_y ##1##2##3##4##5##6##7##8##9{#2}% |
| 21854 |
\XINT_toks {{#3}}% |
| 21855 |
\long\edef\XINT_x {\noexpand\XINT_y \csname XINT_for_left#1\endcsname |
| 21856 |
\the\XINT_toks \csname XINT_for_right#1\endcsname }% |
| 21857 |
\XINT_toks {\XINT_x\let\xintifForFirst\xint_secondoftwo |
| 21858 |
\let\xintifForLast\xint_secondoftwo\XINT_forx_d #1{#2}}% |
| 21859 |
\XINT_xflet\XINT_for_last? |
| 21860 |
}% |
| 21861 |
\def\XINT_for_last? |
| 21862 |
{% |
| 21863 |
\ifx\XINT_token Z\expandafter\XINT_for_last?yes\fi |
| 21864 |
\the\XINT_toks |
| 21865 |
}% |
| 21866 |
\def\XINT_for_last?yes |
| 21867 |
{% |
| 21868 |
\let\xintifForLast\xint_firstoftwo |
| 21869 |
\xintBreakForAndDo{\XINT_x\xint_gobble_i Z}% |
| 21870 |
}% |
| 21871 |
% \end{macrocode} |
| 21872 |
% \subsection{\csh{XINT_forever}, \csh{xintintegers}, \csh{xintdimensions}, \csh{xintrationals}} |
| 21873 |
% \added{1.09e} |
| 21874 |
%\begin{lverb} |
| 21875 |
% But this used inadvertently \xintiadd/\xintimul which |
| 21876 |
% have the unnecessary \xintnum overhead. |
| 21877 |
%\end{lverb} |
| 21878 |
% \changed{1.09f} |
| 21879 |
%\begin{lverb} |
| 21880 |
% Use |
| 21881 |
% \xintiiadd/\xintiimul which do not have this overhead. Also 1.09f uses |
| 21882 |
% \xintZapSpacesB for the \xintrationals case to get rid of leading and ending |
| 21883 |
% spaces in the #4 and #5 delimited parameters of \XINT_forever_opt_a |
| 21884 |
% (for \xintintegers and \xintdimensions this is not necessary, due to the use |
| 21885 |
% of \numexpr resp. \dimexpr in \XINT_?expr_Ua, resp.\XINT_?expr_Da). |
| 21886 |
%\end{lverb} |
| 21887 |
% \begin{macrocode} |
| 21888 |
\catcode`U 3 |
| 21889 |
\catcode`D 3 |
| 21890 |
\catcode`V 3 |
| 21891 |
\let\xintegers U% |
| 21892 |
\let\xintintegers U% |
| 21893 |
\let\xintdimensions D% |
| 21894 |
\let\xintrationals V% |
| 21895 |
\def\XINT_forever #1% |
| 21896 |
{% |
| 21897 |
\expandafter\XINT_forever_a |
| 21898 |
\csname XINT_?expr_\ifx#1UU\else\ifx#1DD\else V\fi\fi a\expandafter\endcsname |
| 21899 |
\csname XINT_?expr_\ifx#1UU\else\ifx#1DD\else V\fi\fi i\expandafter\endcsname |
| 21900 |
\csname XINT_?expr_\ifx#1UU\else\ifx#1DD\else V\fi\fi \endcsname |
| 21901 |
}% |
| 21902 |
\catcode`U 11 |
| 21903 |
\catcode`D 11 |
| 21904 |
\catcode`V 11 |
| 21905 |
\def\XINT_?expr_Ua #1#2% |
| 21906 |
{\expandafter{\expandafter\numexpr\the\numexpr #1\expandafter\relax |
| 21907 |
\expandafter\relax\expandafter}% |
| 21908 |
\expandafter{\the\numexpr #2}}% |
| 21909 |
\def\XINT_?expr_Da #1#2% |
| 21910 |
{\expandafter{\expandafter\dimexpr\number\dimexpr #1\expandafter\relax |
| 21911 |
\expandafter s\expandafter p\expandafter\relax\expandafter}% |
| 21912 |
\expandafter{\number\dimexpr #2}}% |
| 21913 |
\catcode`Z 11 |
| 21914 |
\def\XINT_?expr_Va #1#2% |
| 21915 |
{% |
| 21916 |
\expandafter\XINT_?expr_Vb\expandafter |
| 21917 |
{\romannumeral`&&@\xintrawwithzeros{\xintZapSpacesB{#2}}}% |
| 21918 |
{\romannumeral`&&@\xintrawwithzeros{\xintZapSpacesB{#1}}}% |
| 21919 |
}% |
| 21920 |
\catcode`Z 3 |
| 21921 |
\def\XINT_?expr_Vb #1#2{\expandafter\XINT_?expr_Vc #2.#1.}% |
| 21922 |
\def\XINT_?expr_Vc #1/#2.#3/#4.% |
| 21923 |
{% |
| 21924 |
\xintifEq {#2}{#4}% |
| 21925 |
{\XINT_?expr_Vf {#3}{#1}{#2}}% |
| 21926 |
{\expandafter\XINT_?expr_Vd\expandafter |
| 21927 |
{\romannumeral0\xintiimul {#2}{#4}}% |
| 21928 |
{\romannumeral0\xintiimul {#1}{#4}}% |
| 21929 |
{\romannumeral0\xintiimul {#2}{#3}}% |
| 21930 |
}% |
| 21931 |
}% |
| 21932 |
\def\XINT_?expr_Vd #1#2#3{\expandafter\XINT_?expr_Ve\expandafter {#2}{#3}{#1}}% |
| 21933 |
\def\XINT_?expr_Ve #1#2{\expandafter\XINT_?expr_Vf\expandafter {#2}{#1}}% |
| 21934 |
\def\XINT_?expr_Vf #1#2#3{{#2/#3}{{0}{#1}{#2}{#3}}}% |
| 21935 |
\def\XINT_?expr_Ui {{\numexpr 1\relax}{1}}% |
| 21936 |
\def\XINT_?expr_Di {{\dimexpr 0pt\relax}{65536}}% |
| 21937 |
\def\XINT_?expr_Vi {{1/1}{0111}}% |
| 21938 |
\def\XINT_?expr_U #1#2% |
| 21939 |
{\expandafter{\expandafter\numexpr\the\numexpr #1+#2\relax\relax}{#2}}% |
| 21940 |
\def\XINT_?expr_D #1#2% |
| 21941 |
{\expandafter{\expandafter\dimexpr\the\numexpr #1+#2\relax sp\relax}{#2}}% |
| 21942 |
\def\XINT_?expr_V #1#2{\XINT_?expr_Vx #2}% |
| 21943 |
\def\XINT_?expr_Vx #1#2% |
| 21944 |
{% |
| 21945 |
\expandafter\XINT_?expr_Vy\expandafter |
| 21946 |
{\romannumeral0\xintiiadd {#1}{#2}}{#2}% |
| 21947 |
}% |
| 21948 |
\def\XINT_?expr_Vy #1#2#3#4% |
| 21949 |
{% |
| 21950 |
\expandafter{\romannumeral0\xintiiadd {#3}{#1}/#4}{{#1}{#2}{#3}{#4}}% |
| 21951 |
}% |
| 21952 |
\def\XINT_forever_a #1#2#3#4% |
| 21953 |
{% |
| 21954 |
\ifx #4[\expandafter\XINT_forever_opt_a |
| 21955 |
\else\expandafter\XINT_forever_b |
| 21956 |
\fi #1#2#3#4% |
| 21957 |
}% |
| 21958 |
\def\XINT_forever_b #1#2#3Z{\expandafter\XINT_forever_c\the\XINT_toks #2#3}% |
| 21959 |
\long\def\XINT_forever_c #1#2#3#4#5% |
| 21960 |
{\expandafter\XINT_forever_d\expandafter #2#4#5{#3}Z}% |
| 21961 |
\def\XINT_forever_opt_a #1#2#3[#4+#5]#6Z% |
| 21962 |
{% |
| 21963 |
\expandafter\expandafter\expandafter |
| 21964 |
\XINT_forever_opt_c\expandafter\the\expandafter\XINT_toks |
| 21965 |
\romannumeral`&&@#1{#4}{#5}#3% |
| 21966 |
}% |
| 21967 |
\long\def\XINT_forever_opt_c #1#2#3#4#5#6{\XINT_forever_d #2{#4}{#5}#6{#3}Z}% |
| 21968 |
\long\def\XINT_forever_d #1#2#3#4#5% |
| 21969 |
{% |
| 21970 |
\long\def\XINT_y ##1##2##3##4##5##6##7##8##9{#5}% |
| 21971 |
\XINT_toks {{#2}}% |
| 21972 |
\long\edef\XINT_x {\noexpand\XINT_y \csname XINT_for_left#1\endcsname |
| 21973 |
\the\XINT_toks \csname XINT_for_right#1\endcsname }% |
| 21974 |
\XINT_x |
| 21975 |
\let\xintifForFirst\xint_secondoftwo |
| 21976 |
\let\xintifForLast\xint_secondoftwo |
| 21977 |
\expandafter\XINT_forever_d\expandafter #1\romannumeral`&&@#4{#2}{#3}#4{#5}% |
| 21978 |
}% |
| 21979 |
% \end{macrocode} |
| 21980 |
% \subsection{\csh{xintForpair}, \csh{xintForthree}, \csh{xintForfour}} |
| 21981 |
% \added{1.09c} |
| 21982 |
% \changed[2013/11/02]{1.09f} |
| 21983 |
%\begin{lverb} |
| 21984 |
% \xintForpair delegate to \xintCSVtoList and its |
| 21985 |
% \xintZapSpacesB the handling of spaces. Does not share code with \xintFor |
| 21986 |
% anymore. |
| 21987 |
% |
| 21988 |
% \xintForpair extended to accept #1#2, #2#3 etc... up to |
| 21989 |
% #8#9, \xintForthree, #1#2#3 up to #7#8#9, \xintForfour id. |
| 21990 |
%\end{lverb} |
| 21991 |
% \changed{1.2i} |
| 21992 |
%\begin{lverb} |
| 21993 |
% Slightly more robust \xintifForFirst/\xintifForLast in case of nesting. |
| 21994 |
%\end{lverb} |
| 21995 |
% \changed[2025/06/08]{1.4n} |
| 21996 |
%\begin{lverb} |
| 21997 |
% Allow one final extraneous comma (formerly, such input caused a crash). |
| 21998 |
% This goes via testing an extra token #6, which should be an opening parenthesis. |
| 21999 |
% The potential brace removal changes behavior for illegal inputs. |
| 22000 |
% Successive commas in the input list are still not allowed. |
| 22001 |
%\end{lverb} |
| 22002 |
% \begin{macrocode} |
| 22003 |
\catcode`j 3 |
| 22004 |
\long\def\xintForpair #1#2#3in#4#5#6% |
| 22005 |
{% |
| 22006 |
\let\xintifForFirst\xint_firstoftwo |
| 22007 |
\let\xintifForLast\xint_secondoftwo |
| 22008 |
\XINT_toks {\XINT_forpair_d #2{#6}}% |
| 22009 |
\expandafter\the\expandafter\XINT_toks #4jZ% |
| 22010 |
}% |
| 22011 |
\long\def\XINT_forpair_d #1#2#3(#4)#5#6% |
| 22012 |
{% |
| 22013 |
\long\def\XINT_y ##1##2##3##4##5##6##7##8##9{#2}% |
| 22014 |
\XINT_toks \expandafter{\romannumeral0\xintcsvtolist{ #4}}% |
| 22015 |
\long\edef\XINT_x {\noexpand\XINT_y \csname XINT_for_left#1\endcsname |
| 22016 |
\the\XINT_toks \csname XINT_for_right\the\numexpr#1+\xint_c_i\endcsname}% |
| 22017 |
\if1\ifx #5j1\else\ifx#6j1\else0\fi\fi\expandafter\XINT_for_last?yes\fi |
| 22018 |
\XINT_x |
| 22019 |
\let\xintifForFirst\xint_secondoftwo |
| 22020 |
\let\xintifForLast\xint_secondoftwo |
| 22021 |
\XINT_forpair_d #1{#2}#6% |
| 22022 |
}% |
| 22023 |
\long\def\xintForthree #1#2#3in#4#5#6% |
| 22024 |
{% |
| 22025 |
\let\xintifForFirst\xint_firstoftwo |
| 22026 |
\let\xintifForLast\xint_secondoftwo |
| 22027 |
\XINT_toks {\XINT_forthree_d #2{#6}}% |
| 22028 |
\expandafter\the\expandafter\XINT_toks #4jZ% |
| 22029 |
}% |
| 22030 |
\long\def\XINT_forthree_d #1#2#3(#4)#5#6% |
| 22031 |
{% |
| 22032 |
\long\def\XINT_y ##1##2##3##4##5##6##7##8##9{#2}% |
| 22033 |
\XINT_toks \expandafter{\romannumeral0\xintcsvtolist{ #4}}% |
| 22034 |
\long\edef\XINT_x {\noexpand\XINT_y \csname XINT_for_left#1\endcsname |
| 22035 |
\the\XINT_toks \csname XINT_for_right\the\numexpr#1+\xint_c_ii\endcsname}% |
| 22036 |
\if1\ifx #5j1\else\ifx#6j1\else0\fi\fi\expandafter\XINT_for_last?yes\fi |
| 22037 |
\XINT_x |
| 22038 |
\let\xintifForFirst\xint_secondoftwo |
| 22039 |
\let\xintifForLast\xint_secondoftwo |
| 22040 |
\XINT_forthree_d #1{#2}#6% |
| 22041 |
}% |
| 22042 |
\long\def\xintForfour #1#2#3in#4#5#6% |
| 22043 |
{% |
| 22044 |
\let\xintifForFirst\xint_firstoftwo |
| 22045 |
\let\xintifForLast\xint_secondoftwo |
| 22046 |
\XINT_toks {\XINT_forfour_d #2{#6}}% |
| 22047 |
\expandafter\the\expandafter\XINT_toks #4jZ% |
| 22048 |
}% |
| 22049 |
\long\def\XINT_forfour_d #1#2#3(#4)#5#6% |
| 22050 |
{% |
| 22051 |
\long\def\XINT_y ##1##2##3##4##5##6##7##8##9{#2}% |
| 22052 |
\XINT_toks \expandafter{\romannumeral0\xintcsvtolist{ #4}}% |
| 22053 |
\long\edef\XINT_x {\noexpand\XINT_y \csname XINT_for_left#1\endcsname |
| 22054 |
\the\XINT_toks \csname XINT_for_right\the\numexpr#1+\xint_c_iii\endcsname}% |
| 22055 |
\if1\ifx #5j1\else\ifx#6j1\else0\fi\fi\expandafter\XINT_for_last?yes\fi |
| 22056 |
\XINT_x |
| 22057 |
\let\xintifForFirst\xint_secondoftwo |
| 22058 |
\let\xintifForLast\xint_secondoftwo |
| 22059 |
\XINT_forfour_d #1{#2}#6% |
| 22060 |
}% |
| 22061 |
\catcode`Z 11 |
| 22062 |
\catcode`j 11 |
| 22063 |
% \end{macrocode} |
| 22064 |
% \subsection{\csh{xintAssign}, \csh{xintAssignArray}, \csh{xintDigitsOf}} |
| 22065 |
%\begin{lverb} |
| 22066 |
% \xintAssign {a}{b}..{z}\to\A\B...\Z resp. \xintAssignArray |
| 22067 |
% {a}{b}..{z}\to\U. |
| 22068 |
% |
| 22069 |
% \xintDigitsOf=\xintAssignArray. |
| 22070 |
%\end{lverb} |
| 22071 |
% \changed[2015/09/12]{1.1c} |
| 22072 |
%\begin{lverb} |
| 22073 |
% Belatedly corrects some "features" of |
| 22074 |
% \xintAssign which didn't like the case of a space right before the "\to", or |
| 22075 |
% the case with the first token not an opening brace and the subsequent |
| 22076 |
% material containing brace groups. The new code handles gracefully these |
| 22077 |
% situations. |
| 22078 |
%\end{lverb} |
| 22079 |
% \begin{macrocode} |
| 22080 |
\def\xintAssign{\def\XINT_flet_macro {\XINT_assign_fork}\XINT_flet_zapsp }% |
| 22081 |
\def\XINT_assign_fork |
| 22082 |
{% |
| 22083 |
\let\XINT_assign_def\def |
| 22084 |
\ifx\XINT_token[\expandafter\XINT_assign_opt |
| 22085 |
\else\expandafter\XINT_assign_a |
| 22086 |
\fi |
| 22087 |
}% |
| 22088 |
\def\XINT_assign_opt [#1]% |
| 22089 |
{% |
| 22090 |
\ifcsname #1def\endcsname |
| 22091 |
\expandafter\let\expandafter\XINT_assign_def \csname #1def\endcsname |
| 22092 |
\else |
| 22093 |
\expandafter\let\expandafter\XINT_assign_def \csname xint#1def\endcsname |
| 22094 |
\fi |
| 22095 |
\XINT_assign_a |
| 22096 |
}% |
| 22097 |
\long\def\XINT_assign_a #1\to |
| 22098 |
{% |
| 22099 |
\def\XINT_flet_macro{\XINT_assign_b}% |
| 22100 |
\expandafter\XINT_flet_zapsp\romannumeral`&&@#1\xint:\to |
| 22101 |
}% |
| 22102 |
\long\def\XINT_assign_b |
| 22103 |
{% |
| 22104 |
\ifx\XINT_token\bgroup |
| 22105 |
\expandafter\XINT_assign_c |
| 22106 |
\else\expandafter\XINT_assign_f |
| 22107 |
\fi |
| 22108 |
}% |
| 22109 |
\long\def\XINT_assign_f #1\xint:\to #2% |
| 22110 |
{% |
| 22111 |
\XINT_assign_def #2{#1}% |
| 22112 |
}% |
| 22113 |
\long\def\XINT_assign_c #1% |
| 22114 |
{% |
| 22115 |
\def\XINT_assign_tmp {#1}% |
| 22116 |
\ifx\XINT_assign_tmp\xint_bracedstopper |
| 22117 |
\expandafter\XINT_assign_e |
| 22118 |
\else |
| 22119 |
\expandafter\XINT_assign_d |
| 22120 |
\fi |
| 22121 |
}% |
| 22122 |
\long\def\XINT_assign_d #1\to #2% |
| 22123 |
{% |
| 22124 |
\expandafter\XINT_assign_def\expandafter #2\expandafter{\XINT_assign_tmp}% |
| 22125 |
\XINT_assign_c #1\to |
| 22126 |
}% |
| 22127 |
\def\XINT_assign_e #1\to {}% |
| 22128 |
\def\xintRelaxArray #1% |
| 22129 |
{% |
| 22130 |
\edef\XINT_restoreescapechar {\escapechar\the\escapechar\relax}% |
| 22131 |
\escapechar -1 |
| 22132 |
\expandafter\def\expandafter\xint_arrayname\expandafter {\string #1}% |
| 22133 |
\XINT_restoreescapechar |
| 22134 |
\xintiloop [\csname\xint_arrayname 0\endcsname+-1] |
| 22135 |
\global |
| 22136 |
\expandafter\let\csname\xint_arrayname\xintiloopindex\endcsname\relax |
| 22137 |
\ifnum \xintiloopindex > \xint_c_ |
| 22138 |
\repeat |
| 22139 |
\global\expandafter\let\csname\xint_arrayname 00\endcsname\relax |
| 22140 |
\global\let #1\relax |
| 22141 |
}% |
| 22142 |
\def\xintAssignArray{\def\XINT_flet_macro {\XINT_assignarray_fork}% |
| 22143 |
\XINT_flet_zapsp }% |
| 22144 |
\def\XINT_assignarray_fork |
| 22145 |
{% |
| 22146 |
\let\XINT_assignarray_def\def |
| 22147 |
\ifx\XINT_token[\expandafter\XINT_assignarray_opt |
| 22148 |
\else\expandafter\XINT_assignarray |
| 22149 |
\fi |
| 22150 |
}% |
| 22151 |
\def\XINT_assignarray_opt [#1]% |
| 22152 |
{% |
| 22153 |
\ifcsname #1def\endcsname |
| 22154 |
\expandafter\let\expandafter\XINT_assignarray_def \csname #1def\endcsname |
| 22155 |
\else |
| 22156 |
\expandafter\let\expandafter\XINT_assignarray_def |
| 22157 |
\csname xint#1def\endcsname |
| 22158 |
\fi |
| 22159 |
\XINT_assignarray |
| 22160 |
}% |
| 22161 |
\long\def\XINT_assignarray #1\to #2% |
| 22162 |
{% |
| 22163 |
\edef\XINT_restoreescapechar {\escapechar\the\escapechar\relax }% |
| 22164 |
\escapechar -1 |
| 22165 |
\expandafter\def\expandafter\xint_arrayname\expandafter {\string #2}% |
| 22166 |
\XINT_restoreescapechar |
| 22167 |
\def\xint_itemcount {0}% |
| 22168 |
\expandafter\XINT_assignarray_loop \romannumeral`&&@#1\xint: |
| 22169 |
\csname\xint_arrayname 00\expandafter\endcsname |
| 22170 |
\csname\xint_arrayname 0\expandafter\endcsname |
| 22171 |
\expandafter {\xint_arrayname}#2% |
| 22172 |
}% |
| 22173 |
\long\def\XINT_assignarray_loop #1% |
| 22174 |
{% |
| 22175 |
\def\XINT_assign_tmp {#1}% |
| 22176 |
\ifx\XINT_assign_tmp\xint_bracedstopper |
| 22177 |
\expandafter\def\csname\xint_arrayname 0\expandafter\endcsname |
| 22178 |
\expandafter{\the\numexpr\xint_itemcount}% |
| 22179 |
\expandafter\expandafter\expandafter\XINT_assignarray_end |
| 22180 |
\else |
| 22181 |
\expandafter\def\expandafter\xint_itemcount\expandafter |
| 22182 |
{\the\numexpr\xint_itemcount+\xint_c_i}% |
| 22183 |
\expandafter\XINT_assignarray_def |
| 22184 |
\csname\xint_arrayname\xint_itemcount\expandafter\endcsname |
| 22185 |
\expandafter{\XINT_assign_tmp }% |
| 22186 |
\expandafter\XINT_assignarray_loop |
| 22187 |
\fi |
| 22188 |
}% |
| 22189 |
\def\XINT_assignarray_end #1#2#3#4% |
| 22190 |
{% |
| 22191 |
\def #4##1% |
| 22192 |
{% |
| 22193 |
\romannumeral0\expandafter #1\expandafter{\the\numexpr ##1}% |
| 22194 |
}% |
| 22195 |
\def #1##1% |
| 22196 |
{% |
| 22197 |
\ifnum ##1<\xint_c_ |
| 22198 |
\xint_afterfi{\XINT_expandableerror{Array index is negative: ##1.} }% |
| 22199 |
\else |
| 22200 |
\xint_afterfi {% |
| 22201 |
\ifnum ##1>#2 |
| 22202 |
\xint_afterfi |
| 22203 |
{\XINT_expandableerror{Array index is beyond range: ##1 > #2.} }% |
| 22204 |
\else\xint_afterfi |
| 22205 |
{\expandafter\expandafter\expandafter\space\csname #3##1\endcsname}% |
| 22206 |
\fi}% |
| 22207 |
\fi |
| 22208 |
}% |
| 22209 |
}% |
| 22210 |
\let\xintDigitsOf\xintAssignArray |
| 22211 |
% \end{macrocode} |
| 22212 |
% \subsection{CSV (non user documented) variants of Length, Keep, Trim, NthElt, Reverse} |
| 22213 |
% \changed{1.2j} |
| 22214 |
% These routines are for use by |\xintListSel:x:csv| and |\xintListSel:f:csv| |
| 22215 |
% from \xintexprnameimp, and also for the |reversed| and |len| functions. |
| 22216 |
% Refactored for |1.2j| release, following |1.2i| updates to |\xintKeep|, |
| 22217 |
% |\xintTrim|, ... |
| 22218 |
% |
| 22219 |
% These macros will remain undocumented in the user manual: |
| 22220 |
% |
| 22221 |
% -- they exist primarily for internal use by the \xintexprnameimp parsers, |
| 22222 |
% hence don't have to be general purpose; for example, they a priori need to |
| 22223 |
% handle only catcode 12 tokens (not true in |\xintNewExpr|, though) |
| 22224 |
% hence they are not really worried about |
| 22225 |
% controlling brace stripping (nevertheless |1.2j| has paid some secondary |
| 22226 |
% attention to it, see below.) They are not worried about normalizing leading |
| 22227 |
% spaces either, because none will be encountered when the macros are used as |
| 22228 |
% auxiliaries to the expression parsers. |
| 22229 |
% |
| 22230 |
% -- crucial design elements may change in future: |
| 22231 |
% |
| 22232 |
% 1. whether the handled lists must have or not have a final comma. Currently, |
| 22233 |
% the model is the one of comma separated lists with **no** final comma. But |
| 22234 |
% this means that there can not be a distinction of principle between a truly |
| 22235 |
% empty list and a list which contains one item which turns out to be empty. |
| 22236 |
% More importantly it makes the coding more complicated as it is needed to |
| 22237 |
% distinguish the empty list from the single-item list, both lacking commas. |
| 22238 |
% |
| 22239 |
% For the internal use of \xintexprnameimp, it would be ok to require all list |
| 22240 |
% items to be terminated by a comma, and this would bring quite some |
| 22241 |
% simplications here, but as initially I started with non-terminated lists, I |
| 22242 |
% have left it this way in the |1.2j| refactoring. |
| 22243 |
% |
| 22244 |
% 2. the way to represent the empty list. I was tempted for matter of |
| 22245 |
% optimization and synchronization with \xintexprnameimp context to require |
| 22246 |
% the empty list to be always represented by a space token and to not let the |
| 22247 |
% macros admit a completely empty input. But there were complications so for |
| 22248 |
% the time being |1.2j| does accept truly empty output (it is not |
| 22249 |
% distinguished from an input equal to a space token) and produces empty |
| 22250 |
% output for empty list. This means that the status of the «nil» object for |
| 22251 |
% the \xintexprnameimp parsers is not completely clarified (currently it is |
| 22252 |
% represented by a space token). |
| 22253 |
% |
| 22254 |
% The original Python slicing code in \xintexprnameimp |1.1| used |
| 22255 |
% |\xintCSVtoList| and |\xintListWithSep{,}| to convert back and forth to |
| 22256 |
% token lists and apply |\xintKeep/\xintTrim|. Release |1.2g| switched to |
| 22257 |
% devoted f-expandable macros added to \xinttoolsnameimp. Release |1.2j| |
| 22258 |
% refactored all these macros as a follow-up to |1.2i| improvements to |
| 22259 |
% |\xintKeep/\xintTrim|. They were made |\long| on this occasion and |
| 22260 |
% auxiliary |\xintLengthUpTo:f:csv| was added. |
| 22261 |
% |
| 22262 |
% Leading spaces in items are currently maintained as is by the |1.2j| |
| 22263 |
% macros, even by |\xintNthEltPy:f:csv|, with the exception of the first item, |
| 22264 |
% as the list is f-expanded. Perhaps |\xintNthEltPy:f:csv| should remove a |
| 22265 |
% leading space if present in the picked item; anyway, there are no spaces |
| 22266 |
% for the lists handled internally by the Python slicer of \xintexprnameimp, |
| 22267 |
% except the «nil» object currently represented by exactly one space. |
| 22268 |
% |
| 22269 |
% Kept items (with no leading spaces; but first item special as it will have |
| 22270 |
% lost a leading space due to f-expansion) will lose a brace pair under |
| 22271 |
% |\xintKeep:f:csv| if the first argument was positive and strictly less than |
| 22272 |
% the length of the list. This differs of course from |\xintKeep| (which |
| 22273 |
% always braces items it outputs when used with positive first argument) and |
| 22274 |
% also from |\xintKeepUnbraced| in the case when the whole list is kept. |
| 22275 |
% Actually the case of singleton list is special, and brace removal will |
| 22276 |
% happen then. |
| 22277 |
% |
| 22278 |
% This behaviour was otherwise for releases earlier than |1.2j| and may |
| 22279 |
% change again. |
| 22280 |
% |
| 22281 |
% Directly usable names are provided, but these macros (and the behaviour as |
| 22282 |
% described above) are to be considered \emph{unstable} for the time being. |
| 22283 |
% |
| 22284 |
% \subsubsection{\csh{xintLength:f:csv}} |
| 22285 |
% \added{1.2g} |
| 22286 |
% \changed{1.2j} |
| 22287 |
% Contrarily to |\xintLength| from \xintkernelnameimp |
| 22288 |
% this one expands its argument. |
| 22289 |
% \begin{macrocode} |
| 22290 |
\def\xintLength:f:csv {\romannumeral0\xintlength:f:csv}% |
| 22291 |
\def\xintlength:f:csv #1% |
| 22292 |
{\long\def\xintlength:f:csv ##1{% |
| 22293 |
\expandafter#1\the\numexpr\expandafter\XINT_length:f:csv_a |
| 22294 |
\romannumeral`&&@##1\xint:,\xint:,\xint:,\xint:,% |
| 22295 |
\xint:,\xint:,\xint:,\xint:,\xint:,% |
| 22296 |
\xint_c_ix,\xint_c_viii,\xint_c_vii,\xint_c_vi,% |
| 22297 |
\xint_c_v,\xint_c_iv,\xint_c_iii,\xint_c_ii,\xint_c_i,\xint_bye |
| 22298 |
\relax |
| 22299 |
}}\xintlength:f:csv { }% |
| 22300 |
% \end{macrocode} |
| 22301 |
%\begin{lverb} |
| 22302 |
% Must first check if empty list. |
| 22303 |
%\end{lverb} |
| 22304 |
% \begin{macrocode} |
| 22305 |
\long\def\XINT_length:f:csv_a #1% |
| 22306 |
{% |
| 22307 |
\xint_gob_til_xint: #1\xint_c_\xint_bye\xint:% |
| 22308 |
\XINT_length:f:csv_loop #1% |
| 22309 |
}% |
| 22310 |
\long\def\XINT_length:f:csv_loop #1,#2,#3,#4,#5,#6,#7,#8,#9,% |
| 22311 |
{% |
| 22312 |
\xint_gob_til_xint: #9\XINT_length:f:csv_finish\xint:% |
| 22313 |
\xint_c_ix+\XINT_length:f:csv_loop |
| 22314 |
}% |
| 22315 |
\def\XINT_length:f:csv_finish\xint:\xint_c_ix+\XINT_length:f:csv_loop |
| 22316 |
#1,#2,#3,#4,#5,#6,#7,#8,#9,{#9\xint_bye}% |
| 22317 |
% \end{macrocode} |
| 22318 |
% \subsubsection{\csh{xintLengthUpTo:f:csv}} |
| 22319 |
% \added{1.2j} |
| 22320 |
%\begin{lverb} |
| 22321 |
% \added{1.2j}\xintLengthUpTo:f:csv{N}{comma-list}. No ending comma. Returns |
| 22322 |
% -0 if length>N, else returns difference N-length. **N must be non-negative!!** |
| 22323 |
% |
| 22324 |
% Attention to the dot after \xint_bye for the loop interface. |
| 22325 |
%\end{lverb} |
| 22326 |
% \begin{macrocode} |
| 22327 |
\def\xintLengthUpTo:f:csv {\romannumeral0\xintlengthupto:f:csv}% |
| 22328 |
\long\def\xintlengthupto:f:csv #1#2% |
| 22329 |
{% |
| 22330 |
\expandafter\XINT_lengthupto:f:csv_a |
| 22331 |
\the\numexpr#1\expandafter.% |
| 22332 |
\romannumeral`&&@#2\xint:,\xint:,\xint:,\xint:,% |
| 22333 |
\xint:,\xint:,\xint:,\xint:,% |
| 22334 |
\xint_c_viii,\xint_c_vii,\xint_c_vi,\xint_c_v,% |
| 22335 |
\xint_c_iv,\xint_c_iii,\xint_c_ii,\xint_c_i,\xint_bye.% |
| 22336 |
}% |
| 22337 |
% \end{macrocode} |
| 22338 |
%\begin{lverb} |
| 22339 |
% Must first recognize if empty list. If this is the case, return N. |
| 22340 |
%\end{lverb} |
| 22341 |
% \begin{macrocode} |
| 22342 |
\long\def\XINT_lengthupto:f:csv_a #1.#2% |
| 22343 |
{% |
| 22344 |
\xint_gob_til_xint: #2\XINT_lengthupto:f:csv_empty\xint:% |
| 22345 |
\XINT_lengthupto:f:csv_loop_b #1.#2% |
| 22346 |
}% |
| 22347 |
\def\XINT_lengthupto:f:csv_empty\xint:% |
| 22348 |
\XINT_lengthupto:f:csv_loop_b #1.#2\xint_bye.{ #1}% |
| 22349 |
\def\XINT_lengthupto:f:csv_loop_a #1% |
| 22350 |
{% |
| 22351 |
\xint_UDsignfork |
| 22352 |
#1\XINT_lengthupto:f:csv_gt |
| 22353 |
-\XINT_lengthupto:f:csv_loop_b |
| 22354 |
\krof #1% |
| 22355 |
}% |
| 22356 |
\long\def\XINT_lengthupto:f:csv_gt #1\xint_bye.{-0}% |
| 22357 |
\long\def\XINT_lengthupto:f:csv_loop_b #1.#2,#3,#4,#5,#6,#7,#8,#9,% |
| 22358 |
{% |
| 22359 |
\xint_gob_til_xint: #9\XINT_lengthupto:f:csv_finish_a\xint:% |
| 22360 |
\expandafter\XINT_lengthupto:f:csv_loop_a\the\numexpr #1-\xint_c_viii.% |
| 22361 |
}% |
| 22362 |
\def\XINT_lengthupto:f:csv_finish_a\xint: |
| 22363 |
\expandafter\XINT_lengthupto:f:csv_loop_a |
| 22364 |
\the\numexpr #1-\xint_c_viii.#2,#3,#4,#5,#6,#7,#8,#9,% |
| 22365 |
{% |
| 22366 |
\expandafter\XINT_lengthupto:f:csv_finish_b\the\numexpr #1-#9\xint_bye |
| 22367 |
}% |
| 22368 |
\def\XINT_lengthupto:f:csv_finish_b #1#2.% |
| 22369 |
{% |
| 22370 |
\xint_UDsignfork |
| 22371 |
#1{-0}% |
| 22372 |
-{ #1#2}% |
| 22373 |
\krof |
| 22374 |
}% |
| 22375 |
% \end{macrocode} |
| 22376 |
% \subsubsection{\csh{xintKeep:f:csv}} |
| 22377 |
% \added[2016/03/17]{1.2g} |
| 22378 |
% \changed{1.2j} |
| 22379 |
%\begin{lverb} |
| 22380 |
% Redone with use of \xintLengthUpTo:f:csv. |
| 22381 |
% Same code skeleton as \xintKeep but handling comma separated but non |
| 22382 |
% terminated lists has complications. The \xintKeep in case of a negative #1 |
| 22383 |
% uses \xintgobble, we don't have that for comma delimited items, hence we do |
| 22384 |
% a special loop here (this style of loop is surely competitive with |
| 22385 |
% xintgobble for a few dozens items and even more). The loop knows before |
| 22386 |
% starting that it will not go too far. |
| 22387 |
% |
| 22388 |
%\end{lverb} |
| 22389 |
% \begin{macrocode} |
| 22390 |
\def\xintKeep:f:csv {\romannumeral0\xintkeep:f:csv }% |
| 22391 |
\long\def\xintkeep:f:csv #1#2% |
| 22392 |
{% |
| 22393 |
\expandafter\xint_stop_aftergobble |
| 22394 |
\romannumeral0\expandafter\XINT_keep:f:csv_a |
| 22395 |
\the\numexpr #1\expandafter.\expandafter{\romannumeral`&&@#2}% |
| 22396 |
}% |
| 22397 |
\def\XINT_keep:f:csv_a #1% |
| 22398 |
{% |
| 22399 |
\xint_UDzerominusfork |
| 22400 |
#1-\XINT_keep:f:csv_keepnone |
| 22401 |
0#1\XINT_keep:f:csv_neg |
| 22402 |
0-{\XINT_keep:f:csv_pos #1}% |
| 22403 |
\krof |
| 22404 |
}% |
| 22405 |
\long\def\XINT_keep:f:csv_keepnone .#1{,}% |
| 22406 |
\long\def\XINT_keep:f:csv_neg #1.#2% |
| 22407 |
{% |
| 22408 |
\expandafter\XINT_keep:f:csv_neg_done\expandafter,% |
| 22409 |
\romannumeral0% |
| 22410 |
\expandafter\XINT_keep:f:csv_neg_a\the\numexpr |
| 22411 |
#1-\numexpr\XINT_length:f:csv_a |
| 22412 |
#2\xint:,\xint:,\xint:,\xint:,% |
| 22413 |
\xint:,\xint:,\xint:,\xint:,\xint:,% |
| 22414 |
\xint_c_ix,\xint_c_viii,\xint_c_vii,\xint_c_vi,% |
| 22415 |
\xint_c_v,\xint_c_iv,\xint_c_iii,\xint_c_ii,\xint_c_i,\xint_bye |
| 22416 |
.#2\xint_bye |
| 22417 |
}% |
| 22418 |
\def\XINT_keep:f:csv_neg_a #1% |
| 22419 |
{% |
| 22420 |
\xint_UDsignfork |
| 22421 |
#1{\expandafter\XINT_keep:f:csv_trimloop\the\numexpr-\xint_c_ix+}% |
| 22422 |
-\XINT_keep:f:csv_keepall |
| 22423 |
\krof |
| 22424 |
}% |
| 22425 |
\def\XINT_keep:f:csv_keepall #1.{ }% |
| 22426 |
\long\def\XINT_keep:f:csv_neg_done #1\xint_bye{#1}% |
| 22427 |
\def\XINT_keep:f:csv_trimloop #1#2.% |
| 22428 |
{% |
| 22429 |
\xint_gob_til_minus#1\XINT_keep:f:csv_trimloop_finish-% |
| 22430 |
\expandafter\XINT_keep:f:csv_trimloop |
| 22431 |
\the\numexpr#1#2-\xint_c_ix\expandafter.\XINT_keep:f:csv_trimloop_trimnine |
| 22432 |
}% |
| 22433 |
\long\def\XINT_keep:f:csv_trimloop_trimnine #1,#2,#3,#4,#5,#6,#7,#8,#9,{}% |
| 22434 |
\def\XINT_keep:f:csv_trimloop_finish-% |
| 22435 |
\expandafter\XINT_keep:f:csv_trimloop |
| 22436 |
\the\numexpr-#1-\xint_c_ix\expandafter.\XINT_keep:f:csv_trimloop_trimnine |
| 22437 |
{\csname XINT_trim:f:csv_finish#1\endcsname}% |
| 22438 |
\long\def\XINT_keep:f:csv_pos #1.#2% |
| 22439 |
{% |
| 22440 |
\expandafter\XINT_keep:f:csv_pos_fork |
| 22441 |
\romannumeral0\XINT_lengthupto:f:csv_a |
| 22442 |
#1.#2\xint:,\xint:,\xint:,\xint:,% |
| 22443 |
\xint:,\xint:,\xint:,\xint:,% |
| 22444 |
\xint_c_viii,\xint_c_vii,\xint_c_vi,\xint_c_v,% |
| 22445 |
\xint_c_iv,\xint_c_iii,\xint_c_ii,\xint_c_i,\xint_bye.% |
| 22446 |
.#1.{}#2\xint_bye% |
| 22447 |
}% |
| 22448 |
\def\XINT_keep:f:csv_pos_fork #1#2.% |
| 22449 |
{% |
| 22450 |
\xint_UDsignfork |
| 22451 |
#1{\expandafter\XINT_keep:f:csv_loop\the\numexpr-\xint_c_viii+}% |
| 22452 |
-\XINT_keep:f:csv_pos_keepall |
| 22453 |
\krof |
| 22454 |
}% |
| 22455 |
\long\def\XINT_keep:f:csv_pos_keepall #1.#2#3\xint_bye{,#3}% |
| 22456 |
\def\XINT_keep:f:csv_loop #1#2.% |
| 22457 |
{% |
| 22458 |
\xint_gob_til_minus#1\XINT_keep:f:csv_loop_end-% |
| 22459 |
\expandafter\XINT_keep:f:csv_loop |
| 22460 |
\the\numexpr#1#2-\xint_c_viii\expandafter.\XINT_keep:f:csv_loop_pickeight |
| 22461 |
}% |
| 22462 |
\long\def\XINT_keep:f:csv_loop_pickeight |
| 22463 |
#1#2,#3,#4,#5,#6,#7,#8,#9,{{#1,#2,#3,#4,#5,#6,#7,#8,#9}}% |
| 22464 |
\def\XINT_keep:f:csv_loop_end-\expandafter\XINT_keep:f:csv_loop |
| 22465 |
\the\numexpr-#1-\xint_c_viii\expandafter.\XINT_keep:f:csv_loop_pickeight |
| 22466 |
{\csname XINT_keep:f:csv_end#1\endcsname}% |
| 22467 |
\long\expandafter\def\csname XINT_keep:f:csv_end1\endcsname |
| 22468 |
#1#2,#3,#4,#5,#6,#7,#8,#9\xint_bye {#1,#2,#3,#4,#5,#6,#7,#8}% |
| 22469 |
\long\expandafter\def\csname XINT_keep:f:csv_end2\endcsname |
| 22470 |
#1#2,#3,#4,#5,#6,#7,#8\xint_bye {#1,#2,#3,#4,#5,#6,#7}% |
| 22471 |
\long\expandafter\def\csname XINT_keep:f:csv_end3\endcsname |
| 22472 |
#1#2,#3,#4,#5,#6,#7\xint_bye {#1,#2,#3,#4,#5,#6}% |
| 22473 |
\long\expandafter\def\csname XINT_keep:f:csv_end4\endcsname |
| 22474 |
#1#2,#3,#4,#5,#6\xint_bye {#1,#2,#3,#4,#5}% |
| 22475 |
\long\expandafter\def\csname XINT_keep:f:csv_end5\endcsname |
| 22476 |
#1#2,#3,#4,#5\xint_bye {#1,#2,#3,#4}% |
| 22477 |
\long\expandafter\def\csname XINT_keep:f:csv_end6\endcsname |
| 22478 |
#1#2,#3,#4\xint_bye {#1,#2,#3}% |
| 22479 |
\long\expandafter\def\csname XINT_keep:f:csv_end7\endcsname |
| 22480 |
#1#2,#3\xint_bye {#1,#2}% |
| 22481 |
\long\expandafter\def\csname XINT_keep:f:csv_end8\endcsname |
| 22482 |
#1#2\xint_bye {#1}% |
| 22483 |
% \end{macrocode} |
| 22484 |
% \subsubsection{\csh{xintTrim:f:csv}} |
| 22485 |
% \added[2016/03/17]{1.2g} |
| 22486 |
% \changed[2016/12/20]{1.2j} |
| 22487 |
% Redone on the basis of new |\xintTrim|. |
| 22488 |
% \begin{macrocode} |
| 22489 |
\def\xintTrim:f:csv {\romannumeral0\xinttrim:f:csv }% |
| 22490 |
\long\def\xinttrim:f:csv #1#2% |
| 22491 |
{% |
| 22492 |
\expandafter\xint_stop_aftergobble |
| 22493 |
\romannumeral0\expandafter\XINT_trim:f:csv_a |
| 22494 |
\the\numexpr #1\expandafter.\expandafter{\romannumeral`&&@#2}% |
| 22495 |
}% |
| 22496 |
\def\XINT_trim:f:csv_a #1% |
| 22497 |
{% |
| 22498 |
\xint_UDzerominusfork |
| 22499 |
#1-\XINT_trim:f:csv_trimnone |
| 22500 |
0#1\XINT_trim:f:csv_neg |
| 22501 |
0-{\XINT_trim:f:csv_pos #1}% |
| 22502 |
\krof |
| 22503 |
}% |
| 22504 |
\long\def\XINT_trim:f:csv_trimnone .#1{,#1}% |
| 22505 |
\long\def\XINT_trim:f:csv_neg #1.#2% |
| 22506 |
{% |
| 22507 |
\expandafter\XINT_trim:f:csv_neg_a\the\numexpr |
| 22508 |
#1-\numexpr\XINT_length:f:csv_a |
| 22509 |
#2\xint:,\xint:,\xint:,\xint:,% |
| 22510 |
\xint:,\xint:,\xint:,\xint:,\xint:,% |
| 22511 |
\xint_c_ix,\xint_c_viii,\xint_c_vii,\xint_c_vi,% |
| 22512 |
\xint_c_v,\xint_c_iv,\xint_c_iii,\xint_c_ii,\xint_c_i,\xint_bye |
| 22513 |
.{}#2\xint_bye |
| 22514 |
}% |
| 22515 |
\def\XINT_trim:f:csv_neg_a #1% |
| 22516 |
{% |
| 22517 |
\xint_UDsignfork |
| 22518 |
#1{\expandafter\XINT_keep:f:csv_loop\the\numexpr-\xint_c_viii+}% |
| 22519 |
-\XINT_trim:f:csv_trimall |
| 22520 |
\krof |
| 22521 |
}% |
| 22522 |
\def\XINT_trim:f:csv_trimall {\expandafter,\xint_bye}% |
| 22523 |
\long\def\XINT_trim:f:csv_pos #1.#2% |
| 22524 |
{% |
| 22525 |
\expandafter\XINT_trim:f:csv_pos_done\expandafter,% |
| 22526 |
\romannumeral0% |
| 22527 |
\expandafter\XINT_trim:f:csv_loop\the\numexpr#1-\xint_c_ix.% |
| 22528 |
#2\xint:,\xint:,\xint:,\xint:,\xint:,% |
| 22529 |
\xint:,\xint:,\xint:,\xint:,\xint:\xint_bye |
| 22530 |
}% |
| 22531 |
\def\XINT_trim:f:csv_loop #1#2.% |
| 22532 |
{% |
| 22533 |
\xint_gob_til_minus#1\XINT_trim:f:csv_finish-% |
| 22534 |
\expandafter\XINT_trim:f:csv_loop\the\numexpr#1#2\XINT_trim:f:csv_loop_trimnine |
| 22535 |
}% |
| 22536 |
\long\def\XINT_trim:f:csv_loop_trimnine #1,#2,#3,#4,#5,#6,#7,#8,#9,% |
| 22537 |
{% |
| 22538 |
\xint_gob_til_xint: #9\XINT_trim:f:csv_toofew\xint:-\xint_c_ix.% |
| 22539 |
}% |
| 22540 |
\def\XINT_trim:f:csv_toofew\xint:{*\xint_c_}% |
| 22541 |
\def\XINT_trim:f:csv_finish-% |
| 22542 |
\expandafter\XINT_trim:f:csv_loop\the\numexpr-#1\XINT_trim:f:csv_loop_trimnine |
| 22543 |
{% |
| 22544 |
\csname XINT_trim:f:csv_finish#1\endcsname |
| 22545 |
}% |
| 22546 |
\long\expandafter\def\csname XINT_trim:f:csv_finish1\endcsname |
| 22547 |
#1,#2,#3,#4,#5,#6,#7,#8,{ }% |
| 22548 |
\long\expandafter\def\csname XINT_trim:f:csv_finish2\endcsname |
| 22549 |
#1,#2,#3,#4,#5,#6,#7,{ }% |
| 22550 |
\long\expandafter\def\csname XINT_trim:f:csv_finish3\endcsname |
| 22551 |
#1,#2,#3,#4,#5,#6,{ }% |
| 22552 |
\long\expandafter\def\csname XINT_trim:f:csv_finish4\endcsname |
| 22553 |
#1,#2,#3,#4,#5,{ }% |
| 22554 |
\long\expandafter\def\csname XINT_trim:f:csv_finish5\endcsname |
| 22555 |
#1,#2,#3,#4,{ }% |
| 22556 |
\long\expandafter\def\csname XINT_trim:f:csv_finish6\endcsname |
| 22557 |
#1,#2,#3,{ }% |
| 22558 |
\long\expandafter\def\csname XINT_trim:f:csv_finish7\endcsname |
| 22559 |
#1,#2,{ }% |
| 22560 |
\long\expandafter\def\csname XINT_trim:f:csv_finish8\endcsname |
| 22561 |
#1,{ }% |
| 22562 |
\expandafter\let\csname XINT_trim:f:csv_finish9\endcsname\space |
| 22563 |
\long\def\XINT_trim:f:csv_pos_done #1\xint:#2\xint_bye{#1}% |
| 22564 |
% \end{macrocode} |
| 22565 |
% \subsubsection{\csh{xintNthEltPy:f:csv}} |
| 22566 |
%\begin{lverb} |
| 22567 |
% Counts like Python starting at zero. Last refactored with 1.2j. |
| 22568 |
% Attention, makes currently no effort at removing leading spaces in the |
| 22569 |
% picked item. |
| 22570 |
%\end{lverb} |
| 22571 |
% \begin{macrocode} |
| 22572 |
\def\xintNthEltPy:f:csv {\romannumeral0\xintntheltpy:f:csv }% |
| 22573 |
\long\def\xintntheltpy:f:csv #1#2% |
| 22574 |
{% |
| 22575 |
\expandafter\XINT_nthelt:f:csv_a |
| 22576 |
\the\numexpr #1\expandafter.\expandafter{\romannumeral`&&@#2}% |
| 22577 |
}% |
| 22578 |
\def\XINT_nthelt:f:csv_a #1% |
| 22579 |
{% |
| 22580 |
\xint_UDsignfork |
| 22581 |
#1\XINT_nthelt:f:csv_neg |
| 22582 |
-\XINT_nthelt:f:csv_pos |
| 22583 |
\krof #1% |
| 22584 |
}% |
| 22585 |
\long\def\XINT_nthelt:f:csv_neg -#1.#2% |
| 22586 |
{% |
| 22587 |
\expandafter\XINT_nthelt:f:csv_neg_fork |
| 22588 |
\the\numexpr\XINT_length:f:csv_a |
| 22589 |
#2\xint:,\xint:,\xint:,\xint:,% |
| 22590 |
\xint:,\xint:,\xint:,\xint:,\xint:,% |
| 22591 |
\xint_c_ix,\xint_c_viii,\xint_c_vii,\xint_c_vi,% |
| 22592 |
\xint_c_v,\xint_c_iv,\xint_c_iii,\xint_c_ii,\xint_c_i,\xint_bye |
| 22593 |
-#1.#2,\xint_bye |
| 22594 |
}% |
| 22595 |
\def\XINT_nthelt:f:csv_neg_fork #1% |
| 22596 |
{% |
| 22597 |
\if#1-\expandafter\xint_stop_afterbye\fi |
| 22598 |
\expandafter\XINT_nthelt:f:csv_neg_done |
| 22599 |
\romannumeral0% |
| 22600 |
\expandafter\XINT_keep:f:csv_trimloop\the\numexpr-\xint_c_ix+#1% |
| 22601 |
}% |
| 22602 |
\long\def\XINT_nthelt:f:csv_neg_done#1,#2\xint_bye{ #1}% |
| 22603 |
\long\def\XINT_nthelt:f:csv_pos #1.#2% |
| 22604 |
{% |
| 22605 |
\expandafter\XINT_nthelt:f:csv_pos_done |
| 22606 |
\romannumeral0% |
| 22607 |
\expandafter\XINT_trim:f:csv_loop\the\numexpr#1-\xint_c_ix.% |
| 22608 |
#2\xint:,\xint:,\xint:,\xint:,\xint:,% |
| 22609 |
\xint:,\xint:,\xint:,\xint:,\xint:,\xint_bye |
| 22610 |
}% |
| 22611 |
\def\XINT_nthelt:f:csv_pos_done #1{% |
| 22612 |
\long\def\XINT_nthelt:f:csv_pos_done ##1,##2\xint_bye{% |
| 22613 |
\xint_gob_til_xint:##1\XINT_nthelt:f:csv_pos_cleanup\xint:#1##1}% |
| 22614 |
}\XINT_nthelt:f:csv_pos_done{ }% |
| 22615 |
% \end{macrocode} |
| 22616 |
%\begin{lverb} |
| 22617 |
% This strange thing is in case the picked item was the last one, hence |
| 22618 |
% there was an ending \xint: (we could not put a comma earlier for |
| 22619 |
% matters of not confusing empty list with a singleton list), and we do this |
| 22620 |
% here to activate brace-stripping of item as all other items may be |
| 22621 |
% brace-stripped if picked. This is done for coherence. Of course, in the |
| 22622 |
% context of the xintexpr.sty parsers, there are no braces in list items... |
| 22623 |
%\end{lverb} |
| 22624 |
% \begin{macrocode} |
| 22625 |
\xint_firstofone{\long\def\XINT_nthelt:f:csv_pos_cleanup\xint:} % |
| 22626 |
#1\xint:{ #1}% |
| 22627 |
% \end{macrocode} |
| 22628 |
% \subsubsection{\csh{xintReverse:f:csv}} |
| 22629 |
% \added[2016/03/17]{1.2g} |
| 22630 |
%\begin{lverb} |
| 22631 |
% Contrarily to \xintReverseOrder from xintkernel.sty, this |
| 22632 |
% one expands its argument. Handles empty list too. . |
| 22633 |
%\end{lverb} |
| 22634 |
% \changed{1.2j} Made |\long|. |
| 22635 |
% \begin{macrocode} |
| 22636 |
\def\xintReverse:f:csv {\romannumeral0\xintreverse:f:csv }% |
| 22637 |
\long\def\xintreverse:f:csv #1% |
| 22638 |
{% |
| 22639 |
\expandafter\XINT_reverse:f:csv_loop |
| 22640 |
\expandafter{\expandafter}\romannumeral`&&@#1,% |
| 22641 |
\xint:,% |
| 22642 |
\xint_bye,\xint_bye,\xint_bye,\xint_bye,% |
| 22643 |
\xint_bye,\xint_bye,\xint_bye,\xint_bye,% |
| 22644 |
\xint: |
| 22645 |
}% |
| 22646 |
\long\def\XINT_reverse:f:csv_loop #1#2,#3,#4,#5,#6,#7,#8,#9,% |
| 22647 |
{% |
| 22648 |
\xint_bye #9\XINT_reverse:f:csv_cleanup\xint_bye |
| 22649 |
\XINT_reverse:f:csv_loop {,#9,#8,#7,#6,#5,#4,#3,#2#1}% |
| 22650 |
}% |
| 22651 |
\long\def\XINT_reverse:f:csv_cleanup\xint_bye\XINT_reverse:f:csv_loop #1#2\xint: |
| 22652 |
{% |
| 22653 |
\XINT_reverse:f:csv_finish #1% |
| 22654 |
}% |
| 22655 |
\long\def\XINT_reverse:f:csv_finish #1\xint:,{ }% |
| 22656 |
% \end{macrocode} |
| 22657 |
% \subsubsection{\csh{xintFirstItem:f:csv}} |
| 22658 |
% \added{1.2k} |
| 22659 |
%\begin{lverb} |
| 22660 |
% For use by first() in |
| 22661 |
% \xintexpr-essions, and some amount of compatibility with \xintNewExpr. |
| 22662 |
%\end{lverb} |
| 22663 |
% \begin{macrocode} |
| 22664 |
\def\xintFirstItem:f:csv {\romannumeral0\xintfirstitem:f:csv}% |
| 22665 |
\long\def\xintfirstitem:f:csv #1% |
| 22666 |
{% |
| 22667 |
\expandafter\XINT_first:f:csv_a\romannumeral`&&@#1,\xint_bye |
| 22668 |
}% |
| 22669 |
\long\def\XINT_first:f:csv_a #1,#2\xint_bye{ #1}% |
| 22670 |
% \end{macrocode} |
| 22671 |
% \subsubsection{\csh{xintLastItem:f:csv}} |
| 22672 |
% \added{1.2k} |
| 22673 |
%\begin{lverb} |
| 22674 |
% Based on and sharing code with xintkernel's |
| 22675 |
% \xintLastItem from 1.2i. Output empty if input empty. f-expands its argument |
| 22676 |
% (hence first item, if not protected.) For use by last() in |
| 22677 |
% \xintexpr-essions with to some extent \xintNewExpr compatibility. |
| 22678 |
%\end{lverb} |
| 22679 |
% \begin{macrocode} |
| 22680 |
\def\xintLastItem:f:csv {\romannumeral0\xintlastitem:f:csv}% |
| 22681 |
\long\def\xintlastitem:f:csv #1% |
| 22682 |
{% |
| 22683 |
\expandafter\XINT_last:f:csv_loop\expandafter{\expandafter}\expandafter.% |
| 22684 |
\romannumeral`&&@#1,% |
| 22685 |
\xint:\XINT_last_loop_enda,\xint:\XINT_last_loop_endb,% |
| 22686 |
\xint:\XINT_last_loop_endc,\xint:\XINT_last_loop_endd,% |
| 22687 |
\xint:\XINT_last_loop_ende,\xint:\XINT_last_loop_endf,% |
| 22688 |
\xint:\XINT_last_loop_endg,\xint:\XINT_last_loop_endh,\xint_bye |
| 22689 |
}% |
| 22690 |
\long\def\XINT_last:f:csv_loop #1.#2,#3,#4,#5,#6,#7,#8,#9,% |
| 22691 |
{% |
| 22692 |
\xint_gob_til_xint: #9% |
| 22693 |
{#8}{#7}{#6}{#5}{#4}{#3}{#2}{#1}\xint: |
| 22694 |
\XINT_last:f:csv_loop {#9}.% |
| 22695 |
}% |
| 22696 |
% \end{macrocode} |
| 22697 |
% \subsubsection{\csh{xintKeep:x:csv}} |
| 22698 |
% \added{1.2j} To \xintexprnameimp. Moved here at |1.4|. |
| 22699 |
% Not part of |
| 22700 |
% publicly supported macros, may be removed at any time. |
| 22701 |
% \begin{macrocode} |
| 22702 |
\def\xintKeep:x:csv #1#2% |
| 22703 |
{% |
| 22704 |
\expandafter\xint_gobble_i |
| 22705 |
\romannumeral0\expandafter\XINT_keep:x:csv_pos |
| 22706 |
\the\numexpr #1\expandafter.\expandafter{\romannumeral`&&@#2}% |
| 22707 |
}% |
| 22708 |
\def\XINT_keep:x:csv_pos #1.#2% |
| 22709 |
{% |
| 22710 |
\expandafter\XINT_keep:x:csv_loop\the\numexpr#1-\xint_c_viii.% |
| 22711 |
#2\xint_Bye,\xint_Bye,\xint_Bye,\xint_Bye,% |
| 22712 |
\xint_Bye,\xint_Bye,\xint_Bye,\xint_Bye,\xint_bye |
| 22713 |
}% |
| 22714 |
\def\XINT_keep:x:csv_loop #1% |
| 22715 |
{% |
| 22716 |
\xint_gob_til_minus#1\XINT_keep:x:csv_finish-% |
| 22717 |
\XINT_keep:x:csv_loop_pickeight #1% |
| 22718 |
}% |
| 22719 |
\def\XINT_keep:x:csv_loop_pickeight #1.#2,#3,#4,#5,#6,#7,#8,#9,% |
| 22720 |
{% |
| 22721 |
,#2,#3,#4,#5,#6,#7,#8,#9% |
| 22722 |
\expandafter\XINT_keep:x:csv_loop\the\numexpr#1-\xint_c_viii.% |
| 22723 |
}% |
| 22724 |
\def\XINT_keep:x:csv_finish-\XINT_keep:x:csv_loop_pickeight -#1.% |
| 22725 |
{% |
| 22726 |
\csname XINT_keep:x:csv_finish#1\endcsname |
| 22727 |
}% |
| 22728 |
\expandafter\def\csname XINT_keep:x:csv_finish1\endcsname |
| 22729 |
#1,#2,#3,#4,#5,#6,#7,{,#1,#2,#3,#4,#5,#6,#7\xint_Bye}% |
| 22730 |
\expandafter\def\csname XINT_keep:x:csv_finish2\endcsname |
| 22731 |
#1,#2,#3,#4,#5,#6,{,#1,#2,#3,#4,#5,#6\xint_Bye}% |
| 22732 |
\expandafter\def\csname XINT_keep:x:csv_finish3\endcsname |
| 22733 |
#1,#2,#3,#4,#5,{,#1,#2,#3,#4,#5\xint_Bye}% |
| 22734 |
\expandafter\def\csname XINT_keep:x:csv_finish4\endcsname |
| 22735 |
#1,#2,#3,#4,{,#1,#2,#3,#4\xint_Bye}% |
| 22736 |
\expandafter\def\csname XINT_keep:x:csv_finish5\endcsname |
| 22737 |
#1,#2,#3,{,#1,#2,#3\xint_Bye}% |
| 22738 |
\expandafter\def\csname XINT_keep:x:csv_finish6\endcsname |
| 22739 |
#1,#2,{,#1,#2\xint_Bye}% |
| 22740 |
\expandafter\def\csname XINT_keep:x:csv_finish7\endcsname |
| 22741 |
#1,{,#1\xint_Bye}% |
| 22742 |
\expandafter\let\csname XINT_keep:x:csv_finish8\endcsname\xint_Bye |
| 22743 |
% \end{macrocode} |
| 22744 |
% \subsubsection{Public names for the undocumented csv macros: |
| 22745 |
% \csh{xintCSVLength}, \csh{xintCSVKeep}, \csh{xintCSVKeepx}, \csh{xintCSVTrim}, |
| 22746 |
% \csh{xintCSVNthEltPy}, \csh{xintCSVReverse}, |
| 22747 |
% \csh{xintCSVFirstItem}, \csh{xintCSVLastItem}} |
| 22748 |
% |
| 22749 |
%\begin{lverb} |
| 22750 |
% Completely unstable macros: currently they expand the list argument |
| 22751 |
% and want no final comma. But for matters of xintexpr.sty I could as well |
| 22752 |
% decide to require a final comma, and then I could simplify implementation |
| 22753 |
% but of course this would break the macros if used with current |
| 22754 |
% functionalities. |
| 22755 |
%\end{lverb} |
| 22756 |
% \begin{macrocode} |
| 22757 |
\let\xintCSVLength \xintLength:f:csv |
| 22758 |
\let\xintCSVKeep \xintKeep:f:csv |
| 22759 |
\let\xintCSVKeepx \xintKeep:x:csv |
| 22760 |
\let\xintCSVTrim \xintTrim:f:csv |
| 22761 |
\let\xintCSVNthEltPy \xintNthEltPy:f:csv |
| 22762 |
\let\xintCSVReverse \xintReverse:f:csv |
| 22763 |
\let\xintCSVFirstItem\xintFirstItem:f:csv |
| 22764 |
\let\xintCSVLastItem \xintLastItem:f:csv |
| 22765 |
\let\XINT_tmpa\relax \let\XINT_tmpb\relax \let\XINT_tmpc\relax |
| 22766 |
\XINTrestorecatcodesendinput% |
| 22767 |
% \end{macrocode} |
| 22768 |
% \StoreCodelineNo {xinttools} |
| 22769 |
% \cleardoublepage\let\xinttoolsnameUp\undefined |
| 22770 |
%\gardesactifs |
| 22771 |
%\let</xinttools>\relax |
| 22772 |
%\let<*xintcore>\gardesinactifs |
| 22773 |
%</xinttools>^^A-------------------------------------------------- |
| 22774 |
%<*xintcore>^^A--------------------------------------------------- |
| 22775 |
%^^A -*- coding: utf-8; mode: doctex; fill-column: 78; sentence-end-double-space: t; eval: (auto-fill-mode -1); fill-paragraph-function: nil; -*- |
| 22776 |
% \clearpage\csname xintcorenameUp\endcsname |
| 22777 |
% \let\MakePrivateLetters\xintMakePrivateLetters |
| 22778 |
% \section{Package \xintcorenameimp implementation} |
| 22779 |
% \RaisedLabel{sec:coreimp} |
| 22780 |
% |
| 22781 |
% \localtableofcontents |
| 22782 |
% |
| 22783 |
% Got split off from \xintnameimp with release |1.1|. |
| 22784 |
% |
| 22785 |
% The core arithmetic routines have been entirely rewritten for release |
| 22786 |
% |1.2|. The |1.2i| and |1.2l| brought again some improvements. |
| 22787 |
% |
| 22788 |
% The commenting continues (\xintdocdate) to be very sparse: actually it got |
| 22789 |
% worse than ever with release |1.2|. I will possibly add comments at a |
| 22790 |
% later date, but for the time being the new routines are not commented at |
| 22791 |
% all. |
| 22792 |
% |
| 22793 |
% |1.3| removes all macros which were deprecated at |1.2o|. |
| 22794 |
% |
| 22795 |
% \subsection{Catcodes, \protect\eTeX{} and reload detection} |
| 22796 |
% |
| 22797 |
% The code for reload detection was initially copied from \textsc{Heiko |
| 22798 |
% Oberdiek}'s packages, then modified. |
| 22799 |
% |
| 22800 |
% The method for catcodes was also initially directly inspired by these |
| 22801 |
% packages. |
| 22802 |
% |
| 22803 |
% \begin{macrocode} |
| 22804 |
\begingroup\catcode61\catcode48\catcode32=10\relax% |
| 22805 |
\catcode13=5 % ^^M |
| 22806 |
\endlinechar=13 % |
| 22807 |
\catcode123=1 % { |
| 22808 |
\catcode125=2 % } |
| 22809 |
\catcode64=11 % @ |
| 22810 |
\catcode44=12 % , |
| 22811 |
\catcode46=12 % . |
| 22812 |
\catcode58=12 % : |
| 22813 |
\catcode94=7 % ^ |
| 22814 |
\def\empty{}\def\space{ }\newlinechar10 |
| 22815 |
\def\z{\endgroup}% |
| 22816 |
\expandafter\let\expandafter\x\csname [email protected]\endcsname |
| 22817 |
\expandafter\let\expandafter\w\csname [email protected]\endcsname |
| 22818 |
\expandafter\ifx\csname numexpr\endcsname\relax |
| 22819 |
\expandafter\ifx\csname PackageWarningNoLine\endcsname\relax |
| 22820 |
\immediate\write128{^^JPackage xintcore Warning:^^J% |
| 22821 |
\space\space\space\space |
| 22822 |
\numexpr not available, aborting input.^^J}% |
| 22823 |
\else |
| 22824 |
\PackageWarningNoLine{xintcore}{\numexpr not available, aborting input}% |
| 22825 |
\fi |
| 22826 |
\def\z{\endgroup\endinput}% |
| 22827 |
\else |
| 22828 |
\ifx\x\relax % plain-TeX, first loading of xintcore.sty |
| 22829 |
\ifx\w\relax % but xintkernel.sty not yet loaded. |
| 22830 |
\def\z{\endgroup\input xintkernel.sty\relax}% |
| 22831 |
\fi |
| 22832 |
\else |
| 22833 |
\ifx\x\empty % LaTeX, first loading, |
| 22834 |
% variable is initialized, but \ProvidesPackage not yet seen |
| 22835 |
\ifx\w\relax % xintkernel.sty not yet loaded. |
| 22836 |
\def\z{\endgroup\RequirePackage{xintkernel}}% |
| 22837 |
\fi |
| 22838 |
\else |
| 22839 |
\def\z{\endgroup\endinput}% xintkernel already loaded. |
| 22840 |
\fi |
| 22841 |
\fi |
| 22842 |
\fi |
| 22843 |
\z% |
| 22844 |
\XINTsetupcatcodes% defined in xintkernel.sty |
| 22845 |
% \end{macrocode} |
| 22846 |
% \subsection{Package identification} |
| 22847 |
% \begin{macrocode} |
| 22848 |
\XINT_providespackage |
| 22849 |
\ProvidesPackage{xintcore}% |
| 22850 |
[2025/09/06 v1.4o Expandable arithmetic on big integers (JFB)]% |
| 22851 |
% \end{macrocode} |
| 22852 |
% \subsection{(WIP!) Error conditions and exceptions} |
| 22853 |
%\begin{lverb} |
| 22854 |
% As per the Mike Cowlishaw/IBM's General Decimal Arithmetic Specification |
| 22855 |
% |
| 22856 |
% http://speleotrove.com/decimal/decarith.html |
| 22857 |
% |
| 22858 |
% and the Python3 implementation in its Decimal module. |
| 22859 |
% |
| 22860 |
% Clamped, ConversionSyntax, DivisionByZero, DivisionImpossible, |
| 22861 |
% DivisionUndefined, Inexact, InsufficientStorage, InvalidContext, |
| 22862 |
% InvalidOperation, Overflow, Inexact, Rounded, Subnormal, |
| 22863 |
% Underflow. |
| 22864 |
% |
| 22865 |
% X3.274 rajoute LostDigits |
| 22866 |
% |
| 22867 |
% Python rajoute FloatOperation (et n'inclut pas InsufficientStorage) |
| 22868 |
% |
| 22869 |
% quote de decarith.pdf: |
| 22870 |
% The Clamped, Inexact, Rounded, and Subnormal conditions can coincide with |
| 22871 |
% each other or with other conditions. In these cases then any trap enabled |
| 22872 |
% for another condition takes precedence over (is handled before) all of |
| 22873 |
% these, any Subnormal trap takes precedence over Inexact, any Inexact trap |
| 22874 |
% takes precedence over Rounded, and any Rounded trap takes precedence over |
| 22875 |
% Clamped. |
| 22876 |
% |
| 22877 |
% WORK IN PROGRESS ! (1.2l, 2017/07/26) |
| 22878 |
% |
| 22879 |
% I follow the Python terminology: a trapped signal means it raises an |
| 22880 |
% exception which for us means an expandable error message with some possible |
| 22881 |
% user interaction. In this WIP |
| 22882 |
% state, the interaction is commented out. A non-trapped signal or condition |
| 22883 |
% would activate a (presumably silent) handler. |
| 22884 |
% |
| 22885 |
% Here, no signal-raising condition is "ignored" and all are "trapped" which |
| 22886 |
% means that error handlers are never activated, thus left in garbage state in |
| 22887 |
% the code. |
| 22888 |
% |
| 22889 |
% Various conditions can raise the same signal. |
| 22890 |
% |
| 22891 |
% Only signals, not conditions, raise Flags. |
| 22892 |
% |
| 22893 |
% If a signal is ignored it does not raise a Flag, but it activates the signal |
| 22894 |
% handler (by default now no signal is ignored.) |
| 22895 |
% |
| 22896 |
% If a signal is not ignored it raises a Flag and then if it is not trapped it |
| 22897 |
% activates the handler of the _condition_. |
| 22898 |
% |
| 22899 |
% If trapped (which is default now) an «exception» is raised, which means an |
| 22900 |
% expandable error message (I copied over the LaTeX3 code for expandable error |
| 22901 |
% messages, basically) |
| 22902 |
% interrupts the TeX run. In future, user input could |
| 22903 |
% be solicited, but currently this is commented out. |
| 22904 |
% |
| 22905 |
% For now macros to reset flags are done but without public interface nor |
| 22906 |
% documentation. |
| 22907 |
% |
| 22908 |
% Only four conditions are currently possibly encountered: |
| 22909 |
%- InvalidOperation |
| 22910 |
%- DivisionByZero |
| 22911 |
%- DivisionUndefined (which signals InvalidOperation) |
| 22912 |
%- Underflow |
| 22913 |
% |
| 22914 |
% I did it quickly, anyhow this will become more palpable when some of the |
| 22915 |
% Decimal Specification is actually implemented. The plan is to first do the |
| 22916 |
% X3.274 norm, then more complete implementation will follow... perhaps... |
| 22917 |
%\end{lverb} |
| 22918 |
%\odef\MakePrivateLetters{\MakePrivateLetters\catcode`- 11}^^A |
| 22919 |
% \begin{macrocode} |
| 22920 |
\csname XINT_Clamped_istrapped\endcsname |
| 22921 |
\csname XINT_ConversionSyntax_istrapped\endcsname |
| 22922 |
\csname XINT_DivisionByZero_istrapped\endcsname |
| 22923 |
\csname XINT_DivisionImpossible_istrapped\endcsname |
| 22924 |
\csname XINT_DivisionUndefined_istrapped\endcsname |
| 22925 |
\csname XINT_InvalidOperation_istrapped\endcsname |
| 22926 |
\csname XINT_Overflow_istrapped\endcsname |
| 22927 |
\csname XINT_Underflow_istrapped\endcsname |
| 22928 |
\catcode`- 11 |
| 22929 |
\def\XINT_ConversionSyntax-signal {{InvalidOperation}}% |
| 22930 |
\let\XINT_DivisionImpossible-signal\XINT_ConversionSyntax-signal |
| 22931 |
\let\XINT_DivisionUndefined-signal \XINT_ConversionSyntax-signal |
| 22932 |
\let\XINT_InvalidContext-signal \XINT_ConversionSyntax-signal |
| 22933 |
\catcode`- 12 |
| 22934 |
\def\XINT_signalcondition #1{\expandafter\XINT_signalcondition_a |
| 22935 |
\romannumeral0\ifcsname XINT_#1-signal\endcsname |
| 22936 |
\xint_dothis{\csname XINT_#1-signal\endcsname}% |
| 22937 |
\fi\xint_orthat{{#1}}{#1}}% |
| 22938 |
\def\XINT_signalcondition_a #1#2#3#4#5{% copied over from Python Decimal module |
| 22939 |
% \end{macrocode} |
| 22940 |
% |#1|=signal, |#2|=condition, |#3|=explanation for user, |
| 22941 |
% |#4|=context for error handlers, |#5|=used. |
| 22942 |
% \begin{macrocode} |
| 22943 |
\ifcsname XINT_#1_isignoredflag\endcsname |
| 22944 |
\xint_dothis{\csname XINT_#1.handler\endcsname {#4}}% |
| 22945 |
\fi |
| 22946 |
\expandafter\xint_gobble_i\csname XINT_#1Flag_ON\endcsname |
| 22947 |
\unless\ifcsname XINT_#1_istrapped\endcsname |
| 22948 |
\xint_dothis{\csname XINT_#2.handler\endcsname {#4}}% |
| 22949 |
\fi |
| 22950 |
\xint_orthat{% |
| 22951 |
% the flag raised is named after the signal #1, but we show condition |
| 22952 |
% #2 |
| 22953 |
% \end{macrocode} |
| 22954 |
% \let\MakePrivateLetters\xintMakePrivateLetters |
| 22955 |
%\begin{lverb} |
| 22956 |
% On 2021/05/19, 1.4g, I re-examined \XINT_expandableerror experimenting |
| 22957 |
% at first with an added ^^J to shift to next line the actual message. |
| 22958 |
% |
| 22959 |
% Previously I was calling it thrice (condition #2, user context #3, next |
| 22960 |
% tokens #5) here but it seems more reasonable to use it only once. As total |
| 22961 |
% size is so limited, I decided to only display #3 (information for user) and |
| 22962 |
% drop the #2 (condition, first argument of \XINT_signalcondition) and the |
| 22963 |
% display of the #5 (next tokens, fourth argument of \XINT_signalcondition). |
| 22964 |
% |
| 22965 |
% Besides, why was I doing here \xint_stop_atfirstofone{#5}, which adds |
| 22966 |
% limitations to usage? Now inserting #5 directly so callers will have to |
| 22967 |
% insert a \romannumeral0 stopping space token if needed. I thus have to |
| 22968 |
% update all usages across (mainly, I think) xintfrac. Done, but using here |
| 22969 |
% \xint_firstofone{#5}. This looks silly, but allows some hypothetical future |
| 22970 |
% usage by user of I\xintUse{stuff} usage where \xintUse would be |
| 22971 |
% \xint_firstofthree. |
| 22972 |
% |
| 22973 |
% The problem is that this would have to be explained to user in the error |
| 22974 |
% context but space there is so extremely limited... |
| 22975 |
% |
| 22976 |
% After having reviewed existing usage of \XINT_signalcondition, I noticed |
| 22977 |
% there was free space in most cases and added here " (hit RET)" after #3. |
| 22978 |
% |
| 22979 |
% I experimented with ^^J here too (its effect in the "context" is |
| 22980 |
% independent of the \newlinechar setting, but it depends on the engine: works |
| 22981 |
% with TeXLive pdftex, requires -8bit with xetex) |
| 22982 |
% |
| 22983 |
% However, due to \errorcontextlines being 5 by default in etex (but |
| 22984 |
% xintsession 0.2b sets it to 0), I finally decided to not insert a ^^J |
| 22985 |
% ($&$&J) at all to separate the " (hit RET)" hint. |
| 22986 |
% |
| 22987 |
% On 2021/05/20 evening I found another completely different method for |
| 22988 |
% \XINT_expandableerror, which has some advantages. In particular it allows me |
| 22989 |
% to not use here "#3 (hit RET)" but simply "#3" as such information can be |
| 22990 |
% integrated in a non size limited generic message. |
| 22991 |
% |
| 22992 |
% The maximal size of #3 here was increased from 48 characters (method |
| 22993 |
% with \xint/ being badly delimited), to now 55 characters, longer |
| 22994 |
% messages being truncated at 56 characters with an appended "\ETC.". |
| 22995 |
%\end{lverb} |
| 22996 |
% \begin{macrocode} |
| 22997 |
\XINT_expandableerror{#3}% |
| 22998 |
% not for X3.274 |
| 22999 |
% \XINT_expandableerror{<RET>, or I\xintUse{...}<RET>, or I\xintCTRLC<RET>}% |
| 23000 |
\xint_firstofone{#5}% |
| 23001 |
}% |
| 23002 |
}% |
| 23003 |
%% \def\xintUse{\xint_firstofthree} % defined in xint.sty |
| 23004 |
\def\XINT_ifFlagRaised #1{% |
| 23005 |
\ifcsname XINT_#1Flag_ON\endcsname |
| 23006 |
\expandafter\xint_firstoftwo |
| 23007 |
\else |
| 23008 |
\expandafter\xint_secondoftwo |
| 23009 |
\fi}% |
| 23010 |
\def\XINT_resetFlag #1% |
| 23011 |
{\expandafter\let\csname XINT_#1Flag_ON\endcsname\XINT_undefined}% |
| 23012 |
\def\XINT_resetFlags {% WIP |
| 23013 |
\XINT_resetFlag{InvalidOperation}% also from DivisionUndefined |
| 23014 |
\XINT_resetFlag{DivisionByZero}% |
| 23015 |
\XINT_resetFlag{Underflow}% (\xintiiPow with negative exponent) |
| 23016 |
\XINT_resetFlag{Overflow}% not encountered so far in xint code 1.2l |
| 23017 |
% .. others .. |
| 23018 |
}% |
| 23019 |
\def\XINT_RaiseFlag #1{\expandafter\xint_gobble_i\csname XINT_#1Flag_ON\endcsname}% |
| 23020 |
% \end{macrocode} |
| 23021 |
% NOT IMPLEMENTED! WORK IN PROGRESS! (ALL SIGNALS TRAPPED, NO HANDLERS USED) |
| 23022 |
% \odef\MakePrivateLetters{\MakePrivateLetters\catcode`. 11 }% |
| 23023 |
% \begin{macrocode} |
| 23024 |
\catcode`. 11 |
| 23025 |
\let\XINT_Clamped.handler\xint_firstofone % WIP |
| 23026 |
\def\XINT_InvalidOperation.handler#1{_NaN}% WIP |
| 23027 |
\def\XINT_ConversionSyntax.handler#1{_NaN}% WIP |
| 23028 |
\def\XINT_DivisionByZero.handler#1{_SignedInfinity(#1)}% WIP |
| 23029 |
\def\XINT_DivisionImpossible.handler#1{_NaN}% WIP |
| 23030 |
\def\XINT_DivisionUndefined.handler#1{_NaN}% WIP |
| 23031 |
\let\XINT_Inexact.handler\xint_firstofone % WIP |
| 23032 |
\def\XINT_InvalidContext.handler#1{_NaN}% WIP |
| 23033 |
\let\XINT_Rounded.handler\xint_firstofone % WIP |
| 23034 |
\let\XINT_Subnormal.handler\xint_firstofone% WIP |
| 23035 |
\def\XINT_Overflow.handler#1{_NaN}% WIP |
| 23036 |
\def\XINT_Underflow.handler#1{_NaN}% WIP |
| 23037 |
\catcode`. 12 |
| 23038 |
% \end{macrocode} |
| 23039 |
% \let\MakePrivateLetters\xintMakePrivateLetters |
| 23040 |
% \subsection*{Routines handling integers as lists of token digits} |
| 23041 |
% \addcontentsline{toc}{subsection}{Routines handling integers as lists of token digits} |
| 23042 |
%\begin{lverb} |
| 23043 |
% Routines handling big integers which are lists of digit tokens with no |
| 23044 |
% special additional structure. |
| 23045 |
% |
| 23046 |
% Some |
| 23047 |
% routines do not accept non properly terminated inputs like "\the\numexpr1", |
| 23048 |
% or "\the\mathcode`\-", others do. |
| 23049 |
% |
| 23050 |
% These routines or their sub-routines are mainly for internal usage. |
| 23051 |
%\end{lverb} |
| 23052 |
% |
| 23053 |
% \subsection{\csh{XINT_cuz_small}} |
| 23054 |
%\begin{lverb} |
| 23055 |
% \XINT_cuz_small removes leading zeroes from the first eight digits. Expands |
| 23056 |
% following \romannumeral0. At least one digit is produced. |
| 23057 |
%\end{lverb} |
| 23058 |
% \begin{macrocode} |
| 23059 |
\def\XINT_cuz_small#1{% |
| 23060 |
\def\XINT_cuz_small ##1##2##3##4##5##6##7##8% |
| 23061 |
{% |
| 23062 |
\expandafter#1\the\numexpr ##1##2##3##4##5##6##7##8\relax |
| 23063 |
}}\XINT_cuz_small{ }% |
| 23064 |
% \end{macrocode} |
| 23065 |
% \subsection{\cshnolabel{xintNum}, \csh{xintiNum}} |
| 23066 |
%\begin{lverb} |
| 23067 |
% For example \xintNum {----+-+++---+----000000000000003} |
| 23068 |
% |
| 23069 |
% Very old routine got completely rewritten at 1.2l. |
| 23070 |
% |
| 23071 |
% New code uses \numexpr governed expansion and fixes some issues of former |
| 23072 |
% version particularly regarding inputs of the \numexpr...\relax type without |
| 23073 |
% \the or \number prefix, and/or possibly no terminating \relax. |
| 23074 |
% |
| 23075 |
% \xintiNum{\numexpr 1}\foo in earlier versions caused premature expansion of |
| 23076 |
% \foo. |
| 23077 |
% |
| 23078 |
% \xintiNum{\the\numexpr 1} was ok, but a bit luckily so. |
| 23079 |
% |
| 23080 |
% Also, up to 1.2k inclusive, the macro fetched tokens eight by eight, and not |
| 23081 |
% nine by nine as is done now. I have no idea why. |
| 23082 |
%\end{lverb} |
| 23083 |
% \begin{macrocode} |
| 23084 |
\def\xintiNum {\romannumeral0\xintinum }% |
| 23085 |
\def\xintinum #1% |
| 23086 |
{% |
| 23087 |
\expandafter\XINT_num_cleanup\the\numexpr\expandafter\XINT_num_loop |
| 23088 |
\romannumeral`&&@#1\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint:\Z |
| 23089 |
}% |
| 23090 |
\def\xintNum {\romannumeral0\xintnum }% |
| 23091 |
\let\xintnum\xintinum |
| 23092 |
% \end{macrocode} |
| 23093 |
% Attention |\xintnum| (hence |\xintNum|) gets redefined by |
| 23094 |
% \xintfracnameimp. Click on names to see the redefinition there. |
| 23095 |
% \begin{macrocode} |
| 23096 |
\def\XINT_num #1% |
| 23097 |
{% |
| 23098 |
\expandafter\XINT_num_cleanup\the\numexpr\XINT_num_loop |
| 23099 |
#1\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint:\Z |
| 23100 |
}% |
| 23101 |
\def\XINT_num_loop #1#2#3#4#5#6#7#8#9% |
| 23102 |
{% |
| 23103 |
\xint_gob_til_xint: #9\XINT_num_end\xint: |
| 23104 |
#1#2#3#4#5#6#7#8#9% |
| 23105 |
\ifnum \numexpr #1#2#3#4#5#6#7#8#9+\xint_c_ = \xint_c_ |
| 23106 |
% \end{macrocode} |
| 23107 |
%\begin{lverb} |
| 23108 |
% means that so far only signs encountered, (if syntax is legal) then possibly |
| 23109 |
% zeroes |
| 23110 |
% or a terminated or not terminated \numexpr evaluating to zero |
| 23111 |
% In that latter case a correct zero will be produced in the end. |
| 23112 |
%\end{lverb} |
| 23113 |
% \begin{macrocode} |
| 23114 |
\expandafter\XINT_num_loop |
| 23115 |
\else |
| 23116 |
% \end{macrocode} |
| 23117 |
%\begin{lverb} |
| 23118 |
% non terminated \numexpr (with nine tokens total) are |
| 23119 |
% safe as after \fi, there is then \xint: |
| 23120 |
%\end{lverb} |
| 23121 |
% \begin{macrocode} |
| 23122 |
\expandafter\relax |
| 23123 |
\fi |
| 23124 |
}% |
| 23125 |
\def\XINT_num_end\xint:#1\xint:{#1+\xint_c_\xint:}% empty input ok |
| 23126 |
\def\XINT_num_cleanup #1\xint:#2\Z { #1}% |
| 23127 |
% \end{macrocode} |
| 23128 |
% \subsection{\csh{xintiiSgn}} |
| 23129 |
%\begin{lverb} |
| 23130 |
% 1.2l made \xintiiSgn robust against non terminated input. |
| 23131 |
% |
| 23132 |
% 1.2o deprecates here \xintSgn (it requires xintfrac.sty). |
| 23133 |
%\end{lverb} |
| 23134 |
% \begin{macrocode} |
| 23135 |
\def\xintiiSgn {\romannumeral0\xintiisgn }% |
| 23136 |
\def\xintiisgn #1% |
| 23137 |
{% |
| 23138 |
\expandafter\XINT_sgn \romannumeral`&&@#1\xint: |
| 23139 |
}% |
| 23140 |
\def\XINT_sgn #1#2\xint: |
| 23141 |
{% |
| 23142 |
\xint_UDzerominusfork |
| 23143 |
#1-{ 0}% |
| 23144 |
0#1{-1}% |
| 23145 |
0-{ 1}% |
| 23146 |
\krof |
| 23147 |
}% |
| 23148 |
\def\XINT_Sgn #1#2\xint: |
| 23149 |
{% |
| 23150 |
\xint_UDzerominusfork |
| 23151 |
#1-{0}% |
| 23152 |
0#1{-1}% |
| 23153 |
0-{1}% |
| 23154 |
\krof |
| 23155 |
}% |
| 23156 |
\def\XINT_cntSgn #1#2\xint: |
| 23157 |
{% |
| 23158 |
\xint_UDzerominusfork |
| 23159 |
#1-\xint_c_ |
| 23160 |
0#1\xint_c_mone |
| 23161 |
0-\xint_c_i |
| 23162 |
\krof |
| 23163 |
}% |
| 23164 |
% \end{macrocode} |
| 23165 |
% \subsection{\csh{xintiiOpp}} |
| 23166 |
%\begin{lverb} |
| 23167 |
% Attention, \xintiiOpp non robust against non terminated inputs. |
| 23168 |
% Reason is I don't want to have to grab a delimiter at the end, as everything |
| 23169 |
% happens "upfront". |
| 23170 |
%\end{lverb} |
| 23171 |
% \begin{macrocode} |
| 23172 |
\def\xintiiOpp {\romannumeral0\xintiiopp }% |
| 23173 |
\def\xintiiopp #1% |
| 23174 |
{% |
| 23175 |
\expandafter\XINT_opp \romannumeral`&&@#1% |
| 23176 |
}% |
| 23177 |
\def\XINT_Opp #1{\romannumeral0\XINT_opp #1}% |
| 23178 |
\def\XINT_opp #1% |
| 23179 |
{% |
| 23180 |
\xint_UDzerominusfork |
| 23181 |
#1-{ 0}% zero |
| 23182 |
0#1{ }% negative |
| 23183 |
0-{ -#1}% positive |
| 23184 |
\krof |
| 23185 |
}% |
| 23186 |
% \end{macrocode} |
| 23187 |
% \subsection{\csh{xintiiAbs}} |
| 23188 |
%\begin{lverb} |
| 23189 |
% Attention \xintiiAbs non robust against non terminated input. |
| 23190 |
%\end{lverb} |
| 23191 |
% \begin{macrocode} |
| 23192 |
\def\xintiiAbs {\romannumeral0\xintiiabs }% |
| 23193 |
\def\xintiiabs #1% |
| 23194 |
{% |
| 23195 |
\expandafter\XINT_abs \romannumeral`&&@#1% |
| 23196 |
}% |
| 23197 |
\def\XINT_abs #1% |
| 23198 |
{% |
| 23199 |
\xint_UDsignfork |
| 23200 |
#1{ }% |
| 23201 |
-{ #1}% |
| 23202 |
\krof |
| 23203 |
}% |
| 23204 |
\def\XINT_Abs #1% |
| 23205 |
{% |
| 23206 |
\xint_UDsignfork |
| 23207 |
#1{}% |
| 23208 |
-{#1}% |
| 23209 |
\krof |
| 23210 |
}% |
| 23211 |
% \end{macrocode} |
| 23212 |
% \subsection{\csh{xintFDg}} |
| 23213 |
%\begin{lverb} |
| 23214 |
% FIRST DIGIT. |
| 23215 |
% |
| 23216 |
% 1.2l: \xintiiFDg made robust against non terminated input. |
| 23217 |
% |
| 23218 |
% 1.2o deprecates \xintiiFDg, gives to \xintFDg former meaning of \xintiiFDg. |
| 23219 |
%\end{lverb} |
| 23220 |
% \begin{macrocode} |
| 23221 |
\def\xintFDg {\romannumeral0\xintfdg }% |
| 23222 |
\def\xintfdg #1{\expandafter\XINT_fdg \romannumeral`&&@#1\xint:\Z}% |
| 23223 |
\def\XINT_FDg #1% |
| 23224 |
{\romannumeral0\expandafter\XINT_fdg\romannumeral`&&@\xintnum{#1}\xint:\Z }% |
| 23225 |
\def\XINT_fdg #1#2#3\Z |
| 23226 |
{% |
| 23227 |
\xint_UDzerominusfork |
| 23228 |
#1-{ 0}% zero |
| 23229 |
0#1{ #2}% negative |
| 23230 |
0-{ #1}% positive |
| 23231 |
\krof |
| 23232 |
}% |
| 23233 |
% \end{macrocode} |
| 23234 |
% \subsection{\csh{xintLDg}} |
| 23235 |
%\begin{lverb} |
| 23236 |
% LAST DIGIT. |
| 23237 |
% |
| 23238 |
% Rewritten for 1.2i (2016/12/10). Surprisingly perhaps, it is faster than |
| 23239 |
% \xintLastItem from xintkernel.sty despite the \numexpr operations. |
| 23240 |
% |
| 23241 |
% 1.2o deprecates \xintiiLDg, gives to \xintLDg former meaning of \xintiiLDg. |
| 23242 |
% |
| 23243 |
% Attention \xintLDg non robust against non terminated input. |
| 23244 |
%\end{lverb} |
| 23245 |
% \begin{macrocode} |
| 23246 |
\def\xintLDg {\romannumeral0\xintldg }% |
| 23247 |
\def\xintldg #1{\expandafter\XINT_ldg_fork\romannumeral`&&@#1% |
| 23248 |
\XINT_ldg_c{}{}{}{}{}{}{}{}\xint_bye\relax}% |
| 23249 |
\def\XINT_ldg_fork #1% |
| 23250 |
{% |
| 23251 |
\xint_UDsignfork |
| 23252 |
#1\XINT_ldg |
| 23253 |
-{\XINT_ldg#1}% |
| 23254 |
\krof |
| 23255 |
}% |
| 23256 |
\def\XINT_ldg #1{% |
| 23257 |
\def\XINT_ldg ##1##2##3##4##5##6##7##8##9% |
| 23258 |
{\expandafter#1% |
| 23259 |
\the\numexpr##9##8##7##6##5##4##3##2##1*\xint_c_+\XINT_ldg_a##9}% |
| 23260 |
}\XINT_ldg{ }% |
| 23261 |
\def\XINT_ldg_a#1#2{\XINT_ldg_cbye#2\XINT_ldg_d#1\XINT_ldg_c\XINT_ldg_b#2}% |
| 23262 |
\def\XINT_ldg_b#1#2#3#4#5#6#7#8#9{#9#8#7#6#5#4#3#2#1*\xint_c_+\XINT_ldg_a#9}% |
| 23263 |
\def\XINT_ldg_c #1#2\xint_bye{#1}% |
| 23264 |
\def\XINT_ldg_cbye #1\XINT_ldg_c{}% |
| 23265 |
\def\XINT_ldg_d#1#2\xint_bye{#1}% |
| 23266 |
% \end{macrocode} |
| 23267 |
% |
| 23268 |
% \subsection{\csh{xintDouble}} |
| 23269 |
%\begin{lverb} |
| 23270 |
% Attention \xintDouble non robust against non terminated input. |
| 23271 |
%\end{lverb} |
| 23272 |
% \begin{macrocode} |
| 23273 |
\def\xintDouble {\romannumeral0\xintdouble}% |
| 23274 |
\def\xintdouble #1{\expandafter\XINT_dbl_fork\romannumeral`&&@#1% |
| 23275 |
\xint_bye2345678\xint_bye*\xint_c_ii\relax}% |
| 23276 |
\def\XINT_dbl_fork #1% |
| 23277 |
{% |
| 23278 |
\xint_UDsignfork |
| 23279 |
#1\XINT_dbl_neg |
| 23280 |
-\XINT_dbl |
| 23281 |
\krof #1% |
| 23282 |
}% |
| 23283 |
\def\XINT_dbl_neg-{\expandafter-\romannumeral0\XINT_dbl}% |
| 23284 |
\def\XINT_dbl #1{% |
| 23285 |
\def\XINT_dbl ##1##2##3##4##5##6##7##8% |
| 23286 |
{\expandafter#1\the\numexpr##1##2##3##4##5##6##7##8\XINT_dbl_a}% |
| 23287 |
}\XINT_dbl{ }% |
| 23288 |
\def\XINT_dbl_a #1#2#3#4#5#6#7#8% |
| 23289 |
{\expandafter\XINT_dbl_e\the\numexpr 1#1#2#3#4#5#6#7#8\XINT_dbl_a}% |
| 23290 |
\def\XINT_dbl_e#1{*\xint_c_ii\if#13+\xint_c_i\fi\relax}% |
| 23291 |
% \end{macrocode} |
| 23292 |
% \subsection{\csh{xintHalf}} |
| 23293 |
%\begin{lverb} |
| 23294 |
% Attention \xintHalf non robust against non terminated input. |
| 23295 |
%\end{lverb} |
| 23296 |
% \begin{macrocode} |
| 23297 |
\def\xintHalf {\romannumeral0\xinthalf}% |
| 23298 |
\def\xinthalf #1{\expandafter\XINT_half_fork\romannumeral`&&@#1% |
| 23299 |
\xint_bye\xint_Bye345678\xint_bye |
| 23300 |
*\xint_c_v+\xint_c_v)/\xint_c_x-\xint_c_i\relax}% |
| 23301 |
\def\XINT_half_fork #1% |
| 23302 |
{% |
| 23303 |
\xint_UDsignfork |
| 23304 |
#1\XINT_half_neg |
| 23305 |
-\XINT_half |
| 23306 |
\krof #1% |
| 23307 |
}% |
| 23308 |
\def\XINT_half_neg-{\xintiiopp\XINT_half}% |
| 23309 |
\def\XINT_half #1{% |
| 23310 |
\def\XINT_half ##1##2##3##4##5##6##7##8% |
| 23311 |
{\expandafter#1\the\numexpr(##1##2##3##4##5##6##7##8\XINT_half_a}% |
| 23312 |
}\XINT_half{ }% |
| 23313 |
\def\XINT_half_a#1{\xint_Bye#1\xint_bye\XINT_half_b#1}% |
| 23314 |
\def\XINT_half_b #1#2#3#4#5#6#7#8% |
| 23315 |
{\expandafter\XINT_half_e\the\numexpr(1#1#2#3#4#5#6#7#8\XINT_half_a}% |
| 23316 |
\def\XINT_half_e#1{*\xint_c_v+#1-\xint_c_v)\relax}% |
| 23317 |
% \end{macrocode} |
| 23318 |
% \subsection{\csh{xintInc}} |
| 23319 |
%\begin{lverb} |
| 23320 |
% 1.2i much delayed complete rewrite in 1.2 style. |
| 23321 |
% |
| 23322 |
% As we take 9 by 9 with the input save stack at 5000 this allows a bit less |
| 23323 |
% than 9 times 2500 = 22500 digits on input. |
| 23324 |
% |
| 23325 |
% Attention \xintInc non robust against non terminated input. |
| 23326 |
%\end{lverb} |
| 23327 |
% \begin{macrocode} |
| 23328 |
\def\xintInc {\romannumeral0\xintinc}% |
| 23329 |
\def\xintinc #1{\expandafter\XINT_inc_fork\romannumeral`&&@#1% |
| 23330 |
\xint_bye23456789\xint_bye+\xint_c_i\relax}% |
| 23331 |
\def\XINT_inc_fork #1% |
| 23332 |
{% |
| 23333 |
\xint_UDsignfork |
| 23334 |
#1\XINT_inc_neg |
| 23335 |
-\XINT_inc |
| 23336 |
\krof #1% |
| 23337 |
}% |
| 23338 |
\def\XINT_inc_neg-#1\xint_bye#2\relax |
| 23339 |
{\xintiiopp\XINT_dec #1\XINT_dec_bye234567890\xint_bye}% |
| 23340 |
\def\XINT_inc #1{% |
| 23341 |
\def\XINT_inc ##1##2##3##4##5##6##7##8##9% |
| 23342 |
{\expandafter#1\the\numexpr##1##2##3##4##5##6##7##8##9\XINT_inc_a}% |
| 23343 |
}\XINT_inc{ }% |
| 23344 |
\def\XINT_inc_a #1#2#3#4#5#6#7#8#9% |
| 23345 |
{\expandafter\XINT_inc_e\the\numexpr 1#1#2#3#4#5#6#7#8#9\XINT_inc_a}% |
| 23346 |
\def\XINT_inc_e#1{\if#12+\xint_c_i\fi\relax}% |
| 23347 |
% \end{macrocode} |
| 23348 |
% \subsection{\csh{xintDec}} |
| 23349 |
%\begin{lverb} |
| 23350 |
% 1.2i much delayed complete rewrite in the 1.2 style. Things are a |
| 23351 |
% bit more complicated than \xintInc because 2999999999 is too big for TeX. |
| 23352 |
% |
| 23353 |
% Attention \xintDec non robust against non terminated input. |
| 23354 |
%\end{lverb} |
| 23355 |
% \begin{macrocode} |
| 23356 |
\def\xintDec {\romannumeral0\xintdec}% |
| 23357 |
\def\xintdec #1{\expandafter\XINT_dec_fork\romannumeral`&&@#1% |
| 23358 |
\XINT_dec_bye234567890\xint_bye}% |
| 23359 |
\def\XINT_dec_fork #1% |
| 23360 |
{% |
| 23361 |
\xint_UDsignfork |
| 23362 |
#1\XINT_dec_neg |
| 23363 |
-\XINT_dec |
| 23364 |
\krof #1% |
| 23365 |
}% |
| 23366 |
\def\XINT_dec_neg-#1\XINT_dec_bye#2\xint_bye |
| 23367 |
{\expandafter-% |
| 23368 |
\romannumeral0\XINT_inc #1\xint_bye23456789\xint_bye+\xint_c_i\relax}% |
| 23369 |
\def\XINT_dec #1{% |
| 23370 |
\def\XINT_dec ##1##2##3##4##5##6##7##8##9% |
| 23371 |
{\expandafter#1\the\numexpr##1##2##3##4##5##6##7##8##9\XINT_dec_a}% |
| 23372 |
}\XINT_dec{ }% |
| 23373 |
\def\XINT_dec_a #1#2#3#4#5#6#7#8#9% |
| 23374 |
{\expandafter\XINT_dec_e\the\numexpr 1#1#2#3#4#5#6#7#8#9\XINT_dec_a}% |
| 23375 |
\def\XINT_dec_bye #1\XINT_dec_a#2#3\xint_bye |
| 23376 |
{\if#20-\xint_c_ii\relax+\else-\fi\xint_c_i\relax}% |
| 23377 |
\def\XINT_dec_e#1{\unless\if#11\xint_dothis{-\xint_c_i#1}\fi\xint_orthat\relax}% |
| 23378 |
% \end{macrocode} |
| 23379 |
% \subsection{\csh{xintDSL}} |
| 23380 |
%\begin{lverb} |
| 23381 |
% DECIMAL SHIFT LEFT (=MULTIPLICATION PAR 10). Rewritten for 1.2i. |
| 23382 |
% This was very old code... I never came back to it, but I should have |
| 23383 |
% rewritten it long time ago. |
| 23384 |
% |
| 23385 |
% Attention \xintDSL non robust against non terminated input. |
| 23386 |
%\end{lverb} |
| 23387 |
% \begin{macrocode} |
| 23388 |
\def\xintDSL {\romannumeral0\xintdsl }% |
| 23389 |
\def\xintdsl #1{\expandafter\XINT_dsl\romannumeral`&&@#10}% |
| 23390 |
\def\XINT_dsl#1{% |
| 23391 |
\def\XINT_dsl ##1{\xint_gob_til_zero ##1\xint_dsl_zero 0#1##1}% |
| 23392 |
}\XINT_dsl{ }% |
| 23393 |
\def\xint_dsl_zero 0 0{ }% |
| 23394 |
% \end{macrocode} |
| 23395 |
% \subsection{\csh{xintDSR}} |
| 23396 |
%\begin{lverb} |
| 23397 |
% Decimal shift right, truncates towards zero. Rewritten for 1.2i. |
| 23398 |
% Limited to 22483 digits on input. |
| 23399 |
% |
| 23400 |
% Attention \xintDSR non robust against non terminated input. |
| 23401 |
%\end{lverb} |
| 23402 |
% \begin{macrocode} |
| 23403 |
\def\xintDSR{\romannumeral0\xintdsr}% |
| 23404 |
\def\xintdsr #1{\expandafter\XINT_dsr_fork\romannumeral`&&@#1% |
| 23405 |
\xint_bye\xint_Bye3456789\xint_bye+\xint_c_v)/\xint_c_x-\xint_c_i\relax}% |
| 23406 |
\def\XINT_dsr_fork #1% |
| 23407 |
{% |
| 23408 |
\xint_UDsignfork |
| 23409 |
#1\XINT_dsr_neg |
| 23410 |
-\XINT_dsr |
| 23411 |
\krof #1% |
| 23412 |
}% |
| 23413 |
\def\XINT_dsr_neg-{\xintiiopp\XINT_dsr}% |
| 23414 |
\def\XINT_dsr #1{% |
| 23415 |
\def\XINT_dsr ##1##2##3##4##5##6##7##8##9% |
| 23416 |
{\expandafter#1\the\numexpr(##1##2##3##4##5##6##7##8##9\XINT_dsr_a}% |
| 23417 |
}\XINT_dsr{ }% |
| 23418 |
\def\XINT_dsr_a#1{\xint_Bye#1\xint_bye\XINT_dsr_b#1}% |
| 23419 |
\def\XINT_dsr_b #1#2#3#4#5#6#7#8#9% |
| 23420 |
{\expandafter\XINT_dsr_e\the\numexpr(1#1#2#3#4#5#6#7#8#9\XINT_dsr_a}% |
| 23421 |
\def\XINT_dsr_e #1{)\relax}% |
| 23422 |
% \end{macrocode} |
| 23423 |
% \subsection{\csh{xintDSRr}} |
| 23424 |
%\begin{lverb} |
| 23425 |
% New with 1.2i. Decimal shift right, rounds away from zero; done in |
| 23426 |
% the 1.2 spirit (with much delay, sorry). Used by \xintRound, \xintDivRound. |
| 23427 |
% |
| 23428 |
% This is about the first time I am happy that the division in \numexpr |
| 23429 |
% rounds! |
| 23430 |
% |
| 23431 |
% Attention \xintDSRr non robust against non terminated input. |
| 23432 |
%\end{lverb} |
| 23433 |
% \begin{macrocode} |
| 23434 |
\def\xintDSRr{\romannumeral0\xintdsrr}% |
| 23435 |
\def\xintdsrr #1{\expandafter\XINT_dsrr_fork\romannumeral`&&@#1% |
| 23436 |
\xint_bye\xint_Bye3456789\xint_bye/\xint_c_x\relax}% |
| 23437 |
\def\XINT_dsrr_fork #1% |
| 23438 |
{% |
| 23439 |
\xint_UDsignfork |
| 23440 |
#1\XINT_dsrr_neg |
| 23441 |
-\XINT_dsrr |
| 23442 |
\krof #1% |
| 23443 |
}% |
| 23444 |
\def\XINT_dsrr_neg-{\xintiiopp\XINT_dsrr}% |
| 23445 |
\def\XINT_dsrr #1{% |
| 23446 |
\def\XINT_dsrr ##1##2##3##4##5##6##7##8##9% |
| 23447 |
{\expandafter#1\the\numexpr##1##2##3##4##5##6##7##8##9\XINT_dsrr_a}% |
| 23448 |
}\XINT_dsrr{ }% |
| 23449 |
\def\XINT_dsrr_a#1{\xint_Bye#1\xint_bye\XINT_dsrr_b#1}% |
| 23450 |
\def\XINT_dsrr_b #1#2#3#4#5#6#7#8#9% |
| 23451 |
{\expandafter\XINT_dsrr_e\the\numexpr1#1#2#3#4#5#6#7#8#9\XINT_dsrr_a}% |
| 23452 |
\let\XINT_dsrr_e\XINT_inc_e |
| 23453 |
% \end{macrocode} |
| 23454 |
% \subsection*{Blocks of eight digits} |
| 23455 |
% \addcontentsline{toc}{subsection}{Blocks of eight digits} |
| 23456 |
%\begin{lverb} |
| 23457 |
% The lingua of release 1.2. |
| 23458 |
%\end{lverb} |
| 23459 |
% |
| 23460 |
% \subsection{\csh{XINT_cuz}} |
| 23461 |
%\begin{lverb} |
| 23462 |
% This (launched by \romannumeral0) iterately removes all leading |
| 23463 |
% zeroes from a sequence of 8N digits ended by \R. |
| 23464 |
% |
| 23465 |
% Rewritten for 1.2l, now uses \numexpr governed expansion and \ifnum test |
| 23466 |
% rather than delimited gobbling macros. |
| 23467 |
% |
| 23468 |
% Note 2015/11/28: with only four digits the gob_til_fourzeroes had proved |
| 23469 |
% in some old testing faster than \ifnum test. But with eight digits, the |
| 23470 |
% execution times are much closer, as I tested back then. |
| 23471 |
%\end{lverb} |
| 23472 |
% \begin{macrocode} |
| 23473 |
\def\XINT_cuz #1{% |
| 23474 |
\def\XINT_cuz {\expandafter#1\the\numexpr\XINT_cuz_loop}% |
| 23475 |
}\XINT_cuz{ }% |
| 23476 |
\def\XINT_cuz_loop #1#2#3#4#5#6#7#8#9% |
| 23477 |
{% |
| 23478 |
#1#2#3#4#5#6#7#8% |
| 23479 |
\xint_gob_til_R #9\XINT_cuz_hitend\R |
| 23480 |
\ifnum #1#2#3#4#5#6#7#8>\xint_c_ |
| 23481 |
\expandafter\XINT_cuz_cleantoend |
| 23482 |
\else\expandafter\XINT_cuz_loop |
| 23483 |
\fi #9% |
| 23484 |
}% |
| 23485 |
\def\XINT_cuz_hitend\R #1\R{\relax}% |
| 23486 |
\def\XINT_cuz_cleantoend #1\R{\relax #1}% |
| 23487 |
% \end{macrocode} |
| 23488 |
% \subsection{\csh{XINT_cuz_byviii}} |
| 23489 |
%\begin{lverb} |
| 23490 |
% This removes eight by eight leading zeroes from a sequence of 8N digits |
| 23491 |
% ended by \R. Thus, we still have 8N digits on output. Expansion started by |
| 23492 |
% \romannumeral0 |
| 23493 |
%\end{lverb} |
| 23494 |
% \begin{macrocode} |
| 23495 |
\def\XINT_cuz_byviii #1#2#3#4#5#6#7#8#9% |
| 23496 |
{% |
| 23497 |
\xint_gob_til_R #9\XINT_cuz_byviii_e \R |
| 23498 |
\xint_gob_til_eightzeroes #1#2#3#4#5#6#7#8\XINT_cuz_byviii_z 00000000% |
| 23499 |
\XINT_cuz_byviii_done #1#2#3#4#5#6#7#8#9% |
| 23500 |
}% |
| 23501 |
\def\XINT_cuz_byviii_z 00000000\XINT_cuz_byviii_done 00000000{\XINT_cuz_byviii}% |
| 23502 |
\def\XINT_cuz_byviii_done #1\R { #1}% |
| 23503 |
\def\XINT_cuz_byviii_e\R #1\XINT_cuz_byviii_done #2\R{ #2}% |
| 23504 |
% \end{macrocode} |
| 23505 |
% \subsection{\csh{XINT_unsep_loop}} |
| 23506 |
% |
| 23507 |
%\begin{lverb} |
| 23508 |
% This is used as |
| 23509 |
%( \the\numexpr0\XINT_unsep_loop (blocks of 1<8digits>!)% |
| 23510 |
%: \xint_bye!2!3!4!5!6!7!8!9!\xint_bye\xint_c_i\relax |
| 23511 |
%) |
| 23512 |
% It removes the 1's and !'s, and outputs the 8N digits with a 0 token as |
| 23513 |
% as prefix which will have to be cleaned out by caller. |
| 23514 |
% |
| 23515 |
% Actually it does not matter whether the blocks contain really 8 digits, all |
| 23516 |
% that matters is that they have 1 as first digit (and at most 9 digits after |
| 23517 |
% that to obey the TeX-\numexpr bound). |
| 23518 |
% |
| 23519 |
% Done at 1.2l for usage by other macros. The similar code in earlier releases |
| 23520 |
% was strangely in O(N^2) style, apparently to avoid some memory constraints. |
| 23521 |
% But these memory constraints related to \numexpr chaining seems to be in |
| 23522 |
% many places in xint code base. The 1.2l version is written in the 1.2i style |
| 23523 |
% of \xintInc etc... and is compatible with some 1! block without digits |
| 23524 |
% among the treated blocks, they will disappear. |
| 23525 |
%\end{lverb} |
| 23526 |
% \begin{macrocode} |
| 23527 |
\def\XINT_unsep_loop #1!#2!#3!#4!#5!#6!#7!#8!#9!% |
| 23528 |
{% |
| 23529 |
\expandafter\XINT_unsep_clean |
| 23530 |
\the\numexpr #1\expandafter\XINT_unsep_clean |
| 23531 |
\the\numexpr #2\expandafter\XINT_unsep_clean |
| 23532 |
\the\numexpr #3\expandafter\XINT_unsep_clean |
| 23533 |
\the\numexpr #4\expandafter\XINT_unsep_clean |
| 23534 |
\the\numexpr #5\expandafter\XINT_unsep_clean |
| 23535 |
\the\numexpr #6\expandafter\XINT_unsep_clean |
| 23536 |
\the\numexpr #7\expandafter\XINT_unsep_clean |
| 23537 |
\the\numexpr #8\expandafter\XINT_unsep_clean |
| 23538 |
\the\numexpr #9\XINT_unsep_loop |
| 23539 |
}% |
| 23540 |
\def\XINT_unsep_clean 1{\relax}% |
| 23541 |
% \end{macrocode} |
| 23542 |
% \subsection{\csh{XINT_unsep_cuzsmall}} |
| 23543 |
% |
| 23544 |
%\begin{lverb} |
| 23545 |
% This is used as |
| 23546 |
%( \romannumeral0\XINT_unsep_cuzsmall (blocks of 1<8d>!)% |
| 23547 |
%: \xint_bye!2!3!4!5!6!7!8!9!\xint_bye\xint_c_i\relax |
| 23548 |
%) |
| 23549 |
% It removes the 1's and !'s, and removes the leading zeroes *of |
| 23550 |
% the first block*. |
| 23551 |
% |
| 23552 |
% Redone for 1.2l: the 1.2 variant was strangely in O(N^2) style. |
| 23553 |
%\end{lverb} |
| 23554 |
% \begin{macrocode} |
| 23555 |
\def\XINT_unsep_cuzsmall |
| 23556 |
{% |
| 23557 |
\expandafter\XINT_unsep_cuzsmall_x\the\numexpr0\XINT_unsep_loop |
| 23558 |
}% |
| 23559 |
\def\XINT_unsep_cuzsmall_x #1{% |
| 23560 |
\def\XINT_unsep_cuzsmall_x 0##1##2##3##4##5##6##7##8% |
| 23561 |
{% |
| 23562 |
\expandafter#1\the\numexpr ##1##2##3##4##5##6##7##8\relax |
| 23563 |
}}\XINT_unsep_cuzsmall_x{ }% |
| 23564 |
% \end{macrocode} |
| 23565 |
% \subsection{\csh{XINT_div_unsepQ}} |
| 23566 |
% |
| 23567 |
%\begin{lverb} |
| 23568 |
% This is used by division to remove separators from the produced |
| 23569 |
% quotient. The quotient is produced in the correct order. The routine will |
| 23570 |
% also remove leading zeroes. An extra initial block of 8 zeroes is possible |
| 23571 |
% and thus if present must be removed. Then the next eight digits must be |
| 23572 |
% cleaned of leading zeroes. Attention that there might be a single |
| 23573 |
% block of 8 zeroes. Expansion launched by \romannumeral0. |
| 23574 |
% |
| 23575 |
% Rewritten for 1.2l in 1.2i style. |
| 23576 |
%\end{lverb} |
| 23577 |
% \begin{macrocode} |
| 23578 |
\def\XINT_div_unsepQ_delim {\xint_bye!2!3!4!5!6!7!8!9!\xint_bye\xint_c_i\relax\Z}% |
| 23579 |
\def\XINT_div_unsepQ |
| 23580 |
{% |
| 23581 |
\expandafter\XINT_div_unsepQ_x\the\numexpr0\XINT_unsep_loop |
| 23582 |
}% |
| 23583 |
\def\XINT_div_unsepQ_x #1{% |
| 23584 |
\def\XINT_div_unsepQ_x 0##1##2##3##4##5##6##7##8##9% |
| 23585 |
{% |
| 23586 |
\xint_gob_til_Z ##9\XINT_div_unsepQ_one\Z |
| 23587 |
\xint_gob_til_eightzeroes ##1##2##3##4##5##6##7##8\XINT_div_unsepQ_y 00000000% |
| 23588 |
\expandafter#1\the\numexpr ##1##2##3##4##5##6##7##8\relax ##9% |
| 23589 |
}}\XINT_div_unsepQ_x{ }% |
| 23590 |
\def\XINT_div_unsepQ_y #1{% |
| 23591 |
\def\XINT_div_unsepQ_y ##1\relax ##2##3##4##5##6##7##8##9% |
| 23592 |
{% |
| 23593 |
\expandafter#1\the\numexpr ##2##3##4##5##6##7##8##9\relax |
| 23594 |
}}\XINT_div_unsepQ_y{ }% |
| 23595 |
\def\XINT_div_unsepQ_one#1\expandafter{\expandafter}% |
| 23596 |
% \end{macrocode} |
| 23597 |
% \subsection{\csh{XINT_div_unsepR}} |
| 23598 |
% |
| 23599 |
%\begin{lverb} |
| 23600 |
% This is used by division to remove separators from the produced |
| 23601 |
% remainder. The remainder is here in correct order. It must be cleaned of |
| 23602 |
% leading zeroes, possibly all the way. |
| 23603 |
% |
| 23604 |
% Also rewritten for 1.2l, the 1.2 version was O(N^2) style. |
| 23605 |
% |
| 23606 |
% Terminator \xint_bye!2!3!4!5!6!7!8!9!\xint_bye\xint_c_i\relax\R |
| 23607 |
% |
| 23608 |
% We have a need for something like \R because it is not guaranteed the thing |
| 23609 |
% is not actually zero. |
| 23610 |
%\end{lverb} |
| 23611 |
% \begin{macrocode} |
| 23612 |
\def\XINT_div_unsepR |
| 23613 |
{% |
| 23614 |
\expandafter\XINT_div_unsepR_x\the\numexpr0\XINT_unsep_loop |
| 23615 |
}% |
| 23616 |
\def\XINT_div_unsepR_x#1{% |
| 23617 |
\def\XINT_div_unsepR_x 0{\expandafter#1\the\numexpr\XINT_cuz_loop}% |
| 23618 |
}\XINT_div_unsepR_x{ }% |
| 23619 |
% \end{macrocode} |
| 23620 |
% \subsection{\csh{XINT_zeroes_forviii}} |
| 23621 |
% |
| 23622 |
%\begin{lverb} |
| 23623 |
%( \romannumeral0\XINT_zeroes_forviii #1\R\R\R\R\R\R\R\R{10}0000001\W |
| 23624 |
%) |
| 23625 |
% produces a string of k 0's such that k+length(#1) is smallest bigger multiple |
| 23626 |
% of eight. |
| 23627 |
%\end{lverb} |
| 23628 |
% \begin{macrocode} |
| 23629 |
\def\XINT_zeroes_forviii #1#2#3#4#5#6#7#8% |
| 23630 |
{% |
| 23631 |
\xint_gob_til_R #8\XINT_zeroes_forviii_end\R\XINT_zeroes_forviii |
| 23632 |
}% |
| 23633 |
\def\XINT_zeroes_forviii_end#1{% |
| 23634 |
\def\XINT_zeroes_forviii_end\R\XINT_zeroes_forviii ##1##2##3##4##5##6##7##8##9\W |
| 23635 |
{% |
| 23636 |
\expandafter#1\xint_gob_til_one ##2##3##4##5##6##7##8% |
| 23637 |
}}\XINT_zeroes_forviii_end{ }% |
| 23638 |
% \end{macrocode} |
| 23639 |
% \subsection{\csh{XINT_sepbyviii_Z}} |
| 23640 |
% |
| 23641 |
%\begin{lverb} |
| 23642 |
% This is used as |
| 23643 |
%( \the\numexpr\XINT_sepbyviii_Z <8Ndigits>\XINT_sepbyviii_Z_end 2345678\relax |
| 23644 |
%) |
| 23645 |
% It produces 1<8d>!...1<8d>!1;! |
| 23646 |
% |
| 23647 |
% Prior to 1.2l it used \Z as terminator (hence the name). At 1.2l a switch |
| 23648 |
% to ; was done. This was at a time I thought perhaps I would use an internal |
| 23649 |
% format maintaining such 8 digits blocks, and this had to be compatible with |
| 23650 |
% the \csname...\endcsname encapsulation in \xintexpr parsers. That rationale |
| 23651 |
% is obsolete since 1.4 usage of \expanded in $xintexprnameimp, but if an |
| 23652 |
% internal format is one day used it would be nice to be able to externalize |
| 23653 |
% it easily, so catcode 12 tokens are the most convenient. |
| 23654 |
% |
| 23655 |
% As the expansion is done via successive \numexpr, it is convenient to use |
| 23656 |
% something such as ; which terminates it and stays there. The ! itself would |
| 23657 |
% do. But it proved convenient to have unique ending pattern. I could use |
| 23658 |
% two ! perhaps. |
| 23659 |
%\end{lverb} |
| 23660 |
% \changed{1.4n} |
| 23661 |
%\begin{lverb} |
| 23662 |
% Unfortunately LuaMetaTeX has given to ; and : a meaning as operators inside |
| 23663 |
% its \numexpr. Let's hope ! does not acquire meaning too there. Anyway here |
| 23664 |
% I only need to use \relax;! in \XINT_sepbyviii_Z_end. First step in a tedious |
| 23665 |
% check of the entire codebase... |
| 23666 |
%\end{lverb} |
| 23667 |
% \begin{macrocode} |
| 23668 |
\def\XINT_sepbyviii_Z #1#2#3#4#5#6#7#8% |
| 23669 |
{% |
| 23670 |
1#1#2#3#4#5#6#7#8\expandafter!\the\numexpr\XINT_sepbyviii_Z |
| 23671 |
}% |
| 23672 |
\def\XINT_sepbyviii_Z_end #1\relax {\relax;!}% |
| 23673 |
% \end{macrocode} |
| 23674 |
% \subsection{\csh{XINT_sepbyviii_andcount}} |
| 23675 |
% |
| 23676 |
%\begin{lverb} |
| 23677 |
% This is used as |
| 23678 |
%( \the\numexpr\XINT_sepbyviii_andcount <8Ndigits>$% |
| 23679 |
%: \XINT_sepbyviii_end 2345678\relax |
| 23680 |
%: \xint_c_vii!\xint_c_vi!\xint_c_v!\xint_c_iv!$% |
| 23681 |
%: \xint_c_iii!\xint_c_ii!\xint_c_i!\xint_c_\W |
| 23682 |
%) |
| 23683 |
% It will produce |
| 23684 |
%( 1<8d>!1<8d>!....1<8d>!1\xint:<count of blocks>\xint: |
| 23685 |
%) |
| 23686 |
% Used by |
| 23687 |
% \XINT_div_prepare_g for \XINT_div_prepare_h, and also by \xintiiCmp. |
| 23688 |
%\end{lverb} |
| 23689 |
% \begin{macrocode} |
| 23690 |
\def\XINT_sepbyviii_andcount |
| 23691 |
{% |
| 23692 |
\expandafter\XINT_sepbyviii_andcount_a\the\numexpr\XINT_sepbyviii |
| 23693 |
}% |
| 23694 |
\def\XINT_sepbyviii #1#2#3#4#5#6#7#8% |
| 23695 |
{% |
| 23696 |
1#1#2#3#4#5#6#7#8\expandafter!\the\numexpr\XINT_sepbyviii |
| 23697 |
}% |
| 23698 |
\def\XINT_sepbyviii_end #1\relax {\relax\XINT_sepbyviii_andcount_end!}% |
| 23699 |
\def\XINT_sepbyviii_andcount_a {\XINT_sepbyviii_andcount_b \xint_c_\xint:}% |
| 23700 |
\def\XINT_sepbyviii_andcount_b #1\xint:#2!#3!#4!#5!#6!#7!#8!#9!% |
| 23701 |
{% |
| 23702 |
#2\expandafter!\the\numexpr#3\expandafter!\the\numexpr#4\expandafter |
| 23703 |
!\the\numexpr#5\expandafter!\the\numexpr#6\expandafter!\the\numexpr |
| 23704 |
#7\expandafter!\the\numexpr#8\expandafter!\the\numexpr#9\expandafter!\the\numexpr |
| 23705 |
\expandafter\XINT_sepbyviii_andcount_b\the\numexpr #1+\xint_c_viii\xint:% |
| 23706 |
}% |
| 23707 |
\def\XINT_sepbyviii_andcount_end #1\XINT_sepbyviii_andcount_b\the\numexpr |
| 23708 |
#2+\xint_c_viii\xint:#3#4\W {\expandafter\xint:\the\numexpr #2+#3\xint:}% |
| 23709 |
% \end{macrocode} |
| 23710 |
% \subsection{\csh{XINT_rsepbyviii}} |
| 23711 |
% |
| 23712 |
%\begin{lverb} |
| 23713 |
% This is used as |
| 23714 |
%( \the\numexpr1\XINT_rsepbyviii <8Ndigits>$% |
| 23715 |
%: \XINT_rsepbyviii_end_A 2345678$% |
| 23716 |
%: \XINT_rsepbyviii_end_B 2345678\relax UV$% |
| 23717 |
%) |
| 23718 |
% and will produce |
| 23719 |
%( 1<8digits>!1<8digits>\xint:1<8digits>!... |
| 23720 |
%) |
| 23721 |
% where the original |
| 23722 |
% digits are organized by eight, and the order inside successive pairs of |
| 23723 |
% blocks separated by \xint: has been reversed. Output ends either in |
| 23724 |
% 1<8d>!1<8d>\xint:1U\xint: (even) or 1<8d>!1<8d>\xint:1V!1<8d>\xint: (odd) |
| 23725 |
% |
| 23726 |
% The U an V should be \numexpr1 stoppers (or will expand and be ended by !). |
| 23727 |
% This macro is currently (1.2..1.2l) exclusively used in combination with |
| 23728 |
% \XINT_sepandrev_andcount or \XINT_sepandrev. |
| 23729 |
%\end{lverb} |
| 23730 |
% \begin{macrocode} |
| 23731 |
\def\XINT_rsepbyviii #1#2#3#4#5#6#7#8% |
| 23732 |
{% |
| 23733 |
\XINT_rsepbyviii_b {#1#2#3#4#5#6#7#8}% |
| 23734 |
}% |
| 23735 |
\def\XINT_rsepbyviii_b #1#2#3#4#5#6#7#8#9% |
| 23736 |
{% |
| 23737 |
#2#3#4#5#6#7#8#9\expandafter!\the\numexpr |
| 23738 |
1#1\expandafter\xint:\the\numexpr 1\XINT_rsepbyviii |
| 23739 |
}% |
| 23740 |
\def\XINT_rsepbyviii_end_B #1\relax #2#3{#2\xint:}% |
| 23741 |
\def\XINT_rsepbyviii_end_A #11#2\expandafter #3\relax #4#5{#5!1#2\xint:}% |
| 23742 |
% \end{macrocode} |
| 23743 |
% \subsection{\csh{XINT_sepandrev}} |
| 23744 |
%\begin{lverb} |
| 23745 |
% This is used typically as |
| 23746 |
%( \romannumeral0\XINT_sepandrev <8Ndigits>$% |
| 23747 |
%: \XINT_rsepbyviii_end_A 2345678$% |
| 23748 |
%: \XINT_rsepbyviii_end_B 2345678\relax UV$% |
| 23749 |
%: \R\xint:\R\xint:\R\xint:\R\xint:\R\xint:\R\xint:\R\xint:\R\xint:\W |
| 23750 |
%) |
| 23751 |
% and will produce |
| 23752 |
%( 1<8digits>!1<8digits>!1<8digits>!... |
| 23753 |
%) |
| 23754 |
% where the blocks have |
| 23755 |
% been globally reversed. The UV here are only place holders (must be \numexpr1 |
| 23756 |
% stoppers) to share same |
| 23757 |
% syntax as \XINT_sepandrev_andcount, they are gobbled (#2 in \XINT_sepandrev_done). |
| 23758 |
%\end{lverb} |
| 23759 |
% \begin{macrocode} |
| 23760 |
\def\XINT_sepandrev |
| 23761 |
{% |
| 23762 |
\expandafter\XINT_sepandrev_a\the\numexpr 1\XINT_rsepbyviii |
| 23763 |
}% |
| 23764 |
\def\XINT_sepandrev_a {\XINT_sepandrev_b {}}% |
| 23765 |
\def\XINT_sepandrev_b #1#2\xint:#3\xint:#4\xint:#5\xint:#6\xint:#7\xint:#8\xint:#9\xint:% |
| 23766 |
{% |
| 23767 |
\xint_gob_til_R #9\XINT_sepandrev_end\R |
| 23768 |
\XINT_sepandrev_b {#9!#8!#7!#6!#5!#4!#3!#2!#1}% |
| 23769 |
}% |
| 23770 |
\def\XINT_sepandrev_end\R\XINT_sepandrev_b #1#2\W {\XINT_sepandrev_done #1}% |
| 23771 |
\def\XINT_sepandrev_done #11#2!{ }% |
| 23772 |
% \end{macrocode} |
| 23773 |
% \subsection{\csh{XINT_sepandrev_andcount}} |
| 23774 |
%\begin{lverb} |
| 23775 |
% This is used typically as |
| 23776 |
%( \romannumeral0\XINT_sepandrev_andcount <8Ndigits>$% |
| 23777 |
%: \XINT_rsepbyviii_end_A 2345678$% |
| 23778 |
%: \XINT_rsepbyviii_end_B 2345678\relax\xint_c_ii\xint_c_i |
| 23779 |
%: \R\xint:\xint_c_xii \R\xint:\xint_c_x \R\xint:\xint_c_viii \R\xint:\xint_c_vi |
| 23780 |
%: \R\xint:\xint_c_iv \R\xint:\xint_c_ii \R\xint:\xint_c_\W |
| 23781 |
%) |
| 23782 |
% and will produce |
| 23783 |
%( <length>.1<8digits>!1<8digits>!1<8digits>!... |
| 23784 |
%) |
| 23785 |
% where the |
| 23786 |
% blocks have been globally reversed and <length> is the number of blocks. |
| 23787 |
%\end{lverb} |
| 23788 |
% \begin{macrocode} |
| 23789 |
\def\XINT_sepandrev_andcount |
| 23790 |
{% |
| 23791 |
\expandafter\XINT_sepandrev_andcount_a\the\numexpr 1\XINT_rsepbyviii |
| 23792 |
}% |
| 23793 |
\def\XINT_sepandrev_andcount_a {\XINT_sepandrev_andcount_b 0!{}}% |
| 23794 |
\def\XINT_sepandrev_andcount_b #1!#2#3\xint:#4\xint:#5\xint:#6\xint:#7\xint:#8\xint:#9\xint:% |
| 23795 |
{% |
| 23796 |
\xint_gob_til_R #9\XINT_sepandrev_andcount_end\R |
| 23797 |
\expandafter\XINT_sepandrev_andcount_b \the\numexpr #1+\xint_c_i!% |
| 23798 |
{#9!#8!#7!#6!#5!#4!#3!#2}% |
| 23799 |
}% |
| 23800 |
\def\XINT_sepandrev_andcount_end\R |
| 23801 |
\expandafter\XINT_sepandrev_andcount_b\the\numexpr #1+\xint_c_i!#2#3#4\W |
| 23802 |
{\expandafter\XINT_sepandrev_andcount_done\the\numexpr #3+\xint_c_xiv*#1!#2}% |
| 23803 |
\def\XINT_sepandrev_andcount_done#1{% |
| 23804 |
\def\XINT_sepandrev_andcount_done##1!##21##3!{\expandafter#1\the\numexpr##1-##3\xint:}% |
| 23805 |
}\XINT_sepandrev_andcount_done{ }% |
| 23806 |
% \end{macrocode} |
| 23807 |
% \subsection{\csh{XINT_rev_nounsep}} |
| 23808 |
%\begin{lverb} |
| 23809 |
% This is used as |
| 23810 |
%( \romannumeral0\XINT_rev_nounsep {}<blocks 1<8d>!>\R!\R!\R!\R!\R!\R!\R!\R!\W |
| 23811 |
%) |
| 23812 |
% It reverses the blocks, keeping the 1's and ! separators. Used multiple |
| 23813 |
% times in the division algorithm. The inserted {} here is not optional. |
| 23814 |
%\end{lverb} |
| 23815 |
% \begin{macrocode} |
| 23816 |
\def\XINT_rev_nounsep #1#2!#3!#4!#5!#6!#7!#8!#9!% |
| 23817 |
{% |
| 23818 |
\xint_gob_til_R #9\XINT_rev_nounsep_end\R |
| 23819 |
\XINT_rev_nounsep {#9!#8!#7!#6!#5!#4!#3!#2!#1}% |
| 23820 |
}% |
| 23821 |
\def\XINT_rev_nounsep_end\R\XINT_rev_nounsep #1#2\W {\XINT_rev_nounsep_done #1}% |
| 23822 |
\def\XINT_rev_nounsep_done #11{ 1}% |
| 23823 |
% \end{macrocode} |
| 23824 |
% \subsection{\csh{XINT_unrevbyviii}} |
| 23825 |
%\begin{lverb} |
| 23826 |
% Used as \romannumeral0\XINT_unrevbyviii 1<8d>!....1<8d>! terminated |
| 23827 |
% by |
| 23828 |
%( 1;!1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W |
| 23829 |
%) |
| 23830 |
% The \romannumeral in unrevbyviii_a is for special effects (expand some token |
| 23831 |
% which was put as 1<token>! at the end of the original blocks). This |
| 23832 |
% mechanism is used by 1.2 subtraction (still true for 1.2l). |
| 23833 |
%\end{lverb} |
| 23834 |
% \begin{macrocode} |
| 23835 |
\def\XINT_unrevbyviii #11#2!1#3!1#4!1#5!1#6!1#7!1#8!1#9!% |
| 23836 |
{% |
| 23837 |
\xint_gob_til_R #9\XINT_unrevbyviii_a\R |
| 23838 |
\XINT_unrevbyviii {#9#8#7#6#5#4#3#2#1}% |
| 23839 |
}% |
| 23840 |
\def\XINT_unrevbyviii_a#1{% |
| 23841 |
\def\XINT_unrevbyviii_a\R\XINT_unrevbyviii ##1##2\W |
| 23842 |
{\expandafter#1\romannumeral`&&@\xint_gob_til_sc ##1}% |
| 23843 |
}\XINT_unrevbyviii_a{ }% |
| 23844 |
% \end{macrocode} |
| 23845 |
%\begin{lverb} |
| 23846 |
% Can work with shorter ending pattern: 1;!1\R!1\R!1\R!1\R!1\R!1\R!\W |
| 23847 |
% but the longer one of unrevbyviii is ok here too. Used currently (1.2) only |
| 23848 |
% by addition, now (1.2c) with long ending pattern. Does the final clean up of |
| 23849 |
% leading zeroes contrarily to general \XINT_unrevbyviii. |
| 23850 |
%\end{lverb} |
| 23851 |
% \begin{macrocode} |
| 23852 |
\def\XINT_smallunrevbyviii 1#1!1#2!1#3!1#4!1#5!1#6!1#7!1#8!#9\W% |
| 23853 |
{% |
| 23854 |
\expandafter\XINT_cuz_small\xint_gob_til_sc #8#7#6#5#4#3#2#1% |
| 23855 |
}% |
| 23856 |
% \end{macrocode} |
| 23857 |
% \subsection*{Core arithmetic} |
| 23858 |
% \addcontentsline{toc}{subsection}{Core arithmetic} |
| 23859 |
%\begin{lverb} |
| 23860 |
% The four operations have been rewritten entirely for release 1.2. |
| 23861 |
% The new routines works with separated blocks of eight digits. They all measure |
| 23862 |
% first the lengths of the arguments, even addition and subtraction (this was |
| 23863 |
% not the case with $xintcorenameimp 1.1 or earlier.) |
| 23864 |
% |
| 23865 |
% The technique of chaining \the\numexpr induces a limitation on the |
| 23866 |
% maximal size depending on the size of the input save stack and the maximum |
| 23867 |
% expansion depth. |
| 23868 |
%\end{lverb} |
| 23869 |
%\begin{lverb} |
| 23870 |
% Side remark: I tested that \the\numexpr was more efficient than \number. But |
| 23871 |
% it reduced the allowable numbers for addition from 19976 digits to 19968 |
| 23872 |
% digits. |
| 23873 |
% |
| 23874 |
% 2025 update: both with 1.2 and 1.4m, using TeXLive 2025 (input stack size |
| 23875 |
% and expansion depth both at 10000) the maximal input size for addition is |
| 23876 |
% observed to be at 26648 (it was at 19968 with input stack size at 5000 still |
| 23877 |
% in 2021 with 1.4d) and the one for multiplication (or rather squaring) is |
| 23878 |
% 13320, i.e. about half which sounds logical. In both cases, the expansion |
| 23879 |
% depth is the limiting factor. The macro expansion is tested within an |
| 23880 |
% \edef. |
| 23881 |
% |
| 23882 |
% During the ten years after 1.2 release it seems we indicated here a wrong |
| 23883 |
% value for the maximal input size for multiplication, perhaps a confusion |
| 23884 |
% between input and output size was made at that time. Sorry (but nobody reads |
| 23885 |
% this anyhow). |
| 23886 |
%\end{lverb} |
| 23887 |
% |
| 23888 |
% \subsection{\csh{xintiiAdd}} |
| 23889 |
%\begin{lverb} |
| 23890 |
% 1.2l: \xintiiAdd made robust against non terminated input. |
| 23891 |
%\end{lverb} |
| 23892 |
% \begin{macrocode} |
| 23893 |
\def\xintiiAdd {\romannumeral0\xintiiadd }% |
| 23894 |
\def\xintiiadd #1{\expandafter\XINT_iiadd\romannumeral`&&@#1\xint:}% |
| 23895 |
\def\XINT_iiadd #1#2\xint:#3% |
| 23896 |
{% |
| 23897 |
\expandafter\XINT_add_nfork\expandafter#1\romannumeral`&&@#3\xint:#2\xint: |
| 23898 |
}% |
| 23899 |
\def\XINT_add_fork #1#2\xint:#3\xint:{\XINT_add_nfork #1#3\xint:#2\xint:}% |
| 23900 |
\def\XINT_add_nfork #1#2% |
| 23901 |
{% |
| 23902 |
\xint_UDzerofork |
| 23903 |
#1\XINT_add_firstiszero |
| 23904 |
#2\XINT_add_secondiszero |
| 23905 |
0{}% |
| 23906 |
\krof |
| 23907 |
\xint_UDsignsfork |
| 23908 |
#1#2\XINT_add_minusminus |
| 23909 |
#1-\XINT_add_minusplus |
| 23910 |
#2-\XINT_add_plusminus |
| 23911 |
--\XINT_add_plusplus |
| 23912 |
\krof #1#2% |
| 23913 |
}% |
| 23914 |
\def\XINT_add_firstiszero #1\krof 0#2#3\xint:#4\xint:{ #2#3}% |
| 23915 |
\def\XINT_add_secondiszero #1\krof #20#3\xint:#4\xint:{ #2#4}% |
| 23916 |
\def\XINT_add_minusminus #1#2% |
| 23917 |
{\expandafter-\romannumeral0\XINT_add_pp_a {}{}}% |
| 23918 |
\def\XINT_add_minusplus #1#2{\XINT_sub_mm_a {}#2}% |
| 23919 |
\def\XINT_add_plusminus #1#2% |
| 23920 |
{\expandafter\XINT_opp\romannumeral0\XINT_sub_mm_a #1{}}% |
| 23921 |
\def\XINT_add_pp_a #1#2#3\xint: |
| 23922 |
{% |
| 23923 |
\expandafter\XINT_add_pp_b |
| 23924 |
\romannumeral0\expandafter\XINT_sepandrev_andcount |
| 23925 |
\romannumeral0\XINT_zeroes_forviii #2#3\R\R\R\R\R\R\R\R{10}0000001\W |
| 23926 |
#2#3\XINT_rsepbyviii_end_A 2345678% |
| 23927 |
\XINT_rsepbyviii_end_B 2345678\relax\xint_c_ii\xint_c_i |
| 23928 |
\R\xint:\xint_c_xii \R\xint:\xint_c_x \R\xint:\xint_c_viii \R\xint:\xint_c_vi |
| 23929 |
\R\xint:\xint_c_iv \R\xint:\xint_c_ii \R\xint:\xint_c_\W |
| 23930 |
\X #1% |
| 23931 |
}% |
| 23932 |
\let\XINT_add_plusplus \XINT_add_pp_a |
| 23933 |
\def\XINT_add_pp_b #1\xint:#2\X #3\xint: |
| 23934 |
{% |
| 23935 |
\expandafter\XINT_add_checklengths |
| 23936 |
\the\numexpr #1\expandafter\xint:% |
| 23937 |
\romannumeral0\expandafter\XINT_sepandrev_andcount |
| 23938 |
\romannumeral0\XINT_zeroes_forviii #3\R\R\R\R\R\R\R\R{10}0000001\W |
| 23939 |
#3\XINT_rsepbyviii_end_A 2345678% |
| 23940 |
\XINT_rsepbyviii_end_B 2345678\relax\xint_c_ii\xint_c_i |
| 23941 |
\R\xint:\xint_c_xii \R\xint:\xint_c_x \R\xint:\xint_c_viii \R\xint:\xint_c_vi |
| 23942 |
\R\xint:\xint_c_iv \R\xint:\xint_c_ii \R\xint:\xint_c_\W |
| 23943 |
1;!1;!1;!1;!\W #21;!1;!1;!1;!\W |
| 23944 |
1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W |
| 23945 |
}% |
| 23946 |
% \end{macrocode} |
| 23947 |
%\begin{lverb} |
| 23948 |
% I keep #1.#2. to check if at most 6 + 6 base 10^8 digits which can be |
| 23949 |
% treated faster for final reverse. But is this overhead at all useful ? |
| 23950 |
%\end{lverb} |
| 23951 |
% \begin{macrocode} |
| 23952 |
\def\XINT_add_checklengths #1\xint:#2\xint:% |
| 23953 |
{% |
| 23954 |
\ifnum #2>#1 |
| 23955 |
\expandafter\XINT_add_exchange |
| 23956 |
\else |
| 23957 |
\expandafter\XINT_add_A |
| 23958 |
\fi |
| 23959 |
#1\xint:#2\xint:% |
| 23960 |
}% |
| 23961 |
\def\XINT_add_exchange #1\xint:#2\xint:#3\W #4\W |
| 23962 |
{% |
| 23963 |
\XINT_add_A #2\xint:#1\xint:#4\W #3\W |
| 23964 |
}% |
| 23965 |
\def\XINT_add_A #1\xint:#2\xint:% |
| 23966 |
{% |
| 23967 |
\ifnum #1>\xint_c_vi |
| 23968 |
\expandafter\XINT_add_aa |
| 23969 |
\else \expandafter\XINT_add_aa_small |
| 23970 |
\fi |
| 23971 |
}% |
| 23972 |
\def\XINT_add_aa {\expandafter\XINT_add_out\the\numexpr\XINT_add_a \xint_c_ii}% |
| 23973 |
\def\XINT_add_out{\expandafter\XINT_cuz_small\romannumeral0\XINT_unrevbyviii {}}% |
| 23974 |
\def\XINT_add_aa_small |
| 23975 |
{\expandafter\XINT_smallunrevbyviii\the\numexpr\XINT_add_a \xint_c_ii}% |
| 23976 |
% \end{macrocode} |
| 23977 |
%\begin{lverb} |
| 23978 |
% 2 as first token of #1 stands for "no carry", 3 will mean a carry (we |
| 23979 |
% are adding 1<8digits> to 1<8digits>.) Version 1.2c has terminators of the |
| 23980 |
% shape 1;!, replacing the \Z! used in 1.2. |
| 23981 |
% |
| 23982 |
% Call: \the\numexpr\XINT_add_a 2#11;!1;!1;!1;!\W #21;!1;!1;!1;!\W |
| 23983 |
% where #1 and #2 are blocks of 1<8d>!, and #1 is at most as long as #2. This |
| 23984 |
% last requirement is a bit annoying (if one wants to do recursive algorithms |
| 23985 |
% but not have to check lengths), and I will probably remove it at some point. |
| 23986 |
% |
| 23987 |
% Output: blocks of 1<8d>! representing the addition, (least significant |
| 23988 |
% first), and a final 1;!. In recursive algorithm this 1;! terminator can |
| 23989 |
% thus conveniently be reused as part of input terminator (up to the length |
| 23990 |
% problem). |
| 23991 |
% |
| 23992 |
%\end{lverb} |
| 23993 |
% \begin{macrocode} |
| 23994 |
\def\XINT_add_a #1!#2!#3!#4!#5\W |
| 23995 |
#6!#7!#8!#9!% |
| 23996 |
{% |
| 23997 |
\XINT_add_b |
| 23998 |
#1!#6!#2!#7!#3!#8!#4!#9!% |
| 23999 |
#5\W |
| 24000 |
}% |
| 24001 |
\def\XINT_add_b #11#2#3!#4!% |
| 24002 |
{% |
| 24003 |
\xint_gob_til_sc #2\XINT_add_bi ;% |
| 24004 |
\expandafter\XINT_add_c\the\numexpr#1+1#2#3+#4-\xint_c_ii\xint:% |
| 24005 |
}% |
| 24006 |
\def\XINT_add_bi;\expandafter\XINT_add_c |
| 24007 |
\the\numexpr#1+#2+#3-\xint_c_ii\xint:#4!#5!#6!#7!#8!#9!\W |
| 24008 |
{% |
| 24009 |
\XINT_add_k #1#3!#5!#7!#9!% |
| 24010 |
}% |
| 24011 |
\def\XINT_add_c #1#2\xint:% |
| 24012 |
{% |
| 24013 |
1#2\expandafter!\the\numexpr\XINT_add_d #1% |
| 24014 |
}% |
| 24015 |
\def\XINT_add_d #11#2#3!#4!% |
| 24016 |
{% |
| 24017 |
\xint_gob_til_sc #2\XINT_add_di ;% |
| 24018 |
\expandafter\XINT_add_e\the\numexpr#1+1#2#3+#4-\xint_c_ii\xint:% |
| 24019 |
}% |
| 24020 |
\def\XINT_add_di;\expandafter\XINT_add_e |
| 24021 |
\the\numexpr#1+#2+#3-\xint_c_ii\xint:#4!#5!#6!#7!#8\W |
| 24022 |
{% |
| 24023 |
\XINT_add_k #1#3!#5!#7!% |
| 24024 |
}% |
| 24025 |
\def\XINT_add_e #1#2\xint:% |
| 24026 |
{% |
| 24027 |
1#2\expandafter!\the\numexpr\XINT_add_f #1% |
| 24028 |
}% |
| 24029 |
\def\XINT_add_f #11#2#3!#4!% |
| 24030 |
{% |
| 24031 |
\xint_gob_til_sc #2\XINT_add_fi ;% |
| 24032 |
\expandafter\XINT_add_g\the\numexpr#1+1#2#3+#4-\xint_c_ii\xint:% |
| 24033 |
}% |
| 24034 |
\def\XINT_add_fi;\expandafter\XINT_add_g |
| 24035 |
\the\numexpr#1+#2+#3-\xint_c_ii\xint:#4!#5!#6\W |
| 24036 |
{% |
| 24037 |
\XINT_add_k #1#3!#5!% |
| 24038 |
}% |
| 24039 |
\def\XINT_add_g #1#2\xint:% |
| 24040 |
{% |
| 24041 |
1#2\expandafter!\the\numexpr\XINT_add_h #1% |
| 24042 |
}% |
| 24043 |
\def\XINT_add_h #11#2#3!#4!% |
| 24044 |
{% |
| 24045 |
\xint_gob_til_sc #2\XINT_add_hi ;% |
| 24046 |
\expandafter\XINT_add_i\the\numexpr#1+1#2#3+#4-\xint_c_ii\xint:% |
| 24047 |
}% |
| 24048 |
\def\XINT_add_hi;% |
| 24049 |
\expandafter\XINT_add_i\the\numexpr#1+#2+#3-\xint_c_ii\xint:#4\W |
| 24050 |
{% |
| 24051 |
\XINT_add_k #1#3!% |
| 24052 |
}% |
| 24053 |
\def\XINT_add_i #1#2\xint:% |
| 24054 |
{% |
| 24055 |
1#2\expandafter!\the\numexpr\XINT_add_a #1% |
| 24056 |
}% |
| 24057 |
\def\XINT_add_k #1{\if #12\expandafter\XINT_add_ke\else\expandafter\XINT_add_l \fi}% |
| 24058 |
\def\XINT_add_ke #11;#2\W {\XINT_add_kf #11;!}% |
| 24059 |
\def\XINT_add_kf 1{1\relax }% |
| 24060 |
\def\XINT_add_l 1#1#2{\xint_gob_til_sc #1\XINT_add_lf ;\XINT_add_m 1#1#2}% |
| 24061 |
\def\XINT_add_lf #1\W {1\relax 00000001!1;!}% |
| 24062 |
\def\XINT_add_m #1!{\expandafter\XINT_add_n\the\numexpr\xint_c_i+#1\xint:}% |
| 24063 |
\def\XINT_add_n #1#2\xint:{1#2\expandafter!\the\numexpr\XINT_add_o #1}% |
| 24064 |
% \end{macrocode} |
| 24065 |
%\begin{lverb} |
| 24066 |
% Here 2 stands for "carry", and 1 for "no carry" (we have been adding |
| 24067 |
% 1 to 1<8digits>.) |
| 24068 |
%\end{lverb} |
| 24069 |
% \begin{macrocode} |
| 24070 |
\def\XINT_add_o #1{\if #12\expandafter\XINT_add_l\else\expandafter\XINT_add_ke \fi}% |
| 24071 |
% \end{macrocode} |
| 24072 |
% \subsection{\csh{xintiiCmp}} |
| 24073 |
% \changed[2022/06/05]{1.4m} |
| 24074 |
% Now uses the |\xintstrcmp| engine primitive. |
| 24075 |
% \begin{macrocode} |
| 24076 |
\def\xintiiCmp {\romannumeral0\xintiicmp }% |
| 24077 |
\def\xintiicmp #1{\expandafter\XINT_iicmp\romannumeral`&&@#1\xint:}% |
| 24078 |
\def\XINT_iicmp #1#2\xint:#3% |
| 24079 |
{% |
| 24080 |
\expandafter\XINT_cmp_nfork\expandafter #1\romannumeral`&&@#3\xint:#2\xint: |
| 24081 |
}% |
| 24082 |
\def\XINT_cmp_nfork #1#2% |
| 24083 |
{% |
| 24084 |
\xint_UDzerofork |
| 24085 |
#1\XINT_cmp_firstiszero |
| 24086 |
#2\XINT_cmp_secondiszero |
| 24087 |
0{}% |
| 24088 |
\krof |
| 24089 |
\xint_UDsignsfork |
| 24090 |
#1#2\XINT_cmp_minusminus |
| 24091 |
#1-\XINT_cmp_minusplus |
| 24092 |
#2-\XINT_cmp_plusminus |
| 24093 |
--\XINT_cmp_plusplus |
| 24094 |
\krof #1#2% |
| 24095 |
}% |
| 24096 |
\def\XINT_cmp_firstiszero #1\krof 0#2#3\xint:#4\xint: |
| 24097 |
{% |
| 24098 |
\xint_UDzerominusfork |
| 24099 |
#2-{ 0}% |
| 24100 |
0#2{ 1}% |
| 24101 |
0-{ -1}% |
| 24102 |
\krof |
| 24103 |
}% |
| 24104 |
\def\XINT_cmp_secondiszero #1\krof #20#3\xint:#4\xint: |
| 24105 |
{% |
| 24106 |
\xint_UDzerominusfork |
| 24107 |
#2-{ 0}% |
| 24108 |
0#2{ -1}% |
| 24109 |
0-{ 1}% |
| 24110 |
\krof |
| 24111 |
}% |
| 24112 |
\def\XINT_cmp_plusminus #1\xint:#2\xint:{ 1}% |
| 24113 |
\def\XINT_cmp_minusplus #1\xint:#2\xint:{ -1}% |
| 24114 |
\def\XINT_cmp_minusminus |
| 24115 |
--{\expandafter\XINT_opp\romannumeral0\XINT_cmp_plusplus {}{}}% |
| 24116 |
% \end{macrocode} |
| 24117 |
%\begin{lverb} |
| 24118 |
% The \romannumeral0 trigger induces some complications here to terminate |
| 24119 |
% nicely without grabbing too many tokens in the stream or deteriorating |
| 24120 |
% expansion quality of the non-equal-length branches. |
| 24121 |
% \expanded simplifies things. |
| 24122 |
%\end{lverb} |
| 24123 |
% \begin{macrocode} |
| 24124 |
\def\XINT_cmp_plusplus #1#2#3\xint:#4\xint:{\expanded{ % |
| 24125 |
\ifcase\expandafter\XINT_cntSgn\the\numexpr\xintLength{#1#4}-\xintLength{#2#3}\xint: |
| 24126 |
\xintstrcmp{#1#4}{#2#3}\or1\else-1\fi |
| 24127 |
}% |
| 24128 |
}% |
| 24129 |
% \end{macrocode} |
| 24130 |
% Prior to |1.4m| the «strcmp» primitive was not used by \xintcorenameimp. |
| 24131 |
% Here is the old implementation: |
| 24132 |
%\begin{lverb} |
| 24133 |
%( \def\XINT_cmp_plusplus #1#2#3\xint: |
| 24134 |
%: {$% |
| 24135 |
%: \expandafter\XINT_cmp_pp |
| 24136 |
%: \the\numexpr\expandafter\XINT_sepbyviii_andcount |
| 24137 |
%: \romannumeral0\XINT_zeroes_forviii #2#3\R\R\R\R\R\R\R\R{10}0000001\W |
| 24138 |
%: #2#3\XINT_sepbyviii_end 2345678\relax |
| 24139 |
%: \xint_c_vii!\xint_c_vi!\xint_c_v!\xint_c_iv!$% |
| 24140 |
%: \xint_c_iii!\xint_c_ii!\xint_c_i!\xint_c_\W |
| 24141 |
%: #1$% |
| 24142 |
%: }$% |
| 24143 |
%: \def\XINT_cmp_pp #1\xint:#2\xint:#3\xint: |
| 24144 |
%: {$% |
| 24145 |
%: \expandafter\XINT_cmp_checklengths |
| 24146 |
%: \the\numexpr #2\expandafter\xint:$% |
| 24147 |
%: \the\numexpr\expandafter\XINT_sepbyviii_andcount |
| 24148 |
%: \romannumeral0\XINT_zeroes_forviii #3\R\R\R\R\R\R\R\R{10}0000001\W |
| 24149 |
%: #3\XINT_sepbyviii_end 2345678\relax |
| 24150 |
%: \xint_c_vii!\xint_c_vi!\xint_c_v!\xint_c_iv!$% |
| 24151 |
%: \xint_c_iii!\xint_c_ii!\xint_c_i!\xint_c_\W |
| 24152 |
%: #1;!1;!1;!1;!\W |
| 24153 |
%: }$% |
| 24154 |
%: \def\XINT_cmp_checklengths #1\xint:#2\xint:#3\xint: |
| 24155 |
%: {$% |
| 24156 |
%: \ifnum #1=#3 |
| 24157 |
%: \expandafter\xint_firstoftwo |
| 24158 |
%: \else |
| 24159 |
%: \expandafter\xint_secondoftwo |
| 24160 |
%: \fi |
| 24161 |
%: \XINT_cmp_a {\XINT_cmp_distinctlengths {#1}{#3}}#2;!1;!1;!1;!\W |
| 24162 |
%: }$% |
| 24163 |
%: \def\XINT_cmp_distinctlengths #1#2#3\W #4\W |
| 24164 |
%: {$% |
| 24165 |
%: \ifnum #1>#2 |
| 24166 |
%: \expandafter\xint_firstoftwo |
| 24167 |
%: \else |
| 24168 |
%: \expandafter\xint_secondoftwo |
| 24169 |
%: \fi |
| 24170 |
%: { -1}{ 1}$% |
| 24171 |
%: }$% |
| 24172 |
%: \def\XINT_cmp_a 1#1!1#2!1#3!1#4!#5\W 1#6!1#7!1#8!1#9!$% |
| 24173 |
%: {$% |
| 24174 |
%: \xint_gob_til_sc #1\XINT_cmp_equal ;$% |
| 24175 |
%: \ifnum #1>#6 \XINT_cmp_gt\fi |
| 24176 |
%: \ifnum #1<#6 \XINT_cmp_lt\fi |
| 24177 |
%: \xint_gob_til_sc #2\XINT_cmp_equal ;$% |
| 24178 |
%: \ifnum #2>#7 \XINT_cmp_gt\fi |
| 24179 |
%: \ifnum #2<#7 \XINT_cmp_lt\fi |
| 24180 |
%: \xint_gob_til_sc #3\XINT_cmp_equal ;$% |
| 24181 |
%: \ifnum #3>#8 \XINT_cmp_gt\fi |
| 24182 |
%: \ifnum #3<#8 \XINT_cmp_lt\fi |
| 24183 |
%: \xint_gob_til_sc #4\XINT_cmp_equal ;$% |
| 24184 |
%: \ifnum #4>#9 \XINT_cmp_gt\fi |
| 24185 |
%: \ifnum #4<#9 \XINT_cmp_lt\fi |
| 24186 |
%: \XINT_cmp_a #5\W |
| 24187 |
%: }$% |
| 24188 |
%: \def\XINT_cmp_lt#1{\def\XINT_cmp_lt\fi ##1\W ##2\W {\fi#1-1}}\XINT_cmp_lt{ }$% |
| 24189 |
%: \def\XINT_cmp_gt#1{\def\XINT_cmp_gt\fi ##1\W ##2\W {\fi#11}}\XINT_cmp_gt{ }$% |
| 24190 |
%: \def\XINT_cmp_equal #1\W #2\W { 0}$% |
| 24191 |
%) |
| 24192 |
%\end{lverb} |
| 24193 |
% \subsection{\csh{xintiiSub}} |
| 24194 |
%\begin{lverb} |
| 24195 |
% Entirely rewritten for 1.2. |
| 24196 |
% |
| 24197 |
% Refactored at 1.2l. I was initially aiming at clinching some internal format |
| 24198 |
% of the type 1<8digits>!....1<8digits>! for chaining the arithmetic |
| 24199 |
% operations (as a preliminary step to deciding upon some internal format for |
| 24200 |
% $xintfracnameimp macros), thus I wanted to uniformize delimiters in |
| 24201 |
% particular and have some core macros inputting and outputting such formats. |
| 24202 |
% But the way division is implemented makes it currently very hard to obtain a |
| 24203 |
% satisfactory solution. For subtraction I got there almost, but there was |
| 24204 |
% added overhead and, as the core sub-routine still assumed the shorter number |
| 24205 |
% will be positioned first, one would need to record the length also in the |
| 24206 |
% basic internal format, or add the overhead to not make assumption on which |
| 24207 |
% one is shorter. I thus but back-tracked my steps but in passing I improved |
| 24208 |
% the efficiency (probably) in the worst case branch. |
| 24209 |
% |
| 24210 |
% Sadly this 1.2l refactoring left an extra ! in macro \XINT_sub_l_Ida. This |
| 24211 |
% bug shows only in rare circumstances which escaped out test suite :( |
| 24212 |
% Fixed at 1.2q. |
| 24213 |
% |
| 24214 |
% The other reason for backtracking was in relation with the decimal numbers. |
| 24215 |
% Having a core format in base 10^8 but ultimately the radix is actually 10 |
| 24216 |
% leads to complications. I could use radix 10^8 for \xintiiexpr only, but |
| 24217 |
% then I need to make it compatible with sub-\xintiiexpr in \xintexpr, etc... |
| 24218 |
% there are many issues of this type. |
| 24219 |
% |
| 24220 |
% I considered also an approach like in the 1.2l \xintiiCmp, but decided to |
| 24221 |
% stick with the method here for now. |
| 24222 |
%\end{lverb} |
| 24223 |
% \begin{macrocode} |
| 24224 |
\def\xintiiSub {\romannumeral0\xintiisub }% |
| 24225 |
\def\xintiisub #1{\expandafter\XINT_iisub\romannumeral`&&@#1\xint:}% |
| 24226 |
\def\XINT_iisub #1#2\xint:#3% |
| 24227 |
{% |
| 24228 |
\expandafter\XINT_sub_nfork\expandafter |
| 24229 |
#1\romannumeral`&&@#3\xint:#2\xint: |
| 24230 |
}% |
| 24231 |
\def\XINT_sub_nfork #1#2% |
| 24232 |
{% |
| 24233 |
\xint_UDzerofork |
| 24234 |
#1\XINT_sub_firstiszero |
| 24235 |
#2\XINT_sub_secondiszero |
| 24236 |
0{}% |
| 24237 |
\krof |
| 24238 |
\xint_UDsignsfork |
| 24239 |
#1#2\XINT_sub_minusminus |
| 24240 |
#1-\XINT_sub_minusplus |
| 24241 |
#2-\XINT_sub_plusminus |
| 24242 |
--\XINT_sub_plusplus |
| 24243 |
\krof #1#2% |
| 24244 |
}% |
| 24245 |
\def\XINT_sub_firstiszero #1\krof 0#2#3\xint:#4\xint:{\XINT_opp #2#3}% |
| 24246 |
\def\XINT_sub_secondiszero #1\krof #20#3\xint:#4\xint:{ #2#4}% |
| 24247 |
\def\XINT_sub_plusminus #1#2{\XINT_add_pp_a #1{}}% |
| 24248 |
\def\XINT_sub_plusplus #1#2% |
| 24249 |
{\expandafter\XINT_opp\romannumeral0\XINT_sub_mm_a #1#2}% |
| 24250 |
\def\XINT_sub_minusplus #1#2% |
| 24251 |
{\expandafter-\romannumeral0\XINT_add_pp_a {}#2}% |
| 24252 |
\def\XINT_sub_minusminus #1#2{\XINT_sub_mm_a {}{}}% |
| 24253 |
\def\XINT_sub_mm_a #1#2#3\xint: |
| 24254 |
{% |
| 24255 |
\expandafter\XINT_sub_mm_b |
| 24256 |
\romannumeral0\expandafter\XINT_sepandrev_andcount |
| 24257 |
\romannumeral0\XINT_zeroes_forviii #2#3\R\R\R\R\R\R\R\R{10}0000001\W |
| 24258 |
#2#3\XINT_rsepbyviii_end_A 2345678% |
| 24259 |
\XINT_rsepbyviii_end_B 2345678\relax\xint_c_ii\xint_c_i |
| 24260 |
\R\xint:\xint_c_xii \R\xint:\xint_c_x \R\xint:\xint_c_viii \R\xint:\xint_c_vi |
| 24261 |
\R\xint:\xint_c_iv \R\xint:\xint_c_ii \R\xint:\xint_c_\W |
| 24262 |
\X #1% |
| 24263 |
}% |
| 24264 |
\def\XINT_sub_mm_b #1\xint:#2\X #3\xint: |
| 24265 |
{% |
| 24266 |
\expandafter\XINT_sub_checklengths |
| 24267 |
\the\numexpr #1\expandafter\xint:% |
| 24268 |
\romannumeral0\expandafter\XINT_sepandrev_andcount |
| 24269 |
\romannumeral0\XINT_zeroes_forviii #3\R\R\R\R\R\R\R\R{10}0000001\W |
| 24270 |
#3\XINT_rsepbyviii_end_A 2345678% |
| 24271 |
\XINT_rsepbyviii_end_B 2345678\relax\xint_c_ii\xint_c_i |
| 24272 |
\R\xint:\xint_c_xii \R\xint:\xint_c_x \R\xint:\xint_c_viii \R\xint:\xint_c_vi |
| 24273 |
\R\xint:\xint_c_iv \R\xint:\xint_c_ii \R\xint:\xint_c_\W |
| 24274 |
1;!1;!1;!1;!\W |
| 24275 |
#21;!1;!1;!1;!\W |
| 24276 |
1;!1\R!1\R!1\R!1\R!% |
| 24277 |
1\R!1\R!1\R!1\R!\W |
| 24278 |
}% |
| 24279 |
\def\XINT_sub_checklengths #1\xint:#2\xint:% |
| 24280 |
{% |
| 24281 |
\ifnum #2>#1 |
| 24282 |
\expandafter\XINT_sub_exchange |
| 24283 |
\else |
| 24284 |
\expandafter\XINT_sub_aa |
| 24285 |
\fi |
| 24286 |
}% |
| 24287 |
\def\XINT_sub_exchange #1\W #2\W |
| 24288 |
{% |
| 24289 |
\expandafter\XINT_opp\romannumeral0\XINT_sub_aa #2\W #1\W |
| 24290 |
}% |
| 24291 |
\def\XINT_sub_aa |
| 24292 |
{% |
| 24293 |
\expandafter\XINT_sub_out\the\numexpr\XINT_sub_a\xint_c_i |
| 24294 |
}% |
| 24295 |
% \end{macrocode} |
| 24296 |
%\begin{lverb} |
| 24297 |
% The post-processing (clean-up of zeros, or rescue of situation with |
| 24298 |
% A-B where actually B turns out bigger than A) will be done by a macro which |
| 24299 |
% depends on circumstances and will be initially last token before the |
| 24300 |
% reversion done by \XINT_unrevbyviii. |
| 24301 |
%\end{lverb} |
| 24302 |
% \begin{macrocode} |
| 24303 |
\def\XINT_sub_out {\XINT_unrevbyviii{}}% |
| 24304 |
% \end{macrocode} |
| 24305 |
%\begin{lverb} |
| 24306 |
% 1 as first token of #1 stands for "no carry", 0 will mean a carry. |
| 24307 |
% |
| 24308 |
%( Call: \the\numexpr |
| 24309 |
%: \XINT_sub_a 1#11;!1;!1;!1;!\W |
| 24310 |
%: #21;!1;!1;!1;!\W |
| 24311 |
%) |
| 24312 |
% where #1 and #2 |
| 24313 |
% are blocks of 1<8d>!, #1 (=B) *must* be at most as long as #2 (=A), |
| 24314 |
% (in radix 10^8) |
| 24315 |
% and the routine wants to compute #2-#1 = A - B |
| 24316 |
% |
| 24317 |
% 1.2l uses 1;! delimiters to match those of addition (and multiplication). |
| 24318 |
% But in the end I reverted the code branch which made it possible to chain |
| 24319 |
% such operations keeping internal format in 8 digits blocks throughout. |
| 24320 |
% |
| 24321 |
% \numexpr governed expansion stops with various possibilities: |
| 24322 |
% |
| 24323 |
%- Type Ia: #1 shorter than #2, no final carry |
| 24324 |
%- Type Ib: #1 shorter than #2, a final carry but next block of #2 > 1 |
| 24325 |
%- Type Ica: #1 shorter than #2, a final carry, next block of #2 is final and = 1 |
| 24326 |
%- Type Icb: as Ica except that 00000001 block from #2 was not final |
| 24327 |
%- Type Id: #1 shorter than #2, a final carry, next block of #2 = 0 |
| 24328 |
%- Type IIa: #1 same length as #2, turns out it was <= #2. |
| 24329 |
%- Type IIb: #1 same length as #2, but turned out > #2. |
| 24330 |
% |
| 24331 |
% Various type of post actions are then needed: |
| 24332 |
% |
| 24333 |
%- Ia: clean up of zeros in most significant block of 8 digits |
| 24334 |
% |
| 24335 |
%- Ib: as Ia |
| 24336 |
% |
| 24337 |
%- Ic: there may be significant blocks of 8 zeros to clean up from result. |
| 24338 |
% Only case Ica may have arbitrarily many of them, case Icb has only one such |
| 24339 |
% block. |
| 24340 |
% |
| 24341 |
%- Id: blocks of 99999999 may propagate and there might a be final zero block |
| 24342 |
% created which has to be cleaned up. |
| 24343 |
% |
| 24344 |
%- IIa: arbitrarily many zeros might have to be removed. |
| 24345 |
% |
| 24346 |
%- IIb: We wanted #2-#1 = - (#1-#2), but we got 10^{8N}+#2 -#1 = 10^{8N}-(#1-#2). |
| 24347 |
% We need to do the correction then we are as in IIa situation, except that |
| 24348 |
% final result can not be zero. |
| 24349 |
% |
| 24350 |
% The 1.2l method for this correction is (presumably, testing takes lots of |
| 24351 |
% time, which I do not have) more efficient than in 1.2 release. |
| 24352 |
%\end{lverb} |
| 24353 |
% \begin{macrocode} |
| 24354 |
\def\XINT_sub_a #1!#2!#3!#4!#5\W #6!#7!#8!#9!% |
| 24355 |
{% |
| 24356 |
\XINT_sub_b |
| 24357 |
#1!#6!#2!#7!#3!#8!#4!#9!% |
| 24358 |
#5\W |
| 24359 |
}% |
| 24360 |
% \end{macrocode} |
| 24361 |
%\begin{lverb} |
| 24362 |
% As 1.2l code uses 1<8digits>! blocks one has to be careful with |
| 24363 |
% the carry digit 1 or 0: A #11#2#3 pattern would result into an empty #1 |
| 24364 |
% if the carry digit which is upfront is 1, rather than setting #1=1. |
| 24365 |
%\end{lverb} |
| 24366 |
% \begin{macrocode} |
| 24367 |
\def\XINT_sub_b #1#2#3#4!#5!% |
| 24368 |
{% |
| 24369 |
\xint_gob_til_sc #3\XINT_sub_bi ;% |
| 24370 |
\expandafter\XINT_sub_c\the\numexpr#1+1#5-#3#4-\xint_c_i\xint:% |
| 24371 |
}% |
| 24372 |
\def\XINT_sub_c 1#1#2\xint:% |
| 24373 |
{% |
| 24374 |
1#2\expandafter!\the\numexpr\XINT_sub_d #1% |
| 24375 |
}% |
| 24376 |
\def\XINT_sub_d #1#2#3#4!#5!% |
| 24377 |
{% |
| 24378 |
\xint_gob_til_sc #3\XINT_sub_di ;% |
| 24379 |
\expandafter\XINT_sub_e\the\numexpr#1+1#5-#3#4-\xint_c_i\xint: |
| 24380 |
}% |
| 24381 |
\def\XINT_sub_e 1#1#2\xint:% |
| 24382 |
{% |
| 24383 |
1#2\expandafter!\the\numexpr\XINT_sub_f #1% |
| 24384 |
}% |
| 24385 |
\def\XINT_sub_f #1#2#3#4!#5!% |
| 24386 |
{% |
| 24387 |
\xint_gob_til_sc #3\XINT_sub_fi ;% |
| 24388 |
\expandafter\XINT_sub_g\the\numexpr#1+1#5-#3#4-\xint_c_i\xint: |
| 24389 |
}% |
| 24390 |
\def\XINT_sub_g 1#1#2\xint:% |
| 24391 |
{% |
| 24392 |
1#2\expandafter!\the\numexpr\XINT_sub_h #1% |
| 24393 |
}% |
| 24394 |
\def\XINT_sub_h #1#2#3#4!#5!% |
| 24395 |
{% |
| 24396 |
\xint_gob_til_sc #3\XINT_sub_hi ;% |
| 24397 |
\expandafter\XINT_sub_i\the\numexpr#1+1#5-#3#4-\xint_c_i\xint: |
| 24398 |
}% |
| 24399 |
\def\XINT_sub_i 1#1#2\xint:% |
| 24400 |
{% |
| 24401 |
1#2\expandafter!\the\numexpr\XINT_sub_a #1% |
| 24402 |
}% |
| 24403 |
\def\XINT_sub_bi;% |
| 24404 |
\expandafter\XINT_sub_c\the\numexpr#1+1#2-#3\xint: |
| 24405 |
#4!#5!#6!#7!#8!#9!\W |
| 24406 |
{% |
| 24407 |
\XINT_sub_k #1#2!#5!#7!#9!% |
| 24408 |
}% |
| 24409 |
\def\XINT_sub_di;% |
| 24410 |
\expandafter\XINT_sub_e\the\numexpr#1+1#2-#3\xint: |
| 24411 |
#4!#5!#6!#7!#8\W |
| 24412 |
{% |
| 24413 |
\XINT_sub_k #1#2!#5!#7!% |
| 24414 |
}% |
| 24415 |
\def\XINT_sub_fi;% |
| 24416 |
\expandafter\XINT_sub_g\the\numexpr#1+1#2-#3\xint: |
| 24417 |
#4!#5!#6\W |
| 24418 |
{% |
| 24419 |
\XINT_sub_k #1#2!#5!% |
| 24420 |
}% |
| 24421 |
\def\XINT_sub_hi;% |
| 24422 |
\expandafter\XINT_sub_i\the\numexpr#1+1#2-#3\xint: |
| 24423 |
#4\W |
| 24424 |
{% |
| 24425 |
\XINT_sub_k #1#2!% |
| 24426 |
}% |
| 24427 |
% \end{macrocode} |
| 24428 |
%\begin{lverb} |
| 24429 |
% B terminated. Have we reached the end of A (necessarily at least as |
| 24430 |
% long as B) ? (we are computing A-B, digits of B come first). |
| 24431 |
% |
| 24432 |
% If not, then we are certain that even if there is carry it will not |
| 24433 |
% propagate beyond the end of A. But it may propagate far transforming chains |
| 24434 |
% of 00000000 into 99999999, and if it does go to the final block which possibly is |
| 24435 |
% just 1<00000001>!, we will have those eight zeros to clean up. |
| 24436 |
% |
| 24437 |
% If A and B have the same length (in base 10^8) then arbitrarily many zeros |
| 24438 |
% might have to be cleaned up, and if A<B, the whole result will have to be |
| 24439 |
% complemented first. |
| 24440 |
%\end{lverb} |
| 24441 |
% \begin{macrocode} |
| 24442 |
\def\XINT_sub_k #1#2#3% |
| 24443 |
{% |
| 24444 |
\xint_gob_til_sc #3\XINT_sub_p;\XINT_sub_l #1#2#3% |
| 24445 |
}% |
| 24446 |
\def\XINT_sub_l #1% |
| 24447 |
{\xint_UDzerofork #1\XINT_sub_l_carry 0\XINT_sub_l_Ia\krof}% |
| 24448 |
\def\XINT_sub_l_Ia 1#1;!#2\W{1\relax#1;!1\XINT_sub_fix_none!}% |
| 24449 |
% \end{macrocode} |
| 24450 |
%\begin{lverb} |
| 24451 |
% |
| 24452 |
%\end{lverb} |
| 24453 |
% \begin{macrocode} |
| 24454 |
\def\XINT_sub_l_carry 1#1!{\ifcase #1 |
| 24455 |
\expandafter \XINT_sub_l_Id |
| 24456 |
\or \expandafter \XINT_sub_l_Ic |
| 24457 |
\else\expandafter \XINT_sub_l_Ib\fi 1#1!}% |
| 24458 |
% \end{macrocode} |
| 24459 |
%\begin{lverb} |
| 24460 |
% No \cs{relax} here at 1.4n before the ; for LuaMetaTeX's \cs{numexpr}. |
| 24461 |
% The #1 will bring own delimiter. AM I CERTAIN OF THAT? |
| 24462 |
%\end{lverb} |
| 24463 |
% \begin{macrocode} |
| 24464 |
\def\XINT_sub_l_Ib #1;#2\W {-\xint_c_i+#1;!1\XINT_sub_fix_none!}% |
| 24465 |
\def\XINT_sub_l_Ic 1#1!1#2#3!#4;#5\W |
| 24466 |
{% |
| 24467 |
\xint_gob_til_sc #2\XINT_sub_l_Ica;% |
| 24468 |
1\relax 00000000!1#2#3!#4;!1\XINT_sub_fix_none!% |
| 24469 |
}% |
| 24470 |
% \end{macrocode} |
| 24471 |
%\begin{lverb} |
| 24472 |
% We need to add some extra delimiters at the end for post-action by |
| 24473 |
% \XINT_num, so we first grab the material up to \W |
| 24474 |
%\end{lverb} |
| 24475 |
% \changed{1.4n} |
| 24476 |
% A \cs{relax} added for LuaMeta\TeX{} compatibility. |
| 24477 |
% \begin{macrocode} |
| 24478 |
\def\XINT_sub_l_Ica#1\W |
| 24479 |
{% |
| 24480 |
1\relax;!1\XINT_sub_fix_cuz!% |
| 24481 |
1;!1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W |
| 24482 |
\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint:\Z |
| 24483 |
}% |
| 24484 |
\def\XINT_sub_l_Id 1#1!% |
| 24485 |
{199999999\expandafter!\the\numexpr \XINT_sub_l_Id_a}% |
| 24486 |
\def\XINT_sub_l_Id_a 1#1!{\ifcase #1 |
| 24487 |
\expandafter \XINT_sub_l_Id |
| 24488 |
\or \expandafter \XINT_sub_l_Id_b |
| 24489 |
\else\expandafter \XINT_sub_l_Ib\fi 1#1!}% |
| 24490 |
\def\XINT_sub_l_Id_b 1#1!1#2#3!#4;#5\W |
| 24491 |
{% |
| 24492 |
\xint_gob_til_sc #2\XINT_sub_l_Ida;% |
| 24493 |
1\relax 00000000!1#2#3!#4;!1\XINT_sub_fix_none!% |
| 24494 |
}% |
| 24495 |
% \end{macrocode} |
| 24496 |
% \changed{1.4n} LuaMetaTeX |
| 24497 |
% \begin{macrocode} |
| 24498 |
\def\XINT_sub_l_Ida#1\XINT_sub_fix_none{1\relax;!1\XINT_sub_fix_none}% |
| 24499 |
% \end{macrocode} |
| 24500 |
%\begin{lverb} |
| 24501 |
% This is the case where both operands have same 10^8-base length. |
| 24502 |
% |
| 24503 |
% We were handling A-B but perhaps B>A. The situation with A=B is also |
| 24504 |
% annoying because we then have to clean up all zeros but don't know where to |
| 24505 |
% stop (if A>B the first non-zero 8 digits block would tell use when). |
| 24506 |
% |
| 24507 |
% Here again we need to grab #3\W to position the actually used terminating |
| 24508 |
% delimiters. |
| 24509 |
%\end{lverb} |
| 24510 |
% \changed{1.4n} \cs{relax} for LuaMetaTeX \cs{numexpr} |
| 24511 |
% \begin{macrocode} |
| 24512 |
\def\XINT_sub_p;\XINT_sub_l #1#2\W #3\W |
| 24513 |
{% |
| 24514 |
\xint_UDzerofork |
| 24515 |
#1{1\relax;!1\XINT_sub_fix_neg!% |
| 24516 |
1;!1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W |
| 24517 |
\xint_bye2345678\xint_bye1099999988\relax}% A - B, B > A |
| 24518 |
0{1\relax;!1\XINT_sub_fix_cuz!% |
| 24519 |
1;!1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W}% |
| 24520 |
\krof |
| 24521 |
\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint:\Z |
| 24522 |
}% |
| 24523 |
% \end{macrocode} |
| 24524 |
%\begin{lverb} |
| 24525 |
% Routines for post-processing after reversal, and removal of |
| 24526 |
% separators. It is a matter of cleaning up zeros, and possibly in the bad |
| 24527 |
% case to take a complement before that. |
| 24528 |
%\end{lverb} |
| 24529 |
% \begin{macrocode} |
| 24530 |
\def\XINT_sub_fix_none;{\XINT_cuz_small}% |
| 24531 |
\def\XINT_sub_fix_cuz ;{\expandafter\XINT_num_cleanup\the\numexpr\XINT_num_loop}% |
| 24532 |
% \end{macrocode} |
| 24533 |
%\begin{lverb} |
| 24534 |
% Case with A and B same number of digits in base 10^8 and B>A. |
| 24535 |
% |
| 24536 |
% 1.2l subtle chaining on the model of the 1.2i rewrite of \xintInc and |
| 24537 |
% similar routines. After taking complement, leading zeroes need to be |
| 24538 |
% cleaned up as in B<=A branch. |
| 24539 |
%\end{lverb} |
| 24540 |
% \begin{macrocode} |
| 24541 |
\def\XINT_sub_fix_neg;% |
| 24542 |
{% |
| 24543 |
\expandafter-\romannumeral0\expandafter |
| 24544 |
\XINT_sub_comp_finish\the\numexpr\XINT_sub_comp_loop |
| 24545 |
}% |
| 24546 |
\def\XINT_sub_comp_finish 0{\XINT_sub_fix_cuz;}% |
| 24547 |
\def\XINT_sub_comp_loop #1#2#3#4#5#6#7#8% |
| 24548 |
{% |
| 24549 |
\expandafter\XINT_sub_comp_clean |
| 24550 |
\the\numexpr \xint_c_xi_e_viii_mone-#1#2#3#4#5#6#7#8\XINT_sub_comp_loop |
| 24551 |
}% |
| 24552 |
% \end{macrocode} |
| 24553 |
%\begin{lverb} |
| 24554 |
% #1 = 0 signifie une retenue, #1 = 1 pas de retenue, ce qui ne peut |
| 24555 |
% arriver que tant qu'il n'y a que des zéros du côté non significatif. |
| 24556 |
% Lorsqu'on est revenu au début on a forcément une retenue. |
| 24557 |
%\end{lverb} |
| 24558 |
% \begin{macrocode} |
| 24559 |
\def\XINT_sub_comp_clean 1#1{+#1\relax}% |
| 24560 |
% \end{macrocode} |
| 24561 |
% \subsection{\csh{xintiiMul}} |
| 24562 |
%\begin{lverb} |
| 24563 |
% Completely rewritten for 1.2. |
| 24564 |
% |
| 24565 |
% 1.2l: \xintiiMul made robust against non terminated input. |
| 24566 |
%\end{lverb} |
| 24567 |
% \begin{macrocode} |
| 24568 |
\def\xintiiMul {\romannumeral0\xintiimul }% |
| 24569 |
\def\xintiimul #1% |
| 24570 |
{% |
| 24571 |
\expandafter\XINT_iimul\romannumeral`&&@#1\xint: |
| 24572 |
}% |
| 24573 |
\def\XINT_iimul #1#2\xint:#3% |
| 24574 |
{% |
| 24575 |
\expandafter\XINT_mul_nfork\expandafter #1\romannumeral`&&@#3\xint:#2\xint: |
| 24576 |
}% |
| 24577 |
% \end{macrocode} |
| 24578 |
%\begin{lverb} |
| 24579 |
% 1.2 I have changed the fork, and it complicates matters elsewhere. |
| 24580 |
% |
| 24581 |
% ATTENTION for example that 1.4 \xintiiPrd uses \XINT_mul_nfork now. |
| 24582 |
%\end{lverb} |
| 24583 |
% \begin{macrocode} |
| 24584 |
\def\XINT_mul_fork #1#2\xint:#3\xint:{\XINT_mul_nfork #1#3\xint:#2\xint:}% |
| 24585 |
\def\XINT_mul_nfork #1#2% |
| 24586 |
{% |
| 24587 |
\xint_UDzerofork |
| 24588 |
#1\XINT_mul_zero |
| 24589 |
#2\XINT_mul_zero |
| 24590 |
0{}% |
| 24591 |
\krof |
| 24592 |
\xint_UDsignsfork |
| 24593 |
#1#2\XINT_mul_minusminus |
| 24594 |
#1-\XINT_mul_minusplus |
| 24595 |
#2-\XINT_mul_plusminus |
| 24596 |
--\XINT_mul_plusplus |
| 24597 |
\krof #1#2% |
| 24598 |
}% |
| 24599 |
\def\XINT_mul_zero #1\krof #2#3\xint:#4\xint:{ 0}% |
| 24600 |
\def\XINT_mul_minusminus #1#2{\XINT_mul_plusplus {}{}}% |
| 24601 |
\def\XINT_mul_minusplus #1#2% |
| 24602 |
{\expandafter-\romannumeral0\XINT_mul_plusplus {}#2}% |
| 24603 |
\def\XINT_mul_plusminus #1#2% |
| 24604 |
{\expandafter-\romannumeral0\XINT_mul_plusplus #1{}}% |
| 24605 |
\def\XINT_mul_plusplus #1#2#3\xint: |
| 24606 |
{% |
| 24607 |
\expandafter\XINT_mul_pre_b |
| 24608 |
\romannumeral0\expandafter\XINT_sepandrev_andcount |
| 24609 |
\romannumeral0\XINT_zeroes_forviii #2#3\R\R\R\R\R\R\R\R{10}0000001\W |
| 24610 |
#2#3\XINT_rsepbyviii_end_A 2345678% |
| 24611 |
\XINT_rsepbyviii_end_B 2345678\relax\xint_c_ii\xint_c_i |
| 24612 |
\R\xint:\xint_c_xii \R\xint:\xint_c_x \R\xint:\xint_c_viii \R\xint:\xint_c_vi |
| 24613 |
\R\xint:\xint_c_iv \R\xint:\xint_c_ii \R\xint:\xint_c_\W |
| 24614 |
\W #1% |
| 24615 |
}% |
| 24616 |
\def\XINT_mul_pre_b #1\xint:#2\W #3\xint: |
| 24617 |
{% |
| 24618 |
\expandafter\XINT_mul_checklengths |
| 24619 |
\the\numexpr #1\expandafter\xint:% |
| 24620 |
\romannumeral0\expandafter\XINT_sepandrev_andcount |
| 24621 |
\romannumeral0\XINT_zeroes_forviii #3\R\R\R\R\R\R\R\R{10}0000001\W |
| 24622 |
#3\XINT_rsepbyviii_end_A 2345678% |
| 24623 |
\XINT_rsepbyviii_end_B 2345678\relax\xint_c_ii\xint_c_i |
| 24624 |
\R\xint:\xint_c_xii \R\xint:\xint_c_x \R\xint:\xint_c_viii \R\xint:\xint_c_vi |
| 24625 |
\R\xint:\xint_c_iv \R\xint:\xint_c_ii \R\xint:\xint_c_\W |
| 24626 |
1;!\W #21;!% |
| 24627 |
1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W |
| 24628 |
}% |
| 24629 |
% \end{macrocode} |
| 24630 |
%\begin{lverb} |
| 24631 |
% Cooking recipe, 2015/10/05. |
| 24632 |
%\end{lverb} |
| 24633 |
% \begin{macrocode} |
| 24634 |
\def\XINT_mul_checklengths #1\xint:#2\xint:% |
| 24635 |
{% |
| 24636 |
\ifnum #2=\xint_c_i\expandafter\XINT_mul_smallbyfirst\fi |
| 24637 |
\ifnum #1=\xint_c_i\expandafter\XINT_mul_smallbysecond\fi |
| 24638 |
\ifnum #2<#1 |
| 24639 |
\ifnum \numexpr (#2-\xint_c_i)*(#1-#2)<383 |
| 24640 |
\XINT_mul_exchange |
| 24641 |
\fi |
| 24642 |
\else |
| 24643 |
\ifnum \numexpr (#1-\xint_c_i)*(#2-#1)>383 |
| 24644 |
\XINT_mul_exchange |
| 24645 |
\fi |
| 24646 |
\fi |
| 24647 |
\XINT_mul_start |
| 24648 |
}% |
| 24649 |
\def\XINT_mul_smallbyfirst #1\XINT_mul_start 1#2!1;!\W |
| 24650 |
{% |
| 24651 |
\ifnum#2=\xint_c_i\expandafter\XINT_mul_oneisone\fi |
| 24652 |
\ifnum#2<\xint_c_xxii\expandafter\XINT_mul_verysmall\fi |
| 24653 |
\expandafter\XINT_mul_out\the\numexpr\XINT_smallmul 1#2!% |
| 24654 |
}% |
| 24655 |
\def\XINT_mul_smallbysecond #1\XINT_mul_start #2\W 1#3!1;!% |
| 24656 |
{% |
| 24657 |
\ifnum#3=\xint_c_i\expandafter\XINT_mul_oneisone\fi |
| 24658 |
\ifnum#3<\xint_c_xxii\expandafter\XINT_mul_verysmall\fi |
| 24659 |
\expandafter\XINT_mul_out\the\numexpr\XINT_smallmul 1#3!#2% |
| 24660 |
}% |
| 24661 |
\def\XINT_mul_oneisone #1!{\XINT_mul_out }% |
| 24662 |
\def\XINT_mul_verysmall\expandafter\XINT_mul_out |
| 24663 |
\the\numexpr\XINT_smallmul 1#1!% |
| 24664 |
{\expandafter\XINT_mul_out\the\numexpr\XINT_verysmallmul 0\xint:#1!}% |
| 24665 |
\def\XINT_mul_exchange #1\XINT_mul_start #2\W #31;!% |
| 24666 |
{\fi\fi\XINT_mul_start #31;!\W #2}% |
| 24667 |
\def\XINT_mul_start |
| 24668 |
{\expandafter\XINT_mul_out\the\numexpr\XINT_mul_loop 100000000!1;!\W}% |
| 24669 |
\def\XINT_mul_out |
| 24670 |
{\expandafter\XINT_cuz_small\romannumeral0\XINT_unrevbyviii {}}% |
| 24671 |
% \end{macrocode} |
| 24672 |
%\begin{lverb} |
| 24673 |
% |
| 24674 |
%( Call: |
| 24675 |
%: \the\numexpr \XINT_mul_loop 100000000!1;!\W #11;!\W #21;! |
| 24676 |
%) |
| 24677 |
% where #1 and #2 are (globally reversed) blocks 1<8d>!. Its is generally more |
| 24678 |
% efficient if #1 is the shorter one, but a better recipe is implemented in |
| 24679 |
% \XINT_mul_checklengths. One may call \XINT_mul_loop directly (but |
| 24680 |
% multiplication by zero will produce many 100000000! blocks on output). |
| 24681 |
% |
| 24682 |
% Ends after having produced: 1<8d>!....1<8d>!1;!. The last 8-digits block is |
| 24683 |
% significant one. It can not be 100000000! except if the loop was called with |
| 24684 |
% a zero operand. |
| 24685 |
% |
| 24686 |
% Thus \XINT_mul_loop can be conveniently called directly in recursive |
| 24687 |
% routines, as the output terminator can serve as input terminator, we can |
| 24688 |
% arrange to not have to grab the whole thing again. |
| 24689 |
%\end{lverb} |
| 24690 |
% \begin{macrocode} |
| 24691 |
\def\XINT_mul_loop #1\W #2\W 1#3!% |
| 24692 |
{% |
| 24693 |
\xint_gob_til_sc #3\XINT_mul_e ;% |
| 24694 |
\expandafter\XINT_mul_a\the\numexpr \XINT_smallmul 1#3!#2\W |
| 24695 |
#1\W #2\W |
| 24696 |
}% |
| 24697 |
% \end{macrocode} |
| 24698 |
%\begin{lverb} |
| 24699 |
% Each of #1 and #2 brings its 1;! for \XINT_add_a. |
| 24700 |
%\end{lverb} |
| 24701 |
% \begin{macrocode} |
| 24702 |
\def\XINT_mul_a #1\W #2\W |
| 24703 |
{% |
| 24704 |
\expandafter\XINT_mul_b\the\numexpr |
| 24705 |
\XINT_add_a \xint_c_ii #21;!1;!1;!\W #11;!1;!1;!\W\W |
| 24706 |
}% |
| 24707 |
\def\XINT_mul_b 1#1!{1#1\expandafter!\the\numexpr\XINT_mul_loop }% |
| 24708 |
\def\XINT_mul_e;#1\W 1#2\W #3\W {1\relax #2}% |
| 24709 |
% \end{macrocode} |
| 24710 |
%\begin{lverb} |
| 24711 |
% 1.2 small and mini multiplication in base 10^8 with carry. Used by |
| 24712 |
% the main multiplication routines. But division, float factorial, etc.. have |
| 24713 |
% their own variants as they need output with specific constraints. |
| 24714 |
% |
| 24715 |
% The minimulwc has 1<8digits carry>.<4 high digits>.<4 low digits!<8digits>. |
| 24716 |
% |
| 24717 |
% It produces a block 1<8d>! and then jump back into \XINT_smallmul_a with the |
| 24718 |
% new 8digits carry as argument. The \XINT_smallmul_a fetches a new 1<8d>! |
| 24719 |
% block to multiply, and calls back \XINT_minimul_wc having stored the |
| 24720 |
% multiplicand for re-use later. When the loop terminates, the final carry is |
| 24721 |
% checked for being nul, and in all cases the output is terminated by a 1;! |
| 24722 |
% |
| 24723 |
% Multiplication by zero will produce blocks of zeros. |
| 24724 |
%\end{lverb} |
| 24725 |
% \begin{macrocode} |
| 24726 |
\def\XINT_minimulwc_a 1#1\xint:#2\xint:#3!#4#5#6#7#8\xint:% |
| 24727 |
{% |
| 24728 |
\expandafter\XINT_minimulwc_b |
| 24729 |
\the\numexpr \xint_c_x^ix+#1+#3*#8\xint: |
| 24730 |
#3*#4#5#6#7+#2*#8\xint: |
| 24731 |
#2*#4#5#6#7\xint:% |
| 24732 |
}% |
| 24733 |
\def\XINT_minimulwc_b 1#1#2#3#4#5#6\xint:#7\xint:% |
| 24734 |
{% |
| 24735 |
\expandafter\XINT_minimulwc_c |
| 24736 |
\the\numexpr \xint_c_x^ix+#1#2#3#4#5+#7\xint:#6\xint:% |
| 24737 |
}% |
| 24738 |
\def\XINT_minimulwc_c 1#1#2#3#4#5#6\xint:#7\xint:#8\xint:% |
| 24739 |
{% |
| 24740 |
1#6#7\expandafter!% |
| 24741 |
\the\numexpr\expandafter\XINT_smallmul_a |
| 24742 |
\the\numexpr \xint_c_x^viii+#1#2#3#4#5+#8\xint:% |
| 24743 |
}% |
| 24744 |
\def\XINT_smallmul 1#1#2#3#4#5!{\XINT_smallmul_a 100000000\xint:#1#2#3#4\xint:#5!}% |
| 24745 |
\def\XINT_smallmul_a #1\xint:#2\xint:#3!1#4!% |
| 24746 |
{% |
| 24747 |
\xint_gob_til_sc #4\XINT_smallmul_e;% |
| 24748 |
\XINT_minimulwc_a #1\xint:#2\xint:#3!#4\xint:#2\xint:#3!% |
| 24749 |
}% |
| 24750 |
\def\XINT_smallmul_e;\XINT_minimulwc_a 1#1\xint:#2;#3!% |
| 24751 |
{\xint_gob_til_eightzeroes #1\XINT_smallmul_f 000000001\relax #1!1;!}% |
| 24752 |
\def\XINT_smallmul_f 000000001\relax 00000000!1{1\relax}% |
| 24753 |
\def\XINT_verysmallmul #1\xint:#2!1#3!% |
| 24754 |
{% |
| 24755 |
\xint_gob_til_sc #3\XINT_verysmallmul_e;% |
| 24756 |
\expandafter\XINT_verysmallmul_a |
| 24757 |
\the\numexpr #2*#3+#1\xint:#2!% |
| 24758 |
}% |
| 24759 |
\def\XINT_verysmallmul_e;\expandafter\XINT_verysmallmul_a\the\numexpr |
| 24760 |
#1+#2#3\xint:#4!% |
| 24761 |
{\xint_gob_til_zero #2\XINT_verysmallmul_f 0\xint_c_x^viii+#2#3!1;!}% |
| 24762 |
\def\XINT_verysmallmul_f #1!1{1\relax}% |
| 24763 |
\def\XINT_verysmallmul_a #1#2\xint:% |
| 24764 |
{% |
| 24765 |
\unless\ifnum #1#2<\xint_c_x^ix |
| 24766 |
\expandafter\XINT_verysmallmul_bi\else |
| 24767 |
\expandafter\XINT_verysmallmul_bj\fi |
| 24768 |
\the\numexpr \xint_c_x^ix+#1#2\xint:% |
| 24769 |
}% |
| 24770 |
\def\XINT_verysmallmul_bj{\expandafter\XINT_verysmallmul_cj }% |
| 24771 |
\def\XINT_verysmallmul_cj 1#1#2\xint:% |
| 24772 |
{1#2\expandafter!\the\numexpr\XINT_verysmallmul #1\xint:}% |
| 24773 |
\def\XINT_verysmallmul_bi\the\numexpr\xint_c_x^ix+#1#2#3\xint:% |
| 24774 |
{1#3\expandafter!\the\numexpr\XINT_verysmallmul #1#2\xint:}% |
| 24775 |
% \end{macrocode} |
| 24776 |
%\begin{lverb} |
| 24777 |
% Used by division and by squaring, not by multiplication itself. |
| 24778 |
% |
| 24779 |
% This routine does not loop, it only does one mini multiplication with input |
| 24780 |
% format <4 high digits>.<4 low digits>!<8 digits>!, and on output |
| 24781 |
% 1<8d>!1<8d>!, with least significant block first. |
| 24782 |
%\end{lverb} |
| 24783 |
% \begin{macrocode} |
| 24784 |
\def\XINT_minimul_a #1\xint:#2!#3#4#5#6#7!% |
| 24785 |
{% |
| 24786 |
\expandafter\XINT_minimul_b |
| 24787 |
\the\numexpr \xint_c_x^viii+#2*#7\xint:#2*#3#4#5#6+#1*#7\xint:#1*#3#4#5#6\xint:% |
| 24788 |
}% |
| 24789 |
\def\XINT_minimul_b 1#1#2#3#4#5\xint:#6\xint:% |
| 24790 |
{% |
| 24791 |
\expandafter\XINT_minimul_c |
| 24792 |
\the\numexpr \xint_c_x^ix+#1#2#3#4+#6\xint:#5\xint:% |
| 24793 |
}% |
| 24794 |
\def\XINT_minimul_c 1#1#2#3#4#5#6\xint:#7\xint:#8\xint:% |
| 24795 |
{% |
| 24796 |
1#6#7\expandafter!\the\numexpr \xint_c_x^viii+#1#2#3#4#5+#8!% |
| 24797 |
}% |
| 24798 |
% \end{macrocode} |
| 24799 |
% \subsection{\csh{xintiiDivision}} |
| 24800 |
%\begin{lverb} |
| 24801 |
% Completely rewritten for 1.2. |
| 24802 |
% |
| 24803 |
% WARNING: some comments below try to describe the flow of tokens but they |
| 24804 |
% date back to xint 1.09j and I updated them on the fly while doing the 1.2 |
| 24805 |
% version. As the routine now works in base 10^8, not 10^4 and "drops" the |
| 24806 |
% quotient digits,rather than store them upfront as the earlier code, I may |
| 24807 |
% well have not correctly converted all such comments. At the last minute some |
| 24808 |
% previously #1 became stuff like #1#2#3#4, then of course the old comments |
| 24809 |
% describing what the macro parameters stand for are necessarily wrong. |
| 24810 |
% |
| 24811 |
% Side remark: the way tokens are grouped was not essentially modified in |
| 24812 |
% 1.2, although the situation has changed. It was fine-tuned in xint |
| 24813 |
% 1.0/1.1 but the context has changed, and perhaps I should revisit this. |
| 24814 |
% As a corollary to the fact that quotient digits are now left behind thanks |
| 24815 |
% to the chains of \numexpr, some macros which in 1.0/1.1 fetched up to 9 |
| 24816 |
% parameters now need handle less such parameters. Thus, some rationale for |
| 24817 |
% the way the code was structured has disappeared. |
| 24818 |
% |
| 24819 |
% |
| 24820 |
% 1.2l: \xintiiDivision et al. made robust against non terminated input. |
| 24821 |
%\end{lverb} |
| 24822 |
%\begin{lverb} |
| 24823 |
% #1 = A, #2 = B. On calcule le quotient et le reste dans la division |
| 24824 |
% euclidienne de A par B: A=BQ+R, 0<= R < |B|. |
| 24825 |
%\end{lverb} |
| 24826 |
% \begin{macrocode} |
| 24827 |
\def\xintiiDivision {\romannumeral0\xintiidivision }% |
| 24828 |
\def\xintiidivision #1{\expandafter\XINT_iidivision \romannumeral`&&@#1\xint:}% |
| 24829 |
\def\XINT_iidivision #1#2\xint:#3{\expandafter\XINT_iidivision_a\expandafter #1% |
| 24830 |
\romannumeral`&&@#3\xint:#2\xint:}% |
| 24831 |
% \end{macrocode} |
| 24832 |
%\begin{lverb} |
| 24833 |
% On regarde les signes de A et de B. |
| 24834 |
%\end{lverb} |
| 24835 |
% \begin{macrocode} |
| 24836 |
\def\XINT_iidivision_a #1#2% #1 de A, #2 de B. |
| 24837 |
{% |
| 24838 |
\if0#2\xint_dothis{\XINT_iidivision_divbyzero #1#2}\fi |
| 24839 |
\if0#1\xint_dothis\XINT_iidivision_aiszero\fi |
| 24840 |
\if-#2\xint_dothis{\expandafter\XINT_iidivision_bneg |
| 24841 |
\romannumeral0\XINT_iidivision_bpos #1}\fi |
| 24842 |
\xint_orthat{\XINT_iidivision_bpos #1#2}% |
| 24843 |
}% |
| 24844 |
\def\XINT_iidivision_divbyzero#1#2#3\xint:#4\xint: |
| 24845 |
{\if0#1\xint_dothis{\XINT_signalcondition{DivisionUndefined}}\fi |
| 24846 |
\xint_orthat{\XINT_signalcondition{DivisionByZero}}% |
| 24847 |
{Division by zero: #1#4/#2#3.}{}{{0}{0}}}% |
| 24848 |
\def\XINT_iidivision_aiszero #1\xint:#2\xint:{{0}{0}}% |
| 24849 |
\def\XINT_iidivision_bneg #1% q->-q, r unchanged |
| 24850 |
{\expandafter{\romannumeral0\XINT_opp #1}}% |
| 24851 |
\def\XINT_iidivision_bpos #1% |
| 24852 |
{% |
| 24853 |
\xint_UDsignfork |
| 24854 |
#1\XINT_iidivision_aneg |
| 24855 |
-{\XINT_iidivision_apos #1}% |
| 24856 |
\krof |
| 24857 |
}% |
| 24858 |
% \end{macrocode} |
| 24859 |
%\begin{lverb} |
| 24860 |
% Donc attention malgré son nom \XINT_div_prepare va jusqu'au bout. |
| 24861 |
% C'est donc en fait l'entrée principale (pour B>0, A>0) mais elle va |
| 24862 |
% regarder si B est < 10^8 et s'il vaut alors 1 ou 2, et si A < 10^8. Dans |
| 24863 |
% tous les cas le résultat est produit sous la forme {Q}{R}, avec Q et R sous |
| 24864 |
% leur forme final. On doit ensuite ajuster si le B ou le A initial était |
| 24865 |
% négatif. Je n'ai pas fait beaucoup d'efforts pour être un minimum efficace |
| 24866 |
% si A ou B n'est pas positif. |
| 24867 |
%\end{lverb} |
| 24868 |
% \begin{macrocode} |
| 24869 |
\def\XINT_iidivision_apos #1#2\xint:#3\xint:{\XINT_div_prepare {#2}{#1#3}}% |
| 24870 |
\def\XINT_iidivision_aneg #1\xint:#2\xint: |
| 24871 |
{\expandafter |
| 24872 |
\XINT_iidivision_aneg_b\romannumeral0\XINT_div_prepare {#1}{#2}{#1}}% |
| 24873 |
\def\XINT_iidivision_aneg_b #1#2{\if0\XINT_Sgn #2\xint: |
| 24874 |
\expandafter\XINT_iidivision_aneg_rzero |
| 24875 |
\else |
| 24876 |
\expandafter\XINT_iidivision_aneg_rpos |
| 24877 |
\fi {#1}{#2}}% |
| 24878 |
\def\XINT_iidivision_aneg_rzero #1#2#3{{-#1}{0}}% necessarily q was >0 |
| 24879 |
\def\XINT_iidivision_aneg_rpos #1% |
| 24880 |
{% |
| 24881 |
\expandafter\XINT_iidivision_aneg_end\expandafter |
| 24882 |
{\expandafter-\romannumeral0\xintinc {#1}}% q-> -(1+q) |
| 24883 |
}% |
| 24884 |
\def\XINT_iidivision_aneg_end #1#2#3% |
| 24885 |
{% |
| 24886 |
\expandafter\xint_exchangetwo_keepbraces |
| 24887 |
\expandafter{\romannumeral0\XINT_sub_mm_a {}{}#3\xint:#2\xint:}{#1}% r-> b-r |
| 24888 |
}% |
| 24889 |
% \end{macrocode} |
| 24890 |
%\begin{lverb} |
| 24891 |
% Le diviseur B va être étendu par des zéros pour que sa longueur soit |
| 24892 |
% multiple de huit. Les zéros seront mis du côté non significatif. |
| 24893 |
%\end{lverb} |
| 24894 |
% \begin{macrocode} |
| 24895 |
\def\XINT_div_prepare #1% |
| 24896 |
{% |
| 24897 |
\XINT_div_prepare_a #1\R\R\R\R\R\R\R\R {10}0000001\W !{#1}% |
| 24898 |
}% |
| 24899 |
\def\XINT_div_prepare_a #1#2#3#4#5#6#7#8#9% |
| 24900 |
{% |
| 24901 |
\xint_gob_til_R #9\XINT_div_prepare_small\R |
| 24902 |
\XINT_div_prepare_b #9% |
| 24903 |
}% |
| 24904 |
% \end{macrocode} |
| 24905 |
%\begin{lverb} |
| 24906 |
% B a au plus huit chiffres. On se débarrasse des trucs superflus. Si |
| 24907 |
% B>0 n'est ni 1 ni 2, le point d'entrée est \XINT_div_small_a {B}{A} (avec un |
| 24908 |
% A positif). |
| 24909 |
%\end{lverb} |
| 24910 |
% \begin{macrocode} |
| 24911 |
\def\XINT_div_prepare_small\R #1!#2% |
| 24912 |
{% |
| 24913 |
\ifcase #2 |
| 24914 |
\or\expandafter\XINT_div_BisOne |
| 24915 |
\or\expandafter\XINT_div_BisTwo |
| 24916 |
\else\expandafter\XINT_div_small_a |
| 24917 |
\fi {#2}% |
| 24918 |
}% |
| 24919 |
\def\XINT_div_BisOne #1#2{{#2}{0}}% |
| 24920 |
\def\XINT_div_BisTwo #1#2% |
| 24921 |
{% |
| 24922 |
\expandafter\expandafter\expandafter\XINT_div_BisTwo_a |
| 24923 |
\ifodd\xintLDg{#2} \expandafter1\else \expandafter0\fi {#2}% |
| 24924 |
}% |
| 24925 |
\def\XINT_div_BisTwo_a #1#2% |
| 24926 |
{% |
| 24927 |
\expandafter{\romannumeral0\XINT_half |
| 24928 |
#2\xint_bye\xint_Bye345678\xint_bye |
| 24929 |
*\xint_c_v+\xint_c_v)/\xint_c_x-\xint_c_i\relax}{#1}% |
| 24930 |
}% |
| 24931 |
% \end{macrocode} |
| 24932 |
%\begin{lverb} |
| 24933 |
% B a au plus huit chiffres et est au moins 3. On va l'utiliser |
| 24934 |
% directement, sans d'abord le multiplier par une puissance de 10 pour qu'il |
| 24935 |
% ait 8 chiffres. |
| 24936 |
%\end{lverb} |
| 24937 |
% \begin{macrocode} |
| 24938 |
\def\XINT_div_small_a #1#2% |
| 24939 |
{% |
| 24940 |
\expandafter\XINT_div_small_b |
| 24941 |
\the\numexpr #1/\xint_c_ii\expandafter |
| 24942 |
\xint:\the\numexpr \xint_c_x^viii+#1\expandafter!% |
| 24943 |
\romannumeral0% |
| 24944 |
\XINT_div_small_ba #2\R\R\R\R\R\R\R\R{10}0000001\W |
| 24945 |
#2\XINT_sepbyviii_Z_end 2345678\relax |
| 24946 |
}% |
| 24947 |
% \end{macrocode} |
| 24948 |
%\begin{lverb} |
| 24949 |
% Le #2 poursuivra l'expansion par \XINT_div_dosmallsmall ou par |
| 24950 |
% \XINT_smalldivx_a suivi de \XINT_sdiv_out. |
| 24951 |
%\end{lverb} |
| 24952 |
% \begin{macrocode} |
| 24953 |
\def\XINT_div_small_b #1!#2{#2#1!}% |
| 24954 |
% \end{macrocode} |
| 24955 |
%\begin{lverb} |
| 24956 |
% On ajoute des zéros avant A, puis on le prépare sous la forme de |
| 24957 |
% blocs 1<8d>! Au passage on repère le cas d'un A<10^8. |
| 24958 |
%\end{lverb} |
| 24959 |
% \begin{macrocode} |
| 24960 |
\def\XINT_div_small_ba #1#2#3#4#5#6#7#8#9% |
| 24961 |
{% |
| 24962 |
\xint_gob_til_R #9\XINT_div_smallsmall\R |
| 24963 |
\expandafter\XINT_div_dosmalldiv |
| 24964 |
\the\numexpr\expandafter\XINT_sepbyviii_Z |
| 24965 |
\romannumeral0\XINT_zeroes_forviii |
| 24966 |
#1#2#3#4#5#6#7#8#9% |
| 24967 |
}% |
| 24968 |
% \end{macrocode} |
| 24969 |
%\begin{lverb} |
| 24970 |
% Si A<10^8, on va poursuivre par \XINT_div_dosmallsmall |
| 24971 |
% round(B/2).10^8+B!{A}. On fait la division directe par \numexpr. Le résultat |
| 24972 |
% est produit sous la forme {Q}{R}. |
| 24973 |
%\end{lverb} |
| 24974 |
% \begin{macrocode} |
| 24975 |
\def\XINT_div_smallsmall\R |
| 24976 |
\expandafter\XINT_div_dosmalldiv |
| 24977 |
\the\numexpr\expandafter\XINT_sepbyviii_Z |
| 24978 |
\romannumeral0\XINT_zeroes_forviii #1\R #2\relax |
| 24979 |
{{\XINT_div_dosmallsmall}{#1}}% |
| 24980 |
\def\XINT_div_dosmallsmall #1\xint:1#2!#3% |
| 24981 |
{% |
| 24982 |
\expandafter\XINT_div_smallsmallend |
| 24983 |
\the\numexpr (#3+#1)/#2-\xint_c_i\xint:#2\xint:#3\xint:% |
| 24984 |
}% |
| 24985 |
\def\XINT_div_smallsmallend #1\xint:#2\xint:#3\xint:{\expandafter |
| 24986 |
{\the\numexpr #1\expandafter}\expandafter{\the\numexpr #3-#1*#2}}% |
| 24987 |
% \end{macrocode} |
| 24988 |
%\begin{lverb} |
| 24989 |
% Si A>=10^8, il est maintenant sous la forme 1<8d>!...1<8d>!1;! avec |
| 24990 |
% plus significatifs en premier. Donc on poursuit par$newline |
| 24991 |
% \expandafter\XINT_sdiv_out\the\numexpr\XINT_smalldivx_a |
| 24992 |
% x.1B!1<8d>!...1<8d>!1;! avec x =round(B/2), 1B=10^8+B. |
| 24993 |
%\end{lverb} |
| 24994 |
% \begin{macrocode} |
| 24995 |
\def\XINT_div_dosmalldiv |
| 24996 |
{{\expandafter\XINT_sdiv_out\the\numexpr\XINT_smalldivx_a}}% |
| 24997 |
% \end{macrocode} |
| 24998 |
%\begin{lverb} |
| 24999 |
% Ici B est au moins 10^8, on détermine combien de zéros lui adjoindre |
| 25000 |
% pour qu'il soit de longueur 8N. |
| 25001 |
%\end{lverb} |
| 25002 |
% \begin{macrocode} |
| 25003 |
\def\XINT_div_prepare_b |
| 25004 |
{\expandafter\XINT_div_prepare_c\romannumeral0\XINT_zeroes_forviii }% |
| 25005 |
\def\XINT_div_prepare_c #1!% |
| 25006 |
{% |
| 25007 |
\XINT_div_prepare_d #1.00000000!{#1}% |
| 25008 |
}% |
| 25009 |
\def\XINT_div_prepare_d #1#2#3#4#5#6#7#8#9% |
| 25010 |
{% |
| 25011 |
\expandafter\XINT_div_prepare_e\xint_gob_til_dot #1#2#3#4#5#6#7#8#9!% |
| 25012 |
}% |
| 25013 |
\def\XINT_div_prepare_e #1!#2!#3#4% |
| 25014 |
{% |
| 25015 |
\XINT_div_prepare_f #4#3\X {#1}{#3}% |
| 25016 |
}% |
| 25017 |
% \end{macrocode} |
| 25018 |
%\begin{lverb} |
| 25019 |
% attention qu'on calcule ici x'=x+1 (x = huit premiers chiffres du |
| 25020 |
% diviseur) et que si x=99999999, x' aura donc 9 chiffres, pas compatible avec |
| 25021 |
% div_mini (avant 1.2, x avait 4 chiffres, et on faisait la division avec x' |
| 25022 |
% dans un \numexpr). Bon, facile à dire après avoir laissé passer ce bug dans |
| 25023 |
% 1.2. C'est le problème lorsqu'au lieu de tout refaire à partir de zéro on |
| 25024 |
% recycle d'anciennes routines qui avaient un contexte différent. |
| 25025 |
%\end{lverb} |
| 25026 |
% \begin{macrocode} |
| 25027 |
\def\XINT_div_prepare_f #1#2#3#4#5#6#7#8#9\X |
| 25028 |
{% |
| 25029 |
\expandafter\XINT_div_prepare_g |
| 25030 |
\the\numexpr #1#2#3#4#5#6#7#8+\xint_c_i\expandafter |
| 25031 |
\xint:\the\numexpr (#1#2#3#4#5#6#7#8+\xint_c_i)/\xint_c_ii\expandafter |
| 25032 |
\xint:\the\numexpr #1#2#3#4#5#6#7#8\expandafter |
| 25033 |
\xint:\romannumeral0\XINT_sepandrev_andcount |
| 25034 |
#1#2#3#4#5#6#7#8#9\XINT_rsepbyviii_end_A 2345678% |
| 25035 |
\XINT_rsepbyviii_end_B 2345678\relax\xint_c_ii\xint_c_i |
| 25036 |
\R\xint:\xint_c_xii \R\xint:\xint_c_x \R\xint:\xint_c_viii \R\xint:\xint_c_vi |
| 25037 |
\R\xint:\xint_c_iv \R\xint:\xint_c_ii \R\xint:\xint_c_\W |
| 25038 |
\X |
| 25039 |
}% |
| 25040 |
\def\XINT_div_prepare_g #1\xint:#2\xint:#3\xint:#4\xint:#5\X #6#7#8% |
| 25041 |
{% |
| 25042 |
\expandafter\XINT_div_prepare_h |
| 25043 |
\the\numexpr\expandafter\XINT_sepbyviii_andcount |
| 25044 |
\romannumeral0\XINT_zeroes_forviii #8#7\R\R\R\R\R\R\R\R{10}0000001\W |
| 25045 |
#8#7\XINT_sepbyviii_end 2345678\relax |
| 25046 |
\xint_c_vii!\xint_c_vi!\xint_c_v!\xint_c_iv!% |
| 25047 |
\xint_c_iii!\xint_c_ii!\xint_c_i!\xint_c_\W |
| 25048 |
{#1}{#2}{#3}{#4}{#5}{#6}% |
| 25049 |
}% |
| 25050 |
\def\XINT_div_prepare_h #11\xint:#2\xint:#3#4#5#6%#7#8% |
| 25051 |
{% |
| 25052 |
\XINT_div_start_a {#2}{#6}{#1}{#3}{#4}{#5}%{#7}{#8}% |
| 25053 |
}% |
| 25054 |
% \end{macrocode} |
| 25055 |
%\begin{lverb} |
| 25056 |
% L, K, A, x',y,x, B, «c». Attention que K est diminué de 1 plus loin. |
| 25057 |
% Comme xint 1.2 a déjà repéré K=1, on a ici au minimum K=2. Attention B est à |
| 25058 |
% l'envers, A est à l'endroit et les deux avec séparateurs. Attention que ce |
| 25059 |
% n'est pas ici qu'on boucle mais en \XINT_div_I_a. |
| 25060 |
%\end{lverb} |
| 25061 |
% \begin{macrocode} |
| 25062 |
\def\XINT_div_start_a #1#2% |
| 25063 |
{% |
| 25064 |
\ifnum #1 < #2 |
| 25065 |
\expandafter\XINT_div_zeroQ |
| 25066 |
\else |
| 25067 |
\expandafter\XINT_div_start_b |
| 25068 |
\fi |
| 25069 |
{#1}{#2}% |
| 25070 |
}% |
| 25071 |
\def\XINT_div_zeroQ #1#2#3#4#5#6#7% |
| 25072 |
{% |
| 25073 |
\expandafter\XINT_div_zeroQ_end |
| 25074 |
\romannumeral0\XINT_unsep_cuzsmall |
| 25075 |
#3\xint_bye!2!3!4!5!6!7!8!9!\xint_bye\xint_c_i\relax\xint: |
| 25076 |
}% |
| 25077 |
\def\XINT_div_zeroQ_end #1\xint:#2% |
| 25078 |
{\expandafter{\expandafter0\expandafter}\XINT_div_cleanR #1#2\xint:}% |
| 25079 |
% \end{macrocode} |
| 25080 |
%\begin{lverb} |
| 25081 |
% L, K, A, x',y,x, B, «c»->K.A.x{LK{x'y}x}B«c» |
| 25082 |
%\end{lverb} |
| 25083 |
% \begin{macrocode} |
| 25084 |
\def\XINT_div_start_b #1#2#3#4#5#6% |
| 25085 |
{% |
| 25086 |
\expandafter\XINT_div_finish\the\numexpr |
| 25087 |
\XINT_div_start_c {#2}\xint:#3\xint:{#6}{{#1}{#2}{{#4}{#5}}{#6}}% |
| 25088 |
}% |
| 25089 |
\def\XINT_div_finish |
| 25090 |
{% |
| 25091 |
\expandafter\XINT_div_finish_a \romannumeral`&&@\XINT_div_unsepQ |
| 25092 |
}% |
| 25093 |
\def\XINT_div_finish_a #1\Z #2\xint:{\XINT_div_finish_b #2\xint:{#1}}% |
| 25094 |
% \end{macrocode} |
| 25095 |
%\begin{lverb} |
| 25096 |
% Ici ce sont routines de fin. Le reste déjà nettoyé. R.Q«c». |
| 25097 |
%\end{lverb} |
| 25098 |
% \begin{macrocode} |
| 25099 |
\def\XINT_div_finish_b #1% |
| 25100 |
{% |
| 25101 |
\if0#1% |
| 25102 |
\expandafter\XINT_div_finish_bRzero |
| 25103 |
\else |
| 25104 |
\expandafter\XINT_div_finish_bRpos |
| 25105 |
\fi |
| 25106 |
#1% |
| 25107 |
}% |
| 25108 |
\def\XINT_div_finish_bRzero 0\xint:#1#2{{#1}{0}}% |
| 25109 |
\def\XINT_div_finish_bRpos #1\xint:#2#3% |
| 25110 |
{% |
| 25111 |
\expandafter\xint_exchangetwo_keepbraces\XINT_div_cleanR #1#3\xint:{#2}% |
| 25112 |
}% |
| 25113 |
\def\XINT_div_cleanR #100000000\xint:{{#1}}% |
| 25114 |
% \end{macrocode} |
| 25115 |
%\begin{lverb} |
| 25116 |
% Kalpha.A.x{LK{x'y}x}, B, «c», au début #2=alpha est vide. On fait une |
| 25117 |
% boucle pour prendre K unités de A (on a au moins L égal à K) et les mettre |
| 25118 |
% dans alpha. |
| 25119 |
%\end{lverb} |
| 25120 |
% \begin{macrocode} |
| 25121 |
\def\XINT_div_start_c #1% |
| 25122 |
{% |
| 25123 |
\ifnum #1>\xint_c_vi |
| 25124 |
\expandafter\XINT_div_start_ca |
| 25125 |
\else |
| 25126 |
\expandafter\XINT_div_start_cb |
| 25127 |
\fi {#1}% |
| 25128 |
}% |
| 25129 |
\def\XINT_div_start_ca #1#2\xint:#3!#4!#5!#6!#7!#8!#9!% |
| 25130 |
{% |
| 25131 |
\expandafter\XINT_div_start_c\expandafter |
| 25132 |
{\the\numexpr #1-\xint_c_vii}#2#3!#4!#5!#6!#7!#8!#9!\xint:% |
| 25133 |
}% |
| 25134 |
\def\XINT_div_start_cb #1% |
| 25135 |
{\csname XINT_div_start_c_\romannumeral\numexpr#1\endcsname}% |
| 25136 |
\def\XINT_div_start_c_i #1\xint:#2!% |
| 25137 |
{\XINT_div_start_c_ #1#2!\xint:}% |
| 25138 |
\def\XINT_div_start_c_ii #1\xint:#2!#3!% |
| 25139 |
{\XINT_div_start_c_ #1#2!#3!\xint:}% |
| 25140 |
\def\XINT_div_start_c_iii #1\xint:#2!#3!#4!% |
| 25141 |
{\XINT_div_start_c_ #1#2!#3!#4!\xint:}% |
| 25142 |
\def\XINT_div_start_c_iv #1\xint:#2!#3!#4!#5!% |
| 25143 |
{\XINT_div_start_c_ #1#2!#3!#4!#5!\xint:}% |
| 25144 |
\def\XINT_div_start_c_v #1\xint:#2!#3!#4!#5!#6!% |
| 25145 |
{\XINT_div_start_c_ #1#2!#3!#4!#5!#6!\xint:}% |
| 25146 |
\def\XINT_div_start_c_vi #1\xint:#2!#3!#4!#5!#6!#7!% |
| 25147 |
{\XINT_div_start_c_ #1#2!#3!#4!#5!#6!#7!\xint:}% |
| 25148 |
% \end{macrocode} |
| 25149 |
%\begin{lverb} |
| 25150 |
% #1=a, #2=alpha (de longueur K, à l'endroit).#3=reste de A.#4=x, |
| 25151 |
% #5={LK{x'y}x},#6=B,«c» -> a, x, alpha, B, {00000000}, L, K, {x'y},x, |
| 25152 |
% alpha'=reste de A, B«c». |
| 25153 |
%\end{lverb} |
| 25154 |
% \begin{macrocode} |
| 25155 |
\def\XINT_div_start_c_ 1#1!#2\xint:#3\xint:#4#5#6% |
| 25156 |
{% |
| 25157 |
\XINT_div_I_a {#1}{#4}{1#1!#2}{#6}{00000000}#5{#3}{#6}% |
| 25158 |
}% |
| 25159 |
% \end{macrocode} |
| 25160 |
%\begin{lverb} |
| 25161 |
% Ceci est le point de retour de la boucle principale. a, x, alpha, B, |
| 25162 |
% q0, L, K, {x'y}, x, alpha', B«c» |
| 25163 |
%\end{lverb} |
| 25164 |
% \begin{macrocode} |
| 25165 |
\def\XINT_div_I_a #1#2% |
| 25166 |
{% |
| 25167 |
\expandafter\XINT_div_I_b\the\numexpr #1/#2\xint:{#1}{#2}% |
| 25168 |
}% |
| 25169 |
\def\XINT_div_I_b #1% |
| 25170 |
{% |
| 25171 |
\xint_gob_til_zero #1\XINT_div_I_czero 0\XINT_div_I_c #1% |
| 25172 |
}% |
| 25173 |
% \end{macrocode} |
| 25174 |
%\begin{lverb} |
| 25175 |
% On intercepte petit quotient nul: #1=a, x, alpha, B, #5=q0, L, K, |
| 25176 |
% {x'y}, x, alpha', B«c» -> on lâche un q puis {alpha} L, K, {x'y}, x, |
| 25177 |
% alpha', B«c». |
| 25178 |
%\end{lverb} |
| 25179 |
% \begin{macrocode} |
| 25180 |
\def\XINT_div_I_czero 0\XINT_div_I_c 0\xint:#1#2#3#4#5{1#5\XINT_div_I_g {#3}}% |
| 25181 |
\def\XINT_div_I_c #1\xint:#2#3% |
| 25182 |
{% |
| 25183 |
\expandafter\XINT_div_I_da\the\numexpr #2-#1*#3\xint:#1\xint:{#2}{#3}% |
| 25184 |
}% |
| 25185 |
% \end{macrocode} |
| 25186 |
%\begin{lverb} |
| 25187 |
% r.q.alpha, B, q0, L, K, {x'y}, x, alpha', B«c» |
| 25188 |
%\end{lverb} |
| 25189 |
% \begin{macrocode} |
| 25190 |
\def\XINT_div_I_da #1\xint:% |
| 25191 |
{% |
| 25192 |
\ifnum #1>\xint_c_ix |
| 25193 |
\expandafter\XINT_div_I_dP |
| 25194 |
\else |
| 25195 |
\ifnum #1<\xint_c_ |
| 25196 |
\expandafter\expandafter\expandafter\XINT_div_I_dN |
| 25197 |
\else |
| 25198 |
\expandafter\expandafter\expandafter\XINT_div_I_db |
| 25199 |
\fi |
| 25200 |
\fi |
| 25201 |
}% |
| 25202 |
% \end{macrocode} |
| 25203 |
%\begin{lverb} |
| 25204 |
% attention très mauvaises notations avec _b et _db. |
| 25205 |
%\end{lverb} |
| 25206 |
% \begin{macrocode} |
| 25207 |
\def\XINT_div_I_dN #1\xint:% |
| 25208 |
{% |
| 25209 |
\expandafter\XINT_div_I_b\the\numexpr #1-\xint_c_i\xint:% |
| 25210 |
}% |
| 25211 |
\def\XINT_div_I_db #1\xint:#2#3#4#5% |
| 25212 |
{% |
| 25213 |
\expandafter\XINT_div_I_dc\expandafter #1% |
| 25214 |
\romannumeral0\expandafter\XINT_div_sub\expandafter |
| 25215 |
{\romannumeral0\XINT_rev_nounsep {}#4\R!\R!\R!\R!\R!\R!\R!\R!\W}% |
| 25216 |
{\the\numexpr\XINT_div_verysmallmul #1!#51;!}% |
| 25217 |
\Z {#4}{#5}% |
| 25218 |
}% |
| 25219 |
% \end{macrocode} |
| 25220 |
%\begin{lverb} |
| 25221 |
% La soustraction spéciale renvoie simplement - si le chiffre q est |
| 25222 |
% trop grand. On invoque dans ce cas I_dP. |
| 25223 |
%\end{lverb} |
| 25224 |
% \begin{macrocode} |
| 25225 |
\def\XINT_div_I_dc #1#2% |
| 25226 |
{% |
| 25227 |
\if-#2\expandafter\XINT_div_I_dd\else\expandafter\XINT_div_I_de\fi |
| 25228 |
#1#2% |
| 25229 |
}% |
| 25230 |
\def\XINT_div_I_dd #1-\Z |
| 25231 |
{% |
| 25232 |
\if #11\expandafter\XINT_div_I_dz\fi |
| 25233 |
\expandafter\XINT_div_I_dP\the\numexpr #1-\xint_c_i\xint: XX% |
| 25234 |
}% |
| 25235 |
\def\XINT_div_I_dz #1XX#2#3#4% |
| 25236 |
{% |
| 25237 |
1#4\XINT_div_I_g {#2}% |
| 25238 |
}% |
| 25239 |
\def\XINT_div_I_de #1#2\Z #3#4#5{1#5+#1\XINT_div_I_g {#2}}% |
| 25240 |
% \end{macrocode} |
| 25241 |
%\begin{lverb} |
| 25242 |
% q.alpha, B, q0, L, K, {x'y},x, alpha'B«c» (q=0 has been intercepted) |
| 25243 |
% -> 1nouveauq.nouvel alpha, L, K, {x'y}, x, alpha',B«c» |
| 25244 |
%\end{lverb} |
| 25245 |
% \begin{macrocode} |
| 25246 |
\def\XINT_div_I_dP #1\xint:#2#3#4#5#6% |
| 25247 |
{% |
| 25248 |
1#6+#1\expandafter\XINT_div_I_g\expandafter |
| 25249 |
{\romannumeral0\expandafter\XINT_div_sub\expandafter |
| 25250 |
{\romannumeral0\XINT_rev_nounsep {}#4\R!\R!\R!\R!\R!\R!\R!\R!\W}% |
| 25251 |
{\the\numexpr\XINT_div_verysmallmul #1!#51;!}% |
| 25252 |
}% |
| 25253 |
}% |
| 25254 |
% \end{macrocode} |
| 25255 |
%\begin{lverb} |
| 25256 |
% 1#1=nouveau q. nouvel alpha, L, K, {x'y},x,alpha', BQ«c» |
| 25257 |
%\end{lverb} |
| 25258 |
% \begin{macrocode} |
| 25259 |
% \end{macrocode} |
| 25260 |
%\begin{lverb} |
| 25261 |
% #1=q,#2=nouvel alpha,#3=L, #4=K, #5={x'y}, #6=x, #7= alpha',#8=B, |
| 25262 |
% «c» -> on laisse q puis {x'y}alpha.alpha'.{{x'y}xKL}B«c» |
| 25263 |
%\end{lverb} |
| 25264 |
% \begin{macrocode} |
| 25265 |
\def\XINT_div_I_g #1#2#3#4#5#6#7% |
| 25266 |
{% |
| 25267 |
\expandafter !\the\numexpr |
| 25268 |
\ifnum#2=#3 |
| 25269 |
\expandafter\XINT_div_exittofinish |
| 25270 |
\else |
| 25271 |
\expandafter\XINT_div_I_h |
| 25272 |
\fi |
| 25273 |
{#4}#1\xint:#6\xint:{{#4}{#5}{#3}{#2}}{#7}% |
| 25274 |
}% |
| 25275 |
% \end{macrocode} |
| 25276 |
%\begin{lverb} |
| 25277 |
% {x'y}alpha.alpha'.{{x'y}xKL}B«c» -> Attention retour à l'envoyeur ici |
| 25278 |
% par terminaison des \the\numexpr. On doit reprendre le Q déjà sorti, qui n'a |
| 25279 |
% plus de séparateurs, ni de leading 1. Ensuite R sans leading zeros.«c» |
| 25280 |
%\end{lverb} |
| 25281 |
% \begin{macrocode} |
| 25282 |
\def\XINT_div_exittofinish #1#2\xint:#3\xint:#4#5% |
| 25283 |
{% |
| 25284 |
1\expandafter\expandafter\expandafter!\expandafter\XINT_div_unsepQ_delim |
| 25285 |
\romannumeral0\XINT_div_unsepR #2#3% |
| 25286 |
\xint_bye!2!3!4!5!6!7!8!9!\xint_bye\xint_c_i\relax\R\xint: |
| 25287 |
}% |
| 25288 |
% \end{macrocode} |
| 25289 |
%\begin{lverb} |
| 25290 |
% ATTENTION DESCRIPTION OBSOLÈTE. #1={x'y}alpha.#2!#3=reste de A. |
| 25291 |
% #4={{x'y},x,K,L},#5=B,«c» devient {x'y},alpha sur K+4 chiffres.B, |
| 25292 |
% {{x'y},x,K,L}, #6= nouvel alpha',B,«c» |
| 25293 |
%\end{lverb} |
| 25294 |
% \begin{macrocode} |
| 25295 |
\def\XINT_div_I_h #1\xint:#2!#3\xint:#4#5% |
| 25296 |
{% |
| 25297 |
\XINT_div_II_b #1#2!\xint:{#5}{#4}{#3}{#5}% |
| 25298 |
}% |
| 25299 |
% \end{macrocode} |
| 25300 |
%\begin{lverb} |
| 25301 |
% {x'y}alpha.B, {{x'y},x,K,L}, nouveau alpha',B,«c» |
| 25302 |
%\end{lverb} |
| 25303 |
% \begin{macrocode} |
| 25304 |
\def\XINT_div_II_b #11#2!#3!% |
| 25305 |
{% |
| 25306 |
\xint_gob_til_eightzeroes #2\XINT_div_II_skipc 00000000% |
| 25307 |
\XINT_div_II_c #1{1#2}{#3}% |
| 25308 |
}% |
| 25309 |
% \end{macrocode} |
| 25310 |
%\begin{lverb} |
| 25311 |
% x'y{100000000}{1<8>}reste de alpha.#6=B,#7={{x'y},x,K,L}, alpha',B, |
| 25312 |
% «c» -> {x'y}x,K,L (à diminuer de 4), {alpha sur |
| 25313 |
% K}B{q1=00000000}{alpha'}B,«c» |
| 25314 |
%\end{lverb} |
| 25315 |
% \begin{macrocode} |
| 25316 |
\def\XINT_div_II_skipc 00000000\XINT_div_II_c #1#2#3#4#5\xint:#6#7% |
| 25317 |
{% |
| 25318 |
\XINT_div_II_k #7{#4!#5}{#6}{00000000}% |
| 25319 |
}% |
| 25320 |
% \end{macrocode} |
| 25321 |
%\begin{lverb} |
| 25322 |
% x'ya->1qx'yalpha.B, {{x'y},x,K,L}, nouveau alpha',B, «c». En fait, |
| 25323 |
% attention, ici #3 et #4 sont les 16 premiers chiffres du numérateur,sous la |
| 25324 |
% forme blocs 1<8chiffres>. |
| 25325 |
%\end{lverb} |
| 25326 |
% \begin{macrocode} |
| 25327 |
\def\XINT_div_II_c #1#2#3#4% |
| 25328 |
{% |
| 25329 |
\expandafter\XINT_div_II_d\the\numexpr\XINT_div_xmini |
| 25330 |
#1\xint:#2!#3!#4!{#1}{#2}#3!#4!% |
| 25331 |
}% |
| 25332 |
\def\XINT_div_xmini #1% |
| 25333 |
{% |
| 25334 |
\xint_gob_til_one #1\XINT_div_xmini_a 1\XINT_div_mini #1% |
| 25335 |
}% |
| 25336 |
\def\XINT_div_xmini_a 1\XINT_div_mini 1#1% |
| 25337 |
{% |
| 25338 |
\xint_gob_til_zero #1\XINT_div_xmini_b 0\XINT_div_mini 1#1% |
| 25339 |
}% |
| 25340 |
\def\XINT_div_xmini_b 0\XINT_div_mini 10#1#2#3#4#5#6#7% |
| 25341 |
{% |
| 25342 |
\xint_gob_til_zero #7\XINT_div_xmini_c 0\XINT_div_mini 10#1#2#3#4#5#6#7% |
| 25343 |
}% |
| 25344 |
% \end{macrocode} |
| 25345 |
%\begin{lverb} |
| 25346 |
% x'=10^8 and we return #1=1<8digits>. |
| 25347 |
%\end{lverb} |
| 25348 |
% \begin{macrocode} |
| 25349 |
\def\XINT_div_xmini_c 0\XINT_div_mini 100000000\xint:50000000!#1!#2!{#1!}% |
| 25350 |
% \end{macrocode} |
| 25351 |
%\begin{lverb} |
| 25352 |
% 1 suivi de q1 sur huit chiffres! #2=x', #3=y, #4=alpha.#5=B, |
| 25353 |
% {{x'y},x,K,L}, alpha', B, «c» --> nouvel alpha.x',y,B,q1,{{x'y},x,K,L}, |
| 25354 |
% alpha', B, «c» |
| 25355 |
%\end{lverb} |
| 25356 |
% \begin{macrocode} |
| 25357 |
\def\XINT_div_II_d 1#1#2#3#4#5!#6#7#8\xint:#9% |
| 25358 |
{% |
| 25359 |
\expandafter\XINT_div_II_e |
| 25360 |
\romannumeral0\expandafter\XINT_div_sub\expandafter |
| 25361 |
{\romannumeral0\XINT_rev_nounsep {}#8\R!\R!\R!\R!\R!\R!\R!\R!\W}% |
| 25362 |
{\the\numexpr\XINT_div_smallmul_a 100000000\xint:#1#2#3#4\xint:#5!#91;!}% |
| 25363 |
\xint:{#6}{#7}{#9}{#1#2#3#4#5}% |
| 25364 |
}% |
| 25365 |
% \end{macrocode} |
| 25366 |
%\begin{lverb} |
| 25367 |
% alpha.x',y,B,q1, {{x'y},x,K,L}, alpha', B, «c». Attention la |
| 25368 |
% soustraction spéciale doit maintenir les blocs 1<8>! |
| 25369 |
%\end{lverb} |
| 25370 |
% \begin{macrocode} |
| 25371 |
\def\XINT_div_II_e 1#1!% |
| 25372 |
{% |
| 25373 |
\xint_gob_til_eightzeroes #1\XINT_div_II_skipf 00000000% |
| 25374 |
\XINT_div_II_f 1#1!% |
| 25375 |
}% |
| 25376 |
% \end{macrocode} |
| 25377 |
%\begin{lverb} |
| 25378 |
% 100000000! alpha sur K chiffres.#2=x',#3=y,#4=B,#5=q1, #6={{x'y},x,K,L}, |
| 25379 |
% #7=alpha',B«c» -> {x'y}x,K,L (à diminuer de 1), |
| 25380 |
% {alpha sur K}B{q1}{alpha'}B«c» |
| 25381 |
%\end{lverb} |
| 25382 |
% \begin{macrocode} |
| 25383 |
\def\XINT_div_II_skipf 00000000\XINT_div_II_f 100000000!#1\xint:#2#3#4#5#6% |
| 25384 |
{% |
| 25385 |
\XINT_div_II_k #6{#1}{#4}{#5}% |
| 25386 |
}% |
| 25387 |
% \end{macrocode} |
| 25388 |
%\begin{lverb} |
| 25389 |
% 1<a1>!1<a2>!, alpha (sur K+1 blocs de 8). x', y, B, q1, {{x'y},x,K,L}, |
| 25390 |
% alpha', B,«c». |
| 25391 |
% |
| 25392 |
% Here also we are dividing with x' which could be 10^8 in the exceptional |
| 25393 |
% case x=99999999. Must intercept it before sending to \XINT_div_mini. |
| 25394 |
%\end{lverb} |
| 25395 |
% \begin{macrocode} |
| 25396 |
\def\XINT_div_II_f #1!#2!#3\xint:% |
| 25397 |
{% |
| 25398 |
\XINT_div_II_fa {#1!#2!}{#1!#2!#3}% |
| 25399 |
}% |
| 25400 |
\def\XINT_div_II_fa #1#2#3#4% |
| 25401 |
{% |
| 25402 |
\expandafter\XINT_div_II_g \the\numexpr\XINT_div_xmini #3\xint:#4!#1{#2}% |
| 25403 |
}% |
| 25404 |
% \end{macrocode} |
| 25405 |
%\begin{lverb} |
| 25406 |
% #1=q, #2=alpha (K+4), #3=B, #4=q1, {{x'y},x,K,L}, alpha', BQ«c» |
| 25407 |
% -> 1 puis nouveau q sur 8 chiffres. nouvel alpha sur K blocs, |
| 25408 |
% B, {{x'y},x,K,L}, alpha',B«c» |
| 25409 |
%\end{lverb} |
| 25410 |
% \begin{macrocode} |
| 25411 |
\def\XINT_div_II_g 1#1#2#3#4#5!#6#7#8% |
| 25412 |
{% |
| 25413 |
\expandafter \XINT_div_II_h |
| 25414 |
\the\numexpr 1#1#2#3#4#5+#8\expandafter\expandafter\expandafter |
| 25415 |
\xint:\expandafter\expandafter\expandafter |
| 25416 |
{\expandafter\xint_gob_til_exclam |
| 25417 |
\romannumeral0\expandafter\XINT_div_sub\expandafter |
| 25418 |
{\romannumeral0\XINT_rev_nounsep {}#6\R!\R!\R!\R!\R!\R!\R!\R!\W}% |
| 25419 |
{\the\numexpr\XINT_div_smallmul_a 100000000\xint:#1#2#3#4\xint:#5!#71;!}}% |
| 25420 |
{#7}% |
| 25421 |
}% |
| 25422 |
% \end{macrocode} |
| 25423 |
%\begin{lverb} |
| 25424 |
% 1 puis nouveau q sur 8 chiffres, #2=nouvel alpha sur K blocs, |
| 25425 |
% #3=B, #4={{x'y},x,K,L} avec L à ajuster, alpha', BQ«c» |
| 25426 |
% -> {x'y}x,K,L à diminuer de 1, {alpha}B{q}, alpha', BQ«c» |
| 25427 |
%\end{lverb} |
| 25428 |
% \begin{macrocode} |
| 25429 |
\def\XINT_div_II_h 1#1\xint:#2#3#4% |
| 25430 |
{% |
| 25431 |
\XINT_div_II_k #4{#2}{#3}{#1}% |
| 25432 |
}% |
| 25433 |
% \end{macrocode} |
| 25434 |
%\begin{lverb} |
| 25435 |
% {x'y}x,K,L à diminuer de 1, alpha, B{q}alpha',B«c» |
| 25436 |
% ->nouveau L.K,x',y,x,alpha.B,q,alpha',B,«c» |
| 25437 |
% ->{LK{x'y}x},x,a,alpha.B,q,alpha',B,«c» |
| 25438 |
%\end{lverb} |
| 25439 |
% \begin{macrocode} |
| 25440 |
\def\XINT_div_II_k #1#2#3#4#5% |
| 25441 |
{% |
| 25442 |
\expandafter\XINT_div_II_l \the\numexpr #4-\xint_c_i\xint:{#3}#1{#2}#5\xint:% |
| 25443 |
}% |
| 25444 |
\def\XINT_div_II_l #1\xint:#2#3#4#51#6!% |
| 25445 |
{% |
| 25446 |
\XINT_div_II_m {{#1}{#2}{{#3}{#4}}{#5}}{#5}{#6}1#6!% |
| 25447 |
}% |
| 25448 |
% \end{macrocode} |
| 25449 |
%\begin{lverb} |
| 25450 |
% {LK{x'y}x},x,a,alpha.B{q}alpha'B -> a, x, alpha, B, q, |
| 25451 |
% L, K, {x'y}, x, alpha', B«c» |
| 25452 |
%\end{lverb} |
| 25453 |
% \begin{macrocode} |
| 25454 |
\def\XINT_div_II_m #1#2#3#4\xint:#5#6% |
| 25455 |
{% |
| 25456 |
\XINT_div_I_a {#3}{#2}{#4}{#5}{#6}#1% |
| 25457 |
}% |
| 25458 |
% \end{macrocode} |
| 25459 |
%\begin{lverb} |
| 25460 |
% This multiplication is exactly like \XINT_smallmul -- apart from not |
| 25461 |
% inserting an ending 1;! --, but keeps ever a vanishing ending carry. |
| 25462 |
%\end{lverb} |
| 25463 |
% \begin{macrocode} |
| 25464 |
\def\XINT_div_minimulwc_a 1#1\xint:#2\xint:#3!#4#5#6#7#8\xint:% |
| 25465 |
{% |
| 25466 |
\expandafter\XINT_div_minimulwc_b |
| 25467 |
\the\numexpr \xint_c_x^ix+#1+#3*#8\xint:#3*#4#5#6#7+#2*#8\xint:#2*#4#5#6#7\xint:% |
| 25468 |
}% |
| 25469 |
\def\XINT_div_minimulwc_b 1#1#2#3#4#5#6\xint:#7\xint:% |
| 25470 |
{% |
| 25471 |
\expandafter\XINT_div_minimulwc_c |
| 25472 |
\the\numexpr \xint_c_x^ix+#1#2#3#4#5+#7\xint:#6\xint:% |
| 25473 |
}% |
| 25474 |
\def\XINT_div_minimulwc_c 1#1#2#3#4#5#6\xint:#7\xint:#8\xint:% |
| 25475 |
{% |
| 25476 |
1#6#7\expandafter!% |
| 25477 |
\the\numexpr\expandafter\XINT_div_smallmul_a |
| 25478 |
\the\numexpr \xint_c_x^viii+#1#2#3#4#5+#8\xint:% |
| 25479 |
}% |
| 25480 |
\def\XINT_div_smallmul_a #1\xint:#2\xint:#3!1#4!% |
| 25481 |
{% |
| 25482 |
\xint_gob_til_sc #4\XINT_div_smallmul_e;% |
| 25483 |
\XINT_div_minimulwc_a #1\xint:#2\xint:#3!#4\xint:#2\xint:#3!% |
| 25484 |
}% |
| 25485 |
\def\XINT_div_smallmul_e;\XINT_div_minimulwc_a 1#1\xint:#2;#3!{1\relax #1!}% |
| 25486 |
% \end{macrocode} |
| 25487 |
%\begin{lverb} |
| 25488 |
% Special very small multiplication for division. We only need to cater |
| 25489 |
% for multiplicands from 1 to 9. The ending is different from standard |
| 25490 |
% verysmallmul, a zero carry is not suppressed. And no final 1;! is added. If |
| 25491 |
% multiplicand is just 1 let's not forget to add the zero carry 100000000! at |
| 25492 |
% the end. |
| 25493 |
%\end{lverb} |
| 25494 |
% \begin{macrocode} |
| 25495 |
\def\XINT_div_verysmallmul #1% |
| 25496 |
{\xint_gob_til_one #1\XINT_div_verysmallisone 1\XINT_div_verysmallmul_a 0\xint:#1}% |
| 25497 |
\def\XINT_div_verysmallisone 1\XINT_div_verysmallmul_a 0\xint:1!1#11;!% |
| 25498 |
{1\relax #1100000000!}% |
| 25499 |
\def\XINT_div_verysmallmul_a #1\xint:#2!1#3!% |
| 25500 |
{% |
| 25501 |
\xint_gob_til_sc #3\XINT_div_verysmallmul_e;% |
| 25502 |
\expandafter\XINT_div_verysmallmul_b |
| 25503 |
\the\numexpr \xint_c_x^ix+#2*#3+#1\xint:#2!% |
| 25504 |
}% |
| 25505 |
\def\XINT_div_verysmallmul_b 1#1#2\xint:% |
| 25506 |
{1#2\expandafter!\the\numexpr\XINT_div_verysmallmul_a #1\xint:}% |
| 25507 |
\def\XINT_div_verysmallmul_e;#1;+#2#3!{1\relax 0000000#2!}% |
| 25508 |
% \end{macrocode} |
| 25509 |
%\begin{lverb} |
| 25510 |
% Special subtraction for division purposes. If the subtracted thing |
| 25511 |
% turns out to be bigger, then just return a -. If not, then we must reverse |
| 25512 |
% the result, keeping the separators. |
| 25513 |
%\end{lverb} |
| 25514 |
% \begin{macrocode} |
| 25515 |
\def\XINT_div_sub #1#2% |
| 25516 |
{% |
| 25517 |
\expandafter\XINT_div_sub_clean |
| 25518 |
\the\numexpr\expandafter\XINT_div_sub_a\expandafter |
| 25519 |
1#2;!;!;!;!;!\W #1;!;!;!;!;!\W |
| 25520 |
}% |
| 25521 |
\def\XINT_div_sub_clean #1-#2#3\W |
| 25522 |
{% |
| 25523 |
\if1#2\expandafter\XINT_rev_nounsep\else\expandafter\XINT_div_sub_neg\fi |
| 25524 |
{}#1\R!\R!\R!\R!\R!\R!\R!\R!\W |
| 25525 |
}% |
| 25526 |
\def\XINT_div_sub_neg #1\W { -}% |
| 25527 |
\def\XINT_div_sub_a #1!#2!#3!#4!#5\W #6!#7!#8!#9!% |
| 25528 |
{% |
| 25529 |
\XINT_div_sub_b #1!#6!#2!#7!#3!#8!#4!#9!#5\W |
| 25530 |
}% |
| 25531 |
\def\XINT_div_sub_b #1#2#3!#4!% |
| 25532 |
{% |
| 25533 |
\xint_gob_til_sc #4\XINT_div_sub_bi ;% |
| 25534 |
\expandafter\XINT_div_sub_c\the\numexpr#1-#3+1#4-\xint_c_i\xint:% |
| 25535 |
}% |
| 25536 |
\def\XINT_div_sub_c 1#1#2\xint:% |
| 25537 |
{% |
| 25538 |
1#2\expandafter!\the\numexpr\XINT_div_sub_d #1% |
| 25539 |
}% |
| 25540 |
\def\XINT_div_sub_d #1#2#3!#4!% |
| 25541 |
{% |
| 25542 |
\xint_gob_til_sc #4\XINT_div_sub_di ;% |
| 25543 |
\expandafter\XINT_div_sub_e\the\numexpr#1-#3+1#4-\xint_c_i\xint:% |
| 25544 |
}% |
| 25545 |
\def\XINT_div_sub_e 1#1#2\xint:% |
| 25546 |
{% |
| 25547 |
1#2\expandafter!\the\numexpr\XINT_div_sub_f #1% |
| 25548 |
}% |
| 25549 |
\def\XINT_div_sub_f #1#2#3!#4!% |
| 25550 |
{% |
| 25551 |
\xint_gob_til_sc #4\XINT_div_sub_fi ;% |
| 25552 |
\expandafter\XINT_div_sub_g\the\numexpr#1-#3+1#4-\xint_c_i\xint:% |
| 25553 |
}% |
| 25554 |
\def\XINT_div_sub_g 1#1#2\xint:% |
| 25555 |
{% |
| 25556 |
1#2\expandafter!\the\numexpr\XINT_div_sub_h #1% |
| 25557 |
}% |
| 25558 |
\def\XINT_div_sub_h #1#2#3!#4!% |
| 25559 |
{% |
| 25560 |
\xint_gob_til_sc #4\XINT_div_sub_hi ;% |
| 25561 |
\expandafter\XINT_div_sub_i\the\numexpr#1-#3+1#4-\xint_c_i\xint:% |
| 25562 |
}% |
| 25563 |
\def\XINT_div_sub_i 1#1#2\xint:% |
| 25564 |
{% |
| 25565 |
1#2\expandafter!\the\numexpr\XINT_div_sub_a #1% |
| 25566 |
}% |
| 25567 |
\def\XINT_div_sub_bi;% |
| 25568 |
\expandafter\XINT_div_sub_c\the\numexpr#1-#2+#3\xint:#4!#5!#6!#7!#8!#9!;!\W |
| 25569 |
{% |
| 25570 |
\XINT_div_sub_l #1#2!#5!#7!#9!% |
| 25571 |
}% |
| 25572 |
\def\XINT_div_sub_di;% |
| 25573 |
\expandafter\XINT_div_sub_e\the\numexpr#1-#2+#3\xint:#4!#5!#6!#7!#8\W |
| 25574 |
{% |
| 25575 |
\XINT_div_sub_l #1#2!#5!#7!% |
| 25576 |
}% |
| 25577 |
\def\XINT_div_sub_fi;% |
| 25578 |
\expandafter\XINT_div_sub_g\the\numexpr#1-#2+#3\xint:#4!#5!#6\W |
| 25579 |
{% |
| 25580 |
\XINT_div_sub_l #1#2!#5!% |
| 25581 |
}% |
| 25582 |
\def\XINT_div_sub_hi;% |
| 25583 |
\expandafter\XINT_div_sub_i\the\numexpr#1-#2+#3\xint:#4\W |
| 25584 |
{% |
| 25585 |
\XINT_div_sub_l #1#2!% |
| 25586 |
}% |
| 25587 |
\def\XINT_div_sub_l #1% |
| 25588 |
{% |
| 25589 |
\xint_UDzerofork |
| 25590 |
#1{-2\relax}% |
| 25591 |
0\XINT_div_sub_r |
| 25592 |
\krof |
| 25593 |
}% |
| 25594 |
\def\XINT_div_sub_r #1!% |
| 25595 |
{% |
| 25596 |
-\ifnum 0#1=\xint_c_ 1\else2\fi\relax |
| 25597 |
}% |
| 25598 |
% \end{macrocode} |
| 25599 |
%\begin{lverb} |
| 25600 |
% Ici B<10^8 (et est >2). On |
| 25601 |
% exécute$newline |
| 25602 |
% \expandafter\XINT_sdiv_out\the\numexpr\XINT_smalldivx_a |
| 25603 |
% x.1B!1<8d>!...1<8d>!1;!$newline |
| 25604 |
% avec x =round(B/2), 1B=10^8+B, et A déjà en |
| 25605 |
% blocs 1<8d>! (non renversés). Le \the\numexpr\XINT_smalldivx_a va produire |
| 25606 |
% Q\Z R\W avec un R<10^8, et un Q sous forme de blocs 1<8d>! terminé par 1! |
| 25607 |
% et nécessitant le nettoyage du premier bloc. Dans cette branche le B n'a pas |
| 25608 |
% été multiplié par une puissance de 10, il peut avoir moins de huit chiffres. |
| 25609 |
% |
| 25610 |
%\end{lverb} |
| 25611 |
% \begin{macrocode} |
| 25612 |
\def\XINT_sdiv_out #1;!#2!% |
| 25613 |
{\expandafter |
| 25614 |
{\romannumeral0\XINT_unsep_cuzsmall |
| 25615 |
#1\xint_bye!2!3!4!5!6!7!8!9!\xint_bye\xint_c_i\relax}% |
| 25616 |
{#2}}% |
| 25617 |
% \end{macrocode} |
| 25618 |
%\begin{lverb} |
| 25619 |
% La toute première étape fait la première division pour être sûr par |
| 25620 |
% la suite d'avoir un premier bloc pour A qui sera < B. |
| 25621 |
%\end{lverb} |
| 25622 |
% \begin{macrocode} |
| 25623 |
\def\XINT_smalldivx_a #1\xint:1#2!1#3!% |
| 25624 |
{% |
| 25625 |
\expandafter\XINT_smalldivx_b |
| 25626 |
\the\numexpr (#3+#1)/#2-\xint_c_i!#1\xint:#2!#3!% |
| 25627 |
}% |
| 25628 |
\def\XINT_smalldivx_b #1#2!% |
| 25629 |
{% |
| 25630 |
\if0#1\else |
| 25631 |
\xint_c_x^viii+#1#2\xint_afterfi{\expandafter!\the\numexpr}\fi |
| 25632 |
\XINT_smalldiv_c #1#2!% |
| 25633 |
}% |
| 25634 |
\def\XINT_smalldiv_c #1!#2\xint:#3!#4!% |
| 25635 |
{% |
| 25636 |
\expandafter\XINT_smalldiv_d\the\numexpr #4-#1*#3!#2\xint:#3!% |
| 25637 |
}% |
| 25638 |
% \end{macrocode} |
| 25639 |
%\begin{lverb} |
| 25640 |
% On va boucler ici: #1 est un reste, #2 est x.B (avec B sans le 1 mais |
| 25641 |
% sur huit chiffres). #3#4 est le premier bloc qui reste de A. Si on a terminé |
| 25642 |
% avec A, alors #1 est le reste final. Le quotient lui est terminé par un 1! |
| 25643 |
% ce 1! disparaîtra dans le nettoyage par \XINT_unsep_cuzsmall. |
| 25644 |
%\end{lverb} |
| 25645 |
% \begin{macrocode} |
| 25646 |
\def\XINT_smalldiv_d #1!#2!1#3#4!% |
| 25647 |
{% |
| 25648 |
\xint_gob_til_sc #3\XINT_smalldiv_end ;% |
| 25649 |
\XINT_smalldiv_e #1!#2!1#3#4!% |
| 25650 |
}% |
| 25651 |
\def\XINT_smalldiv_end;\XINT_smalldiv_e #1!#2!1;!{1!;!#1!}% |
| 25652 |
% \end{macrocode} |
| 25653 |
%\begin{lverb} |
| 25654 |
% Il est crucial que le reste #1 est < #3. J'ai documenté cette routine |
| 25655 |
% dans le fichier où j'ai préparé 1.2, il faudra transférer ici. Il n'est pas |
| 25656 |
% nécessaire pour cette routine que le diviseur B ait au moins 8 chiffres. |
| 25657 |
% Mais il doit être < 10^8. |
| 25658 |
%\end{lverb} |
| 25659 |
% \begin{macrocode} |
| 25660 |
\def\XINT_smalldiv_e #1!#2\xint:#3!% |
| 25661 |
{% |
| 25662 |
\expandafter\XINT_smalldiv_f\the\numexpr |
| 25663 |
\xint_c_xi_e_viii_mone+#1*\xint_c_x^viii/#3!#2\xint:#3!#1!% |
| 25664 |
}% |
| 25665 |
\def\XINT_smalldiv_f 1#1#2#3#4#5#6!#7\xint:#8!% |
| 25666 |
{% |
| 25667 |
\xint_gob_til_zero #1\XINT_smalldiv_fz 0% |
| 25668 |
\expandafter\XINT_smalldiv_g |
| 25669 |
\the\numexpr\XINT_minimul_a #2#3#4#5\xint:#6!#8!#2#3#4#5#6!#7\xint:#8!% |
| 25670 |
}% |
| 25671 |
\def\XINT_smalldiv_fz 0% |
| 25672 |
\expandafter\XINT_smalldiv_g\the\numexpr\XINT_minimul_a |
| 25673 |
9999\xint:9999!#1!99999999!#2!0!1#3!% |
| 25674 |
{% |
| 25675 |
\XINT_smalldiv_i \xint:#3!\xint_c_!#2!% |
| 25676 |
}% |
| 25677 |
\def\XINT_smalldiv_g 1#1!1#2!#3!#4!#5!#6!% |
| 25678 |
{% |
| 25679 |
\expandafter\XINT_smalldiv_h\the\numexpr 1#6-#1\xint:#2!#5!#3!#4!% |
| 25680 |
}% |
| 25681 |
\def\XINT_smalldiv_h 1#1#2\xint:#3!#4!% |
| 25682 |
{% |
| 25683 |
\expandafter\XINT_smalldiv_i\the\numexpr #4-#3+#1-\xint_c_i\xint:#2!% |
| 25684 |
}% |
| 25685 |
\def\XINT_smalldiv_i #1\xint:#2!#3!#4\xint:#5!% |
| 25686 |
{% |
| 25687 |
\expandafter\XINT_smalldiv_j\the\numexpr (#1#2+#4)/#5-\xint_c_i!#3!#1#2!#4\xint:#5!% |
| 25688 |
}% |
| 25689 |
\def\XINT_smalldiv_j #1!#2!% |
| 25690 |
{% |
| 25691 |
\xint_c_x^viii+#1+#2\expandafter!\the\numexpr\XINT_smalldiv_k |
| 25692 |
#1!% |
| 25693 |
}% |
| 25694 |
% \end{macrocode} |
| 25695 |
%\begin{lverb} |
| 25696 |
% On boucle vers \XINT_smalldiv_d. |
| 25697 |
%\end{lverb} |
| 25698 |
% \begin{macrocode} |
| 25699 |
\def\XINT_smalldiv_k #1!#2!#3\xint:#4!% |
| 25700 |
{% |
| 25701 |
\expandafter\XINT_smalldiv_d\the\numexpr #2-#1*#4!#3\xint:#4!% |
| 25702 |
}% |
| 25703 |
% \end{macrocode} |
| 25704 |
%\begin{lverb} |
| 25705 |
% Cette routine fait la division euclidienne d'un nombre de seize |
| 25706 |
% chiffres par #1 = C = diviseur sur huit chiffres >= 10^7, avec #2 = sa |
| 25707 |
% moitié utilisée dans \numexpr pour contrebalancer l'arrondi |
| 25708 |
% (ARRRRRRGGGGGHHHH) fait par /. Le nombre divisé XY = X*10^8+Y se présente |
| 25709 |
% sous la forme 1<8chiffres>!1<8chiffres>! avec plus significatif en premier. |
| 25710 |
% |
| 25711 |
% Seul le quotient est calculé, pas le reste. En effet la routine de division |
| 25712 |
% principale va utiliser ce quotient pour déterminer le "grand" reste, et le |
| 25713 |
% petit reste ici ne nous serait d'à peu près aucune utilité. |
| 25714 |
% |
| 25715 |
% ATTENTION UNIQUEMENT UTILISÉ POUR DES SITUATIONS OÙ IL EST GARANTI QUE X < |
| 25716 |
% C ! (et C au moins 10^7) le quotient euclidien de X*10^8+Y par C sera donc < |
| 25717 |
% 10^8. Il sera renvoyé sous la forme 1<8chiffres>. |
| 25718 |
%\end{lverb} |
| 25719 |
% \begin{macrocode} |
| 25720 |
\def\XINT_div_mini #1\xint:#2!1#3!% |
| 25721 |
{% |
| 25722 |
\expandafter\XINT_div_mini_a\the\numexpr |
| 25723 |
\xint_c_xi_e_viii_mone+#3*\xint_c_x^viii/#1!#1\xint:#2!#3!% |
| 25724 |
}% |
| 25725 |
% \end{macrocode} |
| 25726 |
%\begin{lverb} |
| 25727 |
% Note (2015/10/08). Attention à la différence dans l'ordre des |
| 25728 |
% arguments avec ce que je vois en dans \XINT_smalldiv_f. Je ne me souviens |
| 25729 |
% plus du tout s'il y a une raison quelconque. |
| 25730 |
%\end{lverb} |
| 25731 |
% \begin{macrocode} |
| 25732 |
\def\XINT_div_mini_a 1#1#2#3#4#5#6!#7\xint:#8!% |
| 25733 |
{% |
| 25734 |
\xint_gob_til_zero #1\XINT_div_mini_w 0% |
| 25735 |
\expandafter\XINT_div_mini_b |
| 25736 |
\the\numexpr\XINT_minimul_a #2#3#4#5\xint:#6!#7!#2#3#4#5#6!#7\xint:#8!% |
| 25737 |
}% |
| 25738 |
\def\XINT_div_mini_w 0% |
| 25739 |
\expandafter\XINT_div_mini_b\the\numexpr\XINT_minimul_a |
| 25740 |
9999\xint:9999!#1!99999999!#2\xint:#3!00000000!#4!% |
| 25741 |
{% |
| 25742 |
\xint_c_x^viii_mone+(#4+#3)/#2!% |
| 25743 |
}% |
| 25744 |
\def\XINT_div_mini_b 1#1!1#2!#3!#4!#5!#6!% |
| 25745 |
{% |
| 25746 |
\expandafter\XINT_div_mini_c |
| 25747 |
\the\numexpr 1#6-#1\xint:#2!#5!#3!#4!% |
| 25748 |
}% |
| 25749 |
\def\XINT_div_mini_c 1#1#2\xint:#3!#4!% |
| 25750 |
{% |
| 25751 |
\expandafter\XINT_div_mini_d |
| 25752 |
\the\numexpr #4-#3+#1-\xint_c_i\xint:#2!% |
| 25753 |
}% |
| 25754 |
\def\XINT_div_mini_d #1\xint:#2!#3!#4\xint:#5!% |
| 25755 |
{% |
| 25756 |
\xint_c_x^viii_mone+#3+(#1#2+#5)/#4!% |
| 25757 |
}% |
| 25758 |
% \end{macrocode} |
| 25759 |
% \subsection*{Derived arithmetic} |
| 25760 |
% \addcontentsline{toc}{subsection}{Derived arithmetic} |
| 25761 |
% \subsection{\csh{xintiiQuo}, \csh{xintiiRem}} |
| 25762 |
% \begin{macrocode} |
| 25763 |
\def\xintiiQuo {\romannumeral0\xintiiquo }% |
| 25764 |
\def\xintiiRem {\romannumeral0\xintiirem }% |
| 25765 |
\def\xintiiquo |
| 25766 |
{\expandafter\xint_stop_atfirstoftwo\romannumeral0\xintiidivision }% |
| 25767 |
\def\xintiirem |
| 25768 |
{\expandafter\xint_stop_atsecondoftwo\romannumeral0\xintiidivision }% |
| 25769 |
% \end{macrocode} |
| 25770 |
% \subsection{\csh{xintiiDivRound}} |
| 25771 |
%\begin{lverb} |
| 25772 |
% 1.1, transferred from first release of bnumexpr. Rewritten for 1.2. |
| 25773 |
% Ending rewritten for 1.2i. (new \xintDSRr). |
| 25774 |
% |
| 25775 |
% 1.2l: \xintiiDivRound made robust against non terminated input. |
| 25776 |
%\end{lverb} |
| 25777 |
% \begin{macrocode} |
| 25778 |
\def\xintiiDivRound {\romannumeral0\xintiidivround }% |
| 25779 |
\def\xintiidivround #1{\expandafter\XINT_iidivround\romannumeral`&&@#1\xint:}% |
| 25780 |
\def\XINT_iidivround #1#2\xint:#3% |
| 25781 |
{\expandafter\XINT_iidivround_a\expandafter #1\romannumeral`&&@#3\xint:#2\xint:}% |
| 25782 |
\def\XINT_iidivround_a #1#2% #1 de A, #2 de B. |
| 25783 |
{% |
| 25784 |
\if0#2\xint_dothis{\XINT_iidivround_divbyzero#1#2}\fi |
| 25785 |
\if0#1\xint_dothis\XINT_iidivround_aiszero\fi |
| 25786 |
\if-#2\xint_dothis{\XINT_iidivround_bneg #1}\fi |
| 25787 |
\xint_orthat{\XINT_iidivround_bpos #1#2}% |
| 25788 |
}% |
| 25789 |
\def\XINT_iidivround_divbyzero #1#2#3\xint:#4\xint: |
| 25790 |
{\XINT_signalcondition{DivisionByZero}{Division by zero: #1#4/#2#3.}{}{ 0}}% |
| 25791 |
\def\XINT_iidivround_aiszero #1\xint:#2\xint:{ 0}% |
| 25792 |
\def\XINT_iidivround_bpos #1% |
| 25793 |
{% |
| 25794 |
\xint_UDsignfork |
| 25795 |
#1{\xintiiopp\XINT_iidivround_pos {}}% |
| 25796 |
-{\XINT_iidivround_pos #1}% |
| 25797 |
\krof |
| 25798 |
}% |
| 25799 |
\def\XINT_iidivround_bneg #1% |
| 25800 |
{% |
| 25801 |
\xint_UDsignfork |
| 25802 |
#1{\XINT_iidivround_pos {}}% |
| 25803 |
-{\xintiiopp\XINT_iidivround_pos #1}% |
| 25804 |
\krof |
| 25805 |
}% |
| 25806 |
\def\XINT_iidivround_pos #1#2\xint:#3\xint: |
| 25807 |
{% |
| 25808 |
\expandafter\expandafter\expandafter\XINT_dsrr |
| 25809 |
\expandafter\xint_firstoftwo |
| 25810 |
\romannumeral0\XINT_div_prepare {#2}{#1#30}% |
| 25811 |
\xint_bye\xint_Bye3456789\xint_bye/\xint_c_x\relax |
| 25812 |
}% |
| 25813 |
% \end{macrocode} |
| 25814 |
% \subsection{\csh{xintiiDivTrunc}} |
| 25815 |
%\begin{lverb} |
| 25816 |
% 1.2l: \xintiiDivTrunc made robust against non terminated input. |
| 25817 |
%\end{lverb} |
| 25818 |
% \begin{macrocode} |
| 25819 |
\def\xintiiDivTrunc {\romannumeral0\xintiidivtrunc }% |
| 25820 |
\def\xintiidivtrunc #1{\expandafter\XINT_iidivtrunc\romannumeral`&&@#1\xint:}% |
| 25821 |
\def\XINT_iidivtrunc #1#2\xint:#3{\expandafter\XINT_iidivtrunc_a\expandafter #1% |
| 25822 |
\romannumeral`&&@#3\xint:#2\xint:}% |
| 25823 |
\def\XINT_iidivtrunc_a #1#2% #1 de A, #2 de B. |
| 25824 |
{% |
| 25825 |
\if0#2\xint_dothis{\XINT_iidivtrunc_divbyzero#1#2}\fi |
| 25826 |
\if0#1\xint_dothis\XINT_iidivtrunc_aiszero\fi |
| 25827 |
\if-#2\xint_dothis{\XINT_iidivtrunc_bneg #1}\fi |
| 25828 |
\xint_orthat{\XINT_iidivtrunc_bpos #1#2}% |
| 25829 |
}% |
| 25830 |
% \end{macrocode} |
| 25831 |
%\begin{lverb} |
| 25832 |
% Attention to not move DivRound code beyond that point. |
| 25833 |
%\end{lverb} |
| 25834 |
% \begin{macrocode} |
| 25835 |
\let\XINT_iidivtrunc_divbyzero\XINT_iidivround_divbyzero |
| 25836 |
\let\XINT_iidivtrunc_aiszero \XINT_iidivround_aiszero |
| 25837 |
\def\XINT_iidivtrunc_bpos #1% |
| 25838 |
{% |
| 25839 |
\xint_UDsignfork |
| 25840 |
#1{\xintiiopp\XINT_iidivtrunc_pos {}}% |
| 25841 |
-{\XINT_iidivtrunc_pos #1}% |
| 25842 |
\krof |
| 25843 |
}% |
| 25844 |
\def\XINT_iidivtrunc_bneg #1% |
| 25845 |
{% |
| 25846 |
\xint_UDsignfork |
| 25847 |
#1{\XINT_iidivtrunc_pos {}}% |
| 25848 |
-{\xintiiopp\XINT_iidivtrunc_pos #1}% |
| 25849 |
\krof |
| 25850 |
}% |
| 25851 |
\def\XINT_iidivtrunc_pos #1#2\xint:#3\xint: |
| 25852 |
{\expandafter\xint_stop_atfirstoftwo |
| 25853 |
\romannumeral0\XINT_div_prepare {#2}{#1#3}}% |
| 25854 |
% \end{macrocode} |
| 25855 |
% \subsection{\csh{xintiiModTrunc}} |
| 25856 |
%\begin{lverb} |
| 25857 |
% Renamed from \xintiiMod to \xintiiModTrunc at 1.2p. |
| 25858 |
%\end{lverb} |
| 25859 |
% \begin{macrocode} |
| 25860 |
\def\xintiiModTrunc {\romannumeral0\xintiimodtrunc }% |
| 25861 |
\def\xintiimodtrunc #1{\expandafter\XINT_iimodtrunc\romannumeral`&&@#1\xint:}% |
| 25862 |
\def\XINT_iimodtrunc #1#2\xint:#3{\expandafter\XINT_iimodtrunc_a\expandafter #1% |
| 25863 |
\romannumeral`&&@#3\xint:#2\xint:}% |
| 25864 |
\def\XINT_iimodtrunc_a #1#2% #1 de A, #2 de B. |
| 25865 |
{% |
| 25866 |
\if0#2\xint_dothis{\XINT_iimodtrunc_divbyzero#1#2}\fi |
| 25867 |
\if0#1\xint_dothis\XINT_iimodtrunc_aiszero\fi |
| 25868 |
\if-#2\xint_dothis{\XINT_iimodtrunc_bneg #1}\fi |
| 25869 |
\xint_orthat{\XINT_iimodtrunc_bpos #1#2}% |
| 25870 |
}% |
| 25871 |
% \end{macrocode} |
| 25872 |
%\begin{lverb} |
| 25873 |
% Attention to not move DivRound code beyond that point. A bit of abuse |
| 25874 |
% here for divbyzero defaulted-to value, which happily works in both. |
| 25875 |
%\end{lverb} |
| 25876 |
% \begin{macrocode} |
| 25877 |
\let\XINT_iimodtrunc_divbyzero\XINT_iidivround_divbyzero |
| 25878 |
\let\XINT_iimodtrunc_aiszero \XINT_iidivround_aiszero |
| 25879 |
\def\XINT_iimodtrunc_bpos #1% |
| 25880 |
{% |
| 25881 |
\xint_UDsignfork |
| 25882 |
#1{\xintiiopp\XINT_iimodtrunc_pos {}}% |
| 25883 |
-{\XINT_iimodtrunc_pos #1}% |
| 25884 |
\krof |
| 25885 |
}% |
| 25886 |
\def\XINT_iimodtrunc_bneg #1% |
| 25887 |
{% |
| 25888 |
\xint_UDsignfork |
| 25889 |
#1{\xintiiopp\XINT_iimodtrunc_pos {}}% |
| 25890 |
-{\XINT_iimodtrunc_pos #1}% |
| 25891 |
\krof |
| 25892 |
}% |
| 25893 |
\def\XINT_iimodtrunc_pos #1#2\xint:#3\xint: |
| 25894 |
{\expandafter\xint_stop_atsecondoftwo\romannumeral0\XINT_div_prepare |
| 25895 |
{#2}{#1#3}}% |
| 25896 |
% \end{macrocode} |
| 25897 |
% \subsection{\csh{xintiiDivMod}} |
| 25898 |
% \changed{1.2p} |
| 25899 |
% It is associated with floored division (like Python divmod |
| 25900 |
% function), and with the |//| operator in \csbxint{iiexpr}. |
| 25901 |
% \begin{macrocode} |
| 25902 |
\def\xintiiDivMod {\romannumeral0\xintiidivmod }% |
| 25903 |
\def\xintiidivmod #1{\expandafter\XINT_iidivmod\romannumeral`&&@#1\xint:}% |
| 25904 |
\def\XINT_iidivmod #1#2\xint:#3{\expandafter\XINT_iidivmod_a\expandafter #1% |
| 25905 |
\romannumeral`&&@#3\xint:#2\xint:}% |
| 25906 |
\def\XINT_iidivmod_a #1#2% #1 de A, #2 de B. |
| 25907 |
{% |
| 25908 |
\if0#2\xint_dothis{\XINT_iidivmod_divbyzero#1#2}\fi |
| 25909 |
\if0#1\xint_dothis\XINT_iidivmod_aiszero\fi |
| 25910 |
\if-#2\xint_dothis{\XINT_iidivmod_bneg #1}\fi |
| 25911 |
\xint_orthat{\XINT_iidivmod_bpos #1#2}% |
| 25912 |
}% |
| 25913 |
\def\XINT_iidivmod_divbyzero #1#2\xint:#3\xint: |
| 25914 |
{% |
| 25915 |
\XINT_signalcondition{DivisionByZero}{Division by zero: #1#3/#2.}{}% |
| 25916 |
{{0}{0}}% à revoir... |
| 25917 |
}% |
| 25918 |
\def\XINT_iidivmod_aiszero #1\xint:#2\xint:{{0}{0}}% |
| 25919 |
\def\XINT_iidivmod_bneg #1% |
| 25920 |
{% |
| 25921 |
\expandafter\XINT_iidivmod_bneg_finish |
| 25922 |
\romannumeral0\xint_UDsignfork |
| 25923 |
#1{\XINT_iidivmod_bpos {}}% |
| 25924 |
-{\XINT_iidivmod_bpos {-#1}}% |
| 25925 |
\krof |
| 25926 |
}% |
| 25927 |
\def\XINT_iidivmod_bneg_finish#1#2% |
| 25928 |
{% |
| 25929 |
\expandafter\xint_exchangetwo_keepbraces\expandafter |
| 25930 |
{\romannumeral0\xintiiopp#2}{#1}% |
| 25931 |
}% |
| 25932 |
\def\XINT_iidivmod_bpos #1#2\xint:#3\xint:{\xintiidivision{#1#3}{#2}}% |
| 25933 |
% \end{macrocode} |
| 25934 |
% \subsection{\csh{xintiiDivFloor}} |
| 25935 |
%\begin{lverb} |
| 25936 |
% 1.2p. For bnumexpr actually, because \xintiiexpr could use |
| 25937 |
% \xintDivFloor which also outputs an integer in strict format. |
| 25938 |
%\end{lverb} |
| 25939 |
% \begin{macrocode} |
| 25940 |
\def\xintiiDivFloor {\romannumeral0\xintiidivfloor}% |
| 25941 |
\def\xintiidivfloor {\expandafter\xint_stop_atfirstoftwo |
| 25942 |
\romannumeral0\xintiidivmod}% |
| 25943 |
% \end{macrocode} |
| 25944 |
% \subsection{\csh{xintiiMod}} |
| 25945 |
%\begin{lverb} |
| 25946 |
% Associated with floored division at 1.2p. Formerly was associated with |
| 25947 |
% truncated division. |
| 25948 |
%\end{lverb} |
| 25949 |
% \begin{macrocode} |
| 25950 |
\def\xintiiMod {\romannumeral0\xintiimod}% |
| 25951 |
\def\xintiimod {\expandafter\xint_stop_atsecondoftwo |
| 25952 |
\romannumeral0\xintiidivmod}% |
| 25953 |
% \end{macrocode} |
| 25954 |
% \subsection{\csh{xintiiSqr}} |
| 25955 |
%\begin{lverb} |
| 25956 |
% 1.2l: \xintiiSqr made robust against non terminated input. |
| 25957 |
%\end{lverb} |
| 25958 |
% \begin{macrocode} |
| 25959 |
\def\xintiiSqr {\romannumeral0\xintiisqr }% |
| 25960 |
\def\xintiisqr #1% |
| 25961 |
{% |
| 25962 |
\expandafter\XINT_sqr\romannumeral0\xintiiabs{#1}\xint: |
| 25963 |
}% |
| 25964 |
\def\XINT_sqr #1\xint: |
| 25965 |
{% |
| 25966 |
\expandafter\XINT_sqr_a |
| 25967 |
\romannumeral0\expandafter\XINT_sepandrev_andcount |
| 25968 |
\romannumeral0\XINT_zeroes_forviii #1\R\R\R\R\R\R\R\R{10}0000001\W |
| 25969 |
#1\XINT_rsepbyviii_end_A 2345678% |
| 25970 |
\XINT_rsepbyviii_end_B 2345678\relax\xint_c_ii\xint_c_i |
| 25971 |
\R\xint:\xint_c_xii \R\xint:\xint_c_x \R\xint:\xint_c_viii \R\xint:\xint_c_vi |
| 25972 |
\R\xint:\xint_c_iv \R\xint:\xint_c_ii \R\xint:\xint_c_\W |
| 25973 |
\xint: |
| 25974 |
}% |
| 25975 |
% \end{macrocode} |
| 25976 |
%\begin{lverb} |
| 25977 |
% 1.2c \XINT_mul_loop can now be called directly even with small |
| 25978 |
% arguments, thus the following check is not anymore a necessity. |
| 25979 |
%\end{lverb} |
| 25980 |
% \begin{macrocode} |
| 25981 |
\def\XINT_sqr_a #1\xint: |
| 25982 |
{% |
| 25983 |
\ifnum #1=\xint_c_i \expandafter\XINT_sqr_small |
| 25984 |
\else\expandafter\XINT_sqr_start\fi |
| 25985 |
}% |
| 25986 |
\def\XINT_sqr_small 1#1#2#3#4#5!\xint: |
| 25987 |
{% |
| 25988 |
\ifnum #1#2#3#4#5<46341 \expandafter\XINT_sqr_verysmall\fi |
| 25989 |
\expandafter\XINT_sqr_small_out |
| 25990 |
\the\numexpr\XINT_minimul_a #1#2#3#4\xint:#5!#1#2#3#4#5!% |
| 25991 |
}% |
| 25992 |
\def\XINT_sqr_verysmall#1{% |
| 25993 |
\def\XINT_sqr_verysmall |
| 25994 |
\expandafter\XINT_sqr_small_out\the\numexpr\XINT_minimul_a ##1!##2!% |
| 25995 |
{\expandafter#1\the\numexpr ##2*##2\relax}% |
| 25996 |
}\XINT_sqr_verysmall{ }% |
| 25997 |
\def\XINT_sqr_small_out 1#1!1#2!% |
| 25998 |
{% |
| 25999 |
\XINT_cuz #2#1\R |
| 26000 |
}% |
| 26001 |
% \end{macrocode} |
| 26002 |
%\begin{lverb} |
| 26003 |
% An ending 1;! is produced on output for \XINT_mul_loop and gets |
| 26004 |
% incorporated to the delimiter needed by the \XINT_unrevbyviii done by |
| 26005 |
% \XINT_mul_out. |
| 26006 |
%\end{lverb} |
| 26007 |
% \begin{macrocode} |
| 26008 |
\def\XINT_sqr_start #1\xint: |
| 26009 |
{% |
| 26010 |
\expandafter\XINT_mul_out |
| 26011 |
\the\numexpr\XINT_mul_loop |
| 26012 |
100000000!1;!\W #11;!\W #11;!% |
| 26013 |
1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W |
| 26014 |
}% |
| 26015 |
% \end{macrocode} |
| 26016 |
% \subsection{\csh{xintiiPow}} |
| 26017 |
%\begin{lverb} |
| 26018 |
% 1.2f Modifies the initial steps: 1) in order to be able to let more easily |
| 26019 |
% \xintiPow use \xintNum on the exponent once xintfrac.sty is loaded; 2) also |
| 26020 |
% because I noticed it was not very well coded. And it did only a \numexpr on |
| 26021 |
% the exponent, contradicting the documentation related to the "i" convention |
| 26022 |
% in names. |
| 26023 |
% |
| 26024 |
% 1.2l: \xintiiPow made robust against non terminated input. |
| 26025 |
% |
| 26026 |
% The macro makes no a priori test on whether computation has a chance to |
| 26027 |
% complete succesfully, as this depends on TeX memory parameters. But roughly, |
| 26028 |
% the size of the output should be less than the maximal size for addition, |
| 26029 |
% i.e. with TeXLive 2025 settings, have less than about 26600 decimal digits. |
| 26030 |
%\end{lverb} |
| 26031 |
% \begin{macrocode} |
| 26032 |
\def\xintiiPow {\romannumeral0\xintiipow }% |
| 26033 |
\def\xintiipow #1#2% |
| 26034 |
{% |
| 26035 |
\expandafter\xint_pow\the\numexpr #2\expandafter |
| 26036 |
.\romannumeral`&&@#1\xint: |
| 26037 |
}% |
| 26038 |
\def\xint_pow #1.#2%#3\xint: |
| 26039 |
{% |
| 26040 |
\xint_UDzerominusfork |
| 26041 |
#2-\XINT_pow_AisZero |
| 26042 |
0#2\XINT_pow_Aneg |
| 26043 |
0-{\XINT_pow_Apos #2}% |
| 26044 |
\krof {#1}% |
| 26045 |
}% |
| 26046 |
\def\XINT_pow_AisZero #1#2\xint: |
| 26047 |
{% |
| 26048 |
\ifcase\XINT_cntSgn #1\xint: |
| 26049 |
\xint_afterfi { 1}% |
| 26050 |
\or |
| 26051 |
\xint_afterfi { 0}% |
| 26052 |
\else |
| 26053 |
\xint_afterfi |
| 26054 |
{\XINT_signalcondition{DivisionByZero}{0 raised to power #1.}{}{ 0}}% |
| 26055 |
\fi |
| 26056 |
}% |
| 26057 |
\def\XINT_pow_Aneg #1% |
| 26058 |
{% |
| 26059 |
\ifodd #1 |
| 26060 |
\expandafter\XINT_opp\romannumeral0% |
| 26061 |
\fi |
| 26062 |
\XINT_pow_Apos {}{#1}% |
| 26063 |
}% |
| 26064 |
\def\XINT_pow_Apos #1#2{\XINT_pow_Apos_a {#2}#1}% |
| 26065 |
\def\XINT_pow_Apos_a #1#2#3% |
| 26066 |
{% |
| 26067 |
\xint_gob_til_xint: #3\XINT_pow_Apos_short\xint: |
| 26068 |
\XINT_pow_AatleastTwo {#1}#2#3% |
| 26069 |
}% |
| 26070 |
\def\XINT_pow_Apos_short\xint:\XINT_pow_AatleastTwo #1#2\xint: |
| 26071 |
{% |
| 26072 |
\ifcase #2 |
| 26073 |
\xintError:thiscannothappen |
| 26074 |
\or \expandafter\XINT_pow_AisOne |
| 26075 |
\else\expandafter\XINT_pow_AatleastTwo |
| 26076 |
\fi {#1}#2\xint: |
| 26077 |
}% |
| 26078 |
\def\XINT_pow_AisOne #1\xint:{ 1}% |
| 26079 |
\def\XINT_pow_AatleastTwo #1% |
| 26080 |
{% |
| 26081 |
\ifcase\XINT_cntSgn #1\xint: |
| 26082 |
\expandafter\XINT_pow_BisZero |
| 26083 |
\or |
| 26084 |
\expandafter\XINT_pow_I_in |
| 26085 |
\else |
| 26086 |
\expandafter\XINT_pow_BisNegative |
| 26087 |
\fi |
| 26088 |
{#1}% |
| 26089 |
}% |
| 26090 |
\def\XINT_pow_BisNegative #1\xint:{\XINT_signalcondition{Underflow}% |
| 26091 |
{Inverse power is not an integer.}{}{ 0}}% |
| 26092 |
\def\XINT_pow_BisZero #1\xint:{ 1}% |
| 26093 |
% \end{macrocode} |
| 26094 |
%\begin{lverb} |
| 26095 |
% B = #1 > 0, A = #2 > 1. Earlier code checked if size of B did not |
| 26096 |
% exceed a given limit (for example 131000). |
| 26097 |
%\end{lverb} |
| 26098 |
% \begin{macrocode} |
| 26099 |
\def\XINT_pow_I_in #1#2\xint: |
| 26100 |
{% |
| 26101 |
\expandafter\XINT_pow_I_loop |
| 26102 |
\the\numexpr #1\expandafter\xint:% |
| 26103 |
\romannumeral0\expandafter\XINT_sepandrev |
| 26104 |
\romannumeral0\XINT_zeroes_forviii #2\R\R\R\R\R\R\R\R{10}0000001\W |
| 26105 |
#2\XINT_rsepbyviii_end_A 2345678% |
| 26106 |
\XINT_rsepbyviii_end_B 2345678\relax XX% |
| 26107 |
\R\xint:\R\xint:\R\xint:\R\xint:\R\xint:\R\xint:\R\xint:\R\xint:\W |
| 26108 |
1;!\W |
| 26109 |
1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W |
| 26110 |
}% |
| 26111 |
\def\XINT_pow_I_loop #1\xint:% |
| 26112 |
{% |
| 26113 |
\ifnum #1 = \xint_c_i\expandafter\XINT_pow_I_exit\fi |
| 26114 |
\ifodd #1 |
| 26115 |
\expandafter\XINT_pow_II_in |
| 26116 |
\else |
| 26117 |
\expandafter\XINT_pow_I_squareit |
| 26118 |
\fi #1\xint:% |
| 26119 |
}% |
| 26120 |
\def\XINT_pow_I_exit \ifodd #1\fi #2\xint:#3\W {\XINT_mul_out #3}% |
| 26121 |
% \end{macrocode} |
| 26122 |
%\begin{lverb} |
| 26123 |
% The 1.2c \XINT_mul_loop can be called directly even with small |
| 26124 |
% arguments, hence the "butcheckifsmall" is not a necessity as it was earlier |
| 26125 |
% with 1.2. On 2^30, it does bring roughly a 40$char37 $space time gain |
| 26126 |
% though, and 30$char37 $space gain for 2^60. The overhead on big computations |
| 26127 |
% should be negligible. |
| 26128 |
%\end{lverb} |
| 26129 |
% \begin{macrocode} |
| 26130 |
\def\XINT_pow_I_squareit #1\xint:#2\W% |
| 26131 |
{% |
| 26132 |
\expandafter\XINT_pow_I_loop |
| 26133 |
\the\numexpr #1/\xint_c_ii\expandafter\xint:% |
| 26134 |
\the\numexpr\XINT_pow_mulbutcheckifsmall #2\W #2\W |
| 26135 |
}% |
| 26136 |
\def\XINT_pow_mulbutcheckifsmall #1!1#2% |
| 26137 |
{% |
| 26138 |
\xint_gob_til_sc #2\XINT_pow_mul_small;% |
| 26139 |
\XINT_mul_loop 100000000!1;!\W #1!1#2% |
| 26140 |
}% |
| 26141 |
\def\XINT_pow_mul_small;\XINT_mul_loop |
| 26142 |
100000000!1;!\W 1#1!1;!\W |
| 26143 |
{% |
| 26144 |
\XINT_smallmul 1#1!% |
| 26145 |
}% |
| 26146 |
\def\XINT_pow_II_in #1\xint:#2\W |
| 26147 |
{% |
| 26148 |
\expandafter\XINT_pow_II_loop |
| 26149 |
\the\numexpr #1/\xint_c_ii-\xint_c_i\expandafter\xint:% |
| 26150 |
\the\numexpr\XINT_pow_mulbutcheckifsmall #2\W #2\W #2\W |
| 26151 |
}% |
| 26152 |
\def\XINT_pow_II_loop #1\xint:% |
| 26153 |
{% |
| 26154 |
\ifnum #1 = \xint_c_i\expandafter\XINT_pow_II_exit\fi |
| 26155 |
\ifodd #1 |
| 26156 |
\expandafter\XINT_pow_II_odda |
| 26157 |
\else |
| 26158 |
\expandafter\XINT_pow_II_even |
| 26159 |
\fi #1\xint:% |
| 26160 |
}% |
| 26161 |
\def\XINT_pow_II_exit\ifodd #1\fi #2\xint:#3\W #4\W |
| 26162 |
{% |
| 26163 |
\expandafter\XINT_mul_out |
| 26164 |
\the\numexpr\XINT_pow_mulbutcheckifsmall #4\W #3% |
| 26165 |
}% |
| 26166 |
\def\XINT_pow_II_even #1\xint:#2\W |
| 26167 |
{% |
| 26168 |
\expandafter\XINT_pow_II_loop |
| 26169 |
\the\numexpr #1/\xint_c_ii\expandafter\xint:% |
| 26170 |
\the\numexpr\XINT_pow_mulbutcheckifsmall #2\W #2\W |
| 26171 |
}% |
| 26172 |
\def\XINT_pow_II_odda #1\xint:#2\W #3\W |
| 26173 |
{% |
| 26174 |
\expandafter\XINT_pow_II_oddb |
| 26175 |
\the\numexpr #1/\xint_c_ii-\xint_c_i\expandafter\xint:% |
| 26176 |
\the\numexpr\XINT_pow_mulbutcheckifsmall #3\W #2\W #2\W |
| 26177 |
}% |
| 26178 |
\def\XINT_pow_II_oddb #1\xint:#2\W #3\W |
| 26179 |
{% |
| 26180 |
\expandafter\XINT_pow_II_loop |
| 26181 |
\the\numexpr #1\expandafter\xint:% |
| 26182 |
\the\numexpr\XINT_pow_mulbutcheckifsmall #3\W #3\W #2\W |
| 26183 |
}% |
| 26184 |
% \end{macrocode} |
| 26185 |
% \subsection{\csh{xintiiFac}} |
| 26186 |
%\begin{lverb} |
| 26187 |
% Moved here from xint.sty with release 1.2 (to be usable by \bnumexpr). |
| 26188 |
% |
| 26189 |
% Partially rewritten with release 1.2 to benefit from the inner format of the |
| 26190 |
% 1.2 multiplication. |
| 26191 |
% |
| 26192 |
% With current default settings of the etex memory and a.t.t.o.w (11/2015) the |
| 26193 |
% maximal possible computation is 5971! (which has 19956 digits). |
| 26194 |
% |
| 26195 |
% |
| 26196 |
% |
| 26197 |
% Note (end november 2015): I also tried out a quickly written recursive |
| 26198 |
% (binary split) implementation |
| 26199 |
% |
| 26200 |
%( \catcode`_ 11 |
| 26201 |
%: \catcode`^ 11 |
| 26202 |
%: \long\def\xint_firstofthree #1#2#3{#1}$% |
| 26203 |
%: \long\def\xint_secondofthree #1#2#3{#2}$% |
| 26204 |
%: \long\def\xint_thirdofthree #1#2#3{#3}$% |
| 26205 |
%: $% quickly written factorial using binary split recursive method |
| 26206 |
%: \def\tFac {\romannumeral-`0\tfac }$% |
| 26207 |
%: \def\tfac #1{\expandafter\XINT_mul_out |
| 26208 |
%: \romannumeral-`0\ufac {1}{#1}1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W}$% |
| 26209 |
%: \def\ufac #1#2{\ifcase\numexpr#2-#1\relax |
| 26210 |
%: \expandafter\xint_firstofthree |
| 26211 |
%: \or |
| 26212 |
%: \expandafter\xint_secondofthree |
| 26213 |
%: \else |
| 26214 |
%: \expandafter\xint_thirdofthree |
| 26215 |
%: \fi |
| 26216 |
%: {\the\numexpr\xint_c_x^viii+#1!1;!}$% |
| 26217 |
%: {\the\numexpr\xint_c_x^viii+#1*#2!1;!}$% |
| 26218 |
%: {\expandafter\vfac\the\numexpr (#1+#2)/\xint_c_ii.#1.#2.}$% |
| 26219 |
%: }$% |
| 26220 |
%: \def\vfac #1.#2.#3.$% |
| 26221 |
%: {$% |
| 26222 |
%: \expandafter |
| 26223 |
%: \wfac\expandafter |
| 26224 |
%: {\romannumeral-`0\expandafter |
| 26225 |
%: \ufac\expandafter{\the\numexpr #1+\xint_c_i}{#3}}$% |
| 26226 |
%: {\ufac {#2}{#1}}$% |
| 26227 |
%: }$% |
| 26228 |
%: \def\wfac #1#2{\expandafter\zfac\romannumeral-`0#2\W #1}$% |
| 26229 |
%: \def\zfac {\the\numexpr\XINT_mul_loop 100000000!1;!\W }$% core multiplication... |
| 26230 |
%: \catcode`_ 8 |
| 26231 |
%: \catcode`^ 7 |
| 26232 |
%) |
| 26233 |
% and I was quite surprised that it was only about 1.6x--2x slower in the range |
| 26234 |
% N=200 to 2000 than the \xintiiFac here which attempts to be smarter... |
| 26235 |
% |
| 26236 |
% Note (2017, 1.2l): I found out some code comment of mine that the code here |
| 26237 |
% should be more in the style of \xintiiBinomial, but I left matters |
| 26238 |
% untouched. |
| 26239 |
% |
| 26240 |
%\end{lverb} |
| 26241 |
% \begin{macrocode} |
| 26242 |
\def\xintiiFac {\romannumeral0\xintiifac }% |
| 26243 |
\def\xintiifac #1{\expandafter\XINT_fac_fork\the\numexpr#1.}% |
| 26244 |
\def\XINT_fac_fork #1#2.% |
| 26245 |
{% |
| 26246 |
\xint_UDzerominusfork |
| 26247 |
#1-\XINT_fac_zero |
| 26248 |
0#1\XINT_fac_neg |
| 26249 |
0-\XINT_fac_checksize |
| 26250 |
\krof #1#2.% |
| 26251 |
}% |
| 26252 |
\def\XINT_fac_zero #1.{ 1}% |
| 26253 |
\def\XINT_fac_neg #1.{\XINT_signalcondition{InvalidOperation}{Factorial of |
| 26254 |
negative argument: #1.}{}{ 0}}% |
| 26255 |
\def\XINT_fac_checksize #1.% |
| 26256 |
{% |
| 26257 |
\ifnum #1>\xint_c_x^iv \xint_dothis{\XINT_fac_toobig #1.}\fi |
| 26258 |
\ifnum #1>465 \xint_dothis{\XINT_fac_bigloop_a #1.}\fi |
| 26259 |
\ifnum #1>101 \xint_dothis{\XINT_fac_medloop_a #1.\XINT_mul_out}\fi |
| 26260 |
\xint_orthat{\XINT_fac_smallloop_a #1.\XINT_mul_out}% |
| 26261 |
1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W |
| 26262 |
}% |
| 26263 |
\def\XINT_fac_toobig |
| 26264 |
#1.#2\W{\XINT_signalcondition{InvalidOperation}{Factorial |
| 26265 |
argument is too large: #1 > 10^4.}{}{ 0}}% |
| 26266 |
\def\XINT_fac_bigloop_a #1.% |
| 26267 |
{% |
| 26268 |
\expandafter\XINT_fac_bigloop_b \the\numexpr |
| 26269 |
#1+\xint_c_i-\xint_c_ii*((#1-464)/\xint_c_ii).#1.% |
| 26270 |
}% |
| 26271 |
\def\XINT_fac_bigloop_b #1.#2.% |
| 26272 |
{% |
| 26273 |
\expandafter\XINT_fac_medloop_a |
| 26274 |
\the\numexpr #1-\xint_c_i.{\XINT_fac_bigloop_loop #1.#2.}% |
| 26275 |
}% |
| 26276 |
\def\XINT_fac_bigloop_loop #1.#2.% |
| 26277 |
{% |
| 26278 |
\ifnum #1>#2 \expandafter\XINT_fac_bigloop_exit\fi |
| 26279 |
\expandafter\XINT_fac_bigloop_loop |
| 26280 |
\the\numexpr #1+\xint_c_ii\expandafter.% |
| 26281 |
\the\numexpr #2\expandafter.\the\numexpr\XINT_fac_bigloop_mul #1!% |
| 26282 |
}% |
| 26283 |
\def\XINT_fac_bigloop_exit #1!{\XINT_mul_out}% |
| 26284 |
\def\XINT_fac_bigloop_mul #1!% |
| 26285 |
{% |
| 26286 |
\expandafter\XINT_smallmul |
| 26287 |
\the\numexpr \xint_c_x^viii+#1*(#1+\xint_c_i)!% |
| 26288 |
}% |
| 26289 |
\def\XINT_fac_medloop_a #1.% |
| 26290 |
{% |
| 26291 |
\expandafter\XINT_fac_medloop_b |
| 26292 |
\the\numexpr #1+\xint_c_i-\xint_c_iii*((#1-100)/\xint_c_iii).#1.% |
| 26293 |
}% |
| 26294 |
\def\XINT_fac_medloop_b #1.#2.% |
| 26295 |
{% |
| 26296 |
\expandafter\XINT_fac_smallloop_a |
| 26297 |
\the\numexpr #1-\xint_c_i.{\XINT_fac_medloop_loop #1.#2.}% |
| 26298 |
}% |
| 26299 |
\def\XINT_fac_medloop_loop #1.#2.% |
| 26300 |
{% |
| 26301 |
\ifnum #1>#2 \expandafter\XINT_fac_loop_exit\fi |
| 26302 |
\expandafter\XINT_fac_medloop_loop |
| 26303 |
\the\numexpr #1+\xint_c_iii\expandafter.% |
| 26304 |
\the\numexpr #2\expandafter.\the\numexpr\XINT_fac_medloop_mul #1!% |
| 26305 |
}% |
| 26306 |
\def\XINT_fac_medloop_mul #1!% |
| 26307 |
{% |
| 26308 |
\expandafter\XINT_smallmul |
| 26309 |
\the\numexpr |
| 26310 |
\xint_c_x^viii+#1*(#1+\xint_c_i)*(#1+\xint_c_ii)!% |
| 26311 |
}% |
| 26312 |
\def\XINT_fac_smallloop_a #1.% |
| 26313 |
{% |
| 26314 |
\csname |
| 26315 |
XINT_fac_smallloop_\the\numexpr #1-\xint_c_iv*(#1/\xint_c_iv)\relax |
| 26316 |
\endcsname #1.% |
| 26317 |
}% |
| 26318 |
\expandafter\def\csname XINT_fac_smallloop_1\endcsname #1.% |
| 26319 |
{% |
| 26320 |
\XINT_fac_smallloop_loop 2.#1.100000001!1;!% |
| 26321 |
}% |
| 26322 |
\expandafter\def\csname XINT_fac_smallloop_-2\endcsname #1.% |
| 26323 |
{% |
| 26324 |
\XINT_fac_smallloop_loop 3.#1.100000002!1;!% |
| 26325 |
}% |
| 26326 |
\expandafter\def\csname XINT_fac_smallloop_-1\endcsname #1.% |
| 26327 |
{% |
| 26328 |
\XINT_fac_smallloop_loop 4.#1.100000006!1;!% |
| 26329 |
}% |
| 26330 |
\expandafter\def\csname XINT_fac_smallloop_0\endcsname #1.% |
| 26331 |
{% |
| 26332 |
\XINT_fac_smallloop_loop 5.#1.1000000024!1;!% |
| 26333 |
}% |
| 26334 |
\def\XINT_fac_smallloop_loop #1.#2.% |
| 26335 |
{% |
| 26336 |
\ifnum #1>#2 \expandafter\XINT_fac_loop_exit\fi |
| 26337 |
\expandafter\XINT_fac_smallloop_loop |
| 26338 |
\the\numexpr #1+\xint_c_iv\expandafter.% |
| 26339 |
\the\numexpr #2\expandafter.\the\numexpr\XINT_fac_smallloop_mul #1!% |
| 26340 |
}% |
| 26341 |
\def\XINT_fac_smallloop_mul #1!% |
| 26342 |
{% |
| 26343 |
\expandafter\XINT_smallmul |
| 26344 |
\the\numexpr |
| 26345 |
\xint_c_x^viii+#1*(#1+\xint_c_i)*(#1+\xint_c_ii)*(#1+\xint_c_iii)!% |
| 26346 |
}% |
| 26347 |
\def\XINT_fac_loop_exit #1!#2;!#3{#3#2;!}% |
| 26348 |
% \end{macrocode} |
| 26349 |
% \subsection{\csh{XINT_useiimessage}} |
| 26350 |
%\begin{lverb} |
| 26351 |
% 1.2o |
| 26352 |
%\end{lverb} |
| 26353 |
% \begin{macrocode} |
| 26354 |
\def\XINT_useiimessage #1% used in LaTeX only |
| 26355 |
{% |
| 26356 |
\XINT_ifFlagRaised {#1}% |
| 26357 |
{\@backslashchar#1 |
| 26358 |
(load xintfrac or use \@backslashchar xintii\xint_gobble_iv#1!)\MessageBreak}% |
| 26359 |
{}% |
| 26360 |
}% |
| 26361 |
\XINTrestorecatcodesendinput% |
| 26362 |
% \end{macrocode} |
| 26363 |
% \StoreCodelineNo {xintcore} |
| 26364 |
% \cleardoublepage\let\xintcorenameUp\undefined |
| 26365 |
%\gardesactifs |
| 26366 |
%\let</xintcore>\relax |
| 26367 |
%\let<*xint>\gardesinactifs |
| 26368 |
%</xintcore>^^A--------------------------------------------------- |
| 26369 |
%<*xint>^^A------------------------------------------------------- |
| 26370 |
%^^A -*- coding: utf-8; mode: doctex; fill-column: 78; sentence-end-double-space: t; eval: (auto-fill-mode -1); fill-paragraph-function: nil; -*- |
| 26371 |
% \clearpage\csname xintnameUp\endcsname |
| 26372 |
% \let\MakePrivateLetters\xintMakePrivateLetters |
| 26373 |
% \section{Package \xintnameimp implementation} |
| 26374 |
% \RaisedLabel{sec:xintimp} |
| 26375 |
% |
| 26376 |
% \localtableofcontents |
| 26377 |
% |
| 26378 |
% With release |1.1| the core arithmetic routines |\xintiiAdd|, |
| 26379 |
% |\xintiiSub|, |\xintiiMul|, |\xintiiQuo|, |\xintiiPow| were separated to be |
| 26380 |
% the main component of the then new |
| 26381 |
% \xintcorenameimp. |
| 26382 |
% |
| 26383 |
% |1.3b| adds randomness related macros. |
| 26384 |
% \begin{macrocode} |
| 26385 |
\begingroup\catcode61\catcode48\catcode32=10\relax% |
| 26386 |
\catcode13=5 % ^^M |
| 26387 |
\endlinechar=13 % |
| 26388 |
\catcode123=1 % { |
| 26389 |
\catcode125=2 % } |
| 26390 |
\catcode64=11 % @ |
| 26391 |
\catcode44=12 % , |
| 26392 |
\catcode46=12 % . |
| 26393 |
\catcode58=12 % : |
| 26394 |
\catcode94=7 % ^ |
| 26395 |
\def\empty{}\def\space{ }\newlinechar10 |
| 26396 |
\def\z{\endgroup}% |
| 26397 |
\expandafter\let\expandafter\x\csname [email protected]\endcsname |
| 26398 |
\expandafter\let\expandafter\w\csname [email protected]\endcsname |
| 26399 |
\expandafter\ifx\csname numexpr\endcsname\relax |
| 26400 |
\expandafter\ifx\csname PackageWarningNoLine\endcsname\relax |
| 26401 |
\immediate\write128{^^JPackage xint Warning:^^J% |
| 26402 |
\space\space\space\space |
| 26403 |
\numexpr not available, aborting input.^^J}% |
| 26404 |
\else |
| 26405 |
\PackageWarningNoLine{xint}{\numexpr not available, aborting input}% |
| 26406 |
\fi |
| 26407 |
\def\z{\endgroup\endinput}% |
| 26408 |
\else |
| 26409 |
\ifx\x\relax % plain-TeX, first loading of xintcore.sty |
| 26410 |
\ifx\w\relax % but xintkernel.sty not yet loaded. |
| 26411 |
\def\z{\endgroup\input xintcore.sty\relax}% |
| 26412 |
\fi |
| 26413 |
\else |
| 26414 |
\ifx\x\empty % LaTeX, first loading, |
| 26415 |
% variable is initialized, but \ProvidesPackage not yet seen |
| 26416 |
\ifx\w\relax % xintcore.sty not yet loaded. |
| 26417 |
\def\z{\endgroup\RequirePackage{xintcore}}% |
| 26418 |
\fi |
| 26419 |
\else |
| 26420 |
\def\z{\endgroup\endinput}% xint already loaded. |
| 26421 |
\fi |
| 26422 |
\fi |
| 26423 |
\fi |
| 26424 |
\z% |
| 26425 |
\XINTsetupcatcodes% defined in xintkernel.sty (loaded by xintcore.sty) |
| 26426 |
% \end{macrocode} |
| 26427 |
% \subsection{Package identification} |
| 26428 |
% \begin{macrocode} |
| 26429 |
\XINT_providespackage |
| 26430 |
\ProvidesPackage{xint}% |
| 26431 |
[2025/09/06 v1.4o Expandable operations on big integers (JFB)]% |
| 26432 |
% \end{macrocode} |
| 26433 |
% \subsection{\csh{xintLen}, \csh{xintiLen}} |
| 26434 |
%\begin{lverb} |
| 26435 |
% \xintLen gets extended to fractions by xintfrac.sty: A/B is given |
| 26436 |
% length len(A)+len(B)-1 (somewhat arbitrary). It applies \xintNum to its |
| 26437 |
% argument. A minus sign is accepted and ignored. |
| 26438 |
% |
| 26439 |
% |
| 26440 |
% For parallelism with \xintiNum/\xintNum, 1.2o defines \xintiLen. |
| 26441 |
% |
| 26442 |
% \xintLen gets redefined by $xintfracnameimp. |
| 26443 |
%\end{lverb} |
| 26444 |
% \begin{macrocode} |
| 26445 |
\def\xintiLen {\romannumeral0\xintilen }% |
| 26446 |
\def\xintilen #1{\def\xintilen ##1% |
| 26447 |
{% |
| 26448 |
\expandafter#1\the\numexpr |
| 26449 |
\expandafter\XINT_len_fork\romannumeral0\xintinum{##1}% |
| 26450 |
\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint: |
| 26451 |
\xint_c_viii\xint_c_vii\xint_c_vi\xint_c_v |
| 26452 |
\xint_c_iv\xint_c_iii\xint_c_ii\xint_c_i\xint_c_\xint_bye\relax |
| 26453 |
}}\xintilen{ }% |
| 26454 |
\def\xintLen {\romannumeral0\xintlen }% |
| 26455 |
\let\xintlen\xintilen |
| 26456 |
\def\XINT_len_fork #1% |
| 26457 |
{% |
| 26458 |
\expandafter\XINT_length_loop\xint_UDsignfork#1{}-#1\krof |
| 26459 |
}% |
| 26460 |
% \end{macrocode} |
| 26461 |
% \subsection{\csh{xintiiLogTen}} |
| 26462 |
%\begin{lverb} |
| 26463 |
% 1.3e. Support for ilog10() function in \xintiiexpr. See \XINTiLogTen |
| 26464 |
% in xintfrac.sty which also currently uses -"7FFF8000 as value if input is |
| 26465 |
% zero. |
| 26466 |
%\end{lverb} |
| 26467 |
% \begin{macrocode} |
| 26468 |
\def\xintiiLogTen {\the\numexpr\xintiilogten }% |
| 26469 |
\def\xintiilogten #1% |
| 26470 |
{% |
| 26471 |
\expandafter\XINT_iilogten\romannumeral`&&@#1% |
| 26472 |
\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint: |
| 26473 |
\xint_c_viii\xint_c_vii\xint_c_vi\xint_c_v |
| 26474 |
\xint_c_iv\xint_c_iii\xint_c_ii\xint_c_i\xint_c_\xint_bye |
| 26475 |
\relax |
| 26476 |
}% |
| 26477 |
\def\XINT_iilogten #1{\if#10-"7FFF8000\fi -1+% |
| 26478 |
\expandafter\XINT_length_loop\xint_UDsignfork#1{}-#1\krof}% |
| 26479 |
% \end{macrocode} |
| 26480 |
% \subsection{\csh{xintReverseDigits}} |
| 26481 |
%\begin{lverb} |
| 26482 |
% 1.2. |
| 26483 |
% |
| 26484 |
% This puts digits in reverse order, not suppressing leading zeros |
| 26485 |
% after reverse. Despite lacking the "ii" in its name, it does not apply |
| 26486 |
% \xintNum to its argument (contrarily to \xintLen, this is not very coherent). |
| 26487 |
% |
| 26488 |
% 1.2l variant is robust against non terminated \the\numexpr input. |
| 26489 |
% |
| 26490 |
% This macro is currently not used elsewhere in xint code. |
| 26491 |
%\end{lverb} |
| 26492 |
% \begin{macrocode} |
| 26493 |
\def\xintReverseDigits {\romannumeral0\xintreversedigits }% |
| 26494 |
\def\xintreversedigits #1% |
| 26495 |
{% |
| 26496 |
\expandafter\XINT_revdigits\romannumeral`&&@#1% |
| 26497 |
{\XINT_microrevsep_end\W}\XINT_microrevsep_end |
| 26498 |
\XINT_microrevsep_end\XINT_microrevsep_end |
| 26499 |
\XINT_microrevsep_end\XINT_microrevsep_end |
| 26500 |
\XINT_microrevsep_end\XINT_microrevsep_end\XINT_microrevsep_end\Z |
| 26501 |
1\Z!1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W |
| 26502 |
}% |
| 26503 |
\def\XINT_revdigits #1% |
| 26504 |
{% |
| 26505 |
\xint_UDsignfork |
| 26506 |
#1{\expandafter-\romannumeral0\XINT_revdigits_a}% |
| 26507 |
-{\XINT_revdigits_a #1}% |
| 26508 |
\krof |
| 26509 |
}% |
| 26510 |
\def\XINT_revdigits_a |
| 26511 |
{% |
| 26512 |
\expandafter\XINT_revdigits_b\expandafter{\expandafter}% |
| 26513 |
\the\numexpr\XINT_microrevsep |
| 26514 |
}% |
| 26515 |
\def\XINT_microrevsep #1#2#3#4#5#6#7#8#9% |
| 26516 |
{% |
| 26517 |
1#9#8#7#6#5#4#3#2#1\expandafter!\the\numexpr\XINT_microrevsep |
| 26518 |
}% |
| 26519 |
\def\XINT_microrevsep_end #1\W #2\expandafter #3\Z{\relax#2!}% |
| 26520 |
\def\XINT_revdigits_b #11#2!1#3!1#4!1#5!1#6!1#7!1#8!1#9!% |
| 26521 |
{% |
| 26522 |
\xint_gob_til_R #9\XINT_revdigits_end\R |
| 26523 |
\XINT_revdigits_b {#9#8#7#6#5#4#3#2#1}% |
| 26524 |
}% |
| 26525 |
\def\XINT_revdigits_end#1{% |
| 26526 |
\def\XINT_revdigits_end\R\XINT_revdigits_b ##1##2\W |
| 26527 |
{\expandafter#1\xint_gob_til_Z ##1}% |
| 26528 |
}\XINT_revdigits_end{ }% |
| 26529 |
\let\xintRev\xintReverseDigits |
| 26530 |
% \end{macrocode} |
| 26531 |
% \subsection{\csh{xintiiE}} |
| 26532 |
%\begin{lverb} |
| 26533 |
% Originally was used in \xintiiexpr. Transferred from xintfrac for |
| 26534 |
% 1.1. |
| 26535 |
% Code rewritten for 1.2i. |
| 26536 |
% \xintiiE{x}{e} extends x with e zeroes if e is positive and simply outputs |
| 26537 |
% x if e is zero or negative. Attention, le comportement pour e < 0 ne doit |
| 26538 |
% pas être modifié car \xintMod et autres macros en dépendent. |
| 26539 |
%\end{lverb} |
| 26540 |
% \begin{macrocode} |
| 26541 |
\def\xintiiE {\romannumeral0\xintiie }% |
| 26542 |
\def\xintiie #1#2% |
| 26543 |
{\expandafter\XINT_iie_fork\the\numexpr #2\expandafter.\romannumeral`&&@#1;}% |
| 26544 |
\def\XINT_iie_fork #1% |
| 26545 |
{% |
| 26546 |
\xint_UDsignfork |
| 26547 |
#1\XINT_iie_neg |
| 26548 |
-\XINT_iie_a |
| 26549 |
\krof #1% |
| 26550 |
}% |
| 26551 |
% \end{macrocode} |
| 26552 |
%\begin{lverb} |
| 26553 |
% le #2 a le bon pattern terminé par ; #1=0 est OK pour \XINT_rep. |
| 26554 |
%\end{lverb} |
| 26555 |
% \begin{macrocode} |
| 26556 |
\def\XINT_iie_a #1.% |
| 26557 |
{\expandafter\XINT_dsx_append\romannumeral\XINT_rep #1\endcsname 0.}% |
| 26558 |
\def\XINT_iie_neg #1.#2;{ #2}% |
| 26559 |
% \end{macrocode} |
| 26560 |
% \subsection{\csh{xintDecSplit}} |
| 26561 |
%\begin{lverb} |
| 26562 |
% DECIMAL SPLIT |
| 26563 |
% |
| 26564 |
% The macro \xintDecSplit {x}{A} cuts A which is composed of digits (leading |
| 26565 |
% zeroes ok, but no sign) (*) into two (each possibly empty) pieces L and R. |
| 26566 |
% The concatenation LR always reproduces A. |
| 26567 |
% |
| 26568 |
% The position of the cut is specified by the first argument x. If x is zero |
| 26569 |
% or positive the cut location is x slots to the left of the right end of the |
| 26570 |
% number. If x becomes equal to or larger than the length of the number then L |
| 26571 |
% becomes empty. If x is negative the location of the cut is |x| slots to the |
| 26572 |
% right of the left end of the number. |
| 26573 |
% |
| 26574 |
% (*) versions earlier than 1.2i first replaced A with its absolute value. |
| 26575 |
% This is not the case anymore. This macro should NOT be used for A with a |
| 26576 |
% leading sign (+ or -). |
| 26577 |
% |
| 26578 |
% Entirely rewritten for 1.2i (2016/12/11). |
| 26579 |
% |
| 26580 |
% Attention: \xintDecSplit not robust against non terminated second argument. |
| 26581 |
%\end{lverb} |
| 26582 |
% \begin{macrocode} |
| 26583 |
\def\xintDecSplit {\romannumeral0\xintdecsplit }% |
| 26584 |
\def\xintdecsplit #1#2% |
| 26585 |
{% |
| 26586 |
\expandafter\XINT_split_finish |
| 26587 |
\romannumeral0\expandafter\XINT_split_xfork |
| 26588 |
\the\numexpr #1\expandafter.\romannumeral`&&@#2% |
| 26589 |
\xint_bye2345678\xint_bye..% |
| 26590 |
}% |
| 26591 |
\def\XINT_split_finish #1.#2.{{#1}{#2}}% |
| 26592 |
\def\XINT_split_xfork #1% |
| 26593 |
{% |
| 26594 |
\xint_UDzerominusfork |
| 26595 |
#1-\XINT_split_zerosplit |
| 26596 |
0#1\XINT_split_fromleft |
| 26597 |
0-{\XINT_split_fromright #1}% |
| 26598 |
\krof |
| 26599 |
}% |
| 26600 |
\def\XINT_split_zerosplit .#1\xint_bye#2\xint_bye..{ #1..}% |
| 26601 |
\def\XINT_split_fromleft |
| 26602 |
{\expandafter\XINT_split_fromleft_a\the\numexpr\xint_c_viii-}% |
| 26603 |
\def\XINT_split_fromleft_a #1% |
| 26604 |
{% |
| 26605 |
\xint_UDsignfork |
| 26606 |
#1\XINT_split_fromleft_b |
| 26607 |
-{\XINT_split_fromleft_end_a #1}% |
| 26608 |
\krof |
| 26609 |
}% |
| 26610 |
\def\XINT_split_fromleft_b #1.#2#3#4#5#6#7#8#9% |
| 26611 |
{% |
| 26612 |
\expandafter\XINT_split_fromleft_clean |
| 26613 |
\the\numexpr1#2#3#4#5#6#7#8#9\expandafter |
| 26614 |
\XINT_split_fromleft_a\the\numexpr\xint_c_viii-#1.% |
| 26615 |
}% |
| 26616 |
\def\XINT_split_fromleft_end_a #1.% |
| 26617 |
{% |
| 26618 |
\expandafter\XINT_split_fromleft_clean |
| 26619 |
\the\numexpr1\csname XINT_split_fromleft_end#1\endcsname |
| 26620 |
}% |
| 26621 |
\def\XINT_split_fromleft_clean 1{ }% |
| 26622 |
\expandafter\def\csname XINT_split_fromleft_end7\endcsname #1% |
| 26623 |
{#1\XINT_split_fromleft_end_b}% |
| 26624 |
\expandafter\def\csname XINT_split_fromleft_end6\endcsname #1#2% |
| 26625 |
{#1#2\XINT_split_fromleft_end_b}% |
| 26626 |
\expandafter\def\csname XINT_split_fromleft_end5\endcsname #1#2#3% |
| 26627 |
{#1#2#3\XINT_split_fromleft_end_b}% |
| 26628 |
\expandafter\def\csname XINT_split_fromleft_end4\endcsname #1#2#3#4% |
| 26629 |
{#1#2#3#4\XINT_split_fromleft_end_b}% |
| 26630 |
\expandafter\def\csname XINT_split_fromleft_end3\endcsname #1#2#3#4#5% |
| 26631 |
{#1#2#3#4#5\XINT_split_fromleft_end_b}% |
| 26632 |
\expandafter\def\csname XINT_split_fromleft_end2\endcsname #1#2#3#4#5#6% |
| 26633 |
{#1#2#3#4#5#6\XINT_split_fromleft_end_b}% |
| 26634 |
\expandafter\def\csname XINT_split_fromleft_end1\endcsname #1#2#3#4#5#6#7% |
| 26635 |
{#1#2#3#4#5#6#7\XINT_split_fromleft_end_b}% |
| 26636 |
\expandafter\def\csname XINT_split_fromleft_end0\endcsname #1#2#3#4#5#6#7#8% |
| 26637 |
{#1#2#3#4#5#6#7#8\XINT_split_fromleft_end_b}% |
| 26638 |
\def\XINT_split_fromleft_end_b #1\xint_bye#2\xint_bye.{.#1}% puis . |
| 26639 |
\def\XINT_split_fromright #1.#2\xint_bye |
| 26640 |
{% |
| 26641 |
\expandafter\XINT_split_fromright_a |
| 26642 |
\the\numexpr#1-\numexpr\XINT_length_loop |
| 26643 |
#2\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint: |
| 26644 |
\xint_c_viii\xint_c_vii\xint_c_vi\xint_c_v |
| 26645 |
\xint_c_iv\xint_c_iii\xint_c_ii\xint_c_i\xint_c_\xint_bye |
| 26646 |
.#2\xint_bye |
| 26647 |
}% |
| 26648 |
\def\XINT_split_fromright_a #1% |
| 26649 |
{% |
| 26650 |
\xint_UDsignfork |
| 26651 |
#1\XINT_split_fromleft |
| 26652 |
-\XINT_split_fromright_Lempty |
| 26653 |
\krof |
| 26654 |
}% |
| 26655 |
\def\XINT_split_fromright_Lempty #1.#2\xint_bye#3..{.#2.}% |
| 26656 |
% \end{macrocode} |
| 26657 |
% \subsection{\csh{xintDecSplitL}} |
| 26658 |
% \begin{macrocode} |
| 26659 |
\def\xintDecSplitL {\romannumeral0\xintdecsplitl }% |
| 26660 |
\def\xintdecsplitl #1#2% |
| 26661 |
{% |
| 26662 |
\expandafter\XINT_splitl_finish |
| 26663 |
\romannumeral0\expandafter\XINT_split_xfork |
| 26664 |
\the\numexpr #1\expandafter.\romannumeral`&&@#2% |
| 26665 |
\xint_bye2345678\xint_bye..% |
| 26666 |
}% |
| 26667 |
\def\XINT_splitl_finish #1.#2.{ #1}% |
| 26668 |
% \end{macrocode} |
| 26669 |
% \subsection{\csh{xintDecSplitR}} |
| 26670 |
% \begin{macrocode} |
| 26671 |
\def\xintDecSplitR {\romannumeral0\xintdecsplitr }% |
| 26672 |
\def\xintdecsplitr #1#2% |
| 26673 |
{% |
| 26674 |
\expandafter\XINT_splitr_finish |
| 26675 |
\romannumeral0\expandafter\XINT_split_xfork |
| 26676 |
\the\numexpr #1\expandafter.\romannumeral`&&@#2% |
| 26677 |
\xint_bye2345678\xint_bye..% |
| 26678 |
}% |
| 26679 |
\def\XINT_splitr_finish #1.#2.{ #2}% |
| 26680 |
% \end{macrocode} |
| 26681 |
% \subsection{\csh{xintDSHr}} |
| 26682 |
%\begin{lverb} |
| 26683 |
% DECIMAL SHIFTS \xintDSH {x}{A}$\ |
| 26684 |
% si x <= 0, fait A -> A.10^(|x|). |
| 26685 |
% si x > 0, et A >=0, fait A -> quo(A,10^(x))$\ |
| 26686 |
% si x > 0, et A < 0, fait A -> -quo(-A,10^(x))$\ |
| 26687 |
% (donc pour x > 0 c'est comme DSR itéré x fois)$\ |
| 26688 |
% \xintDSHr donne le `reste' (si x<=0 donne zéro). |
| 26689 |
% |
| 26690 |
% Badly named macros. |
| 26691 |
% |
| 26692 |
% Rewritten for 1.2i, this was old code and \xintDSx has changed interface. |
| 26693 |
%\end{lverb} |
| 26694 |
% \begin{macrocode} |
| 26695 |
\def\xintDSHr {\romannumeral0\xintdshr }% |
| 26696 |
\def\xintdshr #1#2% |
| 26697 |
{% |
| 26698 |
\expandafter\XINT_dshr_fork\the\numexpr#1\expandafter.\romannumeral`&&@#2;% |
| 26699 |
}% |
| 26700 |
\def\XINT_dshr_fork #1% |
| 26701 |
{% |
| 26702 |
\xint_UDzerominusfork |
| 26703 |
0#1\XINT_dshr_xzeroorneg |
| 26704 |
#1-\XINT_dshr_xzeroorneg |
| 26705 |
0-\XINT_dshr_xpositive |
| 26706 |
\krof #1% |
| 26707 |
}% |
| 26708 |
\def\XINT_dshr_xzeroorneg #1;{ 0}% |
| 26709 |
\def\XINT_dshr_xpositive |
| 26710 |
{% |
| 26711 |
\expandafter\xint_stop_atsecondoftwo\romannumeral0\XINT_dsx_xisPos |
| 26712 |
}% |
| 26713 |
% \end{macrocode} |
| 26714 |
% \subsection{\csh{xintDSH}} |
| 26715 |
% \begin{macrocode} |
| 26716 |
\def\xintDSH {\romannumeral0\xintdsh }% |
| 26717 |
\def\xintdsh #1#2% |
| 26718 |
{% |
| 26719 |
\expandafter\XINT_dsh_fork\the\numexpr#1\expandafter.\romannumeral`&&@#2;% |
| 26720 |
}% |
| 26721 |
\def\XINT_dsh_fork #1% |
| 26722 |
{% |
| 26723 |
\xint_UDzerominusfork |
| 26724 |
#1-\XINT_dsh_xiszero |
| 26725 |
0#1\XINT_dsx_xisNeg_checkA |
| 26726 |
0-{\XINT_dsh_xisPos #1}% |
| 26727 |
\krof |
| 26728 |
}% |
| 26729 |
\def\XINT_dsh_xiszero #1.#2;{ #2}% |
| 26730 |
\def\XINT_dsh_xisPos |
| 26731 |
{% |
| 26732 |
\expandafter\xint_stop_atfirstoftwo\romannumeral0\XINT_dsx_xisPos |
| 26733 |
}% |
| 26734 |
% \end{macrocode} |
| 26735 |
% \subsection{\csh{xintDSx}} |
| 26736 |
%\begin{lverb} |
| 26737 |
% --> Attention le cas x=0 est traité dans la même catégorie que x > 0 <-- |
| 26738 |
% |
| 26739 |
%( si x < 0, fait A -> A.10^(|x|) |
| 26740 |
%: si x >= 0, et A >=0, fait A -> {quo(A,10^(x))}{rem(A,10^(x))} |
| 26741 |
%: si x >= 0, et A < 0, d'abord on calcule {quo(-A,10^(x))}{rem(-A,10^(x))} |
| 26742 |
%: puis, si le premier n'est pas nul on lui donne le signe - |
| 26743 |
%: si le premier est nul on donne le signe - au second. |
| 26744 |
%) |
| 26745 |
% On peut donc toujours reconstituer l'original A par 10^x Q \pm R |
| 26746 |
% où il faut prendre le signe plus si Q est positif ou nul et le signe moins si |
| 26747 |
% Q est strictement négatif. |
| 26748 |
% |
| 26749 |
% Rewritten for 1.2i, this was old code. |
| 26750 |
% |
| 26751 |
%\end{lverb} |
| 26752 |
% \begin{macrocode} |
| 26753 |
\def\xintDSx {\romannumeral0\xintdsx }% |
| 26754 |
\def\xintdsx #1#2% |
| 26755 |
{% |
| 26756 |
\expandafter\XINT_dsx_fork\the\numexpr#1\expandafter.\romannumeral`&&@#2;% |
| 26757 |
}% |
| 26758 |
\def\XINT_dsx_fork #1% |
| 26759 |
{% |
| 26760 |
\xint_UDzerominusfork |
| 26761 |
#1-\XINT_dsx_xisZero |
| 26762 |
0#1\XINT_dsx_xisNeg_checkA |
| 26763 |
0-{\XINT_dsx_xisPos #1}% |
| 26764 |
\krof |
| 26765 |
}% |
| 26766 |
\def\XINT_dsx_xisZero #1.#2;{{#2}{0}}% |
| 26767 |
\def\XINT_dsx_xisNeg_checkA #1.#2% |
| 26768 |
{% |
| 26769 |
\xint_gob_til_zero #2\XINT_dsx_xisNeg_Azero 0% |
| 26770 |
\expandafter\XINT_dsx_append\romannumeral\XINT_rep #1\endcsname 0.#2% |
| 26771 |
}% |
| 26772 |
\def\XINT_dsx_xisNeg_Azero #1;{ 0}% |
| 26773 |
\def\XINT_dsx_addzeros #1% |
| 26774 |
{\expandafter\XINT_dsx_append\romannumeral\XINT_rep#1\endcsname0.}% |
| 26775 |
\def\XINT_dsx_addzerosnofuss #1% |
| 26776 |
{\expandafter\XINT_dsx_append\romannumeral\xintreplicate{#1}0.}% |
| 26777 |
\def\XINT_dsx_append #1.#2;{ #2#1}% |
| 26778 |
\def\XINT_dsx_xisPos #1.#2% |
| 26779 |
{% |
| 26780 |
\xint_UDzerominusfork |
| 26781 |
#2-\XINT_dsx_AisZero |
| 26782 |
0#2\XINT_dsx_AisNeg |
| 26783 |
0-\XINT_dsx_AisPos |
| 26784 |
\krof #1.#2% |
| 26785 |
}% |
| 26786 |
\def\XINT_dsx_AisZero #1;{{0}{0}}% |
| 26787 |
\def\XINT_dsx_AisNeg #1.-#2;% |
| 26788 |
{% |
| 26789 |
\expandafter\XINT_dsx_AisNeg_checkiffirstempty |
| 26790 |
\romannumeral0\XINT_split_xfork #1.#2\xint_bye2345678\xint_bye..% |
| 26791 |
}% |
| 26792 |
\def\XINT_dsx_AisNeg_checkiffirstempty #1% |
| 26793 |
{% |
| 26794 |
\xint_gob_til_dot #1\XINT_dsx_AisNeg_finish_zero.% |
| 26795 |
\XINT_dsx_AisNeg_finish_notzero #1% |
| 26796 |
}% |
| 26797 |
\def\XINT_dsx_AisNeg_finish_zero.\XINT_dsx_AisNeg_finish_notzero.#1.% |
| 26798 |
{% |
| 26799 |
\expandafter\XINT_dsx_end |
| 26800 |
\expandafter {\romannumeral0\XINT_num {-#1}}{0}% |
| 26801 |
}% |
| 26802 |
\def\XINT_dsx_AisNeg_finish_notzero #1.#2.% |
| 26803 |
{% |
| 26804 |
\expandafter\XINT_dsx_end |
| 26805 |
\expandafter {\romannumeral0\XINT_num {#2}}{-#1}% |
| 26806 |
}% |
| 26807 |
\def\XINT_dsx_AisPos #1.#2;% |
| 26808 |
{% |
| 26809 |
\expandafter\XINT_dsx_AisPos_finish |
| 26810 |
\romannumeral0\XINT_split_xfork #1.#2\xint_bye2345678\xint_bye..% |
| 26811 |
}% |
| 26812 |
\def\XINT_dsx_AisPos_finish #1.#2.% |
| 26813 |
{% |
| 26814 |
\expandafter\XINT_dsx_end |
| 26815 |
\expandafter {\romannumeral0\XINT_num {#2}}% |
| 26816 |
{\romannumeral0\XINT_num {#1}}% |
| 26817 |
}% |
| 26818 |
\def\XINT_dsx_end #1#2{\expandafter{#2}{#1}}% |
| 26819 |
% \end{macrocode} |
| 26820 |
% \subsection{\csh{xintiiEq}} |
| 26821 |
%\begin{lverb} |
| 26822 |
% no \xintiieq. |
| 26823 |
%\end{lverb} |
| 26824 |
% \begin{macrocode} |
| 26825 |
\def\xintiiEq #1#2{\romannumeral0\xintiiifeq{#1}{#2}{1}{0}}% |
| 26826 |
% \end{macrocode} |
| 26827 |
% \subsection{\csh{xintiiNotEq}} |
| 26828 |
%\begin{lverb} |
| 26829 |
% Pour xintexpr. Pas de version en lowercase. |
| 26830 |
%\end{lverb} |
| 26831 |
% \begin{macrocode} |
| 26832 |
\def\xintiiNotEq #1#2{\romannumeral0\xintiiifeq {#1}{#2}{0}{1}}% |
| 26833 |
% \end{macrocode} |
| 26834 |
% \subsection{\csh{xintiiGeq}} |
| 26835 |
%\begin{lverb} |
| 26836 |
% PLUS GRAND OU ÉGAL |
| 26837 |
% attention compare les **valeurs absolues** |
| 26838 |
% |
| 26839 |
% 1.2l made \xintiiGeq robust against non terminated items. |
| 26840 |
% |
| 26841 |
% 1.2l rewrote \xintiiCmp, but forgot to handle \xintiiGeq too. Done at 1.2m. |
| 26842 |
% |
| 26843 |
% This macro should have been called \xintGEq for example. |
| 26844 |
%\end{lverb} |
| 26845 |
% \begin{macrocode} |
| 26846 |
\def\xintiiGeq {\romannumeral0\xintiigeq }% |
| 26847 |
\def\xintiigeq #1{\expandafter\XINT_iigeq\romannumeral`&&@#1\xint:}% |
| 26848 |
\def\XINT_iigeq #1#2\xint:#3% |
| 26849 |
{% |
| 26850 |
\expandafter\XINT_geq_fork\expandafter #1\romannumeral`&&@#3\xint:#2\xint: |
| 26851 |
}% |
| 26852 |
\def\XINT_geq #1#2\xint:#3% |
| 26853 |
{% |
| 26854 |
\expandafter\XINT_geq_fork\expandafter #1\romannumeral0\xintnum{#3}\xint:#2\xint: |
| 26855 |
}% |
| 26856 |
\def\XINT_geq_fork #1#2% |
| 26857 |
{% |
| 26858 |
\xint_UDzerofork |
| 26859 |
#1\XINT_geq_firstiszero |
| 26860 |
#2\XINT_geq_secondiszero |
| 26861 |
0{}% |
| 26862 |
\krof |
| 26863 |
\xint_UDsignsfork |
| 26864 |
#1#2\XINT_geq_minusminus |
| 26865 |
#1-\XINT_geq_minusplus |
| 26866 |
#2-\XINT_geq_plusminus |
| 26867 |
--\XINT_geq_plusplus |
| 26868 |
\krof #1#2% |
| 26869 |
}% |
| 26870 |
\def\XINT_geq_firstiszero #1\krof 0#2#3\xint:#4\xint: |
| 26871 |
{\xint_UDzerofork #2{ 1}0{ 0}\krof }% |
| 26872 |
\def\XINT_geq_secondiszero #1\krof #20#3\xint:#4\xint:{ 1}% |
| 26873 |
\def\XINT_geq_plusminus #1-{\XINT_geq_plusplus #1{}}% |
| 26874 |
\def\XINT_geq_minusplus -#1{\XINT_geq_plusplus {}#1}% |
| 26875 |
\def\XINT_geq_minusminus --{\XINT_geq_plusplus {}{}}% |
| 26876 |
\def\XINT_geq_plusplus |
| 26877 |
{\expandafter\XINT_geq_finish\romannumeral0\XINT_cmp_plusplus}% |
| 26878 |
\def\XINT_geq_finish #1{\if-#1\expandafter\XINT_geq_no |
| 26879 |
\else\expandafter\XINT_geq_yes\fi}% |
| 26880 |
\def\XINT_geq_no 1{ 0}% |
| 26881 |
\def\XINT_geq_yes { 1}% |
| 26882 |
% \end{macrocode} |
| 26883 |
% \subsection{\csh{xintiiGt}} |
| 26884 |
% \begin{macrocode} |
| 26885 |
\def\xintiiGt #1#2{\romannumeral0\xintiiifgt{#1}{#2}{1}{0}}% |
| 26886 |
% \end{macrocode} |
| 26887 |
% \subsection{\csh{xintiiLt}} |
| 26888 |
% \begin{macrocode} |
| 26889 |
\def\xintiiLt #1#2{\romannumeral0\xintiiiflt{#1}{#2}{1}{0}}% |
| 26890 |
% \end{macrocode} |
| 26891 |
% \subsection{\csh{xintiiGtorEq}} |
| 26892 |
% \begin{macrocode} |
| 26893 |
\def\xintiiGtorEq #1#2{\romannumeral0\xintiiiflt {#1}{#2}{0}{1}}% |
| 26894 |
% \end{macrocode} |
| 26895 |
% \subsection{\csh{xintiiLtorEq}} |
| 26896 |
% \begin{macrocode} |
| 26897 |
\def\xintiiLtorEq #1#2{\romannumeral0\xintiiifgt {#1}{#2}{0}{1}}% |
| 26898 |
% \end{macrocode} |
| 26899 |
% \subsection{\csh{xintiiIsZero}} |
| 26900 |
%\begin{lverb} |
| 26901 |
% 1.09a. restyled in 1.09i. 1.1 adds \xintiiIsZero, etc... for |
| 26902 |
% optimization in \xintexpr |
| 26903 |
%\end{lverb} |
| 26904 |
% \begin{macrocode} |
| 26905 |
\def\xintiiIsZero {\romannumeral0\xintiiiszero }% |
| 26906 |
\def\xintiiiszero #1{\if0\xintiiSgn{#1}\xint_afterfi{ 1}\else\xint_afterfi{ 0}\fi}% |
| 26907 |
% \end{macrocode} |
| 26908 |
% \subsection{\csh{xintiiIsNotZero}} |
| 26909 |
%\begin{lverb} |
| 26910 |
% 1.09a. restyled in 1.09i. 1.1 adds \xintiiIsZero, etc... for |
| 26911 |
% optimization in \xintexpr |
| 26912 |
%\end{lverb} |
| 26913 |
% \begin{macrocode} |
| 26914 |
\def\xintiiIsNotZero {\romannumeral0\xintiiisnotzero }% |
| 26915 |
\def\xintiiisnotzero |
| 26916 |
#1{\if0\xintiiSgn{#1}\xint_afterfi{ 0}\else\xint_afterfi{ 1}\fi}% |
| 26917 |
% \end{macrocode} |
| 26918 |
% \subsection{\csh{xintiiIsOne}} |
| 26919 |
%\begin{lverb} |
| 26920 |
% Added in 1.03. 1.09a defines \xintIsOne. 1.1a adds \xintiiIsOne. |
| 26921 |
% |
| 26922 |
% \XINT_isOne rewritten for 1.2g. Works with expanded strict integers, |
| 26923 |
% positive or negative. |
| 26924 |
% |
| 26925 |
% |
| 26926 |
% |
| 26927 |
%\end{lverb} |
| 26928 |
% \begin{macrocode} |
| 26929 |
\def\xintiiIsOne {\romannumeral0\xintiiisone }% |
| 26930 |
\def\xintiiisone #1{\expandafter\XINT_isone\romannumeral`&&@#1XY}% |
| 26931 |
\def\XINT_isone #1#2#3Y% |
| 26932 |
{% |
| 26933 |
\unless\if#2X\xint_dothis{ 0}\fi |
| 26934 |
\unless\if#11\xint_dothis{ 0}\fi |
| 26935 |
\xint_orthat{ 1}% |
| 26936 |
}% |
| 26937 |
\def\XINT_isOne #1{\XINT_is_One#1XY}% |
| 26938 |
\def\XINT_is_One #1#2#3Y% |
| 26939 |
{% |
| 26940 |
\unless\if#2X\xint_dothis0\fi |
| 26941 |
\unless\if#11\xint_dothis0\fi |
| 26942 |
\xint_orthat1% |
| 26943 |
}% |
| 26944 |
% \end{macrocode} |
| 26945 |
% \subsection{\csh{xintiiOdd}} |
| 26946 |
%\begin{lverb} |
| 26947 |
% \xintOdd is needed for the xintexpr-essions even() and odd() |
| 26948 |
% functions (and also by \xintNewExpr). |
| 26949 |
%\end{lverb} |
| 26950 |
% \begin{macrocode} |
| 26951 |
\def\xintiiOdd {\romannumeral0\xintiiodd }% |
| 26952 |
\def\xintiiodd #1% |
| 26953 |
{% |
| 26954 |
\ifodd\xintLDg{#1} %<- intentional space |
| 26955 |
\xint_afterfi{ 1}% |
| 26956 |
\else |
| 26957 |
\xint_afterfi{ 0}% |
| 26958 |
\fi |
| 26959 |
}% |
| 26960 |
% \end{macrocode} |
| 26961 |
% \subsection{\csh{xintiiEven}} |
| 26962 |
% \begin{macrocode} |
| 26963 |
\def\xintiiEven {\romannumeral0\xintiieven }% |
| 26964 |
\def\xintiieven #1% |
| 26965 |
{% |
| 26966 |
\ifodd\xintLDg{#1} %<- intentional space |
| 26967 |
\xint_afterfi{ 0}% |
| 26968 |
\else |
| 26969 |
\xint_afterfi{ 1}% |
| 26970 |
\fi |
| 26971 |
}% |
| 26972 |
% \end{macrocode} |
| 26973 |
% \subsection{\csh{xintiiMON}} |
| 26974 |
%\begin{lverb} |
| 26975 |
% MINUS ONE TO THE POWER N |
| 26976 |
%\end{lverb} |
| 26977 |
% \begin{macrocode} |
| 26978 |
\def\xintiiMON {\romannumeral0\xintiimon }% |
| 26979 |
\def\xintiimon #1% |
| 26980 |
{% |
| 26981 |
\ifodd\xintLDg {#1} %<- intentional space |
| 26982 |
\xint_afterfi{ -1}% |
| 26983 |
\else |
| 26984 |
\xint_afterfi{ 1}% |
| 26985 |
\fi |
| 26986 |
}% |
| 26987 |
% \end{macrocode} |
| 26988 |
% \subsection{\csh{xintiiMMON}} |
| 26989 |
%\begin{lverb} |
| 26990 |
% MINUS ONE TO THE POWER N-1 |
| 26991 |
%\end{lverb} |
| 26992 |
% \begin{macrocode} |
| 26993 |
\def\xintiiMMON {\romannumeral0\xintiimmon }% |
| 26994 |
\def\xintiimmon #1% |
| 26995 |
{% |
| 26996 |
\ifodd\xintLDg {#1} %<- intentional space |
| 26997 |
\xint_afterfi{ 1}% |
| 26998 |
\else |
| 26999 |
\xint_afterfi{ -1}% |
| 27000 |
\fi |
| 27001 |
}% |
| 27002 |
% \end{macrocode} |
| 27003 |
% \subsection{\csh{xintSgnFork}} |
| 27004 |
%\begin{lverb} |
| 27005 |
% Expandable three-way fork added in 1.07. The argument #1 must expand |
| 27006 |
% to non-self-ending -1,0 or 1. 1.09i with _thenstop (now _stop_at...). |
| 27007 |
%\end{lverb} |
| 27008 |
% \begin{macrocode} |
| 27009 |
\def\xintSgnFork {\romannumeral0\xintsgnfork }% |
| 27010 |
\def\xintsgnfork #1% |
| 27011 |
{% |
| 27012 |
\ifcase #1 \expandafter\xint_stop_atsecondofthree |
| 27013 |
\or\expandafter\xint_stop_atthirdofthree |
| 27014 |
\else\expandafter\xint_stop_atfirstofthree |
| 27015 |
\fi |
| 27016 |
}% |
| 27017 |
% \end{macrocode} |
| 27018 |
% \subsection{\csh{xintiiifSgn}} |
| 27019 |
%\begin{lverb} |
| 27020 |
% Expandable three-way fork added in 1.09a. Branches expandably |
| 27021 |
% depending on whether <0, =0, >0. Choice of branch guaranteed in two steps. |
| 27022 |
% |
| 27023 |
% 1.09i has \xint_firstofthreeafterstop (now \xint_stop_atfirstofthree) etc |
| 27024 |
% for faster expansion. |
| 27025 |
% |
| 27026 |
% 1.1 adds \xintiiifSgn for optimization in xintexpr-essions. Should I move |
| 27027 |
% them to xintcore? (for bnumexpr) |
| 27028 |
%\end{lverb} |
| 27029 |
% \begin{macrocode} |
| 27030 |
\def\xintiiifSgn {\romannumeral0\xintiiifsgn }% |
| 27031 |
\def\xintiiifsgn #1% |
| 27032 |
{% |
| 27033 |
\ifcase \xintiiSgn{#1} |
| 27034 |
\expandafter\xint_stop_atsecondofthree |
| 27035 |
\or\expandafter\xint_stop_atthirdofthree |
| 27036 |
\else\expandafter\xint_stop_atfirstofthree |
| 27037 |
\fi |
| 27038 |
}% |
| 27039 |
% \end{macrocode} |
| 27040 |
% \subsection{\csh{xintiiifCmp}} |
| 27041 |
%\begin{lverb} |
| 27042 |
% 1.09e |
| 27043 |
% \xintifCmp {n}{m}{if n<m}{if n=m}{if n>m}. 1.1a adds ii variant |
| 27044 |
%\end{lverb} |
| 27045 |
% \begin{macrocode} |
| 27046 |
\def\xintiiifCmp {\romannumeral0\xintiiifcmp }% |
| 27047 |
\def\xintiiifcmp #1#2% |
| 27048 |
{% |
| 27049 |
\ifcase\xintiiCmp {#1}{#2} |
| 27050 |
\expandafter\xint_stop_atsecondofthree |
| 27051 |
\or\expandafter\xint_stop_atthirdofthree |
| 27052 |
\else\expandafter\xint_stop_atfirstofthree |
| 27053 |
\fi |
| 27054 |
}% |
| 27055 |
% \end{macrocode} |
| 27056 |
% \subsection{\csh{xintiiifEq}} |
| 27057 |
%\begin{lverb} |
| 27058 |
% 1.09a \xintifEq {n}{m}{YES if n=m}{NO if n<>m}. 1.1a adds ii variant |
| 27059 |
%\end{lverb} |
| 27060 |
% \begin{macrocode} |
| 27061 |
\def\xintiiifEq {\romannumeral0\xintiiifeq }% |
| 27062 |
\def\xintiiifeq #1#2% |
| 27063 |
{% |
| 27064 |
\if0\xintiiCmp{#1}{#2}% |
| 27065 |
\expandafter\xint_stop_atfirstoftwo |
| 27066 |
\else\expandafter\xint_stop_atsecondoftwo |
| 27067 |
\fi |
| 27068 |
}% |
| 27069 |
% \end{macrocode} |
| 27070 |
% \subsection{\csh{xintiiifGt}} |
| 27071 |
%\begin{lverb} |
| 27072 |
% 1.09a \xintifGt {n}{m}{YES if n>m}{NO if n<=m}. 1.1a adds ii variant |
| 27073 |
%\end{lverb} |
| 27074 |
% \begin{macrocode} |
| 27075 |
\def\xintiiifGt {\romannumeral0\xintiiifgt }% |
| 27076 |
\def\xintiiifgt #1#2% |
| 27077 |
{% |
| 27078 |
\if1\xintiiCmp{#1}{#2}% |
| 27079 |
\expandafter\xint_stop_atfirstoftwo |
| 27080 |
\else\expandafter\xint_stop_atsecondoftwo |
| 27081 |
\fi |
| 27082 |
}% |
| 27083 |
% \end{macrocode} |
| 27084 |
% \subsection{\csh{xintiiifLt}} |
| 27085 |
%\begin{lverb} |
| 27086 |
% 1.09a \xintifLt {n}{m}{YES if n<m}{NO if n>=m}. Restyled in 1.09i. |
| 27087 |
% 1.1a adds ii variant |
| 27088 |
%\end{lverb} |
| 27089 |
% \begin{macrocode} |
| 27090 |
\def\xintiiifLt {\romannumeral0\xintiiiflt }% |
| 27091 |
\def\xintiiiflt #1#2% |
| 27092 |
{% |
| 27093 |
\ifnum\xintiiCmp{#1}{#2}<\xint_c_ |
| 27094 |
\expandafter\xint_stop_atfirstoftwo |
| 27095 |
\else \expandafter\xint_stop_atsecondoftwo |
| 27096 |
\fi |
| 27097 |
}% |
| 27098 |
% \end{macrocode} |
| 27099 |
% \subsection{\csh{xintiiifZero}} |
| 27100 |
%\begin{lverb} |
| 27101 |
% Expandable two-way fork added in 1.09a. Branches expandably depending on |
| 27102 |
% whether the argument is zero (branch A) or not (branch B). 1.09i restyling. By |
| 27103 |
% the way it appears (not thoroughly tested, though) that \if tests are faster |
| 27104 |
% than \ifnum tests. 1.1 adds ii versions. |
| 27105 |
%\end{lverb} |
| 27106 |
% \begin{macrocode} |
| 27107 |
\def\xintiiifZero {\romannumeral0\xintiiifzero }% |
| 27108 |
\def\xintiiifzero #1% |
| 27109 |
{% |
| 27110 |
\if0\xintiiSgn{#1}% |
| 27111 |
\expandafter\xint_stop_atfirstoftwo |
| 27112 |
\else |
| 27113 |
\expandafter\xint_stop_atsecondoftwo |
| 27114 |
\fi |
| 27115 |
}% |
| 27116 |
% \end{macrocode} |
| 27117 |
% \subsection{\csh{xintiiifNotZero}} |
| 27118 |
% \begin{macrocode} |
| 27119 |
\def\xintiiifNotZero {\romannumeral0\xintiiifnotzero }% |
| 27120 |
\def\xintiiifnotzero #1% |
| 27121 |
{% |
| 27122 |
\if0\xintiiSgn{#1}% |
| 27123 |
\expandafter\xint_stop_atsecondoftwo |
| 27124 |
\else |
| 27125 |
\expandafter\xint_stop_atfirstoftwo |
| 27126 |
\fi |
| 27127 |
}% |
| 27128 |
% \end{macrocode} |
| 27129 |
% \subsection{\csh{xintiiifOne}} |
| 27130 |
%\begin{lverb} |
| 27131 |
% added in 1.09i. 1.1a adds \xintiiifOne. |
| 27132 |
%\end{lverb} |
| 27133 |
% \begin{macrocode} |
| 27134 |
\def\xintiiifOne {\romannumeral0\xintiiifone }% |
| 27135 |
\def\xintiiifone #1% |
| 27136 |
{% |
| 27137 |
\if1\xintiiIsOne{#1}% |
| 27138 |
\expandafter\xint_stop_atfirstoftwo |
| 27139 |
\else |
| 27140 |
\expandafter\xint_stop_atsecondoftwo |
| 27141 |
\fi |
| 27142 |
}% |
| 27143 |
% \end{macrocode} |
| 27144 |
% \subsection{\csh{xintiiifOdd}} |
| 27145 |
%\begin{lverb} |
| 27146 |
% 1.09e. Restyled in 1.09i. 1.1a adds \xintiiifOdd. |
| 27147 |
%\end{lverb} |
| 27148 |
% \begin{macrocode} |
| 27149 |
\def\xintiiifOdd {\romannumeral0\xintiiifodd }% |
| 27150 |
\def\xintiiifodd #1% |
| 27151 |
{% |
| 27152 |
\if\xintiiOdd{#1}1% |
| 27153 |
\expandafter\xint_stop_atfirstoftwo |
| 27154 |
\else |
| 27155 |
\expandafter\xint_stop_atsecondoftwo |
| 27156 |
\fi |
| 27157 |
}% |
| 27158 |
% \end{macrocode} |
| 27159 |
% \subsection{\csh{xintifTrueAelseB}, \csh{xintifFalseAelseB}} |
| 27160 |
%\begin{lverb} |
| 27161 |
% 1.09i, with name changes at 1.2i. |
| 27162 |
% |
| 27163 |
% 1.2o uses \xintiiifNotZero, see comments to \xintAND etc... This will work |
| 27164 |
% fine with arguments being nested xintfrac.sty macros, without the overhead |
| 27165 |
% of \xintNum or \xintRaw parsing. |
| 27166 |
%\end{lverb} |
| 27167 |
% \begin{macrocode} |
| 27168 |
\def\xintifTrueAelseB {\romannumeral0\xintiiifnotzero}% |
| 27169 |
\def\xintifFalseAelseB{\romannumeral0\xintiiifzero}% |
| 27170 |
% \end{macrocode} |
| 27171 |
% \subsection{\csh{xintIsTrue}, \csh{xintIsFalse}} |
| 27172 |
%\begin{lverb} |
| 27173 |
% 1.09c. Suppressed at 1.2o. They seem not to have been documented, fortunately. |
| 27174 |
%\end{lverb} |
| 27175 |
% \begin{macrocode} |
| 27176 |
%\let\xintIsTrue \xintIsNotZero |
| 27177 |
%\let\xintIsFalse\xintIsZero |
| 27178 |
% \end{macrocode} |
| 27179 |
% \subsection{\csh{xintNOT}} |
| 27180 |
%\begin{lverb} |
| 27181 |
% 1.09c with name change at 1.2o. Besides, the macro is now defined as ii-type. |
| 27182 |
%\end{lverb} |
| 27183 |
% \begin{macrocode} |
| 27184 |
\def\xintNOT{\romannumeral0\xintiiiszero}% |
| 27185 |
% \end{macrocode} |
| 27186 |
% \subsection{\csh{xintAND}, \csh{xintOR}, \csh{xintXOR}} |
| 27187 |
%\begin{lverb} |
| 27188 |
% Added with 1.09a. But they used \xintSgn, etc... rather than |
| 27189 |
% \xintiiSgn. This brings \xintNum overhead which is not really desired, and |
| 27190 |
% which is not needed for use by xintexpr.sty. At 1.2o I modify them to use |
| 27191 |
% only ii macros. This is enough for sign or zeroness even for xintfrac |
| 27192 |
% format, as manipulated inside the \xintexpr. Big hesitation whether there |
| 27193 |
% should be however \xintiiAND outputting 1 or 0 versus an \xintAND outputting |
| 27194 |
% 1[0] versus 0[0] for example. |
| 27195 |
%\end{lverb} |
| 27196 |
% \begin{macrocode} |
| 27197 |
\def\xintAND {\romannumeral0\xintand }% |
| 27198 |
\def\xintand #1#2{\if0\xintiiSgn{#1}\expandafter\xint_firstoftwo |
| 27199 |
\else\expandafter\xint_secondoftwo\fi |
| 27200 |
{ 0}{\xintiiisnotzero{#2}}}% |
| 27201 |
\def\xintOR {\romannumeral0\xintor }% |
| 27202 |
\def\xintor #1#2{\if0\xintiiSgn{#1}\expandafter\xint_firstoftwo |
| 27203 |
\else\expandafter\xint_secondoftwo\fi |
| 27204 |
{\xintiiisnotzero{#2}}{ 1}}% |
| 27205 |
\def\xintXOR {\romannumeral0\xintxor }% |
| 27206 |
\def\xintxor #1#2{\if\xintiiIsZero{#1}\xintiiIsZero{#2}% |
| 27207 |
\xint_afterfi{ 0}\else\xint_afterfi{ 1}\fi }% |
| 27208 |
% \end{macrocode} |
| 27209 |
% \subsection{\csh{xintANDof}} |
| 27210 |
%\begin{lverb} |
| 27211 |
% New with 1.09a. \xintANDof works also with an empty list. Empty items |
| 27212 |
% however are not accepted. |
| 27213 |
% |
| 27214 |
% 1.2l made \xintANDof robust against non terminated items. |
| 27215 |
% |
| 27216 |
% 1.2o's \xintifTrueAelseB is now an ii macro, actually. |
| 27217 |
% |
| 27218 |
% 1.4. This macro as well as ORof and XORof were formally not used by |
| 27219 |
% xintexpr, which uses comma separated items, but at 1.4 xintexpr uses braced |
| 27220 |
% items. And the macros here got slightly refactored and \XINT_ANDof added for |
| 27221 |
% usage by xintexpr and the NewExpr hook. For some random reason I decided to |
| 27222 |
% use ^ as delimiter this has to do that other macros in xintfrac in same |
| 27223 |
% family (such as \xintGCDof, \xintSum) also use \xint: internally and |
| 27224 |
% although not strictly needed having two separate ones clarifies. |
| 27225 |
% |
| 27226 |
%\end{lverb} |
| 27227 |
% \begin{macrocode} |
| 27228 |
\def\xintANDof {\romannumeral0\xintandof }% |
| 27229 |
\def\xintandof #1{\expandafter\XINT_andof\romannumeral`&&@#1^}% |
| 27230 |
\def\XINT_ANDof {\romannumeral0\XINT_andof}% |
| 27231 |
\def\XINT_andof #1% |
| 27232 |
{% |
| 27233 |
\xint_gob_til_^ #1\XINT_andof_yes ^% |
| 27234 |
\xintiiifNotZero{#1}\XINT_andof\XINT_andof_no |
| 27235 |
}% |
| 27236 |
\def\XINT_andof_no #1^{ 0}% |
| 27237 |
\def\XINT_andof_yes ^#1\XINT_andof_no{ 1}% |
| 27238 |
% \end{macrocode} |
| 27239 |
% \subsection{\csh{xintORof}} |
| 27240 |
%\begin{lverb} |
| 27241 |
% New with 1.09a. Works also with an empty list. Empty items |
| 27242 |
% however are not accepted. |
| 27243 |
% |
| 27244 |
% 1.2l made \xintORof robust against non terminated items. |
| 27245 |
% |
| 27246 |
% Refactored at 1.4. |
| 27247 |
%\end{lverb} |
| 27248 |
% \begin{macrocode} |
| 27249 |
\def\xintORof {\romannumeral0\xintorof }% |
| 27250 |
\def\xintorof #1{\expandafter\XINT_orof\romannumeral`&&@#1^}% |
| 27251 |
\def\XINT_ORof {\romannumeral0\XINT_orof}% |
| 27252 |
\def\XINT_orof #1% |
| 27253 |
{% |
| 27254 |
\xint_gob_til_^ #1\XINT_orof_no ^% |
| 27255 |
\xintiiifNotZero{#1}\XINT_orof_yes\XINT_orof |
| 27256 |
}% |
| 27257 |
\def\XINT_orof_yes#1^{ 1}% |
| 27258 |
\def\XINT_orof_no ^#1\XINT_orof{ 0}% |
| 27259 |
% \end{macrocode} |
| 27260 |
% \subsection{\csh{xintXORof}} |
| 27261 |
%\begin{lverb} |
| 27262 |
% New with 1.09a. Works with an empty list, too. Empty items |
| 27263 |
% however are not accepted. \XINT_xorof_c more |
| 27264 |
% efficient in 1.09i. |
| 27265 |
% |
| 27266 |
% 1.2l made \xintXORof robust against non terminated items. |
| 27267 |
% |
| 27268 |
% Refactored at 1.4 to use \numexpr (or an \ifnum). I have not tested if |
| 27269 |
% more efficient or not or if one can do better without \the. |
| 27270 |
% \XINT_XORof for xintexpr matters. |
| 27271 |
%\end{lverb} |
| 27272 |
% \begin{macrocode} |
| 27273 |
\def\xintXORof {\romannumeral0\xintxorof }% |
| 27274 |
\def\xintxorof #1{\expandafter\XINT_xorof\romannumeral`&&@#1^}% |
| 27275 |
\def\XINT_XORof {\romannumeral0\XINT_xorof}% |
| 27276 |
\def\XINT_xorof {\if1\the\numexpr\XINT_xorof_a}% |
| 27277 |
\def\XINT_xorof_a #1% |
| 27278 |
{% |
| 27279 |
\xint_gob_til_^ #1\XINT_xorof_e ^% |
| 27280 |
\xintiiifNotZero{#1}{-}{}\XINT_xorof_a |
| 27281 |
}% |
| 27282 |
\def\XINT_xorof_e ^#1\XINT_xorof_a |
| 27283 |
{1\relax\xint_afterfi{ 0}\else\xint_afterfi{ 1}\fi}% |
| 27284 |
% \end{macrocode} |
| 27285 |
% \subsection{\csh{xintiiMax}} |
| 27286 |
%\begin{lverb} |
| 27287 |
% At 1.2m, a long-standing bug was fixed: \xintiiMax had the overhead of |
| 27288 |
% applying \xintNum to its arguments due to use of a sub-macro of \xintGeq |
| 27289 |
% code to which this overhead was added at some point. |
| 27290 |
% |
| 27291 |
% And on this occasion I reduced even more number of times input is grabbed. |
| 27292 |
%\end{lverb} |
| 27293 |
% \begin{macrocode} |
| 27294 |
\def\xintiiMax {\romannumeral0\xintiimax }% |
| 27295 |
\def\xintiimax #1% |
| 27296 |
{% |
| 27297 |
\expandafter\xint_iimax \romannumeral`&&@#1\xint: |
| 27298 |
}% |
| 27299 |
\def\xint_iimax #1\xint:#2% |
| 27300 |
{% |
| 27301 |
\expandafter\XINT_max_fork\romannumeral`&&@#2\xint:#1\xint: |
| 27302 |
}% |
| 27303 |
% \end{macrocode} |
| 27304 |
%\begin{lverb} |
| 27305 |
% #3#4 vient du *premier*, |
| 27306 |
% #1#2 vient du *second*. I have renamed the sub-macros at 1.2m because the |
| 27307 |
% terminology was quite counter-intuitive; there was no bug, but still. |
| 27308 |
%\end{lverb} |
| 27309 |
% \begin{macrocode} |
| 27310 |
\def\XINT_max_fork #1#2\xint:#3#4\xint: |
| 27311 |
{% |
| 27312 |
\xint_UDsignsfork |
| 27313 |
#1#3\XINT_max_minusminus % A < 0, B < 0 |
| 27314 |
#1-\XINT_max_plusminus % B < 0, A >= 0 |
| 27315 |
#3-\XINT_max_minusplus % A < 0, B >= 0 |
| 27316 |
--{\xint_UDzerosfork |
| 27317 |
#1#3\XINT_max_zerozero % A = B = 0 |
| 27318 |
#10\XINT_max_pluszero % B = 0, A > 0 |
| 27319 |
#30\XINT_max_zeroplus % A = 0, B > 0 |
| 27320 |
00\XINT_max_plusplus % A, B > 0 |
| 27321 |
\krof }% |
| 27322 |
\krof |
| 27323 |
#3#1#2\xint:#4\xint: |
| 27324 |
\expandafter\xint_stop_atfirstoftwo |
| 27325 |
\else |
| 27326 |
\expandafter\xint_stop_atsecondoftwo |
| 27327 |
\fi |
| 27328 |
{#3#4}{#1#2}% |
| 27329 |
}% |
| 27330 |
% \end{macrocode} |
| 27331 |
%\begin{lverb} |
| 27332 |
% Refactored at 1.2m for avoiding grabbing arguments. Position of inputs |
| 27333 |
% shared with iiCmp and iiGeq code. |
| 27334 |
%\end{lverb} |
| 27335 |
% \begin{macrocode} |
| 27336 |
\def\XINT_max_zerozero #1\fi{\xint_stop_atfirstoftwo }% |
| 27337 |
\def\XINT_max_zeroplus #1\fi{\xint_stop_atsecondoftwo }% |
| 27338 |
\def\XINT_max_pluszero #1\fi{\xint_stop_atfirstoftwo }% |
| 27339 |
\def\XINT_max_minusplus #1\fi{\xint_stop_atsecondoftwo }% |
| 27340 |
\def\XINT_max_plusminus #1\fi{\xint_stop_atfirstoftwo }% |
| 27341 |
\def\XINT_max_plusplus |
| 27342 |
{% |
| 27343 |
\if1\romannumeral0\XINT_geq_plusplus |
| 27344 |
}% |
| 27345 |
% \end{macrocode} |
| 27346 |
%\begin{lverb} |
| 27347 |
% Premier des testés |A|=-A, second est |B|=-B. On veut le max(A,B), |
| 27348 |
% c'est donc A si |A|<|B| (ou |A|=|B|, mais peu importe alors). Donc on peut |
| 27349 |
% faire cela avec \unless. Simple. |
| 27350 |
%\end{lverb} |
| 27351 |
% \begin{macrocode} |
| 27352 |
\def\XINT_max_minusminus --% |
| 27353 |
{% |
| 27354 |
\unless\if1\romannumeral0\XINT_geq_plusplus{}{}% |
| 27355 |
}% |
| 27356 |
% \end{macrocode} |
| 27357 |
% \subsection{\csh{xintiiMin}} |
| 27358 |
%\begin{lverb} |
| 27359 |
% New with 1.09a. I add \xintiiMin in 1.1 and \xintMin is |
| 27360 |
% an $xintfracnameimp macro. |
| 27361 |
% |
| 27362 |
% At 1.2m, a long-standing bug was fixed: \xintiiMin had the overhead of |
| 27363 |
% applying \xintNum to its arguments due to use of a sub-macro of \xintGeq |
| 27364 |
% code to which this overhead was added at some point. |
| 27365 |
% |
| 27366 |
% And on this occasion I reduced even more number of times input is grabbed. |
| 27367 |
%\end{lverb} |
| 27368 |
% \begin{macrocode} |
| 27369 |
\def\xintiiMin {\romannumeral0\xintiimin }% |
| 27370 |
\def\xintiimin #1% |
| 27371 |
{% |
| 27372 |
\expandafter\xint_iimin \romannumeral`&&@#1\xint: |
| 27373 |
}% |
| 27374 |
\def\xint_iimin #1\xint:#2% |
| 27375 |
{% |
| 27376 |
\expandafter\XINT_min_fork\romannumeral`&&@#2\xint:#1\xint: |
| 27377 |
}% |
| 27378 |
\def\XINT_min_fork #1#2\xint:#3#4\xint: |
| 27379 |
{% |
| 27380 |
\xint_UDsignsfork |
| 27381 |
#1#3\XINT_min_minusminus % A < 0, B < 0 |
| 27382 |
#1-\XINT_min_plusminus % B < 0, A >= 0 |
| 27383 |
#3-\XINT_min_minusplus % A < 0, B >= 0 |
| 27384 |
--{\xint_UDzerosfork |
| 27385 |
#1#3\XINT_min_zerozero % A = B = 0 |
| 27386 |
#10\XINT_min_pluszero % B = 0, A > 0 |
| 27387 |
#30\XINT_min_zeroplus % A = 0, B > 0 |
| 27388 |
00\XINT_min_plusplus % A, B > 0 |
| 27389 |
\krof }% |
| 27390 |
\krof |
| 27391 |
#3#1#2\xint:#4\xint: |
| 27392 |
\expandafter\xint_stop_atsecondoftwo |
| 27393 |
\else |
| 27394 |
\expandafter\xint_stop_atfirstoftwo |
| 27395 |
\fi |
| 27396 |
{#3#4}{#1#2}% |
| 27397 |
}% |
| 27398 |
\def\XINT_min_zerozero #1\fi{\xint_stop_atfirstoftwo }% |
| 27399 |
\def\XINT_min_zeroplus #1\fi{\xint_stop_atfirstoftwo }% |
| 27400 |
\def\XINT_min_pluszero #1\fi{\xint_stop_atsecondoftwo }% |
| 27401 |
\def\XINT_min_minusplus #1\fi{\xint_stop_atfirstoftwo }% |
| 27402 |
\def\XINT_min_plusminus #1\fi{\xint_stop_atsecondoftwo }% |
| 27403 |
\def\XINT_min_plusplus |
| 27404 |
{% |
| 27405 |
\if1\romannumeral0\XINT_geq_plusplus |
| 27406 |
}% |
| 27407 |
\def\XINT_min_minusminus --% |
| 27408 |
{% |
| 27409 |
\unless\if1\romannumeral0\XINT_geq_plusplus{}{}% |
| 27410 |
}% |
| 27411 |
% \end{macrocode} |
| 27412 |
% \subsection{\csh{xintiiMaxof}} |
| 27413 |
%\begin{lverb} |
| 27414 |
% New with 1.09a. 1.2 has NO MORE \xintMaxof, requires \xintfracname. |
| 27415 |
% 1.2a adds \xintiiMaxof, as \xintiiMaxof:csv is not public. |
| 27416 |
% |
| 27417 |
% NOT compatible with empty list. |
| 27418 |
% |
| 27419 |
% 1.2l made \xintiiMaxof robust against non terminated items. |
| 27420 |
% |
| 27421 |
% 1.4 refactors code to allow empty argument. For usage by \xintiiexpr. |
| 27422 |
% Slight deterioration, will come back. |
| 27423 |
% |
| 27424 |
%\end{lverb} |
| 27425 |
% \begin{macrocode} |
| 27426 |
\def\xintiiMaxof {\romannumeral0\xintiimaxof }% |
| 27427 |
\def\xintiimaxof #1{\expandafter\XINT_iimaxof\romannumeral`&&@#1^}% |
| 27428 |
\def\XINT_iiMaxof{\romannumeral0\XINT_iimaxof}% |
| 27429 |
\def\XINT_iimaxof#1% |
| 27430 |
{% |
| 27431 |
\xint_gob_til_^ #1\XINT_iimaxof_empty ^% |
| 27432 |
\expandafter\XINT_iimaxof_loop\romannumeral`&&@#1\xint: |
| 27433 |
}% |
| 27434 |
\def\XINT_iimaxof_empty ^#1\xint:{ 0}% |
| 27435 |
\def\XINT_iimaxof_loop #1\xint:#2% |
| 27436 |
{% |
| 27437 |
\xint_gob_til_^ #2\XINT_iimaxof_e ^% |
| 27438 |
\expandafter\XINT_iimaxof_loop\romannumeral0\xintiimax{#1}{#2}\xint: |
| 27439 |
}% |
| 27440 |
\def\XINT_iimaxof_e ^#1\xintiimax #2#3\xint:{ #2}% |
| 27441 |
% \end{macrocode} |
| 27442 |
% \subsection{\csh{xintiiMinof}} |
| 27443 |
%\begin{lverb} |
| 27444 |
% 1.09a. 1.2a adds \xintiiMinof which was lacking. |
| 27445 |
% |
| 27446 |
% 1.4 refactoring for \xintiiexpr matters. |
| 27447 |
%\end{lverb} |
| 27448 |
% \begin{macrocode} |
| 27449 |
\def\xintiiMinof {\romannumeral0\xintiiminof }% |
| 27450 |
\def\xintiiminof #1{\expandafter\XINT_iiminof\romannumeral`&&@#1^}% |
| 27451 |
\def\XINT_iiMinof{\romannumeral0\XINT_iiminof}% |
| 27452 |
\def\XINT_iiminof#1% |
| 27453 |
{% |
| 27454 |
\xint_gob_til_^ #1\XINT_iiminof_empty ^% |
| 27455 |
\expandafter\XINT_iiminof_loop\romannumeral`&&@#1\xint: |
| 27456 |
}% |
| 27457 |
\def\XINT_iiminof_empty ^#1\xint:{ 0}% |
| 27458 |
\def\XINT_iiminof_loop #1\xint:#2% |
| 27459 |
{% |
| 27460 |
\xint_gob_til_^ #2\XINT_iiminof_e ^% |
| 27461 |
\expandafter\XINT_iiminof_loop\romannumeral0\xintiimin{#1}{#2}\xint: |
| 27462 |
}% |
| 27463 |
\def\XINT_iiminof_e ^#1\xintiimin #2#3\xint:{ #2}% |
| 27464 |
% \end{macrocode} |
| 27465 |
% \subsection{\csh{xintiiSum}} |
| 27466 |
%\begin{lverb} |
| 27467 |
% \xintiiSum {{a}{b}...{z}} |
| 27468 |
% Refactored at 1.4 for matters initially related to xintexpr delimiter |
| 27469 |
% choice. |
| 27470 |
% |
| 27471 |
% |
| 27472 |
%\end{lverb} |
| 27473 |
% \begin{macrocode} |
| 27474 |
\def\xintiiSum {\romannumeral0\xintiisum }% |
| 27475 |
\def\xintiisum #1{\expandafter\XINT_iisum\romannumeral`&&@#1^}% |
| 27476 |
\def\XINT_iiSum{\romannumeral0\XINT_iisum}% |
| 27477 |
\def\XINT_iisum #1% |
| 27478 |
{% |
| 27479 |
\expandafter\XINT_iisum_a\romannumeral`&&@#1\xint: |
| 27480 |
}% |
| 27481 |
\def\XINT_iisum_a #1% |
| 27482 |
{% |
| 27483 |
\xint_gob_til_^ #1\XINT_iisum_empty ^% |
| 27484 |
\XINT_iisum_loop #1% |
| 27485 |
}% |
| 27486 |
\def\XINT_iisum_empty ^#1\xint:{ 0}% |
| 27487 |
% \end{macrocode} |
| 27488 |
%\begin{lverb} |
| 27489 |
% bad coding as it depends on internal conventions of \XINT_add_nfork |
| 27490 |
%\end{lverb} |
| 27491 |
% \begin{macrocode} |
| 27492 |
\def\XINT_iisum_loop #1#2\xint:#3% |
| 27493 |
{% |
| 27494 |
\expandafter\XINT_iisum_loop_a |
| 27495 |
\expandafter#1\romannumeral`&&@#3\xint:#2\xint:\xint: |
| 27496 |
}% |
| 27497 |
\def\XINT_iisum_loop_a #1#2% |
| 27498 |
{% |
| 27499 |
\xint_gob_til_^ #2\XINT_iisum_loop_end ^% |
| 27500 |
\expandafter\XINT_iisum_loop\romannumeral0\XINT_add_nfork #1#2% |
| 27501 |
}% |
| 27502 |
% \end{macrocode} |
| 27503 |
%\begin{lverb} |
| 27504 |
% see previous comment! |
| 27505 |
%\end{lverb} |
| 27506 |
% \begin{macrocode} |
| 27507 |
\def\XINT_iisum_loop_end ^#1\XINT_add_nfork #2#3\xint:#4\xint:\xint:{ #2#4}% |
| 27508 |
% \end{macrocode} |
| 27509 |
% \subsection{\csh{xintiiPrd}} |
| 27510 |
%\begin{lverb} |
| 27511 |
% \xintiiPrd {{a}...{z}} |
| 27512 |
% |
| 27513 |
% |
| 27514 |
% Macros renamed and refactored (slightly more macros here to supposedly bring |
| 27515 |
% micro-gain) at 1.4 to match changes in xintfrac of delimiter, in sync with |
| 27516 |
% some usage in xintexpr. |
| 27517 |
% |
| 27518 |
% Contrarily to the xintfrac version \xintPrd, this one aborts as soon as it |
| 27519 |
% hits a zero value. |
| 27520 |
% |
| 27521 |
% |
| 27522 |
%\end{lverb} |
| 27523 |
% \begin{macrocode} |
| 27524 |
\def\xintiiPrd {\romannumeral0\xintiiprd }% |
| 27525 |
\def\xintiiprd #1{\expandafter\XINT_iiprd\romannumeral`&&@#1^}% |
| 27526 |
\def\XINT_iiPrd{\romannumeral0\XINT_iiprd}% |
| 27527 |
% \end{macrocode} |
| 27528 |
%\begin{lverb} |
| 27529 |
% The above romannumeral caused f-expansion of the list argument. |
| 27530 |
% We f-expand below the first item and each successive items because |
| 27531 |
% we do not use \xintiiMul but jump directly into \XINT_mul_nfork. |
| 27532 |
% |
| 27533 |
%\end{lverb} |
| 27534 |
% \begin{macrocode} |
| 27535 |
\def\XINT_iiprd #1% |
| 27536 |
{% |
| 27537 |
\expandafter\XINT_iiprd_a\romannumeral`&&@#1\xint: |
| 27538 |
}% |
| 27539 |
\def\XINT_iiprd_a #1% |
| 27540 |
{% |
| 27541 |
\xint_gob_til_^ #1\XINT_iiprd_empty ^% |
| 27542 |
\xint_gob_til_zero #1\XINT_iiprd_zero 0% |
| 27543 |
\XINT_iiprd_loop #1% |
| 27544 |
}% |
| 27545 |
\def\XINT_iiprd_empty ^#1\xint:{ 1}% |
| 27546 |
\def\XINT_iiprd_zero 0#1^{ 0}% |
| 27547 |
% \end{macrocode} |
| 27548 |
%\begin{lverb} |
| 27549 |
% bad coding as it depends on internal conventions of \XINT_mul_nfork |
| 27550 |
%\end{lverb} |
| 27551 |
% \begin{macrocode} |
| 27552 |
\def\XINT_iiprd_loop #1#2\xint:#3% |
| 27553 |
{% |
| 27554 |
\expandafter\XINT_iiprd_loop_a |
| 27555 |
\expandafter#1\romannumeral`&&@#3\xint:#2\xint:\xint: |
| 27556 |
}% |
| 27557 |
\def\XINT_iiprd_loop_a #1#2% |
| 27558 |
{% |
| 27559 |
\xint_gob_til_^ #2\XINT_iiprd_loop_end ^% |
| 27560 |
\xint_gob_til_zero #2\XINT_iiprd_zero 0% |
| 27561 |
\expandafter\XINT_iiprd_loop\romannumeral0\XINT_mul_nfork #1#2% |
| 27562 |
}% |
| 27563 |
% \end{macrocode} |
| 27564 |
%\begin{lverb} |
| 27565 |
% see previous comment! |
| 27566 |
%\end{lverb} |
| 27567 |
% \begin{macrocode} |
| 27568 |
\def\XINT_iiprd_loop_end ^#1\XINT_mul_nfork #2#3\xint:#4\xint:\xint:{ #2#4}% |
| 27569 |
% \end{macrocode} |
| 27570 |
% \subsection{\csh{xintiiSquareRoot}} |
| 27571 |
%\begin{lverb} |
| 27572 |
% First done with 1.08. |
| 27573 |
% |
| 27574 |
% 1.1 added \xintiiSquareRoot. |
| 27575 |
% |
| 27576 |
% 1.1a added \xintiiSqrtR. |
| 27577 |
% |
| 27578 |
% 1.2f (2016/03/01-02-03) has rewritten the implementation, the underlying |
| 27579 |
% mathematics remaining about the same. The routine is much faster for inputs |
| 27580 |
% having up to 16 digits (because it does it all with \numexpr directly now), |
| 27581 |
% and also much faster for very long inputs (because it now fetches only the |
| 27582 |
% needed new digits after the first 16 (or 17) ones, via the geometric |
| 27583 |
% sequence 16, then 32, then 64, etc...; earlier version did the computations |
| 27584 |
% with all remaining digits after a suitable starting point with correct 4 or |
| 27585 |
% 5 leading digits). Note however that the fetching of tokens is via |
| 27586 |
% intrinsically O(N^2) macros, hence inevitably inputs with thousands of |
| 27587 |
% digits start being treated less well. |
| 27588 |
% |
| 27589 |
% Actually there is some room for improvements, one could prepare better |
| 27590 |
% input X for the upcoming treatment of fetching its digits by 16, then 32, |
| 27591 |
% then 64, etc... |
| 27592 |
% |
| 27593 |
% Incidently, as \xintiiSqrt uses subtraction and subtraction was broken from |
| 27594 |
% 1.2 to 1.2c, then for another reason from 1.2c to 1.2f, it could |
| 27595 |
% get wrong in certain (relatively rare) cases. There was also a bug that |
| 27596 |
% made it unneedlessly slow for odd number of digits on input. |
| 27597 |
% |
| 27598 |
% 1.2f also modifies \xintFloatSqrt in xintfrac.sty which now has more |
| 27599 |
% code in common with here and benefits from the same speed improvements. |
| 27600 |
% |
| 27601 |
% 1.2k belatedly corrects the output to {1}{1} and not 11 when input is zero. |
| 27602 |
% As braces are used in all other cases they should have been used here too. |
| 27603 |
% |
| 27604 |
% Also, 1.2k adds an \xintiSqrtR macro, for coherence as \xintiSqrt is |
| 27605 |
% defined (and mentioned in user manual.) |
| 27606 |
% |
| 27607 |
%\end{lverb} |
| 27608 |
% |
| 27609 |
% \begin{macrocode} |
| 27610 |
\def\xintiiSquareRoot {\romannumeral0\xintiisquareroot }% |
| 27611 |
\def\xintiisquareroot #1{\expandafter\XINT_sqrt_checkin\romannumeral`&&@#1\xint:}% |
| 27612 |
\def\XINT_sqrt_checkin #1% |
| 27613 |
{% |
| 27614 |
\xint_UDzerominusfork |
| 27615 |
#1-\XINT_sqrt_iszero |
| 27616 |
0#1\XINT_sqrt_isneg |
| 27617 |
0-\XINT_sqrt |
| 27618 |
\krof #1% |
| 27619 |
}% |
| 27620 |
\def\XINT_sqrt_iszero #1\xint:{{1}{1}}% |
| 27621 |
\def\XINT_sqrt_isneg #1\xint: |
| 27622 |
{\XINT_signalcondition{InvalidOperation}% |
| 27623 |
{Square root of negative: #1.}{}{{0}{0}}}% |
| 27624 |
\def\XINT_sqrt #1\xint: |
| 27625 |
{% |
| 27626 |
\expandafter\XINT_sqrt_start\romannumeral0\xintlength {#1}.#1.% |
| 27627 |
}% |
| 27628 |
\def\XINT_sqrt_start #1.% |
| 27629 |
{% |
| 27630 |
\ifnum #1<\xint_c_x\xint_dothis\XINT_sqrt_small_a\fi |
| 27631 |
\xint_orthat\XINT_sqrt_big_a #1.% |
| 27632 |
}% |
| 27633 |
\def\XINT_sqrt_small_a #1.{\XINT_sqrt_a #1.\XINT_sqrt_small_d }% |
| 27634 |
\def\XINT_sqrt_big_a #1.{\XINT_sqrt_a #1.\XINT_sqrt_big_d }% |
| 27635 |
\def\XINT_sqrt_a #1.% |
| 27636 |
{% |
| 27637 |
\ifodd #1 |
| 27638 |
\expandafter\XINT_sqrt_bO |
| 27639 |
\else |
| 27640 |
\expandafter\XINT_sqrt_bE |
| 27641 |
\fi |
| 27642 |
#1.% |
| 27643 |
}% |
| 27644 |
\def\XINT_sqrt_bE #1.#2#3#4% |
| 27645 |
{% |
| 27646 |
\XINT_sqrt_c {#3#4}#2{#1}#3#4% |
| 27647 |
}% |
| 27648 |
\def\XINT_sqrt_bO #1.#2#3% |
| 27649 |
{% |
| 27650 |
\XINT_sqrt_c #3#2{#1}#3% |
| 27651 |
}% |
| 27652 |
\def\XINT_sqrt_c #1#2% |
| 27653 |
{% |
| 27654 |
\expandafter #2% |
| 27655 |
\the\numexpr \ifnum #1>\xint_c_ii |
| 27656 |
\ifnum #1>\xint_c_vi |
| 27657 |
\ifnum #1>12 \ifnum #1>20 \ifnum #1>30 |
| 27658 |
\ifnum #1>42 \ifnum #1>56 \ifnum #1>72 |
| 27659 |
\ifnum #1>90 |
| 27660 |
10\else 9\fi \else 8\fi \else 7\fi \else 6\fi \else 5\fi |
| 27661 |
\else 4\fi \else 3\fi \else 2\fi \else 1\fi .% |
| 27662 |
}% |
| 27663 |
\def\XINT_sqrt_small_d #1.#2% |
| 27664 |
{% |
| 27665 |
\expandafter\XINT_sqrt_small_e |
| 27666 |
\the\numexpr #1\ifcase \numexpr #2/\xint_c_ii-\xint_c_i\relax |
| 27667 |
\or 0\or 00\or 000\or 0000\fi .% |
| 27668 |
}% |
| 27669 |
\def\XINT_sqrt_small_e #1.#2.% |
| 27670 |
{% |
| 27671 |
\expandafter\XINT_sqrt_small_ea\the\numexpr #1*#1-#2.#1.% |
| 27672 |
}% |
| 27673 |
\def\XINT_sqrt_small_ea #1% |
| 27674 |
{% |
| 27675 |
\if0#1\xint_dothis\XINT_sqrt_small_ez\fi |
| 27676 |
\if-#1\xint_dothis\XINT_sqrt_small_eb\fi |
| 27677 |
\xint_orthat\XINT_sqrt_small_f #1% |
| 27678 |
}% |
| 27679 |
\def\XINT_sqrt_small_ez 0.#1.{\expandafter{\the\numexpr#1+\xint_c_i |
| 27680 |
\expandafter}\expandafter{\the\numexpr #1*\xint_c_ii+\xint_c_i}}% |
| 27681 |
\def\XINT_sqrt_small_eb -#1.#2.% |
| 27682 |
{% |
| 27683 |
\expandafter\XINT_sqrt_small_ec \the\numexpr |
| 27684 |
(#1-\xint_c_i+#2)/(\xint_c_ii*#2).#1.#2.% |
| 27685 |
}% |
| 27686 |
\def\XINT_sqrt_small_ec #1.#2.#3.% |
| 27687 |
{% |
| 27688 |
\expandafter\XINT_sqrt_small_f \the\numexpr |
| 27689 |
-#2+\xint_c_ii*#3*#1+#1*#1\expandafter.\the\numexpr #3+#1.% |
| 27690 |
}% |
| 27691 |
\def\XINT_sqrt_small_f #1.#2.% |
| 27692 |
{% |
| 27693 |
\expandafter\XINT_sqrt_small_g |
| 27694 |
\the\numexpr (#1+#2)/(\xint_c_ii*#2)-\xint_c_i.#1.#2.% |
| 27695 |
}% |
| 27696 |
\def\XINT_sqrt_small_g #1#2.% |
| 27697 |
{% |
| 27698 |
\if 0#1% |
| 27699 |
\expandafter\XINT_sqrt_small_end |
| 27700 |
\else |
| 27701 |
\expandafter\XINT_sqrt_small_h |
| 27702 |
\fi |
| 27703 |
#1#2.% |
| 27704 |
}% |
| 27705 |
\def\XINT_sqrt_small_h #1.#2.#3.% |
| 27706 |
{% |
| 27707 |
\expandafter\XINT_sqrt_small_f |
| 27708 |
\the\numexpr #2-\xint_c_ii*#1*#3+#1*#1\expandafter.% |
| 27709 |
\the\numexpr #3-#1.% |
| 27710 |
}% |
| 27711 |
\def\XINT_sqrt_small_end #1.#2.#3.{{#3}{#2}}% |
| 27712 |
\def\XINT_sqrt_big_d #1.#2% |
| 27713 |
{% |
| 27714 |
\ifodd #2 \xint_dothis{\expandafter\XINT_sqrt_big_eO}\fi |
| 27715 |
\xint_orthat{\expandafter\XINT_sqrt_big_eE}% |
| 27716 |
\the\numexpr (#2-\xint_c_i)/\xint_c_ii.#1;% |
| 27717 |
}% |
| 27718 |
\def\XINT_sqrt_big_eE #1;#2#3#4#5#6#7#8#9% |
| 27719 |
{% |
| 27720 |
\XINT_sqrt_big_eE_a #1;{#2#3#4#5#6#7#8#9}% |
| 27721 |
}% |
| 27722 |
\def\XINT_sqrt_big_eE_a #1.#2;#3% |
| 27723 |
{% |
| 27724 |
\expandafter\XINT_sqrt_bigormed_f |
| 27725 |
\romannumeral0\XINT_sqrt_small_e #2000.#3.#1;% |
| 27726 |
}% |
| 27727 |
\def\XINT_sqrt_big_eO #1;#2#3#4#5#6#7#8#9% |
| 27728 |
{% |
| 27729 |
\XINT_sqrt_big_eO_a #1;{#2#3#4#5#6#7#8#9}% |
| 27730 |
}% |
| 27731 |
\def\XINT_sqrt_big_eO_a #1.#2;#3#4% |
| 27732 |
{% |
| 27733 |
\expandafter\XINT_sqrt_bigormed_f |
| 27734 |
\romannumeral0\XINT_sqrt_small_e #20000.#3#4.#1;% |
| 27735 |
}% |
| 27736 |
\def\XINT_sqrt_bigormed_f #1#2#3;% |
| 27737 |
{% |
| 27738 |
\ifnum#3<\xint_c_ix |
| 27739 |
\xint_dothis {\csname XINT_sqrt_med_f\romannumeral#3\endcsname}% |
| 27740 |
\fi |
| 27741 |
\xint_orthat\XINT_sqrt_big_f #1.#2.#3;% |
| 27742 |
}% |
| 27743 |
\def\XINT_sqrt_med_fv {\XINT_sqrt_med_fa .}% |
| 27744 |
\def\XINT_sqrt_med_fvi {\XINT_sqrt_med_fa 0.}% |
| 27745 |
\def\XINT_sqrt_med_fvii {\XINT_sqrt_med_fa 00.}% |
| 27746 |
\def\XINT_sqrt_med_fviii{\XINT_sqrt_med_fa 000.}% |
| 27747 |
\def\XINT_sqrt_med_fa #1.#2.#3.#4;% |
| 27748 |
{% |
| 27749 |
\expandafter\XINT_sqrt_med_fb |
| 27750 |
\the\numexpr (#30#1-5#1)/(\xint_c_ii*#2).#1.#2.#3.% |
| 27751 |
}% |
| 27752 |
\def\XINT_sqrt_med_fb #1.#2.#3.#4.#5.% |
| 27753 |
{% |
| 27754 |
\expandafter\XINT_sqrt_small_ea |
| 27755 |
\the\numexpr (#40#2-\xint_c_ii*#3*#1)*10#2+(#1*#1-#5)\expandafter.% |
| 27756 |
\the\numexpr #30#2-#1.% |
| 27757 |
}% |
| 27758 |
\def\XINT_sqrt_big_f #1;#2#3#4#5#6#7#8#9% |
| 27759 |
{% |
| 27760 |
\XINT_sqrt_big_fa #1;{#2#3#4#5#6#7#8#9}% |
| 27761 |
}% |
| 27762 |
\def\XINT_sqrt_big_fa #1.#2.#3;#4% |
| 27763 |
{% |
| 27764 |
\expandafter\XINT_sqrt_big_ga |
| 27765 |
\the\numexpr #3-\xint_c_viii\expandafter.% |
| 27766 |
\romannumeral0\XINT_sqrt_med_fa 000.#1.#2.;#4.% |
| 27767 |
}% |
| 27768 |
% \end{macrocode} |
| 27769 |
%\begin{lverb} |
| 27770 |
% |
| 27771 |
%\end{lverb} |
| 27772 |
% \begin{macrocode} |
| 27773 |
\def\XINT_sqrt_big_ga #1.#2#3% |
| 27774 |
{% |
| 27775 |
\ifnum #1>\xint_c_viii |
| 27776 |
\expandafter\XINT_sqrt_big_gb\else |
| 27777 |
\expandafter\XINT_sqrt_big_ka |
| 27778 |
\fi #1.#3.#2.% |
| 27779 |
}% |
| 27780 |
\def\XINT_sqrt_big_gb #1.#2.#3.% |
| 27781 |
{% |
| 27782 |
\expandafter\XINT_sqrt_big_gc |
| 27783 |
\the\numexpr (\xint_c_ii*#2-\xint_c_i)*\xint_c_x^viii/(\xint_c_iv*#3).% |
| 27784 |
#3.#2.#1;% |
| 27785 |
}% |
| 27786 |
\def\XINT_sqrt_big_gc #1.#2.#3.% |
| 27787 |
{% |
| 27788 |
\expandafter\XINT_sqrt_big_gd |
| 27789 |
\romannumeral0\xintiiadd |
| 27790 |
{\xintiiSub {#300000000}{\xintDouble{\xintiiMul{#2}{#1}}}00000000}% |
| 27791 |
{\xintiiSqr {#1}}.% |
| 27792 |
\romannumeral0\xintiisub{#200000000}{#1}.% |
| 27793 |
}% |
| 27794 |
\def\XINT_sqrt_big_gd #1.#2.% |
| 27795 |
{% |
| 27796 |
\expandafter\XINT_sqrt_big_ge #2.#1.% |
| 27797 |
}% |
| 27798 |
\def\XINT_sqrt_big_ge #1;#2#3#4#5#6#7#8#9% |
| 27799 |
{\XINT_sqrt_big_gf #1.#2#3#4#5#6#7#8#9;}% |
| 27800 |
\def\XINT_sqrt_big_gf #1;#2#3#4#5#6#7#8#9% |
| 27801 |
{\XINT_sqrt_big_gg #1#2#3#4#5#6#7#8#9.}% |
| 27802 |
\def\XINT_sqrt_big_gg #1.#2.#3.#4.% |
| 27803 |
{% |
| 27804 |
\expandafter\XINT_sqrt_big_gloop |
| 27805 |
\expandafter\xint_c_xvi\expandafter.% |
| 27806 |
\the\numexpr #3-\xint_c_viii\expandafter.% |
| 27807 |
\romannumeral0\xintiisub {#2}{\xintiNum{#4}}.#1.% |
| 27808 |
}% |
| 27809 |
\def\XINT_sqrt_big_gloop #1.#2.% |
| 27810 |
{% |
| 27811 |
\unless\ifnum #1<#2 \xint_dothis\XINT_sqrt_big_ka \fi |
| 27812 |
\xint_orthat{\XINT_sqrt_big_gi #1.}#2.% |
| 27813 |
}% |
| 27814 |
\def\XINT_sqrt_big_gi #1.% |
| 27815 |
{% |
| 27816 |
\expandafter\XINT_sqrt_big_gj\romannumeral\xintreplicate{#1}0.#1.% |
| 27817 |
}% |
| 27818 |
\def\XINT_sqrt_big_gj #1.#2.#3.#4.#5.% |
| 27819 |
{% |
| 27820 |
\expandafter\XINT_sqrt_big_gk |
| 27821 |
\romannumeral0\xintiidivision {#4#1}% |
| 27822 |
{\XINT_dbl #5\xint_bye2345678\xint_bye*\xint_c_ii\relax}.% |
| 27823 |
#1.#5.#2.#3.% |
| 27824 |
}% |
| 27825 |
\def\XINT_sqrt_big_gk #1#2.#3.#4.% |
| 27826 |
{% |
| 27827 |
\expandafter\XINT_sqrt_big_gl |
| 27828 |
\romannumeral0\xintiiadd {#2#3}{\xintiiSqr{#1}}.% |
| 27829 |
\romannumeral0\xintiisub {#4#3}{#1}.% |
| 27830 |
}% |
| 27831 |
\def\XINT_sqrt_big_gl #1.#2.% |
| 27832 |
{% |
| 27833 |
\expandafter\XINT_sqrt_big_gm #2.#1.% |
| 27834 |
}% |
| 27835 |
\def\XINT_sqrt_big_gm #1.#2.#3.#4.#5.% |
| 27836 |
{% |
| 27837 |
\expandafter\XINT_sqrt_big_gn |
| 27838 |
\romannumeral0\XINT_split_fromleft\xint_c_ii*#3.#5\xint_bye2345678\xint_bye..% |
| 27839 |
#1.#2.#3.#4.% |
| 27840 |
}% |
| 27841 |
\def\XINT_sqrt_big_gn #1.#2.#3.#4.#5.#6.% |
| 27842 |
{% |
| 27843 |
\expandafter\XINT_sqrt_big_gloop |
| 27844 |
\the\numexpr \xint_c_ii*#5\expandafter.% |
| 27845 |
\the\numexpr #6-#5\expandafter.% |
| 27846 |
\romannumeral0\xintiisub{#4}{\xintiNum{#1}}.#3.#2.% |
| 27847 |
}% |
| 27848 |
\def\XINT_sqrt_big_ka #1.#2.#3.#4.% |
| 27849 |
{% |
| 27850 |
\expandafter\XINT_sqrt_big_kb |
| 27851 |
\romannumeral0\XINT_dsx_addzeros {#1}#3;.% |
| 27852 |
\romannumeral0\xintiisub |
| 27853 |
{\XINT_dsx_addzerosnofuss {\xint_c_ii*#1}#2;}% |
| 27854 |
{\xintiNum{#4}}.% |
| 27855 |
}% |
| 27856 |
\def\XINT_sqrt_big_kb #1.#2.% |
| 27857 |
{% |
| 27858 |
\expandafter\XINT_sqrt_big_kc #2.#1.% |
| 27859 |
}% |
| 27860 |
\def\XINT_sqrt_big_kc #1% |
| 27861 |
{% |
| 27862 |
\if0#1\xint_dothis\XINT_sqrt_big_kz\fi |
| 27863 |
\xint_orthat\XINT_sqrt_big_kloop #1% |
| 27864 |
}% |
| 27865 |
\def\XINT_sqrt_big_kz 0.#1.% |
| 27866 |
{% |
| 27867 |
\expandafter\XINT_sqrt_big_kend |
| 27868 |
\romannumeral0% |
| 27869 |
\xintinc{\XINT_dbl#1\xint_bye2345678\xint_bye*\xint_c_ii\relax}.#1.% |
| 27870 |
}% |
| 27871 |
\def\XINT_sqrt_big_kend #1.#2.% |
| 27872 |
{% |
| 27873 |
\expandafter{\romannumeral0\xintinc{#2}}{#1}% |
| 27874 |
}% |
| 27875 |
\def\XINT_sqrt_big_kloop #1.#2.% |
| 27876 |
{% |
| 27877 |
\expandafter\XINT_sqrt_big_ke |
| 27878 |
\romannumeral0\xintiidivision{#1}% |
| 27879 |
{\romannumeral0\XINT_dbl #2\xint_bye2345678\xint_bye*\xint_c_ii\relax}{#2}% |
| 27880 |
}% |
| 27881 |
\def\XINT_sqrt_big_ke #1% |
| 27882 |
{% |
| 27883 |
\if0\XINT_Sgn #1\xint: |
| 27884 |
\expandafter \XINT_sqrt_big_end |
| 27885 |
\else \expandafter \XINT_sqrt_big_kf |
| 27886 |
\fi {#1}% |
| 27887 |
}% |
| 27888 |
\def\XINT_sqrt_big_kf #1#2#3% |
| 27889 |
{% |
| 27890 |
\expandafter\XINT_sqrt_big_kg |
| 27891 |
\romannumeral0\xintiisub {#3}{#1}.% |
| 27892 |
\romannumeral0\xintiiadd {#2}{\xintiiSqr {#1}}.% |
| 27893 |
}% |
| 27894 |
\def\XINT_sqrt_big_kg #1.#2.% |
| 27895 |
{% |
| 27896 |
\expandafter\XINT_sqrt_big_kloop #2.#1.% |
| 27897 |
}% |
| 27898 |
\def\XINT_sqrt_big_end #1#2#3{{#3}{#2}}% |
| 27899 |
% \end{macrocode} |
| 27900 |
% \subsection{\csh{xintiiSqrt}, \csh{xintiiSqrtR}} |
| 27901 |
% \begin{macrocode} |
| 27902 |
\def\xintiiSqrt {\romannumeral0\xintiisqrt }% |
| 27903 |
\def\xintiisqrt {\expandafter\XINT_sqrt_post\romannumeral0\xintiisquareroot }% |
| 27904 |
\def\XINT_sqrt_post #1#2{\XINT_dec #1\XINT_dec_bye234567890\xint_bye}% |
| 27905 |
\def\xintiiSqrtR {\romannumeral0\xintiisqrtr }% |
| 27906 |
\def\xintiisqrtr {\expandafter\XINT_sqrtr_post\romannumeral0\xintiisquareroot }% |
| 27907 |
% \end{macrocode} |
| 27908 |
%\begin{lverb} |
| 27909 |
% N = (#1)^2 - #2 avec #1 le plus petit possible et #2>0 (hence #2<2*#1). |
| 27910 |
% (#1-.5)^2=#1^2-#1+.25=N+#2-#1+.25. Si 0<#2<#1, <= N-0.75<N, donc rounded->#1 |
| 27911 |
% si #2>=#1, (#1-.5)^2>=N+.25>N, donc rounded->#1-1. |
| 27912 |
%\end{lverb} |
| 27913 |
% \begin{macrocode} |
| 27914 |
\def\XINT_sqrtr_post #1#2% |
| 27915 |
{\xintiiifLt {#2}{#1}{ #1}{\XINT_dec #1\XINT_dec_bye234567890\xint_bye}}% |
| 27916 |
% \end{macrocode} |
| 27917 |
% \subsection{\csh{xintiiBinomial}} |
| 27918 |
%\begin{lverb} |
| 27919 |
% 2015/11/28-29 for 1.2f. |
| 27920 |
% |
| 27921 |
% 2016/11/19 for 1.2h: I truly can't understand why I hard-coded last |
| 27922 |
% year an error-message for arguments outside of the range for binomial |
| 27923 |
% formula. Naturally there should be no error but a rather a 0 return |
| 27924 |
% value for binomial(x,y), if y<0 or x<y ! |
| 27925 |
% |
| 27926 |
% I really lack some kind of infinity or NaN value. |
| 27927 |
%\end{lverb} |
| 27928 |
% \begin{macrocode} |
| 27929 |
\def\xintiiBinomial {\romannumeral0\xintiibinomial }% |
| 27930 |
\def\xintiibinomial #1#2% |
| 27931 |
{% |
| 27932 |
\expandafter\XINT_binom_pre\the\numexpr #1\expandafter.\the\numexpr #2.% |
| 27933 |
}% |
| 27934 |
\def\XINT_binom_pre #1.#2.% |
| 27935 |
{% |
| 27936 |
\expandafter\XINT_binom_fork \the\numexpr#1-#2.#2.#1.% |
| 27937 |
}% |
| 27938 |
% \end{macrocode} |
| 27939 |
%\begin{lverb} |
| 27940 |
% k.x-k.x. I hesitated to restrict maximal allowed value of x to 10000. |
| 27941 |
% Finally I don't. But due to using small multiplication and small division, x |
| 27942 |
% must have at most eight digits. If x>=2^31 an arithmetic overflow error will |
| 27943 |
% have happened already. |
| 27944 |
%\end{lverb} |
| 27945 |
% \begin{macrocode} |
| 27946 |
\def\XINT_binom_fork #1#2.#3#4.#5#6.% |
| 27947 |
{% |
| 27948 |
\if-#5\xint_dothis{\XINT_signalcondition{InvalidOperation}% |
| 27949 |
{Binomial with negative first argument: #5#6.}{}{ 0}}\fi |
| 27950 |
\if-#1\xint_dothis{ 0}\fi |
| 27951 |
\if-#3\xint_dothis{ 0}\fi |
| 27952 |
\if0#1\xint_dothis{ 1}\fi |
| 27953 |
\if0#3\xint_dothis{ 1}\fi |
| 27954 |
\ifnum #5#6>\xint_c_x^viii_mone\xint_dothis |
| 27955 |
{\XINT_signalcondition{InvalidOperation}% |
| 27956 |
{Binomial with too large argument: #5#6 >= 10^8.}{}{ 0}}\fi |
| 27957 |
\ifnum #1#2>#3#4 \xint_dothis{\XINT_binom_a #1#2.#3#4.}\fi |
| 27958 |
\xint_orthat{\XINT_binom_a #3#4.#1#2.}% |
| 27959 |
}% |
| 27960 |
% \end{macrocode} |
| 27961 |
%\begin{lverb} |
| 27962 |
% x-k.k. avec 0<k<x, k<=x-k. Les divisions produiront en extra après le |
| 27963 |
% quotient un terminateur 1!\Z!0!. On va procéder par petite multiplication |
| 27964 |
% suivie par petite division. Donc ici on met le 1!\Z!0! pour amorcer. |
| 27965 |
% |
| 27966 |
% Le \xint_bye!2!3!4!5!6!7!8!9!\xint_bye\xint_c_i\relax est le terminateur pour le |
| 27967 |
% \XINT_unsep_cuzsmall final. |
| 27968 |
%\end{lverb} |
| 27969 |
% \begin{macrocode} |
| 27970 |
\def\XINT_binom_a #1.#2.% |
| 27971 |
{% |
| 27972 |
\expandafter\XINT_binom_b\the\numexpr \xint_c_i+#1.1.#2.100000001!1!;!0!% |
| 27973 |
}% |
| 27974 |
% \end{macrocode} |
| 27975 |
%\begin{lverb} |
| 27976 |
% y=x-k+1.j=1.k. On va évaluer par y/1*(y+1)/2*(y+2)/3 etc... On essaie |
| 27977 |
% de regrouper de manière à utiliser au mieux \numexpr. On peut aller jusqu'à |
| 27978 |
% x=10000 car 9999*10000<10^8. 463*464*465=99896880, 98*99*100*101=97990200. |
| 27979 |
% On va vérifier à chaque étape si on dépasse un seuil. Le style de |
| 27980 |
% l'implémentation diffère de celui que j'avais utilisé pour \xintiiFac. On |
| 27981 |
% pourrait tout-à-fait avoir une verybigloop, mais bon. Je rajoute aussi un |
| 27982 |
% verysmall. Le traitement est un peu différent pour elle afin d'aller jusqu'à |
| 27983 |
% x=29 (et pas seulement 26 si je suivais le modèle des autres, mais je veux |
| 27984 |
% pouvoir faire binomial(29,1), binomial(29,2), ... en vsmall). |
| 27985 |
%\end{lverb} |
| 27986 |
% \begin{macrocode} |
| 27987 |
\def\XINT_binom_b #1.% |
| 27988 |
{% |
| 27989 |
\ifnum #1>9999 \xint_dothis\XINT_binom_vbigloop \fi |
| 27990 |
\ifnum #1>463 \xint_dothis\XINT_binom_bigloop \fi |
| 27991 |
\ifnum #1>98 \xint_dothis\XINT_binom_medloop \fi |
| 27992 |
\ifnum #1>29 \xint_dothis\XINT_binom_smallloop \fi |
| 27993 |
\xint_orthat\XINT_binom_vsmallloop #1.% |
| 27994 |
}% |
| 27995 |
% \end{macrocode} |
| 27996 |
%\begin{lverb} |
| 27997 |
% y.j.k. Au départ on avait x-k+1.1.k. Ensuite on a des blocs 1<8d>! |
| 27998 |
% donnant le résultat intermédiaire, dans l'ordre, et à la fin on a 1!1;!0!. |
| 27999 |
% Dans smallloop on peut prendre 4 par 4. |
| 28000 |
%\end{lverb} |
| 28001 |
% \begin{macrocode} |
| 28002 |
\def\XINT_binom_smallloop #1.#2.#3.% |
| 28003 |
{% |
| 28004 |
\ifcase\numexpr #3-#2\relax |
| 28005 |
\expandafter\XINT_binom_end_ |
| 28006 |
\or \expandafter\XINT_binom_end_i |
| 28007 |
\or \expandafter\XINT_binom_end_ii |
| 28008 |
\or \expandafter\XINT_binom_end_iii |
| 28009 |
\else\expandafter\XINT_binom_smallloop_a |
| 28010 |
\fi #1.#2.#3.% |
| 28011 |
}% |
| 28012 |
% \end{macrocode} |
| 28013 |
%\begin{lverb} |
| 28014 |
% Ça m'ennuie un peu de reprendre les #1, #2, #3 ici. On a besoin de |
| 28015 |
% \numexpr pour \XINT_binom_div, mais de \romannumeral0 pour le unsep après |
| 28016 |
% \XINT_binom_mul. |
| 28017 |
%\end{lverb} |
| 28018 |
% \begin{macrocode} |
| 28019 |
\def\XINT_binom_smallloop_a #1.#2.#3.% |
| 28020 |
{% |
| 28021 |
\expandafter\XINT_binom_smallloop_b |
| 28022 |
\the\numexpr #1+\xint_c_iv\expandafter.% |
| 28023 |
\the\numexpr #2+\xint_c_iv\expandafter.% |
| 28024 |
\the\numexpr #3\expandafter.% |
| 28025 |
\the\numexpr\expandafter\XINT_binom_div |
| 28026 |
\the\numexpr #2*(#2+\xint_c_i)*(#2+\xint_c_ii)*(#2+\xint_c_iii)\expandafter |
| 28027 |
!\romannumeral0\expandafter\XINT_binom_mul |
| 28028 |
\the\numexpr #1*(#1+\xint_c_i)*(#1+\xint_c_ii)*(#1+\xint_c_iii)!% |
| 28029 |
}% |
| 28030 |
\def\XINT_binom_smallloop_b #1.% |
| 28031 |
{% |
| 28032 |
\ifnum #1>98 \expandafter\XINT_binom_medloop \else |
| 28033 |
\expandafter\XINT_binom_smallloop \fi #1.% |
| 28034 |
}% |
| 28035 |
% \end{macrocode} |
| 28036 |
%\begin{lverb} |
| 28037 |
% Ici on prend trois par trois. |
| 28038 |
%\end{lverb} |
| 28039 |
% \begin{macrocode} |
| 28040 |
\def\XINT_binom_medloop #1.#2.#3.% |
| 28041 |
{% |
| 28042 |
\ifcase\numexpr #3-#2\relax |
| 28043 |
\expandafter\XINT_binom_end_ |
| 28044 |
\or \expandafter\XINT_binom_end_i |
| 28045 |
\or \expandafter\XINT_binom_end_ii |
| 28046 |
\else\expandafter\XINT_binom_medloop_a |
| 28047 |
\fi #1.#2.#3.% |
| 28048 |
}% |
| 28049 |
\def\XINT_binom_medloop_a #1.#2.#3.% |
| 28050 |
{% |
| 28051 |
\expandafter\XINT_binom_medloop_b |
| 28052 |
\the\numexpr #1+\xint_c_iii\expandafter.% |
| 28053 |
\the\numexpr #2+\xint_c_iii\expandafter.% |
| 28054 |
\the\numexpr #3\expandafter.% |
| 28055 |
\the\numexpr\expandafter\XINT_binom_div |
| 28056 |
\the\numexpr #2*(#2+\xint_c_i)*(#2+\xint_c_ii)\expandafter |
| 28057 |
!\romannumeral0\expandafter\XINT_binom_mul |
| 28058 |
\the\numexpr #1*(#1+\xint_c_i)*(#1+\xint_c_ii)!% |
| 28059 |
}% |
| 28060 |
\def\XINT_binom_medloop_b #1.% |
| 28061 |
{% |
| 28062 |
\ifnum #1>463 \expandafter\XINT_binom_bigloop \else |
| 28063 |
\expandafter\XINT_binom_medloop \fi #1.% |
| 28064 |
}% |
| 28065 |
% \end{macrocode} |
| 28066 |
%\begin{lverb} |
| 28067 |
% Ici on prend deux par deux. |
| 28068 |
%\end{lverb} |
| 28069 |
% \begin{macrocode} |
| 28070 |
\def\XINT_binom_bigloop #1.#2.#3.% |
| 28071 |
{% |
| 28072 |
\ifcase\numexpr #3-#2\relax |
| 28073 |
\expandafter\XINT_binom_end_ |
| 28074 |
\or \expandafter\XINT_binom_end_i |
| 28075 |
\else\expandafter\XINT_binom_bigloop_a |
| 28076 |
\fi #1.#2.#3.% |
| 28077 |
}% |
| 28078 |
\def\XINT_binom_bigloop_a #1.#2.#3.% |
| 28079 |
{% |
| 28080 |
\expandafter\XINT_binom_bigloop_b |
| 28081 |
\the\numexpr #1+\xint_c_ii\expandafter.% |
| 28082 |
\the\numexpr #2+\xint_c_ii\expandafter.% |
| 28083 |
\the\numexpr #3\expandafter.% |
| 28084 |
\the\numexpr\expandafter\XINT_binom_div |
| 28085 |
\the\numexpr #2*(#2+\xint_c_i)\expandafter |
| 28086 |
!\romannumeral0\expandafter\XINT_binom_mul |
| 28087 |
\the\numexpr #1*(#1+\xint_c_i)!% |
| 28088 |
}% |
| 28089 |
\def\XINT_binom_bigloop_b #1.% |
| 28090 |
{% |
| 28091 |
\ifnum #1>9999 \expandafter\XINT_binom_vbigloop \else |
| 28092 |
\expandafter\XINT_binom_bigloop \fi #1.% |
| 28093 |
}% |
| 28094 |
% \end{macrocode} |
| 28095 |
%\begin{lverb} |
| 28096 |
% Et finalement un par un. |
| 28097 |
%\end{lverb} |
| 28098 |
% \begin{macrocode} |
| 28099 |
\def\XINT_binom_vbigloop #1.#2.#3.% |
| 28100 |
{% |
| 28101 |
\ifnum #3=#2 |
| 28102 |
\expandafter\XINT_binom_end_ |
| 28103 |
\else\expandafter\XINT_binom_vbigloop_a |
| 28104 |
\fi #1.#2.#3.% |
| 28105 |
}% |
| 28106 |
\def\XINT_binom_vbigloop_a #1.#2.#3.% |
| 28107 |
{% |
| 28108 |
\expandafter\XINT_binom_vbigloop |
| 28109 |
\the\numexpr #1+\xint_c_i\expandafter.% |
| 28110 |
\the\numexpr #2+\xint_c_i\expandafter.% |
| 28111 |
\the\numexpr #3\expandafter.% |
| 28112 |
\the\numexpr\expandafter\XINT_binom_div\the\numexpr #2\expandafter |
| 28113 |
!\romannumeral0\XINT_binom_mul #1!% |
| 28114 |
}% |
| 28115 |
% \end{macrocode} |
| 28116 |
%\begin{lverb} |
| 28117 |
% y.j.k. La partie very small. y est au plus 26 (non 29 mais retesté |
| 28118 |
% dans \XINT_binom_vsmallloop_a), et tous les binomial(29,n) sont <10^8. On |
| 28119 |
% peut donc faire y(y+1)(y+2)(y+3) et aussi il y a le fait que etex fait a*b/c |
| 28120 |
% en double precision. Pour ne pas bifurquer à la fin sur smallloop, si n=27, |
| 28121 |
% 27, ou 29 on procède un peu différemment des autres boucles. Si je testais |
| 28122 |
% aussi #1 après #3-#2 pour les autres il faudrait des terminaisons |
| 28123 |
% différentes. |
| 28124 |
%\end{lverb} |
| 28125 |
% \begin{macrocode} |
| 28126 |
\def\XINT_binom_vsmallloop #1.#2.#3.% |
| 28127 |
{% |
| 28128 |
\ifcase\numexpr #3-#2\relax |
| 28129 |
\expandafter\XINT_binom_vsmallend_ |
| 28130 |
\or \expandafter\XINT_binom_vsmallend_i |
| 28131 |
\or \expandafter\XINT_binom_vsmallend_ii |
| 28132 |
\or \expandafter\XINT_binom_vsmallend_iii |
| 28133 |
\else\expandafter\XINT_binom_vsmallloop_a |
| 28134 |
\fi #1.#2.#3.% |
| 28135 |
}% |
| 28136 |
\def\XINT_binom_vsmallloop_a #1.% |
| 28137 |
{% |
| 28138 |
\ifnum #1>26 \expandafter\XINT_binom_smallloop_a \else |
| 28139 |
\expandafter\XINT_binom_vsmallloop_b \fi #1.% |
| 28140 |
}% |
| 28141 |
\def\XINT_binom_vsmallloop_b #1.#2.#3.% |
| 28142 |
{% |
| 28143 |
\expandafter\XINT_binom_vsmallloop |
| 28144 |
\the\numexpr #1+\xint_c_iv\expandafter.% |
| 28145 |
\the\numexpr #2+\xint_c_iv\expandafter.% |
| 28146 |
\the\numexpr #3\expandafter.% |
| 28147 |
\the\numexpr \expandafter\XINT_binom_vsmallmuldiv |
| 28148 |
\the\numexpr #2*(#2+\xint_c_i)*(#2+\xint_c_ii)*(#2+\xint_c_iii)\expandafter |
| 28149 |
!\the\numexpr #1*(#1+\xint_c_i)*(#1+\xint_c_ii)*(#1+\xint_c_iii)!% |
| 28150 |
}% |
| 28151 |
\def\XINT_binom_mul #1!#21!;!0!% |
| 28152 |
{% |
| 28153 |
\expandafter\XINT_rev_nounsep\expandafter{\expandafter}% |
| 28154 |
\the\numexpr\expandafter\XINT_smallmul |
| 28155 |
\the\numexpr\xint_c_x^viii+#1\expandafter |
| 28156 |
!\romannumeral0\XINT_rev_nounsep {}1;!#2% |
| 28157 |
\R!\R!\R!\R!\R!\R!\R!\R!\W |
| 28158 |
\R!\R!\R!\R!\R!\R!\R!\R!\W |
| 28159 |
1;!% |
| 28160 |
}% |
| 28161 |
\def\XINT_binom_div #1!1;!% |
| 28162 |
{% |
| 28163 |
\expandafter\XINT_smalldivx_a |
| 28164 |
\the\numexpr #1/\xint_c_ii\expandafter\xint: |
| 28165 |
\the\numexpr \xint_c_x^viii+#1!% |
| 28166 |
}% |
| 28167 |
% \end{macrocode} |
| 28168 |
%\begin{lverb} |
| 28169 |
% Vaguement envisagé d'éviter le 10^8+ mais bon. |
| 28170 |
%\end{lverb} |
| 28171 |
% \begin{macrocode} |
| 28172 |
\def\XINT_binom_vsmallmuldiv #1!#2!1#3!{\xint_c_x^viii+#2*#3/#1!}% |
| 28173 |
% \end{macrocode} |
| 28174 |
%\begin{lverb} |
| 28175 |
% On a des terminaisons communes aux trois situations small, med, big, |
| 28176 |
% et on est sûr de pouvoir faire les multiplications dans \numexpr, car on |
| 28177 |
% vient ici *après* avoir comparé à 9999 ou 463 ou 98. |
| 28178 |
%\end{lverb} |
| 28179 |
% \begin{macrocode} |
| 28180 |
\def\XINT_binom_end_iii #1.#2.#3.% |
| 28181 |
{% |
| 28182 |
\expandafter\XINT_binom_finish |
| 28183 |
\the\numexpr\expandafter\XINT_binom_div |
| 28184 |
\the\numexpr #2*(#2+\xint_c_i)*(#2+\xint_c_ii)*(#2+\xint_c_iii)\expandafter |
| 28185 |
!\romannumeral0\expandafter\XINT_binom_mul |
| 28186 |
\the\numexpr #1*(#1+\xint_c_i)*(#1+\xint_c_ii)*(#1+\xint_c_iii)!% |
| 28187 |
}% |
| 28188 |
\def\XINT_binom_end_ii #1.#2.#3.% |
| 28189 |
{% |
| 28190 |
\expandafter\XINT_binom_finish |
| 28191 |
\the\numexpr\expandafter\XINT_binom_div |
| 28192 |
\the\numexpr #2*(#2+\xint_c_i)*(#2+\xint_c_ii)\expandafter |
| 28193 |
!\romannumeral0\expandafter\XINT_binom_mul |
| 28194 |
\the\numexpr #1*(#1+\xint_c_i)*(#1+\xint_c_ii)!% |
| 28195 |
}% |
| 28196 |
\def\XINT_binom_end_i #1.#2.#3.% |
| 28197 |
{% |
| 28198 |
\expandafter\XINT_binom_finish |
| 28199 |
\the\numexpr\expandafter\XINT_binom_div |
| 28200 |
\the\numexpr #2*(#2+\xint_c_i)\expandafter |
| 28201 |
!\romannumeral0\expandafter\XINT_binom_mul |
| 28202 |
\the\numexpr #1*(#1+\xint_c_i)!% |
| 28203 |
}% |
| 28204 |
\def\XINT_binom_end_ #1.#2.#3.% |
| 28205 |
{% |
| 28206 |
\expandafter\XINT_binom_finish |
| 28207 |
\the\numexpr\expandafter\XINT_binom_div\the\numexpr #2\expandafter |
| 28208 |
!\romannumeral0\XINT_binom_mul #1!% |
| 28209 |
}% |
| 28210 |
\def\XINT_binom_finish #1;!0!% |
| 28211 |
{\XINT_unsep_cuzsmall #1\xint_bye!2!3!4!5!6!7!8!9!\xint_bye\xint_c_i\relax}% |
| 28212 |
% \end{macrocode} |
| 28213 |
%\begin{lverb} |
| 28214 |
% Duplication de code seulement pour la boucle avec très |
| 28215 |
% petits coeffs, mais en plus on fait au maximum des possibilités. (on |
| 28216 |
% pourrait tester plus le résultat déjà obtenu). |
| 28217 |
%\end{lverb} |
| 28218 |
% \begin{macrocode} |
| 28219 |
\def\XINT_binom_vsmallend_iii #1.% |
| 28220 |
{% |
| 28221 |
\ifnum #1>26 \expandafter\XINT_binom_end_iii \else |
| 28222 |
\expandafter\XINT_binom_vsmallend_iiib \fi #1.% |
| 28223 |
}% |
| 28224 |
\def\XINT_binom_vsmallend_iiib #1.#2.#3.% |
| 28225 |
{% |
| 28226 |
\expandafter\XINT_binom_vsmallfinish |
| 28227 |
\the\numexpr \expandafter\XINT_binom_vsmallmuldiv |
| 28228 |
\the\numexpr #2*(#2+\xint_c_i)*(#2+\xint_c_ii)*(#2+\xint_c_iii)\expandafter |
| 28229 |
!\the\numexpr #1*(#1+\xint_c_i)*(#1+\xint_c_ii)*(#1+\xint_c_iii)!% |
| 28230 |
}% |
| 28231 |
\def\XINT_binom_vsmallend_ii #1.% |
| 28232 |
{% |
| 28233 |
\ifnum #1>27 \expandafter\XINT_binom_end_ii \else |
| 28234 |
\expandafter\XINT_binom_vsmallend_iib \fi #1.% |
| 28235 |
}% |
| 28236 |
\def\XINT_binom_vsmallend_iib #1.#2.#3.% |
| 28237 |
{% |
| 28238 |
\expandafter\XINT_binom_vsmallfinish |
| 28239 |
\the\numexpr \expandafter\XINT_binom_vsmallmuldiv |
| 28240 |
\the\numexpr #2*(#2+\xint_c_i)*(#2+\xint_c_ii)\expandafter |
| 28241 |
!\the\numexpr #1*(#1+\xint_c_i)*(#1+\xint_c_ii)!% |
| 28242 |
}% |
| 28243 |
\def\XINT_binom_vsmallend_i #1.% |
| 28244 |
{% |
| 28245 |
\ifnum #1>28 \expandafter\XINT_binom_end_i \else |
| 28246 |
\expandafter\XINT_binom_vsmallend_ib \fi #1.% |
| 28247 |
}% |
| 28248 |
\def\XINT_binom_vsmallend_ib #1.#2.#3.% |
| 28249 |
{% |
| 28250 |
\expandafter\XINT_binom_vsmallfinish |
| 28251 |
\the\numexpr \expandafter\XINT_binom_vsmallmuldiv |
| 28252 |
\the\numexpr #2*(#2+\xint_c_i)\expandafter |
| 28253 |
!\the\numexpr #1*(#1+\xint_c_i)!% |
| 28254 |
}% |
| 28255 |
\def\XINT_binom_vsmallend_ #1.% |
| 28256 |
{% |
| 28257 |
\ifnum #1>29 \expandafter\XINT_binom_end_ \else |
| 28258 |
\expandafter\XINT_binom_vsmallend_b \fi #1.% |
| 28259 |
}% |
| 28260 |
\def\XINT_binom_vsmallend_b #1.#2.#3.% |
| 28261 |
{% |
| 28262 |
\expandafter\XINT_binom_vsmallfinish |
| 28263 |
\the\numexpr\XINT_binom_vsmallmuldiv #2!#1!% |
| 28264 |
}% |
| 28265 |
\def\XINT_binom_vsmallfinish#1{% |
| 28266 |
\def\XINT_binom_vsmallfinish1##1!1!;!0!{\expandafter#1\the\numexpr##1\relax}% |
| 28267 |
}\XINT_binom_vsmallfinish{ }% |
| 28268 |
% \end{macrocode} |
| 28269 |
% \subsection{\csh{xintiiPFactorial}} |
| 28270 |
%\begin{lverb} |
| 28271 |
% 2015/11/29 for 1.2f. Partial factorial pfac(a,b)=(a+1)...b, only for |
| 28272 |
% non-negative integers with a<=b<10^8. |
| 28273 |
% |
| 28274 |
% 1.2h (2016/11/20) removes the non-negativity condition. It was a bit |
| 28275 |
% unfortunate that the code raised \xintError:OutOfRangePFac if 0<=a<=b<10^8 |
| 28276 |
% was violated. The rule now applied is to interpret pfac(a,b) as the product |
| 28277 |
% for a<j<=b (not as a ratio of Gamma function), hence if a>=b, return 1 |
| 28278 |
% because of an empty product. If a<b: if a<0, return 0 for b>=0 and |
| 28279 |
% (-1)^(b-a) times |b|...(|a|-1) for b<0. But only for the range 0<= |
| 28280 |
% a <= b < 10^8 is the macro result to be considered as stable. |
| 28281 |
%\end{lverb} |
| 28282 |
% \begin{macrocode} |
| 28283 |
\def\xintiiPFactorial {\romannumeral0\xintiipfactorial }% |
| 28284 |
\def\xintiipfactorial #1#2% |
| 28285 |
{% |
| 28286 |
\expandafter\XINT_pfac_fork\the\numexpr#1\expandafter.\the\numexpr #2.% |
| 28287 |
}% |
| 28288 |
\def\xintPFactorial{\romannumeral0\xintpfactorial}% |
| 28289 |
\let\xintpfactorial\xintiipfactorial |
| 28290 |
% \end{macrocode} |
| 28291 |
%\begin{lverb} |
| 28292 |
% Code is a simplified version of the one for \xintiiBinomial, with no |
| 28293 |
% attempt at implementing a "very small" branch. |
| 28294 |
%\end{lverb} |
| 28295 |
% \begin{macrocode} |
| 28296 |
\def\XINT_pfac_fork #1#2.#3#4.% |
| 28297 |
{% |
| 28298 |
\unless\ifnum #1#2<#3#4 \xint_dothis\XINT_pfac_one\fi |
| 28299 |
\if-#3\xint_dothis\XINT_pfac_neg\fi |
| 28300 |
\if-#1\xint_dothis\XINT_pfac_zero\fi |
| 28301 |
\ifnum #3#4>\xint_c_x^viii_mone\xint_dothis\XINT_pfac_outofrange\fi |
| 28302 |
\xint_orthat \XINT_pfac_a #1#2.#3#4.% |
| 28303 |
}% |
| 28304 |
\def\XINT_pfac_outofrange #1.#2.% |
| 28305 |
{\XINT_signalcondition{InvalidOperation}% |
| 28306 |
{pFactorial with too large argument: #2 >= 10^8.}{}{ 0}}% |
| 28307 |
\def\XINT_pfac_one #1.#2.{ 1}% |
| 28308 |
\def\XINT_pfac_zero #1.#2.{ 0}% |
| 28309 |
\def\XINT_pfac_neg -#1.-#2.% |
| 28310 |
{% |
| 28311 |
\ifnum #1>\xint_c_x^viii\xint_dothis\XINT_pfac_outofrange\fi |
| 28312 |
\xint_orthat |
| 28313 |
{\ifodd\numexpr#2-#1\relax\xint_afterfi{\expandafter-\romannumeral`&&@}\fi |
| 28314 |
\expandafter\XINT_pfac_a }% |
| 28315 |
\the\numexpr #2-\xint_c_i\expandafter.\the\numexpr#1-\xint_c_i.% |
| 28316 |
}% |
| 28317 |
\def\XINT_pfac_a #1.#2.% |
| 28318 |
{% |
| 28319 |
\expandafter\XINT_pfac_b\the\numexpr \xint_c_i+#1.#2.100000001!1;!% |
| 28320 |
1\R!1\R!1\R!1\R!1\R!1\R!1\R!1\R!\W |
| 28321 |
}% |
| 28322 |
\def\XINT_pfac_b #1.% |
| 28323 |
{% |
| 28324 |
\ifnum #1>9999 \xint_dothis\XINT_pfac_vbigloop \fi |
| 28325 |
\ifnum #1>463 \xint_dothis\XINT_pfac_bigloop \fi |
| 28326 |
\ifnum #1>98 \xint_dothis\XINT_pfac_medloop \fi |
| 28327 |
\xint_orthat\XINT_pfac_smallloop #1.% |
| 28328 |
}% |
| 28329 |
\def\XINT_pfac_smallloop #1.#2.% |
| 28330 |
{% |
| 28331 |
\ifcase\numexpr #2-#1\relax |
| 28332 |
\expandafter\XINT_pfac_end_ |
| 28333 |
\or \expandafter\XINT_pfac_end_i |
| 28334 |
\or \expandafter\XINT_pfac_end_ii |
| 28335 |
\or \expandafter\XINT_pfac_end_iii |
| 28336 |
\else\expandafter\XINT_pfac_smallloop_a |
| 28337 |
\fi #1.#2.% |
| 28338 |
}% |
| 28339 |
\def\XINT_pfac_smallloop_a #1.#2.% |
| 28340 |
{% |
| 28341 |
\expandafter\XINT_pfac_smallloop_b |
| 28342 |
\the\numexpr #1+\xint_c_iv\expandafter.% |
| 28343 |
\the\numexpr #2\expandafter.% |
| 28344 |
\the\numexpr\expandafter\XINT_smallmul |
| 28345 |
\the\numexpr \xint_c_x^viii+#1*(#1+\xint_c_i)*(#1+\xint_c_ii)*(#1+\xint_c_iii)!% |
| 28346 |
}% |
| 28347 |
\def\XINT_pfac_smallloop_b #1.% |
| 28348 |
{% |
| 28349 |
\ifnum #1>98 \expandafter\XINT_pfac_medloop \else |
| 28350 |
\expandafter\XINT_pfac_smallloop \fi #1.% |
| 28351 |
}% |
| 28352 |
\def\XINT_pfac_medloop #1.#2.% |
| 28353 |
{% |
| 28354 |
\ifcase\numexpr #2-#1\relax |
| 28355 |
\expandafter\XINT_pfac_end_ |
| 28356 |
\or \expandafter\XINT_pfac_end_i |
| 28357 |
\or \expandafter\XINT_pfac_end_ii |
| 28358 |
\else\expandafter\XINT_pfac_medloop_a |
| 28359 |
\fi #1.#2.% |
| 28360 |
}% |
| 28361 |
\def\XINT_pfac_medloop_a #1.#2.% |
| 28362 |
{% |
| 28363 |
\expandafter\XINT_pfac_medloop_b |
| 28364 |
\the\numexpr #1+\xint_c_iii\expandafter.% |
| 28365 |
\the\numexpr #2\expandafter.% |
| 28366 |
\the\numexpr\expandafter\XINT_smallmul |
| 28367 |
\the\numexpr \xint_c_x^viii+#1*(#1+\xint_c_i)*(#1+\xint_c_ii)!% |
| 28368 |
}% |
| 28369 |
\def\XINT_pfac_medloop_b #1.% |
| 28370 |
{% |
| 28371 |
\ifnum #1>463 \expandafter\XINT_pfac_bigloop \else |
| 28372 |
\expandafter\XINT_pfac_medloop \fi #1.% |
| 28373 |
}% |
| 28374 |
\def\XINT_pfac_bigloop #1.#2.% |
| 28375 |
{% |
| 28376 |
\ifcase\numexpr #2-#1\relax |
| 28377 |
\expandafter\XINT_pfac_end_ |
| 28378 |
\or \expandafter\XINT_pfac_end_i |
| 28379 |
\else\expandafter\XINT_pfac_bigloop_a |
| 28380 |
\fi #1.#2.% |
| 28381 |
}% |
| 28382 |
\def\XINT_pfac_bigloop_a #1.#2.% |
| 28383 |
{% |
| 28384 |
\expandafter\XINT_pfac_bigloop_b |
| 28385 |
\the\numexpr #1+\xint_c_ii\expandafter.% |
| 28386 |
\the\numexpr #2\expandafter.% |
| 28387 |
\the\numexpr\expandafter |
| 28388 |
\XINT_smallmul\the\numexpr \xint_c_x^viii+#1*(#1+\xint_c_i)!% |
| 28389 |
}% |
| 28390 |
\def\XINT_pfac_bigloop_b #1.% |
| 28391 |
{% |
| 28392 |
\ifnum #1>9999 \expandafter\XINT_pfac_vbigloop \else |
| 28393 |
\expandafter\XINT_pfac_bigloop \fi #1.% |
| 28394 |
}% |
| 28395 |
\def\XINT_pfac_vbigloop #1.#2.% |
| 28396 |
{% |
| 28397 |
\ifnum #2=#1 |
| 28398 |
\expandafter\XINT_pfac_end_ |
| 28399 |
\else\expandafter\XINT_pfac_vbigloop_a |
| 28400 |
\fi #1.#2.% |
| 28401 |
}% |
| 28402 |
\def\XINT_pfac_vbigloop_a #1.#2.% |
| 28403 |
{% |
| 28404 |
\expandafter\XINT_pfac_vbigloop |
| 28405 |
\the\numexpr #1+\xint_c_i\expandafter.% |
| 28406 |
\the\numexpr #2\expandafter.% |
| 28407 |
\the\numexpr\expandafter\XINT_smallmul\the\numexpr\xint_c_x^viii+#1!% |
| 28408 |
}% |
| 28409 |
\def\XINT_pfac_end_iii #1.#2.% |
| 28410 |
{% |
| 28411 |
\expandafter\XINT_mul_out |
| 28412 |
\the\numexpr\expandafter\XINT_smallmul |
| 28413 |
\the\numexpr \xint_c_x^viii+#1*(#1+\xint_c_i)*(#1+\xint_c_ii)*(#1+\xint_c_iii)!% |
| 28414 |
}% |
| 28415 |
\def\XINT_pfac_end_ii #1.#2.% |
| 28416 |
{% |
| 28417 |
\expandafter\XINT_mul_out |
| 28418 |
\the\numexpr\expandafter\XINT_smallmul |
| 28419 |
\the\numexpr \xint_c_x^viii+#1*(#1+\xint_c_i)*(#1+\xint_c_ii)!% |
| 28420 |
}% |
| 28421 |
\def\XINT_pfac_end_i #1.#2.% |
| 28422 |
{% |
| 28423 |
\expandafter\XINT_mul_out |
| 28424 |
\the\numexpr\expandafter\XINT_smallmul |
| 28425 |
\the\numexpr \xint_c_x^viii+#1*(#1+\xint_c_i)!% |
| 28426 |
}% |
| 28427 |
\def\XINT_pfac_end_ #1.#2.% |
| 28428 |
{% |
| 28429 |
\expandafter\XINT_mul_out |
| 28430 |
\the\numexpr\expandafter\XINT_smallmul\the\numexpr \xint_c_x^viii+#1!% |
| 28431 |
}% |
| 28432 |
% \end{macrocode} |
| 28433 |
% \subsection{\csh{xintBool}, \csh{xintToggle}} |
| 28434 |
%\begin{lverb} |
| 28435 |
% 1.09c |
| 28436 |
%\end{lverb} |
| 28437 |
% \begin{macrocode} |
| 28438 |
\def\xintBool #1{\romannumeral`&&@% |
| 28439 |
\csname if#1\endcsname\expandafter1\else\expandafter0\fi }% |
| 28440 |
\def\xintToggle #1{\romannumeral`&&@\iftoggle{#1}{1}{0}}% |
| 28441 |
% \end{macrocode} |
| 28442 |
% \subsection{\csh{xintiiGCD}} |
| 28443 |
% |1.3d|: |\xintiiGCD| code from \xintgcdnameimp is copied here to |
| 28444 |
% support |gcd()| function in \csbxint{iiexpr}. |
| 28445 |
% |
| 28446 |
% |1.4|: removed from \xintgcdnameimp the original caode as now |
| 28447 |
% \xintgcdnameimp loads \xintnameimp. |
| 28448 |
% |
| 28449 |
% \changed[2021/03/22]{1.4d} Damn'ed! Since |1.3d| (2019/01/06) the code was |
| 28450 |
% broken if one of the arguments vanished due to a typo in macro names: |
| 28451 |
% "AisZero" at one location and "Aiszero" at next, and same for B... |
| 28452 |
% |
| 28453 |
% How could this not be detected by my tests !?! |
| 28454 |
% |
| 28455 |
% This caused |\xintiiGCDof| hence the |gcd()| function in |\xintiiexpr| to |
| 28456 |
% break as soon as one argument was zero. |
| 28457 |
% \begin{macrocode} |
| 28458 |
\def\xintiiGCD {\romannumeral0\xintiigcd }% |
| 28459 |
\def\xintiigcd #1{\expandafter\XINT_iigcd\romannumeral0\xintiiabs#1\xint:}% |
| 28460 |
\def\XINT_iigcd #1#2\xint:#3% |
| 28461 |
{% |
| 28462 |
\expandafter\XINT_gcd_fork\expandafter#1% |
| 28463 |
\romannumeral0\xintiiabs#3\xint:#1#2\xint: |
| 28464 |
}% |
| 28465 |
\def\XINT_gcd_fork #1#2% |
| 28466 |
{% |
| 28467 |
\xint_UDzerofork |
| 28468 |
#1\XINT_gcd_Aiszero |
| 28469 |
#2\XINT_gcd_Biszero |
| 28470 |
0\XINT_gcd_loop |
| 28471 |
\krof |
| 28472 |
#2% |
| 28473 |
}% |
| 28474 |
\def\XINT_gcd_Aiszero #1\xint:#2\xint:{ #1}% |
| 28475 |
\def\XINT_gcd_Biszero #1\xint:#2\xint:{ #2}% |
| 28476 |
\def\XINT_gcd_loop #1\xint:#2\xint: |
| 28477 |
{% |
| 28478 |
\expandafter\expandafter\expandafter\XINT_gcd_CheckRem |
| 28479 |
\expandafter\xint_secondoftwo |
| 28480 |
\romannumeral0\XINT_div_prepare {#1}{#2}\xint:#1\xint: |
| 28481 |
}% |
| 28482 |
\def\XINT_gcd_CheckRem #1% |
| 28483 |
{% |
| 28484 |
\xint_gob_til_zero #1\XINT_gcd_end0\XINT_gcd_loop #1% |
| 28485 |
}% |
| 28486 |
\def\XINT_gcd_end0\XINT_gcd_loop #1\xint:#2\xint:{ #2}% |
| 28487 |
% \end{macrocode} |
| 28488 |
% \subsection{\csh{xintiiGCDof}} |
| 28489 |
%\begin{lverb} |
| 28490 |
% New with 1.09a (was located in xintgcd.sty). |
| 28491 |
% |
| 28492 |
% 1.2l adds protection against items being non-terminated \the\numexpr. |
| 28493 |
% |
| 28494 |
% 1.4 renames the macro into \xintiiGCDof and moves it here. |
| 28495 |
% Terminator modified to ^ for direct call by \xintiiexpr function. |
| 28496 |
% |
| 28497 |
% 1.4d fixes breakage inherited since 1.3d rom \xintiiGCD, in case |
| 28498 |
% any argument vanished. |
| 28499 |
% |
| 28500 |
% Currently does not support empty list of arguments. |
| 28501 |
%\end{lverb} |
| 28502 |
% \begin{macrocode} |
| 28503 |
\def\xintiiGCDof {\romannumeral0\xintiigcdof }% |
| 28504 |
\def\xintiigcdof #1{\expandafter\XINT_iigcdof_a\romannumeral`&&@#1^}% |
| 28505 |
\def\XINT_iiGCDof {\romannumeral0\XINT_iigcdof_a}% |
| 28506 |
\def\XINT_iigcdof_a #1{\expandafter\XINT_iigcdof_b\romannumeral`&&@#1!}% |
| 28507 |
\def\XINT_iigcdof_b #1!#2{\expandafter\XINT_iigcdof_c\romannumeral`&&@#2!{#1}!}% |
| 28508 |
\def\XINT_iigcdof_c #1{\xint_gob_til_^ #1\XINT_iigcdof_e ^\XINT_iigcdof_d #1}% |
| 28509 |
\def\XINT_iigcdof_d #1!{\expandafter\XINT_iigcdof_b\romannumeral0\xintiigcd {#1}}% |
| 28510 |
\def\XINT_iigcdof_e #1!#2!{ #2}% |
| 28511 |
% \end{macrocode} |
| 28512 |
% \subsection{\csh{xintiiLCM}} |
| 28513 |
% Copied over |\xintiiLCM| code from \xintgcdnameimp at |1.3d| in order to |
| 28514 |
% support |lcm()| function in \csbxint{iiexpr}. |
| 28515 |
% |
| 28516 |
% At |1.4| original code removed from \xintgcdnameimp as the latter now requires |
| 28517 |
% \xintnameimp. |
| 28518 |
% \begin{macrocode} |
| 28519 |
\def\xintiiLCM {\romannumeral0\xintiilcm}% |
| 28520 |
\def\xintiilcm #1{\expandafter\XINT_iilcm\romannumeral0\xintiiabs#1\xint:}% |
| 28521 |
\def\XINT_iilcm #1#2\xint:#3% |
| 28522 |
{% |
| 28523 |
\expandafter\XINT_lcm_fork\expandafter#1% |
| 28524 |
\romannumeral0\xintiiabs#3\xint:#1#2\xint: |
| 28525 |
}% |
| 28526 |
\def\XINT_lcm_fork #1#2% |
| 28527 |
{% |
| 28528 |
\xint_UDzerofork |
| 28529 |
#1\XINT_lcm_iszero |
| 28530 |
#2\XINT_lcm_iszero |
| 28531 |
0\XINT_lcm_notzero |
| 28532 |
\krof |
| 28533 |
#2% |
| 28534 |
}% |
| 28535 |
\def\XINT_lcm_iszero #1\xint:#2\xint:{ 0}% |
| 28536 |
\def\XINT_lcm_notzero #1\xint:#2\xint: |
| 28537 |
{% |
| 28538 |
\expandafter\XINT_lcm_end\romannumeral0% |
| 28539 |
\expandafter\expandafter\expandafter\XINT_gcd_CheckRem |
| 28540 |
\expandafter\xint_secondoftwo |
| 28541 |
\romannumeral0\XINT_div_prepare {#1}{#2}\xint:#1\xint: |
| 28542 |
\xint:#1\xint:#2\xint: |
| 28543 |
}% |
| 28544 |
\def\XINT_lcm_end #1\xint:#2\xint:#3\xint:{\xintiimul {#2}{\xintiiQuo{#3}{#1}}}% |
| 28545 |
% \end{macrocode} |
| 28546 |
% \subsection{\csh{xintiiLCMof}} |
| 28547 |
%\begin{lverb} |
| 28548 |
% See comments of \xintiiGCDof. |
| 28549 |
%\end{lverb} |
| 28550 |
% \begin{macrocode} |
| 28551 |
\def\xintiiLCMof {\romannumeral0\xintiilcmof }% |
| 28552 |
\def\xintiilcmof #1{\expandafter\XINT_iilcmof_a\romannumeral`&&@#1^}% |
| 28553 |
\def\XINT_iiLCMof {\romannumeral0\XINT_iilcmof_a}% |
| 28554 |
\def\XINT_iilcmof_a #1{\expandafter\XINT_iilcmof_b\romannumeral`&&@#1!}% |
| 28555 |
\def\XINT_iilcmof_b #1!#2{\expandafter\XINT_iilcmof_c\romannumeral`&&@#2!{#1}!}% |
| 28556 |
\def\XINT_iilcmof_c #1{\xint_gob_til_^ #1\XINT_iilcmof_e ^\XINT_iilcmof_d #1}% |
| 28557 |
\def\XINT_iilcmof_d #1!{\expandafter\XINT_iilcmof_b\romannumeral0\xintiilcm {#1}}% |
| 28558 |
\def\XINT_iilcmof_e #1!#2!{ #2}% |
| 28559 |
% \end{macrocode} |
| 28560 |
% \subsection{(WIP) \csh{xintRandomDigits}} |
| 28561 |
%\begin{lverb} |
| 28562 |
% 1.3b. See user manual. Whether this will be part of xintkernel, |
| 28563 |
% xintcore, or xint is yet to be decided. |
| 28564 |
%\end{lverb} |
| 28565 |
% \begin{macrocode} |
| 28566 |
\def\xintRandomDigits{\romannumeral0\xintrandomdigits}% |
| 28567 |
\def\xintrandomdigits#1% |
| 28568 |
{% |
| 28569 |
\csname xint_gob_andstop_\expandafter\XINT_randomdigits\the\numexpr#1\xint: |
| 28570 |
}% |
| 28571 |
\def\XINT_randomdigits#1\xint: |
| 28572 |
{% |
| 28573 |
\expandafter\XINT_randomdigits_a |
| 28574 |
\the\numexpr(#1+\xint_c_iii)/\xint_c_viii\xint:#1\xint: |
| 28575 |
}% |
| 28576 |
\def\XINT_randomdigits_a#1\xint:#2\xint: |
| 28577 |
{% |
| 28578 |
\romannumeral\numexpr\xint_c_viii*#1-#2\csname XINT_% |
| 28579 |
\romannumeral\XINT_replicate #1\endcsname \csname |
| 28580 |
XINT_rdg\endcsname |
| 28581 |
}% |
| 28582 |
\def\XINT_rdg |
| 28583 |
{% |
| 28584 |
\expandafter\XINT_rdg_aux\the\numexpr% |
| 28585 |
\xint_c_nine_x^viii% |
| 28586 |
-\xint_texuniformdeviate\xint_c_ii^vii% |
| 28587 |
-\xint_c_ii^vii*\xint_texuniformdeviate\xint_c_ii^vii% |
| 28588 |
-\xint_c_ii^xiv*\xint_texuniformdeviate\xint_c_ii^vii% |
| 28589 |
-\xint_c_ii^xxi*\xint_texuniformdeviate\xint_c_ii^vii% |
| 28590 |
+\xint_texuniformdeviate\xint_c_x^viii% |
| 28591 |
\relax% |
| 28592 |
}% |
| 28593 |
\def\XINT_rdg_aux#1{XINT_rdg\endcsname}% |
| 28594 |
\let\XINT_XINT_rdg\endcsname |
| 28595 |
% \end{macrocode} |
| 28596 |
% \subsection{(WIP) \csh{XINT_eightrandomdigits}, \csh{xintEightRandomDigits}} |
| 28597 |
%\begin{lverb} |
| 28598 |
% 1.3b. 1.4 adds some public alias... |
| 28599 |
%\end{lverb} |
| 28600 |
% \begin{macrocode} |
| 28601 |
\def\XINT_eightrandomdigits |
| 28602 |
{% |
| 28603 |
\expandafter\xint_gobble_i\the\numexpr% |
| 28604 |
\xint_c_nine_x^viii% |
| 28605 |
-\xint_texuniformdeviate\xint_c_ii^vii% |
| 28606 |
-\xint_c_ii^vii*\xint_texuniformdeviate\xint_c_ii^vii% |
| 28607 |
-\xint_c_ii^xiv*\xint_texuniformdeviate\xint_c_ii^vii% |
| 28608 |
-\xint_c_ii^xxi*\xint_texuniformdeviate\xint_c_ii^vii% |
| 28609 |
+\xint_texuniformdeviate\xint_c_x^viii% |
| 28610 |
\relax% |
| 28611 |
}% |
| 28612 |
\let\xintEightRandomDigits\XINT_eightrandomdigits |
| 28613 |
\def\xintRandBit{\xint_texuniformdeviate\xint_c_ii}% |
| 28614 |
% \end{macrocode} |
| 28615 |
% \subsection{(WIP) \csh{xintRandBit}} |
| 28616 |
%\begin{lverb} |
| 28617 |
% 1.4 And let's add also \xintRandBit while we are at it. |
| 28618 |
%\end{lverb} |
| 28619 |
% \begin{macrocode} |
| 28620 |
\def\xintRandBit{\xint_texuniformdeviate\xint_c_ii}% |
| 28621 |
% \end{macrocode} |
| 28622 |
% \subsection{(WIP) \csh{xintXRandomDigits}} |
| 28623 |
%\begin{lverb} |
| 28624 |
% 1.3b. |
| 28625 |
%\end{lverb} |
| 28626 |
% \begin{macrocode} |
| 28627 |
\def\xintXRandomDigits#1% |
| 28628 |
{% |
| 28629 |
\csname xint_gobble_\expandafter\XINT_xrandomdigits\the\numexpr#1\xint: |
| 28630 |
}% |
| 28631 |
\def\XINT_xrandomdigits#1\xint: |
| 28632 |
{% |
| 28633 |
\expandafter\XINT_xrandomdigits_a |
| 28634 |
\the\numexpr(#1+\xint_c_iii)/\xint_c_viii\xint:#1\xint: |
| 28635 |
}% |
| 28636 |
\def\XINT_xrandomdigits_a#1\xint:#2\xint: |
| 28637 |
{% |
| 28638 |
\romannumeral\numexpr\xint_c_viii*#1-#2\expandafter\endcsname |
| 28639 |
\romannumeral`&&@\romannumeral |
| 28640 |
\XINT_replicate #1\endcsname\XINT_eightrandomdigits |
| 28641 |
}% |
| 28642 |
% \end{macrocode} |
| 28643 |
% \subsection{(WIP) \csh{xintiiRandRangeAtoB}} |
| 28644 |
%\begin{lverb} |
| 28645 |
% 1.3b. Support for randrange() function. |
| 28646 |
% |
| 28647 |
% We do it f-expandably for matters of \xintNewExpr etc... The \xintexpr will |
| 28648 |
% add \xintNum wrapper to possible fractional input. But \xintiiexpr will call |
| 28649 |
% as is. |
| 28650 |
% |
| 28651 |
% TODO: ? implement third argument (STEP) |
| 28652 |
% TODO: \xintNum wrapper (which truncates) not so good in floatexpr. Use round? |
| 28653 |
% |
| 28654 |
% It is an error if b<=a, as in Python. |
| 28655 |
%\end{lverb} |
| 28656 |
% \begin{macrocode} |
| 28657 |
\def\xintiiRandRangeAtoB{\romannumeral`&&@\xintiirandrangeAtoB}% |
| 28658 |
\def\xintiirandrangeAtoB#1% |
| 28659 |
{% |
| 28660 |
\expandafter\XINT_randrangeAtoB_a\romannumeral`&&@#1\xint: |
| 28661 |
}% |
| 28662 |
\def\XINT_randrangeAtoB_a#1\xint:#2% |
| 28663 |
{% |
| 28664 |
\xintiiadd{\expandafter\XINT_randrange |
| 28665 |
\romannumeral0\xintiisub{#2}{#1}\xint:}% |
| 28666 |
{#1}% |
| 28667 |
}% |
| 28668 |
% \end{macrocode} |
| 28669 |
% \subsection{(WIP) \csh{xintiiRandRange}} |
| 28670 |
%\begin{lverb} |
| 28671 |
% 1.3b. Support for randrange(). |
| 28672 |
%\end{lverb} |
| 28673 |
% \begin{macrocode} |
| 28674 |
\def\xintiiRandRange{\romannumeral`&&@\xintiirandrange}% |
| 28675 |
\def\xintiirandrange#1% |
| 28676 |
{% |
| 28677 |
\expandafter\XINT_randrange\romannumeral`&&@#1\xint: |
| 28678 |
}% |
| 28679 |
\def\XINT_randrange #1% |
| 28680 |
{% |
| 28681 |
\xint_UDzerominusfork |
| 28682 |
#1-\XINT_randrange_err:empty |
| 28683 |
0#1\XINT_randrange_err:empty |
| 28684 |
0-\XINT_randrange_a |
| 28685 |
\krof #1% |
| 28686 |
}% |
| 28687 |
\def\XINT_randrange_err:empty#1\xint: |
| 28688 |
{% |
| 28689 |
\XINT_expandableerror{Empty range for randrange.} 0% |
| 28690 |
}% |
| 28691 |
\def\XINT_randrange_a #1\xint: |
| 28692 |
{% |
| 28693 |
\expandafter\XINT_randrange_b\romannumeral0\xintlength{#1}.#1\xint: |
| 28694 |
}% |
| 28695 |
\def\XINT_randrange_b #1.% |
| 28696 |
{% |
| 28697 |
\ifnum#1<\xint_c_x\xint_dothis{\the\numexpr\XINT_uniformdeviate{}}\fi |
| 28698 |
\xint_orthat{\XINT_randrange_c #1.}% |
| 28699 |
}% |
| 28700 |
\def\XINT_randrange_c #1.#2#3#4#5#6#7#8#9% |
| 28701 |
{% |
| 28702 |
\expandafter\XINT_randrange_d |
| 28703 |
\the\numexpr\expandafter\XINT_uniformdeviate\expandafter |
| 28704 |
{\expandafter}\the\numexpr\xint_c_i+#2#3#4#5#6#7#8#9\xint:\xint: |
| 28705 |
#2#3#4#5#6#7#8#9\xint:#1\xint: |
| 28706 |
}% |
| 28707 |
% \end{macrocode} |
| 28708 |
%\begin{lverb} |
| 28709 |
% This raises following annex question: immediately after setting the |
| 28710 |
% seed is it possible for \xintUniformDeviate{N} where N>0 has exactly eight |
| 28711 |
% digits to return either 0 or N-1 ? It could be that this is never the case, |
| 28712 |
% then there is a bias in randrange(). Of course there are anyhow only 2^28 |
| 28713 |
% seeds so randrange(10^X) is by necessity biased when executed immediately |
| 28714 |
% after setting the seed, if X is at least 9. |
| 28715 |
%\end{lverb} |
| 28716 |
% \begin{macrocode} |
| 28717 |
\def\XINT_randrange_d #1\xint:#2\xint: |
| 28718 |
{% |
| 28719 |
\ifnum#1=\xint_c_\xint_dothis\XINT_randrange_Z\fi |
| 28720 |
\ifnum#1=#2 \xint_dothis\XINT_randrange_A\fi |
| 28721 |
\xint_orthat\XINT_randrange_e #1\xint: |
| 28722 |
}% |
| 28723 |
\def\XINT_randrange_e #1\xint:#2\xint:#3\xint: |
| 28724 |
{% |
| 28725 |
\the\numexpr#1\expandafter\relax |
| 28726 |
\romannumeral0\xintrandomdigits{#2-\xint_c_viii}% |
| 28727 |
}% |
| 28728 |
% \end{macrocode} |
| 28729 |
%\begin{lverb} |
| 28730 |
% This is quite unlikely to get executed but if it does it must |
| 28731 |
% pay attention to leading zeros, hence the \xintinum. |
| 28732 |
% We don't have to be |
| 28733 |
% overly obstinate about removing overheads... |
| 28734 |
%\end{lverb} |
| 28735 |
% \begin{macrocode} |
| 28736 |
\def\XINT_randrange_Z 0\xint:#1\xint:#2\xint: |
| 28737 |
{% |
| 28738 |
\xintinum{\xintRandomDigits{#1-\xint_c_viii}}% |
| 28739 |
}% |
| 28740 |
% \end{macrocode} |
| 28741 |
%\begin{lverb} |
| 28742 |
% Here too, overhead is not such a problem. The idea is that we got by |
| 28743 |
% extraordinary same first 8 digits as upper range bound so we pick at random |
| 28744 |
% the remaining needed digits in one go and compare with the upper bound. If too |
| 28745 |
% big, we start again with another random 8 leading digits in given range. No |
| 28746 |
% need to aim at any kind of efficiency for the check and loop back. |
| 28747 |
%\end{lverb} |
| 28748 |
% \begin{macrocode} |
| 28749 |
\def\XINT_randrange_A #1\xint:#2\xint:#3\xint: |
| 28750 |
{% |
| 28751 |
\expandafter\XINT_randrange_B |
| 28752 |
\romannumeral0\xintrandomdigits{#2-\xint_c_viii}\xint: |
| 28753 |
#3\xint:#2.#1\xint: |
| 28754 |
}% |
| 28755 |
\def\XINT_randrange_B #1\xint:#2\xint:#3.#4\xint: |
| 28756 |
{% |
| 28757 |
\xintiiifLt{#1}{#2}{\XINT_randrange_E}{\XINT_randrange_again}% |
| 28758 |
#4#1\xint:#3.#4#2\xint: |
| 28759 |
}% |
| 28760 |
\def\XINT_randrange_E #1\xint:#2\xint:{ #1}% |
| 28761 |
\def\XINT_randrange_again #1\xint:{\XINT_randrange_c}% |
| 28762 |
% \end{macrocode} |
| 28763 |
% \subsection{(WIP) Adjustments for engines without uniformdeviate primitive} |
| 28764 |
%\added{1.3b} |
| 28765 |
% \begin{macrocode} |
| 28766 |
\ifdefined\xint_texuniformdeviate |
| 28767 |
\else |
| 28768 |
\def\xintrandomdigits#1% |
| 28769 |
{% |
| 28770 |
\XINT_expandableerror |
| 28771 |
{No uniformdeviate at engine level.} 0% |
| 28772 |
}% |
| 28773 |
\let\xintXRandomDigits\xintRandomDigits |
| 28774 |
\def\XINT_randrange#1\xint: |
| 28775 |
{% |
| 28776 |
\XINT_expandableerror |
| 28777 |
{No uniformdeviate at engine level.} 0% |
| 28778 |
}% |
| 28779 |
\fi |
| 28780 |
\XINTrestorecatcodesendinput% |
| 28781 |
% \end{macrocode} |
| 28782 |
% \StoreCodelineNo {xint} |
| 28783 |
% \cleardoublepage\let\xintnameUp\undefined |
| 28784 |
%\gardesactifs |
| 28785 |
%\let</xint>\relax |
| 28786 |
%\let<*xintbinhex>\gardesinactifs |
| 28787 |
%</xint>^^A------------------------------------------------------- |
| 28788 |
%<*xintbinhex>^^A------------------------------------------------- |
| 28789 |
%^^A -*- coding: utf-8; mode: doctex; fill-column: 78; sentence-end-double-space: t; eval: (auto-fill-mode -1); fill-paragraph-function: nil; -*- |
| 28790 |
% \clearpage\csname xintbinhexnameUp\endcsname |
| 28791 |
% \let\MakePrivateLetters\xintMakePrivateLetters |
| 28792 |
% \section{Package \xintbinhexnameimp implementation} |
| 28793 |
% \RaisedLabel{sec:binheximp} |
| 28794 |
% |
| 28795 |
% \localtableofcontents |
| 28796 |
% |
| 28797 |
% The commenting is currently (\xintdocdate) still very sparse. |
| 28798 |
% |
| 28799 |
% |1.2m| (|2017/07/31|) rewrote entirely the original macros coming with |
| 28800 |
% |1.08| (|2013/06/07|). |
| 28801 |
% |
| 28802 |
% At |1.2n| the dependencies on \xintcorenameimp were removed, so now the |
| 28803 |
% package loads only \xintkernelnameimp. |
| 28804 |
% |
| 28805 |
% Also at |1.2n| (|2017/08/06|), \cs{csname} governed expansion was used at some places |
| 28806 |
% rather than \cs{numexpr}. This increased the maximal input sizes for |
| 28807 |
% \csbxint{DecToHex}, \csbxint{DecToBin}, and \csbxint{BinToHex}. |
| 28808 |
% |
| 28809 |
% |1.4n| (|2025/09/05|) adds: |
| 28810 |
% \begin{itemize}[nosep] |
| 28811 |
% \item Conversion to and from octal base. |
| 28812 |
% \item Usage of \cs{expanded} in place of the \cs{csname}-based expansion |
| 28813 |
% from |1.2n|. This has increased the maximal input sizes. The increase is |
| 28814 |
% spectacular for the conversions between binary, octal and hexadecimal, the |
| 28815 |
% limit on size being solely dependent on \TeX{} main memory size. This |
| 28816 |
% change however caused seemingly (but barely tested) a slight (1\%) |
| 28817 |
% decrease in speed for \csbxint{DecToHex} and \csbxint{HexToDec}. |
| 28818 |
% \end{itemize} |
| 28819 |
% |
| 28820 |
% Note that the whole architecture was last re-thought in 2017 at a time |
| 28821 |
% \cs{expanded} did not exist. The most subtle coding, which is the one |
| 28822 |
% regarding conversion to and from decimal radix is of such a nature that I am |
| 28823 |
% not motivated at this stage to modify it other than minimally (see initial |
| 28824 |
% code comments for \csbxint{DecToHex}). So the \cs{expanded} was used |
| 28825 |
% therein but only for some subroutines. For the conversions between binary, |
| 28826 |
% octal, and hexadecimal, the whole expansion basically is governed by a |
| 28827 |
% single \cs{expanded}. But for legacy reasons and stylistic coherence across |
| 28828 |
% the codebase, the code keeps using |\romannumeral0| trigger at the start of |
| 28829 |
% the macros with a systematic naming scheme. I am not much motivated to |
| 28830 |
% engage into systematic changes across about \dtt{20000} code lines in the |
| 28831 |
% \xintnameimp bundle! |
| 28832 |
% |
| 28833 |
% \xintexprnameimp loads \xintbinhexnameimp automatically as of |1.4n|. |
| 28834 |
% Formerly it supported only |"| prefix for hexadecimal, now it supports also |
| 28835 |
% |'| for octal, as well as |0x|, |0o| and |0b|. |
| 28836 |
% |
| 28837 |
% \subsection{Catcodes, \protect\eTeX{} and reload detection} |
| 28838 |
% |
| 28839 |
% The code for reload detection was initially copied from \textsc{Heiko |
| 28840 |
% Oberdiek}'s packages, then modified. |
| 28841 |
% |
| 28842 |
% The method for catcodes was also initially directly inspired by these |
| 28843 |
% packages. |
| 28844 |
% \begin{macrocode} |
| 28845 |
\begingroup\catcode61\catcode48\catcode32=10\relax% |
| 28846 |
\catcode13=5 % ^^M |
| 28847 |
\endlinechar=13 % |
| 28848 |
\catcode123=1 % { |
| 28849 |
\catcode125=2 % } |
| 28850 |
\catcode64=11 % @ |
| 28851 |
\catcode44=12 % , |
| 28852 |
\catcode46=12 % . |
| 28853 |
\catcode58=12 % : |
| 28854 |
\catcode94=7 % ^ |
| 28855 |
\def\empty{}\def\space{ }\newlinechar10 |
| 28856 |
\def\z{\endgroup}% |
| 28857 |
\expandafter\let\expandafter\x\csname [email protected]\endcsname |
| 28858 |
\expandafter\let\expandafter\w\csname [email protected]\endcsname |
| 28859 |
\expandafter\ifx\csname numexpr\endcsname\relax |
| 28860 |
\expandafter\ifx\csname PackageWarningNoLine\endcsname\relax |
| 28861 |
\immediate\write128{^^JPackage xintbinhex Warning:^^J% |
| 28862 |
\space\space\space\space |
| 28863 |
\numexpr not available, aborting input.^^J}% |
| 28864 |
\else |
| 28865 |
\PackageWarningNoLine{xintbinhex}{\numexpr not available, aborting input}% |
| 28866 |
\fi |
| 28867 |
\def\z{\endgroup\endinput}% |
| 28868 |
\else |
| 28869 |
\ifx\x\relax % plain-TeX, first loading of xintbinhex.sty |
| 28870 |
\ifx\w\relax % but xintkernel.sty not yet loaded. |
| 28871 |
\def\z{\endgroup\input xintkernel.sty\relax}% |
| 28872 |
\fi |
| 28873 |
\else |
| 28874 |
\ifx\x\empty % LaTeX, first loading, |
| 28875 |
% variable is initialized, but \ProvidesPackage not yet seen |
| 28876 |
\ifx\w\relax % xintkernel.sty not yet loaded. |
| 28877 |
\def\z{\endgroup\RequirePackage{xintkernel}}% |
| 28878 |
\fi |
| 28879 |
\else |
| 28880 |
\def\z{\endgroup\endinput}% xintbinhex already loaded. |
| 28881 |
\fi |
| 28882 |
\fi |
| 28883 |
\fi |
| 28884 |
\z% |
| 28885 |
\XINTsetupcatcodes% defined in xintkernel.sty |
| 28886 |
% \end{macrocode} |
| 28887 |
% \subsection{Package identification} |
| 28888 |
% \begin{macrocode} |
| 28889 |
\XINT_providespackage |
| 28890 |
\ProvidesPackage{xintbinhex}% |
| 28891 |
[2025/09/06 v1.4o Expandable radix conversions (2, 8, 10, and 16) (JFB)]% |
| 28892 |
% \end{macrocode} |
| 28893 |
% \subsection{Storage macros} |
| 28894 |
% \changed{1.2n} Switch to \cs{csname}-governed expansion at various places. |
| 28895 |
% |
| 28896 |
% \changed{1.4n} Move two \cs{newcount}'s to \xintkernelnameimp. |
| 28897 |
% |
| 28898 |
% \changed{1.4n} This release uses \cs{expanded} in place of \cs{csname} |
| 28899 |
% governed expansion. This means that the mysterious \cs{endcsname}'s have |
| 28900 |
% vanished from the storage macros. And support for octal was added, hence |
| 28901 |
% a few more storage macros were added. |
| 28902 |
% \begin{macrocode} |
| 28903 |
\def\XINT_tmpa #1{\ifx\relax#1\else |
| 28904 |
\expandafter\edef\csname XINT_csdth_#1\endcsname |
| 28905 |
{\ifcase #1 0\or 1\or 2\or 3\or 4\or 5\or 6\or 7\or |
| 28906 |
8\or 9\or A\or B\or C\or D\or E\or F\fi}% |
| 28907 |
\expandafter\XINT_tmpa\fi }% |
| 28908 |
\XINT_tmpa {0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}{15}\relax |
| 28909 |
\def\XINT_tmpa #1{\ifx\relax#1\else |
| 28910 |
\expandafter\edef\csname XINT_csdtb_#1\endcsname |
| 28911 |
{\ifcase #1 |
| 28912 |
0000\or 0001\or 0010\or 0011\or 0100\or 0101\or 0110\or 0111\or |
| 28913 |
1000\or 1001\or 1010\or 1011\or 1100\or 1101\or 1110\or 1111\fi}% |
| 28914 |
\expandafter\XINT_tmpa\fi }% |
| 28915 |
\XINT_tmpa {0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}{15}\relax |
| 28916 |
\let\XINT_tmpa\relax |
| 28917 |
\expandafter\def\csname XINT_csbth_0000\endcsname {0}% |
| 28918 |
\expandafter\def\csname XINT_csbth_0001\endcsname {1}% |
| 28919 |
\expandafter\def\csname XINT_csbth_0010\endcsname {2}% |
| 28920 |
\expandafter\def\csname XINT_csbth_0011\endcsname {3}% |
| 28921 |
\expandafter\def\csname XINT_csbth_0100\endcsname {4}% |
| 28922 |
\expandafter\def\csname XINT_csbth_0101\endcsname {5}% |
| 28923 |
\expandafter\def\csname XINT_csbth_0110\endcsname {6}% |
| 28924 |
\expandafter\def\csname XINT_csbth_0111\endcsname {7}% |
| 28925 |
\expandafter\def\csname XINT_csbth_1000\endcsname {8}% |
| 28926 |
\expandafter\def\csname XINT_csbth_1001\endcsname {9}% |
| 28927 |
\expandafter\def\csname XINT_csbth_1010\endcsname {A}% |
| 28928 |
\expandafter\def\csname XINT_csbth_1011\endcsname {B}% |
| 28929 |
\expandafter\def\csname XINT_csbth_1100\endcsname {C}% |
| 28930 |
\expandafter\def\csname XINT_csbth_1101\endcsname {D}% |
| 28931 |
\expandafter\def\csname XINT_csbth_1110\endcsname {E}% |
| 28932 |
\expandafter\def\csname XINT_csbth_1111\endcsname {F}% |
| 28933 |
\expandafter\def\csname XINT_csbto_000\endcsname {0}% |
| 28934 |
\expandafter\def\csname XINT_csbto_001\endcsname {1}% |
| 28935 |
\expandafter\def\csname XINT_csbto_010\endcsname {2}% |
| 28936 |
\expandafter\def\csname XINT_csbto_011\endcsname {3}% |
| 28937 |
\expandafter\def\csname XINT_csbto_100\endcsname {4}% |
| 28938 |
\expandafter\def\csname XINT_csbto_101\endcsname {5}% |
| 28939 |
\expandafter\def\csname XINT_csbto_110\endcsname {6}% |
| 28940 |
\expandafter\def\csname XINT_csbto_111\endcsname {7}% |
| 28941 |
\expandafter\def\csname XINT_cshtb_0\endcsname {0000}% |
| 28942 |
\expandafter\def\csname XINT_cshtb_1\endcsname {0001}% |
| 28943 |
\expandafter\def\csname XINT_cshtb_2\endcsname {0010}% |
| 28944 |
\expandafter\def\csname XINT_cshtb_3\endcsname {0011}% |
| 28945 |
\expandafter\def\csname XINT_cshtb_4\endcsname {0100}% |
| 28946 |
\expandafter\def\csname XINT_cshtb_5\endcsname {0101}% |
| 28947 |
\expandafter\def\csname XINT_cshtb_6\endcsname {0110}% |
| 28948 |
\expandafter\def\csname XINT_cshtb_7\endcsname {0111}% |
| 28949 |
\expandafter\def\csname XINT_cshtb_8\endcsname {1000}% |
| 28950 |
\expandafter\def\csname XINT_cshtb_9\endcsname {1001}% |
| 28951 |
\def\XINT_cshtb_A {1010}% |
| 28952 |
\def\XINT_cshtb_B {1011}% |
| 28953 |
\def\XINT_cshtb_C {1100}% |
| 28954 |
\def\XINT_cshtb_D {1101}% |
| 28955 |
\def\XINT_cshtb_E {1110}% |
| 28956 |
\def\XINT_cshtb_F {1111}% |
| 28957 |
\expandafter\def\csname XINT_csotb_0\endcsname {000}% |
| 28958 |
\expandafter\def\csname XINT_csotb_1\endcsname {001}% |
| 28959 |
\expandafter\def\csname XINT_csotb_2\endcsname {010}% |
| 28960 |
\expandafter\def\csname XINT_csotb_3\endcsname {011}% |
| 28961 |
\expandafter\def\csname XINT_csotb_4\endcsname {100}% |
| 28962 |
\expandafter\def\csname XINT_csotb_5\endcsname {101}% |
| 28963 |
\expandafter\def\csname XINT_csotb_6\endcsname {110}% |
| 28964 |
\expandafter\def\csname XINT_csotb_7\endcsname {111}% |
| 28965 |
% \end{macrocode} |
| 28966 |
% \subsection{Helper macros} |
| 28967 |
% We need at |1.4n| to ensure lengths either multiple of 5, 4 or 3. |
| 28968 |
% For multiples of three we simply imitate what we had in 2017 |
| 28969 |
% for multiples of four. For multiples of five we will do it |
| 28970 |
% rather ``in place'' appealing to \csbxint{Length} and |
| 28971 |
% \csbxint{Replicate} for convenience. I suspected grabbing |
| 28972 |
% five by five (as we can't do ten by ten) would prove less |
| 28973 |
% efficient, but I am not motivated enough at this stage to |
| 28974 |
% devote the time needed for implementing and comparing. |
| 28975 |
% \subsubsection{\csh{XINT_zeroes_foriv}} |
| 28976 |
%\noindent |
| 28977 |
%\begin{lverb} |
| 28978 |
%( \romannumeral0\XINT_zeroes_foriv #1\R{0\R}{00\R}{000\R}$% |
| 28979 |
%: \R{0\R}{00\R}{000\R}\R\W |
| 28980 |
%) |
| 28981 |
% expands to <empty> or 0 or 00 or 000 as needed to prepend to #1 |
| 28982 |
% to extend it to length 4N. |
| 28983 |
%\end{lverb} |
| 28984 |
% \begin{macrocode} |
| 28985 |
\def\XINT_zeroes_foriv #1#2#3#4#5#6#7#8% |
| 28986 |
{% |
| 28987 |
\xint_gob_til_R #8\XINT_zeroes_foriv_end\R\XINT_zeroes_foriv |
| 28988 |
}% |
| 28989 |
\def\XINT_zeroes_foriv_end\R\XINT_zeroes_foriv #1#2\W |
| 28990 |
{\XINT_zeroes_foriv_done #1}% |
| 28991 |
\def\XINT_zeroes_foriv_done #1\R{ #1}% |
| 28992 |
% \end{macrocode} |
| 28993 |
% \subsubsection{\csh{XINT_zeroes_foriii}} |
| 28994 |
% \added{1.4n} |
| 28995 |
%\begin{lverb} |
| 28996 |
%( \romannumeral0\XINT_zeroes_foriii #1\R{0\R}{00\R}$% |
| 28997 |
%: \R{0\R}{00\R}$% |
| 28998 |
%: \R{0\R}{00\R}\R\W |
| 28999 |
%) |
| 29000 |
% expands to <empty> or 0 or 00 as needed to prepend to #1 |
| 29001 |
% to extend it to length 3N. |
| 29002 |
%\end{lverb} |
| 29003 |
% \begin{macrocode} |
| 29004 |
\def\XINT_zeroes_foriii #1#2#3#4#5#6#7#8#9% |
| 29005 |
{% |
| 29006 |
\xint_gob_til_R #9\XINT_zeroes_foriii_end\R\XINT_zeroes_foriii |
| 29007 |
}% |
| 29008 |
\def\XINT_zeroes_foriii_end\R\XINT_zeroes_foriii #1#2\W |
| 29009 |
{\XINT_zeroes_foriii_done #1}% |
| 29010 |
\def\XINT_zeroes_foriii_done #1\R{ #1}% |
| 29011 |
% \end{macrocode} |
| 29012 |
% \subsection{\csh{xintDecToHex}} |
| 29013 |
% |
| 29014 |
% Now that illicit tools such as \ctanpackage{unravel} exist, we can not hide |
| 29015 |
% anymore too much the crux of the matter. Let's simply say that the decimal |
| 29016 |
% input is tacitly converted into a sequence of successive elementary steps |
| 29017 |
% ``multiply by 10000 and add a base 10000 digit''. This is made to act on a |
| 29018 |
% sequence of radix $16^4$ digits (note that $10000<16^4$). Those radix |
| 29019 |
% $16^4$ digits are of course manipulated via \cs{numexpr} as $10^5$-based |
| 29020 |
% digits (note that $16^4<10^5$ and that not only $16^4\cdot 1000< 10^9 |
| 29021 |
% <2^{31}$ but also $10^9+16^4\cdot 1000<2^{31}$ which helps in ensuring |
| 29022 |
% certain operations expand to a fixed number of digit tokens). When the |
| 29023 |
% sequence of elementary steps is complete, the base-$16^4$ digits only need |
| 29024 |
% to be converted to hexadecimal notation and purged of separators. Of course |
| 29025 |
% doing the whole thing expandably requires some skill. This was done when I |
| 29026 |
% was not yet an old man, and obviously was still very clever. Enjoy. |
| 29027 |
% |
| 29028 |
% |
| 29029 |
% \changed{1.2m} Rewritten from scratch using the \xintcorenameimp |
| 29030 |
% |1.2| style. Now guards against non terminated inputs. |
| 29031 |
% |
| 29032 |
% \changed{1.2n} |
| 29033 |
% Coding improvements, \cs{csname}-governed expansion, increased maximal size. |
| 29034 |
% |
| 29035 |
% \changed{1.2o} |
| 29036 |
% Again coding improvements (efficiency gain about 6\%). |
| 29037 |
% |
| 29038 |
% \changed{1.4n} |
| 29039 |
% Replacement of \cs{csname}-based expansion by usage of \cs{expanded}. This |
| 29040 |
% has increased the maximal input size from 12035 to 16042 digits (depends on |
| 29041 |
% nesting level; evaluated with TL2025 default \TeX{} memory parameters, see |
| 29042 |
% user manual). I noticed a slight performance decrease of the order of 1\% |
| 29043 |
% but did not test extensively. |
| 29044 |
% |
| 29045 |
% Perhaps \cs{expanded} could be used to a deeper refactoring but... I |
| 29046 |
% preferred to make minimal changes, not having kept in mind all subtle |
| 29047 |
% details of the 2017 code. |
| 29048 |
% \begin{macrocode} |
| 29049 |
\def\xintDecToHex {\romannumeral0\xintdectohex }% |
| 29050 |
\def\xintdectohex #1% |
| 29051 |
{% |
| 29052 |
\expandafter\XINT_dth_checkin\romannumeral`&&@#1\xint: |
| 29053 |
}% |
| 29054 |
\def\XINT_dth_checkin #1% |
| 29055 |
{% |
| 29056 |
\xint_UDsignfork |
| 29057 |
#1\XINT_dth_neg |
| 29058 |
-{\XINT_dth_main #1}% |
| 29059 |
\krof |
| 29060 |
}% |
| 29061 |
\def\XINT_dth_neg {\expandafter-\romannumeral0\XINT_dth_main}% |
| 29062 |
\def\XINT_dth_main #1\xint: |
| 29063 |
{% |
| 29064 |
\expandafter\XINT_dth_finish |
| 29065 |
\romannumeral`&&@\expandafter\XINT_dthb_start |
| 29066 |
\romannumeral0\XINT_zeroes_foriv |
| 29067 |
#1\R{0\R}{00\R}{000\R}\R{0\R}{00\R}{000\R}\R\W |
| 29068 |
#1\xint_bye\XINT_dth_tohex |
| 29069 |
}% |
| 29070 |
\def\XINT_dthb_start #1#2#3#4#5% |
| 29071 |
{% |
| 29072 |
\xint_bye#5\XINT_dthb_small\xint_bye\XINT_dthb_start_a #1#2#3#4#5% |
| 29073 |
}% |
| 29074 |
\def\XINT_dthb_small\xint_bye\XINT_dthb_start_a #1\xint_bye#2{#2#1!}% |
| 29075 |
\def\XINT_dthb_start_a #1#2#3#4#5#6#7#8#9% |
| 29076 |
{% |
| 29077 |
\expandafter\XINT_dthb_again |
| 29078 |
\the\numexpr\expandafter\XINT_dthb_update |
| 29079 |
\the\numexpr#1#2#3#4% |
| 29080 |
\xint_bye#9\XINT_dthb_lastpass\xint_bye |
| 29081 |
#5#6#7#8!\XINT_dthb_exclam\relax\XINT_dthb_nextfour #9% |
| 29082 |
}% |
| 29083 |
% \end{macrocode} |
| 29084 |
%\begin{lverb} |
| 29085 |
% The 1.2n inserted |
| 29086 |
% exclamations marks, which when bumping back from \XINT_dthb_again gave rise |
| 29087 |
% to a \numexpr-loop which gathered the ! delimited arguments and inserted |
| 29088 |
% \expandafter\XINT_dthb_update\the\numexpr dynamically. The 1.2o trick is to |
| 29089 |
% insert it here immediately. Then at \XINT_dthb_again the \numexpr will |
| 29090 |
% trigger an already prepared chain. |
| 29091 |
% |
| 29092 |
% The crux of the thing is handling of #3 at \XINT_dthb_update_a. |
| 29093 |
%\end{lverb} |
| 29094 |
% \begin{macrocode} |
| 29095 |
\def\XINT_dthb_exclam {!\XINT_dthb_exclam\relax |
| 29096 |
\expandafter\XINT_dthb_update\the\numexpr}% |
| 29097 |
\def\XINT_dthb_update #1!% |
| 29098 |
{% |
| 29099 |
\expandafter\XINT_dthb_update_a |
| 29100 |
\the\numexpr (#1+\xint_c_ii^xv)/\xint_c_ii^xvi-\xint_c_i\xint: |
| 29101 |
#1\xint:% |
| 29102 |
}% |
| 29103 |
% \end{macrocode} |
| 29104 |
% The four zeros here will get appended to prior digits. They enact |
| 29105 |
% the multiplication by 10000. |
| 29106 |
% \begin{macrocode} |
| 29107 |
\def\XINT_dthb_update_a #1\xint:#2\xint:#3% |
| 29108 |
{% |
| 29109 |
0000+#1\expandafter#3\the\numexpr#2-#1*\xint_c_ii^xvi |
| 29110 |
}% |
| 29111 |
\def\XINT_dthb_nextfour #1#2#3#4#5% |
| 29112 |
{% |
| 29113 |
\xint_bye#5\XINT_dthb_lastpass\xint_bye |
| 29114 |
#1#2#3#4!\XINT_dthb_exclam\relax\XINT_dthb_nextfour#5% |
| 29115 |
}% |
| 29116 |
\def\XINT_dthb_lastpass\xint_bye #1!#2\xint_bye#3{#1!#3!}% |
| 29117 |
\def\XINT_dthb_again #1!#2#3% |
| 29118 |
{% |
| 29119 |
\ifx#3\relax |
| 29120 |
\expandafter\xint_firstoftwo |
| 29121 |
\else |
| 29122 |
\expandafter\xint_secondoftwo |
| 29123 |
\fi |
| 29124 |
{\expandafter\XINT_dthb_again |
| 29125 |
\the\numexpr |
| 29126 |
\ifnum #1>\xint_c_ |
| 29127 |
\xint_afterfi{\expandafter\XINT_dthb_update\the\numexpr#1}% |
| 29128 |
\fi}% |
| 29129 |
{\ifnum #1>\xint_c_ \xint_dothis{#2#1!}\fi\xint_orthat{!#2!}}% |
| 29130 |
}% |
| 29131 |
% \end{macrocode} |
| 29132 |
% |1.4n| replaces here \cs{csname}'s method by simpler \cs{expanded} control. |
| 29133 |
% This is the part of the algorithm which rewrites base $16^4$ (kept in decimal) |
| 29134 |
% digits into four hexadecimal digits. |
| 29135 |
% \begin{macrocode} |
| 29136 |
\def\XINT_dth_tohex |
| 29137 |
{% |
| 29138 |
\expandafter\XINT_dth_tohex_a\expanded\XINT_tofourhex |
| 29139 |
}% |
| 29140 |
\def\XINT_dth_tohex_a{!\XINT_dth_tohex!}% |
| 29141 |
\def\XINT_tofourhex #1!% |
| 29142 |
{% |
| 29143 |
{\iffalse}\fi\expandafter\XINT_tofourhex_a |
| 29144 |
\the\numexpr (#1+\xint_c_ii^vii)/\xint_c_ii^viii-\xint_c_i\xint: |
| 29145 |
#1\xint: |
| 29146 |
}% |
| 29147 |
\def\XINT_tofourhex_a #1\xint:#2\xint: |
| 29148 |
{% |
| 29149 |
\expandafter\XINT_tofourhex_c |
| 29150 |
\the\numexpr (#1+\xint_c_viii)/\xint_c_xvi-\xint_c_i\xint: |
| 29151 |
#1\xint: |
| 29152 |
#2-\xint_c_ii^viii*#1!% |
| 29153 |
}% |
| 29154 |
\def\XINT_tofourhex_c #1\xint:#2\xint: |
| 29155 |
{% |
| 29156 |
\csname XINT_csdth_#1\endcsname |
| 29157 |
\csname XINT_csdth_\the\numexpr #2-\xint_c_xvi*#1\endcsname |
| 29158 |
\expandafter\XINT_tofourhex_d\the\numexpr |
| 29159 |
}% |
| 29160 |
\def\XINT_tofourhex_d #1!% |
| 29161 |
{% |
| 29162 |
\expandafter\XINT_tofourhex_e |
| 29163 |
\the\numexpr (#1+\xint_c_viii)/\xint_c_xvi-\xint_c_i\xint: |
| 29164 |
#1\xint: |
| 29165 |
}% |
| 29166 |
\def\XINT_tofourhex_e #1\xint:#2\xint: |
| 29167 |
{% |
| 29168 |
\csname XINT_csdth_#1\endcsname |
| 29169 |
\csname XINT_csdth_\the\numexpr #2-\xint_c_xvi*#1\endcsname |
| 29170 |
\iffalse{\fi}% |
| 29171 |
}% |
| 29172 |
% \end{macrocode} |
| 29173 |
% We only clean up up to 3 hexadecimal zeros, as output is produced in chunks |
| 29174 |
% of 4 hex digits, and (this comment added at |1.4n|) as far as I understand |
| 29175 |
% the leading chunk can be |0000| only if input was vanishing. |
| 29176 |
% |
| 29177 |
% The coding for this simple trimming may not be the most efficient, but this |
| 29178 |
% code is executed only once. I remember from 2017 that I had gotten tired to |
| 29179 |
% always try to optimize and did not even try to test efficiency. |
| 29180 |
% \begin{macrocode} |
| 29181 |
\def\XINT_dth_finish !\XINT_dth_tohex!#1#2#3% |
| 29182 |
{% |
| 29183 |
\unless\if#10\xint_dothis{ #1#2#3}\fi |
| 29184 |
\unless\if#20\xint_dothis{ #2#3}\fi |
| 29185 |
\unless\if#30\xint_dothis{ #3}\fi |
| 29186 |
\xint_orthat{ }% |
| 29187 |
}% |
| 29188 |
% \end{macrocode} |
| 29189 |
% \subsection{\csh{xintDecToOct}} |
| 29190 |
% \added{1.4n} |
| 29191 |
% |
| 29192 |
% This late extension to the package is imitated from (the \cs{expanded} |
| 29193 |
% updated) \csbxint{DecToHex}. |
| 29194 |
% |
| 29195 |
% It does not share macros with \csbxint{DecToHeX} to same extent as |
| 29196 |
% \csbxint{DecToBin} does (those macros with |_dthb_| in their names), because |
| 29197 |
% the input gets converted to radix |8^5|, not radix |16^4|. |
| 29198 |
% |
| 29199 |
% Note that we have $10000<8^5<100000$ and refer to \csbxint{DecToHex} for |
| 29200 |
% some information on the algorithm. |
| 29201 |
% \begin{macrocode} |
| 29202 |
\def\xintDecToOct {\romannumeral0\xintdectooct }% |
| 29203 |
\def\xintdectooct #1% |
| 29204 |
{% |
| 29205 |
\expandafter\XINT_dto_checkin\romannumeral`&&@#1\xint: |
| 29206 |
}% |
| 29207 |
\def\XINT_dto_checkin #1% |
| 29208 |
{% |
| 29209 |
\xint_UDsignfork |
| 29210 |
#1\XINT_dto_neg |
| 29211 |
-{\XINT_dto_main #1}% |
| 29212 |
\krof |
| 29213 |
}% |
| 29214 |
\def\XINT_dto_neg {\expandafter-\romannumeral0\XINT_dto_main}% |
| 29215 |
\def\XINT_dto_main #1\xint: |
| 29216 |
{% |
| 29217 |
\expandafter\XINT_dto_finish |
| 29218 |
\romannumeral`&&@\expandafter\XINT_dto_start |
| 29219 |
\romannumeral0\XINT_zeroes_foriv |
| 29220 |
#1\R{0\R}{00\R}{000\R}\R{0\R}{00\R}{000\R}\R\W |
| 29221 |
#1\xint_bye\XINT_dto_tooct |
| 29222 |
}% |
| 29223 |
\def\XINT_dto_start #1#2#3#4#5% |
| 29224 |
{% |
| 29225 |
\xint_bye#5\XINT_dto_small\xint_bye\XINT_dto_start_a #1#2#3#4#5% |
| 29226 |
}% |
| 29227 |
\def\XINT_dto_small\xint_bye\XINT_dto_start_a #1\xint_bye#2{#2#1!}% |
| 29228 |
\def\XINT_dto_start_a #1#2#3#4#5#6#7#8#9% |
| 29229 |
{% |
| 29230 |
\expandafter\XINT_dto_again\the\numexpr\expandafter\XINT_dto_update |
| 29231 |
\the\numexpr#1#2#3#4% |
| 29232 |
\xint_bye#9\XINT_dto_lastpass\xint_bye |
| 29233 |
#5#6#7#8!\XINT_dto_exclam\relax\XINT_dto_nextfour #9% |
| 29234 |
}% |
| 29235 |
\def\XINT_dto_exclam {!\XINT_dto_exclam\relax |
| 29236 |
\expandafter\XINT_dto_update\the\numexpr}% |
| 29237 |
\def\XINT_dto_update #1!% |
| 29238 |
{% |
| 29239 |
\expandafter\XINT_dto_update_a |
| 29240 |
\the\numexpr (#1+\xint_c_ii^xiv)/\xint_c_ii^xv-\xint_c_i\xint: |
| 29241 |
#1\xint:% |
| 29242 |
}% |
| 29243 |
\def\XINT_dto_update_a #1\xint:#2\xint:#3% |
| 29244 |
{% |
| 29245 |
0000+#1\expandafter#3\the\numexpr#2-#1*\xint_c_ii^xv |
| 29246 |
}% |
| 29247 |
\def\XINT_dto_nextfour #1#2#3#4#5% |
| 29248 |
{% |
| 29249 |
\xint_bye#5\XINT_dto_lastpass\xint_bye |
| 29250 |
#1#2#3#4!\XINT_dto_exclam\relax\XINT_dto_nextfour#5% |
| 29251 |
}% |
| 29252 |
\def\XINT_dto_lastpass\xint_bye #1!#2\xint_bye#3{#1!#3!}% |
| 29253 |
\def\XINT_dto_again #1!#2#3% |
| 29254 |
{% |
| 29255 |
\ifx#3\relax |
| 29256 |
\expandafter\xint_firstoftwo |
| 29257 |
\else |
| 29258 |
\expandafter\xint_secondoftwo |
| 29259 |
\fi |
| 29260 |
{\expandafter\XINT_dto_again |
| 29261 |
\the\numexpr |
| 29262 |
\ifnum #1>\xint_c_ |
| 29263 |
\xint_afterfi{\expandafter\XINT_dto_update\the\numexpr#1}% |
| 29264 |
\fi}% |
| 29265 |
{\ifnum #1>\xint_c_ \xint_dothis{#2#1!}\fi\xint_orthat{!#2!}}% |
| 29266 |
}% |
| 29267 |
\def\XINT_dto_tooct |
| 29268 |
{% |
| 29269 |
\expandafter\XINT_dto_tooct_a\expanded\XINT_tofiveoct |
| 29270 |
}% |
| 29271 |
\def\XINT_dto_tooct_a{!\XINT_dto_tooct!}% |
| 29272 |
\def\XINT_tofiveoct #1!% |
| 29273 |
{% |
| 29274 |
{\iffalse}\fi\expandafter\XINT_tofiveoct_a |
| 29275 |
\the\numexpr (#1+\xint_c_ii^viii)/\xint_c_ii^ix-\xint_c_i\xint: |
| 29276 |
#1\xint: |
| 29277 |
}% |
| 29278 |
\def\XINT_tofiveoct_a #1\xint:#2\xint: |
| 29279 |
{% |
| 29280 |
\expandafter\XINT_tofiveoct_c |
| 29281 |
\the\numexpr (#1+\xint_c_iv)/\xint_c_viii-\xint_c_i\xint:#1\xint: |
| 29282 |
#2-\xint_c_ii^ix*#1!% |
| 29283 |
}% |
| 29284 |
\def\XINT_tofiveoct_c #1\xint:#2\xint: |
| 29285 |
{% |
| 29286 |
#1\the\numexpr #2-\xint_c_viii*#1\relax |
| 29287 |
\expandafter\XINT_tofiveoct_d\the\numexpr |
| 29288 |
}% |
| 29289 |
\def\XINT_tofiveoct_d #1!% |
| 29290 |
{% |
| 29291 |
\expandafter\XINT_tofiveoct_e |
| 29292 |
\the\numexpr (#1+\xint_c_ii^v)/\xint_c_ii^vi-\xint_c_i\xint: |
| 29293 |
#1\xint: |
| 29294 |
}% |
| 29295 |
\def\XINT_tofiveoct_e #1\xint:#2\xint: |
| 29296 |
{% |
| 29297 |
#1\expandafter\XINT_tofiveoct_f\the\numexpr #2-\xint_c_ii^vi*#1!% |
| 29298 |
}% |
| 29299 |
\def\XINT_tofiveoct_f #1!% |
| 29300 |
{% |
| 29301 |
\expandafter\XINT_tofiveoct_g |
| 29302 |
\the\numexpr (#1+\xint_c_iv)/\xint_c_viii-\xint_c_i\xint: |
| 29303 |
#1\xint: |
| 29304 |
}% |
| 29305 |
\def\XINT_tofiveoct_g #1\xint:#2\xint: |
| 29306 |
{% |
| 29307 |
#1\the\numexpr #2-\xint_c_viii*#1\iffalse{\fi}% |
| 29308 |
}% |
| 29309 |
% \end{macrocode} |
| 29310 |
% We only clean-up up to 4 zero octal digits, as output was |
| 29311 |
% produced in chunks of 5 octal digits and as far as this author |
| 29312 |
% understands his own code, the leading block can not be vanishing, |
| 29313 |
% except when input was itself only with zeros. |
| 29314 |
% \begin{macrocode} |
| 29315 |
\def\XINT_dto_finish !\XINT_dto_tooct!#1#2#3#4% |
| 29316 |
{% |
| 29317 |
\unless\if#10\xint_dothis{ #1#2#3#4}\fi |
| 29318 |
\unless\if#20\xint_dothis{ #2#3#4}\fi |
| 29319 |
\unless\if#30\xint_dothis{ #3#4}\fi |
| 29320 |
\unless\if#40\xint_dothis{ #4}\fi |
| 29321 |
\xint_orthat{ }% |
| 29322 |
}% |
| 29323 |
% \end{macrocode} |
| 29324 |
% \subsection{\csh{xintDecToBin}} |
| 29325 |
% An input without leading zeroes gives an output without leading zeroes. |
| 29326 |
% |
| 29327 |
% Macros with |_dtohb| in their names are shared with \csbxint{DecToHex}. |
| 29328 |
% |
| 29329 |
% \changed{1.2m} |
| 29330 |
% Complete rewrite in the |1.2| style. Also, |1.2m| version is robust |
| 29331 |
% against non terminated inputs. |
| 29332 |
% |
| 29333 |
% \changed{1.2n} |
| 29334 |
% Increased maximal size from using \cs{csname}-based expansion. |
| 29335 |
% |
| 29336 |
% \changed{1.4n} |
| 29337 |
% Same use of \cs{expanded} as in \csbxint{DecToHex}. |
| 29338 |
% \begin{macrocode} |
| 29339 |
\def\xintDecToBin {\romannumeral0\xintdectobin }% |
| 29340 |
\def\xintdectobin #1% |
| 29341 |
{% |
| 29342 |
\expandafter\XINT_dtb_checkin\romannumeral`&&@#1\xint: |
| 29343 |
}% |
| 29344 |
\def\XINT_dtb_checkin #1% |
| 29345 |
{% |
| 29346 |
\xint_UDsignfork |
| 29347 |
#1\XINT_dtb_neg |
| 29348 |
-{\XINT_dtb_main #1}% |
| 29349 |
\krof |
| 29350 |
}% |
| 29351 |
\def\XINT_dtb_neg {\expandafter-\romannumeral0\XINT_dtb_main}% |
| 29352 |
\def\XINT_dtb_main #1\xint: |
| 29353 |
{% |
| 29354 |
\expandafter\XINT_dtb_finish |
| 29355 |
\romannumeral`&&@\expandafter\XINT_dthb_start |
| 29356 |
\romannumeral0\XINT_zeroes_foriv |
| 29357 |
#1\R{0\R}{00\R}{000\R}\R{0\R}{00\R}{000\R}\R\W |
| 29358 |
#1\xint_bye\XINT_dtb_tobin |
| 29359 |
}% |
| 29360 |
\def\XINT_dtb_tobin |
| 29361 |
{% |
| 29362 |
\expandafter\XINT_dtb_tobin_a\expanded\XINT_tosixteenbits |
| 29363 |
}% |
| 29364 |
\def\XINT_dtb_tobin_a{!\XINT_dtb_tobin!}% |
| 29365 |
\def\XINT_tosixteenbits #1!% |
| 29366 |
{% |
| 29367 |
{\iffalse}\fi\expandafter\XINT_tosixteenbits_a |
| 29368 |
\the\numexpr (#1+\xint_c_ii^vii)/\xint_c_ii^viii-\xint_c_i\xint: |
| 29369 |
#1\xint: |
| 29370 |
}% |
| 29371 |
\def\XINT_tosixteenbits_a #1\xint:#2\xint: |
| 29372 |
{% |
| 29373 |
\expandafter\XINT_tosixteenbits_c |
| 29374 |
\the\numexpr (#1+\xint_c_viii)/\xint_c_xvi-\xint_c_i\xint: |
| 29375 |
#1\xint: |
| 29376 |
#2-\xint_c_ii^viii*#1!% |
| 29377 |
}% |
| 29378 |
\def\XINT_tosixteenbits_c #1\xint:#2\xint: |
| 29379 |
{% |
| 29380 |
\csname XINT_csdtb_#1\endcsname |
| 29381 |
\csname XINT_csdtb_\the\numexpr #2-\xint_c_xvi*#1\endcsname |
| 29382 |
\expandafter\XINT_tosixteenbits_d\the\numexpr |
| 29383 |
}% |
| 29384 |
\def\XINT_tosixteenbits_d #1!% |
| 29385 |
{% |
| 29386 |
\expandafter\XINT_tosixteenbits_e |
| 29387 |
\the\numexpr (#1+\xint_c_viii)/\xint_c_xvi-\xint_c_i\xint: |
| 29388 |
#1\xint: |
| 29389 |
}% |
| 29390 |
\def\XINT_tosixteenbits_e #1\xint:#2\xint: |
| 29391 |
{% |
| 29392 |
\csname XINT_csdtb_#1\endcsname |
| 29393 |
\csname XINT_csdtb_\the\numexpr #2-\xint_c_xvi*#1\endcsname |
| 29394 |
\iffalse{\fi}% |
| 29395 |
}% |
| 29396 |
\def\XINT_dtb_finish !\XINT_dtb_tobin!#1#2#3#4#5#6#7#8% |
| 29397 |
{% |
| 29398 |
\expandafter\XINT_dtb_finish_a\the\numexpr #1#2#3#4#5#6#7#8\relax |
| 29399 |
}% |
| 29400 |
\def\XINT_dtb_finish_a #1{% |
| 29401 |
\def\XINT_dtb_finish_a ##1##2##3##4##5##6##7##8##9% |
| 29402 |
{% |
| 29403 |
\expandafter#1\the\numexpr ##1##2##3##4##5##6##7##8##9\relax |
| 29404 |
}}\XINT_dtb_finish_a { }% |
| 29405 |
% \end{macrocode} |
| 29406 |
% \subsection{\csh{xintHexToDec}} |
| 29407 |
%\begin{lverb} |
| 29408 |
% Completely (and belatedly) rewritten at 1.2m in the 1.2 style. |
| 29409 |
% |
| 29410 |
% 1.2m version robust against non terminated inputs, but there is no primitive |
| 29411 |
% from TeX which may generate hexadecimal digits and provoke expansion ahead, |
| 29412 |
% afaik, except of course if decimal digits are treated as hexadecimal. This |
| 29413 |
% robustness is not on purpose but from need to expand argument and then grab |
| 29414 |
% it again. So we do it safely. |
| 29415 |
% |
| 29416 |
% Increased maximal size at 1.2n. |
| 29417 |
% |
| 29418 |
% 1.2m version robust against non terminated inputs. |
| 29419 |
% |
| 29420 |
% An input without leading zeroes gives an output without leading zeroes. |
| 29421 |
%\end{lverb} |
| 29422 |
% \begin{macrocode} |
| 29423 |
\def\xintHexToDec {\romannumeral0\xinthextodec }% |
| 29424 |
\def\xinthextodec #1% |
| 29425 |
{% |
| 29426 |
\expandafter\XINT_htd_checkin\romannumeral`&&@#1\xint: |
| 29427 |
}% |
| 29428 |
\def\XINT_htd_checkin #1% |
| 29429 |
{% |
| 29430 |
\xint_UDsignfork |
| 29431 |
#1\XINT_htd_neg |
| 29432 |
-{\XINT_htd_main #1}% |
| 29433 |
\krof |
| 29434 |
}% |
| 29435 |
\def\XINT_htd_neg {\expandafter-\romannumeral0\XINT_htd_main}% |
| 29436 |
\def\XINT_htd_main #1\xint: |
| 29437 |
{% |
| 29438 |
\expandafter\XINT_htd_startb |
| 29439 |
\the\numexpr\expandafter\XINT_htd_starta |
| 29440 |
\romannumeral0\XINT_zeroes_foriv |
| 29441 |
#1\R{0\R}{00\R}{000\R}\R{0\R}{00\R}{000\R}\R\W |
| 29442 |
#1\xint_bye!2!3!4!5!6!7!8!9!\xint_bye\relax |
| 29443 |
}% |
| 29444 |
\def\XINT_htd_starta #1#2#3#4{"#1#2#3#4+\xint_c_x^v!}% |
| 29445 |
\def\XINT_htd_startb 1#1% |
| 29446 |
{% |
| 29447 |
\if#10\expandafter\XINT_htd_startba\else |
| 29448 |
\expandafter\XINT_htd_startbb |
| 29449 |
\fi 1#1% |
| 29450 |
}% |
| 29451 |
\def\XINT_htd_startba 10#1!{\XINT_htd_again #1% |
| 29452 |
\xint_bye!2!3!4!5!6!7!8!9!\xint_bye\XINT_htd_nextfour}% |
| 29453 |
\def\XINT_htd_startbb 1#1#2!{\XINT_htd_again #1!#2% |
| 29454 |
\xint_bye!2!3!4!5!6!7!8!9!\xint_bye\XINT_htd_nextfour}% |
| 29455 |
% \end{macrocode} |
| 29456 |
% It is a bit annoying to grab all to the end here. I had a |
| 29457 |
% version, modeled on the |1.2n| variant of \csbxint{DecToHex} which solved |
| 29458 |
% that problem, but it did not prove much (or at all) faster in my brief |
| 29459 |
% testing and it had the defect of a reduced maximal allowed size of the |
| 29460 |
% input. |
| 29461 |
% \begin{macrocode} |
| 29462 |
\def\XINT_htd_again #1\XINT_htd_nextfour #2% |
| 29463 |
{% |
| 29464 |
\xint_bye #2\XINT_htd_finish\xint_bye |
| 29465 |
\expandafter\XINT_htd_A\the\numexpr |
| 29466 |
\XINT_htd_a #1\XINT_htd_nextfour #2% |
| 29467 |
}% |
| 29468 |
\def\XINT_htd_a #1!#2!#3!#4!#5!#6!#7!#8!#9!% |
| 29469 |
{% |
| 29470 |
#1\expandafter\XINT_htd_update |
| 29471 |
\the\numexpr #2\expandafter\XINT_htd_update |
| 29472 |
\the\numexpr #3\expandafter\XINT_htd_update |
| 29473 |
\the\numexpr #4\expandafter\XINT_htd_update |
| 29474 |
\the\numexpr #5\expandafter\XINT_htd_update |
| 29475 |
\the\numexpr #6\expandafter\XINT_htd_update |
| 29476 |
\the\numexpr #7\expandafter\XINT_htd_update |
| 29477 |
\the\numexpr #8\expandafter\XINT_htd_update |
| 29478 |
\the\numexpr #9\expandafter\XINT_htd_update |
| 29479 |
\the\numexpr \XINT_htd_a |
| 29480 |
}% |
| 29481 |
\def\XINT_htd_nextfour #1#2#3#4% |
| 29482 |
{% |
| 29483 |
*\xint_c_ii^xvi+"#1#2#3#4+\xint_c_x^ix\relax\xint_bye!% |
| 29484 |
2!3!4!5!6!7!8!9!\xint_bye\XINT_htd_nextfour |
| 29485 |
}% |
| 29486 |
\def\XINT_htd_update 1#1#2#3#4#5% |
| 29487 |
{% |
| 29488 |
*\xint_c_ii^xvi+10000#1#2#3#4#5!% |
| 29489 |
}% |
| 29490 |
% \end{macrocode} |
| 29491 |
% \changed{1.4n} |
| 29492 |
% \csbXINT{_htd_A} small refactoring to introduce shared macros |
| 29493 |
% with the octal conversion routine. Slight loss of efficiency. |
| 29494 |
% \begin{macrocode} |
| 29495 |
\def\XINT_htd_A {\XINT_hotd_A\XINT_htd_again}% |
| 29496 |
\def\XINT_hotd_A #11#2% |
| 29497 |
{% |
| 29498 |
\if#20\expandafter\XINT_hotd_Aa\else |
| 29499 |
\expandafter\XINT_hotd_Ab |
| 29500 |
\fi #11#2% |
| 29501 |
}% |
| 29502 |
\def\XINT_hotd_Aa #110#2#3#4#5{#1#2#3#4#5!}% |
| 29503 |
\def\XINT_hotd_Ab #11#2#3#4#5#6{#1#2!#3#4#5#6!}% |
| 29504 |
\def\XINT_htd_finish\xint_bye |
| 29505 |
\expandafter\XINT_htd_A\the\numexpr \XINT_htd_a #1\XINT_htd_nextfour |
| 29506 |
{% |
| 29507 |
\expandafter\XINT_htd_finish_cuz\the\numexpr0\XINT_htd_unsep_loop #1% |
| 29508 |
}% |
| 29509 |
\def\XINT_htd_unsep_loop #1!#2!#3!#4!#5!#6!#7!#8!#9!% |
| 29510 |
{% |
| 29511 |
\expandafter\XINT_unsep_clean |
| 29512 |
\the\numexpr 1#1#2\expandafter\XINT_unsep_clean |
| 29513 |
\the\numexpr 1#3#4\expandafter\XINT_unsep_clean |
| 29514 |
\the\numexpr 1#5#6\expandafter\XINT_unsep_clean |
| 29515 |
\the\numexpr 1#7#8\expandafter\XINT_unsep_clean |
| 29516 |
\the\numexpr 1#9\XINT_htd_unsep_loop_a |
| 29517 |
}% |
| 29518 |
\def\XINT_htd_unsep_loop_a #1!#2!#3!#4!#5!#6!#7!#8!#9!% |
| 29519 |
{% |
| 29520 |
#1\expandafter\XINT_unsep_clean |
| 29521 |
\the\numexpr 1#2#3\expandafter\XINT_unsep_clean |
| 29522 |
\the\numexpr 1#4#5\expandafter\XINT_unsep_clean |
| 29523 |
\the\numexpr 1#6#7\expandafter\XINT_unsep_clean |
| 29524 |
\the\numexpr 1#8#9\XINT_htd_unsep_loop |
| 29525 |
}% |
| 29526 |
\def\XINT_unsep_clean 1{\relax}% also in xintcore |
| 29527 |
\def\XINT_htd_finish_cuz #1{% |
| 29528 |
\def\XINT_htd_finish_cuz ##1##2##3##4##5% |
| 29529 |
{\expandafter#1\the\numexpr ##1##2##3##4##5\relax}% |
| 29530 |
}\XINT_htd_finish_cuz{ }% |
| 29531 |
% \end{macrocode} |
| 29532 |
% \subsection{\csh{xintOctToDec}} |
| 29533 |
% \added{1.4n} |
| 29534 |
% Yes, the explanations are somewhat lacking. Basically this imitates |
| 29535 |
% \csbxint{xintHexToDec} the main difference being to handle 5 octal |
| 29536 |
% digits at a time in place of 4 hexadecimal ones. |
| 29537 |
% \begin{macrocode} |
| 29538 |
\def\xintOctToDec {\romannumeral0\xintocttodec }% |
| 29539 |
\def\xintocttodec #1% |
| 29540 |
{% |
| 29541 |
\expandafter\XINT_otd_checkin\romannumeral`&&@#1\xint: |
| 29542 |
}% |
| 29543 |
\def\XINT_otd_checkin #1% |
| 29544 |
{% |
| 29545 |
\xint_UDsignfork |
| 29546 |
#1\XINT_otd_neg |
| 29547 |
-{\XINT_otd_main #1}% |
| 29548 |
\krof |
| 29549 |
}% |
| 29550 |
\def\XINT_otd_neg {\expandafter-\romannumeral0\XINT_otd_main}% |
| 29551 |
% \end{macrocode} |
| 29552 |
% First we inject leading octal zeroes to make the length a multiple of 5. We |
| 29553 |
% do not try to code a direct way as with \csbXINT{_zeroes_foriv}, in part |
| 29554 |
% because as we can't grab 10 by 10, we would have to proceed 5 by 5, which |
| 29555 |
% for very long input may prove slower than using \csbxint{Length} combined |
| 29556 |
% with \csbxint{Replicate}, as provided by \xintkernelnameimp. However, the |
| 29557 |
% author is not motivated enough to do the alternative coding and compare its |
| 29558 |
% efficiency with the one here. |
| 29559 |
% \begin{macrocode} |
| 29560 |
\def\XINT_otd_main #1\xint: |
| 29561 |
{% |
| 29562 |
\expandafter\XINT_otd_startb |
| 29563 |
\the\numexpr\expandafter\XINT_otd_starta_i |
| 29564 |
\romannumeral0\xintlength{#1}\xint: |
| 29565 |
#1\xint_bye!2!3!4!5!6!7!8!9!\xint_bye\relax |
| 29566 |
}% |
| 29567 |
\def\XINT_otd_starta_i #1\xint: |
| 29568 |
{% |
| 29569 |
\expandafter\XINT_otd_starta |
| 29570 |
\romannumeral\xintreplicate{\xint_c_v*((#1+\xint_c_ii)/\xint_c_v)-#1}{0}% |
| 29571 |
}% |
| 29572 |
% \end{macrocode} |
| 29573 |
% Now we grab five octal digits and convert to decimal in a \cs{numexpr}. |
| 29574 |
% \begin{macrocode} |
| 29575 |
\def\XINT_otd_starta #1#2#3#4#5{'#1#2#3#4#5+\xint_c_x^v!}% |
| 29576 |
\def\XINT_otd_startb 1#1% |
| 29577 |
{% |
| 29578 |
\if#10\expandafter\XINT_otd_startba\else |
| 29579 |
\expandafter\XINT_otd_startbb |
| 29580 |
\fi 1#1% |
| 29581 |
}% |
| 29582 |
\def\XINT_otd_startba 10#1!{\XINT_otd_again #1% |
| 29583 |
\xint_bye!2!3!4!5!6!7!8!9!\xint_bye\XINT_otd_nextfive}% |
| 29584 |
\def\XINT_otd_startbb 1#1#2!{\XINT_otd_again #1!#2% |
| 29585 |
\xint_bye!2!3!4!5!6!7!8!9!\xint_bye\XINT_otd_nextfive}% |
| 29586 |
\def\XINT_otd_again #1\XINT_otd_nextfive #2% |
| 29587 |
{% |
| 29588 |
\xint_bye #2\XINT_otd_finish\xint_bye |
| 29589 |
\expandafter\XINT_otd_A\the\numexpr |
| 29590 |
\XINT_otd_a #1\XINT_otd_nextfive #2% |
| 29591 |
}% |
| 29592 |
\def\XINT_otd_a #1!#2!#3!#4!#5!#6!#7!#8!#9!% |
| 29593 |
{% |
| 29594 |
#1\expandafter\XINT_otd_update |
| 29595 |
\the\numexpr #2\expandafter\XINT_otd_update |
| 29596 |
\the\numexpr #3\expandafter\XINT_otd_update |
| 29597 |
\the\numexpr #4\expandafter\XINT_otd_update |
| 29598 |
\the\numexpr #5\expandafter\XINT_otd_update |
| 29599 |
\the\numexpr #6\expandafter\XINT_otd_update |
| 29600 |
\the\numexpr #7\expandafter\XINT_otd_update |
| 29601 |
\the\numexpr #8\expandafter\XINT_otd_update |
| 29602 |
\the\numexpr #9\expandafter\XINT_otd_update |
| 29603 |
\the\numexpr \XINT_otd_a |
| 29604 |
}% |
| 29605 |
\def\XINT_otd_nextfive #1#2#3#4#5% |
| 29606 |
{% |
| 29607 |
*\xint_c_ii^xv+'#1#2#3#4#5+\xint_c_x^ix\relax\xint_bye!% |
| 29608 |
2!3!4!5!6!7!8!9!\xint_bye\XINT_otd_nextfive |
| 29609 |
}% |
| 29610 |
\def\XINT_otd_update 1#1#2#3#4#5% |
| 29611 |
{% |
| 29612 |
*\xint_c_ii^xv+10000#1#2#3#4#5!% |
| 29613 |
}% |
| 29614 |
% \end{macrocode} |
| 29615 |
% We can hook here into the \csbxint{HexToDec} final sub-routines. |
| 29616 |
% \begin{macrocode} |
| 29617 |
\def\XINT_otd_A {\XINT_hotd_A\XINT_otd_again}% |
| 29618 |
\def\XINT_otd_finish\xint_bye |
| 29619 |
\expandafter\XINT_otd_A\the\numexpr \XINT_otd_a #1\XINT_otd_nextfive |
| 29620 |
{% |
| 29621 |
\expandafter\XINT_htd_finish_cuz\the\numexpr0\XINT_htd_unsep_loop #1% |
| 29622 |
}% |
| 29623 |
% \end{macrocode} |
| 29624 |
% \subsection{\csh{xintBinToDec}} |
| 29625 |
%\begin{lverb} |
| 29626 |
% Redone entirely for 1.2m. Starts by converting to hexadecimal |
| 29627 |
% first. |
| 29628 |
% |
| 29629 |
% Increased maximal size at 1.2n. |
| 29630 |
% |
| 29631 |
% An input without leading zeroes gives an output without leading zeroes. |
| 29632 |
% |
| 29633 |
% Robust against non-terminated input. |
| 29634 |
%\end{lverb} |
| 29635 |
% \begin{macrocode} |
| 29636 |
\def\xintBinToDec {\romannumeral0\xintbintodec }% |
| 29637 |
\def\xintbintodec #1% |
| 29638 |
{% |
| 29639 |
\expandafter\XINT_btd_checkin\romannumeral`&&@#1\xint: |
| 29640 |
}% |
| 29641 |
\def\XINT_btd_checkin #1% |
| 29642 |
{% |
| 29643 |
\xint_UDsignfork |
| 29644 |
#1\XINT_btd_N |
| 29645 |
-{\XINT_btd_main #1}% |
| 29646 |
\krof |
| 29647 |
}% |
| 29648 |
\def\XINT_btd_N {\expandafter-\romannumeral0\XINT_btd_main }% |
| 29649 |
\def\XINT_btd_main #1\xint: |
| 29650 |
{% |
| 29651 |
\expandafter\XINT_btd_htd |
| 29652 |
\expanded{\expandafter\XINT_bth_loop |
| 29653 |
\romannumeral0\XINT_zeroes_foriv |
| 29654 |
#1\R{0\R}{00\R}{000\R}\R{0\R}{00\R}{000\R}\R\W |
| 29655 |
#1nonenone\xint_bye}\xint: |
| 29656 |
}% |
| 29657 |
\def\XINT_btd_htd #1\xint: |
| 29658 |
{% |
| 29659 |
\expandafter\XINT_htd_startb |
| 29660 |
\the\numexpr\expandafter\XINT_htd_starta |
| 29661 |
\romannumeral0\XINT_zeroes_foriv |
| 29662 |
#1\R{0\R}{00\R}{000\R}\R{0\R}{00\R}{000\R}\R\W |
| 29663 |
#1\xint_bye!2!3!4!5!6!7!8!9!\xint_bye\relax |
| 29664 |
}% |
| 29665 |
% \end{macrocode} |
| 29666 |
% \subsection{\csh{xintHexToOct}} |
| 29667 |
% |
| 29668 |
% \added{1.4n} This is done the lazy way, from hexadecimal to binary to octal. |
| 29669 |
% I am simply not motivated enough at this stage to implement a direct |
| 29670 |
% conversion (3 hexa digits mapping to 4 octal ones), handle leading zeros, |
| 29671 |
% and compare efficiency and size limits with the simple minded one here. |
| 29672 |
% \begin{macrocode} |
| 29673 |
\def\xintHexToOct {\romannumeral0\xinthextooct }% |
| 29674 |
\def\xinthextooct #1% |
| 29675 |
{% |
| 29676 |
\expandafter\XINT_bto_checkin |
| 29677 |
\romannumeral0\expandafter\XINT_htb_checkin\romannumeral`&&@#1.........\xint_bye |
| 29678 |
\iffalse{\fi}% |
| 29679 |
\xint: |
| 29680 |
}% |
| 29681 |
% \end{macrocode} |
| 29682 |
% \subsection{\csh{xintHexToBin}} |
| 29683 |
%\begin{lverb} |
| 29684 |
% Completely rewritten for 1.2m. |
| 29685 |
% |
| 29686 |
% Only up to three zeros are removed on front of output: if the input had a |
| 29687 |
% leading zero, there will be a leading zero (and then possibly 4n of them if |
| 29688 |
% inputs had more leading zeroes) on output. |
| 29689 |
% |
| 29690 |
% Rewritten again at 1.2n for \csname governed expansion. |
| 29691 |
%\end{lverb} |
| 29692 |
% \changed{1.4n} |
| 29693 |
% Use of \cs{expanded} (quasi globally, in contrast to the local uses |
| 29694 |
% made in the decimal conversions).. Dramatic increase of upper limit |
| 29695 |
% on the size of input. |
| 29696 |
% |
| 29697 |
% As a by-product the initial expansion of the argument |#1| is now |
| 29698 |
% guarded at the end by (many) full stops, but anyhow I don't know |
| 29699 |
% \TeX{} construct potentially creating hexadecimal digits and |
| 29700 |
% potentially causing expansion of what comes next if not terminated. |
| 29701 |
% \begin{macrocode} |
| 29702 |
\def\xintHexToBin {\romannumeral0\xinthextobin }% |
| 29703 |
\def\xinthextobin #1% |
| 29704 |
{% |
| 29705 |
\expandafter\XINT_htb_checkin\romannumeral`&&@#1.........\xint_bye |
| 29706 |
\iffalse{\fi}% |
| 29707 |
}% |
| 29708 |
\def\XINT_htb_checkin #1% |
| 29709 |
{% |
| 29710 |
\xint_UDsignfork |
| 29711 |
#1\XINT_htb_N |
| 29712 |
-{\XINT_htb_main #1}% |
| 29713 |
\krof |
| 29714 |
}% |
| 29715 |
\def\XINT_htb_N {\expandafter-\romannumeral0\XINT_htb_main }% |
| 29716 |
\def\XINT_htb_main |
| 29717 |
{% |
| 29718 |
\expandafter\XINT_htb_cuz |
| 29719 |
\expanded{\iffalse}\fi\XINT_htb_loop |
| 29720 |
}% |
| 29721 |
\def\XINT_htb_loop #1#2#3#4#5#6#7#8#9% |
| 29722 |
{% |
| 29723 |
\csname XINT_cshtb_#1\endcsname |
| 29724 |
\csname XINT_cshtb_#2\endcsname |
| 29725 |
\csname XINT_cshtb_#3\endcsname |
| 29726 |
\csname XINT_cshtb_#4\endcsname |
| 29727 |
\csname XINT_cshtb_#5\endcsname |
| 29728 |
\csname XINT_cshtb_#6\endcsname |
| 29729 |
\csname XINT_cshtb_#7\endcsname |
| 29730 |
\csname XINT_cshtb_#8\endcsname |
| 29731 |
\csname XINT_cshtb_#9\endcsname |
| 29732 |
\XINT_htb_loop |
| 29733 |
}% |
| 29734 |
\expandafter\let\csname XINT_cshtb_.\endcsname\xint_bye |
| 29735 |
\def\XINT_htb_cuz #1{% |
| 29736 |
\def\XINT_htb_cuz ##1##2##3##4% |
| 29737 |
{\expandafter#1\the\numexpr##1##2##3##4\relax}% |
| 29738 |
}\XINT_htb_cuz { }% |
| 29739 |
% \end{macrocode} |
| 29740 |
% \subsection{\csh{xintCHexToBin}} |
| 29741 |
%\begin{lverb} |
| 29742 |
% The 1.08 macro had same functionality as \xintHexToBin, and slightly |
| 29743 |
% different code, the 1.2m version has the same code as \xintHexToBin except |
| 29744 |
% that it does not remove leading zeros from output: if the input had N |
| 29745 |
% hexadecimal digits, the output will have exactly 4N binary digits. |
| 29746 |
% |
| 29747 |
% Rewritten again at 1.2n for \csname governed expansion. |
| 29748 |
%\end{lverb} |
| 29749 |
% \changed{1.4n} |
| 29750 |
% Kept in sync with new \csbxint{HexToBin}. |
| 29751 |
% \begin{macrocode} |
| 29752 |
\def\xintCHexToBin {\romannumeral0\xintchextobin }% |
| 29753 |
\def\xintchextobin #1% |
| 29754 |
{% |
| 29755 |
\expandafter\XINT_chtb_checkin\romannumeral`&&@#1.........\xint_bye |
| 29756 |
\iffalse{\fi}% |
| 29757 |
}% |
| 29758 |
\def\XINT_chtb_checkin #1% |
| 29759 |
{% |
| 29760 |
\xint_UDsignfork |
| 29761 |
#1\XINT_chtb_N |
| 29762 |
-{\XINT_chtb_main #1}% |
| 29763 |
\krof |
| 29764 |
}% |
| 29765 |
\def\XINT_chtb_N {\expandafter-\romannumeral0\XINT_chtb_main }% |
| 29766 |
\def\XINT_chtb_main {\expanded{ \iffalse}\fi\XINT_htb_loop}% |
| 29767 |
% \end{macrocode} |
| 29768 |
% \subsection{\csh{xintOctToHex}} |
| 29769 |
% |
| 29770 |
% \added{1.4n} This is done the lazy way, from octal to binary to hexadecimal. |
| 29771 |
% \begin{macrocode} |
| 29772 |
\def\xintOctToHex {\romannumeral0\xintocttohex }% |
| 29773 |
\def\xintocttohex #1% |
| 29774 |
{% |
| 29775 |
\expandafter\XINT_bth_checkin |
| 29776 |
\romannumeral0\expandafter\XINT_otb_checkin\romannumeral`&&@#1.........\xint_bye |
| 29777 |
\iffalse{\fi}% |
| 29778 |
\xint: |
| 29779 |
}% |
| 29780 |
% \end{macrocode} |
| 29781 |
% \subsection{\csh{xintBinToHex}} |
| 29782 |
% \changed{1.2m} Complete rewrite. Much more efficient but smaller maximals sizes. |
| 29783 |
% \changed{1.2n} |
| 29784 |
% Again redone and now using \cs{csname} governed expansion: increased |
| 29785 |
% maximal size. |
| 29786 |
% |
| 29787 |
% Size of output is ceil(size(input)/4). If the input has leading zeroes, |
| 29788 |
% they may exist in the output too. |
| 29789 |
% An input without leading zeroes gives an output without leading zeroes. |
| 29790 |
% |
| 29791 |
% \changed{1.4n} |
| 29792 |
% Expansion is governed by \cs{expanded}. Tremendous increase of maximal |
| 29793 |
% size. Note that for legacy reasons of the package history, the primary |
| 29794 |
% trigger is via |\romannumeral0|, we could use \cs{expanded} upfront, |
| 29795 |
% with some advantages. But well. |
| 29796 |
% \begin{macrocode} |
| 29797 |
\def\xintBinToHex {\romannumeral0\xintbintohex }% |
| 29798 |
\def\xintbintohex #1% |
| 29799 |
{% |
| 29800 |
\expandafter\XINT_bth_checkin\romannumeral`&&@#1\xint: |
| 29801 |
}% |
| 29802 |
\def\XINT_bth_checkin #1% |
| 29803 |
{% |
| 29804 |
\xint_UDsignfork |
| 29805 |
#1\XINT_bth_N |
| 29806 |
-{\XINT_bth_main #1}% |
| 29807 |
\krof |
| 29808 |
}% |
| 29809 |
\def\XINT_bth_N {\expandafter-\romannumeral0\XINT_bth_main }% |
| 29810 |
\def\XINT_bth_main #1\xint: |
| 29811 |
{% |
| 29812 |
\expanded{ \expandafter\XINT_bth_loop |
| 29813 |
\romannumeral0\XINT_zeroes_foriv |
| 29814 |
#1\R{0\R}{00\R}{000\R}\R{0\R}{00\R}{000\R}\R\W |
| 29815 |
#1% |
| 29816 |
nonenone\xint_bye}% |
| 29817 |
}% |
| 29818 |
\def\XINT_bth_loop #1#2#3#4#5#6#7#8% |
| 29819 |
{% |
| 29820 |
\csname XINT_csbth_#1#2#3#4\endcsname |
| 29821 |
\csname XINT_csbth_#5#6#7#8\endcsname |
| 29822 |
\XINT_bth_loop |
| 29823 |
}% |
| 29824 |
\let\XINT_csbth_none\xint_bye |
| 29825 |
% \end{macrocode} |
| 29826 |
% \subsection{\csh{xintOctToBin}} |
| 29827 |
% \added{1.4n} |
| 29828 |
% \begin{macrocode} |
| 29829 |
\def\xintOctToBin {\romannumeral0\xintocttobin }% |
| 29830 |
\def\xintocttobin #1% |
| 29831 |
{% |
| 29832 |
\expandafter\XINT_otb_checkin\romannumeral`&&@#1.........\xint_bye |
| 29833 |
\iffalse{\fi}% |
| 29834 |
}% |
| 29835 |
\def\XINT_otb_checkin #1% |
| 29836 |
{% |
| 29837 |
\xint_UDsignfork |
| 29838 |
#1\XINT_otb_N |
| 29839 |
-{\XINT_otb_main #1}% |
| 29840 |
\krof |
| 29841 |
}% |
| 29842 |
\def\XINT_otb_N {\expandafter-\romannumeral0\XINT_otb_main }% |
| 29843 |
\def\XINT_otb_main |
| 29844 |
{% |
| 29845 |
\expandafter\XINT_otb_cuz |
| 29846 |
\expanded{\iffalse}\fi \XINT_otb_loop |
| 29847 |
}% |
| 29848 |
\def\XINT_otb_loop #1#2#3#4#5#6#7#8#9% |
| 29849 |
{% |
| 29850 |
\csname XINT_csotb_#1\endcsname |
| 29851 |
\csname XINT_csotb_#2\endcsname |
| 29852 |
\csname XINT_csotb_#3\endcsname |
| 29853 |
\csname XINT_csotb_#4\endcsname |
| 29854 |
\csname XINT_csotb_#5\endcsname |
| 29855 |
\csname XINT_csotb_#6\endcsname |
| 29856 |
\csname XINT_csotb_#7\endcsname |
| 29857 |
\csname XINT_csotb_#8\endcsname |
| 29858 |
\csname XINT_csotb_#9\endcsname |
| 29859 |
\XINT_otb_loop |
| 29860 |
}% |
| 29861 |
\expandafter\let\csname XINT_csotb_.\endcsname\xint_bye |
| 29862 |
\def\XINT_otb_cuz #1{% |
| 29863 |
\def\XINT_otb_cuz ##1##2##3% |
| 29864 |
{\expandafter#1\the\numexpr##1##2##3\relax}% |
| 29865 |
}\XINT_otb_cuz { }% |
| 29866 |
% \end{macrocode} |
| 29867 |
% \subsection{\csh{xintCOctToBin}} |
| 29868 |
% \added{1.4n} |
| 29869 |
% \begin{macrocode} |
| 29870 |
\def\xintCOctToBin {\romannumeral0\xintcocttobin }% |
| 29871 |
\def\xintcocttobin #1% |
| 29872 |
{% |
| 29873 |
\expandafter\XINT_cotb_checkin\romannumeral`&&@#1.........\xint_bye |
| 29874 |
\iffalse{\fi}% |
| 29875 |
}% |
| 29876 |
\def\XINT_cotb_checkin #1% |
| 29877 |
{% |
| 29878 |
\xint_UDsignfork |
| 29879 |
#1\XINT_cotb_N |
| 29880 |
-{\XINT_cotb_main #1}% |
| 29881 |
\krof |
| 29882 |
}% |
| 29883 |
\def\XINT_cotb_N {\expandafter-\romannumeral0\XINT_cotb_main }% |
| 29884 |
\def\XINT_cotb_main {\expanded{ \iffalse}\fi\XINT_otb_loop}% |
| 29885 |
% \end{macrocode} |
| 29886 |
% \subsection{\csh{xintBinToOct}} |
| 29887 |
% \added{1.4n} |
| 29888 |
% \begin{macrocode} |
| 29889 |
\def\xintBinToOct {\romannumeral0\xintbintooct }% |
| 29890 |
\def\xintbintooct #1% |
| 29891 |
{% |
| 29892 |
\expandafter\XINT_bto_checkin\romannumeral`&&@#1\xint: |
| 29893 |
}% |
| 29894 |
\def\XINT_bto_checkin #1% |
| 29895 |
{% |
| 29896 |
\xint_UDsignfork |
| 29897 |
#1\XINT_bto_N |
| 29898 |
-{\XINT_bto_main #1}% |
| 29899 |
\krof |
| 29900 |
}% |
| 29901 |
\def\XINT_bto_N {\expandafter-\romannumeral0\XINT_bto_main }% |
| 29902 |
\def\XINT_bto_main #1\xint: |
| 29903 |
{% |
| 29904 |
\expanded{ \expandafter\XINT_bto_loop |
| 29905 |
\romannumeral0\XINT_zeroes_foriii |
| 29906 |
#1\R{0\R}{00\R}\R{0\R}{00\R}\R{0\R}{00\R}\R\W |
| 29907 |
#1% |
| 29908 |
endendend\xint_bye}% |
| 29909 |
}% |
| 29910 |
\def\XINT_bto_loop #1#2#3#4#5#6#7#8#9% |
| 29911 |
{% |
| 29912 |
\csname XINT_csbto_#1#2#3\endcsname |
| 29913 |
\csname XINT_csbto_#4#5#6\endcsname |
| 29914 |
\csname XINT_csbto_#7#8#9\endcsname |
| 29915 |
\XINT_bto_loop |
| 29916 |
}% |
| 29917 |
\let\XINT_csbto_end\xint_bye |
| 29918 |
\XINTrestorecatcodesendinput% |
| 29919 |
% \end{macrocode} |
| 29920 |
% \StoreCodelineNo {xintbinhex} |
| 29921 |
% \cleardoublepage\let\xintbinhexnameUp\undefined |
| 29922 |
%\gardesactifs |
| 29923 |
%\let</xintbinhex>\relax |
| 29924 |
%\let<*xintgcd>\gardesinactifs |
| 29925 |
%</xintbinhex>^^A------------------------------------------------- |
| 29926 |
%<*xintgcd>^^A---------------------------------------------------- |
| 29927 |
%^^A -*- coding: utf-8; mode: doctex; fill-column: 78; sentence-end-double-space: t; eval: (auto-fill-mode -1); fill-paragraph-function: nil; -*- |
| 29928 |
% \clearpage\csname xintgcdnameUp\endcsname |
| 29929 |
% \let\MakePrivateLetters\xintMakePrivateLetters |
| 29930 |
% \section{Package \xintgcdnameimp implementation} |
| 29931 |
% \RaisedLabel{sec:gcdimp} |
| 29932 |
% |
| 29933 |
% \localtableofcontents |
| 29934 |
% |
| 29935 |
% The commenting is currently (\xintdocdate) very sparse. |
| 29936 |
% |
| 29937 |
% Release |1.09h| has |
| 29938 |
% modified a bit the |\xintTypesetEuclideAlgorithm| and |
| 29939 |
% |\xintTypesetBezoutAlgorithm| layout with respect to line indentation in |
| 29940 |
% particular. And they use the \xinttoolsnameimp |\xintloop| rather than the |
| 29941 |
% Plain \TeX{} or \LaTeX{}'s |\loop|. |
| 29942 |
% |
| 29943 |
% |
| 29944 |
% Breaking change at |1.2p|: |\xintBezout{A}{B}| formerly had output |
| 29945 |
% |{A}{B}{U}{V}{D}| with |AU-BV=D|, now it is |{U}{V}{D}| with |AU+BV=D|. |
| 29946 |
% |
| 29947 |
% From |1.1| to |1.3f| the package loaded only \xintcorenameimp. At |1.4| it |
| 29948 |
% now automatically loads both of \xintnameimp and \xinttoolsnameimp (the |
| 29949 |
% latter being in fact a requirement of \csbxint{TypesetEuclideAlgorithm} and |
| 29950 |
% \csbxint{TypesetBezoutAlgorithm} since |1.09h|). |
| 29951 |
% |
| 29952 |
% \begin{framed} |
| 29953 |
% At |1.4| \csbxint{GCD}, \csbxint{LCM}, \csbxint{GCDof}, and \csbxint{LCMof} |
| 29954 |
% are \emph{removed} from the package:\IMPORTANTf they are provided only by |
| 29955 |
% \xintfracnameimp and they handle general fractions, not only integers. |
| 29956 |
% |
| 29957 |
% The original\CHANGEDf{1.4} integer-only macros have been renamed into respectively |
| 29958 |
% \csbxint{iiGCD}, \csbxint{iiLCM}, \csbxint{iiGCDof}, and \csbxint{iiLCMof} |
| 29959 |
% and got relocated into \xintnameimp package. |
| 29960 |
% \end{framed} |
| 29961 |
% |
| 29962 |
% \subsection{Catcodes, \protect\eTeX{} and reload detection} |
| 29963 |
% |
| 29964 |
% The code for reload detection was initially copied from \textsc{Heiko |
| 29965 |
% Oberdiek}'s packages, then modified. |
| 29966 |
% |
| 29967 |
% The method for catcodes was also initially directly inspired by these |
| 29968 |
% packages. |
| 29969 |
% |
| 29970 |
% \begin{macrocode} |
| 29971 |
\begingroup\catcode61\catcode48\catcode32=10\relax% |
| 29972 |
\catcode13=5 % ^^M |
| 29973 |
\endlinechar=13 % |
| 29974 |
\catcode123=1 % { |
| 29975 |
\catcode125=2 % } |
| 29976 |
\catcode64=11 % @ |
| 29977 |
\catcode44=12 % , |
| 29978 |
\catcode46=12 % . |
| 29979 |
\catcode58=12 % : |
| 29980 |
\catcode94=7 % ^ |
| 29981 |
\def\empty{}\def\space{ }\newlinechar10 |
| 29982 |
\def\z{\endgroup}% |
| 29983 |
\expandafter\let\expandafter\x\csname [email protected]\endcsname |
| 29984 |
\expandafter\let\expandafter\w\csname [email protected]\endcsname |
| 29985 |
\expandafter\let\expandafter\t\csname [email protected]\endcsname |
| 29986 |
\expandafter\ifx\csname numexpr\endcsname\relax |
| 29987 |
\expandafter\ifx\csname PackageWarningNoLine\endcsname\relax |
| 29988 |
\immediate\write128{^^JPackage xintgcd Warning:^^J% |
| 29989 |
\space\space\space\space |
| 29990 |
\numexpr not available, aborting input.^^J}% |
| 29991 |
\else |
| 29992 |
\PackageWarningNoLine{xintgcd}{\numexpr not available, aborting input}% |
| 29993 |
\fi |
| 29994 |
\def\z{\endgroup\endinput}% |
| 29995 |
\else |
| 29996 |
\ifx\x\relax % plain-TeX, first loading of xintgcd.sty |
| 29997 |
\ifx\w\relax % but xint.sty not yet loaded. |
| 29998 |
\expandafter\def\expandafter\z\expandafter{\z\input xint.sty\relax}% |
| 29999 |
\fi |
| 30000 |
\ifx\t\relax % but xinttools.sty not yet loaded. |
| 30001 |
\expandafter\def\expandafter\z\expandafter{\z\input xinttools.sty\relax}% |
| 30002 |
\fi |
| 30003 |
\else |
| 30004 |
\ifx\x\empty % LaTeX, first loading, |
| 30005 |
% variable is initialized, but \ProvidesPackage not yet seen |
| 30006 |
\ifx\w\relax % xint.sty not yet loaded. |
| 30007 |
\expandafter\def\expandafter\z\expandafter{\z\RequirePackage{xint}}% |
| 30008 |
\fi |
| 30009 |
\ifx\t\relax % xinttools.sty not yet loaded. |
| 30010 |
\expandafter\def\expandafter\z\expandafter{\z\RequirePackage{xinttools}}% |
| 30011 |
\fi |
| 30012 |
\else |
| 30013 |
\def\z{\endgroup\endinput}% xintgcd already loaded. |
| 30014 |
\fi |
| 30015 |
\fi |
| 30016 |
\fi |
| 30017 |
\z% |
| 30018 |
\XINTsetupcatcodes% defined in xintkernel.sty |
| 30019 |
% \end{macrocode} |
| 30020 |
% \subsection{Package identification} |
| 30021 |
% \begin{macrocode} |
| 30022 |
\XINT_providespackage |
| 30023 |
\ProvidesPackage{xintgcd}% |
| 30024 |
[2025/09/06 v1.4o Euclide algorithm with xint package (JFB)]% |
| 30025 |
% \end{macrocode} |
| 30026 |
% \subsection{\csh{xintBezout}} |
| 30027 |
%\begin{lverb} |
| 30028 |
% \xintBezout{#1}{#2} |
| 30029 |
% produces {U}{V}{D} with UA+VB=D, D = PGCD(A,B) (non-positive), |
| 30030 |
% where #1 and #2 f-expand to big integers A and B. |
| 30031 |
% |
| 30032 |
% I had not checked this macro for about three years when I realized in |
| 30033 |
% January 2017 that \xintBezout{A}{B} was buggy for the cases A = 0 or B = 0. |
| 30034 |
% I fixed that blemish in 1.2l but overlooked the other blemish that |
| 30035 |
% \xintBezout{A}{B} with A multiple of B produced a coefficient U as -0 in |
| 30036 |
% place of 0. |
| 30037 |
% |
| 30038 |
% Hence I rewrote again for 1.2p. On this occasion I modified the output |
| 30039 |
% of the macro to be {U}{V}{D} with AU+BV=D, formerly it was |
| 30040 |
% {A}{B}{U}{V}{D} with AU - BV = D. This is quite breaking change! |
| 30041 |
% |
| 30042 |
% Note in particular change of sign of V. |
| 30043 |
% |
| 30044 |
% I don't know why I had designed this macro to contain {A}{B} in its output. |
| 30045 |
% Perhaps I initially intended to output {A//D}{B//D} (but forgot), as this is |
| 30046 |
% actually possible from outcome of the last iteration, with no need of |
| 30047 |
% actually dividing. Current code however arranges to skip this last update, |
| 30048 |
% as U and V are already furnished by the iteration prior to realizing that |
| 30049 |
% the last non-zero remainder was found. |
| 30050 |
% |
| 30051 |
% Also 1.2l raised InvalidOperation if both A and B vanished, but I removed |
| 30052 |
% this behaviour at 1.2p. |
| 30053 |
%\end{lverb} |
| 30054 |
% \begin{macrocode} |
| 30055 |
\def\xintBezout {\romannumeral0\xintbezout }% |
| 30056 |
\def\xintbezout #1% |
| 30057 |
{% |
| 30058 |
\expandafter\XINT_bezout\expandafter {\romannumeral0\xintnum{#1}}% |
| 30059 |
}% |
| 30060 |
\def\XINT_bezout #1#2% |
| 30061 |
{% |
| 30062 |
\expandafter\XINT_bezout_fork \romannumeral0\xintnum{#2}\Z #1\Z |
| 30063 |
}% |
| 30064 |
% \end{macrocode} |
| 30065 |
%\begin{lverb} |
| 30066 |
% #3#4 = A, #1#2=B. Micro improvement for 1.2l. |
| 30067 |
%\end{lverb} |
| 30068 |
% \begin{macrocode} |
| 30069 |
\def\XINT_bezout_fork #1#2\Z #3#4\Z |
| 30070 |
{% |
| 30071 |
\xint_UDzerosfork |
| 30072 |
#1#3\XINT_bezout_botharezero |
| 30073 |
#10\XINT_bezout_secondiszero |
| 30074 |
#30\XINT_bezout_firstiszero |
| 30075 |
00\xint_UDsignsfork |
| 30076 |
\krof |
| 30077 |
#1#3\XINT_bezout_minusminus % A < 0, B < 0 |
| 30078 |
#1-\XINT_bezout_minusplus % A > 0, B < 0 |
| 30079 |
#3-\XINT_bezout_plusminus % A < 0, B > 0 |
| 30080 |
--\XINT_bezout_plusplus % A > 0, B > 0 |
| 30081 |
\krof |
| 30082 |
{#2}{#4}#1#3% #1#2=B, #3#4=A |
| 30083 |
}% |
| 30084 |
\def\XINT_bezout_botharezero #1\krof#2#300{{0}{0}{0}}% |
| 30085 |
\def\XINT_bezout_firstiszero #1\krof#2#3#4#5% |
| 30086 |
{% |
| 30087 |
\xint_UDsignfork |
| 30088 |
#4{{0}{-1}{#2}}% |
| 30089 |
-{{0}{1}{#4#2}}% |
| 30090 |
\krof |
| 30091 |
}% |
| 30092 |
\def\XINT_bezout_secondiszero #1\krof#2#3#4#5% |
| 30093 |
{% |
| 30094 |
\xint_UDsignfork |
| 30095 |
#5{{-1}{0}{#3}}% |
| 30096 |
-{{1}{0}{#5#3}}% |
| 30097 |
\krof |
| 30098 |
}% |
| 30099 |
% \end{macrocode} |
| 30100 |
%\begin{lverb} |
| 30101 |
% #4#2= A < 0, #3#1 = B < 0 |
| 30102 |
%\end{lverb} |
| 30103 |
% \begin{macrocode} |
| 30104 |
\def\XINT_bezout_minusminus #1#2#3#4% |
| 30105 |
{% |
| 30106 |
\expandafter\XINT_bezout_mm_post |
| 30107 |
\romannumeral0\expandafter\XINT_bezout_preloop_a |
| 30108 |
\romannumeral0\XINT_div_prepare {#1}{#2}{#1}% |
| 30109 |
}% |
| 30110 |
\def\XINT_bezout_mm_post #1#2% |
| 30111 |
{% |
| 30112 |
\expandafter\XINT_bezout_mm_postb\expandafter |
| 30113 |
{\romannumeral0\xintiiopp{#2}}{\romannumeral0\xintiiopp{#1}}% |
| 30114 |
}% |
| 30115 |
\def\XINT_bezout_mm_postb #1#2{\expandafter{#2}{#1}}% |
| 30116 |
% \end{macrocode} |
| 30117 |
%\begin{lverb} |
| 30118 |
% minusplus #4#2= A > 0, B < 0 |
| 30119 |
%\end{lverb} |
| 30120 |
% \begin{macrocode} |
| 30121 |
\def\XINT_bezout_minusplus #1#2#3#4% |
| 30122 |
{% |
| 30123 |
\expandafter\XINT_bezout_mp_post |
| 30124 |
\romannumeral0\expandafter\XINT_bezout_preloop_a |
| 30125 |
\romannumeral0\XINT_div_prepare {#1}{#4#2}{#1}% |
| 30126 |
}% |
| 30127 |
\def\XINT_bezout_mp_post #1#2% |
| 30128 |
{% |
| 30129 |
\expandafter\xint_exchangetwo_keepbraces\expandafter |
| 30130 |
{\romannumeral0\xintiiopp {#2}}{#1}% |
| 30131 |
}% |
| 30132 |
% \end{macrocode} |
| 30133 |
%\begin{lverb} |
| 30134 |
% plusminus A < 0, B > 0 |
| 30135 |
%\end{lverb} |
| 30136 |
% \begin{macrocode} |
| 30137 |
\def\XINT_bezout_plusminus #1#2#3#4% |
| 30138 |
{% |
| 30139 |
\expandafter\XINT_bezout_pm_post |
| 30140 |
\romannumeral0\expandafter\XINT_bezout_preloop_a |
| 30141 |
\romannumeral0\XINT_div_prepare {#3#1}{#2}{#3#1}% |
| 30142 |
}% |
| 30143 |
\def\XINT_bezout_pm_post #1{\expandafter{\romannumeral0\xintiiopp{#1}}}% |
| 30144 |
% \end{macrocode} |
| 30145 |
%\begin{lverb} |
| 30146 |
% plusplus, B = #3#1 > 0, A = #4#2 > 0 |
| 30147 |
%\end{lverb} |
| 30148 |
% \begin{macrocode} |
| 30149 |
\def\XINT_bezout_plusplus #1#2#3#4% |
| 30150 |
{% |
| 30151 |
\expandafter\XINT_bezout_preloop_a |
| 30152 |
\romannumeral0\XINT_div_prepare {#3#1}{#4#2}{#3#1}% |
| 30153 |
}% |
| 30154 |
% \end{macrocode} |
| 30155 |
%\begin{lverb} |
| 30156 |
%( n = 0: BA1001 (B, A, e=1, vv, uu, v, u) |
| 30157 |
%: r(1)=B, r(0)=A, après n étapes {r(n+1)}{r(n)}{vv}{uu}{v}{u} |
| 30158 |
%: q(n) quotient de r(n-1) par r(n) |
| 30159 |
%: si reste nul, exit et renvoie U = -e*uu, V = e*vv, A*U+B*V=D |
| 30160 |
%: sinon mise à jour |
| 30161 |
%: vv, v = q * vv + v, vv |
| 30162 |
%: uu, u = q * uu + u, uu |
| 30163 |
%: e = -e |
| 30164 |
%: puis calcul quotient reste et itération |
| 30165 |
%) |
| 30166 |
% |
| 30167 |
% We arrange for \xintiiMul sub-routine to be called only with positive |
| 30168 |
% arguments, thus skipping some un-needed sign parsing there. For that though |
| 30169 |
% we have to screen out the special cases A divides B, or B divides A. And we |
| 30170 |
% first want to exchange A and B if A < B. These special cases are the only |
| 30171 |
% one possibly leading to U or V zero (for A and B positive which is the case |
| 30172 |
% here.) Thus the general case always leads to non-zero U and V's and assigning |
| 30173 |
% a final sign is done simply adding a - to one of them, with no fear of |
| 30174 |
% producing -0. |
| 30175 |
%\end{lverb} |
| 30176 |
% \begin{macrocode} |
| 30177 |
\def\XINT_bezout_preloop_a #1#2#3% |
| 30178 |
{% |
| 30179 |
\if0#1\xint_dothis\XINT_bezout_preloop_exchange\fi |
| 30180 |
\if0#2\xint_dothis\XINT_bezout_preloop_exit\fi |
| 30181 |
\xint_orthat{\expandafter\XINT_bezout_loop_B}% |
| 30182 |
\romannumeral0\XINT_div_prepare {#2}{#3}{#2}{#1}110% |
| 30183 |
}% |
| 30184 |
\def\XINT_bezout_preloop_exit |
| 30185 |
\romannumeral0\XINT_div_prepare #1#2#3#4#5#6#7% |
| 30186 |
{% |
| 30187 |
{0}{1}{#2}% |
| 30188 |
}% |
| 30189 |
\def\XINT_bezout_preloop_exchange |
| 30190 |
{% |
| 30191 |
\expandafter\xint_exchangetwo_keepbraces |
| 30192 |
\romannumeral0\expandafter\XINT_bezout_preloop_A |
| 30193 |
}% |
| 30194 |
\def\XINT_bezout_preloop_A #1#2#3#4% |
| 30195 |
{% |
| 30196 |
\if0#2\xint_dothis\XINT_bezout_preloop_exit\fi |
| 30197 |
\xint_orthat{\expandafter\XINT_bezout_loop_B}% |
| 30198 |
\romannumeral0\XINT_div_prepare {#2}{#3}{#2}{#1}% |
| 30199 |
}% |
| 30200 |
\def\XINT_bezout_loop_B #1#2% |
| 30201 |
{% |
| 30202 |
\if0#2\expandafter\XINT_bezout_exitA |
| 30203 |
\else\expandafter\XINT_bezout_loop_C |
| 30204 |
\fi {#1}{#2}% |
| 30205 |
}% |
| 30206 |
% \end{macrocode} |
| 30207 |
%\begin{lverb} |
| 30208 |
% We use the fact that the \romannumeral-`0 (or equivalent) done by \xintiiadd |
| 30209 |
% will absorb the initial space token left by \XINT_mul_plusplus in its |
| 30210 |
% output. |
| 30211 |
% |
| 30212 |
% We arranged for operands here to be always positive which is needed for |
| 30213 |
% \XINT_mul_plusplus entry point (last time I checked...). Admittedly this |
| 30214 |
% kind of optimization is not good for maintenance of code, but I can't resist |
| 30215 |
% temptation of limiting the shuffling around of tokens... |
| 30216 |
%\end{lverb} |
| 30217 |
% \begin{macrocode} |
| 30218 |
\def\XINT_bezout_loop_C #1#2#3#4#5#6#7% |
| 30219 |
{% |
| 30220 |
\expandafter\XINT_bezout_loop_D\expandafter |
| 30221 |
{\romannumeral0\xintiiadd{\XINT_mul_plusplus{}{}#1\xint:#4\xint:}{#6}}% |
| 30222 |
{\romannumeral0\xintiiadd{\XINT_mul_plusplus{}{}#1\xint:#5\xint:}{#7}}% |
| 30223 |
{#2}{#3}{#4}{#5}% |
| 30224 |
}% |
| 30225 |
\def\XINT_bezout_loop_D #1#2% |
| 30226 |
{% |
| 30227 |
\expandafter\XINT_bezout_loop_E\expandafter{#2}{#1}% |
| 30228 |
}% |
| 30229 |
\def\XINT_bezout_loop_E #1#2#3#4% |
| 30230 |
{% |
| 30231 |
\expandafter\XINT_bezout_loop_b |
| 30232 |
\romannumeral0\XINT_div_prepare {#3}{#4}{#3}{#2}{#1}% |
| 30233 |
}% |
| 30234 |
\def\XINT_bezout_loop_b #1#2% |
| 30235 |
{% |
| 30236 |
\if0#2\expandafter\XINT_bezout_exita |
| 30237 |
\else\expandafter\XINT_bezout_loop_c |
| 30238 |
\fi {#1}{#2}% |
| 30239 |
}% |
| 30240 |
\def\XINT_bezout_loop_c #1#2#3#4#5#6#7% |
| 30241 |
{% |
| 30242 |
\expandafter\XINT_bezout_loop_d\expandafter |
| 30243 |
{\romannumeral0\xintiiadd{\XINT_mul_plusplus{}{}#1\xint:#4\xint:}{#6}}% |
| 30244 |
{\romannumeral0\xintiiadd{\XINT_mul_plusplus{}{}#1\xint:#5\xint:}{#7}}% |
| 30245 |
{#2}{#3}{#4}{#5}% |
| 30246 |
}% |
| 30247 |
\def\XINT_bezout_loop_d #1#2% |
| 30248 |
{% |
| 30249 |
\expandafter\XINT_bezout_loop_e\expandafter{#2}{#1}% |
| 30250 |
}% |
| 30251 |
\def\XINT_bezout_loop_e #1#2#3#4% |
| 30252 |
{% |
| 30253 |
\expandafter\XINT_bezout_loop_B |
| 30254 |
\romannumeral0\XINT_div_prepare {#3}{#4}{#3}{#2}{#1}% |
| 30255 |
}% |
| 30256 |
% \end{macrocode} |
| 30257 |
%\begin{lverb} |
| 30258 |
% sortir U, V, D mais on a travaillé avec vv, uu, v, u dans cet ordre.$\ |
| 30259 |
% The code is structured so that #4 and #5 are guaranteed non-zero |
| 30260 |
% if we exit here, hence we can not create a -0 in output. |
| 30261 |
%\end{lverb} |
| 30262 |
% \begin{macrocode} |
| 30263 |
\def\XINT_bezout_exita #1#2#3#4#5#6#7{{-#5}{#4}{#3}}% |
| 30264 |
\def\XINT_bezout_exitA #1#2#3#4#5#6#7{{#5}{-#4}{#3}}% |
| 30265 |
% \end{macrocode} |
| 30266 |
% \subsection{\csh{xintEuclideAlgorithm}} |
| 30267 |
%\begin{lverb} |
| 30268 |
% Pour Euclide: |
| 30269 |
% {N}{A}{D=r(n)}{B}{q1}{r1}{q2}{r2}{q3}{r3}....{qN}{rN=0}$\ |
| 30270 |
% u<2n> = u<2n+3>u<2n+2> + u<2n+4> à la n ième étape. |
| 30271 |
% |
| 30272 |
% Formerly, used \xintiabs, but got deprecated at 1.2o. |
| 30273 |
%\end{lverb} |
| 30274 |
% \begin{macrocode} |
| 30275 |
\def\xintEuclideAlgorithm {\romannumeral0\xinteuclidealgorithm }% |
| 30276 |
\def\xinteuclidealgorithm #1% |
| 30277 |
{% |
| 30278 |
\expandafter\XINT_euc\expandafter{\romannumeral0\xintiiabs{\xintNum{#1}}}% |
| 30279 |
}% |
| 30280 |
\def\XINT_euc #1#2% |
| 30281 |
{% |
| 30282 |
\expandafter\XINT_euc_fork\romannumeral0\xintiiabs{\xintNum{#2}}\Z #1\Z |
| 30283 |
}% |
| 30284 |
% \end{macrocode} |
| 30285 |
%\begin{lverb} |
| 30286 |
% Ici #3#4=A, #1#2=B |
| 30287 |
%\end{lverb} |
| 30288 |
% \begin{macrocode} |
| 30289 |
\def\XINT_euc_fork #1#2\Z #3#4\Z |
| 30290 |
{% |
| 30291 |
\xint_UDzerofork |
| 30292 |
#1\XINT_euc_BisZero |
| 30293 |
#3\XINT_euc_AisZero |
| 30294 |
0\XINT_euc_a |
| 30295 |
\krof |
| 30296 |
{0}{#1#2}{#3#4}{{#3#4}{#1#2}}{}\Z |
| 30297 |
}% |
| 30298 |
% \end{macrocode} |
| 30299 |
%\begin{lverb} |
| 30300 |
% Le {} pour protéger {{A}{B}} si on s'arrête après une étape (B divise |
| 30301 |
% A). |
| 30302 |
% On va renvoyer:$\ |
| 30303 |
% {N}{A}{D=r(n)}{B}{q1}{r1}{q2}{r2}{q3}{r3}....{qN}{rN=0} |
| 30304 |
%\end{lverb} |
| 30305 |
% \begin{macrocode} |
| 30306 |
\def\XINT_euc_AisZero #1#2#3#4#5#6{{1}{0}{#2}{#2}{0}{0}}% |
| 30307 |
\def\XINT_euc_BisZero #1#2#3#4#5#6{{1}{0}{#3}{#3}{0}{0}}% |
| 30308 |
% \end{macrocode} |
| 30309 |
%\begin{lverb} |
| 30310 |
% {n}{rn}{an}{{qn}{rn}}...{{A}{B}}{}\Z$\ |
| 30311 |
% a(n) = r(n-1). Pour n=0 on a juste {0}{B}{A}{{A}{B}}{}\Z$\ |
| 30312 |
% \XINT_div_prepare {u}{v} divise v par u |
| 30313 |
%\end{lverb} |
| 30314 |
% \begin{macrocode} |
| 30315 |
\def\XINT_euc_a #1#2#3% |
| 30316 |
{% |
| 30317 |
\expandafter\XINT_euc_b\the\numexpr #1+\xint_c_i\expandafter.% |
| 30318 |
\romannumeral0\XINT_div_prepare {#2}{#3}{#2}% |
| 30319 |
}% |
| 30320 |
% \end{macrocode} |
| 30321 |
%\begin{lverb} |
| 30322 |
% {n+1}{q(n+1)}{r(n+1)}{rn}{{qn}{rn}}... |
| 30323 |
%\end{lverb} |
| 30324 |
% \begin{macrocode} |
| 30325 |
\def\XINT_euc_b #1.#2#3#4% |
| 30326 |
{% |
| 30327 |
\XINT_euc_c #3\Z {#1}{#3}{#4}{{#2}{#3}}% |
| 30328 |
}% |
| 30329 |
% \end{macrocode} |
| 30330 |
%\begin{lverb} |
| 30331 |
% r(n+1)\Z {n+1}{r(n+1)}{r(n)}{{q(n+1)}{r(n+1)}}{{qn}{rn}}...$\ |
| 30332 |
% Test si r(n+1) est nul. |
| 30333 |
%\end{lverb} |
| 30334 |
% \begin{macrocode} |
| 30335 |
\def\XINT_euc_c #1#2\Z |
| 30336 |
{% |
| 30337 |
\xint_gob_til_zero #1\XINT_euc_end0\XINT_euc_a |
| 30338 |
}% |
| 30339 |
% \end{macrocode} |
| 30340 |
%\begin{lverb} |
| 30341 |
% {n+1}{r(n+1)}{r(n)}{{q(n+1)}{r(n+1)}}...{}\Z |
| 30342 |
% Ici r(n+1) = 0. On arrête on se prépare à inverser |
| 30343 |
% {n+1}{0}{r(n)}{{q(n+1)}{r(n+1)}}.....{{q1}{r1}}{{A}{B}}{}\Z$\ |
| 30344 |
% On veut renvoyer: {N=n+1}{A}{D=r(n)}{B}{q1}{r1}{q2}{r2}{q3}{r3}....{qN}{rN=0} |
| 30345 |
%\end{lverb} |
| 30346 |
% \begin{macrocode} |
| 30347 |
\def\XINT_euc_end0\XINT_euc_a #1#2#3#4\Z% |
| 30348 |
{% |
| 30349 |
\expandafter\XINT_euc_end_a |
| 30350 |
\romannumeral0% |
| 30351 |
\XINT_rord_main {}#4{{#1}{#3}}% |
| 30352 |
\xint: |
| 30353 |
\xint_bye\xint_bye\xint_bye\xint_bye |
| 30354 |
\xint_bye\xint_bye\xint_bye\xint_bye |
| 30355 |
\xint: |
| 30356 |
}% |
| 30357 |
\def\XINT_euc_end_a #1#2#3{{#1}{#3}{#2}}% |
| 30358 |
% \end{macrocode} |
| 30359 |
% \subsection{\csh{xintBezoutAlgorithm}} |
| 30360 |
%\begin{lverb} |
| 30361 |
% Pour Bezout: objectif, renvoyer$\ |
| 30362 |
% {N}{A}{0}{1}{D=r(n)}{B}{1}{0}{q1}{r1}{alpha1=q1}{beta1=1}$\ |
| 30363 |
% {q2}{r2}{alpha2}{beta2}....{qN}{rN=0}{alphaN=A/D}{betaN=B/D}$\ |
| 30364 |
% alpha0=1, beta0=0, alpha(-1)=0, beta(-1)=1 |
| 30365 |
%\end{lverb} |
| 30366 |
% \begin{macrocode} |
| 30367 |
\def\xintBezoutAlgorithm {\romannumeral0\xintbezoutalgorithm }% |
| 30368 |
\def\xintbezoutalgorithm #1% |
| 30369 |
{% |
| 30370 |
\expandafter \XINT_bezalg |
| 30371 |
\expandafter{\romannumeral0\xintiiabs{\xintNum{#1}}}% |
| 30372 |
}% |
| 30373 |
\def\XINT_bezalg #1#2% |
| 30374 |
{% |
| 30375 |
\expandafter\XINT_bezalg_fork\romannumeral0\xintiiabs{\xintNum{#2}}\Z #1\Z |
| 30376 |
}% |
| 30377 |
% \end{macrocode} |
| 30378 |
%\begin{lverb} |
| 30379 |
% Ici #3#4=A, #1#2=B |
| 30380 |
%\end{lverb} |
| 30381 |
% \begin{macrocode} |
| 30382 |
\def\XINT_bezalg_fork #1#2\Z #3#4\Z |
| 30383 |
{% |
| 30384 |
\xint_UDzerofork |
| 30385 |
#1\XINT_bezalg_BisZero |
| 30386 |
#3\XINT_bezalg_AisZero |
| 30387 |
0\XINT_bezalg_a |
| 30388 |
\krof |
| 30389 |
0{#1#2}{#3#4}1001{{#3#4}{#1#2}}{}\Z |
| 30390 |
}% |
| 30391 |
\def\XINT_bezalg_AisZero #1#2#3\Z{{1}{0}{0}{1}{#2}{#2}{1}{0}{0}{0}{0}{1}}% |
| 30392 |
\def\XINT_bezalg_BisZero #1#2#3#4\Z{{1}{0}{0}{1}{#3}{#3}{1}{0}{0}{0}{0}{1}}% |
| 30393 |
% \end{macrocode} |
| 30394 |
%\begin{lverb} |
| 30395 |
% pour préparer l'étape n+1 il faut |
| 30396 |
% {n}{r(n)}{r(n-1)}{alpha(n)}{beta(n)}{alpha(n-1)}{beta(n-1)}& |
| 30397 |
% {{q(n)}{r(n)}{alpha(n)}{beta(n)}}... |
| 30398 |
% division de #3 par #2 |
| 30399 |
%\end{lverb} |
| 30400 |
% \begin{macrocode} |
| 30401 |
\def\XINT_bezalg_a #1#2#3% |
| 30402 |
{% |
| 30403 |
\expandafter\XINT_bezalg_b\the\numexpr #1+\xint_c_i\expandafter.% |
| 30404 |
\romannumeral0\XINT_div_prepare {#2}{#3}{#2}% |
| 30405 |
}% |
| 30406 |
% \end{macrocode} |
| 30407 |
%\begin{lverb} |
| 30408 |
% {n+1}{q(n+1)}{r(n+1)}{r(n)}{alpha(n)}{beta(n)}{alpha(n-1)}{beta(n-1)}... |
| 30409 |
%\end{lverb} |
| 30410 |
% \begin{macrocode} |
| 30411 |
\def\XINT_bezalg_b #1.#2#3#4#5#6#7#8% |
| 30412 |
{% |
| 30413 |
\expandafter\XINT_bezalg_c\expandafter |
| 30414 |
{\romannumeral0\xintiiadd {\xintiiMul {#6}{#2}}{#8}}% |
| 30415 |
{\romannumeral0\xintiiadd {\xintiiMul {#5}{#2}}{#7}}% |
| 30416 |
{#1}{#2}{#3}{#4}{#5}{#6}% |
| 30417 |
}% |
| 30418 |
% \end{macrocode} |
| 30419 |
%\begin{lverb} |
| 30420 |
% {beta(n+1)}{alpha(n+1)}{n+1}{q(n+1)}{r(n+1)}{r(n)}{alpha(n)}{beta(n}} |
| 30421 |
%\end{lverb} |
| 30422 |
% \begin{macrocode} |
| 30423 |
\def\XINT_bezalg_c #1#2#3#4#5#6% |
| 30424 |
{% |
| 30425 |
\expandafter\XINT_bezalg_d\expandafter {#2}{#3}{#4}{#5}{#6}{#1}% |
| 30426 |
}% |
| 30427 |
% \end{macrocode} |
| 30428 |
%\begin{lverb} |
| 30429 |
% {alpha(n+1)}{n+1}{q(n+1)}{r(n+1)}{r(n)}{beta(n+1)} |
| 30430 |
%\end{lverb} |
| 30431 |
% \begin{macrocode} |
| 30432 |
\def\XINT_bezalg_d #1#2#3#4#5#6#7#8% |
| 30433 |
{% |
| 30434 |
\XINT_bezalg_e #4\Z {#2}{#4}{#5}{#1}{#6}{#7}{#8}{{#3}{#4}{#1}{#6}}% |
| 30435 |
}% |
| 30436 |
% \end{macrocode} |
| 30437 |
%\begin{lverb} |
| 30438 |
% r(n+1)\Z {n+1}{r(n+1)}{r(n)}{alpha(n+1)}{beta(n+1)}$\ |
| 30439 |
% {alpha(n)}{beta(n)}{q,r,alpha,beta(n+1)}$\ |
| 30440 |
% Test si r(n+1) est nul. |
| 30441 |
%\end{lverb} |
| 30442 |
% \begin{macrocode} |
| 30443 |
\def\XINT_bezalg_e #1#2\Z |
| 30444 |
{% |
| 30445 |
\xint_gob_til_zero #1\XINT_bezalg_end0\XINT_bezalg_a |
| 30446 |
}% |
| 30447 |
% \end{macrocode} |
| 30448 |
%\begin{lverb} |
| 30449 |
% Ici r(n+1) = 0. On arrête on se prépare à inverser.$\ |
| 30450 |
% {n+1}{r(n+1)}{r(n)}{alpha(n+1)}{beta(n+1)}{alpha(n)}{beta(n)}$\ |
| 30451 |
% {q,r,alpha,beta(n+1)}...{{A}{B}}{}\Z$\ |
| 30452 |
% On veut renvoyer$\ |
| 30453 |
% {N}{A}{0}{1}{D=r(n)}{B}{1}{0}{q1}{r1}{alpha1=q1}{beta1=1}$\ |
| 30454 |
% {q2}{r2}{alpha2}{beta2}....{qN}{rN=0}{alphaN=A/D}{betaN=B/D} |
| 30455 |
%\end{lverb} |
| 30456 |
% \begin{macrocode} |
| 30457 |
\def\XINT_bezalg_end0\XINT_bezalg_a #1#2#3#4#5#6#7#8\Z |
| 30458 |
{% |
| 30459 |
\expandafter\XINT_bezalg_end_a |
| 30460 |
\romannumeral0% |
| 30461 |
\XINT_rord_main {}#8{{#1}{#3}}% |
| 30462 |
\xint: |
| 30463 |
\xint_bye\xint_bye\xint_bye\xint_bye |
| 30464 |
\xint_bye\xint_bye\xint_bye\xint_bye |
| 30465 |
\xint: |
| 30466 |
}% |
| 30467 |
% \end{macrocode} |
| 30468 |
%\begin{lverb} |
| 30469 |
% {N}{D}{A}{B}{q1}{r1}{alpha1=q1}{beta1=1}{q2}{r2}{alpha2}{beta2}$\ |
| 30470 |
% ....{qN}{rN=0}{alphaN=A/D}{betaN=B/D}$\ |
| 30471 |
% On veut renvoyer$\ |
| 30472 |
% {N}{A}{0}{1}{D=r(n)}{B}{1}{0}{q1}{r1}{alpha1=q1}{beta1=1}$\ |
| 30473 |
% {q2}{r2}{alpha2}{beta2}....{qN}{rN=0}{alphaN=A/D}{betaN=B/D} |
| 30474 |
%\end{lverb} |
| 30475 |
% \begin{macrocode} |
| 30476 |
\def\XINT_bezalg_end_a #1#2#3#4{{#1}{#3}{0}{1}{#2}{#4}{1}{0}}% |
| 30477 |
% \end{macrocode} |
| 30478 |
% \subsection{\csh{xintTypesetEuclideAlgorithm}} |
| 30479 |
%\begin{lverb} |
| 30480 |
% TYPESETTING |
| 30481 |
% |
| 30482 |
% Organisation: |
| 30483 |
% |
| 30484 |
% {N}{A}{D}{B}{q1}{r1}{q2}{r2}{q3}{r3}....{qN}{rN=0}$\ |
| 30485 |
% \U1 = N = nombre d'étapes, \U3 = PGCD, \U2 = A, \U4=B |
| 30486 |
% q1 = \U5, q2 = \U7 --> qn = \U<2n+3>, rn = \U<2n+4> |
| 30487 |
% bn = rn. B = r0. A=r(-1) |
| 30488 |
% |
| 30489 |
% r(n-2) = q(n)r(n-1)+r(n) (n e étape) |
| 30490 |
% |
| 30491 |
% \U{2n} = \U{2n+3} \times \U{2n+2} + \U{2n+4}, n e étape. |
| 30492 |
% (avec n entre 1 et N) |
| 30493 |
% |
| 30494 |
% 1.09h uses \xintloop, and \par rather than \endgraf; and \par rather than |
| 30495 |
% \hfill\break |
| 30496 |
%\end{lverb} |
| 30497 |
% \begin{macrocode} |
| 30498 |
\def\xintTypesetEuclideAlgorithm {% |
| 30499 |
\unless\ifdefined\xintAssignArray |
| 30500 |
\errmessage |
| 30501 |
{xintgcd: package xinttools is required for \string\xintTypesetEuclideAlgorithm}% |
| 30502 |
\expandafter\xint_gobble_iii |
| 30503 |
\fi |
| 30504 |
\XINT_TypesetEuclideAlgorithm |
| 30505 |
}% |
| 30506 |
\def\XINT_TypesetEuclideAlgorithm #1#2% |
| 30507 |
{% l'algo remplace #1 et #2 par |#1| et |#2| |
| 30508 |
\par |
| 30509 |
\begingroup |
| 30510 |
\xintAssignArray\xintEuclideAlgorithm {#1}{#2}\to\U |
| 30511 |
\edef\A{\U2}\edef\B{\U4}\edef\N{\U1}% |
| 30512 |
\setbox 0 \vbox{\halign {$##$\cr \A\cr \B \cr}}% |
| 30513 |
\count 255 1 |
| 30514 |
\xintloop |
| 30515 |
\indent\hbox to \wd 0 {\hfil$\U{\numexpr 2*\count255\relax}$}% |
| 30516 |
${} = \U{\numexpr 2*\count255 + 3\relax} |
| 30517 |
\times \U{\numexpr 2*\count255 + 2\relax} |
| 30518 |
+ \U{\numexpr 2*\count255 + 4\relax}$% |
| 30519 |
\ifnum \count255 < \N |
| 30520 |
\par |
| 30521 |
\advance \count255 1 |
| 30522 |
\repeat |
| 30523 |
\endgroup |
| 30524 |
}% |
| 30525 |
% \end{macrocode} |
| 30526 |
% \subsection{\csh{xintTypesetBezoutAlgorithm}} |
| 30527 |
%\begin{lverb} |
| 30528 |
% Pour Bezout on a: |
| 30529 |
% {N}{A}{0}{1}{D=r(n)}{B}{1}{0}{q1}{r1}{alpha1=q1}{beta1=1}$\ |
| 30530 |
% {q2}{r2}{alpha2}{beta2}....{qN}{rN=0}{alphaN=A/D}{betaN=B/D}% |
| 30531 |
% Donc 4N+8 termes: |
| 30532 |
% U1 = N, U2= A, U5=D, U6=B, q1 = U9, qn = U{4n+5}, n au moins 1$\ |
| 30533 |
% rn = U{4n+6}, n au moins -1$\ |
| 30534 |
% alpha(n) = U{4n+7}, n au moins -1$\ |
| 30535 |
% beta(n) = U{4n+8}, n au moins -1 |
| 30536 |
% |
| 30537 |
% 1.09h uses \xintloop, and \par rather than \endgraf; and no more \parindent0pt |
| 30538 |
%\end{lverb} |
| 30539 |
% \begin{macrocode} |
| 30540 |
\def\xintTypesetBezoutAlgorithm {% |
| 30541 |
\unless\ifdefined\xintAssignArray |
| 30542 |
\errmessage |
| 30543 |
{xintgcd: package xinttools is required for \string\xintTypesetBezoutAlgorithm}% |
| 30544 |
\expandafter\xint_gobble_iii |
| 30545 |
\fi |
| 30546 |
\XINT_TypesetBezoutAlgorithm |
| 30547 |
}% |
| 30548 |
\def\XINT_TypesetBezoutAlgorithm #1#2% |
| 30549 |
{% |
| 30550 |
\par |
| 30551 |
\begingroup |
| 30552 |
\xintAssignArray\xintBezoutAlgorithm {#1}{#2}\to\BEZ |
| 30553 |
\edef\A{\BEZ2}\edef\B{\BEZ6}\edef\N{\BEZ1}% A = |#1|, B = |#2| |
| 30554 |
\setbox 0 \vbox{\halign {$##$\cr \A\cr \B \cr}}% |
| 30555 |
\count255 1 |
| 30556 |
\xintloop |
| 30557 |
\indent\hbox to \wd 0 {\hfil$\BEZ{4*\count255 - 2}$}% |
| 30558 |
${} = \BEZ{4*\count255 + 5} |
| 30559 |
\times \BEZ{4*\count255 + 2} |
| 30560 |
+ \BEZ{4*\count255 + 6}$\hfill\break |
| 30561 |
\hbox to \wd 0 {\hfil$\BEZ{4*\count255 +7}$}% |
| 30562 |
${} = \BEZ{4*\count255 + 5} |
| 30563 |
\times \BEZ{4*\count255 + 3} |
| 30564 |
+ \BEZ{4*\count255 - 1}$\hfill\break |
| 30565 |
\hbox to \wd 0 {\hfil$\BEZ{4*\count255 +8}$}% |
| 30566 |
${} = \BEZ{4*\count255 + 5} |
| 30567 |
\times \BEZ{4*\count255 + 4} |
| 30568 |
+ \BEZ{4*\count255 }$ |
| 30569 |
\par |
| 30570 |
\ifnum \count255 < \N |
| 30571 |
\advance \count255 1 |
| 30572 |
\repeat |
| 30573 |
\edef\U{\BEZ{4*\N + 4}}% |
| 30574 |
\edef\V{\BEZ{4*\N + 3}}% |
| 30575 |
\edef\D{\BEZ5}% |
| 30576 |
\ifodd\N |
| 30577 |
$\U\times\A - \V\times \B = -\D$% |
| 30578 |
\else |
| 30579 |
$\U\times\A - \V\times\B = \D$% |
| 30580 |
\fi |
| 30581 |
\par |
| 30582 |
\endgroup |
| 30583 |
}% |
| 30584 |
\XINTrestorecatcodesendinput% |
| 30585 |
% \end{macrocode} |
| 30586 |
% \StoreCodelineNo {xintgcd} |
| 30587 |
% \cleardoublepage\let\xintgcdnameUp\undefined |
| 30588 |
%\gardesactifs |
| 30589 |
%\let</xintgcd>\relax |
| 30590 |
%\let<*xintfrac>\gardesinactifs |
| 30591 |
%</xintgcd>^^A---------------------------------------------------- |
| 30592 |
%<*xintfrac>^^A--------------------------------------------------- |
| 30593 |
%^^A -*- coding: utf-8; mode: doctex; fill-column: 72; sentence-end-double-space: t; eval: (auto-fill-mode -1); fill-paragraph-function: nil; -*- |
| 30594 |
% \clearpage\csname xintfracnameUp\endcsname |
| 30595 |
% \let\MakePrivateLetters\xintMakePrivateLetters |
| 30596 |
% \section{Package \xintfracnameimp implementation} |
| 30597 |
% \RaisedLabel{sec:fracimp} |
| 30598 |
% |
| 30599 |
% \localtableofcontents |
| 30600 |
% |
| 30601 |
% The commenting is currently (\xintdocdate) very sparse. |
| 30602 |
% |
| 30603 |
% \subsection{Catcodes, \protect\eTeX{} and reload detection} |
| 30604 |
% |
| 30605 |
% The code for reload detection was initially copied from \textsc{Heiko |
| 30606 |
% Oberdiek}'s packages, then modified. |
| 30607 |
% |
| 30608 |
% The method for catcodes was also initially directly inspired by these |
| 30609 |
% packages. |
| 30610 |
% |
| 30611 |
% \begin{macrocode} |
| 30612 |
\begingroup\catcode61\catcode48\catcode32=10\relax% |
| 30613 |
\catcode13=5 % ^^M |
| 30614 |
\endlinechar=13 % |
| 30615 |
\catcode123=1 % { |
| 30616 |
\catcode125=2 % } |
| 30617 |
\catcode64=11 % @ |
| 30618 |
\catcode44=12 % , |
| 30619 |
\catcode46=12 % . |
| 30620 |
\catcode58=12 % : |
| 30621 |
\catcode94=7 % ^ |
| 30622 |
\def\empty{}\def\space{ }\newlinechar10 |
| 30623 |
\def\z{\endgroup}% |
| 30624 |
\expandafter\let\expandafter\x\csname [email protected]\endcsname |
| 30625 |
\expandafter\let\expandafter\w\csname [email protected]\endcsname |
| 30626 |
\expandafter\ifx\csname numexpr\endcsname\relax |
| 30627 |
\expandafter\ifx\csname PackageWarningNoLine\endcsname\relax |
| 30628 |
\immediate\write128{^^JPackage xintfrac Warning:^^J% |
| 30629 |
\space\space\space\space |
| 30630 |
\numexpr not available, aborting input.^^J}% |
| 30631 |
\else |
| 30632 |
\PackageWarningNoLine{xintfrac}{\numexpr not available, aborting input}% |
| 30633 |
\fi |
| 30634 |
\def\z{\endgroup\endinput}% |
| 30635 |
\else |
| 30636 |
\ifx\x\relax % plain-TeX, first loading of xintfrac.sty |
| 30637 |
\ifx\w\relax % but xint.sty not yet loaded. |
| 30638 |
\def\z{\endgroup\input xint.sty\relax}% |
| 30639 |
\fi |
| 30640 |
\else |
| 30641 |
\ifx\x\empty % LaTeX, first loading, |
| 30642 |
% variable is initialized, but \ProvidesPackage not yet seen |
| 30643 |
\ifx\w\relax % xint.sty not yet loaded. |
| 30644 |
\def\z{\endgroup\RequirePackage{xint}}% |
| 30645 |
\fi |
| 30646 |
\else |
| 30647 |
\def\z{\endgroup\endinput}% xintfrac already loaded. |
| 30648 |
\fi |
| 30649 |
\fi |
| 30650 |
\fi |
| 30651 |
\z% |
| 30652 |
\XINTsetupcatcodes% defined in xintkernel.sty |
| 30653 |
% \end{macrocode} |
| 30654 |
% \subsection{Package identification} |
| 30655 |
% \begin{macrocode} |
| 30656 |
\XINT_providespackage |
| 30657 |
\ProvidesPackage{xintfrac}% |
| 30658 |
[2025/09/06 v1.4o Expandable operations on fractions (JFB)]% |
| 30659 |
% \end{macrocode} |
| 30660 |
% \subsection{\csh{XINT_cntSgnFork}} |
| 30661 |
%\begin{lverb} |
| 30662 |
% 1.09i. Used internally, #1 must expand to \m@ne, \z@, or \@ne or |
| 30663 |
% equivalent. \XINT_cntSgnFork does not insert a romannumeral stopper. |
| 30664 |
%\end{lverb} |
| 30665 |
% \begin{macrocode} |
| 30666 |
\def\XINT_cntSgnFork #1% |
| 30667 |
{% |
| 30668 |
\ifcase #1\expandafter\xint_secondofthree |
| 30669 |
\or\expandafter\xint_thirdofthree |
| 30670 |
\else\expandafter\xint_firstofthree |
| 30671 |
\fi |
| 30672 |
}% |
| 30673 |
% \end{macrocode} |
| 30674 |
% \subsection{\cshnolabel{xintLen}} |
| 30675 |
%\begin{lverb} |
| 30676 |
% The used formula is disputable, the idea is that A/1 and A should have |
| 30677 |
% same length. Venerable code rewritten for 1.2i, following updates to |
| 30678 |
% \xintLength in xintkernel.sty. And sadly, I forgot on this |
| 30679 |
% occasion that this macro is not supposed to count the sign... Fixed in 1.2k. |
| 30680 |
%\end{lverb} |
| 30681 |
% \begin{macrocode} |
| 30682 |
\def\xintLen {\romannumeral0\xintlen }% |
| 30683 |
\def\xintlen #1% |
| 30684 |
{% |
| 30685 |
\expandafter\XINT_flen\romannumeral0\XINT_infrac {#1}% |
| 30686 |
}% |
| 30687 |
\def\XINT_flen#1{\def\XINT_flen ##1##2##3% |
| 30688 |
{% |
| 30689 |
\expandafter#1% |
| 30690 |
\the\numexpr \XINT_abs##1+% |
| 30691 |
\XINT_len_fork ##2##3\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint: |
| 30692 |
\xint_c_viii\xint_c_vii\xint_c_vi\xint_c_v |
| 30693 |
\xint_c_iv\xint_c_iii\xint_c_ii\xint_c_i\xint_c_\xint_bye-\xint_c_i |
| 30694 |
\relax |
| 30695 |
}}\XINT_flen{ }% |
| 30696 |
% \end{macrocode} |
| 30697 |
% \subsection{\csh{XINT_outfrac}} |
| 30698 |
% \changed{1.06b} |
| 30699 |
%\begin{lverb} |
| 30700 |
% 1.06b version now outputs 0/1[0] and not 0[0] in case of zero. More generally |
| 30701 |
% all macros have been checked in xintfrac, xintseries, xintcfrac, to make sure |
| 30702 |
% the output format for fractions was always A/B[n]. (except \xintIrr, |
| 30703 |
% \xintJrr, \xintRawWithZeros). |
| 30704 |
% |
| 30705 |
% Months later (2014/10/22): perhaps I should document what this macro does |
| 30706 |
% before I forget? from {e}{N}{D} it outputs N/D[e], checking in passing if |
| 30707 |
% D=0 or if N=0. It also makes sure D is not < 0. I am not sure but I don't |
| 30708 |
% think there is any place in the code which could call \XINT_outfrac with a D |
| 30709 |
% < 0, but I should check. |
| 30710 |
%\end{lverb} |
| 30711 |
% \begin{macrocode} |
| 30712 |
\def\XINT_outfrac #1#2#3% |
| 30713 |
{% |
| 30714 |
\ifcase\XINT_cntSgn #3\xint: |
| 30715 |
\expandafter \XINT_outfrac_divisionbyzero |
| 30716 |
\or |
| 30717 |
\expandafter \XINT_outfrac_P |
| 30718 |
\else |
| 30719 |
\expandafter \XINT_outfrac_N |
| 30720 |
\fi |
| 30721 |
{#2}{#3}[#1]% |
| 30722 |
}% |
| 30723 |
\def\XINT_outfrac_divisionbyzero #1#2[#3]% |
| 30724 |
{% |
| 30725 |
\XINT_signalcondition{DivisionByZero}{Division by zero: #1/#2.}{}{ 0/1[0]}% |
| 30726 |
}% |
| 30727 |
\def\XINT_outfrac_P#1{% |
| 30728 |
\def\XINT_outfrac_P ##1##2% |
| 30729 |
{\if0\XINT_Sgn ##1\xint:\expandafter\XINT_outfrac_Zero\fi#1##1/##2}% |
| 30730 |
}\XINT_outfrac_P{ }% |
| 30731 |
\def\XINT_outfrac_Zero #1[#2]{ 0/1[0]}% |
| 30732 |
\def\XINT_outfrac_N #1#2% |
| 30733 |
{% |
| 30734 |
\expandafter\XINT_outfrac_N_a\expandafter |
| 30735 |
{\romannumeral0\XINT_opp #2}{\romannumeral0\XINT_opp #1}% |
| 30736 |
}% |
| 30737 |
\def\XINT_outfrac_N_a #1#2% |
| 30738 |
{% |
| 30739 |
\expandafter\XINT_outfrac_P\expandafter {#2}{#1}% |
| 30740 |
}% |
| 30741 |
% \end{macrocode} |
| 30742 |
% \subsection{\csh{XINT_infrac}} |
| 30743 |
% \added{1.03} |
| 30744 |
%\begin{lverb} |
| 30745 |
% Parses fraction, scientific notation, etc... and produces {n}{A}{B} |
| 30746 |
% corresponding to A/B times 10^n. No reduction to smallest terms. |
| 30747 |
%\end{lverb} |
| 30748 |
% \changed{1.07} |
| 30749 |
%\begin{lverb} |
| 30750 |
% Extended in 1.07 to accept scientific notation on input. With lowercase |
| 30751 |
% e only. The \xintexpr parser does accept uppercase E also. Ah, by the way, |
| 30752 |
% perhaps I should at least say what this macro does? (belated addition |
| 30753 |
% 2014/10/22...), before I forget! It prepares the fraction in the internal |
| 30754 |
% format {exponent}{Numerator}{Denominator} where Denominator is at least 1. |
| 30755 |
%\end{lverb} |
| 30756 |
% \changed[2015/10/09]{1.2} |
| 30757 |
%\begin{lverb} |
| 30758 |
% This venerable macro from the very early days |
| 30759 |
% has gotten a lifting for release 1.2. There were two kinds of issues: |
| 30760 |
% |
| 30761 |
% 1) use of \W, \Z, \T delimiters was very poor choice as this could clash with |
| 30762 |
% user input, |
| 30763 |
% |
| 30764 |
% 2) the new \XINT_frac_gen handles macros (possibly empty) in the input as |
| 30765 |
% general as \A.\Be\C/\D.\Ee\F. The earlier version would not have expanded |
| 30766 |
% the \B or \E$empty: digits after decimal mark were constrained to arise from |
| 30767 |
% expansion of the first token. Thus the 1.03 original code would have |
| 30768 |
% expanded only \A, \D, \C, and \F for this input. |
| 30769 |
% |
| 30770 |
% This reminded me think I should revisit the remaining earlier |
| 30771 |
% portions of code, as I was still learning TeX coding when I wrote them. |
| 30772 |
% |
| 30773 |
% Also I thought about parsing even faster the A/B[N] input, not expanding B, |
| 30774 |
% but this turned out to clash with some established uses in the documentation |
| 30775 |
% such as 1/\xintiiSqr{...}[0]. For the implementation, careful here about |
| 30776 |
% potential brace removals with parameter patterns such as like #1/#2#3[#4]for |
| 30777 |
% example. |
| 30778 |
% |
| 30779 |
% While I was at it 1.2 added \numexpr parsing of the N, which earlier was |
| 30780 |
% restricted to be only explicit digits. I allowed [] with empty N, but the |
| 30781 |
% way I did it in 1.2 with \the\numexpr 0#1 was buggy, as it did not allow #1 |
| 30782 |
% to be a \count for example or itself a \numexpr (although such inputs were |
| 30783 |
% not previously allowed, I later turned out to use them in the code itself, |
| 30784 |
% e.g. the float factorial of version 1.2f). The better way would be |
| 30785 |
% \the\numexpr#1+\xint_c_ but 1.2f finally does only \the\numexpr #1 and #1 is |
| 30786 |
% not allowed to be empty. |
| 30787 |
% |
| 30788 |
% The 1.2 \XINT_frac_gen had two locations with such a problematic \numexpr |
| 30789 |
% 0#1 which I replaced for 1.2f with \numexpr#1+\xint_c_. |
| 30790 |
% |
| 30791 |
% Regarding calling the macro with an argument A[<expression>], a / inthe |
| 30792 |
% expression must be suitably hidden for example in \firstofone type |
| 30793 |
% constructs. |
| 30794 |
% |
| 30795 |
% Note: when the numerator is found to be zero \XINT_infrac *always* returns |
| 30796 |
% {0}{0}{1}. This behaviour must not change because 1.2g \xintFloat and |
| 30797 |
% XINTinFloat (for example) rely upon it: if the denominator on output is not |
| 30798 |
% 1, then \xintFloat assumes that the numerator is not zero. |
| 30799 |
% |
| 30800 |
% As described in the manual, if the input contains a (final) [N] part, it is |
| 30801 |
% assumed that it is in the shape A[N] or A/B[N] with A (and B) not containing |
| 30802 |
% neither decimal mark nor scientific part, moreover B must be positive and A |
| 30803 |
% have at most one minus sign (and no plus sign). Else there will be errors, |
| 30804 |
% for example -0/2[0] would not be recognized as being zero at this stage and |
| 30805 |
% this could cause issues afterwards. When there is no ending [N] part, both |
| 30806 |
% numerator and denominator will be parsed for the more general format |
| 30807 |
% allowing decimal digits and scientific part and possibly multiple leading |
| 30808 |
% signs. |
| 30809 |
%\end{lverb} |
| 30810 |
% \changed{1.2l} |
| 30811 |
%\begin{lverb} |
| 30812 |
% 1.2l fixes frailty of \XINT_infrac (hence basically of all xintfrac macros) |
| 30813 |
% respective to non terminated \numexpr input: \xintRaw{\the\numexpr1} for |
| 30814 |
% example. The issue was that \numexpr sees the / and expands what's next. |
| 30815 |
% But even \numexpr 1// for example creates an error, and to my mind this is |
| 30816 |
% a defect of \numexpr. It should be able to trace back and see that / was |
| 30817 |
% used as delimiter not as operator. Anyway, I thus fixed this problem |
| 30818 |
% belatedly here regarding \XINT_infrac. |
| 30819 |
%\end{lverb} |
| 30820 |
% \changed{1.4l} |
| 30821 |
%\begin{lverb} |
| 30822 |
% Deprecate venerable \XINT_inFrac, whose new name is \xintRawBraced. |
| 30823 |
% Should have been removed then. |
| 30824 |
%\end{lverb} |
| 30825 |
% \changed[2025/07/25]{1.4n} |
| 30826 |
%\begin{lverb} |
| 30827 |
% Remove \XINT_inFrac. |
| 30828 |
%\end{lverb} |
| 30829 |
% \begin{macrocode} |
| 30830 |
\def\XINT_infrac #1% the core xintfrac in-parser; triggered by \romannumeral0 |
| 30831 |
{% |
| 30832 |
\expandafter\XINT_infrac_fork\romannumeral`&&@#1\xint:/\XINT_W[\XINT_W\XINT_T |
| 30833 |
}% |
| 30834 |
\def\XINT_infrac_fork #1[#2% |
| 30835 |
{% |
| 30836 |
\xint_UDXINTWfork |
| 30837 |
#2\XINT_frac_gen % input has no brackets [N] |
| 30838 |
\XINT_W\XINT_infrac_res_a % there is some [N], must be strict A[N] or A/B[N] input |
| 30839 |
\krof |
| 30840 |
#1[#2% |
| 30841 |
}% |
| 30842 |
\def\XINT_infrac_res_a #1% |
| 30843 |
{% |
| 30844 |
\xint_gob_til_zero #1\XINT_infrac_res_zero 0\XINT_infrac_res_b #1% |
| 30845 |
}% |
| 30846 |
% \end{macrocode} |
| 30847 |
%\begin{lverb} |
| 30848 |
% Note that input exponent is here ignored and forced to be zero. |
| 30849 |
%\end{lverb} |
| 30850 |
% \begin{macrocode} |
| 30851 |
\def\XINT_infrac_res_zero 0\XINT_infrac_res_b #1\XINT_T {{0}{0}{1}}% |
| 30852 |
\def\XINT_infrac_res_b #1/#2% |
| 30853 |
{% |
| 30854 |
\xint_UDXINTWfork |
| 30855 |
#2\XINT_infrac_res_ca % it was A[N] input |
| 30856 |
\XINT_W\XINT_infrac_res_cb % it was A/B[N] input |
| 30857 |
\krof |
| 30858 |
#1/#2% |
| 30859 |
}% |
| 30860 |
% \end{macrocode} |
| 30861 |
%\begin{lverb} |
| 30862 |
% An empty [] is not allowed. (this was authorized in 1.2, removed in |
| 30863 |
% 1.2f). |
| 30864 |
%\end{lverb} |
| 30865 |
% \begin{macrocode} |
| 30866 |
\def\XINT_infrac_res_ca #1[#2]\xint:/\XINT_W[\XINT_W\XINT_T |
| 30867 |
{\expandafter{\the\numexpr #2}{#1}{1}}% |
| 30868 |
\def\XINT_infrac_res_cb #1/#2[% |
| 30869 |
{\expandafter\XINT_infrac_res_cc\romannumeral`&&@#2~#1[}% |
| 30870 |
\def\XINT_infrac_res_cc #1~#2[#3]\xint:/\XINT_W[\XINT_W\XINT_T |
| 30871 |
{\expandafter{\the\numexpr #3}{#2}{#1}}% |
| 30872 |
% \end{macrocode} |
| 30873 |
% \subsection{\csh{XINT_frac_gen}} |
| 30874 |
% \changed{1.07} |
| 30875 |
%\begin{lverb} |
| 30876 |
% Extended at to recognize and accept scientific notation both at |
| 30877 |
% the numerator and (possible) denominator. Only a lowercase e will do here, |
| 30878 |
% but uppercase E is possible within an \xintexpr..\relax |
| 30879 |
%\end{lverb} |
| 30880 |
% \changed{1.2} |
| 30881 |
%\begin{lverb} |
| 30882 |
% Completely rewritten. The parsing handles inputs such as |
| 30883 |
% \A.\Be\C/\D.\Ee\F where each of \A, \B, \D, and \E may need f-expansion and |
| 30884 |
% \C and \F will end up in \numexpr. |
| 30885 |
%\end{lverb} |
| 30886 |
% \changed{1.2f} |
| 30887 |
%\begin{lverb} |
| 30888 |
% 1.2f corrects an issue to allow \C and \F to be \count variable (or |
| 30889 |
% expressions with \numexpr): 1.2 did a bad \numexpr0#1 which allowed only |
| 30890 |
% explicit digits for expanded #1. |
| 30891 |
%\end{lverb} |
| 30892 |
% \begin{macrocode} |
| 30893 |
\def\XINT_frac_gen #1/#2% |
| 30894 |
{% |
| 30895 |
\xint_UDXINTWfork |
| 30896 |
#2\XINT_frac_gen_A % there was no / |
| 30897 |
\XINT_W\XINT_frac_gen_B % there was a / |
| 30898 |
\krof |
| 30899 |
#1/#2% |
| 30900 |
}% |
| 30901 |
% \end{macrocode} |
| 30902 |
%\begin{lverb} |
| 30903 |
% Note that #1 is only expanded so far up to decimal mark or "e". |
| 30904 |
%\end{lverb} |
| 30905 |
% \begin{macrocode} |
| 30906 |
\def\XINT_frac_gen_A #1\xint:/\XINT_W [\XINT_W {\XINT_frac_gen_C 0~1!#1ee.\XINT_W }% |
| 30907 |
\def\XINT_frac_gen_B #1/#2\xint:/\XINT_W[%\XINT_W |
| 30908 |
{% |
| 30909 |
\expandafter\XINT_frac_gen_Ba |
| 30910 |
\romannumeral`&&@#2ee.\XINT_W\XINT_Z #1ee.%\XINT_W |
| 30911 |
}% |
| 30912 |
\def\XINT_frac_gen_Ba #1.#2% |
| 30913 |
{% |
| 30914 |
\xint_UDXINTWfork |
| 30915 |
#2\XINT_frac_gen_Bb |
| 30916 |
\XINT_W\XINT_frac_gen_Bc |
| 30917 |
\krof |
| 30918 |
#1.#2% |
| 30919 |
}% |
| 30920 |
\def\XINT_frac_gen_Bb #1e#2e#3\XINT_Z |
| 30921 |
{\expandafter\XINT_frac_gen_C\the\numexpr #2+\xint_c_~#1!}% |
| 30922 |
\def\XINT_frac_gen_Bc #1.#2e% |
| 30923 |
{% |
| 30924 |
\expandafter\XINT_frac_gen_Bd\romannumeral`&&@#2.#1e% |
| 30925 |
}% |
| 30926 |
\def\XINT_frac_gen_Bd #1.#2e#3e#4\XINT_Z |
| 30927 |
{% |
| 30928 |
\expandafter\XINT_frac_gen_C\the\numexpr #3-% |
| 30929 |
\numexpr\XINT_length_loop |
| 30930 |
#1\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint: |
| 30931 |
\xint_c_viii\xint_c_vii\xint_c_vi\xint_c_v |
| 30932 |
\xint_c_iv\xint_c_iii\xint_c_ii\xint_c_i\xint_c_\xint_bye |
| 30933 |
~#2#1!% |
| 30934 |
}% |
| 30935 |
\def\XINT_frac_gen_C #1!#2.#3% |
| 30936 |
{% |
| 30937 |
\xint_UDXINTWfork |
| 30938 |
#3\XINT_frac_gen_Ca |
| 30939 |
\XINT_W\XINT_frac_gen_Cb |
| 30940 |
\krof |
| 30941 |
#1!#2.#3% |
| 30942 |
}% |
| 30943 |
\def\XINT_frac_gen_Ca #1~#2!#3e#4e#5\XINT_T |
| 30944 |
{% |
| 30945 |
\expandafter\XINT_frac_gen_F\the\numexpr #4-#1\expandafter |
| 30946 |
~\romannumeral0\expandafter\XINT_num_cleanup\the\numexpr\XINT_num_loop |
| 30947 |
#2\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint:\Z~#3~% |
| 30948 |
}% |
| 30949 |
\def\XINT_frac_gen_Cb #1.#2e% |
| 30950 |
{% |
| 30951 |
\expandafter\XINT_frac_gen_Cc\romannumeral`&&@#2.#1e% |
| 30952 |
}% |
| 30953 |
\def\XINT_frac_gen_Cc #1.#2~#3!#4e#5e#6\XINT_T |
| 30954 |
{% |
| 30955 |
\expandafter\XINT_frac_gen_F\the\numexpr #5-#2-% |
| 30956 |
\numexpr\XINT_length_loop |
| 30957 |
#1\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint: |
| 30958 |
\xint_c_viii\xint_c_vii\xint_c_vi\xint_c_v |
| 30959 |
\xint_c_iv\xint_c_iii\xint_c_ii\xint_c_i\xint_c_\xint_bye |
| 30960 |
\relax\expandafter~% |
| 30961 |
\romannumeral0\expandafter\XINT_num_cleanup\the\numexpr\XINT_num_loop |
| 30962 |
#3\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint:\Z |
| 30963 |
~#4#1~% |
| 30964 |
}% |
| 30965 |
\def\XINT_frac_gen_F #1~#2% |
| 30966 |
{% |
| 30967 |
\xint_UDzerominusfork |
| 30968 |
#2-\XINT_frac_gen_Gdivbyzero |
| 30969 |
0#2{\XINT_frac_gen_G -{}}% |
| 30970 |
0-{\XINT_frac_gen_G {}#2}% |
| 30971 |
\krof #1~% |
| 30972 |
}% |
| 30973 |
\def\XINT_frac_gen_Gdivbyzero #1~~#2~% |
| 30974 |
{% |
| 30975 |
\expandafter\XINT_frac_gen_Gdivbyzero_a |
| 30976 |
\romannumeral0\expandafter\XINT_num_cleanup\the\numexpr\XINT_num_loop |
| 30977 |
#2\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint:\Z~#1~% |
| 30978 |
}% |
| 30979 |
\def\XINT_frac_gen_Gdivbyzero_a #1~#2~% |
| 30980 |
{% |
| 30981 |
\XINT_signalcondition{DivisionByZero}{Division by zero: #1/0.}{}{{#2}{#1}{0}}% |
| 30982 |
}% |
| 30983 |
\def\XINT_frac_gen_G #1#2#3~#4~#5~% |
| 30984 |
{% |
| 30985 |
\expandafter\XINT_frac_gen_Ga |
| 30986 |
\romannumeral0\expandafter\XINT_num_cleanup\the\numexpr\XINT_num_loop |
| 30987 |
#1#5\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint:\Z~#3~{#2#4}% |
| 30988 |
}% |
| 30989 |
\def\XINT_frac_gen_Ga #1#2~#3~% |
| 30990 |
{% |
| 30991 |
\xint_gob_til_zero #1\XINT_frac_gen_zero 0% |
| 30992 |
{#3}{#1#2}% |
| 30993 |
}% |
| 30994 |
\def\XINT_frac_gen_zero 0#1#2#3{{0}{0}{1}}% |
| 30995 |
% \end{macrocode} |
| 30996 |
% \subsection{\csh{XINT_factortens}} |
| 30997 |
%\begin{lverb} |
| 30998 |
% This is the core macro for \xintREZ. To be used as |
| 30999 |
% \romannumeral0\XINT_factortens{...}. Output is A.N. (formerly {A}{N}) where |
| 31000 |
% A is the integer stripped from trailing zeroes and N is the number of |
| 31001 |
% removed zeroes. Only for positive strict integers! |
| 31002 |
%\end{lverb} |
| 31003 |
% \changed{1.3a} |
| 31004 |
%\begin{lverb} |
| 31005 |
% Completely rewritten at 1.3a to replace a double \xintReverseOrder by a |
| 31006 |
% direct \numexpr governed expansion to the end and back, à la 1.2. I should |
| 31007 |
% comment more... and perhaps improve again in future. |
| 31008 |
% |
| 31009 |
% Testing shows significant gain at 100 digits or more. |
| 31010 |
%\end{lverb} |
| 31011 |
% \begin{macrocode} |
| 31012 |
\def\XINT_factortens #1{\expandafter\XINT_factortens_z |
| 31013 |
\romannumeral0\XINT_factortens_a#1% |
| 31014 |
\XINT_factortens_b123456789.}% |
| 31015 |
\def\XINT_factortens_z.\XINT_factortens_y{ }% |
| 31016 |
\def\XINT_factortens_a #1#2#3#4#5#6#7#8#9% |
| 31017 |
{\expandafter\XINT_factortens_x |
| 31018 |
\the\numexpr 1#1#2#3#4#5#6#7#8#9\XINT_factortens_a}% |
| 31019 |
\def\XINT_factortens_b#1\XINT_factortens_a#2#3.% |
| 31020 |
{.\XINT_factortens_cc 000000000-#2.}% |
| 31021 |
\def\XINT_factortens_x1#1.#2{#2#1}% |
| 31022 |
\def\XINT_factortens_y{.\XINT_factortens_y}% |
| 31023 |
\def\XINT_factortens_cc #1#2#3#4#5#6#7#8#9% |
| 31024 |
{\if#90\xint_dothis |
| 31025 |
{\expandafter\XINT_factortens_d\the\numexpr #8#7#6#5#4#3#2#1\relax |
| 31026 |
\xint_c_i 2345678.}\fi |
| 31027 |
\xint_orthat{\XINT_factortens_yy{#1#2#3#4#5#6#7#8#9}}}% |
| 31028 |
\def\XINT_factortens_yy #1#2.{.\XINT_factortens_y#1.0.}% |
| 31029 |
\def\XINT_factortens_c #1#2#3#4#5#6#7#8#9% |
| 31030 |
{\if#90\xint_dothis |
| 31031 |
{\expandafter\XINT_factortens_d\the\numexpr #8#7#6#5#4#3#2#1\relax |
| 31032 |
\xint_c_i 2345678.}\fi |
| 31033 |
\xint_orthat{.\XINT_factortens_y #1#2#3#4#5#6#7#8#9.}}% |
| 31034 |
\def\XINT_factortens_d #1#2#3#4#5#6#7#8#9% |
| 31035 |
{\if#10\expandafter\XINT_factortens_e\fi |
| 31036 |
\XINT_factortens_f #9#9#8#7#6#5#4#3#2#1.}% |
| 31037 |
\def\XINT_factortens_f #1#2\xint_c_i#3.#4.#5.% |
| 31038 |
{\expandafter\XINT_factortens_g\the\numexpr#1+#5.#3.}% |
| 31039 |
\def\XINT_factortens_g #1.#2.{.\XINT_factortens_y#2.#1.}% |
| 31040 |
\def\XINT_factortens_e #1..#2.% |
| 31041 |
{\expandafter.\expandafter\XINT_factortens_c |
| 31042 |
\the\numexpr\xint_c_ix+#2.}% |
| 31043 |
% \end{macrocode} |
| 31044 |
% \subsection{\xintListWithSep{, } |
| 31045 |
% {\xintApply{ \csh}{{xintEq}{xintNotEq}{xintGt}{xintLt}{xintGtorEq} |
| 31046 |
% {xintLtorEq}{xintIsZero}{xintIsNotZero}{xintOdd} |
| 31047 |
% {xintEven}{xintifSgn}{xintifCmp}{xintifEq}{xintifGt}{xintifLt} |
| 31048 |
% {xintifZero}{xintifNotZero}{xintifOne}{xintifOdd}}}} |
| 31049 |
% |
| 31050 |
%\begin{lverb} |
| 31051 |
% Moved here at 1.3. Formerly these macros were already defined in |
| 31052 |
% xint.sty or even xintcore.sty. They are slim wrappers of macros defined |
| 31053 |
% elsewhere in xintfrac. |
| 31054 |
%\end{lverb} |
| 31055 |
% \begin{macrocode} |
| 31056 |
\def\xintEq {\romannumeral0\xinteq }% |
| 31057 |
\def\xinteq #1#2{\xintifeq{#1}{#2}{1}{0}}% |
| 31058 |
\def\xintNotEq#1#2{\romannumeral0\xintifeq {#1}{#2}{0}{1}}% |
| 31059 |
\def\xintGt {\romannumeral0\xintgt }% |
| 31060 |
\def\xintgt #1#2{\xintifgt{#1}{#2}{1}{0}}% |
| 31061 |
\def\xintLt {\romannumeral0\xintlt }% |
| 31062 |
\def\xintlt #1#2{\xintiflt{#1}{#2}{1}{0}}% |
| 31063 |
\def\xintGtorEq #1#2{\romannumeral0\xintiflt {#1}{#2}{0}{1}}% |
| 31064 |
\def\xintLtorEq #1#2{\romannumeral0\xintifgt {#1}{#2}{0}{1}}% |
| 31065 |
\def\xintIsZero {\romannumeral0\xintiszero }% |
| 31066 |
\def\xintiszero #1{\if0\xintSgn{#1}\xint_afterfi{ 1}\else\xint_afterfi{ 0}\fi}% |
| 31067 |
\def\xintIsNotZero{\romannumeral0\xintisnotzero }% |
| 31068 |
\def\xintisnotzero |
| 31069 |
#1{\if0\xintSgn{#1}\xint_afterfi{ 0}\else\xint_afterfi{ 1}\fi}% |
| 31070 |
\def\xintOdd {\romannumeral0\xintodd }% |
| 31071 |
\def\xintodd #1% |
| 31072 |
{% |
| 31073 |
\ifodd\xintLDg{\xintNum{#1}} %<- intentional space |
| 31074 |
\xint_afterfi{ 1}% |
| 31075 |
\else |
| 31076 |
\xint_afterfi{ 0}% |
| 31077 |
\fi |
| 31078 |
}% |
| 31079 |
\def\xintEven {\romannumeral0\xinteven }% |
| 31080 |
\def\xinteven #1% |
| 31081 |
{% |
| 31082 |
\ifodd\xintLDg{\xintNum{#1}} %<- intentional space |
| 31083 |
\xint_afterfi{ 0}% |
| 31084 |
\else |
| 31085 |
\xint_afterfi{ 1}% |
| 31086 |
\fi |
| 31087 |
}% |
| 31088 |
\def\xintifSgn{\romannumeral0\xintifsgn }% |
| 31089 |
\def\xintifsgn #1% |
| 31090 |
{% |
| 31091 |
\ifcase \xintSgn{#1} |
| 31092 |
\expandafter\xint_stop_atsecondofthree |
| 31093 |
\or\expandafter\xint_stop_atthirdofthree |
| 31094 |
\else\expandafter\xint_stop_atfirstofthree |
| 31095 |
\fi |
| 31096 |
}% |
| 31097 |
\def\xintifCmp{\romannumeral0\xintifcmp }% |
| 31098 |
\def\xintifcmp #1#2% |
| 31099 |
{% |
| 31100 |
\ifcase\xintCmp {#1}{#2} |
| 31101 |
\expandafter\xint_stop_atsecondofthree |
| 31102 |
\or\expandafter\xint_stop_atthirdofthree |
| 31103 |
\else\expandafter\xint_stop_atfirstofthree |
| 31104 |
\fi |
| 31105 |
}% |
| 31106 |
\def\xintifEq {\romannumeral0\xintifeq }% |
| 31107 |
\def\xintifeq #1#2% |
| 31108 |
{% |
| 31109 |
\if0\xintCmp{#1}{#2}% |
| 31110 |
\expandafter\xint_stop_atfirstoftwo |
| 31111 |
\else\expandafter\xint_stop_atsecondoftwo |
| 31112 |
\fi |
| 31113 |
}% |
| 31114 |
\def\xintifGt {\romannumeral0\xintifgt }% |
| 31115 |
\def\xintifgt #1#2% |
| 31116 |
{% |
| 31117 |
\if1\xintCmp{#1}{#2}% |
| 31118 |
\expandafter\xint_stop_atfirstoftwo |
| 31119 |
\else\expandafter\xint_stop_atsecondoftwo |
| 31120 |
\fi |
| 31121 |
}% |
| 31122 |
\def\xintifLt {\romannumeral0\xintiflt }% |
| 31123 |
\def\xintiflt #1#2% |
| 31124 |
{% |
| 31125 |
\ifnum\xintCmp{#1}{#2}<\xint_c_ |
| 31126 |
\expandafter\xint_stop_atfirstoftwo |
| 31127 |
\else \expandafter\xint_stop_atsecondoftwo |
| 31128 |
\fi |
| 31129 |
}% |
| 31130 |
\def\xintifZero {\romannumeral0\xintifzero }% |
| 31131 |
\def\xintifzero #1% |
| 31132 |
{% |
| 31133 |
\if0\xintSgn{#1}% |
| 31134 |
\expandafter\xint_stop_atfirstoftwo |
| 31135 |
\else |
| 31136 |
\expandafter\xint_stop_atsecondoftwo |
| 31137 |
\fi |
| 31138 |
}% |
| 31139 |
\def\xintifNotZero{\romannumeral0\xintifnotzero }% |
| 31140 |
\def\xintifnotzero #1% |
| 31141 |
{% |
| 31142 |
\if0\xintSgn{#1}% |
| 31143 |
\expandafter\xint_stop_atsecondoftwo |
| 31144 |
\else |
| 31145 |
\expandafter\xint_stop_atfirstoftwo |
| 31146 |
\fi |
| 31147 |
}% |
| 31148 |
\def\xintifOne {\romannumeral0\xintifone }% |
| 31149 |
\def\xintifone #1% |
| 31150 |
{% |
| 31151 |
\if1\xintIsOne{#1}% |
| 31152 |
\expandafter\xint_stop_atfirstoftwo |
| 31153 |
\else |
| 31154 |
\expandafter\xint_stop_atsecondoftwo |
| 31155 |
\fi |
| 31156 |
}% |
| 31157 |
\def\xintifOdd {\romannumeral0\xintifodd }% |
| 31158 |
\def\xintifodd #1% |
| 31159 |
{% |
| 31160 |
\if\xintOdd{#1}1% |
| 31161 |
\expandafter\xint_stop_atfirstoftwo |
| 31162 |
\else |
| 31163 |
\expandafter\xint_stop_atsecondoftwo |
| 31164 |
\fi |
| 31165 |
}% |
| 31166 |
% \end{macrocode} |
| 31167 |
% \subsection{\csh{xintRaw}} |
| 31168 |
% \added{1.07} |
| 31169 |
%\begin{lverb} |
| 31170 |
% 1.07: this macro simply prints in a user readable form the fraction after its |
| 31171 |
% initial scanning. Useful when put inside braces in an \xintexpr, when the |
| 31172 |
% input is not yet in the A/B[n] form. |
| 31173 |
%\end{lverb} |
| 31174 |
% \begin{macrocode} |
| 31175 |
\def\xintRaw {\romannumeral0\xintraw }% |
| 31176 |
\def\xintraw |
| 31177 |
{% |
| 31178 |
\expandafter\XINT_raw\romannumeral0\XINT_infrac |
| 31179 |
}% |
| 31180 |
\def\XINT_raw #1#2#3{ #2/#3[#1]}% |
| 31181 |
% \end{macrocode} |
| 31182 |
% \subsection{\csh{xintRawBraced}} |
| 31183 |
% \added{1.4l} |
| 31184 |
%\begin{lverb} |
| 31185 |
% User level interface to core \romannumeral0\XINT_infrac. Replaces |
| 31186 |
% \XINT_inFrac which was defined but nowhere used by the xint packages. |
| 31187 |
%\end{lverb} |
| 31188 |
% \begin{macrocode} |
| 31189 |
\def\xintRawBraced {\romannumeral0\xintrawbraced }% |
| 31190 |
\let\xintrawbraced \XINT_infrac |
| 31191 |
% \end{macrocode} |
| 31192 |
% \subsection{\csh{xintiLogTen}} |
| 31193 |
% \added{1.3e} |
| 31194 |
%\begin{lverb} |
| 31195 |
% The exponent a, such that 10^a<= abs(x) < 10^(a+1). No rounding done on x, |
| 31196 |
% handled as an exact fraction. |
| 31197 |
%\end{lverb} |
| 31198 |
% \begin{macrocode} |
| 31199 |
\def\xintiLogTen {\the\numexpr\xintilogten}% |
| 31200 |
\def\xintilogten |
| 31201 |
{% |
| 31202 |
\expandafter\XINT_ilogten\romannumeral0\xintraw |
| 31203 |
}% |
| 31204 |
\def\XINT_ilogten #1% |
| 31205 |
{% |
| 31206 |
\xint_UDzerominusfork |
| 31207 |
0#1\XINT_ilogten_p |
| 31208 |
#1-\XINT_ilogten_z |
| 31209 |
0-{\XINT_ilogten_p#1}% |
| 31210 |
\krof |
| 31211 |
}% |
| 31212 |
\def\XINT_ilogten_z #1[#2]{-"7FFF8000\relax}% |
| 31213 |
\def\XINT_ilogten_p #1/#2[#3]% |
| 31214 |
{% |
| 31215 |
#3+\expandafter\XINT_ilogten_a |
| 31216 |
\the\numexpr\xintLength{#1}\expandafter.\the\numexpr\xintLength{#2}.#1.#2.% |
| 31217 |
}% |
| 31218 |
\def\XINT_ilogten_a #1.#2.% |
| 31219 |
{% |
| 31220 |
#1-#2\ifnum#1>#2 |
| 31221 |
\expandafter\XINT_ilogten_aa |
| 31222 |
\else |
| 31223 |
\expandafter\XINT_ilogten_ab |
| 31224 |
\fi #1.#2.% |
| 31225 |
}% |
| 31226 |
\def\XINT_ilogten_aa #1.#2.#3.#4.% |
| 31227 |
{% |
| 31228 |
\xintiiifLt{#3}{\XINT_dsx_addzerosnofuss{#1-#2}#4;}{-1}{}\relax |
| 31229 |
}% |
| 31230 |
\def\XINT_ilogten_ab #1.#2.#3.#4.% |
| 31231 |
{% |
| 31232 |
\xintiiifLt{\XINT_dsx_addzerosnofuss{#2-#1}#3;}{#4}{-1}{}\relax |
| 31233 |
}% |
| 31234 |
% \end{macrocode} |
| 31235 |
% \subsection{\csh{xintPRaw}} |
| 31236 |
% \added{1.09b} |
| 31237 |
% \begin{macrocode} |
| 31238 |
\def\xintPRaw {\romannumeral0\xintpraw }% |
| 31239 |
\def\xintpraw |
| 31240 |
{% |
| 31241 |
\expandafter\XINT_praw\romannumeral0\XINT_infrac |
| 31242 |
}% |
| 31243 |
\def\XINT_praw #1% |
| 31244 |
{% |
| 31245 |
\ifnum #1=\xint_c_ \expandafter\XINT_praw_a\fi \XINT_praw_A {#1}% |
| 31246 |
}% |
| 31247 |
\def\XINT_praw_A #1#2#3% |
| 31248 |
{% |
| 31249 |
\if\XINT_isOne{#3}1\expandafter\xint_firstoftwo |
| 31250 |
\else\expandafter\xint_secondoftwo |
| 31251 |
\fi { #2[#1]}{ #2/#3[#1]}% |
| 31252 |
}% |
| 31253 |
\def\XINT_praw_a\XINT_praw_A #1#2#3% |
| 31254 |
{% |
| 31255 |
\if\XINT_isOne{#3}1\expandafter\xint_firstoftwo |
| 31256 |
\else\expandafter\xint_secondoftwo |
| 31257 |
\fi { #2}{ #2/#3}% |
| 31258 |
}% |
| 31259 |
% \end{macrocode} |
| 31260 |
% \subsection{\csh{xintSPRaw}} |
| 31261 |
%\begin{lverb} |
| 31262 |
% This private macro was for internal usage by \xinttheexpr. |
| 31263 |
% It got moved here |
| 31264 |
% at 1.4 and is not used anymore by the package. |
| 31265 |
% |
| 31266 |
% It checks if input has a [N] part, if yes uses \xintPRaw, else |
| 31267 |
% simply lets the input pass through as is. |
| 31268 |
%\end{lverb} |
| 31269 |
% \begin{macrocode} |
| 31270 |
\def\xintSPRaw {\romannumeral0\xintspraw }% |
| 31271 |
\def\xintspraw #1{\expandafter\XINT_spraw\romannumeral`&&@#1[\W]}% |
| 31272 |
\def\XINT_spraw #1[#2#3]{\xint_gob_til_W #2\XINT_spraw_a\W\XINT_spraw_p #1[#2#3]}% |
| 31273 |
\def\XINT_spraw_a\W\XINT_spraw_p #1[\W]{ #1}% |
| 31274 |
\def\XINT_spraw_p #1[\W]{\xintpraw {#1}}% |
| 31275 |
% \end{macrocode} |
| 31276 |
% \subsection{\csh{xintFracToSci}} |
| 31277 |
% \added{1.4l} |
| 31278 |
%\begin{lverb} |
| 31279 |
% The macro with this name which was added here at 1.4 then had |
| 31280 |
% various changes and finally was moved to $xintexprnameimp at 1.4k |
| 31281 |
% is now called there |
| 31282 |
% \xint_FracToSci_x and is private. The present macro is public and |
| 31283 |
% behaves like the other $xintfracnameimp macros: f-expandable and |
| 31284 |
% accepts general input. Its output is exactly the same as |
| 31285 |
% \xint_FracToSci_x for same inputs, with the exception of the empty |
| 31286 |
% input which \xintFracToSci will output as 0 but \xint_FracToSci_x |
| 31287 |
% as empty. But the latter is not used by \xinteval for an empty |
| 31288 |
% leaf as it employs then \xintexprEmptyItem. |
| 31289 |
%\end{lverb} |
| 31290 |
% \begin{macrocode} |
| 31291 |
\def\xintFracToSci{\romannumeral0\xintfractosci}% |
| 31292 |
\def\xintfractosci#1{\expandafter\XINT_fractosci\romannumeral0\xintraw{#1}}% |
| 31293 |
\def\XINT_fractosci#1#2/#3[#4]{\expanded{ % |
| 31294 |
\ifnum#4=\xint_c_ #1#2\else |
| 31295 |
\romannumeral0\expandafter\XINT_pfloat_a_fork\romannumeral0\xintrez{#1#2[#4]}% |
| 31296 |
\fi |
| 31297 |
\if\XINT_isOne{#3}1\else\if#10\else/#3\fi\fi}% |
| 31298 |
}% |
| 31299 |
% \end{macrocode} |
| 31300 |
% \subsection{\csh{xintFracToDecimal}} |
| 31301 |
% \added{1.4l} |
| 31302 |
%\begin{lverb} |
| 31303 |
% The macro with this name which was added at 1.4k to |
| 31304 |
% $xintexprnameimp has been removed. The public variant here |
| 31305 |
% behaves like the other |
| 31306 |
% $xintfracnameimp macros: f-expandable and accepts general input. |
| 31307 |
%\end{lverb} |
| 31308 |
% \begin{macrocode} |
| 31309 |
\def\xintFracToDecimal{\romannumeral0\xintfractodecimal}% |
| 31310 |
\def\xintfractodecimal#1{\expandafter\XINT_fractodecimal\romannumeral0\xintraw{#1}}% |
| 31311 |
\def\XINT_fractodecimal #1#2/#3[#4]{\expanded{ % |
| 31312 |
\ifnum#4=\xint_c_ #1#2\else |
| 31313 |
\romannumeral0\expandafter\XINT_dectostr\romannumeral0\xintrez{#1#2[#4]}% |
| 31314 |
\fi |
| 31315 |
\if\XINT_isOne{#3}1\else\if#10\else/#3\fi\fi}% |
| 31316 |
}% |
| 31317 |
% \end{macrocode} |
| 31318 |
% \subsection{\csh{xintRawWithZeros}} |
| 31319 |
%\begin{lverb} |
| 31320 |
% This was called \xintRaw in versions earlier than 1.07 |
| 31321 |
%\end{lverb} |
| 31322 |
% \begin{macrocode} |
| 31323 |
\def\xintRawWithZeros {\romannumeral0\xintrawwithzeros }% |
| 31324 |
\def\xintrawwithzeros |
| 31325 |
{% |
| 31326 |
\expandafter\XINT_rawz_fork\romannumeral0\XINT_infrac |
| 31327 |
}% |
| 31328 |
\def\XINT_rawz_fork #1% |
| 31329 |
{% |
| 31330 |
\ifnum#1<\xint_c_ |
| 31331 |
\expandafter\XINT_rawz_Ba |
| 31332 |
\else |
| 31333 |
\expandafter\XINT_rawz_A |
| 31334 |
\fi |
| 31335 |
#1.% |
| 31336 |
}% |
| 31337 |
\def\XINT_rawz_A #1.#2#3{\XINT_dsx_addzeros{#1}#2;/#3}% |
| 31338 |
\def\XINT_rawz_Ba -#1.#2#3{\expandafter\XINT_rawz_Bb |
| 31339 |
\expandafter{\romannumeral0\XINT_dsx_addzeros{#1}#3;}{#2}}% |
| 31340 |
\def\XINT_rawz_Bb #1#2{ #2/#1}% |
| 31341 |
% \end{macrocode} |
| 31342 |
% \subsection{\csh{xintDecToString}} |
| 31343 |
% \added{1.3} |
| 31344 |
%\begin{lverb} |
| 31345 |
% This is a backport from polexpr 0.4. It is definitely not in |
| 31346 |
% final form, consider it to be an unstable macro. |
| 31347 |
%\end{lverb} |
| 31348 |
% \begin{macrocode} |
| 31349 |
\def\xintDecToString{\romannumeral0\xintdectostring}% |
| 31350 |
\def\xintdectostring#1{\expandafter\XINT_dectostr\romannumeral0\xintraw{#1}}% |
| 31351 |
\def\XINT_dectostr #1/#2[#3]{\xintiiifZero {#1}% |
| 31352 |
\XINT_dectostr_z |
| 31353 |
{\if1\XINT_isOne{#2}\expandafter\XINT_dectostr_a |
| 31354 |
\else\expandafter\XINT_dectostr_b |
| 31355 |
\fi}% |
| 31356 |
#1/#2[#3]% |
| 31357 |
}% |
| 31358 |
\def\XINT_dectostr_z#1[#2]{ 0}% |
| 31359 |
\def\XINT_dectostr_a#1/#2[#3]{% |
| 31360 |
\ifnum#3<\xint_c_\xint_dothis{\xinttrunc{-#3}{#1[#3]}}\fi |
| 31361 |
\xint_orthat{\xintiie{#1}{#3}}% |
| 31362 |
}% |
| 31363 |
\def\XINT_dectostr_b#1/#2[#3]{% just to handle this somehow |
| 31364 |
\ifnum#3<\xint_c_\xint_dothis{\xinttrunc{-#3}{#1[#3]}/#2}\fi |
| 31365 |
\xint_orthat{\xintiie{#1}{#3}/#2}% |
| 31366 |
}% |
| 31367 |
% \end{macrocode} |
| 31368 |
% \subsection{\csh{xintDecToStringREZ}} |
| 31369 |
% \added{1.4e} |
| 31370 |
%\begin{lverb} |
| 31371 |
% And I took this opportunity to improve documentation in manual. |
| 31372 |
%\end{lverb} |
| 31373 |
% \begin{macrocode} |
| 31374 |
\def\xintDecToStringREZ{\romannumeral0\xintdectostringrez}% |
| 31375 |
\def\xintdectostringrez#1{\expandafter\XINT_dectostr\romannumeral0\xintrez{#1}}% |
| 31376 |
% \end{macrocode} |
| 31377 |
% \subsection{\csh{xintFloor}, \csh{xintiFloor}} |
| 31378 |
% \added{1.09a} |
| 31379 |
%\begin{lverb} |
| 31380 |
% 1.1 for \xintiFloor/\xintFloor. Not efficient if big negative |
| 31381 |
% decimal exponent. Also sub-efficient if big positive decimal exponent. |
| 31382 |
%\end{lverb} |
| 31383 |
% \begin{macrocode} |
| 31384 |
\def\xintFloor {\romannumeral0\xintfloor }% |
| 31385 |
\def\xintfloor #1% devrais-je faire \xintREZ? |
| 31386 |
{\expandafter\XINT_ifloor \romannumeral0\xintrawwithzeros {#1}./1[0]}% |
| 31387 |
\def\xintiFloor {\romannumeral0\xintifloor }% |
| 31388 |
\def\xintifloor #1% |
| 31389 |
{\expandafter\XINT_ifloor \romannumeral0\xintrawwithzeros {#1}.}% |
| 31390 |
\def\XINT_ifloor #1/#2.{\xintiiquo {#1}{#2}}% |
| 31391 |
% \end{macrocode} |
| 31392 |
% \subsection{\csh{xintCeil}, \csh{xintiCeil}} |
| 31393 |
% \added{1.09a} |
| 31394 |
% \begin{macrocode} |
| 31395 |
\def\xintCeil {\romannumeral0\xintceil }% |
| 31396 |
\def\xintceil #1{\xintiiopp {\xintFloor {\xintOpp{#1}}}}% |
| 31397 |
\def\xintiCeil {\romannumeral0\xinticeil }% |
| 31398 |
\def\xinticeil #1{\xintiiopp {\xintiFloor {\xintOpp{#1}}}}% |
| 31399 |
% \end{macrocode} |
| 31400 |
% \subsection{\csh{xintNumerator}} |
| 31401 |
% \begin{macrocode} |
| 31402 |
\def\xintNumerator {\romannumeral0\xintnumerator }% |
| 31403 |
\def\xintnumerator |
| 31404 |
{% |
| 31405 |
\expandafter\XINT_numer\romannumeral0\XINT_infrac |
| 31406 |
}% |
| 31407 |
\def\XINT_numer #1% |
| 31408 |
{% |
| 31409 |
\ifcase\XINT_cntSgn #1\xint: |
| 31410 |
\expandafter\XINT_numer_B |
| 31411 |
\or |
| 31412 |
\expandafter\XINT_numer_A |
| 31413 |
\else |
| 31414 |
\expandafter\XINT_numer_B |
| 31415 |
\fi |
| 31416 |
{#1}% |
| 31417 |
}% |
| 31418 |
\def\XINT_numer_A #1#2#3{\XINT_dsx_addzeros{#1}#2;}% |
| 31419 |
\def\XINT_numer_B #1#2#3{ #2}% |
| 31420 |
% \end{macrocode} |
| 31421 |
% \subsection{\csh{xintDenominator}} |
| 31422 |
% \begin{macrocode} |
| 31423 |
\def\xintDenominator {\romannumeral0\xintdenominator }% |
| 31424 |
\def\xintdenominator |
| 31425 |
{% |
| 31426 |
\expandafter\XINT_denom_fork\romannumeral0\XINT_infrac |
| 31427 |
}% |
| 31428 |
\def\XINT_denom_fork #1% |
| 31429 |
{% |
| 31430 |
\ifnum#1<\xint_c_ |
| 31431 |
\expandafter\XINT_denom_B |
| 31432 |
\else |
| 31433 |
\expandafter\XINT_denom_A |
| 31434 |
\fi |
| 31435 |
#1.% |
| 31436 |
}% |
| 31437 |
\def\XINT_denom_A #1.#2#3{ #3}% |
| 31438 |
\def\XINT_denom_B -#1.#2#3{\XINT_dsx_addzeros{#1}#3;}% |
| 31439 |
% \end{macrocode} |
| 31440 |
% \subsection{\csh{xintTeXFrac}} |
| 31441 |
% \added{1.03} |
| 31442 |
%\begin{lverb} |
| 31443 |
% Useless typesetting macro. |
| 31444 |
%\end{lverb} |
| 31445 |
% \changed[2021/05/24]{1.4g} |
| 31446 |
%\begin{lverb} |
| 31447 |
% Renamed from \xintFrac. |
| 31448 |
%\end{lverb} |
| 31449 |
% \changed{1.4m} |
| 31450 |
% The old name now raises an error, not a warning. |
| 31451 |
% \begin{macrocode} |
| 31452 |
\ifdefined\PackageWarning |
| 31453 |
\def\xintfracTeXDeprecation#1#2{% |
| 31454 |
\PackageWarning{xintfrac}{\string#1 is deprecated. Use \string#2\MessageBreak |
| 31455 |
to suppress this warning}#2% |
| 31456 |
}% |
| 31457 |
\else |
| 31458 |
\edef\xintfracTeXDeprecation#1#2{{\newlinechar10 |
| 31459 |
\immediate\noexpand\write128{&&JPackage xintfrac Warning: \noexpand\string#1 is |
| 31460 |
deprecated. Use \noexpand\string#2&&J% |
| 31461 |
(xintfrac)\xintReplicate{16}{ }to suppress this warning |
| 31462 |
on input line \noexpand\the\inputlineno.&&J}}#2% |
| 31463 |
}% |
| 31464 |
\fi |
| 31465 |
\ifdefined\PackageError |
| 31466 |
\def\xintfracTeXError#1#2{% |
| 31467 |
\PackageError{xintfrac}{\string#1 has been removed.\MessageBreak |
| 31468 |
Use \string#2 to suppress this error}% |
| 31469 |
{I will fix it for now if you hit the `Return' key.}#2% |
| 31470 |
}% |
| 31471 |
\else |
| 31472 |
\edef\xintfracTeXError#1#2{{\newlinechar10 |
| 31473 |
\errhelp{I will fix it for now if you hit the `Return' key.}% |
| 31474 |
\errmessage{Package xintfrac Error: \noexpand\string#1 has been removed.&&J% |
| 31475 |
(xintfrac)\xintReplicate{16}{ }Use \noexpand\string#2 to suppress this error}}#2% |
| 31476 |
}% |
| 31477 |
\fi |
| 31478 |
\def\xintFrac {\xintfracTeXError\xintFrac\xintTeXFrac}% |
| 31479 |
\def\xintTeXFrac{\romannumeral0\xintfrac }% |
| 31480 |
\def\xintfrac #1% |
| 31481 |
{% |
| 31482 |
\expandafter\XINT_fracfrac_A\romannumeral0\XINT_infrac {#1}% |
| 31483 |
}% |
| 31484 |
\def\XINT_fracfrac_A #1{\XINT_fracfrac_B #1\Z }% |
| 31485 |
\catcode`^=7 |
| 31486 |
\def\XINT_fracfrac_B #1#2\Z |
| 31487 |
{% |
| 31488 |
\xint_gob_til_zero #1\XINT_fracfrac_C 0\XINT_fracfrac_D {10^{#1#2}}% |
| 31489 |
}% |
| 31490 |
\def\XINT_fracfrac_C 0\XINT_fracfrac_D #1#2#3% |
| 31491 |
{% |
| 31492 |
\if1\XINT_isOne {#3}% |
| 31493 |
\xint_afterfi {\expandafter\xint_stop_atfirstoftwo\xint_gobble_ii }% |
| 31494 |
\fi |
| 31495 |
\space |
| 31496 |
\frac {#2}{#3}% |
| 31497 |
}% |
| 31498 |
\def\XINT_fracfrac_D #1#2#3% |
| 31499 |
{% |
| 31500 |
\if1\XINT_isOne {#3}\XINT_fracfrac_E\fi |
| 31501 |
\space |
| 31502 |
\frac {#2}{#3}#1% |
| 31503 |
}% |
| 31504 |
\def\XINT_fracfrac_E \fi\space\frac #1#2{\fi \space #1\cdot }% |
| 31505 |
% \end{macrocode} |
| 31506 |
% \subsection{\csh{xintTeXsignedFrac}} |
| 31507 |
% \changed[2021/05/24]{1.4g} |
| 31508 |
%\begin{lverb} |
| 31509 |
% Renamed from \xintSignedFrac. |
| 31510 |
%\end{lverb} |
| 31511 |
% \changed{1.4m} |
| 31512 |
% The old name now raises an error, not a warning. |
| 31513 |
% \begin{macrocode} |
| 31514 |
\def\xintSignedFrac {\xintfracTeXError\xintSignedFrac\xintTeXsignedFrac}% |
| 31515 |
\def\xintTeXsignedFrac{\romannumeral0\xintsignedfrac }% |
| 31516 |
\def\xintsignedfrac #1% |
| 31517 |
{% |
| 31518 |
\expandafter\XINT_sgnfrac_a\romannumeral0\XINT_infrac {#1}% |
| 31519 |
}% |
| 31520 |
\def\XINT_sgnfrac_a #1#2% |
| 31521 |
{% |
| 31522 |
\XINT_sgnfrac_b #2\Z {#1}% |
| 31523 |
}% |
| 31524 |
\def\XINT_sgnfrac_b #1% |
| 31525 |
{% |
| 31526 |
\xint_UDsignfork |
| 31527 |
#1\XINT_sgnfrac_N |
| 31528 |
-{\XINT_sgnfrac_P #1}% |
| 31529 |
\krof |
| 31530 |
}% |
| 31531 |
\def\XINT_sgnfrac_P #1\Z #2% |
| 31532 |
{% |
| 31533 |
\XINT_fracfrac_A {#2}{#1}% |
| 31534 |
}% |
| 31535 |
\def\XINT_sgnfrac_N |
| 31536 |
{% |
| 31537 |
\expandafter-\romannumeral0\XINT_sgnfrac_P |
| 31538 |
}% |
| 31539 |
% \end{macrocode} |
| 31540 |
% \subsection{\csh{xintTeXFromSci}} |
| 31541 |
% \added{1.4g} |
| 31542 |
%\begin{lverb} |
| 31543 |
% The main problem is how to name this and related macros. |
| 31544 |
% |
| 31545 |
% I use \expanded here, as \xintFracToSci is not f-expandable. |
| 31546 |
% |
| 31547 |
% Some complications as I want this to be usable on output of \xintFracToSci |
| 31548 |
% hence need to handle the case of a /B. After some hesitations I ended with |
| 31549 |
% the following which looks reasonable: |
| 31550 |
%(- if no scientific part, use \frac (or \over) for A/B |
| 31551 |
%:- if scientific part, postfix /B as \cdot B^{-1} |
| 31552 |
%) |
| 31553 |
%\end{lverb} |
| 31554 |
% \changed{1.4l} |
| 31555 |
%\begin{lverb} |
| 31556 |
% Suppress external \expanded. Keep internal one. |
| 31557 |
% |
| 31558 |
% Rename \xintTeXFromSci from \xintTeXfromSci. Keep deprecated old name |
| 31559 |
% for the moment. |
| 31560 |
% |
| 31561 |
% Add \xintTeXFromScifracmacro. Make it \protected. |
| 31562 |
% |
| 31563 |
% Nota bene: catcode of ^ is normal one here (else nothing would work). |
| 31564 |
%\end{lverb} |
| 31565 |
% \begin{macrocode} |
| 31566 |
\def\xintTeXfromSci{\xintfracTeXDeprecated\xintTeXfromSci\xintTeXFromSci}% |
| 31567 |
\def\xintTeXFromSci#1% |
| 31568 |
{% |
| 31569 |
\expandafter\XINT_texfromsci\expanded{#1}/\relax/\xint: |
| 31570 |
}% |
| 31571 |
\def\XINT_texfromsci #1/#2#3/#4\xint: |
| 31572 |
{% |
| 31573 |
\XINT_texfromsci_a #1e\relax e\xint: |
| 31574 |
{\ifx\relax#2\xint_dothis\xint_firstofone\fi |
| 31575 |
\xint_orthat{\xintTeXFromScifracmacro{#2#3}}}% |
| 31576 |
{\unless\ifx\relax#2\cdot{#2#3}^{-1}\fi}% |
| 31577 |
}% |
| 31578 |
\def\XINT_texfromsci_a #1e#2#3e#4\xint:#5#6% |
| 31579 |
{% |
| 31580 |
\ifx\relax#2#5{#1}\else#1\cdot10^{#2#3}#6\fi |
| 31581 |
}% |
| 31582 |
\ifdefined\frac |
| 31583 |
\protected\def\xintTeXFromScifracmacro#1#2{\frac{#2}{#1}}% |
| 31584 |
\else |
| 31585 |
\protected\def\xintTeXFromScifracmacro#1#2{{#2\over#1}}% |
| 31586 |
\fi |
| 31587 |
% \end{macrocode} |
| 31588 |
% \subsection{\csh{xintTeXOver}} |
| 31589 |
% \changed[2021/05/24]{1.4g} |
| 31590 |
%\begin{lverb} |
| 31591 |
% Renamed from \xintFwOver. |
| 31592 |
%\end{lverb} |
| 31593 |
% \changed{1.4m} |
| 31594 |
% The old name now raises an error, not a warning. |
| 31595 |
% \begin{macrocode} |
| 31596 |
\def\xintFwOver {\xintfracTeXError\xintFwOver\xintTeXOver}% |
| 31597 |
\def\xintTeXOver{\romannumeral0\xintfwover }% |
| 31598 |
\def\xintfwover #1% |
| 31599 |
{% |
| 31600 |
\expandafter\XINT_fwover_A\romannumeral0\XINT_infrac {#1}% |
| 31601 |
}% |
| 31602 |
\def\XINT_fwover_A #1{\XINT_fwover_B #1\Z }% |
| 31603 |
\def\XINT_fwover_B #1#2\Z |
| 31604 |
{% |
| 31605 |
\xint_gob_til_zero #1\XINT_fwover_C 0\XINT_fwover_D {10^{#1#2}}% |
| 31606 |
}% |
| 31607 |
\catcode`^=11 |
| 31608 |
\def\XINT_fwover_C #1#2#3#4#5% |
| 31609 |
{% |
| 31610 |
\if0\XINT_isOne {#5}\xint_afterfi { {#4\over #5}}% |
| 31611 |
\else\xint_afterfi { #4}% |
| 31612 |
\fi |
| 31613 |
}% |
| 31614 |
\def\XINT_fwover_D #1#2#3% |
| 31615 |
{% |
| 31616 |
\if0\XINT_isOne {#3}\xint_afterfi { {#2\over #3}}% |
| 31617 |
\else\xint_afterfi { #2\cdot }% |
| 31618 |
\fi |
| 31619 |
#1% |
| 31620 |
}% |
| 31621 |
% \end{macrocode} |
| 31622 |
% \subsection{\csh{xintTeXsignedOver}} |
| 31623 |
% \changed[2021/05/24]{1.4g} |
| 31624 |
%\begin{lverb} |
| 31625 |
% Renamed from \xintSignedFwOver. |
| 31626 |
%\end{lverb} |
| 31627 |
% \changed{1.4m} |
| 31628 |
% The old name now raises an error, not a warning. |
| 31629 |
% \begin{macrocode} |
| 31630 |
\def\xintSignedFwOver {\xintfracTeXError\xintSignedFwOver\xintTeXsignedOver}% |
| 31631 |
\def\xintTeXsignedOver{\romannumeral0\xintsignedfwover }% |
| 31632 |
\def\xintsignedfwover #1% |
| 31633 |
{% |
| 31634 |
\expandafter\XINT_sgnfwover_a\romannumeral0\XINT_infrac {#1}% |
| 31635 |
}% |
| 31636 |
\def\XINT_sgnfwover_a #1#2% |
| 31637 |
{% |
| 31638 |
\XINT_sgnfwover_b #2\Z {#1}% |
| 31639 |
}% |
| 31640 |
\def\XINT_sgnfwover_b #1% |
| 31641 |
{% |
| 31642 |
\xint_UDsignfork |
| 31643 |
#1\XINT_sgnfwover_N |
| 31644 |
-{\XINT_sgnfwover_P #1}% |
| 31645 |
\krof |
| 31646 |
}% |
| 31647 |
\def\XINT_sgnfwover_P #1\Z #2% |
| 31648 |
{% |
| 31649 |
\XINT_fwover_A {#2}{#1}% |
| 31650 |
}% |
| 31651 |
\def\XINT_sgnfwover_N |
| 31652 |
{% |
| 31653 |
\expandafter-\romannumeral0\XINT_sgnfwover_P |
| 31654 |
}% |
| 31655 |
% \end{macrocode} |
| 31656 |
% \subsection{\csh{xintREZ}} |
| 31657 |
%\begin{lverb} |
| 31658 |
% Removes trailing zeros from A and B and adjust the N in A/B[N]. |
| 31659 |
% |
| 31660 |
% The macro really doing the job \XINT_factortens was redone at 1.3a. But |
| 31661 |
% speed gain really noticeable only beyond about 100 digits. |
| 31662 |
%\end{lverb} |
| 31663 |
% \begin{macrocode} |
| 31664 |
\def\xintREZ {\romannumeral0\xintrez }% |
| 31665 |
\def\xintrez |
| 31666 |
{% |
| 31667 |
\expandafter\XINT_rez_A\romannumeral0\XINT_infrac |
| 31668 |
}% |
| 31669 |
\def\XINT_rez_A #1#2% |
| 31670 |
{% |
| 31671 |
\XINT_rez_AB #2\Z {#1}% |
| 31672 |
}% |
| 31673 |
\def\XINT_rez_AB #1% |
| 31674 |
{% |
| 31675 |
\xint_UDzerominusfork |
| 31676 |
#1-\XINT_rez_zero |
| 31677 |
0#1\XINT_rez_neg |
| 31678 |
0-{\XINT_rez_B #1}% |
| 31679 |
\krof |
| 31680 |
}% |
| 31681 |
\def\XINT_rez_zero #1\Z #2#3{ 0/1[0]}% |
| 31682 |
\def\XINT_rez_neg {\expandafter-\romannumeral0\XINT_rez_B }% |
| 31683 |
\def\XINT_rez_B #1\Z |
| 31684 |
{% |
| 31685 |
\expandafter\XINT_rez_C\romannumeral0\XINT_factortens {#1}% |
| 31686 |
}% |
| 31687 |
\def\XINT_rez_C #1.#2.#3#4% |
| 31688 |
{% |
| 31689 |
\expandafter\XINT_rez_D\romannumeral0\XINT_factortens {#4}#3+#2.#1.% |
| 31690 |
}% |
| 31691 |
\def\XINT_rez_D #1.#2.#3.% |
| 31692 |
{% |
| 31693 |
\expandafter\XINT_rez_E\the\numexpr #3-#2.#1.% |
| 31694 |
}% |
| 31695 |
\def\XINT_rez_E #1.#2.#3.{ #3/#2[#1]}% |
| 31696 |
% \end{macrocode} |
| 31697 |
% \subsection{\csh{xintE}} |
| 31698 |
% \added{1.07} |
| 31699 |
%\begin{lverb} |
| 31700 |
% The fraction is the first argument contrarily to \xintTrunc and |
| 31701 |
% \xintRound. |
| 31702 |
%\end{lverb} |
| 31703 |
% \changed{1.1} |
| 31704 |
%\begin{lverb} |
| 31705 |
% 1.1 modifies and moves \xintiiE to xint.sty. |
| 31706 |
%\end{lverb} |
| 31707 |
% \begin{macrocode} |
| 31708 |
\def\xintE {\romannumeral0\xinte }% |
| 31709 |
\def\xinte #1% |
| 31710 |
{% |
| 31711 |
\expandafter\XINT_e \romannumeral0\XINT_infrac {#1}% |
| 31712 |
}% |
| 31713 |
\def\XINT_e #1#2#3#4% |
| 31714 |
{% |
| 31715 |
\expandafter\XINT_e_end\the\numexpr #1+#4.{#2}{#3}% |
| 31716 |
}% |
| 31717 |
\def\XINT_e_end #1.#2#3{ #2/#3[#1]}% |
| 31718 |
% \end{macrocode} |
| 31719 |
% \subsection{\csh{xintIrr}, \csh{xintPIrr}} |
| 31720 |
% \changed{1.04} |
| 31721 |
%\begin{lverb} |
| 31722 |
% fixes a buggy \xintIrr {0}. |
| 31723 |
%\end{lverb} |
| 31724 |
% \changed{1.05} |
| 31725 |
%\begin{lverb} |
| 31726 |
% modifies the initial parsing and post-processing to use \xintrawwithzeros |
| 31727 |
% and to more quickly deal with an input denominator equal to 1. |
| 31728 |
%\end{lverb} |
| 31729 |
% \changed{1.08} |
| 31730 |
%\begin{lverb} |
| 31731 |
% this version does not remove a /1 denominator. |
| 31732 |
%\end{lverb} |
| 31733 |
% \changed{1.3} |
| 31734 |
%\begin{lverb} |
| 31735 |
% added \xintPIrr (partial Irr, which ignores the decimal part). |
| 31736 |
%\end{lverb} |
| 31737 |
% \begin{macrocode} |
| 31738 |
\def\xintIrr {\romannumeral0\xintirr }% |
| 31739 |
\def\xintPIrr{\romannumeral0\xintpirr }% |
| 31740 |
\def\xintirr #1% |
| 31741 |
{% |
| 31742 |
\expandafter\XINT_irr_start\romannumeral0\xintrawwithzeros {#1}\Z |
| 31743 |
}% |
| 31744 |
\def\xintpirr #1% |
| 31745 |
{% |
| 31746 |
\expandafter\XINT_pirr_start\romannumeral0\xintraw{#1}% |
| 31747 |
}% |
| 31748 |
\def\XINT_irr_start #1#2/#3\Z |
| 31749 |
{% |
| 31750 |
\if0\XINT_isOne {#3}% |
| 31751 |
\xint_afterfi |
| 31752 |
{\xint_UDsignfork |
| 31753 |
#1\XINT_irr_negative |
| 31754 |
-{\XINT_irr_nonneg #1}% |
| 31755 |
\krof}% |
| 31756 |
\else |
| 31757 |
\xint_afterfi{\XINT_irr_denomisone #1}% |
| 31758 |
\fi |
| 31759 |
#2\Z {#3}% |
| 31760 |
}% |
| 31761 |
\def\XINT_pirr_start #1#2/#3[% |
| 31762 |
{% |
| 31763 |
\if0\XINT_isOne {#3}% |
| 31764 |
\xint_afterfi |
| 31765 |
{\xint_UDsignfork |
| 31766 |
#1\XINT_irr_negative |
| 31767 |
-{\XINT_irr_nonneg #1}% |
| 31768 |
\krof}% |
| 31769 |
\else |
| 31770 |
\xint_afterfi{\XINT_irr_denomisone #1}% |
| 31771 |
\fi |
| 31772 |
#2\Z {#3}[% |
| 31773 |
}% |
| 31774 |
\def\XINT_irr_denomisone #1\Z #2{ #1/1}% changed in 1.08 |
| 31775 |
\def\XINT_irr_negative #1\Z #2{\XINT_irr_D #1\Z #2\Z -}% |
| 31776 |
\def\XINT_irr_nonneg #1\Z #2{\XINT_irr_D #1\Z #2\Z \space}% |
| 31777 |
\def\XINT_irr_D #1#2\Z #3#4\Z |
| 31778 |
{% |
| 31779 |
\xint_UDzerosfork |
| 31780 |
#3#1\XINT_irr_indeterminate |
| 31781 |
#30\XINT_irr_divisionbyzero |
| 31782 |
#10\XINT_irr_zero |
| 31783 |
00\XINT_irr_loop_a |
| 31784 |
\krof |
| 31785 |
{#3#4}{#1#2}{#3#4}{#1#2}% |
| 31786 |
}% |
| 31787 |
\def\XINT_irr_indeterminate #1#2#3#4#5% |
| 31788 |
{% |
| 31789 |
\XINT_signalcondition{DivisionUndefined}{0/0 indeterminate fraction.}{}{ 0/1}% |
| 31790 |
}% |
| 31791 |
\def\XINT_irr_divisionbyzero #1#2#3#4#5% |
| 31792 |
{% |
| 31793 |
\XINT_signalcondition{DivisionByZero}{Division by zero: #5#2/0.}{}{ 0/1}% |
| 31794 |
}% |
| 31795 |
\def\XINT_irr_zero #1#2#3#4#5{ 0/1}% changed in 1.08 |
| 31796 |
\def\XINT_irr_loop_a #1#2% |
| 31797 |
{% |
| 31798 |
\expandafter\XINT_irr_loop_d |
| 31799 |
\romannumeral0\XINT_div_prepare {#1}{#2}{#1}% |
| 31800 |
}% |
| 31801 |
\def\XINT_irr_loop_d #1#2% |
| 31802 |
{% |
| 31803 |
\XINT_irr_loop_e #2\Z |
| 31804 |
}% |
| 31805 |
\def\XINT_irr_loop_e #1#2\Z |
| 31806 |
{% |
| 31807 |
\xint_gob_til_zero #1\XINT_irr_loop_exit0\XINT_irr_loop_a {#1#2}% |
| 31808 |
}% |
| 31809 |
\def\XINT_irr_loop_exit0\XINT_irr_loop_a #1#2#3#4% |
| 31810 |
{% |
| 31811 |
\expandafter\XINT_irr_loop_exitb\expandafter |
| 31812 |
{\romannumeral0\xintiiquo {#3}{#2}}% |
| 31813 |
{\romannumeral0\xintiiquo {#4}{#2}}% |
| 31814 |
}% |
| 31815 |
\def\XINT_irr_loop_exitb #1#2% |
| 31816 |
{% |
| 31817 |
\expandafter\XINT_irr_finish\expandafter {#2}{#1}% |
| 31818 |
}% |
| 31819 |
\def\XINT_irr_finish #1#2#3{#3#1/#2}% changed in 1.08 |
| 31820 |
% \end{macrocode} |
| 31821 |
% \subsection{\csh{xintifInt}} |
| 31822 |
% \begin{macrocode} |
| 31823 |
\def\xintifInt {\romannumeral0\xintifint }% |
| 31824 |
\def\xintifint #1{\expandafter\XINT_ifint\romannumeral0\xintrawwithzeros {#1}.}% |
| 31825 |
\def\XINT_ifint #1/#2.% |
| 31826 |
{% |
| 31827 |
\if 0\xintiiRem {#1}{#2}% |
| 31828 |
\expandafter\xint_stop_atfirstoftwo |
| 31829 |
\else |
| 31830 |
\expandafter\xint_stop_atsecondoftwo |
| 31831 |
\fi |
| 31832 |
}% |
| 31833 |
% \end{macrocode} |
| 31834 |
% \subsection{\csh{xintIsInt}} |
| 31835 |
%\begin{lverb} |
| 31836 |
% Added at 1.3d only, for isint() xintexpr function. |
| 31837 |
%\end{lverb} |
| 31838 |
% \begin{macrocode} |
| 31839 |
\def\xintIsInt {\romannumeral0\xintisint }% |
| 31840 |
\def\xintisint #1% |
| 31841 |
{\expandafter\XINT_ifint\romannumeral0\xintrawwithzeros {#1}.10}% |
| 31842 |
% \end{macrocode} |
| 31843 |
% \subsection{\csh{xintJrr}} |
| 31844 |
% \begin{macrocode} |
| 31845 |
\def\xintJrr {\romannumeral0\xintjrr }% |
| 31846 |
\def\xintjrr #1% |
| 31847 |
{% |
| 31848 |
\expandafter\XINT_jrr_start\romannumeral0\xintrawwithzeros {#1}\Z |
| 31849 |
}% |
| 31850 |
\def\XINT_jrr_start #1#2/#3\Z |
| 31851 |
{% |
| 31852 |
\if0\XINT_isOne {#3}\xint_afterfi |
| 31853 |
{\xint_UDsignfork |
| 31854 |
#1\XINT_jrr_negative |
| 31855 |
-{\XINT_jrr_nonneg #1}% |
| 31856 |
\krof}% |
| 31857 |
\else |
| 31858 |
\xint_afterfi{\XINT_jrr_denomisone #1}% |
| 31859 |
\fi |
| 31860 |
#2\Z {#3}% |
| 31861 |
}% |
| 31862 |
\def\XINT_jrr_denomisone #1\Z #2{ #1/1}% changed in 1.08 |
| 31863 |
\def\XINT_jrr_negative #1\Z #2{\XINT_jrr_D #1\Z #2\Z -}% |
| 31864 |
\def\XINT_jrr_nonneg #1\Z #2{\XINT_jrr_D #1\Z #2\Z \space}% |
| 31865 |
\def\XINT_jrr_D #1#2\Z #3#4\Z |
| 31866 |
{% |
| 31867 |
\xint_UDzerosfork |
| 31868 |
#3#1\XINT_jrr_indeterminate |
| 31869 |
#30\XINT_jrr_divisionbyzero |
| 31870 |
#10\XINT_jrr_zero |
| 31871 |
00\XINT_jrr_loop_a |
| 31872 |
\krof |
| 31873 |
{#3#4}{#1#2}1001% |
| 31874 |
}% |
| 31875 |
\def\XINT_jrr_indeterminate #1#2#3#4#5#6#7% |
| 31876 |
{% |
| 31877 |
\XINT_signalcondition{DivisionUndefined}{0/0 indeterminate fraction.}{}{ 0/1}% |
| 31878 |
}% |
| 31879 |
\def\XINT_jrr_divisionbyzero #1#2#3#4#5#6#7% |
| 31880 |
{% |
| 31881 |
\XINT_signalcondition{DivisionByZero}{Division by zero: #7#2/0.}{}{ 0/1}% |
| 31882 |
}% |
| 31883 |
\def\XINT_jrr_zero #1#2#3#4#5#6#7{ 0/1}% changed in 1.08 |
| 31884 |
\def\XINT_jrr_loop_a #1#2% |
| 31885 |
{% |
| 31886 |
\expandafter\XINT_jrr_loop_b |
| 31887 |
\romannumeral0\XINT_div_prepare {#1}{#2}{#1}% |
| 31888 |
}% |
| 31889 |
\def\XINT_jrr_loop_b #1#2#3#4#5#6#7% |
| 31890 |
{% |
| 31891 |
\expandafter \XINT_jrr_loop_c \expandafter |
| 31892 |
{\romannumeral0\xintiiadd{\XINT_mul_fork #4\xint:#1\xint:}{#6}}% |
| 31893 |
{\romannumeral0\xintiiadd{\XINT_mul_fork #5\xint:#1\xint:}{#7}}% |
| 31894 |
{#2}{#3}{#4}{#5}% |
| 31895 |
}% |
| 31896 |
\def\XINT_jrr_loop_c #1#2% |
| 31897 |
{% |
| 31898 |
\expandafter \XINT_jrr_loop_d \expandafter{#2}{#1}% |
| 31899 |
}% |
| 31900 |
\def\XINT_jrr_loop_d #1#2#3#4% |
| 31901 |
{% |
| 31902 |
\XINT_jrr_loop_e #3\Z {#4}{#2}{#1}% |
| 31903 |
}% |
| 31904 |
\def\XINT_jrr_loop_e #1#2\Z |
| 31905 |
{% |
| 31906 |
\xint_gob_til_zero #1\XINT_jrr_loop_exit0\XINT_jrr_loop_a {#1#2}% |
| 31907 |
}% |
| 31908 |
\def\XINT_jrr_loop_exit0\XINT_jrr_loop_a #1#2#3#4#5#6% |
| 31909 |
{% |
| 31910 |
\XINT_irr_finish {#3}{#4}% |
| 31911 |
}% |
| 31912 |
% \end{macrocode} |
| 31913 |
% \subsection{\csh{xintTFrac}} |
| 31914 |
% \added{1.09i} |
| 31915 |
%\begin{lverb} |
| 31916 |
% For frac in \xintexpr. And \xintFrac is already assigned. T for |
| 31917 |
% truncation. However, potentially not very efficient with numbers in scientific |
| 31918 |
% notations, with big exponents. Will have to think it again some day. I |
| 31919 |
% hesitated how to call the macro. Same convention as in maple, but some people |
| 31920 |
% reserve fractional part to x - floor(x). Also, not clear if I had to make it |
| 31921 |
% negative (or zero) if x < 0, or rather always positive. There should be in |
| 31922 |
% fact such a thing for each rounding function, trunc, round, floor, ceil. |
| 31923 |
%\end{lverb} |
| 31924 |
% \begin{macrocode} |
| 31925 |
\def\xintTFrac {\romannumeral0\xinttfrac }% |
| 31926 |
\def\xinttfrac #1{\expandafter\XINT_tfrac_fork\romannumeral0\xintrawwithzeros {#1}\Z }% |
| 31927 |
\def\XINT_tfrac_fork #1% |
| 31928 |
{% |
| 31929 |
\xint_UDzerominusfork |
| 31930 |
#1-\XINT_tfrac_zero |
| 31931 |
0#1{\xintiiopp\XINT_tfrac_P }% |
| 31932 |
0-{\XINT_tfrac_P #1}% |
| 31933 |
\krof |
| 31934 |
}% |
| 31935 |
\def\XINT_tfrac_zero #1\Z { 0/1[0]}% |
| 31936 |
\def\XINT_tfrac_P #1/#2\Z {\expandafter\XINT_rez_AB |
| 31937 |
\romannumeral0\xintiirem{#1}{#2}\Z {0}{#2}}% |
| 31938 |
% \end{macrocode} |
| 31939 |
% \subsection{\csh{xintTrunc}, \csh{xintiTrunc}} |
| 31940 |
%\begin{lverb} |
| 31941 |
% |
| 31942 |
% This of course has a long history. Only showing here some comments. |
| 31943 |
%\end{lverb} |
| 31944 |
% \changed{1.2i} |
| 31945 |
%\begin{lverb} |
| 31946 |
% 1.2i release notes: ever since its inception this macro was stupid for a |
| 31947 |
% decimal input: it did not handle it separately from the general fraction |
| 31948 |
% case A/B[N] with B>1, hence ended up doing divisions by powers of ten. But |
| 31949 |
% this meant that nesting \xintTrunc with itself was very inefficient. |
| 31950 |
% |
| 31951 |
% 1.2i version is better. However it still handles B>1, N<0 via adding zeros |
| 31952 |
% to B and dividing with this extended B. A possibly more efficient approach |
| 31953 |
% is implemented in \xintXTrunc, but its logic is more complicated, the code |
| 31954 |
% is quite longer and making it f-expandable would not shorten it... I decided |
| 31955 |
% for the time being to not complicate things here. |
| 31956 |
%\end{lverb} |
| 31957 |
% \changed[2020/02/18]{1.4a} |
| 31958 |
%\begin{lverb} |
| 31959 |
% |
| 31960 |
% Adds handling of a negative first argument. |
| 31961 |
% |
| 31962 |
% Zero input still gives single digit 0 output as I did not want to complicate |
| 31963 |
% the code. But if quantization gives 0, the exponent [D] will be there. Well |
| 31964 |
% actually eD because of problem that sign of original is preserved in output |
| 31965 |
% so we can have -0 and I can not use -0[D] notation as it is not legal for |
| 31966 |
% strict format. So I will use -0eD hence eD generally even though this means |
| 31967 |
% so slight suboptimality for trunc() function in \xintexpr. |
| 31968 |
% |
| 31969 |
% The idea to give a meaning to negative D (in the context of optional |
| 31970 |
% argument to \xintiexpr) was suggested a long time ago by Kpym (October 20, |
| 31971 |
% 2015). His suggestion was then to treat it as positive D but trim trailing |
| 31972 |
% zeroes. But since then, there is \xintDecToString which can be combined with |
| 31973 |
% \xintREZ, and I feel matters of formatting output require a whole module (or |
| 31974 |
% rather use existing third-party tools), and I decided to opt rather for an |
| 31975 |
% operation similar as the quantize() of Python Decimal module. I.e. we |
| 31976 |
% truncate (or round) to an integer multiple of a given power of 10. |
| 31977 |
% |
| 31978 |
% Other reason to decide to do this is that it looks as if I don't even need |
| 31979 |
% to understand the original code to hack into its ending via \XINT_trunc_G or |
| 31980 |
% \XINT_itrunc_G. For the latter it looks as if logically I simply have to do |
| 31981 |
% nothing. For the former I simply have to add some eD postfix. |
| 31982 |
%\end{lverb} |
| 31983 |
% \begin{macrocode} |
| 31984 |
\def\xintTrunc {\romannumeral0\xinttrunc }% |
| 31985 |
\def\xintiTrunc {\romannumeral0\xintitrunc}% |
| 31986 |
\def\xinttrunc #1{\expandafter\XINT_trunc\the\numexpr#1.\XINT_trunc_G}% |
| 31987 |
\def\xintitrunc #1{\expandafter\XINT_trunc\the\numexpr#1.\XINT_itrunc_G}% |
| 31988 |
\def\XINT_trunc #1.#2#3% |
| 31989 |
{% |
| 31990 |
\expandafter\XINT_trunc_a\romannumeral0\XINT_infrac{#3}#1.#2% |
| 31991 |
}% |
| 31992 |
\def\XINT_trunc_a #1#2#3#4.#5% |
| 31993 |
{% |
| 31994 |
\if0\XINT_Sgn#2\xint:\xint_dothis\XINT_trunc_zero\fi |
| 31995 |
\if1\XINT_is_One#3XY\xint_dothis\XINT_trunc_sp_b\fi |
| 31996 |
\xint_orthat\XINT_trunc_b #1+#4.{#2}{#3}#5#4.% |
| 31997 |
}% |
| 31998 |
\def\XINT_trunc_zero #1.#2.{ 0}% |
| 31999 |
\def\XINT_trunc_b {\expandafter\XINT_trunc_B\the\numexpr}% |
| 32000 |
\def\XINT_trunc_sp_b {\expandafter\XINT_trunc_sp_B\the\numexpr}% |
| 32001 |
\def\XINT_trunc_B #1% |
| 32002 |
{% |
| 32003 |
\xint_UDsignfork |
| 32004 |
#1\XINT_trunc_C |
| 32005 |
-\XINT_trunc_D |
| 32006 |
\krof #1% |
| 32007 |
}% |
| 32008 |
\def\XINT_trunc_sp_B #1% |
| 32009 |
{% |
| 32010 |
\xint_UDsignfork |
| 32011 |
#1\XINT_trunc_sp_C |
| 32012 |
-\XINT_trunc_sp_D |
| 32013 |
\krof #1% |
| 32014 |
}% |
| 32015 |
\def\XINT_trunc_C -#1.#2#3% |
| 32016 |
{% |
| 32017 |
\expandafter\XINT_trunc_CE |
| 32018 |
\romannumeral0\XINT_dsx_addzeros{#1}#3;.{#2}% |
| 32019 |
}% |
| 32020 |
\def\XINT_trunc_CE #1.#2{\XINT_trunc_E #2.{#1}}% |
| 32021 |
\def\XINT_trunc_sp_C -#1.#2#3{\XINT_trunc_sp_Ca #2.#1.}% |
| 32022 |
\def\XINT_trunc_sp_Ca #1% |
| 32023 |
{% |
| 32024 |
\xint_UDsignfork |
| 32025 |
#1{\XINT_trunc_sp_Cb -}% |
| 32026 |
-{\XINT_trunc_sp_Cb \space#1}% |
| 32027 |
\krof |
| 32028 |
}% |
| 32029 |
\def\XINT_trunc_sp_Cb #1#2.#3.% |
| 32030 |
{% |
| 32031 |
\expandafter\XINT_trunc_sp_Cc |
| 32032 |
\romannumeral0\expandafter\XINT_split_fromright_a |
| 32033 |
\the\numexpr#3-\numexpr\XINT_length_loop |
| 32034 |
#2\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint:\xint: |
| 32035 |
\xint_c_viii\xint_c_vii\xint_c_vi\xint_c_v |
| 32036 |
\xint_c_iv\xint_c_iii\xint_c_ii\xint_c_i\xint_c_\xint_bye |
| 32037 |
.#2\xint_bye2345678\xint_bye..#1% |
| 32038 |
}% |
| 32039 |
\def\XINT_trunc_sp_Cc #1% |
| 32040 |
{% |
| 32041 |
\if.#1\xint_dothis{\XINT_trunc_sp_Cd 0.}\fi |
| 32042 |
\xint_orthat {\XINT_trunc_sp_Cd #1}% |
| 32043 |
}% |
| 32044 |
\def\XINT_trunc_sp_Cd #1.#2.#3% |
| 32045 |
{% |
| 32046 |
\XINT_trunc_sp_F #3#1.% |
| 32047 |
}% |
| 32048 |
\def\XINT_trunc_D #1.#2% |
| 32049 |
{% |
| 32050 |
\expandafter\XINT_trunc_E |
| 32051 |
\romannumeral0\XINT_dsx_addzeros {#1}#2;.% |
| 32052 |
}% |
| 32053 |
\def\XINT_trunc_sp_D #1.#2#3% |
| 32054 |
{% |
| 32055 |
\expandafter\XINT_trunc_sp_E |
| 32056 |
\romannumeral0\XINT_dsx_addzeros {#1}#2;.% |
| 32057 |
}% |
| 32058 |
\def\XINT_trunc_E #1% |
| 32059 |
{% |
| 32060 |
\xint_UDsignfork |
| 32061 |
#1{\XINT_trunc_F -}% |
| 32062 |
-{\XINT_trunc_F \space#1}% |
| 32063 |
\krof |
| 32064 |
}% |
| 32065 |
\def\XINT_trunc_sp_E #1% |
| 32066 |
{% |
| 32067 |
\xint_UDsignfork |
| 32068 |
#1{\XINT_trunc_sp_F -}% |
| 32069 |
-{\XINT_trunc_sp_F\space#1}% |
| 32070 |
\krof |
| 32071 |
}% |
| 32072 |
\def\XINT_trunc_F #1#2.#3#4% |
| 32073 |
{\expandafter#4\romannumeral`&&@\expandafter\xint_firstoftwo |
| 32074 |
\romannumeral0\XINT_div_prepare {#3}{#2}.#1}% |
| 32075 |
\def\XINT_trunc_sp_F #1#2.#3{#3#2.#1}% |
| 32076 |
\def\XINT_itrunc_G #1#2.#3#4.% |
| 32077 |
{% |
| 32078 |
\if#10\xint_dothis{ 0}\fi |
| 32079 |
\xint_orthat{#3#1}#2% |
| 32080 |
}% |
| 32081 |
\def\XINT_trunc_G #1.#2#3#4.% |
| 32082 |
{% |
| 32083 |
\xint_gob_til_minus#3\XINT_trunc_Hc-% |
| 32084 |
\expandafter\XINT_trunc_H |
| 32085 |
\the\numexpr\romannumeral0\xintlength {#1}-#3#4.#3#4.{#1}#2% |
| 32086 |
}% |
| 32087 |
\def\XINT_trunc_Hc-\expandafter\XINT_trunc_H |
| 32088 |
\the\numexpr\romannumeral0\xintlength #1.-#2.#3#4{#4#3e#2}% |
| 32089 |
\def\XINT_trunc_H #1.#2.% |
| 32090 |
{% |
| 32091 |
\ifnum #1 > \xint_c_ \xint_dothis{\XINT_trunc_Ha {#2}}\fi |
| 32092 |
\xint_orthat {\XINT_trunc_Hb {-#1}}% -0,--1,--2, .... |
| 32093 |
}% |
| 32094 |
\def\XINT_trunc_Ha% |
| 32095 |
{% |
| 32096 |
\expandafter\XINT_trunc_Haa\romannumeral0\xintdecsplit |
| 32097 |
}% |
| 32098 |
\def\XINT_trunc_Haa #1#2#3{#3#1.#2}% |
| 32099 |
\def\XINT_trunc_Hb #1#2#3% |
| 32100 |
{% |
| 32101 |
\expandafter #3\expandafter0\expandafter.% |
| 32102 |
\romannumeral\xintreplicate{#1}0#2% |
| 32103 |
}% |
| 32104 |
% \end{macrocode} |
| 32105 |
% \subsection{\csh{xintTTrunc}} |
| 32106 |
% \added{1.1} |
| 32107 |
% \begin{macrocode} |
| 32108 |
\def\xintTTrunc {\romannumeral0\xintttrunc }% |
| 32109 |
\def\xintttrunc {\xintitrunc\xint_c_}% |
| 32110 |
% \end{macrocode} |
| 32111 |
% \subsection{\csh{xintNum}, \csh{xintnum}} |
| 32112 |
% \begin{macrocode} |
| 32113 |
\let\xintnum \xintttrunc |
| 32114 |
% \end{macrocode} |
| 32115 |
% \subsection{\csh{xintRound}, \csh{xintiRound}} |
| 32116 |
%\begin{lverb} |
| 32117 |
% Modified in 1.2i. |
| 32118 |
% |
| 32119 |
% It benefits first of all from the faster \xintTrunc, particularly when the |
| 32120 |
% input is already a decimal number (denominator B=1). |
| 32121 |
% |
| 32122 |
% And the rounding is now done in 1.2 style (with much delay, sorry), like of |
| 32123 |
% the rewritten \xintInc and \xintDec. |
| 32124 |
% |
| 32125 |
% At 1.4a, first argument can be negative. This is handled at \XINT_trunc_G. |
| 32126 |
% |
| 32127 |
%\end{lverb} |
| 32128 |
% \begin{macrocode} |
| 32129 |
\def\xintRound {\romannumeral0\xintround }% |
| 32130 |
\def\xintiRound {\romannumeral0\xintiround }% |
| 32131 |
\def\xintround #1{\expandafter\XINT_round\the\numexpr #1.\XINT_round_A}% |
| 32132 |
\def\xintiround #1{\expandafter\XINT_round\the\numexpr #1.\XINT_iround_A}% |
| 32133 |
\def\XINT_round #1.{\expandafter\XINT_round_aa\the\numexpr #1+\xint_c_i.#1.}% |
| 32134 |
\def\XINT_round_aa #1.#2.#3#4% |
| 32135 |
{% |
| 32136 |
\expandafter\XINT_round_a\romannumeral0\XINT_infrac{#4}#1.#3#2.% |
| 32137 |
}% |
| 32138 |
\def\XINT_round_a #1#2#3#4.% |
| 32139 |
{% |
| 32140 |
\if0\XINT_Sgn#2\xint:\xint_dothis\XINT_trunc_zero\fi |
| 32141 |
\if1\XINT_is_One#3XY\xint_dothis\XINT_trunc_sp_b\fi |
| 32142 |
\xint_orthat\XINT_trunc_b #1+#4.{#2}{#3}% |
| 32143 |
}% |
| 32144 |
\def\XINT_round_A{\expandafter\XINT_trunc_G\romannumeral0\XINT_round_B}% |
| 32145 |
\def\XINT_iround_A{\expandafter\XINT_itrunc_G\romannumeral0\XINT_round_B}% |
| 32146 |
\def\XINT_round_B #1.% |
| 32147 |
{\XINT_dsrr #1\xint_bye\xint_Bye3456789\xint_bye/\xint_c_x\relax.}% |
| 32148 |
% \end{macrocode} |
| 32149 |
% \subsection{\csh{xintXTrunc}} |
| 32150 |
% \added[2014/01/06]{1.09j} |
| 32151 |
%\begin{lverb} |
| 32152 |
% This is completely expandable but not f-expandable. |
| 32153 |
%\end{lverb} |
| 32154 |
% \changed[2016/12/04]{1.2i} |
| 32155 |
%\begin{lverb} |
| 32156 |
% Rewritten: |
| 32157 |
% |
| 32158 |
% - no more use of \xintiloop from xinttools.sty |
| 32159 |
% (replaced by \xintreplicate... from xintkernel.sty), |
| 32160 |
% |
| 32161 |
% - no more use in 0>N>-D case of a dummy control sequence name via |
| 32162 |
% \csname...\endcsname |
| 32163 |
% |
| 32164 |
% - handles better the case of an input already a decimal number |
| 32165 |
%\end{lverb} |
| 32166 |
% \begin{macrocode} |
| 32167 |
\def\xintXTrunc #1%#2% |
| 32168 |
{% |
| 32169 |
\expandafter\XINT_xtrunc_a |
| 32170 |
\the\numexpr #1\expandafter.\romannumeral0\xintraw |
| 32171 |
}% |
| 32172 |
\def\XINT_xtrunc_a #1.% ?? faire autre chose |
| 32173 |
{% |
| 32174 |
\expandafter\XINT_xtrunc_b\the\numexpr\ifnum#1<\xint_c_i \xint_c_i-\fi #1.% |
| 32175 |
}% |
| 32176 |
\def\XINT_xtrunc_b #1.#2{\XINT_xtrunc_c #2{#1}}% |
| 32177 |
\def\XINT_xtrunc_c #1% |
| 32178 |
{% |
| 32179 |
\xint_UDzerominusfork |
| 32180 |
#1-\XINT_xtrunc_zero |
| 32181 |
0#1{-\XINT_xtrunc_d {}}% |
| 32182 |
0-{\XINT_xtrunc_d #1}% |
| 32183 |
\krof |
| 32184 |
}%[ |
| 32185 |
\def\XINT_xtrunc_zero #1#2]{0.\romannumeral\xintreplicate{#1}0}% |
| 32186 |
\def\XINT_xtrunc_d #1#2#3/#4[#5]% |
| 32187 |
{% |
| 32188 |
\XINT_xtrunc_prepare_a#4\R\R\R\R\R\R\R\R {10}0000001\W |
| 32189 |
!{#4};{#5}{#2}{#1#3}% |
| 32190 |
}% |
| 32191 |
\def\XINT_xtrunc_prepare_a #1#2#3#4#5#6#7#8#9% |
| 32192 |
{% |
| 32193 |
\xint_gob_til_R #9\XINT_xtrunc_prepare_small\R |
| 32194 |
\XINT_xtrunc_prepare_b #9% |
| 32195 |
}% |
| 32196 |
\def\XINT_xtrunc_prepare_small\R #1!#2;% |
| 32197 |
{% |
| 32198 |
\ifcase #2 |
| 32199 |
\or\expandafter\XINT_xtrunc_BisOne |
| 32200 |
\or\expandafter\XINT_xtrunc_BisTwo |
| 32201 |
\or |
| 32202 |
\or\expandafter\XINT_xtrunc_BisFour |
| 32203 |
\or\expandafter\XINT_xtrunc_BisFive |
| 32204 |
\or |
| 32205 |
\or |
| 32206 |
\or\expandafter\XINT_xtrunc_BisEight |
| 32207 |
\fi\XINT_xtrunc_BisSmall {#2}% |
| 32208 |
}% |
| 32209 |
\def\XINT_xtrunc_BisOne\XINT_xtrunc_BisSmall #1#2#3#4% |
| 32210 |
{\XINT_xtrunc_sp_e {#2}{#4}{#3}}% |
| 32211 |
\def\XINT_xtrunc_BisTwo\XINT_xtrunc_BisSmall #1#2#3#4% |
| 32212 |
{% |
| 32213 |
\expandafter\XINT_xtrunc_sp_e\expandafter |
| 32214 |
{\the\numexpr #2-\xint_c_i\expandafter}\expandafter |
| 32215 |
{\romannumeral0\xintiimul 5{#4}}{#3}% |
| 32216 |
}% |
| 32217 |
\def\XINT_xtrunc_BisFour\XINT_xtrunc_BisSmall #1#2#3#4% |
| 32218 |
{% |
| 32219 |
\expandafter\XINT_xtrunc_sp_e\expandafter |
| 32220 |
{\the\numexpr #2-\xint_c_ii\expandafter}\expandafter |
| 32221 |
{\romannumeral0\xintiimul {25}{#4}}{#3}% |
| 32222 |
}% |
| 32223 |
\def\XINT_xtrunc_BisFive\XINT_xtrunc_BisSmall #1#2#3#4% |
| 32224 |
{% |
| 32225 |
\expandafter\XINT_xtrunc_sp_e\expandafter |
| 32226 |
{\the\numexpr #2-\xint_c_i\expandafter}\expandafter |
| 32227 |
{\romannumeral0\xintdouble {#4}}{#3}% |
| 32228 |
}% |
| 32229 |
\def\XINT_xtrunc_BisEight\XINT_xtrunc_BisSmall #1#2#3#4% |
| 32230 |
{% |
| 32231 |
\expandafter\XINT_xtrunc_sp_e\expandafter |
| 32232 |
{\the\numexpr #2-\xint_c_iii\expandafter}\expandafter |
| 32233 |
{\romannumeral0\xintiimul {125}{#4}}{#3}% |
| 32234 |
}% |
| 32235 |
\def\XINT_xtrunc_BisSmall #1% |
| 32236 |
{% |
| 32237 |
\expandafter\XINT_xtrunc_e\expandafter |
| 32238 |
{\expandafter\XINT_xtrunc_small_a |
| 32239 |
\the\numexpr #1/\xint_c_ii\expandafter |
| 32240 |
.\the\numexpr \xint_c_x^viii+#1!}% |
| 32241 |
}% |
| 32242 |
\def\XINT_xtrunc_small_a #1.#2!#3% |
| 32243 |
{% |
| 32244 |
\expandafter\XINT_div_small_b\the\numexpr #1\expandafter |
| 32245 |
\xint:\the\numexpr #2\expandafter!% |
| 32246 |
\romannumeral0\XINT_div_small_ba #3\R\R\R\R\R\R\R\R{10}0000001\W |
| 32247 |
#3\XINT_sepbyviii_Z_end 2345678\relax |
| 32248 |
}% |
| 32249 |
\def\XINT_xtrunc_prepare_b |
| 32250 |
{\expandafter\XINT_xtrunc_prepare_c\romannumeral0\XINT_zeroes_forviii }% |
| 32251 |
\def\XINT_xtrunc_prepare_c #1!% |
| 32252 |
{% |
| 32253 |
\XINT_xtrunc_prepare_d #1.00000000!{#1}% |
| 32254 |
}% |
| 32255 |
\def\XINT_xtrunc_prepare_d #1#2#3#4#5#6#7#8#9% |
| 32256 |
{% |
| 32257 |
\expandafter\XINT_xtrunc_prepare_e |
| 32258 |
\xint_gob_til_dot #1#2#3#4#5#6#7#8#9!% |
| 32259 |
}% |
| 32260 |
\def\XINT_xtrunc_prepare_e #1!#2!#3#4% |
| 32261 |
{% |
| 32262 |
\XINT_xtrunc_prepare_f #4#3\X {#1}{#3}% |
| 32263 |
}% |
| 32264 |
\def\XINT_xtrunc_prepare_f #1#2#3#4#5#6#7#8#9\X |
| 32265 |
{% |
| 32266 |
\expandafter\XINT_xtrunc_prepare_g\expandafter |
| 32267 |
\XINT_div_prepare_g |
| 32268 |
\the\numexpr #1#2#3#4#5#6#7#8+\xint_c_i\expandafter |
| 32269 |
\xint:\the\numexpr (#1#2#3#4#5#6#7#8+\xint_c_i)/\xint_c_ii\expandafter |
| 32270 |
\xint:\the\numexpr #1#2#3#4#5#6#7#8\expandafter |
| 32271 |
\xint:\romannumeral0\XINT_sepandrev_andcount |
| 32272 |
#1#2#3#4#5#6#7#8#9\XINT_rsepbyviii_end_A 2345678% |
| 32273 |
\XINT_rsepbyviii_end_B 2345678\relax\xint_c_ii\xint_c_i |
| 32274 |
\R\xint:\xint_c_xii \R\xint:\xint_c_x \R\xint:\xint_c_viii \R\xint:\xint_c_vi |
| 32275 |
\R\xint:\xint_c_iv \R\xint:\xint_c_ii \R\xint:\xint_c_\W |
| 32276 |
\X |
| 32277 |
}% |
| 32278 |
\def\XINT_xtrunc_prepare_g #1;{\XINT_xtrunc_e {#1}}% |
| 32279 |
\def\XINT_xtrunc_e #1#2% |
| 32280 |
{% |
| 32281 |
\ifnum #2<\xint_c_ |
| 32282 |
\expandafter\XINT_xtrunc_I |
| 32283 |
\else |
| 32284 |
\expandafter\XINT_xtrunc_II |
| 32285 |
\fi #2\xint:{#1}% |
| 32286 |
}% |
| 32287 |
\def\XINT_xtrunc_I -#1\xint:#2#3#4% |
| 32288 |
{% |
| 32289 |
\expandafter\XINT_xtrunc_I_a\romannumeral0#2{#4}{#2}{#1}{#3}% |
| 32290 |
}% |
| 32291 |
\def\XINT_xtrunc_I_a #1#2#3#4#5% |
| 32292 |
{% |
| 32293 |
\expandafter\XINT_xtrunc_I_b\the\numexpr #4-#5\xint:#4\xint:{#5}{#2}{#3}{#1}% |
| 32294 |
}% |
| 32295 |
\def\XINT_xtrunc_I_b #1% |
| 32296 |
{% |
| 32297 |
\xint_UDsignfork |
| 32298 |
#1\XINT_xtrunc_IA_c |
| 32299 |
-\XINT_xtrunc_IB_c |
| 32300 |
\krof #1% |
| 32301 |
}% |
| 32302 |
\def\XINT_xtrunc_IA_c -#1\xint:#2\xint:#3#4#5#6% |
| 32303 |
{% |
| 32304 |
\expandafter\XINT_xtrunc_IA_d |
| 32305 |
\the\numexpr#2-\xintLength{#6}\xint:{#6}% |
| 32306 |
\expandafter\XINT_xtrunc_IA_xd |
| 32307 |
\the\numexpr (#1+\xint_c_ii^v)/\xint_c_ii^vi-\xint_c_i\xint:#1\xint:{#5}{#4}% |
| 32308 |
}% |
| 32309 |
\def\XINT_xtrunc_IA_d #1% |
| 32310 |
{% |
| 32311 |
\xint_UDsignfork |
| 32312 |
#1\XINT_xtrunc_IAA_e |
| 32313 |
-\XINT_xtrunc_IAB_e |
| 32314 |
\krof #1% |
| 32315 |
}% |
| 32316 |
\def\XINT_xtrunc_IAA_e -#1\xint:#2% |
| 32317 |
{% |
| 32318 |
\romannumeral0\XINT_split_fromleft |
| 32319 |
#1.#2\xint_gobble_i\xint_bye2345678\xint_bye..% |
| 32320 |
}% |
| 32321 |
\def\XINT_xtrunc_IAB_e #1\xint:#2% |
| 32322 |
{% |
| 32323 |
0.\romannumeral\XINT_rep#1\endcsname0#2% |
| 32324 |
}% |
| 32325 |
\def\XINT_xtrunc_IA_xd #1\xint:#2\xint:% |
| 32326 |
{% |
| 32327 |
\expandafter\XINT_xtrunc_IA_xe\the\numexpr #2-\xint_c_ii^vi*#1\xint:#1\xint:% |
| 32328 |
}% |
| 32329 |
\def\XINT_xtrunc_IA_xe #1\xint:#2\xint:#3#4% |
| 32330 |
{% |
| 32331 |
\XINT_xtrunc_loop {#2}{#4}{#3}{#1}% |
| 32332 |
}% |
| 32333 |
\def\XINT_xtrunc_IB_c #1\xint:#2\xint:#3#4#5#6% |
| 32334 |
{% |
| 32335 |
\expandafter\XINT_xtrunc_IB_d |
| 32336 |
\romannumeral0\XINT_split_xfork #1.#6\xint_bye2345678\xint_bye..{#3}% |
| 32337 |
}% |
| 32338 |
\def\XINT_xtrunc_IB_d #1.#2.#3% |
| 32339 |
{% |
| 32340 |
\expandafter\XINT_xtrunc_IA_d\the\numexpr#3-\xintLength {#1}\xint:{#1}% |
| 32341 |
}% |
| 32342 |
\def\XINT_xtrunc_II #1\xint:% |
| 32343 |
{% |
| 32344 |
\expandafter\XINT_xtrunc_II_a\romannumeral\xintreplicate{#1}0\xint:% |
| 32345 |
}% |
| 32346 |
\def\XINT_xtrunc_II_a #1\xint:#2#3#4% |
| 32347 |
{% |
| 32348 |
\expandafter\XINT_xtrunc_II_b |
| 32349 |
\the\numexpr (#3+\xint_c_ii^v)/\xint_c_ii^vi-\xint_c_i\expandafter\xint:% |
| 32350 |
\the\numexpr #3\expandafter\xint:\romannumeral0#2{#4#1}{#2}% |
| 32351 |
}% |
| 32352 |
\def\XINT_xtrunc_II_b #1\xint:#2\xint:% |
| 32353 |
{% |
| 32354 |
\expandafter\XINT_xtrunc_II_c\the\numexpr #2-\xint_c_ii^vi*#1\xint:#1\xint:% |
| 32355 |
}% |
| 32356 |
\def\XINT_xtrunc_II_c #1\xint:#2\xint:#3#4#5% |
| 32357 |
{% |
| 32358 |
#3.\XINT_xtrunc_loop {#2}{#4}{#5}{#1}% |
| 32359 |
}% |
| 32360 |
\def\XINT_xtrunc_loop #1% |
| 32361 |
{% |
| 32362 |
\ifnum #1=\xint_c_ \expandafter\XINT_xtrunc_transition\fi |
| 32363 |
\expandafter\XINT_xtrunc_loop_a\the\numexpr #1-\xint_c_i\xint:% |
| 32364 |
}% |
| 32365 |
\def\XINT_xtrunc_loop_a #1\xint:#2#3% |
| 32366 |
{% |
| 32367 |
\expandafter\XINT_xtrunc_loop_b\romannumeral0#3% |
| 32368 |
{#20000000000000000000000000000000000000000000000000000000000000000}% |
| 32369 |
{#1}{#3}% |
| 32370 |
}% |
| 32371 |
\def\XINT_xtrunc_loop_b #1#2#3% |
| 32372 |
{% |
| 32373 |
\romannumeral\xintreplicate{\xint_c_ii^vi-\xintLength{#1}}0#1% |
| 32374 |
\XINT_xtrunc_loop {#3}{#2}% |
| 32375 |
}% |
| 32376 |
\def\XINT_xtrunc_transition |
| 32377 |
\expandafter\XINT_xtrunc_loop_a\the\numexpr #1\xint:#2#3#4% |
| 32378 |
{% |
| 32379 |
\ifnum #4=\xint_c_ \expandafter\xint_gobble_vi\fi |
| 32380 |
\expandafter\XINT_xtrunc_finish\expandafter |
| 32381 |
{\romannumeral0\XINT_dsx_addzeros{#4}#2;}{#3}{#4}% |
| 32382 |
}% |
| 32383 |
\def\XINT_xtrunc_finish #1#2% |
| 32384 |
{% |
| 32385 |
\expandafter\XINT_xtrunc_finish_a\romannumeral0#2{#1}% |
| 32386 |
}% |
| 32387 |
\def\XINT_xtrunc_finish_a #1#2#3% |
| 32388 |
{% |
| 32389 |
\romannumeral\xintreplicate{#3-\xintLength{#1}}0#1% |
| 32390 |
}% |
| 32391 |
\def\XINT_xtrunc_sp_e #1% |
| 32392 |
{% |
| 32393 |
\ifnum #1<\xint_c_ |
| 32394 |
\expandafter\XINT_xtrunc_sp_I |
| 32395 |
\else |
| 32396 |
\expandafter\XINT_xtrunc_sp_II |
| 32397 |
\fi #1\xint:% |
| 32398 |
}% |
| 32399 |
\def\XINT_xtrunc_sp_I -#1\xint:#2#3% |
| 32400 |
{% |
| 32401 |
\expandafter\XINT_xtrunc_sp_I_a\the\numexpr #1-#3\xint:#1\xint:{#3}{#2}% |
| 32402 |
}% |
| 32403 |
\def\XINT_xtrunc_sp_I_a #1% |
| 32404 |
{% |
| 32405 |
\xint_UDsignfork |
| 32406 |
#1\XINT_xtrunc_sp_IA_b |
| 32407 |
-\XINT_xtrunc_sp_IB_b |
| 32408 |
\krof #1% |
| 32409 |
}% |
| 32410 |
\def\XINT_xtrunc_sp_IA_b -#1\xint:#2\xint:#3#4% |
| 32411 |
{% |
| 32412 |
\expandafter\XINT_xtrunc_sp_IA_c |
| 32413 |
\the\numexpr#2-\xintLength{#4}\xint:{#4}\romannumeral\XINT_rep#1\endcsname0% |
| 32414 |
}% |
| 32415 |
\def\XINT_xtrunc_sp_IA_c #1% |
| 32416 |
{% |
| 32417 |
\xint_UDsignfork |
| 32418 |
#1\XINT_xtrunc_sp_IAA |
| 32419 |
-\XINT_xtrunc_sp_IAB |
| 32420 |
\krof #1% |
| 32421 |
}% |
| 32422 |
\def\XINT_xtrunc_sp_IAA -#1\xint:#2% |
| 32423 |
{% |
| 32424 |
\romannumeral0\XINT_split_fromleft |
| 32425 |
#1.#2\xint_gobble_i\xint_bye2345678\xint_bye..% |
| 32426 |
}% |
| 32427 |
\def\XINT_xtrunc_sp_IAB #1\xint:#2% |
| 32428 |
{% |
| 32429 |
0.\romannumeral\XINT_rep#1\endcsname0#2% |
| 32430 |
}% |
| 32431 |
\def\XINT_xtrunc_sp_IB_b #1\xint:#2\xint:#3#4% |
| 32432 |
{% |
| 32433 |
\expandafter\XINT_xtrunc_sp_IB_c |
| 32434 |
\romannumeral0\XINT_split_xfork #1.#4\xint_bye2345678\xint_bye..{#3}% |
| 32435 |
}% |
| 32436 |
\def\XINT_xtrunc_sp_IB_c #1.#2.#3% |
| 32437 |
{% |
| 32438 |
\expandafter\XINT_xtrunc_sp_IA_c\the\numexpr#3-\xintLength {#1}\xint:{#1}% |
| 32439 |
}% |
| 32440 |
\def\XINT_xtrunc_sp_II #1\xint:#2#3% |
| 32441 |
{% |
| 32442 |
#2\romannumeral\XINT_rep#1\endcsname0.\romannumeral\XINT_rep#3\endcsname0% |
| 32443 |
}% |
| 32444 |
% \end{macrocode} |
| 32445 |
% \subsection{\csh{xintAdd}} |
| 32446 |
% \changed{1.3} |
| 32447 |
%\begin{lverb} |
| 32448 |
% Big change at 1.3: a/b+c/d uses lcm(b,d) as denominator. |
| 32449 |
%\end{lverb} |
| 32450 |
% \begin{macrocode} |
| 32451 |
\def\xintAdd {\romannumeral0\xintadd }% |
| 32452 |
\def\xintadd #1{\expandafter\XINT_fadd\romannumeral0\xintraw {#1}}% |
| 32453 |
\def\XINT_fadd #1{\xint_gob_til_zero #1\XINT_fadd_Azero 0\XINT_fadd_a #1}% |
| 32454 |
\def\XINT_fadd_Azero #1]{\xintraw }% |
| 32455 |
\def\XINT_fadd_a #1/#2[#3]#4% |
| 32456 |
{\expandafter\XINT_fadd_b\romannumeral0\xintraw {#4}{#3}{#1}{#2}}% |
| 32457 |
\def\XINT_fadd_b #1{\xint_gob_til_zero #1\XINT_fadd_Bzero 0\XINT_fadd_c #1}% |
| 32458 |
\def\XINT_fadd_Bzero #1]#2#3#4{ #3/#4[#2]}% |
| 32459 |
\def\XINT_fadd_c #1/#2[#3]#4% |
| 32460 |
{% |
| 32461 |
\expandafter\XINT_fadd_Aa\the\numexpr #4-#3.{#3}{#4}{#1}{#2}% |
| 32462 |
}% |
| 32463 |
\def\XINT_fadd_Aa #1% |
| 32464 |
{% |
| 32465 |
\xint_UDzerominusfork |
| 32466 |
#1-\XINT_fadd_B |
| 32467 |
0#1\XINT_fadd_Bb |
| 32468 |
0-\XINT_fadd_Ba |
| 32469 |
\krof #1% |
| 32470 |
}% |
| 32471 |
\def\XINT_fadd_B #1.#2#3#4#5#6#7{\XINT_fadd_C {#4}{#5}{#7}{#6}[#3]}% |
| 32472 |
\def\XINT_fadd_Ba #1.#2#3#4#5#6#7% |
| 32473 |
{% |
| 32474 |
\expandafter\XINT_fadd_C\expandafter |
| 32475 |
{\romannumeral0\XINT_dsx_addzeros {#1}#6;}% |
| 32476 |
{#7}{#5}{#4}[#2]% |
| 32477 |
}% |
| 32478 |
\def\XINT_fadd_Bb -#1.#2#3#4#5#6#7% |
| 32479 |
{% |
| 32480 |
\expandafter\XINT_fadd_C\expandafter |
| 32481 |
{\romannumeral0\XINT_dsx_addzeros {#1}#4;}% |
| 32482 |
{#5}{#7}{#6}[#3]% |
| 32483 |
}% |
| 32484 |
\def\XINT_fadd_iszero #1[#2]{ 0/1[0]}% ou [#2] originel? |
| 32485 |
\def\XINT_fadd_C #1#2#3% |
| 32486 |
{% |
| 32487 |
\expandafter\XINT_fadd_D_b |
| 32488 |
\romannumeral0\XINT_div_prepare{#2}{#3}{#2}{#2}{#3}{#1}% |
| 32489 |
}% |
| 32490 |
% \end{macrocode} |
| 32491 |
%\begin{lverb} |
| 32492 |
% Basically a clone of the \XINT_irr_loop_a loop. I should modify the |
| 32493 |
% output of \XINT_div_prepare perhaps to be optimized for checking if |
| 32494 |
% remainder vanishes. |
| 32495 |
%\end{lverb} |
| 32496 |
% \begin{macrocode} |
| 32497 |
\def\XINT_fadd_D_a #1#2% |
| 32498 |
{% |
| 32499 |
\expandafter\XINT_fadd_D_b |
| 32500 |
\romannumeral0\XINT_div_prepare {#1}{#2}{#1}% |
| 32501 |
}% |
| 32502 |
\def\XINT_fadd_D_b #1#2{\XINT_fadd_D_c #2\Z}% |
| 32503 |
\def\XINT_fadd_D_c #1#2\Z |
| 32504 |
{% |
| 32505 |
\xint_gob_til_zero #1\XINT_fadd_D_exit0\XINT_fadd_D_a {#1#2}% |
| 32506 |
}% |
| 32507 |
\def\XINT_fadd_D_exit0\XINT_fadd_D_a #1#2#3% |
| 32508 |
{% |
| 32509 |
\expandafter\XINT_fadd_E |
| 32510 |
\romannumeral0\xintiiquo {#3}{#2}.{#2}% |
| 32511 |
}% |
| 32512 |
\def\XINT_fadd_E #1.#2#3% |
| 32513 |
{% |
| 32514 |
\expandafter\XINT_fadd_F |
| 32515 |
\romannumeral0\xintiimul{#1}{#3}.{\xintiiQuo{#3}{#2}}{#1}% |
| 32516 |
}% |
| 32517 |
\def\XINT_fadd_F #1.#2#3#4#5% |
| 32518 |
{% |
| 32519 |
\expandafter\XINT_fadd_G |
| 32520 |
\romannumeral0\xintiiadd{\xintiiMul{#2}{#4}}{\xintiiMul{#3}{#5}}/#1% |
| 32521 |
}% |
| 32522 |
\def\XINT_fadd_G #1{% |
| 32523 |
\def\XINT_fadd_G ##1{\if0##1\expandafter\XINT_fadd_iszero\fi#1##1}% |
| 32524 |
}\XINT_fadd_G{ }% |
| 32525 |
% \end{macrocode} |
| 32526 |
% \subsection{\csh{xintSub}} |
| 32527 |
% \changed{1.3} |
| 32528 |
%\begin{lverb} |
| 32529 |
% Since 1.3 will use least common multiple of denominators. |
| 32530 |
%\end{lverb} |
| 32531 |
% \begin{macrocode} |
| 32532 |
\def\xintSub {\romannumeral0\xintsub }% |
| 32533 |
\def\xintsub #1{\expandafter\XINT_fsub\romannumeral0\xintraw {#1}}% |
| 32534 |
\def\XINT_fsub #1{\xint_gob_til_zero #1\XINT_fsub_Azero 0\XINT_fsub_a #1}% |
| 32535 |
\def\XINT_fsub_Azero #1]{\xintopp }% |
| 32536 |
\def\XINT_fsub_a #1/#2[#3]#4% |
| 32537 |
{\expandafter\XINT_fsub_b\romannumeral0\xintraw {#4}{#3}{#1}{#2}}% |
| 32538 |
\def\XINT_fsub_b #1{\xint_UDzerominusfork |
| 32539 |
#1-\XINT_fadd_Bzero |
| 32540 |
0#1\XINT_fadd_c |
| 32541 |
0-{\XINT_fadd_c -#1}% |
| 32542 |
\krof }% |
| 32543 |
% \end{macrocode} |
| 32544 |
% \subsection{\csh{xintSum}} |
| 32545 |
%\begin{lverb} |
| 32546 |
% There was (not documented anymore since 1.09d, 2013/10/22) a macro |
| 32547 |
% \xintSumExpr, but it has been deleted at 1.2l. |
| 32548 |
% |
| 32549 |
% Empty items in the input are not accepted by this macro, but the input |
| 32550 |
% may be empty. |
| 32551 |
% |
| 32552 |
% Refactored slightly at 1.4. \XINT_Sum used in xintexpr code. |
| 32553 |
%\end{lverb} |
| 32554 |
% \begin{macrocode} |
| 32555 |
\def\xintSum {\romannumeral0\xintsum }% |
| 32556 |
\def\xintsum #1{\expandafter\XINT_sum\romannumeral`&&@#1^}% |
| 32557 |
\def\XINT_Sum{\romannumeral0\XINT_sum}% |
| 32558 |
\def\XINT_sum#1% |
| 32559 |
{% |
| 32560 |
\xint_gob_til_^ #1\XINT_sum_empty ^% |
| 32561 |
\expandafter\XINT_sum_loop\romannumeral0\xintraw{#1}\xint: |
| 32562 |
}% |
| 32563 |
\def\XINT_sum_empty ^#1\xint:{ 0/1[0]}% |
| 32564 |
\def\XINT_sum_loop #1\xint:#2% |
| 32565 |
{% |
| 32566 |
\xint_gob_til_^ #2\XINT_sum_end ^% |
| 32567 |
\expandafter\XINT_sum_loop |
| 32568 |
\romannumeral0\xintadd{#1}{\romannumeral0\xintraw{#2}}\xint: |
| 32569 |
}% |
| 32570 |
\def\XINT_sum_end ^#1\xintadd #2#3\xint:{ #2}% |
| 32571 |
% \end{macrocode} |
| 32572 |
% \subsection{\csh{xintMul}} |
| 32573 |
% \begin{macrocode} |
| 32574 |
\def\xintMul {\romannumeral0\xintmul }% |
| 32575 |
\def\xintmul #1{\expandafter\XINT_fmul\romannumeral0\xintraw {#1}.}% |
| 32576 |
\def\XINT_fmul #1{\xint_gob_til_zero #1\XINT_fmul_zero 0\XINT_fmul_a #1}% |
| 32577 |
\def\XINT_fmul_a #1[#2].#3% |
| 32578 |
{\expandafter\XINT_fmul_b\romannumeral0\xintraw {#3}#1[#2.]}% |
| 32579 |
\def\XINT_fmul_b #1{\xint_gob_til_zero #1\XINT_fmul_zero 0\XINT_fmul_c #1}% |
| 32580 |
\def\XINT_fmul_c #1/#2[#3]#4/#5[#6.]% |
| 32581 |
{% |
| 32582 |
\expandafter\XINT_fmul_d |
| 32583 |
\expandafter{\the\numexpr #3+#6\expandafter}% |
| 32584 |
\expandafter{\romannumeral0\xintiimul {#5}{#2}}% |
| 32585 |
{\romannumeral0\xintiimul {#4}{#1}}% |
| 32586 |
}% |
| 32587 |
\def\XINT_fmul_d #1#2#3% |
| 32588 |
{% |
| 32589 |
\expandafter \XINT_fmul_e \expandafter{#3}{#1}{#2}% |
| 32590 |
}% |
| 32591 |
\def\XINT_fmul_e #1#2{\XINT_outfrac {#2}{#1}}% |
| 32592 |
\def\XINT_fmul_zero #1.#2{ 0/1[0]}% |
| 32593 |
% \end{macrocode} |
| 32594 |
% \subsection{\csh{xintSqr}} |
| 32595 |
% \begin{macrocode} |
| 32596 |
\def\xintSqr {\romannumeral0\xintsqr }% |
| 32597 |
\def\xintsqr #1{\expandafter\XINT_fsqr\romannumeral0\xintraw {#1}}% |
| 32598 |
\def\XINT_fsqr #1{\xint_gob_til_zero #1\XINT_fsqr_zero 0\XINT_fsqr_a #1}% |
| 32599 |
\def\XINT_fsqr_a #1/#2[#3]% |
| 32600 |
{% |
| 32601 |
\expandafter\XINT_fsqr_b |
| 32602 |
\expandafter{\the\numexpr #3+#3\expandafter}% |
| 32603 |
\expandafter{\romannumeral0\xintiisqr {#2}}% |
| 32604 |
{\romannumeral0\xintiisqr {#1}}% |
| 32605 |
}% |
| 32606 |
\def\XINT_fsqr_b #1#2#3{\expandafter \XINT_fmul_e \expandafter{#3}{#1}{#2}}% |
| 32607 |
\def\XINT_fsqr_zero #1]{ 0/1[0]}% |
| 32608 |
% \end{macrocode} |
| 32609 |
% \subsection{\csh{xintPow}} |
| 32610 |
%\begin{lverb} |
| 32611 |
% 1.2f: to be coherent with the "i" convention \xintiPow should parse also its |
| 32612 |
% exponent via \xintNum when xintfrac.sty is loaded. This was not the case so |
| 32613 |
% far. Cependant le problème est que le fait d'appliquer \xintNum rend |
| 32614 |
% impossible certains inputs qui auraient pu être gérès par \numexpr. Le |
| 32615 |
% \numexpr externe est ici pour intercepter trop grand input. |
| 32616 |
%\end{lverb} |
| 32617 |
% \begin{macrocode} |
| 32618 |
\def\xintipow #1#2% |
| 32619 |
{% |
| 32620 |
\expandafter\xint_pow\the\numexpr \xintNum{#2}\expandafter |
| 32621 |
.\romannumeral0\xintnum{#1}\xint: |
| 32622 |
}% |
| 32623 |
\def\xintPow {\romannumeral0\xintpow }% |
| 32624 |
\def\xintpow #1% |
| 32625 |
{% |
| 32626 |
\expandafter\XINT_fpow\expandafter {\romannumeral0\XINT_infrac {#1}}% |
| 32627 |
}% |
| 32628 |
\def\XINT_fpow #1#2% |
| 32629 |
{% |
| 32630 |
\expandafter\XINT_fpow_fork\the\numexpr \xintNum{#2}\relax\Z #1% |
| 32631 |
}% |
| 32632 |
\def\XINT_fpow_fork #1#2\Z |
| 32633 |
{% |
| 32634 |
\xint_UDzerominusfork |
| 32635 |
#1-\XINT_fpow_zero |
| 32636 |
0#1\XINT_fpow_neg |
| 32637 |
0-{\XINT_fpow_pos #1}% |
| 32638 |
\krof |
| 32639 |
{#2}% |
| 32640 |
}% |
| 32641 |
\def\XINT_fpow_zero #1#2#3#4{ 1/1[0]}% |
| 32642 |
\def\XINT_fpow_pos #1#2#3#4#5% |
| 32643 |
{% |
| 32644 |
\expandafter\XINT_fpow_pos_A\expandafter |
| 32645 |
{\the\numexpr #1#2*#3\expandafter}\expandafter |
| 32646 |
{\romannumeral0\xintiipow {#5}{#1#2}}% |
| 32647 |
{\romannumeral0\xintiipow {#4}{#1#2}}% |
| 32648 |
}% |
| 32649 |
\def\XINT_fpow_neg #1#2#3#4% |
| 32650 |
{% |
| 32651 |
\expandafter\XINT_fpow_pos_A\expandafter |
| 32652 |
{\the\numexpr -#1*#2\expandafter}\expandafter |
| 32653 |
{\romannumeral0\xintiipow {#3}{#1}}% |
| 32654 |
{\romannumeral0\xintiipow {#4}{#1}}% |
| 32655 |
}% |
| 32656 |
\def\XINT_fpow_pos_A #1#2#3% |
| 32657 |
{% |
| 32658 |
\expandafter\XINT_fpow_pos_B\expandafter {#3}{#1}{#2}% |
| 32659 |
}% |
| 32660 |
\def\XINT_fpow_pos_B #1#2{\XINT_outfrac {#2}{#1}}% |
| 32661 |
% \end{macrocode} |
| 32662 |
% \subsection{\csh{xintFac}} |
| 32663 |
%\begin{lverb} |
| 32664 |
% Factorial coefficients: variant which can be chained with other |
| 32665 |
% xintfrac macros. |
| 32666 |
%\end{lverb} |
| 32667 |
% \begin{macrocode} |
| 32668 |
\def\xintFac {\romannumeral0\xintfac}% |
| 32669 |
\def\xintfac #1{\expandafter\XINT_fac_fork\the\numexpr\xintNum{#1}.[0]}% |
| 32670 |
% \end{macrocode} |
| 32671 |
% \subsection{\csh{xintBinomial}} |
| 32672 |
% \added{1.2f} |
| 32673 |
% \begin{macrocode} |
| 32674 |
\def\xintBinomial {\romannumeral0\xintbinomial}% |
| 32675 |
\def\xintbinomial #1#2% |
| 32676 |
{% |
| 32677 |
\expandafter\XINT_binom_pre |
| 32678 |
\the\numexpr\xintNum{#1}\expandafter.\the\numexpr\xintNum{#2}.[0]% |
| 32679 |
}% |
| 32680 |
% \end{macrocode} |
| 32681 |
% \subsection{\csh{xintPFactorial}} |
| 32682 |
% \added{1.2f} |
| 32683 |
%\begin{lverb} |
| 32684 |
% Partial factorial. For needs of xintexpr.sty. |
| 32685 |
%\end{lverb} |
| 32686 |
% \begin{macrocode} |
| 32687 |
\def\xintipfactorial #1#2% |
| 32688 |
{% |
| 32689 |
\expandafter\XINT_pfac_fork |
| 32690 |
\the\numexpr\xintNum{#1}\expandafter.\the\numexpr\xintNum{#2}.% |
| 32691 |
}% |
| 32692 |
\def\xintPFactorial {\romannumeral0\xintpfactorial}% |
| 32693 |
\def\xintpfactorial #1#2% |
| 32694 |
{% |
| 32695 |
\expandafter\XINT_pfac_fork |
| 32696 |
\the\numexpr\xintNum{#1}\expandafter.\the\numexpr\xintNum{#2}.[0]% |
| 32697 |
}% |
| 32698 |
% \end{macrocode} |
| 32699 |
% \subsection{\csh{xintPrd}} |
| 32700 |
%\begin{lverb} |
| 32701 |
% Refactored at 1.4. After some hesitation the routine still does |
| 32702 |
% not try to detect on the fly a zero item, to abort the loop. Indeed |
| 32703 |
% this would add some overhead generally (as we need normalizing the item before |
| 32704 |
% checking if it vanishes hence we must then grab things once more). |
| 32705 |
%\end{lverb} |
| 32706 |
% \begin{macrocode} |
| 32707 |
\def\xintPrd {\romannumeral0\xintprd }% |
| 32708 |
\def\xintprd #1{\expandafter\XINT_prd\romannumeral`&&@#1^}% |
| 32709 |
\def\XINT_Prd{\romannumeral0\XINT_prd}% |
| 32710 |
\def\XINT_prd#1% |
| 32711 |
{% |
| 32712 |
\xint_gob_til_^ #1\XINT_prd_empty ^% |
| 32713 |
\expandafter\XINT_prd_loop\romannumeral0\xintraw{#1}\xint: |
| 32714 |
}% |
| 32715 |
\def\XINT_prd_empty ^#1\xint:{ 1/1[0]}% |
| 32716 |
\def\XINT_prd_loop #1\xint:#2% |
| 32717 |
{% |
| 32718 |
\xint_gob_til_^ #2\XINT_prd_end ^% |
| 32719 |
\expandafter\XINT_prd_loop |
| 32720 |
\romannumeral0\xintmul{#1}{\romannumeral0\xintraw{#2}}\xint: |
| 32721 |
}% |
| 32722 |
\def\XINT_prd_end ^#1\xintmul #2#3\xint:{ #2}% |
| 32723 |
% \end{macrocode} |
| 32724 |
% \subsection{\csh{xintDiv}} |
| 32725 |
% \begin{macrocode} |
| 32726 |
\def\xintDiv {\romannumeral0\xintdiv }% |
| 32727 |
\def\xintdiv #1% |
| 32728 |
{% |
| 32729 |
\expandafter\XINT_fdiv\expandafter {\romannumeral0\XINT_infrac {#1}}% |
| 32730 |
}% |
| 32731 |
\def\XINT_fdiv #1#2% |
| 32732 |
{\expandafter\XINT_fdiv_A\romannumeral0\XINT_infrac {#2}#1}% |
| 32733 |
\def\XINT_fdiv_A #1#2#3#4#5#6% |
| 32734 |
{% |
| 32735 |
\expandafter\XINT_fdiv_B |
| 32736 |
\expandafter{\the\numexpr #4-#1\expandafter}% |
| 32737 |
\expandafter{\romannumeral0\xintiimul {#2}{#6}}% |
| 32738 |
{\romannumeral0\xintiimul {#3}{#5}}% |
| 32739 |
}% |
| 32740 |
\def\XINT_fdiv_B #1#2#3% |
| 32741 |
{% |
| 32742 |
\expandafter\XINT_fdiv_C |
| 32743 |
\expandafter{#3}{#1}{#2}% |
| 32744 |
}% |
| 32745 |
\def\XINT_fdiv_C #1#2{\XINT_outfrac {#2}{#1}}% |
| 32746 |
% \end{macrocode} |
| 32747 |
% \subsection{\csh{xintDivFloor}} |
| 32748 |
% \added{1.1} |
| 32749 |
%\begin{lverb} |
| 32750 |
% Changed at 1.2p to not append /1[0] ending but rather output a |
| 32751 |
% big integer in strict format, like \xintDivTrunc and \xintDivRound. |
| 32752 |
%\end{lverb} |
| 32753 |
% \begin{macrocode} |
| 32754 |
\def\xintDivFloor {\romannumeral0\xintdivfloor }% |
| 32755 |
\def\xintdivfloor #1#2{\xintifloor{\xintDiv {#1}{#2}}}% |
| 32756 |
% \end{macrocode} |
| 32757 |
% \subsection{\csh{xintDivTrunc}} |
| 32758 |
% \added{1.1} |
| 32759 |
% \begin{macrocode} |
| 32760 |
\def\xintDivTrunc {\romannumeral0\xintdivtrunc }% |
| 32761 |
\def\xintdivtrunc #1#2{\xintttrunc {\xintDiv {#1}{#2}}}% |
| 32762 |
% \end{macrocode} |
| 32763 |
% \subsection{\csh{xintDivRound}} |
| 32764 |
%\begin{lverb} |
| 32765 |
% 1.1 |
| 32766 |
%\end{lverb} |
| 32767 |
% \begin{macrocode} |
| 32768 |
\def\xintDivRound {\romannumeral0\xintdivround }% |
| 32769 |
\def\xintdivround #1#2{\xintiround 0{\xintDiv {#1}{#2}}}% |
| 32770 |
% \end{macrocode} |
| 32771 |
% \subsection{\csh{xintModTrunc}} |
| 32772 |
% \added{1.1} |
| 32773 |
%\begin{lverb} |
| 32774 |
% \xintModTrunc {q1}{q2} computes q1 - q2*t(q1/q2) with t(q1/q2) |
| 32775 |
% equal to the truncated division of two fractions q1 and q2. |
| 32776 |
% |
| 32777 |
% Its former name, prior to 1.2p, was \xintMod. |
| 32778 |
%\end{lverb} |
| 32779 |
% \changed{1.3} |
| 32780 |
%\begin{lverb} |
| 32781 |
% At 1.3, uses least common multiple denominator, like \xintMod (next). |
| 32782 |
%\end{lverb} |
| 32783 |
% \begin{macrocode} |
| 32784 |
\def\xintModTrunc {\romannumeral0\xintmodtrunc }% |
| 32785 |
\def\xintmodtrunc #1{\expandafter\XINT_modtrunc_a\romannumeral0\xintraw{#1}.}% |
| 32786 |
\def\XINT_modtrunc_a #1#2.#3% |
| 32787 |
{\expandafter\XINT_modtrunc_b\expandafter #1\romannumeral0\xintraw{#3}#2.}% |
| 32788 |
\def\XINT_modtrunc_b #1#2% #1 de A, #2 de B. |
| 32789 |
{% |
| 32790 |
\if0#2\xint_dothis{\XINT_modtrunc_divbyzero #1#2}\fi |
| 32791 |
\if0#1\xint_dothis\XINT_modtrunc_aiszero\fi |
| 32792 |
\if-#2\xint_dothis{\XINT_modtrunc_bneg #1}\fi |
| 32793 |
\xint_orthat{\XINT_modtrunc_bpos #1#2}% |
| 32794 |
}% |
| 32795 |
\def\XINT_modtrunc_divbyzero #1#2[#3]#4.% |
| 32796 |
{% |
| 32797 |
\XINT_signalcondition{DivisionByZero}{Division by zero: #1#4/(#2[#3]).}{}{ 0/1[0]}% |
| 32798 |
}% |
| 32799 |
\def\XINT_modtrunc_aiszero #1.{ 0/1[0]}% |
| 32800 |
\def\XINT_modtrunc_bneg #1% |
| 32801 |
{% |
| 32802 |
\xint_UDsignfork |
| 32803 |
#1{\xintiiopp\XINT_modtrunc_pos {}}% |
| 32804 |
-{\XINT_modtrunc_pos #1}% |
| 32805 |
\krof |
| 32806 |
}% |
| 32807 |
\def\XINT_modtrunc_bpos #1% |
| 32808 |
{% |
| 32809 |
\xint_UDsignfork |
| 32810 |
#1{\xintiiopp\XINT_modtrunc_pos {}}% |
| 32811 |
-{\XINT_modtrunc_pos #1}% |
| 32812 |
\krof |
| 32813 |
}% |
| 32814 |
% \end{macrocode} |
| 32815 |
%\begin{lverb} |
| 32816 |
% Attention. This crucially uses that xint's \xintiiE{x}{e} is defined |
| 32817 |
% to return x unchanged if e is negative (and x extended by e zeroes if e >= |
| 32818 |
% 0). |
| 32819 |
%\end{lverb} |
| 32820 |
% \begin{macrocode} |
| 32821 |
\def\XINT_modtrunc_pos #1#2/#3[#4]#5/#6[#7].% |
| 32822 |
{% |
| 32823 |
\expandafter\XINT_modtrunc_pos_a |
| 32824 |
\the\numexpr\ifnum#7>#4 #4\else #7\fi\expandafter.% |
| 32825 |
\romannumeral0\expandafter\XINT_mod_D_b |
| 32826 |
\romannumeral0\XINT_div_prepare{#3}{#6}{#3}{#3}{#6}% |
| 32827 |
{#1#5}{#7-#4}{#2}{#4-#7}% |
| 32828 |
}% |
| 32829 |
\def\XINT_modtrunc_pos_a #1.#2#3#4{\xintiirem {#3}{#4}/#2[#1]}% |
| 32830 |
% \end{macrocode} |
| 32831 |
% \subsection{\csh{xintDivMod}} |
| 32832 |
% \added{1.2p} |
| 32833 |
%\begin{lverb} |
| 32834 |
% \xintDivMod{q1}{q2} outputs {floor(q1/q2)}{q1 - q2*floor(q1/q2)}. |
| 32835 |
% Attention that it relies on \xintiiE{x}{e} returning x if e < 0. |
| 32836 |
%\end{lverb} |
| 32837 |
% \changed{1.3} |
| 32838 |
%\begin{lverb} |
| 32839 |
% Modified (like \xintAdd and \xintSub) at 1.3 to use a l.c.m for final |
| 32840 |
% denominator of the "mod" part. |
| 32841 |
%\end{lverb} |
| 32842 |
% \begin{macrocode} |
| 32843 |
\def\xintDivMod {\romannumeral0\xintdivmod }% |
| 32844 |
\def\xintdivmod #1{\expandafter\XINT_divmod_a\romannumeral0\xintraw{#1}.}% |
| 32845 |
\def\XINT_divmod_a #1#2.#3% |
| 32846 |
{\expandafter\XINT_divmod_b\expandafter #1\romannumeral0\xintraw{#3}#2.}% |
| 32847 |
\def\XINT_divmod_b #1#2% #1 de A, #2 de B. |
| 32848 |
{% |
| 32849 |
\if0#2\xint_dothis{\XINT_divmod_divbyzero #1#2}\fi |
| 32850 |
\if0#1\xint_dothis\XINT_divmod_aiszero\fi |
| 32851 |
\if-#2\xint_dothis{\XINT_divmod_bneg #1}\fi |
| 32852 |
\xint_orthat{\XINT_divmod_bpos #1#2}% |
| 32853 |
}% |
| 32854 |
\def\XINT_divmod_divbyzero #1#2[#3]#4.% |
| 32855 |
{% |
| 32856 |
\XINT_signalcondition{DivisionByZero}{Division by zero: #1#4/(#2[#3]).}{}% |
| 32857 |
{{0}{0/1[0]}}% à revoir... |
| 32858 |
}% |
| 32859 |
\def\XINT_divmod_aiszero #1.{{0}{0/1[0]}}% |
| 32860 |
\def\XINT_divmod_bneg #1% f // -g = (-f) // g, f % -g = - ((-f) % g) |
| 32861 |
{% |
| 32862 |
\expandafter\XINT_divmod_bneg_finish |
| 32863 |
\romannumeral0\xint_UDsignfork |
| 32864 |
#1{\XINT_divmod_bpos {}}% |
| 32865 |
-{\XINT_divmod_bpos {-#1}}% |
| 32866 |
\krof |
| 32867 |
}% |
| 32868 |
\def\XINT_divmod_bneg_finish#1#2% |
| 32869 |
{% |
| 32870 |
\expandafter\xint_exchangetwo_keepbraces\expandafter |
| 32871 |
{\romannumeral0\xintiiopp#2}{#1}% |
| 32872 |
}% |
| 32873 |
\def\XINT_divmod_bpos #1#2/#3[#4]#5/#6[#7].% |
| 32874 |
{% |
| 32875 |
\expandafter\XINT_divmod_bpos_a |
| 32876 |
\the\numexpr\ifnum#7>#4 #4\else #7\fi\expandafter.% |
| 32877 |
\romannumeral0\expandafter\XINT_mod_D_b |
| 32878 |
\romannumeral0\XINT_div_prepare{#3}{#6}{#3}{#3}{#6}% |
| 32879 |
{#1#5}{#7-#4}{#2}{#4-#7}% |
| 32880 |
}% |
| 32881 |
\def\XINT_divmod_bpos_a #1.#2#3#4% |
| 32882 |
{% |
| 32883 |
\expandafter\XINT_divmod_bpos_finish |
| 32884 |
\romannumeral0\xintiidivision{#3}{#4}{/#2[#1]}% |
| 32885 |
}% |
| 32886 |
\def\XINT_divmod_bpos_finish #1#2#3{{#1}{#2#3}}% |
| 32887 |
% \end{macrocode} |
| 32888 |
% \subsection{\csh{xintMod}} |
| 32889 |
% \added{1.2p} |
| 32890 |
%\begin{lverb} |
| 32891 |
% \xintMod{q1}{q2} computes q1 - q2*floor(q1/q2). Attention that |
| 32892 |
% it relies on \xintiiE{x}{e} returning x if e < 0. |
| 32893 |
% |
| 32894 |
% Prior to 1.2p, that macro had the meaning now attributed to \xintModTrunc. |
| 32895 |
%\end{lverb} |
| 32896 |
% \changed{1.3} |
| 32897 |
%\begin{lverb} |
| 32898 |
% Modified (like \xintAdd and \xintSub) at 1.3 to use a l.c.m for final |
| 32899 |
% denominator. |
| 32900 |
%\end{lverb} |
| 32901 |
% \begin{macrocode} |
| 32902 |
\def\xintMod {\romannumeral0\xintmod }% |
| 32903 |
\def\xintmod #1{\expandafter\XINT_mod_a\romannumeral0\xintraw{#1}.}% |
| 32904 |
\def\XINT_mod_a #1#2.#3% |
| 32905 |
{\expandafter\XINT_mod_b\expandafter #1\romannumeral0\xintraw{#3}#2.}% |
| 32906 |
\def\XINT_mod_b #1#2% #1 de A, #2 de B. |
| 32907 |
{% |
| 32908 |
\if0#2\xint_dothis{\XINT_mod_divbyzero #1#2}\fi |
| 32909 |
\if0#1\xint_dothis\XINT_mod_aiszero\fi |
| 32910 |
\if-#2\xint_dothis{\XINT_mod_bneg #1}\fi |
| 32911 |
\xint_orthat{\XINT_mod_bpos #1#2}% |
| 32912 |
}% |
| 32913 |
% \end{macrocode} |
| 32914 |
%\begin{lverb} |
| 32915 |
% Attention to not move ModTrunc code beyond that point. |
| 32916 |
%\end{lverb} |
| 32917 |
% \begin{macrocode} |
| 32918 |
\let\XINT_mod_divbyzero\XINT_modtrunc_divbyzero |
| 32919 |
\let\XINT_mod_aiszero \XINT_modtrunc_aiszero |
| 32920 |
\def\XINT_mod_bneg #1% f % -g = - ((-f) % g), for g > 0 |
| 32921 |
{% |
| 32922 |
\xintiiopp\xint_UDsignfork |
| 32923 |
#1{\XINT_mod_bpos {}}% |
| 32924 |
-{\XINT_mod_bpos {-#1}}% |
| 32925 |
\krof |
| 32926 |
}% |
| 32927 |
\def\XINT_mod_bpos #1#2/#3[#4]#5/#6[#7].% |
| 32928 |
{% |
| 32929 |
\expandafter\XINT_mod_bpos_a |
| 32930 |
\the\numexpr\ifnum#7>#4 #4\else #7\fi\expandafter.% |
| 32931 |
\romannumeral0\expandafter\XINT_mod_D_b |
| 32932 |
\romannumeral0\XINT_div_prepare{#3}{#6}{#3}{#3}{#6}% |
| 32933 |
{#1#5}{#7-#4}{#2}{#4-#7}% |
| 32934 |
}% |
| 32935 |
\def\XINT_mod_D_a #1#2% |
| 32936 |
{% |
| 32937 |
\expandafter\XINT_mod_D_b |
| 32938 |
\romannumeral0\XINT_div_prepare {#1}{#2}{#1}% |
| 32939 |
}% |
| 32940 |
\def\XINT_mod_D_b #1#2{\XINT_mod_D_c #2\Z}% |
| 32941 |
\def\XINT_mod_D_c #1#2\Z |
| 32942 |
{% |
| 32943 |
\xint_gob_til_zero #1\XINT_mod_D_exit0\XINT_mod_D_a {#1#2}% |
| 32944 |
}% |
| 32945 |
\def\XINT_mod_D_exit0\XINT_mod_D_a #1#2#3% |
| 32946 |
{% |
| 32947 |
\expandafter\XINT_mod_E |
| 32948 |
\romannumeral0\xintiiquo {#3}{#2}.{#2}% |
| 32949 |
}% |
| 32950 |
\def\XINT_mod_E #1.#2#3% |
| 32951 |
{% |
| 32952 |
\expandafter\XINT_mod_F |
| 32953 |
\romannumeral0\xintiimul{#1}{#3}.{\xintiiQuo{#3}{#2}}{#1}% |
| 32954 |
}% |
| 32955 |
\def\XINT_mod_F #1.#2#3#4#5#6#7% |
| 32956 |
{% |
| 32957 |
{#1}{\xintiiE{\xintiiMul{#4}{#3}}{#5}}% |
| 32958 |
{\xintiiE{\xintiiMul{#6}{#2}}{#7}}% |
| 32959 |
}% |
| 32960 |
\def\XINT_mod_bpos_a #1.#2#3#4{\xintiirem {#3}{#4}/#2[#1]}% |
| 32961 |
% \end{macrocode} |
| 32962 |
% \subsection{\csh{xintIsOne}} |
| 32963 |
% \added{1.09a} |
| 32964 |
%\begin{lverb} |
| 32965 |
% Could be more efficient. For fractions with big |
| 32966 |
% powers of tens, it is better to use \xintCmp{f}{1}. Restyled in 1.09i. |
| 32967 |
%\end{lverb} |
| 32968 |
% \begin{macrocode} |
| 32969 |
\def\xintIsOne {\romannumeral0\xintisone }% |
| 32970 |
\def\xintisone #1{\expandafter\XINT_fracisone |
| 32971 |
\romannumeral0\xintrawwithzeros{#1}\Z }% |
| 32972 |
\def\XINT_fracisone #1/#2\Z |
| 32973 |
{\if0\xintiiCmp {#1}{#2}\xint_afterfi{ 1}\else\xint_afterfi{ 0}\fi}% |
| 32974 |
% \end{macrocode} |
| 32975 |
% \subsection{\csh{xintGeq}} |
| 32976 |
% \begin{macrocode} |
| 32977 |
\def\xintGeq {\romannumeral0\xintgeq }% |
| 32978 |
\def\xintgeq #1% |
| 32979 |
{% |
| 32980 |
\expandafter\XINT_fgeq\expandafter {\romannumeral0\xintabs {#1}}% |
| 32981 |
}% |
| 32982 |
\def\XINT_fgeq #1#2% |
| 32983 |
{% |
| 32984 |
\expandafter\XINT_fgeq_A \romannumeral0\xintabs {#2}#1% |
| 32985 |
}% |
| 32986 |
\def\XINT_fgeq_A #1% |
| 32987 |
{% |
| 32988 |
\xint_gob_til_zero #1\XINT_fgeq_Zii 0% |
| 32989 |
\XINT_fgeq_B #1% |
| 32990 |
}% |
| 32991 |
\def\XINT_fgeq_Zii 0\XINT_fgeq_B #1[#2]#3[#4]{ 1}% |
| 32992 |
\def\XINT_fgeq_B #1/#2[#3]#4#5/#6[#7]% |
| 32993 |
{% |
| 32994 |
\xint_gob_til_zero #4\XINT_fgeq_Zi 0% |
| 32995 |
\expandafter\XINT_fgeq_C\expandafter |
| 32996 |
{\the\numexpr #7-#3\expandafter}\expandafter |
| 32997 |
{\romannumeral0\xintiimul {#4#5}{#2}}% |
| 32998 |
{\romannumeral0\xintiimul {#6}{#1}}% |
| 32999 |
}% |
| 33000 |
\def\XINT_fgeq_Zi 0#1#2#3#4#5#6#7{ 0}% |
| 33001 |
\def\XINT_fgeq_C #1#2#3% |
| 33002 |
{% |
| 33003 |
\expandafter\XINT_fgeq_D\expandafter |
| 33004 |
{#3}{#1}{#2}% |
| 33005 |
}% |
| 33006 |
\def\XINT_fgeq_D #1#2#3% |
| 33007 |
{% |
| 33008 |
\expandafter\XINT_cntSgnFork\romannumeral`&&@\expandafter\XINT_cntSgn |
| 33009 |
\the\numexpr #2+\xintLength{#3}-\xintLength{#1}\relax\xint: |
| 33010 |
{ 0}{\XINT_fgeq_E #2\Z {#3}{#1}}{ 1}% |
| 33011 |
}% |
| 33012 |
\def\XINT_fgeq_E #1% |
| 33013 |
{% |
| 33014 |
\xint_UDsignfork |
| 33015 |
#1\XINT_fgeq_Fd |
| 33016 |
-{\XINT_fgeq_Fn #1}% |
| 33017 |
\krof |
| 33018 |
}% |
| 33019 |
\def\XINT_fgeq_Fd #1\Z #2#3% |
| 33020 |
{% |
| 33021 |
\expandafter\XINT_fgeq_Fe |
| 33022 |
\romannumeral0\XINT_dsx_addzeros {#1}#3;\xint:#2\xint: |
| 33023 |
}% |
| 33024 |
\def\XINT_fgeq_Fe #1\xint:#2#3\xint:{\XINT_geq_plusplus #2#1\xint:#3\xint:}% |
| 33025 |
\def\XINT_fgeq_Fn #1\Z #2#3% |
| 33026 |
{% |
| 33027 |
\expandafter\XINT_fgeq_Fo |
| 33028 |
\romannumeral0\XINT_dsx_addzeros {#1}#2;\xint:#3\xint: |
| 33029 |
}% |
| 33030 |
\def\XINT_fgeq_Fo #1#2\xint:#3\xint:{\XINT_geq_plusplus #1#3\xint:#2\xint:}% |
| 33031 |
% \end{macrocode} |
| 33032 |
% \subsection{\csh{xintMax}} |
| 33033 |
% \begin{macrocode} |
| 33034 |
\def\xintMax {\romannumeral0\xintmax }% |
| 33035 |
\def\xintmax #1% |
| 33036 |
{% |
| 33037 |
\expandafter\XINT_fmax\expandafter {\romannumeral0\xintraw {#1}}% |
| 33038 |
}% |
| 33039 |
\def\XINT_fmax #1#2% |
| 33040 |
{% |
| 33041 |
\expandafter\XINT_fmax_A\romannumeral0\xintraw {#2}#1% |
| 33042 |
}% |
| 33043 |
\def\XINT_fmax_A #1#2/#3[#4]#5#6/#7[#8]% |
| 33044 |
{% |
| 33045 |
\xint_UDsignsfork |
| 33046 |
#1#5\XINT_fmax_minusminus |
| 33047 |
-#5\XINT_fmax_firstneg |
| 33048 |
#1-\XINT_fmax_secondneg |
| 33049 |
--\XINT_fmax_nonneg_a |
| 33050 |
\krof |
| 33051 |
#1#5{#2/#3[#4]}{#6/#7[#8]}% |
| 33052 |
}% |
| 33053 |
\def\XINT_fmax_minusminus --% |
| 33054 |
{\expandafter-\romannumeral0\XINT_fmin_nonneg_b }% |
| 33055 |
\def\XINT_fmax_firstneg #1-#2#3{ #1#2}% |
| 33056 |
\def\XINT_fmax_secondneg -#1#2#3{ #1#3}% |
| 33057 |
\def\XINT_fmax_nonneg_a #1#2#3#4% |
| 33058 |
{% |
| 33059 |
\XINT_fmax_nonneg_b {#1#3}{#2#4}% |
| 33060 |
}% |
| 33061 |
\def\XINT_fmax_nonneg_b #1#2% |
| 33062 |
{% |
| 33063 |
\if0\romannumeral0\XINT_fgeq_A #1#2% |
| 33064 |
\xint_afterfi{ #1}% |
| 33065 |
\else \xint_afterfi{ #2}% |
| 33066 |
\fi |
| 33067 |
}% |
| 33068 |
% \end{macrocode} |
| 33069 |
% \subsection{\csh{xintMaxof}} |
| 33070 |
%\begin{lverb} |
| 33071 |
% 1.2l protects \xintMaxof against items with non terminated |
| 33072 |
% \the\numexpr expressions. |
| 33073 |
% |
| 33074 |
% 1.4 renders the macro compatible with an empty argument and it also defines |
| 33075 |
% an accessor \XINT_Maxof suitable for xintexpr usage (formerly xintexpr |
| 33076 |
% had its own macro handling comma separated values, but it changed |
| 33077 |
% internal representation at 1.4). |
| 33078 |
% |
| 33079 |
%\end{lverb} |
| 33080 |
% \begin{macrocode} |
| 33081 |
\def\xintMaxof {\romannumeral0\xintmaxof }% |
| 33082 |
\def\xintmaxof #1{\expandafter\XINT_maxof\romannumeral`&&@#1^}% |
| 33083 |
\def\XINT_Maxof{\romannumeral0\XINT_maxof}% |
| 33084 |
\def\XINT_maxof#1% |
| 33085 |
{% |
| 33086 |
\xint_gob_til_^ #1\XINT_maxof_empty ^% |
| 33087 |
\expandafter\XINT_maxof_loop\romannumeral0\xintraw{#1}\xint: |
| 33088 |
}% |
| 33089 |
\def\XINT_maxof_empty ^#1\xint:{ 0/1[0]}% |
| 33090 |
\def\XINT_maxof_loop #1\xint:#2% |
| 33091 |
{% |
| 33092 |
\xint_gob_til_^ #2\XINT_maxof_e ^% |
| 33093 |
\expandafter\XINT_maxof_loop |
| 33094 |
\romannumeral0\xintmax{#1}{\romannumeral0\xintraw{#2}}\xint: |
| 33095 |
}% |
| 33096 |
\def\XINT_maxof_e ^#1\xintmax #2#3\xint:{ #2}% |
| 33097 |
% \end{macrocode} |
| 33098 |
% \subsection{\csh{xintMin}} |
| 33099 |
% \begin{macrocode} |
| 33100 |
\def\xintMin {\romannumeral0\xintmin }% |
| 33101 |
\def\xintmin #1% |
| 33102 |
{% |
| 33103 |
\expandafter\XINT_fmin\expandafter {\romannumeral0\xintraw {#1}}% |
| 33104 |
}% |
| 33105 |
\def\XINT_fmin #1#2% |
| 33106 |
{% |
| 33107 |
\expandafter\XINT_fmin_A\romannumeral0\xintraw {#2}#1% |
| 33108 |
}% |
| 33109 |
\def\XINT_fmin_A #1#2/#3[#4]#5#6/#7[#8]% |
| 33110 |
{% |
| 33111 |
\xint_UDsignsfork |
| 33112 |
#1#5\XINT_fmin_minusminus |
| 33113 |
-#5\XINT_fmin_firstneg |
| 33114 |
#1-\XINT_fmin_secondneg |
| 33115 |
--\XINT_fmin_nonneg_a |
| 33116 |
\krof |
| 33117 |
#1#5{#2/#3[#4]}{#6/#7[#8]}% |
| 33118 |
}% |
| 33119 |
\def\XINT_fmin_minusminus --% |
| 33120 |
{\expandafter-\romannumeral0\XINT_fmax_nonneg_b }% |
| 33121 |
\def\XINT_fmin_firstneg #1-#2#3{ -#3}% |
| 33122 |
\def\XINT_fmin_secondneg -#1#2#3{ -#2}% |
| 33123 |
\def\XINT_fmin_nonneg_a #1#2#3#4% |
| 33124 |
{% |
| 33125 |
\XINT_fmin_nonneg_b {#1#3}{#2#4}% |
| 33126 |
}% |
| 33127 |
\def\XINT_fmin_nonneg_b #1#2% |
| 33128 |
{% |
| 33129 |
\if0\romannumeral0\XINT_fgeq_A #1#2% |
| 33130 |
\xint_afterfi{ #2}% |
| 33131 |
\else \xint_afterfi{ #1}% |
| 33132 |
\fi |
| 33133 |
}% |
| 33134 |
% \end{macrocode} |
| 33135 |
% \subsection{\csh{xintMinof}} |
| 33136 |
%\begin{lverb} |
| 33137 |
% 1.2l protects \xintMinof against items with non terminated |
| 33138 |
% \the\numexpr expressions. |
| 33139 |
% |
| 33140 |
% 1.4 version is compatible with an empty input (empty items are handled as zero). |
| 33141 |
%\end{lverb} |
| 33142 |
% \begin{macrocode} |
| 33143 |
\def\xintMinof {\romannumeral0\xintminof }% |
| 33144 |
\def\xintminof #1{\expandafter\XINT_minof\romannumeral`&&@#1^}% |
| 33145 |
\def\XINT_Minof{\romannumeral0\XINT_minof}% |
| 33146 |
\def\XINT_minof#1% |
| 33147 |
{% |
| 33148 |
\xint_gob_til_^ #1\XINT_minof_empty ^% |
| 33149 |
\expandafter\XINT_minof_loop\romannumeral0\xintraw{#1}\xint: |
| 33150 |
}% |
| 33151 |
\def\XINT_minof_empty ^#1\xint:{ 0/1[0]}% |
| 33152 |
\def\XINT_minof_loop #1\xint:#2% |
| 33153 |
{% |
| 33154 |
\xint_gob_til_^ #2\XINT_minof_e ^% |
| 33155 |
\expandafter\XINT_minof_loop\romannumeral0\xintmin{#1}{\romannumeral0\xintraw{#2}}\xint: |
| 33156 |
}% |
| 33157 |
\def\XINT_minof_e ^#1\xintmin #2#3\xint:{ #2}% |
| 33158 |
% \end{macrocode} |
| 33159 |
% \subsection{\csh{xintCmp}} |
| 33160 |
% \begin{macrocode} |
| 33161 |
\def\xintCmp {\romannumeral0\xintcmp }% |
| 33162 |
\def\xintcmp #1% |
| 33163 |
{% |
| 33164 |
\expandafter\XINT_fcmp\expandafter {\romannumeral0\xintraw {#1}}% |
| 33165 |
}% |
| 33166 |
\def\XINT_fcmp #1#2% |
| 33167 |
{% |
| 33168 |
\expandafter\XINT_fcmp_A\romannumeral0\xintraw {#2}#1% |
| 33169 |
}% |
| 33170 |
\def\XINT_fcmp_A #1#2/#3[#4]#5#6/#7[#8]% |
| 33171 |
{% |
| 33172 |
\xint_UDsignsfork |
| 33173 |
#1#5\XINT_fcmp_minusminus |
| 33174 |
-#5\XINT_fcmp_firstneg |
| 33175 |
#1-\XINT_fcmp_secondneg |
| 33176 |
--\XINT_fcmp_nonneg_a |
| 33177 |
\krof |
| 33178 |
#1#5{#2/#3[#4]}{#6/#7[#8]}% |
| 33179 |
}% |
| 33180 |
\def\XINT_fcmp_minusminus --#1#2{\XINT_fcmp_B #2#1}% |
| 33181 |
\def\XINT_fcmp_firstneg #1-#2#3{ -1}% |
| 33182 |
\def\XINT_fcmp_secondneg -#1#2#3{ 1}% |
| 33183 |
\def\XINT_fcmp_nonneg_a #1#2% |
| 33184 |
{% |
| 33185 |
\xint_UDzerosfork |
| 33186 |
#1#2\XINT_fcmp_zerozero |
| 33187 |
0#2\XINT_fcmp_firstzero |
| 33188 |
#10\XINT_fcmp_secondzero |
| 33189 |
00\XINT_fcmp_pos |
| 33190 |
\krof |
| 33191 |
#1#2% |
| 33192 |
}% |
| 33193 |
\def\XINT_fcmp_zerozero #1#2#3#4{ 0}% |
| 33194 |
\def\XINT_fcmp_firstzero #1#2#3#4{ -1}% |
| 33195 |
\def\XINT_fcmp_secondzero #1#2#3#4{ 1}% |
| 33196 |
\def\XINT_fcmp_pos #1#2#3#4% |
| 33197 |
{% |
| 33198 |
\XINT_fcmp_B #1#3#2#4% |
| 33199 |
}% |
| 33200 |
\def\XINT_fcmp_B #1/#2[#3]#4/#5[#6]% |
| 33201 |
{% |
| 33202 |
\expandafter\XINT_fcmp_C\expandafter |
| 33203 |
{\the\numexpr #6-#3\expandafter}\expandafter |
| 33204 |
{\romannumeral0\xintiimul {#4}{#2}}% |
| 33205 |
{\romannumeral0\xintiimul {#5}{#1}}% |
| 33206 |
}% |
| 33207 |
\def\XINT_fcmp_C #1#2#3% |
| 33208 |
{% |
| 33209 |
\expandafter\XINT_fcmp_D\expandafter |
| 33210 |
{#3}{#1}{#2}% |
| 33211 |
}% |
| 33212 |
\def\XINT_fcmp_D #1#2#3% |
| 33213 |
{% |
| 33214 |
\expandafter\XINT_cntSgnFork\romannumeral`&&@\expandafter\XINT_cntSgn |
| 33215 |
\the\numexpr #2+\xintLength{#3}-\xintLength{#1}\relax\xint: |
| 33216 |
{ -1}{\XINT_fcmp_E #2\Z {#3}{#1}}{ 1}% |
| 33217 |
}% |
| 33218 |
\def\XINT_fcmp_E #1% |
| 33219 |
{% |
| 33220 |
\xint_UDsignfork |
| 33221 |
#1\XINT_fcmp_Fd |
| 33222 |
-{\XINT_fcmp_Fn #1}% |
| 33223 |
\krof |
| 33224 |
}% |
| 33225 |
\def\XINT_fcmp_Fd #1\Z #2#3% |
| 33226 |
{% |
| 33227 |
\expandafter\XINT_fcmp_Fe |
| 33228 |
\romannumeral0\XINT_dsx_addzeros {#1}#3;\xint:#2\xint: |
| 33229 |
}% |
| 33230 |
\def\XINT_fcmp_Fe #1\xint:#2#3\xint:{\XINT_cmp_plusplus #2#1\xint:#3\xint:}% |
| 33231 |
\def\XINT_fcmp_Fn #1\Z #2#3% |
| 33232 |
{% |
| 33233 |
\expandafter\XINT_fcmp_Fo |
| 33234 |
\romannumeral0\XINT_dsx_addzeros {#1}#2;\xint:#3\xint: |
| 33235 |
}% |
| 33236 |
\def\XINT_fcmp_Fo #1#2\xint:#3\xint:{\XINT_cmp_plusplus #1#3\xint:#2\xint:}% |
| 33237 |
% \end{macrocode} |
| 33238 |
% \subsection{\csh{xintAbs}} |
| 33239 |
% \begin{macrocode} |
| 33240 |
\def\xintAbs {\romannumeral0\xintabs }% |
| 33241 |
\def\xintabs #1{\expandafter\XINT_abs\romannumeral0\xintraw {#1}}% |
| 33242 |
% \end{macrocode} |
| 33243 |
% \subsection{\csh{xintOpp}} |
| 33244 |
% \begin{macrocode} |
| 33245 |
\def\xintOpp {\romannumeral0\xintopp }% |
| 33246 |
\def\xintopp #1{\expandafter\XINT_opp\romannumeral0\xintraw {#1}}% |
| 33247 |
% \end{macrocode} |
| 33248 |
% \subsection{\csh{xintInv}} |
| 33249 |
% \changed{1.3d} |
| 33250 |
% \begin{macrocode} |
| 33251 |
\def\xintInv {\romannumeral0\xintinv }% |
| 33252 |
\def\xintinv #1{\expandafter\XINT_inv\romannumeral0\xintraw {#1}}% |
| 33253 |
\def\XINT_inv #1% |
| 33254 |
{% |
| 33255 |
\xint_UDzerominusfork |
| 33256 |
#1-\XINT_inv_iszero |
| 33257 |
0#1\XINT_inv_a |
| 33258 |
0-{\XINT_inv_a {}}% |
| 33259 |
\krof #1% |
| 33260 |
}% |
| 33261 |
\def\XINT_inv_iszero #1]% |
| 33262 |
{\XINT_signalcondition{DivisionByZero}{Inverse of zero: inv(#1]).}{}{ 0/1[0]}}% |
| 33263 |
\def\XINT_inv_a #1#2/#3[#4#5]% |
| 33264 |
{% |
| 33265 |
\xint_UDzerominusfork |
| 33266 |
#4-\XINT_inv_expiszero |
| 33267 |
0#4\XINT_inv_b |
| 33268 |
0-{\XINT_inv_b -#4}% |
| 33269 |
\krof #5.{#1#3/#2}% |
| 33270 |
}% |
| 33271 |
\def\XINT_inv_expiszero #1.#2{ #2[0]}% |
| 33272 |
\def\XINT_inv_b #1.#2{ #2[#1]}% |
| 33273 |
% \end{macrocode} |
| 33274 |
% \subsection{\csh{xintSgn}} |
| 33275 |
% \begin{macrocode} |
| 33276 |
\def\xintSgn {\romannumeral0\xintsgn }% |
| 33277 |
\def\xintsgn #1{\expandafter\XINT_sgn\romannumeral0\xintraw {#1}\xint:}% |
| 33278 |
% \end{macrocode} |
| 33279 |
% \subsection{\csh{xintSignBit}} |
| 33280 |
% \added{1.4l} |
| 33281 |
% \begin{macrocode} |
| 33282 |
\def\xintSignBit {\romannumeral0\xintsignbit }% |
| 33283 |
\def\xintsignbit #1{\expandafter\XINT_signbit\romannumeral0\xintraw {#1}\xint:}% |
| 33284 |
\def\XINT_signbit #1#2\xint: |
| 33285 |
{% |
| 33286 |
\xint_UDzerominusfork |
| 33287 |
#1-{ 0}% |
| 33288 |
0#1{ 1}% |
| 33289 |
0-{ 0}% |
| 33290 |
\krof |
| 33291 |
}% |
| 33292 |
% \end{macrocode} |
| 33293 |
% \subsection{\csh{xintGCD}} |
| 33294 |
% \changed{1.4} |
| 33295 |
% They replace the former \xintgcdnameimp macros of the same names which |
| 33296 |
% truncated to integers their arguments. Fraction-producing |gcd()| and |
| 33297 |
% |lcm()| functions were available since |1.3d| \xintexprnameimp, with |
| 33298 |
% non-public support macros handling comma separated values. |
| 33299 |
% |
| 33300 |
% \changed{1.4d} |
| 33301 |
% Somewhat strangely \csh{xintGCD} was formerly \csh{xintGCDof} used with only two |
| 33302 |
% arguments, as the latter directly implemented a fractionl gcd algorithm |
| 33303 |
% using \csh{xintMod} repeatedly for two arguments. |
| 33304 |
% |
| 33305 |
% Now \csh{xintGCD} contains the pairwise gcd routine and \csh{xintGCDof} |
| 33306 |
% is only a wrapper. And the pairwise gcd is reduced to integer-only |
| 33307 |
% computations to hopefully reduce fraction overhead. |
| 33308 |
% |
| 33309 |
% Each input is filtered via |\xintPIrr| and |\xintREZ| to reduce size |
| 33310 |
% of maniuplate integers in algebra. |
| 33311 |
% |
| 33312 |
% But hesitation about applying |\xintPIrr| to output, and/or |\xintREZ|. |
| 33313 |
% (as it is applied on input). |
| 33314 |
% |
| 33315 |
% But as the code is now used for frational lcm's we actually need to do |
| 33316 |
% some reduction of output else lcm's of integers will not be necessarily |
| 33317 |
% printed by |\xinteval| as integers. |
| 33318 |
% |
| 33319 |
% Well finally I apply |\xintIrr| (but not |\xintREZ| to output). |
| 33320 |
% Hesitations here (thinking of inputs with large [n] parts, the output |
| 33321 |
% will have many zeros). So I do this only for the user macro but |
| 33322 |
% the core routine as used by |\xintGCDof| will not do it. |
| 33323 |
% |
| 33324 |
% Also at |1.4d| the code uses |\expanded|. |
| 33325 |
% \begin{macrocode} |
| 33326 |
\def\xintGCD {\romannumeral0\xintgcd}% |
| 33327 |
\def\xintgcd #1% |
| 33328 |
{% |
| 33329 |
\expandafter\XINT_fgcd_in |
| 33330 |
\romannumeral0\xintrez{\xintPIrr{\xintAbs{#1}}}\xint: |
| 33331 |
}% |
| 33332 |
\def\XINT_fgcd_in #1#2\xint:#3% |
| 33333 |
{% |
| 33334 |
\expandafter\XINT_fgcd_out |
| 33335 |
\romannumeral0\expandafter\XINT_fgcd_chkzeros\expandafter#1% |
| 33336 |
\romannumeral0\xintrez{\xintPIrr{\xintAbs{#3}}}\xint:#1#2\xint: |
| 33337 |
}% |
| 33338 |
\def\XINT_fgcd_out#1[#2]{\xintirr{#1[#2]}[0]}% |
| 33339 |
\def\XINT_fgcd_chkzeros #1#2% |
| 33340 |
{% |
| 33341 |
\xint_UDzerofork |
| 33342 |
#1\XINT_fgcd_aiszero |
| 33343 |
#2\XINT_fgcd_biszero |
| 33344 |
0\XINT_fgcd_main |
| 33345 |
\krof #2% |
| 33346 |
}% |
| 33347 |
\def\XINT_fgcd_aiszero #1\xint:#2\xint:{ #1}% |
| 33348 |
\def\XINT_fgcd_biszero #1\xint:#2\xint:{ #2}% |
| 33349 |
\def\XINT_fgcd_main #1/#2[#3]\xint:#4/#5[#6]\xint: |
| 33350 |
{% |
| 33351 |
\expandafter\XINT_fgcd_a |
| 33352 |
\romannumeral0\XINT_gcd_loop #2\xint:#5\xint:\xint: |
| 33353 |
#2\xint:#5\xint:#1\xint:#4\xint:#3.#6.% |
| 33354 |
}% |
| 33355 |
\def\XINT_fgcd_a #1\xint:#2\xint: |
| 33356 |
{% |
| 33357 |
\expandafter\XINT_fgcd_b |
| 33358 |
\romannumeral0\xintiiquo{#2}{#1}\xint:#1\xint:#2\xint: |
| 33359 |
}% |
| 33360 |
\def\XINT_fgcd_b #1\xint:#2\xint:#3\xint:#4\xint:#5\xint:#6\xint:#7.#8.% |
| 33361 |
{% |
| 33362 |
\expanded{% |
| 33363 |
\xintiigcd{\xintiiE{\xintiiMul{#5}{\xintiiQuo{#4}{#2}}}{#7-#8}}% |
| 33364 |
{\xintiiE{\xintiiMul{#6}{#1}}{#8-#7}}% |
| 33365 |
/\xintiiMul{#1}{#4}% |
| 33366 |
[\ifnum#7>#8 #8\else #7\fi]% |
| 33367 |
}% |
| 33368 |
}% |
| 33369 |
% \end{macrocode} |
| 33370 |
% \subsection{\csh{xintGCDof}} |
| 33371 |
% \changed{1.4} |
| 33372 |
% This inherits from former non public \xintexprnameimp macro called |
| 33373 |
% |\xintGCDof:csv|, which handled comma separated items. |
| 33374 |
% |
| 33375 |
% It handles fractions presented as braced items and is the support macro |
| 33376 |
% for the |gcd()| function in |\xintexpr| and |\xintfloatexpr|. The support |
| 33377 |
% macro for the |gcd()| function in |\xintiiexpr| is \csbxint{iiGCDof}, from |
| 33378 |
% \xintnameimp. |
| 33379 |
% |
| 33380 |
% An empty input is allowed but I have some hesitations on the return |
| 33381 |
% value of 1. |
| 33382 |
% |
| 33383 |
% \changed{1.4d} |
| 33384 |
% Sadly the |1.4| version had multiple problems: |
| 33385 |
% \begin{itemize} |
| 33386 |
% \item broken if first argument vanished, |
| 33387 |
% \item broken if some argument was not in strict format, for example |
| 33388 |
% had leading chains of signs or zeros (|\xintGCDof{2}{03}|). |
| 33389 |
% This bug originates in the fact the original macro |
| 33390 |
% was used only in \xintexprnameimp sanitized context. |
| 33391 |
% \end{itemize} |
| 33392 |
% |
| 33393 |
% Also, output is now always an irreducible fraction (ending with |[0]|). |
| 33394 |
% \begin{macrocode} |
| 33395 |
\def\xintGCDof {\romannumeral0\xintgcdof}% |
| 33396 |
\def\xintgcdof #1{\expandafter\XINT_fgcdof\romannumeral`&&@#1^}% |
| 33397 |
\def\XINT_GCDof{\romannumeral0\XINT_fgcdof}% |
| 33398 |
\def\XINT_fgcdof #1% |
| 33399 |
{% |
| 33400 |
\expandafter\XINT_fgcdof_chkempty\romannumeral`&&@#1\xint: |
| 33401 |
}% |
| 33402 |
\def\XINT_fgcdof_chkempty #1% |
| 33403 |
{% |
| 33404 |
\xint_gob_til_^#1\XINT_fgcdof_empty ^\XINT_fgcdof_in #1% |
| 33405 |
}% |
| 33406 |
\def\XINT_fgcdof_empty #1\xint:{ 1/1[0]}% hesitation, should it be infinity? O? |
| 33407 |
\def\XINT_fgcdof_in #1\xint: |
| 33408 |
{% |
| 33409 |
\expandafter\XINT_fgcd_out |
| 33410 |
\romannumeral0\expandafter\XINT_fgcdof_loop |
| 33411 |
\romannumeral0\xintrez{\xintPIrr{\xintAbs{#1}}}\xint: |
| 33412 |
}% |
| 33413 |
\def\XINT_fgcdof_loop #1\xint:#2% |
| 33414 |
{% |
| 33415 |
\expandafter\XINT_fgcdof_chkend\romannumeral`&&@#2\xint:#1\xint:\xint: |
| 33416 |
}% |
| 33417 |
\def\XINT_fgcdof_chkend #1% |
| 33418 |
{% |
| 33419 |
\xint_gob_til_^#1\XINT_fgcdof_end ^\XINT_fgcdof_loop_pair #1% |
| 33420 |
}% |
| 33421 |
\def\XINT_fgcdof_end #1\xint:#2\xint:\xint:{ #2}% |
| 33422 |
\def\XINT_fgcdof_loop_pair #1\xint:#2% |
| 33423 |
{% |
| 33424 |
\expandafter\XINT_fgcdof_loop |
| 33425 |
\romannumeral0\expandafter\XINT_fgcd_chkzeros\expandafter#2% |
| 33426 |
\romannumeral0\xintrez{\xintPIrr{\xintAbs{#1}}}\xint:#2% |
| 33427 |
}% |
| 33428 |
% \end{macrocode} |
| 33429 |
% \subsection{\csh{xintLCM}} |
| 33430 |
% Same comments as for \csh{xintGCD}. |
| 33431 |
% Entirely redone for |1.4d|. |
| 33432 |
% Well, actually we can express it in terms of fractional gcd. |
| 33433 |
% \begin{macrocode} |
| 33434 |
\def\xintLCM {\romannumeral0\xintlcm}% |
| 33435 |
\def\xintlcm #1% |
| 33436 |
{% |
| 33437 |
\expandafter\XINT_flcm_in |
| 33438 |
\romannumeral0\xintrez{\xintPIrr{\xintAbs{#1}}}\xint: |
| 33439 |
}% |
| 33440 |
\def\XINT_flcm_in #1#2\xint:#3% |
| 33441 |
{% |
| 33442 |
\expandafter\XINT_fgcd_out |
| 33443 |
\romannumeral0\expandafter\XINT_flcm_chkzeros\expandafter#1% |
| 33444 |
\romannumeral0\xintrez{\xintPIrr{\xintAbs{#3}}}\xint:#1#2\xint: |
| 33445 |
}% |
| 33446 |
\def\XINT_flcm_chkzeros #1#2% |
| 33447 |
{% |
| 33448 |
\xint_UDzerofork |
| 33449 |
#1\XINT_flcm_zero |
| 33450 |
#2\XINT_flcm_zero |
| 33451 |
0\XINT_flcm_main |
| 33452 |
\krof #2% |
| 33453 |
}% |
| 33454 |
\def\XINT_flcm_zero #1\xint:#2\xint:{ 0/1[0]}% |
| 33455 |
\def\XINT_flcm_main #1/#2[#3]\xint:#4/#5[#6]\xint: |
| 33456 |
{% |
| 33457 |
\xintinv |
| 33458 |
{% |
| 33459 |
\romannumeral0\XINT_fgcd_main #2/#1[-#3]\xint:#5/#4[-#6]\xint: |
| 33460 |
}% |
| 33461 |
}% |
| 33462 |
% \end{macrocode} |
| 33463 |
% \subsection{\csh{xintLCMof}} |
| 33464 |
% See comments for |\xintGCDof|. \xintnameimp provides the integer only |
| 33465 |
% \csbxint{iiLCMof}. |
| 33466 |
% |
| 33467 |
% \changed{1.4d}{} |
| 33468 |
% Sadly, although a public \xintfracnameimp macro, it did not (since |1.4|) |
| 33469 |
% sanitize its arguments like other \xintfracnameimp macros. |
| 33470 |
% |
| 33471 |
% \begin{macrocode} |
| 33472 |
\def\xintLCMof {\romannumeral0\xintlcmof}% |
| 33473 |
\def\xintlcmof #1{\expandafter\XINT_flcmof\romannumeral`&&@#1^}% |
| 33474 |
\def\XINT_LCMof{\romannumeral0\XINT_flcmof}% |
| 33475 |
\def\XINT_flcmof #1% |
| 33476 |
{% |
| 33477 |
\expandafter\XINT_flcmof_chkempty\romannumeral`&&@#1\xint: |
| 33478 |
}% |
| 33479 |
\def\XINT_flcmof_chkempty #1% |
| 33480 |
{% |
| 33481 |
\xint_gob_til_^#1\XINT_flcmof_empty ^\XINT_flcmof_in #1% |
| 33482 |
}% |
| 33483 |
\def\XINT_flcmof_empty #1\xint:{ 0/1[0]}% hesitation |
| 33484 |
\def\XINT_flcmof_in #1\xint: |
| 33485 |
{% |
| 33486 |
\expandafter\XINT_fgcd_out |
| 33487 |
\romannumeral0\expandafter\XINT_flcmof_loop |
| 33488 |
\romannumeral0\xintrez{\xintPIrr{\xintAbs{#1}}}\xint: |
| 33489 |
}% |
| 33490 |
\def\XINT_flcmof_loop #1\xint:#2% |
| 33491 |
{% |
| 33492 |
\expandafter\XINT_flcmof_chkend\romannumeral`&&@#2\xint:#1\xint:\xint: |
| 33493 |
}% |
| 33494 |
\def\XINT_flcmof_chkend #1% |
| 33495 |
{% |
| 33496 |
\xint_gob_til_^#1\XINT_flcmof_end ^\XINT_flcmof_loop_pair #1% |
| 33497 |
}% |
| 33498 |
\def\XINT_flcmof_end #1\xint:#2\xint:\xint:{ #2}% |
| 33499 |
\def\XINT_flcmof_loop_pair #1\xint:#2% |
| 33500 |
{% |
| 33501 |
\expandafter\XINT_flcmof_chkzero |
| 33502 |
\romannumeral0\expandafter\XINT_flcm_chkzeros\expandafter#2% |
| 33503 |
\romannumeral0\xintrez{\xintPIrr{\xintAbs{#1}}}\xint:#2% |
| 33504 |
}% |
| 33505 |
\def\XINT_flcmof_chkzero #1% |
| 33506 |
{% |
| 33507 |
\xint_gob_til_zero#1\XINT_flcmof_zero0\XINT_flcmof_loop#1% |
| 33508 |
}% |
| 33509 |
\def\XINT_flcmof_zero#1^{ 0/1[0]}% |
| 33510 |
% \end{macrocode} |
| 33511 |
% \subsection{Floating point macros} |
| 33512 |
% |
| 33513 |
% For a long time the float routines dating back to releases |1.07/1.08a| |
| 33514 |
% (May-June 2013) were not modified. |
| 33515 |
% |
| 33516 |
% Since |1.2f| (March 2016) the four operations first round their arguments to |
| 33517 |
% |\xinttheDigits|-floats (or |P|-floats), not (|\xinttheDigits+2|)-floats or |
| 33518 |
% (|P+2|)-floats as was the case with earlier releases. |
| 33519 |
% |
| 33520 |
% The four operations addition, subtraction, multiplication, division have |
| 33521 |
% always produced the correct rounding of the theoretical exact value to |P| |
| 33522 |
% or |\xinttheDigits| digits when the inputs are decimal numbers with at most |
| 33523 |
% |P| digits, and arbitrary decimal exponent part. |
| 33524 |
% |
| 33525 |
% From |1.08a| to |1.2j|, |\xintFloat| (and |\XINTinFloat| which is used to |
| 33526 |
% parse inputs to other float macros) handled a fractional input |A/B| via an |
| 33527 |
% initial replacement to |A'/B'| where |A'| and |B'| were |A| and |B| |
| 33528 |
% truncated to |Q+2| digits (where asked-for precision is |Q|), and then they |
| 33529 |
% correctly rounded |A'/B'| to |Q| digits. But this meant that this rounding of |
| 33530 |
% the input could differ (by up to one unit in the last place) from the |
| 33531 |
% correct rounding of the original |A/B| to the asked-for number of |
| 33532 |
% digits (which until |1.2f| in uses as auxiliary to the macros for the basic |
| 33533 |
% operations was 2 more than the prevailing precision). |
| 33534 |
% |
| 33535 |
% Since |1.2k| all inputs are correctly rounded to the asked-for number of |
| 33536 |
% digits (this was, I think, the case in the |1.07| release -- there are no |
| 33537 |
% code comments -- but was, afaicr, not very efficiently done, and this is why |
| 33538 |
% the |1.08a| release opeted for truncation of the numerator and denominator.) |
| 33539 |
% |
| 33540 |
% Notice that in float expressions, the |/| is treated as operator, hence the |
| 33541 |
% above discussion makes a difference only for the special input form |
| 33542 |
% |qfloat(A/B)| or for an |\xintexpr A/B\relax| embedded in the float |
| 33543 |
% expression, with |A| or |B| having more digits than the prevailing float |
| 33544 |
% precision. |
| 33545 |
% |
| 33546 |
% \begin{framed} |
| 33547 |
% Internally there is no inner representation of |P|-floats as such !!!!! |
| 33548 |
% |
| 33549 |
% The input parser will again compute the length of the mantissa on each use |
| 33550 |
% !!! This is obviously something that must be improved upon before |
| 33551 |
% implementation of higher functions. |
| 33552 |
% |
| 33553 |
% Currently, special tricks are used to quickly recognize inputs having no |
| 33554 |
% denominators, or fractions whose numerators and denominators are not too |
| 33555 |
% long compared to the target precision |P|, and in particular |P|-floats or |
| 33556 |
% quotients of two such. |
| 33557 |
% |
| 33558 |
% Another long-standing issue is that float multiplication will first |
| 33559 |
% compute the |2P| or |2P-1| digits of the exact product, and then round it |
| 33560 |
% to |P| digits. This is sub-optimal for large |P| particularly as the |
| 33561 |
% multiplication algorithm is basically the schoolbook one, hence |
| 33562 |
% \emph{worse} than quadratic in the \TeX\ implementation which has extra |
| 33563 |
% cost of fetching long sequences of tokens. |
| 33564 |
% \end{framed} |
| 33565 |
% |
| 33566 |
%\begin{lverb} |
| 33567 |
% Changes at 1.4e (done 2021/04/15; undone 2021/04/29) |
| 33568 |
% |
| 33569 |
% Macros named \XINTinFloat<name> are not public user-level but were designed |
| 33570 |
% a long time ago for \xintfloatexpr context as a very preliminary step |
| 33571 |
% towards attempting to preserve some internal format, here A[N] type. |
| 33572 |
% |
| 33573 |
% When <name> is lowercased it means it needs a \romannumeral0 trigger |
| 33574 |
% (\XINTinfloatS keeps an uppercase S). |
| 33575 |
% |
| 33576 |
% Most were coded to check for an optional argument [D], and to use |
| 33577 |
% D=\XINTdigits in its place if absent but it turned out only \XINTinfloatpow, |
| 33578 |
% \XINTinfloatmul, \XINTinfloatadd were actually used with an optional |
| 33579 |
% argument and this happened only in macros from the very old xintseries.sty, |
| 33580 |
% so I changed all of them to not check for optional argument [D] anymore, |
| 33581 |
% keeping only some private interface for the xintseries.sty use case. Some |
| 33582 |
% required being used with [D], some still had names ending in "digits" |
| 33583 |
% indicating they would use \XINTdigits always. |
| 33584 |
% |
| 33585 |
% Indeed basically all algebra is done "exactly" and the [D] governs rules of |
| 33586 |
% float-rounding on input and output. |
| 33587 |
% |
| 33588 |
% During development of 1.4e we fleetingly experimented with letting the value |
| 33589 |
% used in place of D be \XINTdigitsx to 1.4e, i.e. \XINTdigits with guard |
| 33590 |
% digits, a situation which was motivated by the implementation of |
| 33591 |
% trigonometrical functions at high level, i.e. using \xintdeffloatfunc which |
| 33592 |
% had no mechanism to make intermediate calculations with guard digits. |
| 33593 |
% |
| 33594 |
% Simply doing everything "as is" but with 2 guard digits proved very good |
| 33595 |
% (surprisingly efficient, even) to the trigonometrical functions. However |
| 33596 |
% using them systematically raises many issues (for example, the correct |
| 33597 |
% rounding at P digits is destroyed if we obtain it a D=P+2 then round from |
| 33598 |
% P+2 to P digits so we definitely can not do this as default, so some |
| 33599 |
% interface is needed to define intermediate functions only using such guard |
| 33600 |
% digits and keeping them in their output). |
| 33601 |
% |
| 33602 |
% Finally, an approach limited to the xinttrig.sty scope was used and I |
| 33603 |
% removed all \XINTdigitsx related matters from 1.4e. But this left some |
| 33604 |
% modifications of the interfaces of the "float" macros here which this list |
| 33605 |
% tries to document, mainly for the author's benefit. |
| 33606 |
% |
| 33607 |
%( Macros always using \XINTdigits and now not allowing [P] option |
| 33608 |
%: \XINTinFloatAdd |
| 33609 |
%: \XINTinFloatSub |
| 33610 |
%: \XINTinFloatMul |
| 33611 |
%: \XINTinFloatSqr |
| 33612 |
%: \XINTinFloatInv |
| 33613 |
%: \XINTinFloatDiv |
| 33614 |
%: \XINTinFloatPow |
| 33615 |
%: \XINTinFloatPower |
| 33616 |
%: \XINTinFloatPFactorial |
| 33617 |
%: \XINTinFloatBinomial |
| 33618 |
%: |
| 33619 |
%: Macros which already did not allow [P] option prior to 1.4e refactoring |
| 33620 |
%: \XINTinFloatFrac (renamed from \XINTinFloatFracdigits) |
| 33621 |
%: \XINTinFloatE |
| 33622 |
%: \XINTinFloatMod |
| 33623 |
%: \XINTinFloatDivFloor |
| 33624 |
%: \XINTinFloatDivMod |
| 33625 |
%: |
| 33626 |
%: Macros requiring a [P]. Some of the "_wopt" named macros are& |
| 33627 |
% renamings of macros formerly requiring [P]. |
| 33628 |
%: \XINTinFloat |
| 33629 |
%: \XINTinFloatS |
| 33630 |
%: \XINTFloatiLogTen |
| 33631 |
%: \XINTinRandomFloatS (this one has only the [P] mandatory argument) |
| 33632 |
%: \XINTinFloatFac |
| 33633 |
%: \XINTinFloatSqrt |
| 33634 |
%: \XINTinFloatAdd_wopt, \XINTinfloatadd_wopt |
| 33635 |
%: \XINTinFloatSub_wopt, \XINTinfloatsub_wopt |
| 33636 |
%: \XINTinFloatMul_wopt, \XINTinfloatmul_wopt |
| 33637 |
%: \XINTinFloatSqr_wopt |
| 33638 |
%: \XINTinfloatpow_wopt (not FloatPow) |
| 33639 |
%: \XINTinFloatDiv_wopt |
| 33640 |
%: \XINTinFloatInv_wopt |
| 33641 |
%: |
| 33642 |
%: Specially named macros indicating usage of \XINTdigits |
| 33643 |
%: \XINTinFloatdigits |
| 33644 |
%: \XINTinFloatSdigits |
| 33645 |
%: \XINTFloatiLogTendigits |
| 33646 |
%: \XINTinRandomFloatSdigits |
| 33647 |
%: \XINTinFloatFacdigits |
| 33648 |
%: \XINTinFloatSqrtdigits |
| 33649 |
%) |
| 33650 |
%\end{lverb} |
| 33651 |
% |
| 33652 |
% \subsection{\csh{xintDigits}, \csh{xintSetDigits}} |
| 33653 |
% \changed{1.3} |
| 33654 |
%\begin{lverb} |
| 33655 |
% 1.3f allows \xintDigits= in place of \xintDigits$empty:= syntax. |
| 33656 |
% It defines \xintDigits*[:]= which reloads xinttrig.sty. Perhaps this should |
| 33657 |
% be default, well. |
| 33658 |
% |
| 33659 |
% During 1.4e development I added an interface for guard digits, but I decided |
| 33660 |
% to drop inclusion from 1.4e release because there were pending issues both |
| 33661 |
% in documentation and functionalities for which I did not have time left. |
| 33662 |
% |
| 33663 |
% 1.4e fixes the issue that \xinttheDigits could not be used in the right hand |
| 33664 |
% side of \xintDigits[*][:]=...; or inside the argument to \xintSetDigits. |
| 33665 |
%\end{lverb} |
| 33666 |
% \begin{macrocode} |
| 33667 |
\mathchardef\XINTdigits 16 |
| 33668 |
\chardef\XINTguarddigits 0 |
| 33669 |
\def\xinttheDigits {\number\XINTdigits}% |
| 33670 |
%\def\xinttheGuardDigits{\number\XINTguarddigits}% |
| 33671 |
\def\xinttheGuardDigits{0}% in case used in some of my test files |
| 33672 |
\def\xintDigits #1={\afterassignment\xintDigits_i\mathchardef\XINT_digits=}% |
| 33673 |
\def\xintDigits_i#1% |
| 33674 |
{% |
| 33675 |
\let\XINTdigits\XINT_digits |
| 33676 |
}% |
| 33677 |
\def\xintSetDigits #1% |
| 33678 |
{% |
| 33679 |
\mathchardef\XINT_digits=\numexpr#1\relax |
| 33680 |
\let\XINTdigits=\XINT_digits |
| 33681 |
}% |
| 33682 |
% \end{macrocode} |
| 33683 |
% |
| 33684 |
% \subsection{\csh{xintFloat}, \csh{xintFloatZero}} |
| 33685 |
%\begin{lverb} |
| 33686 |
% 1.2f and 1.2g brought some refactoring which resulted in faster treatment of |
| 33687 |
% decimal inputs. 1.2i dropped use of some old routines dating back to pre 1.2 |
| 33688 |
% era in favor of more modern \xintDSRr for rounding. Then 1.2k improves |
| 33689 |
% again the handling of denominators B with few digits. |
| 33690 |
% |
| 33691 |
% But the main change with 1.2k is a complete rewrite of the B>1 case in |
| 33692 |
% order to achieve again correct rounding in all cases. |
| 33693 |
% |
| 33694 |
% The original version from 1.07 (May 2013) computed the exact rounding |
| 33695 |
% to P digits for all inputs. But from 1.08 on (June 2013), the macro handled |
| 33696 |
% A/B input by first truncating both A and B to at most P+2 digits. This meant |
| 33697 |
% that decimal input (arbitrarily long, with scientific part) was correctly |
| 33698 |
% rounded, but in case of fractional input there could be up to 0.6 unit in |
| 33699 |
% the last place difference of the produced rounding to the input, hence the |
| 33700 |
% output could differ from the correct rounding. |
| 33701 |
% |
| 33702 |
% Example with 16 digits (the default): \xintFloat {1/17597472569900621233}$newline |
| 33703 |
% with xintfrac 1.07: 5.682634230727187e-20$newline |
| 33704 |
% with xintfrac 1.08b--1.2j: 5.682634230727188e-20$newline |
| 33705 |
% with xintfrac 1.2k: 5.682634230727187e-20$newline |
| 33706 |
% The exact value is 5.682634230727187499924124...e-20, showing that 1.07 and |
| 33707 |
% 1.2k |
| 33708 |
% produce the correct rounding. |
| 33709 |
% |
| 33710 |
% Currently the code ends in a more costly branch in about 1 case among 500, |
| 33711 |
% where it does some extra operations (a multiplication in particular). There |
| 33712 |
% is a free parameter delta (here set at 4), I have yet to make some numerical |
| 33713 |
% explorations, to see if it could be favorable to set it to a higher value |
| 33714 |
% (with delta=5, there is only 1 exceptional case in 5000, etc...). |
| 33715 |
% |
| 33716 |
% I have always hesitated about the policy of printing 10.00...0 in case of |
| 33717 |
% rounding upwards to the next power of ten. Already since 1.2f \XINTinFloat |
| 33718 |
% always produced a mantissa with exactly P digits (except for the zero |
| 33719 |
% value). Starting with 1.2k, \xintFloat drops this habit of printing |
| 33720 |
% 10.00..0 in such cases. Side note: the rounding-up detection worked when the |
| 33721 |
% input A/B was with numerator A and denominator B having each less than P+2 |
| 33722 |
% digits, or with B=1, else, it could happen that the output was a power of |
| 33723 |
% ten but not detected to be a rounding up of the original fraction. The value |
| 33724 |
% was ok, but printed 1.0...0eN with P-1 zeroes, not 10.0...0e(N-1). |
| 33725 |
% |
| 33726 |
% I decided it was not worth the effort to enhance the algorithm to detect |
| 33727 |
% with 100$% fiability all cases of rounding up to next |
| 33728 |
% power of ten, hence 1.2k dropped this. |
| 33729 |
% |
| 33730 |
% To avoid duplication of code, and any extra burden on \XINTinFloat, which is |
| 33731 |
% the macro used internally by the float macros for parsing their inputs, we |
| 33732 |
% simply make now \xintFloat a wrapper of \XINTinFloat. |
| 33733 |
%\end{lverb} |
| 33734 |
% \begin{macrocode} |
| 33735 |
\def\xintFloatZero{0.0e0}% 1.4k breaking change. Replaces hard-coded 0.e0 |
| 33736 |
\def\xintFloat {\romannumeral0\xintfloat }% |
| 33737 |
\def\xintfloat #1{\XINT_float_chkopt #1\xint:}% |
| 33738 |
\def\XINT_float_chkopt #1% |
| 33739 |
{% |
| 33740 |
\ifx [#1\expandafter\XINT_float_opt |
| 33741 |
\else\expandafter\XINT_float_noopt |
| 33742 |
\fi #1% |
| 33743 |
}% |
| 33744 |
\def\XINT_float_noopt #1\xint:% |
| 33745 |
{% |
| 33746 |
\expandafter\XINT_float_post |
| 33747 |
\romannumeral0\XINTinfloat[\XINTdigits]{#1}\XINTdigits.% |
| 33748 |
}% |
| 33749 |
\def\XINT_float_opt [\xint: |
| 33750 |
{% |
| 33751 |
\expandafter\XINT_float_opt_a\the\numexpr |
| 33752 |
}% |
| 33753 |
\def\XINT_float_opt_a #1]#2% |
| 33754 |
{% |
| 33755 |
\expandafter\XINT_float_post |
| 33756 |
\romannumeral0\XINTinfloat[#1]{#2}#1.% |
| 33757 |
}% |
| 33758 |
\def\XINT_float_post #1% |
| 33759 |
{% |
| 33760 |
\xint_UDzerominusfork |
| 33761 |
#1-\XINT_float_zero |
| 33762 |
0#1\XINT_float_neg |
| 33763 |
0-\XINT_float_pos |
| 33764 |
\krof #1% |
| 33765 |
}%[ |
| 33766 |
\def\XINT_float_zero #1]#2.{\expanded{ \xintFloatZero}}% |
| 33767 |
\def\XINT_float_neg-{\expandafter-\romannumeral0\XINT_float_pos}% |
| 33768 |
\def\XINT_float_pos #1#2[#3]#4.% |
| 33769 |
{% |
| 33770 |
\expandafter\XINT_float_pos_done\the\numexpr#3+#4-\xint_c_i.#1.#2;% |
| 33771 |
}% |
| 33772 |
\def\XINT_float_pos_done #1.#2;{ #2e#1}% |
| 33773 |
% \end{macrocode} |
| 33774 |
% \subsection{\csh{xintFloatBraced}} |
| 33775 |
% \added{1.4l} |
| 33776 |
%\begin{lverb} |
| 33777 |
% Je ne le fais pas comme un wrapper au-dessus de \xintFloat |
| 33778 |
% car c'est pénible avec argument optionnel donc finalemnt |
| 33779 |
% on est obligé de rajouter overhead comme ici. |
| 33780 |
% |
| 33781 |
%( Hésitation si on obéit à \xintFloatZero ou pas. Finalement non. |
| 33782 |
%: Hésitation si on renvoie avec séparateur décimal ou pas. |
| 33783 |
%: Hésitation si on met l'exposant scientifique en premier. |
| 33784 |
%: Hésitation si on sépare le signe pour le mettre en premier. |
| 33785 |
%: Hésitation si on renvoie un exposant pour mantisse normalisée& |
| 33786 |
% ou pas normalisée. |
| 33787 |
%) |
| 33788 |
% |
| 33789 |
% Finalement je décide {signe}{exposant}{mantisse sans point décimal}. |
| 33790 |
% Avec en fait 0 ou 1 pour signe (mais ce sign bit mais ça n'a pas grand |
| 33791 |
% sens en décimal...). Non finalement mantisse avec point décimal. |
| 33792 |
%\end{lverb} |
| 33793 |
% \begin{macrocode} |
| 33794 |
\def\xintFloatBraced{\romannumeral0\xintfloatbraced }% |
| 33795 |
\def\xintfloatbraced#1{\XINT_floatbr_chkopt #1\xint:}% |
| 33796 |
\def\XINT_floatbr_chkopt #1% |
| 33797 |
{% |
| 33798 |
\ifx [#1\expandafter\XINT_floatbr_opt |
| 33799 |
\else\expandafter\XINT_floatbr_noopt |
| 33800 |
\fi #1% |
| 33801 |
}% |
| 33802 |
\def\XINT_floatbr_noopt #1\xint:% |
| 33803 |
{% |
| 33804 |
\expandafter\XINT_floatbr_post |
| 33805 |
\romannumeral0\XINTinfloat[\XINTdigits]{#1}\XINTdigits.% |
| 33806 |
}% |
| 33807 |
\def\XINT_floatbr_opt [\xint: |
| 33808 |
{% |
| 33809 |
\expandafter\XINT_floatbr_opt_a\the\numexpr |
| 33810 |
}% |
| 33811 |
\def\XINT_floatbr_opt_a #1]#2% |
| 33812 |
{% |
| 33813 |
\expandafter\XINT_floatbr_post |
| 33814 |
\romannumeral0\XINTinfloat[#1]{#2}#1.% |
| 33815 |
}% |
| 33816 |
\def\XINT_floatbr_post #1% |
| 33817 |
{% |
| 33818 |
\xint_UDzerominusfork |
| 33819 |
#1-\XINT_floatbr_zero |
| 33820 |
0#1\XINT_floatbr_neg |
| 33821 |
0-\XINT_floatbr_pos |
| 33822 |
\krof #1% |
| 33823 |
}% |
| 33824 |
% \end{macrocode} |
| 33825 |
%\begin{lverb} |
| 33826 |
% Hésitation à faire |
| 33827 |
%( \def\XINT_floatbr_zero #1]#2.{\expandafter\XINT_floatbr_zero_a\xintFloatZero e0e\relax}% |
| 33828 |
%: \def\XINT_floatbr_zero_a#1e#2e#3\relax{{#1}{#2}}% |
| 33829 |
%) |
| 33830 |
% Finalement non. Et même je décide de renvoyer autant de zéros que P. |
| 33831 |
% De plus depuis j'ai opté pour {sign bit}{exposant}{mantisse} |
| 33832 |
% Hésitation si mantisse avec ou sans le séparateur décimal. |
| 33833 |
% Est-ce que je devrais mettre plutôt -0+ au début? |
| 33834 |
%\end{lverb} |
| 33835 |
% \begin{macrocode} |
| 33836 |
\def\XINT_floatbr_zero #1]#2.{\expanded{{0}{0}{0.\xintReplicate{#2-\xint_c_i}0}}}% |
| 33837 |
\def\XINT_floatbr_neg-{\expandafter\XINT_floatbr_neg_a\romannumeral0\XINT_floatbr_pos}% |
| 33838 |
\def\XINT_floatbr_neg_a#1{{1}}% |
| 33839 |
\def\XINT_floatbr_pos #1#2[#3]#4.% |
| 33840 |
{% |
| 33841 |
\expanded{{0}{\the\numexpr#3+#4-\xint_c_i}}{#1.#2}% |
| 33842 |
}% |
| 33843 |
% \end{macrocode} |
| 33844 |
% \subsection{\csh{XINTinFloat}, \csh{XINTinFloatS}} |
| 33845 |
%\begin{lverb} |
| 33846 |
% This routine is like \xintFloat but produces an output of the shape A[N] |
| 33847 |
% which is then parsed faster as input to other float macros. |
| 33848 |
% Float operations in \xintfloatexpr...\relax use internally this format. |
| 33849 |
% |
| 33850 |
% It must be used in form \XINTinFloat[P]{f}: the optional [P] is |
| 33851 |
% mandatory. |
| 33852 |
% |
| 33853 |
% Since 1.2f, the mantissa always has exactly P digits even in case of |
| 33854 |
% rounding up to next power of ten. This simplifies other routines. |
| 33855 |
% |
| 33856 |
% (but the zero value must always be checked for, as it outputs 0[0]) |
| 33857 |
% |
| 33858 |
% 1.2g added a variant \XINTinFloatS which, in case of decimal input with less |
| 33859 |
% than the asked for precision P will not add extra zeros to the mantissa. For |
| 33860 |
% example it may output 2[0] even if P=500, rather than the canonical |
| 33861 |
% representation 200...000[-499]. This is how \xintFloatMul and \xintFloatDiv |
| 33862 |
% parse their inputs, which speeds-up follow-up processing. But \xintFloatAdd |
| 33863 |
% and \xintFloatSub still use \XINTinFloat for parsing their inputs; anyway |
| 33864 |
% this will have to be changed again when inner structure will carry upfront |
| 33865 |
% at least the length of mantissa as data. |
| 33866 |
% |
| 33867 |
% Each time \XINTinFloat is called it at least computes a length. Naturally if |
| 33868 |
% we had some format for floats that would be dispensed of...$newline |
| 33869 |
% something like |
| 33870 |
% <letterP><length of mantissa>.mantissa.exponent, etc... not yet. |
| 33871 |
% |
| 33872 |
% Since 1.2k, \XINTinFloat always correctly rounds its argument, even if it |
| 33873 |
% is a fraction with very big numerator and denominator. See the discussion of |
| 33874 |
% \xintFloat. |
| 33875 |
%\end{lverb} |
| 33876 |
% \begin{macrocode} |
| 33877 |
\def\XINTinFloat {\romannumeral0\XINTinfloat }% |
| 33878 |
\def\XINTinfloat |
| 33879 |
{\expandafter\XINT_infloat_clean\romannumeral0\XINT_infloat}% |
| 33880 |
% \end{macrocode} |
| 33881 |
%\begin{lverb} |
| 33882 |
% Attention que ici le fait que l'on grabbe #1 est important car il |
| 33883 |
% pourrait y avoir un zéro (en particulier dans le cas où input est nul). |
| 33884 |
%\end{lverb} |
| 33885 |
% \begin{macrocode} |
| 33886 |
\def\XINT_infloat_clean #1% |
| 33887 |
{\if #1!\xint_dothis\XINT_infloat_clean_a\fi\xint_orthat{ }#1}% |
| 33888 |
% \end{macrocode} |
| 33889 |
%\begin{lverb} |
| 33890 |
% Ici on ajoute les zeros pour faire exactement avec P chiffres. |
| 33891 |
% Car le #1 = P - L avec L la longueur de #2, (ou plutôt de abs(#2), |
| 33892 |
% car ici le #2 peut avoir un signe) et L < P |
| 33893 |
%\end{lverb} |
| 33894 |
% \begin{macrocode} |
| 33895 |
\def\XINT_infloat_clean_a !#1.#2[#3]% |
| 33896 |
{% |
| 33897 |
\expandafter\XINT_infloat_done |
| 33898 |
\the\numexpr #3-#1\expandafter.% |
| 33899 |
\romannumeral0\XINT_dsx_addzeros {#1}#2;;% |
| 33900 |
}% |
| 33901 |
\def\XINT_infloat_done #1.#2;{ #2[#1]}% |
| 33902 |
% \end{macrocode} |
| 33903 |
%\begin{lverb} |
| 33904 |
% variant which allows output with shorter mantissas. |
| 33905 |
%\end{lverb} |
| 33906 |
% \begin{macrocode} |
| 33907 |
\def\XINTinFloatS {\romannumeral0\XINTinfloatS}% |
| 33908 |
\def\XINTinfloatS |
| 33909 |
{\expandafter\XINT_infloatS_clean\romannumeral0\XINT_infloat}% |
| 33910 |
\def\XINT_infloatS_clean #1% |
| 33911 |
{\if #1!\xint_dothis\XINT_infloatS_clean_a\fi\xint_orthat{ }#1}% |
| 33912 |
\def\XINT_infloatS_clean_a !#1.{ }% |
| 33913 |
% \end{macrocode} |
| 33914 |
%\begin{lverb} |
| 33915 |
% début de la routine proprement dite, |
| 33916 |
% l'argument optionnel est obligatoire. |
| 33917 |
%\end{lverb} |
| 33918 |
% \begin{macrocode} |
| 33919 |
\def\XINT_infloat [#1]%#2% |
| 33920 |
{% |
| 33921 |
\expandafter\XINT_infloat_a\the\numexpr #1\expandafter.% |
| 33922 |
\romannumeral0\XINT_infrac% {#2}% |
| 33923 |
}% |
| 33924 |
% \end{macrocode} |
| 33925 |
%\begin{lverb} |
| 33926 |
% #1=P, #2=n, #3=A, #4=B. |
| 33927 |
%\end{lverb} |
| 33928 |
% \begin{macrocode} |
| 33929 |
\def\XINT_infloat_a #1.#2#3#4% |
| 33930 |
{% |
| 33931 |
% \end{macrocode} |
| 33932 |
%\begin{lverb} |
| 33933 |
% micro boost au lieu d'utiliser \XINT_isOne{#4}, mais pas bon style. |
| 33934 |
%\end{lverb} |
| 33935 |
% \begin{macrocode} |
| 33936 |
\if1\XINT_is_One#4XY% |
| 33937 |
\expandafter\XINT_infloat_sp |
| 33938 |
\else\expandafter\XINT_infloat_fork |
| 33939 |
\fi #3.{#1}{#2}{#4}% |
| 33940 |
}% |
| 33941 |
% \end{macrocode} |
| 33942 |
%\begin{lverb} |
| 33943 |
% Special quick treatment of B=1 case (1.2f then again 1.2g.)$newline |
| 33944 |
% maintenant: A.{P}{N}{1} |
| 33945 |
% Il est possible que A soit nul. |
| 33946 |
%\end{lverb} |
| 33947 |
% \begin{macrocode} |
| 33948 |
\def\XINT_infloat_sp #1% |
| 33949 |
{% |
| 33950 |
\xint_UDzerominusfork |
| 33951 |
#1-\XINT_infloat_spzero |
| 33952 |
0#1\XINT_infloat_spneg |
| 33953 |
0-\XINT_infloat_sppos |
| 33954 |
\krof #1% |
| 33955 |
}% |
| 33956 |
% \end{macrocode} |
| 33957 |
%\begin{lverb} |
| 33958 |
% Attention surtout pas 0/1[0] ici. |
| 33959 |
%\end{lverb} |
| 33960 |
% \begin{macrocode} |
| 33961 |
\def\XINT_infloat_spzero 0.#1#2#3{ 0[0]}% |
| 33962 |
\def\XINT_infloat_spneg-% |
| 33963 |
{\expandafter\XINT_infloat_spnegend\romannumeral0\XINT_infloat_sppos}% |
| 33964 |
\def\XINT_infloat_spnegend #1% |
| 33965 |
{\if#1!\expandafter\XINT_infloat_spneg_needzeros\fi -#1}% |
| 33966 |
\def\XINT_infloat_spneg_needzeros -!#1.{!#1.-}% |
| 33967 |
% \end{macrocode} |
| 33968 |
%\begin{lverb} |
| 33969 |
% in: A.{P}{N}{1}$newline |
| 33970 |
% out: P-L.A.P.N. |
| 33971 |
%\end{lverb} |
| 33972 |
% \begin{macrocode} |
| 33973 |
\def\XINT_infloat_sppos #1.#2#3#4% |
| 33974 |
{% |
| 33975 |
\expandafter\XINT_infloat_sp_b\the\numexpr#2-\xintLength{#1}.#1.#2.#3.% |
| 33976 |
}% |
| 33977 |
% \end{macrocode} |
| 33978 |
%\begin{lverb} |
| 33979 |
% #1= P-L. Si c'est positif ou nul il faut retrancher #1 à l'exposant, et |
| 33980 |
% ajouter autant de zéros. On regarde premier token. |
| 33981 |
% P-L.A.P.N. |
| 33982 |
%\end{lverb} |
| 33983 |
% \begin{macrocode} |
| 33984 |
\def\XINT_infloat_sp_b #1% |
| 33985 |
{% |
| 33986 |
\xint_UDzerominusfork |
| 33987 |
#1-\XINT_infloat_sp_quick |
| 33988 |
0#1\XINT_infloat_sp_c |
| 33989 |
0-\XINT_infloat_sp_needzeros |
| 33990 |
\krof #1% |
| 33991 |
}% |
| 33992 |
% \end{macrocode} |
| 33993 |
%\begin{lverb} |
| 33994 |
% Ici P=L. Le cas usuel dans \xintfloatexpr. |
| 33995 |
%\end{lverb} |
| 33996 |
% \begin{macrocode} |
| 33997 |
\def\XINT_infloat_sp_quick 0.#1.#2.#3.{ #1[#3]}% |
| 33998 |
% \end{macrocode} |
| 33999 |
%\begin{lverb} |
| 34000 |
% Ici #1=P-L est >0. L'exposant sera N-(P-L). #2=A. #3=P. #4=N.$newline |
| 34001 |
% 18 mars 2016. En fait dans certains contextes il est sous-optimal d'ajouter les |
| 34002 |
% zéros. Par exemple quand c'est appelé par la multiplication ou la division, |
| 34003 |
% c'est idiot de convertir 2 en 200000...00000[-499]. |
| 34004 |
% Donc je redéfinis addzeros en needzeroes. Si on appelle sous la forme |
| 34005 |
% \XINTinFloatS, on ne fait pas l'addition de zeros. |
| 34006 |
%\end{lverb} |
| 34007 |
% \begin{macrocode} |
| 34008 |
\def\XINT_infloat_sp_needzeros #1.#2.#3.#4.{!#1.#2[#4]}% |
| 34009 |
% \end{macrocode} |
| 34010 |
%\begin{lverb} |
| 34011 |
% L-P=#1.A=#2#3.P=#4.N=#5.$newline |
| 34012 |
% Ici P<L. Il va falloir arrondir. Attention si on va à la puissance de 10 |
| 34013 |
% suivante. En #1 on a L-P qui est >0. L'exposant final sera N+L-P, |
| 34014 |
% sauf dans le cas spécial, il sera alors N+L-P+1. L'ajustement final |
| 34015 |
% est fait par \XINT_infloat_Y. |
| 34016 |
%\end{lverb} |
| 34017 |
% \begin{macrocode} |
| 34018 |
\def\XINT_infloat_sp_c -#1.#2#3.#4.#5.% |
| 34019 |
{% |
| 34020 |
\expandafter\XINT_infloat_Y |
| 34021 |
\the\numexpr #5+#1\expandafter.% |
| 34022 |
\romannumeral0\expandafter\XINT_infloat_sp_round |
| 34023 |
\romannumeral0\XINT_split_fromleft |
| 34024 |
(\xint_c_i+#4).#2#3\xint_bye2345678\xint_bye..#2% |
| 34025 |
}% |
| 34026 |
\def\XINT_infloat_sp_round #1.#2.% |
| 34027 |
{% |
| 34028 |
\XINT_dsrr#1\xint_bye\xint_Bye3456789\xint_bye/\xint_c_x\relax.% |
| 34029 |
}% |
| 34030 |
% \end{macrocode} |
| 34031 |
%\begin{lverb} |
| 34032 |
% General branch for A/B with B>1 inputs. It achieves correct rounding |
| 34033 |
% always since 1.2k (done January 2, 2017.) This branch is never taken for A=0 |
| 34034 |
% because \XINT_infrac will have returned B=1 then. |
| 34035 |
%\end{lverb} |
| 34036 |
% \begin{macrocode} |
| 34037 |
\def\XINT_infloat_fork #1% |
| 34038 |
{% |
| 34039 |
\xint_UDsignfork |
| 34040 |
#1\XINT_infloat_J |
| 34041 |
-\XINT_infloat_K |
| 34042 |
\krof #1% |
| 34043 |
}% |
| 34044 |
\def\XINT_infloat_J-{\expandafter-\romannumeral0\XINT_infloat_K }% |
| 34045 |
% \end{macrocode} |
| 34046 |
%\begin{lverb} |
| 34047 |
% A.{P}{n}{B} avec B>1. |
| 34048 |
%\end{lverb} |
| 34049 |
% \begin{macrocode} |
| 34050 |
\def\XINT_infloat_K #1.#2% |
| 34051 |
{% |
| 34052 |
\expandafter\XINT_infloat_L |
| 34053 |
\the\numexpr\xintLength{#1}\expandafter.\the\numexpr #2+\xint_c_iv.{#1}{#2}% |
| 34054 |
}% |
| 34055 |
% \end{macrocode} |
| 34056 |
%\begin{lverb} |
| 34057 |
% |A|.P+4.{A}{P}{n}{B}. We check if A already has length |
| 34058 |
% <= P+4. |
| 34059 |
%\end{lverb} |
| 34060 |
% \begin{macrocode} |
| 34061 |
\def\XINT_infloat_L #1.#2.% |
| 34062 |
{% |
| 34063 |
\ifnum #1>#2 |
| 34064 |
\expandafter\XINT_infloat_Ma |
| 34065 |
\else |
| 34066 |
\expandafter\XINT_infloat_Mb |
| 34067 |
\fi #1.#2.% |
| 34068 |
}% |
| 34069 |
% \end{macrocode} |
| 34070 |
%\begin{lverb} |
| 34071 |
% |A|.P+4.{A}{P}{n}{B}. We will keep only the first P+4 |
| 34072 |
% digits of A, denoted A'' in what follows. |
| 34073 |
% |
| 34074 |
% output: u=-0.A''.junk.P+4.|A|.{A}{P}{n}{B} |
| 34075 |
%\end{lverb} |
| 34076 |
% \begin{macrocode} |
| 34077 |
\def\XINT_infloat_Ma #1.#2.#3% |
| 34078 |
{% |
| 34079 |
\expandafter\XINT_infloat_MtoN\expandafter-\expandafter0\expandafter.% |
| 34080 |
\romannumeral0\XINT_split_fromleft#2.#3\xint_bye2345678\xint_bye..% |
| 34081 |
#2.#1.{#3}% |
| 34082 |
}% |
| 34083 |
% \end{macrocode} |
| 34084 |
%\begin{lverb} |
| 34085 |
% |A|.P+4.{A}{P}{n}{B}.$newline |
| 34086 |
% Here A is short. We set u = P+4-|A|, and A''=A (A' = 10^u A) |
| 34087 |
% |
| 34088 |
% output: u.A''..P+4.|A|.{A}{P}{n}{B} |
| 34089 |
%\end{lverb} |
| 34090 |
% \begin{macrocode} |
| 34091 |
\def\XINT_infloat_Mb #1.#2.#3% |
| 34092 |
{% |
| 34093 |
\expandafter\XINT_infloat_MtoN\the\numexpr#2-#1.% |
| 34094 |
#3..#2.#1.{#3}% |
| 34095 |
}% |
| 34096 |
% \end{macrocode} |
| 34097 |
%\begin{lverb} |
| 34098 |
% input u.A''.junk.P+4.|A|.{A}{P}{n}{B}$newline |
| 34099 |
% output |B|.P+4.{B}u.A''.P.|A|.n.{A}{B} |
| 34100 |
%\end{lverb} |
| 34101 |
% \begin{macrocode} |
| 34102 |
\def\XINT_infloat_MtoN #1.#2.#3.#4.#5.#6#7#8#9% |
| 34103 |
{% |
| 34104 |
\expandafter\XINT_infloat_N |
| 34105 |
\the\numexpr\xintLength{#9}.#4.{#9}#1.#2.#7.#5.#8.{#6}{#9}% |
| 34106 |
}% |
| 34107 |
\def\XINT_infloat_N #1.#2.% |
| 34108 |
{% |
| 34109 |
\ifnum #1>#2 |
| 34110 |
\expandafter\XINT_infloat_Oa |
| 34111 |
\else |
| 34112 |
\expandafter\XINT_infloat_Ob |
| 34113 |
\fi #1.#2.% |
| 34114 |
}% |
| 34115 |
% \end{macrocode} |
| 34116 |
%\begin{lverb} |
| 34117 |
% input |B|.P+4.{B}u.A''.P.|A|.n.{A}{B}$newline |
| 34118 |
% output v=-0.B''.junk.|B|.u.A''.P.|A|.n.{A}{B} |
| 34119 |
%\end{lverb} |
| 34120 |
% \begin{macrocode} |
| 34121 |
\def\XINT_infloat_Oa #1.#2.#3% |
| 34122 |
{% |
| 34123 |
\expandafter\XINT_infloat_P\expandafter-\expandafter0\expandafter.% |
| 34124 |
\romannumeral0\XINT_split_fromleft#2.#3\xint_bye2345678\xint_bye..% |
| 34125 |
#1.% |
| 34126 |
}% |
| 34127 |
% \end{macrocode} |
| 34128 |
%\begin{lverb} |
| 34129 |
% output v=P+4-|B|>=0.B''.junk.|B|.u.A''.P.|A|.n.{A}{B} |
| 34130 |
%\end{lverb} |
| 34131 |
% \begin{macrocode} |
| 34132 |
\def\XINT_infloat_Ob #1.#2.#3% |
| 34133 |
{% |
| 34134 |
\expandafter\XINT_infloat_P\the\numexpr#2-#1.#3..#1.% |
| 34135 |
}% |
| 34136 |
% \end{macrocode} |
| 34137 |
%\begin{lverb} |
| 34138 |
% input v.B''.junk.|B|.u.A''.P.|A|.n.{A}{B}$newline |
| 34139 |
% output Q1.P.|B|.|A|.n.{A}{B}$newline |
| 34140 |
% Q1 = division euclidienne de A''.10^{u-v+P+3} par B''. |
| 34141 |
% |
| 34142 |
% Special detection of cases with A and B both having length at most P+4: this |
| 34143 |
% will happen when called from \xintFloatDiv as A and B (produced then via |
| 34144 |
% \XINTinFloatS) will have at most P digits. We then only need integer division |
| 34145 |
% with P+1 extra zeros, not P+3. |
| 34146 |
%\end{lverb} |
| 34147 |
% \begin{macrocode} |
| 34148 |
\def\XINT_infloat_P #1#2.#3.#4.#5.#6#7.#8.#9.% |
| 34149 |
{% |
| 34150 |
\csname XINT_infloat_Q\if-#1\else\if-#6\else q\fi\fi\expandafter\endcsname |
| 34151 |
\romannumeral0\xintiiquo |
| 34152 |
{\romannumeral0\XINT_dsx_addzerosnofuss |
| 34153 |
{#6#7-#1#2+#9+\xint_c_iii\if-#1\else\if-#6\else-\xint_c_ii\fi\fi}#8;}% |
| 34154 |
{#3}.#9.#5.% |
| 34155 |
}% |
| 34156 |
% \end{macrocode} |
| 34157 |
%\begin{lverb} |
| 34158 |
% «quick» branch. |
| 34159 |
%\end{lverb} |
| 34160 |
% \begin{macrocode} |
| 34161 |
\def\XINT_infloat_Qq #1.#2.% |
| 34162 |
{% |
| 34163 |
\expandafter\XINT_infloat_Rq |
| 34164 |
\romannumeral0\XINT_split_fromleft#2.#1\xint_bye2345678\xint_bye..#2.% |
| 34165 |
}% |
| 34166 |
\def\XINT_infloat_Rq #1.#2#3.% |
| 34167 |
{% |
| 34168 |
\ifnum#2<\xint_c_v |
| 34169 |
\expandafter\XINT_infloat_SEq |
| 34170 |
\else\expandafter\XINT_infloat_SUp |
| 34171 |
\fi |
| 34172 |
{\if.#3.\xint_c_\else\xint_c_i\fi}#1.% |
| 34173 |
}% |
| 34174 |
% \end{macrocode} |
| 34175 |
%\begin{lverb} |
| 34176 |
% standard branch which will have to handle undecided rounding, if too |
| 34177 |
% close to a mid-value. |
| 34178 |
%\end{lverb} |
| 34179 |
% \begin{macrocode} |
| 34180 |
\def\XINT_infloat_Q #1.#2.% |
| 34181 |
{% |
| 34182 |
\expandafter\XINT_infloat_R |
| 34183 |
\romannumeral0\XINT_split_fromleft#2.#1\xint_bye2345678\xint_bye..#2.% |
| 34184 |
}% |
| 34185 |
\def\XINT_infloat_R #1.#2#3#4#5.% |
| 34186 |
{% |
| 34187 |
\if.#5.\expandafter\XINT_infloat_Sa\else\expandafter\XINT_infloat_Sb\fi |
| 34188 |
#2#3#4#5.#1.% |
| 34189 |
}% |
| 34190 |
% \end{macrocode} |
| 34191 |
%\begin{lverb} |
| 34192 |
% trailing digits.Q.P.|B|.|A|.n.{A}{B}$newline |
| 34193 |
% #1=trailing digits (they may have leading zeros.) |
| 34194 |
%\end{lverb} |
| 34195 |
% \begin{macrocode} |
| 34196 |
\def\XINT_infloat_Sa #1.% |
| 34197 |
{% |
| 34198 |
\ifnum#1>500 \xint_dothis\XINT_infloat_SUp\fi |
| 34199 |
\ifnum#1<499 \xint_dothis\XINT_infloat_SEq\fi |
| 34200 |
\xint_orthat\XINT_infloat_X\xint_c_ |
| 34201 |
}% |
| 34202 |
\def\XINT_infloat_Sb #1.% |
| 34203 |
{% |
| 34204 |
\ifnum#1>5009 \xint_dothis\XINT_infloat_SUp\fi |
| 34205 |
\ifnum#1<4990 \xint_dothis\XINT_infloat_SEq\fi |
| 34206 |
\xint_orthat\XINT_infloat_X\xint_c_i |
| 34207 |
}% |
| 34208 |
% \end{macrocode} |
| 34209 |
%\begin{lverb} |
| 34210 |
% epsilon #2=Q.#3=P.#4=|B|.#5=|A|.#6=n.{A}{B}$newline |
| 34211 |
% exposant final est n+|A|-|B|-P+epsilon |
| 34212 |
%\end{lverb} |
| 34213 |
% \begin{macrocode} |
| 34214 |
\def\XINT_infloat_SEq #1#2.#3.#4.#5.#6.#7#8% |
| 34215 |
{% |
| 34216 |
\expandafter\XINT_infloat_SY |
| 34217 |
\the\numexpr #6+#5-#4-#3+#1.#2.% |
| 34218 |
}% |
| 34219 |
\def\XINT_infloat_SY #1.#2.{ #2[#1]}% |
| 34220 |
% \end{macrocode} |
| 34221 |
%\begin{lverb} |
| 34222 |
% initial digit #2 put aside to check for case of rounding up to |
| 34223 |
% next power of ten, which will need adjustment of mantissa and |
| 34224 |
% exponent. |
| 34225 |
%\end{lverb} |
| 34226 |
% \begin{macrocode} |
| 34227 |
\def\XINT_infloat_SUp #1#2#3.#4.#5.#6.#7.#8#9% |
| 34228 |
{% |
| 34229 |
\expandafter\XINT_infloat_Y |
| 34230 |
\the\numexpr#7+#6-#5-#4+#1\expandafter.% |
| 34231 |
\romannumeral0\xintinc{#2#3}.#2% |
| 34232 |
}% |
| 34233 |
% \end{macrocode} |
| 34234 |
%\begin{lverb} |
| 34235 |
% epsilon Q.P.|B|.|A|.n.{A}{B}$newline |
| 34236 |
% |
| 34237 |
% \xintDSH{-x}{U} multiplies U by 10^x. When x is negative, this means |
| 34238 |
% it truncates (i.e. it drops the last -x digits). |
| 34239 |
% |
| 34240 |
% We don't try to optimize too much macro calls here, the odds are 2 per 1000 |
| 34241 |
% for this branch to be taken. Perhaps in future I will use higher free |
| 34242 |
% parameter d, which currently is set at 4. |
| 34243 |
% |
| 34244 |
% #1=epsilon, #2#3=Q, #4=P, #5=|B|, #6=|A|, #7=n, #8=A, #9=B |
| 34245 |
%\end{lverb} |
| 34246 |
% \begin{macrocode} |
| 34247 |
\def\XINT_infloat_X #1#2#3.#4.#5.#6.#7.#8#9% |
| 34248 |
{% |
| 34249 |
\expandafter\XINT_infloat_Y |
| 34250 |
\the\numexpr #7+#6-#5-#4+#1\expandafter.% |
| 34251 |
\romannumeral`&&@\romannumeral0\xintiiiflt |
| 34252 |
{\xintDSH{#6-#5-#4+#1}{\xintDouble{#8}}}% |
| 34253 |
{\xintiiMul{\xintInc{\xintDouble{#2#3}}}{#9}}% |
| 34254 |
\xint_firstofone |
| 34255 |
\xintinc{#2#3}.#2% |
| 34256 |
}% |
| 34257 |
% \end{macrocode} |
| 34258 |
%\begin{lverb} |
| 34259 |
% check for rounding up to next power of ten. |
| 34260 |
%\end{lverb} |
| 34261 |
% \begin{macrocode} |
| 34262 |
\def\XINT_infloat_Y #1{% |
| 34263 |
\def\XINT_infloat_Y ##1.##2##3.##4% |
| 34264 |
{% |
| 34265 |
\if##49\if##21\expandafter\expandafter\expandafter\XINT_infloat_Z\fi\fi |
| 34266 |
#1##2##3[##1]% |
| 34267 |
}}\XINT_infloat_Y{ }% |
| 34268 |
% \end{macrocode} |
| 34269 |
%\begin{lverb} |
| 34270 |
% #1=1, #2=0. |
| 34271 |
%\end{lverb} |
| 34272 |
% \begin{macrocode} |
| 34273 |
\def\XINT_infloat_Z #1#2#3[#4]% |
| 34274 |
{% |
| 34275 |
\expandafter\XINT_infloat_ZZ\the\numexpr#4+\xint_c_i.#3.% |
| 34276 |
}% |
| 34277 |
\def\XINT_infloat_ZZ #1.#2.{ 1#2[#1]}% |
| 34278 |
% \end{macrocode} |
| 34279 |
% \subsection{\csh{XINTFloatiLogTen}} |
| 34280 |
% \added{1.3e} |
| 34281 |
%\begin{lverb} |
| 34282 |
% Le comportement pour un input nul est non |
| 34283 |
% encore finalisé. Il changera lorsque NaN, +Inf, -Inf existeront. |
| 34284 |
% |
| 34285 |
% The optional argument [#1] is in fact mandatory and #1 is |
| 34286 |
% not pre-expanded in a \numexpr. |
| 34287 |
% |
| 34288 |
% The return value here 2^31-2^15 is highly undecided. |
| 34289 |
%\end{lverb} |
| 34290 |
% \begin{macrocode} |
| 34291 |
\def\XINTFloatiLogTen {\the\numexpr\XINTfloatilogten}% |
| 34292 |
\def\XINTfloatilogten [#1]#2% |
| 34293 |
{\expandafter\XINT_floatilogten\romannumeral0\XINT_infloat[#1]{#2}#1.}% |
| 34294 |
\def\XINTFloatiLogTendigits{\the\numexpr\XINTfloatilogten[\XINTdigits]}% |
| 34295 |
\def\XINT_floatilogten #1{% |
| 34296 |
\if #10\xint_dothis\XINT_floatilogten_z\fi |
| 34297 |
\if #1!\xint_dothis\XINT_floatilogten_a\fi |
| 34298 |
\xint_orthat\XINT_floatilogten_b #1% |
| 34299 |
}% |
| 34300 |
\def\XINT_floatilogten_z 0[0]#1.{-"7FFF8000\relax}% |
| 34301 |
\def\XINT_floatilogten_a !#1.#2[#3]#4.{#3-#1+#4-\xint_c_i\relax}% |
| 34302 |
\def\XINT_floatilogten_b #1[#2]#3.{#2+#3-\xint_c_i\relax}% |
| 34303 |
% \end{macrocode} |
| 34304 |
% \subsection{\csh{xintPFloat}} |
| 34305 |
% \added{1.1} |
| 34306 |
% \changed{1.4e} |
| 34307 |
%\begin{lverb} |
| 34308 |
% |
| 34309 |
% xint has not yet incorporated a general formatter as it was |
| 34310 |
% not a priority during development and external solutions exist |
| 34311 |
% (I did not check for a while but I think LaTeX3 has implemented |
| 34312 |
% a general formatter in the printf or Python ".format" spirit) |
| 34313 |
% |
| 34314 |
% But when one starts using really the package, especially in |
| 34315 |
% an interactive way (xintsession 2021), one needs the default |
| 34316 |
% output to be as nice as possible. |
| 34317 |
% |
| 34318 |
% The \xintPFloat macro was added at 1.1 as a "prettifying printer" |
| 34319 |
% for floats, basically influenced by Maple. |
| 34320 |
% |
| 34321 |
%( The rules were: |
| 34322 |
%: 0. The input is float-rounded to either Digits or the optional argument |
| 34323 |
%: 1. zero is printed as "0." |
| 34324 |
%: 2. x.yz...eK is printed "as is" if K>5 or K<-5. |
| 34325 |
%: 3. if -5<=K<=5, fixed point decimal notation is used. |
| 34326 |
%: 4. in cases 2. and 3., no trimming of trailing zeroes. |
| 34327 |
%) |
| 34328 |
% |
| 34329 |
% 1.4b added \xintPFloatE to customize whether to use |
| 34330 |
% e or E. |
| 34331 |
% |
| 34332 |
% |
| 34333 |
% 1.4e, with some hesitation, decided to make a breaking change and to modify |
| 34334 |
% the behaviour. |
| 34335 |
% |
| 34336 |
%( The new rules: |
| 34337 |
%: 0. The input is float-rounded to either Digits or the optional argument |
| 34338 |
%: 1. zero is printed as 0.0 |
| 34339 |
%: 2. x.yz...eK is printed in decimal fixed point if -4<=K<=+5& |
| 34340 |
% (notice the change, formerly K=-5 used fixed point notation in output)& |
| 34341 |
% else it is printed in scientific notation |
| 34342 |
%: 3. trailing zeros of the mantissa are trimmed always |
| 34343 |
%: 4. in case of decimal fixed point for an integer, there& |
| 34344 |
% is a trailing ".0" |
| 34345 |
%: 5. in case of scientific notation with a one-digit trimmed mantissa& |
| 34346 |
% there is an added ".0" too |
| 34347 |
%) |
| 34348 |
% |
| 34349 |
% Further, \xintPFloatE can now also be redefined as a macro with a parameter |
| 34350 |
% delimited by a full stop, with the full stop also in its ouput as |
| 34351 |
% terminator. It would then grab the scientific exponent K as explicit digit |
| 34352 |
% possibly prefixed by a minus sign. The macro must be f-expandable. |
| 34353 |
% |
| 34354 |
% The macro \xintPFloat_wopt is only there for a micro gain as the package |
| 34355 |
% does |
| 34356 |
% |
| 34357 |
% \let\xintfloatexprPrintOne\xintPFloat_wopt |
| 34358 |
% |
| 34359 |
% as it knows it will |
| 34360 |
% be used always with a [P] argument in the xintexpr.sty context. |
| 34361 |
%\end{lverb} |
| 34362 |
% \changed{1.4k} |
| 34363 |
%\begin{lverb} |
| 34364 |
% Addition of customization via \xintPFloatZero, \xintPFloatLengthOneSuffix, |
| 34365 |
% \xintPFloatNoSciEmax, \xintPFloatNoSciEmin which replace formerly |
| 34366 |
% hard-coded behaviour. |
| 34367 |
% |
| 34368 |
% Breaking change to not add ".0" suffix to integers (when scientific |
| 34369 |
% notation dropped) or to one-digit mantissas. |
| 34370 |
% |
| 34371 |
% In my own practice I started being annoyed by the automatic trimming of |
| 34372 |
% zeros added at 1.4e. |
| 34373 |
% |
| 34374 |
% This change had been influenced by using Python in interactive mode |
| 34375 |
% which since 3.1 prints floats (in decimal conversion) choosing the |
| 34376 |
% shortest string. In particular it trims trailing zeros, and it drops |
| 34377 |
% the scientific notation in favor of decimal notation for something |
| 34378 |
% like -4<= K <= 15, with K the scientific exponent. |
| 34379 |
% |
| 34380 |
% At 1.4e I was still influenced by my experience with Maple and |
| 34381 |
% did for -4 <= K <= 5. Not very well thought anyhow (one may wish |
| 34382 |
% to use decimal notation when sending things to PostScript, so perhaps |
| 34383 |
% I should have kept with -5). |
| 34384 |
% |
| 34385 |
% But, the main problem is with trimming trailing zeros: although in |
| 34386 |
% interactive sessions, this has its logic, as soon as one does tables |
| 34387 |
% with numbers, dropping a trailing zero upsets alignments or creates |
| 34388 |
% visual holes compared to other lines and this is in the end very |
| 34389 |
% annoying. |
| 34390 |
% |
| 34391 |
% After much hesitation, I decided to slightly modifify only the former |
| 34392 |
% behaviour: trimming only if that removes at least 4 zeros. I had also |
| 34393 |
% experimented with another condition: trimmed mantissas should be at |
| 34394 |
% most 6 digits (for example) wide, else use no trimming. |
| 34395 |
% |
| 34396 |
% Threshold customizable via \xintPFloatMinTrimmed. |
| 34397 |
%\end{lverb} |
| 34398 |
% \changed[2022/05/22]{1.4l} |
| 34399 |
%\begin{lverb} |
| 34400 |
% The 1.4k check for canceling the trimming of trailing zeros |
| 34401 |
% took over priority over the later check for being an integer when |
| 34402 |
% decimal fixed point notation was used (or being only with a one-digit |
| 34403 |
% trimmed mantissa). In particular if user set \xintPFloatMinTrimmed to |
| 34404 |
% the value of Digits (or P) to avoid trimming it also prevented |
| 34405 |
% recognition of some integers (but not all). Fixed at 1.4l |
| 34406 |
%\end{lverb} |
| 34407 |
% \begin{macrocode} |
| 34408 |
\def\xintPFloatE{e}% |
| 34409 |
\def\xintPFloatNoSciEmax{\xint_c_v}% 1e6 uses sci.not. |
| 34410 |
\def\xintPFloatNoSciEmin{-\xint_c_iv}% 1e-5 uses sci.not. |
| 34411 |
\def\xintPFloatIntSuffix{}% |
| 34412 |
\def\xintPFloatLengthOneSuffix{}% |
| 34413 |
\def\xintPFloatZero{0}% |
| 34414 |
\def\xintPFloatMinTrimmed{\xint_c_iv}% |
| 34415 |
\def\xintPFloat {\romannumeral0\xintpfloat }% |
| 34416 |
\def\xintpfloat #1{\XINT_pfloat_chkopt #1\xint:}% |
| 34417 |
\def\xintPFloat_wopt[#1]#2% |
| 34418 |
{% |
| 34419 |
\romannumeral0\expandafter\XINT_pfloat |
| 34420 |
\romannumeral0\XINTinfloatS[#1]{#2}#1.% |
| 34421 |
}% |
| 34422 |
\def\XINT_pfloat_chkopt #1% |
| 34423 |
{% |
| 34424 |
\ifx [#1\expandafter\XINT_pfloat_opt |
| 34425 |
\else\expandafter\XINT_pfloat_noopt |
| 34426 |
\fi #1% |
| 34427 |
}% |
| 34428 |
\def\XINT_pfloat_noopt #1\xint:% |
| 34429 |
{% |
| 34430 |
\expandafter\XINT_pfloat\romannumeral0\XINTinfloatS[\XINTdigits]{#1}% |
| 34431 |
\XINTdigits.% |
| 34432 |
}% |
| 34433 |
\def\XINT_pfloat_opt [\xint:{\expandafter\XINT_pfloat_opt_a\the\numexpr}% |
| 34434 |
\def\XINT_pfloat_opt_a #1]#2% |
| 34435 |
{% |
| 34436 |
\expandafter\XINT_pfloat\romannumeral0\XINTinfloatS[#1]{#2}% |
| 34437 |
#1.% |
| 34438 |
}% |
| 34439 |
\def\XINT_pfloat#1]% |
| 34440 |
{% |
| 34441 |
\expandafter\XINT_pfloat_fork\romannumeral0\xintrez{#1]}% |
| 34442 |
}% |
| 34443 |
\def\XINT_pfloat_fork#1% |
| 34444 |
{% |
| 34445 |
\xint_UDzerominusfork |
| 34446 |
#1-\XINT_pfloat_zero |
| 34447 |
0#1\XINT_pfloat_neg |
| 34448 |
0-\XINT_pfloat_pos |
| 34449 |
\krof #1% |
| 34450 |
}% |
| 34451 |
\def\XINT_pfloat_zero#1]#2.{\expanded{ \xintPFloatZero}}% |
| 34452 |
\def\XINT_pfloat_neg-{\expandafter-\romannumeral0\XINT_pfloat_pos}% |
| 34453 |
\def\XINT_pfloat_pos#1/1[#2]#3.% |
| 34454 |
{% |
| 34455 |
\expandafter\XINT_pfloat_aa\the\numexpr\xintLength{#1}.% |
| 34456 |
#3.#2.#1.% |
| 34457 |
}% |
| 34458 |
% \end{macrocode} |
| 34459 |
%\begin{lverb} |
| 34460 |
%( #1 est la longueur de la mantisse trimmée |
| 34461 |
%: #2 est Digits ou P |
| 34462 |
%: Si #2-#1 < MinTrimmed, on se prépare à peut-être remettre les trailing zeros |
| 34463 |
%) |
| 34464 |
% |
| 34465 |
% On teste pour #2=#1, car c'est le cas le plus fréquent (mais est-ce |
| 34466 |
% une bonne idée) car on sait qu'alors il n'y a pas de trailing zéros |
| 34467 |
% donc on va direct vers \XINT_pfloat_a. |
| 34468 |
%\end{lverb} |
| 34469 |
% \begin{macrocode} |
| 34470 |
\def\XINT_pfloat_aa #1.#2.% |
| 34471 |
{% |
| 34472 |
\unless\ifnum\xintPFloatMinTrimmed>\numexpr#2-#1\relax |
| 34473 |
\xint_dothis\XINT_pfloat_a\fi |
| 34474 |
\ifnum#2>#1 \xint_dothis{\XINT_pfloat_i #2.}\fi |
| 34475 |
\xint_orthat\XINT_pfloat_a #1.% |
| 34476 |
}% |
| 34477 |
% \end{macrocode} |
| 34478 |
%\begin{lverb} |
| 34479 |
% Needed for \xintFracToSci, which uses old pre 1.4k interface, |
| 34480 |
% where the P parameter was not stored for counting how many zeros |
| 34481 |
% were trimmed. \xintFracToSci trims always. |
| 34482 |
%\end{lverb} |
| 34483 |
% \begin{macrocode} |
| 34484 |
\def\XINT_pfloat_a_fork#1% |
| 34485 |
{% |
| 34486 |
\xint_UDzerominusfork |
| 34487 |
#1-\XINT_pfloat_a_zero |
| 34488 |
0#1\XINT_pfloat_a_neg |
| 34489 |
0-\XINT_pfloat_a_pos |
| 34490 |
\krof #1% |
| 34491 |
}% |
| 34492 |
\def\XINT_pfloat_a_zero#1]{\expanded{ \xintPFloatZero}}% |
| 34493 |
\def\XINT_pfloat_a_neg-{\expandafter-\romannumeral0\XINT_pfloat_a_pos}% |
| 34494 |
\def\XINT_pfloat_a_pos#1/1[#2]% |
| 34495 |
{% |
| 34496 |
\expandafter\XINT_pfloat_a\the\numexpr\xintLength{#1}.#2.#1.% |
| 34497 |
}% |
| 34498 |
% \end{macrocode} |
| 34499 |
%\begin{lverb} |
| 34500 |
%( #1 est P > #2 mais peut être encore sous la forme \XINTdigits |
| 34501 |
%: #2 est la longueur de la mantisse trimmée |
| 34502 |
%: #3 est l'exposant non normalisé |
| 34503 |
%: #4 est la mantisse |
| 34504 |
%) |
| 34505 |
% On reconstitue les trailing zéros à remettre éventuellement. |
| 34506 |
%\end{lverb} |
| 34507 |
% \begin{macrocode} |
| 34508 |
\def\XINT_pfloat_i #1.#2.%#3.#4.% |
| 34509 |
{% |
| 34510 |
\expandafter\XINT_pfloat_j\romannumeral\xintreplicate{#1-#2}0.#2.% |
| 34511 |
}% |
| 34512 |
% \end{macrocode} |
| 34513 |
%\begin{lverb} |
| 34514 |
%( #1 est les trailing zeros à remettre peut-être |
| 34515 |
%: #2 est la longueur de la mantisse trimmée |
| 34516 |
%: #3#4 est l'exposant N pour mantisse trimmée entière |
| 34517 |
%: #5 serait la mantisse trimmée |
| 34518 |
%) |
| 34519 |
% On calcule l'exposant scientifique. |
| 34520 |
% |
| 34521 |
% La façon bizarre de mettre #3 est liée aux versions anciennes |
| 34522 |
% de la macro, héritage conservé pour minimiser effort d'adaptation. |
| 34523 |
%\end{lverb} |
| 34524 |
% \begin{macrocode} |
| 34525 |
\def\XINT_pfloat_j #1.#2.#3#4.%#5. |
| 34526 |
{% |
| 34527 |
\expandafter\XINT_pfloat_b\the\numexpr#2+#3#4-\xint_c_i.% |
| 34528 |
#3#2.#1.% |
| 34529 |
}% |
| 34530 |
% \end{macrocode} |
| 34531 |
%\begin{lverb} |
| 34532 |
%( #1 est la longueur de la mantisse trimmée |
| 34533 |
%: #2#3 est l'exposant N pour mantisse trimmée |
| 34534 |
%: #4 serait la mantisse |
| 34535 |
%) |
| 34536 |
% On calcule l'exposant scientifique. On est arrivé ici dans |
| 34537 |
% une branche où on n'a pas besoin de remettre les zéros trimmés |
| 34538 |
% donc on positionne un dernier argument vide pour \XINT_pfloat_b |
| 34539 |
%\end{lverb} |
| 34540 |
% \begin{macrocode} |
| 34541 |
\def\XINT_pfloat_a #1.#2#3.%#4. |
| 34542 |
{% |
| 34543 |
\expandafter\XINT_pfloat_b\the\numexpr#1+#2#3-\xint_c_i.% |
| 34544 |
#2#1..% |
| 34545 |
}% |
| 34546 |
% \end{macrocode} |
| 34547 |
%\begin{lverb} |
| 34548 |
%( #1 est l'exposant scientifique K |
| 34549 |
%: #2 est le signe ou premier chiffre de l'exposant N pour mantisse trimmée |
| 34550 |
%: #3 serait la longueur de la mantisse trimmée |
| 34551 |
%: #4 serait les trailing zéros |
| 34552 |
%: #5 serait la mantisse trimmée |
| 34553 |
%) |
| 34554 |
% On va vers \XINT_float_P lorsque l'on n'utilise pas la notation |
| 34555 |
% scientifique, mais qu'on a besoin de chiffres non nuls fractionnaires, |
| 34556 |
% et vers \XINT_float_Ps si on n'en a pas besoin. |
| 34557 |
% |
| 34558 |
% On va vers \XINT_pfloat_N lorsque l'on n'utilise pas la notation |
| 34559 |
% scientifique et que l'exposant scientifique était strictement négatif. |
| 34560 |
%\end{lverb} |
| 34561 |
% \begin{macrocode} |
| 34562 |
\def\XINT_pfloat_b #1.#2%#3.#4.#5. |
| 34563 |
{% |
| 34564 |
\ifnum \xintPFloatNoSciEmax<#1 \xint_dothis\XINT_pfloat_sci\fi |
| 34565 |
\ifnum \xintPFloatNoSciEmin>#1 \xint_dothis\XINT_pfloat_sci\fi |
| 34566 |
\ifnum #1<\xint_c_ \xint_dothis\XINT_pfloat_N\fi |
| 34567 |
\if-#2\xint_dothis\XINT_pfloat_P\fi |
| 34568 |
\xint_orthat\XINT_pfloat_Ps |
| 34569 |
#1.% |
| 34570 |
}% |
| 34571 |
% \end{macrocode} |
| 34572 |
%\begin{lverb} |
| 34573 |
% #1 is the scientific exponent, #2 is the length of the trimmed mantissa, |
| 34574 |
% #3 are the trailing zeros, #4 is the trimmed integer mantissa |
| 34575 |
% |
| 34576 |
% \xintPFloatE can be replaced by any f-expandable macro with a dot-delimited |
| 34577 |
% argument which produces a dot-delimited output. |
| 34578 |
%\end{lverb} |
| 34579 |
% \begin{macrocode} |
| 34580 |
\def\XINT_pfloat_sci #1.#2.% |
| 34581 |
{% |
| 34582 |
\ifnum#2=\xint_c_i\expandafter\XINT_pfloat_sci_i\expandafter\fi |
| 34583 |
\expandafter\XINT_pfloat_sci_a\romannumeral`&&@\xintPFloatE #1.% |
| 34584 |
}% |
| 34585 |
\def\XINT_pfloat_sci_a #1.#2.#3#4.{ #3.#4#2#1}% |
| 34586 |
% \end{macrocode} |
| 34587 |
%\begin{lverb} |
| 34588 |
% #1#2=\fi\XINT_pfloat_sci_a |
| 34589 |
% |
| 34590 |
% 1-digit mantissa, hesitation between d.0eK or deK |
| 34591 |
% Finally at 1.4k, \xintPFloatLengthOneSuffix for customization. |
| 34592 |
%\end{lverb} |
| 34593 |
% \begin{macrocode} |
| 34594 |
\def\XINT_pfloat_sci_i #1#2#3.#4.#5.{\expanded{#1 #5\xintPFloatLengthOneSuffix}#3}% |
| 34595 |
% \end{macrocode} |
| 34596 |
%\begin{lverb} |
| 34597 |
% #1=sci.exp. K, #2=mant. wd L, #3=trailing zéros, #4=trimmed mantissa |
| 34598 |
% |
| 34599 |
% For _N, #1 is at most -1, for _P, #1 is at least 0. For _P there |
| 34600 |
% will be fractional digits, and #1+1 digits before the mark. |
| 34601 |
%\end{lverb} |
| 34602 |
% \begin{macrocode} |
| 34603 |
\def\XINT_pfloat_N#1.#2.#3.#4.% |
| 34604 |
{% |
| 34605 |
\expandafter\XINT_pfloat_N_e\romannumeral\xintreplicate{-#1}{0}#4#3% |
| 34606 |
}% |
| 34607 |
\def\XINT_pfloat_N_e 0{ 0.}% |
| 34608 |
% \end{macrocode} |
| 34609 |
%\begin{lverb} |
| 34610 |
% #1=sci.exp. K, #2=mant. wd L, #3=trailing zéros, #4=trimmed mantissa |
| 34611 |
% |
| 34612 |
% Abusive usage of internal \XINT_split_fromleft_a. |
| 34613 |
% It means using x = -1 - #1 in \xintDecSplit from xint.sty. |
| 34614 |
% We benefit also with the way \xintDecSplit is built upon |
| 34615 |
% \XINT_split_fromleft with a final clean-up which here |
| 34616 |
% we can shortcut via using terminator "\xint_bye." not "\xint_bye.." |
| 34617 |
%\end{lverb} |
| 34618 |
% \begin{macrocode} |
| 34619 |
\def\XINT_pfloat_P #1.#2.#3.#4.% |
| 34620 |
{% |
| 34621 |
\expandafter\XINT_split_fromleft_a |
| 34622 |
\the\numexpr\xint_c_vii-#1.#4\xint_bye2345678\xint_bye.#3% |
| 34623 |
}% |
| 34624 |
% \end{macrocode} |
| 34625 |
%\begin{lverb} |
| 34626 |
% Here we have an integer so we only need to postfix the trimmed mantissa #4 |
| 34627 |
% with #1+1-#2 zeros (#1=sci exp., #2=trimmed mantissa width). Less cumbersome |
| 34628 |
% to do that with \expanded. And the trailing zeros #3 ignored here. |
| 34629 |
%\end{lverb} |
| 34630 |
% \begin{macrocode} |
| 34631 |
\def\XINT_pfloat_Ps #1.#2.#3.#4.% |
| 34632 |
{% |
| 34633 |
\expanded{ #4% |
| 34634 |
\romannumeral\xintreplicate{#1+\xint_c_i-#2}{0}\xintPFloatIntSuffix}% |
| 34635 |
}% |
| 34636 |
% \end{macrocode} |
| 34637 |
% \subsection{\csh{xintFloatToDecimal}} |
| 34638 |
% \added{1.4k} |
| 34639 |
% \begin{macrocode} |
| 34640 |
\def\xintFloatToDecimal {\romannumeral0\xintfloattodecimal }% |
| 34641 |
\def\xintfloattodecimal #1{\XINT_floattodec_chkopt #1\xint:}% |
| 34642 |
\def\XINT_floattodec_chkopt #1% |
| 34643 |
{% |
| 34644 |
\ifx [#1\expandafter\XINT_floattodec_opt |
| 34645 |
\else\expandafter\XINT_floattodec_noopt |
| 34646 |
\fi #1% |
| 34647 |
}% |
| 34648 |
\def\XINT_floattodec_noopt #1\xint:% |
| 34649 |
{% |
| 34650 |
\expandafter\XINT_floattodec\romannumeral0\XINTinfloatS[\XINTdigits]{#1}% |
| 34651 |
}% |
| 34652 |
\def\XINT_floattodec_opt [\xint:#1]% |
| 34653 |
{% |
| 34654 |
\expandafter\XINT_floattodec\romannumeral0\XINTinfloatS[#1]% |
| 34655 |
}% |
| 34656 |
% \end{macrocode} |
| 34657 |
%\begin{lverb} |
| 34658 |
% Temptation to try to use direct access to lower entry points |
| 34659 |
% from \xintREZ, but it dates back from very early days and uses old \Z |
| 34660 |
% delimiters (same remarks for the code jumping from \xintFracToSci |
| 34661 |
% to \xintrez) |
| 34662 |
%\end{lverb} |
| 34663 |
% \begin{macrocode} |
| 34664 |
\def\XINT_floattodec#1]% |
| 34665 |
{% |
| 34666 |
\expandafter\XINT_dectostr\romannumeral0\xintrez{#1]}% |
| 34667 |
}% |
| 34668 |
% \end{macrocode} |
| 34669 |
% |
| 34670 |
% \subsection{\csh{XINTinFloatFrac}} |
| 34671 |
% \added{1.09i} |
| 34672 |
% |
| 34673 |
%\begin{lverb} |
| 34674 |
% For frac function in \xintfloatexpr. This version computes |
| 34675 |
% exactly from the input the fractional part and then only converts it |
| 34676 |
% into a float with the asked-for number of digits. I will have to think |
| 34677 |
% it again some day, certainly. |
| 34678 |
%\end{lverb} |
| 34679 |
% |
| 34680 |
% \changed{1.1} |
| 34681 |
%\begin{lverb} |
| 34682 |
% 1.1 removes optional argument for which there was anyhow no interface, for |
| 34683 |
% technical reasons having to do with \xintNewExpr. |
| 34684 |
%\end{lverb} |
| 34685 |
% |
| 34686 |
% \changed{1.1a} |
| 34687 |
%\begin{lverb} |
| 34688 |
% 1.1a renames the macro as \XINTinFloatFracdigits (from \XINTinFloatFrac) to |
| 34689 |
% be synchronous with the \XINTinFloatSqrt and \XINTinFloat habits related to |
| 34690 |
% \xintNewExpr context and issues with macro names. |
| 34691 |
%\end{lverb} |
| 34692 |
% |
| 34693 |
% \changed{1.4e} |
| 34694 |
%\begin{lverb} |
| 34695 |
% 1.4e renames it back to \XINTinFloatFrac because of all such similarly named |
| 34696 |
% macros also using \XINTdigits forcedly. |
| 34697 |
%\end{lverb} |
| 34698 |
% \begin{macrocode} |
| 34699 |
\def\XINTinFloatFrac {\romannumeral0\XINTinfloatfrac}% |
| 34700 |
\def\XINTinfloatfrac #1% |
| 34701 |
{% |
| 34702 |
\expandafter\XINT_infloatfrac_a\expandafter {\romannumeral0\xinttfrac{#1}}% |
| 34703 |
}% |
| 34704 |
\def\XINT_infloatfrac_a {\XINTinfloat[\XINTdigits]}% |
| 34705 |
% \end{macrocode} |
| 34706 |
% \subsection{\csh{xintFloatAdd}, \csh{XINTinFloatAdd}} |
| 34707 |
%\begin{lverb} |
| 34708 |
% First included in release 1.07. |
| 34709 |
% |
| 34710 |
% 1.09ka improved a bit the efficiency. However the add, sub, mul, div |
| 34711 |
% routines were provisory and supposed to be revised soon. |
| 34712 |
% |
| 34713 |
% Which didn't happen until 1.2f. Now, the inputs are first rounded to P |
| 34714 |
% digits, not P+2 as earlier. |
| 34715 |
% |
| 34716 |
% See general introduction for important changes at 1.4e relative to |
| 34717 |
% the \XINTinFloat<name> macros. |
| 34718 |
% |
| 34719 |
%\end{lverb} |
| 34720 |
% \begin{macrocode} |
| 34721 |
\def\xintFloatAdd {\romannumeral0\xintfloatadd}% |
| 34722 |
\def\xintfloatadd #1{\XINT_fladd_chkopt \xintfloat #1\xint:}% |
| 34723 |
\def\XINTinFloatAdd{\romannumeral0\XINTinfloatadd }% |
| 34724 |
\def\XINTinfloatadd{\XINT_fladd_opt_a\XINTdigits.\XINTinfloatS}% |
| 34725 |
\def\XINTinFloatAdd_wopt{\romannumeral0\XINTinfloatadd_wopt}% |
| 34726 |
\def\XINTinfloatadd_wopt[#1]{\expandafter\XINT_fladd_opt_a\the\numexpr#1.\XINTinfloatS}% |
| 34727 |
\def\XINT_fladd_chkopt #1#2% |
| 34728 |
{% |
| 34729 |
\ifx [#2\expandafter\XINT_fladd_opt |
| 34730 |
\else\expandafter\XINT_fladd_noopt |
| 34731 |
\fi #1#2% |
| 34732 |
}% |
| 34733 |
\def\XINT_fladd_noopt #1#2\xint:#3% |
| 34734 |
{% |
| 34735 |
#1[\XINTdigits]% |
| 34736 |
{\expandafter\XINT_FL_add_a |
| 34737 |
\romannumeral0\XINTinfloat[\XINTdigits]{#2}\XINTdigits.{#3}}% |
| 34738 |
}% |
| 34739 |
\def\XINT_fladd_opt #1[\xint:#2]%#3#4% |
| 34740 |
{% |
| 34741 |
\expandafter\XINT_fladd_opt_a\the\numexpr #2.#1% |
| 34742 |
}% |
| 34743 |
\def\XINT_fladd_opt_a #1.#2#3#4% |
| 34744 |
{% |
| 34745 |
#2[#1]{\expandafter\XINT_FL_add_a\romannumeral0\XINTinfloat[#1]{#3}#1.{#4}}% |
| 34746 |
}% |
| 34747 |
\def\XINT_FL_add_a #1% |
| 34748 |
{% |
| 34749 |
\xint_gob_til_zero #1\XINT_FL_add_zero 0\XINT_FL_add_b #1% |
| 34750 |
}% |
| 34751 |
\def\XINT_FL_add_zero #1.#2{#2}%[[ |
| 34752 |
\def\XINT_FL_add_b #1]#2.#3% |
| 34753 |
{% |
| 34754 |
\expandafter\XINT_FL_add_c\romannumeral0\XINTinfloat[#2]{#3}#2.#1]% |
| 34755 |
}% |
| 34756 |
\def\XINT_FL_add_c #1% |
| 34757 |
{% |
| 34758 |
\xint_gob_til_zero #1\XINT_FL_add_zero 0\XINT_FL_add_d #1% |
| 34759 |
}% |
| 34760 |
\def\XINT_FL_add_d #1[#2]#3.#4[#5]% |
| 34761 |
{% |
| 34762 |
\ifnum\numexpr #2-#3-#5>\xint_c_\xint_dothis\xint_firstoftwo\fi |
| 34763 |
\ifnum\numexpr #5-#3-#2>\xint_c_\xint_dothis\xint_secondoftwo\fi |
| 34764 |
\xint_orthat\xintAdd {#1[#2]}{#4[#5]}% |
| 34765 |
}% |
| 34766 |
% \end{macrocode} |
| 34767 |
% \subsection{\csh{xintFloatSub}, \csh{XINTinFloatSub}} |
| 34768 |
% \added{1.07} |
| 34769 |
% \changed{1.2f} |
| 34770 |
%\begin{lverb} |
| 34771 |
% Starting with 1.2f the arguments undergo an intial rounding to the target |
| 34772 |
% precision P not P+2. |
| 34773 |
%\end{lverb} |
| 34774 |
% |
| 34775 |
% \begin{macrocode} |
| 34776 |
\def\xintFloatSub {\romannumeral0\xintfloatsub}% |
| 34777 |
\def\xintfloatsub #1{\XINT_flsub_chkopt \xintfloat #1\xint:}% |
| 34778 |
\def\XINTinFloatSub{\romannumeral0\XINTinfloatsub}% |
| 34779 |
\def\XINTinfloatsub{\XINT_flsub_opt_a\XINTdigits.\XINTinfloatS}% |
| 34780 |
\def\XINTinFloatSub_wopt{\romannumeral0\XINTinfloatsub_wopt}% |
| 34781 |
\def\XINTinfloatsub_wopt[#1]{\expandafter\XINT_flsub_opt_a\the\numexpr#1.\XINTinfloatS}% |
| 34782 |
\def\XINT_flsub_chkopt #1#2% |
| 34783 |
{% |
| 34784 |
\ifx [#2\expandafter\XINT_flsub_opt |
| 34785 |
\else\expandafter\XINT_flsub_noopt |
| 34786 |
\fi #1#2% |
| 34787 |
}% |
| 34788 |
\def\XINT_flsub_noopt #1#2\xint:#3% |
| 34789 |
{% |
| 34790 |
#1[\XINTdigits]% |
| 34791 |
{\expandafter\XINT_FL_add_a |
| 34792 |
\romannumeral0\XINTinfloat[\XINTdigits]{#2}\XINTdigits.{\xintOpp{#3}}}% |
| 34793 |
}% |
| 34794 |
\def\XINT_flsub_opt #1[\xint:#2]%#3#4% |
| 34795 |
{% |
| 34796 |
\expandafter\XINT_flsub_opt_a\the\numexpr #2.#1% |
| 34797 |
}% |
| 34798 |
\def\XINT_flsub_opt_a #1.#2#3#4% |
| 34799 |
{% |
| 34800 |
#2[#1]{\expandafter\XINT_FL_add_a\romannumeral0\XINTinfloat[#1]{#3}#1.{\xintOpp{#4}}}% |
| 34801 |
}% |
| 34802 |
% \end{macrocode} |
| 34803 |
% \subsection{\csh{xintFloatMul}, \csh{XINTinFloatMul}} |
| 34804 |
% \added{1.07} |
| 34805 |
% \changed{1.2d} |
| 34806 |
%\begin{lverb} |
| 34807 |
% Starting with 1.2f the arguments are rounded to the target precision P not |
| 34808 |
% P+2. |
| 34809 |
%\end{lverb} |
| 34810 |
% \changed{1.2g} |
| 34811 |
%\begin{lverb} |
| 34812 |
% 1.2g handles the inputs via \XINTinFloatS which will be more efficient when |
| 34813 |
% the precision is large and the input is for example a small constant like 2. |
| 34814 |
%\end{lverb} |
| 34815 |
% \begin{macrocode} |
| 34816 |
\def\xintFloatMul {\romannumeral0\xintfloatmul}% |
| 34817 |
\def\xintfloatmul #1{\XINT_flmul_chkopt \xintfloat #1\xint:}% |
| 34818 |
\def\XINTinFloatMul{\romannumeral0\XINTinfloatmul}% |
| 34819 |
\def\XINTinfloatmul{\XINT_flmul_opt_a\XINTdigits.\XINTinfloatS}% |
| 34820 |
\def\XINTinFloatMul_wopt{\romannumeral0\XINTinfloatmul_wopt}% |
| 34821 |
\def\XINTinfloatmul_wopt[#1]{\expandafter\XINT_flmul_opt_a\the\numexpr#1.\XINTinfloatS}% |
| 34822 |
\def\XINT_flmul_chkopt #1#2% |
| 34823 |
{% |
| 34824 |
\ifx [#2\expandafter\XINT_flmul_opt |
| 34825 |
\else\expandafter\XINT_flmul_noopt |
| 34826 |
\fi #1#2% |
| 34827 |
}% |
| 34828 |
\def\XINT_flmul_noopt #1#2\xint:#3% |
| 34829 |
{% |
| 34830 |
#1[\XINTdigits]% |
| 34831 |
{\expandafter\XINT_FL_mul_a |
| 34832 |
\romannumeral0\XINTinfloatS[\XINTdigits]{#2}\XINTdigits.{#3}}% |
| 34833 |
}% |
| 34834 |
\def\XINT_flmul_opt #1[\xint:#2]%#3#4% |
| 34835 |
{% |
| 34836 |
\expandafter\XINT_flmul_opt_a\the\numexpr #2.#1% |
| 34837 |
}% |
| 34838 |
\def\XINT_flmul_opt_a #1.#2#3#4% |
| 34839 |
{% |
| 34840 |
#2[#1]{\expandafter\XINT_FL_mul_a\romannumeral0\XINTinfloatS[#1]{#3}#1.{#4}}% |
| 34841 |
}% |
| 34842 |
\def\XINT_FL_mul_a #1[#2]#3.#4% |
| 34843 |
{% |
| 34844 |
\expandafter\XINT_FL_mul_b\romannumeral0\XINTinfloatS[#3]{#4}#1[#2]% |
| 34845 |
}% |
| 34846 |
\def\XINT_FL_mul_b #1[#2]#3[#4]{\xintiiMul{#3}{#1}/1[#4+#2]}% |
| 34847 |
% \end{macrocode} |
| 34848 |
% \subsection{\csh{xintFloatSqr}, \csh{XINTinFloatSqr}} |
| 34849 |
% \added{1.4e} |
| 34850 |
%\begin{lverb} |
| 34851 |
% Strangely \xintFloatSqr had never been defined so far. |
| 34852 |
% |
| 34853 |
% An \XINTinFloatSqr{#1} was defined in xintexpr.sty directly as |
| 34854 |
% \XINTinFloatMul[\XINTdigits]{#1}{#1}, to support the sqr() function. The |
| 34855 |
% {#1}{#1} causes no problem as #1 in this context is always pre-expanded so |
| 34856 |
% we don't need to worry about this, and the \xintdeffloatfunc mechanism |
| 34857 |
% should hopefully take care to add the needed argument pre-expansion if need |
| 34858 |
% be. |
| 34859 |
% |
| 34860 |
% Anyway let's do this finally properly here. |
| 34861 |
%\end{lverb} |
| 34862 |
% \begin{macrocode} |
| 34863 |
\def\xintFloatSqr {\romannumeral0\xintfloatsqr}% |
| 34864 |
\def\xintfloatsqr #1{\XINT_flsqr_chkopt \xintfloat #1\xint:}% |
| 34865 |
\def\XINTinFloatSqr{\romannumeral0\XINTinfloatsqr}% |
| 34866 |
\def\XINTinfloatsqr{\XINT_flsqr_opt_a\XINTdigits.\XINTinfloatS}% |
| 34867 |
\def\XINT_flsqr_chkopt #1#2% |
| 34868 |
{% |
| 34869 |
\ifx [#2\expandafter\XINT_flsqr_opt |
| 34870 |
\else\expandafter\XINT_flsqr_noopt |
| 34871 |
\fi #1#2% |
| 34872 |
}% |
| 34873 |
\def\XINT_flsqr_noopt #1#2\xint: |
| 34874 |
{% |
| 34875 |
#1[\XINTdigits]% |
| 34876 |
{\expandafter\XINT_FL_sqr_a\romannumeral0\XINTinfloatS[\XINTdigits]{#2}}% |
| 34877 |
}% |
| 34878 |
\def\XINT_flsqr_opt #1[\xint:#2]% |
| 34879 |
{% |
| 34880 |
\expandafter\XINT_flsqr_opt_a\the\numexpr #2.#1% |
| 34881 |
}% |
| 34882 |
\def\XINT_flsqr_opt_a #1.#2#3% |
| 34883 |
{% |
| 34884 |
#2[#1]{\expandafter\XINT_FL_sqr_a\romannumeral0\XINTinfloatS[#1]{#3}}% |
| 34885 |
}% |
| 34886 |
\def\XINT_FL_sqr_a #1[#2]{\xintiiSqr{#1}/1[#2+#2]}% |
| 34887 |
\def\XINTinFloatSqr_wopt[#1]#2{\XINTinFloatS[#1]{\expandafter\XINT_FL_sqr_a\romannumeral0\XINTinfloatS[#1]{#2}}}% |
| 34888 |
% \end{macrocode} |
| 34889 |
% \subsection{\csh{XINTinFloatInv}} |
| 34890 |
% \added{1.3e} |
| 34891 |
%\begin{lverb} |
| 34892 |
% Added belatedly at 1.3e, to support inv() function. We use Short |
| 34893 |
% output, for rare inv(\xintexpr 1/3\relax) case. I need to think the whole |
| 34894 |
% thing out at some later date. |
| 34895 |
%\end{lverb} |
| 34896 |
% \begin{macrocode} |
| 34897 |
\def\XINTinFloatInv#1{\XINTinFloatS[\XINTdigits]{\xintInv{#1}}}% |
| 34898 |
\def\XINTinFloatInv_wopt[#1]#2{\XINTinFloatS[#1]{\xintInv{#2}}}% |
| 34899 |
% \end{macrocode} |
| 34900 |
% \subsection{\csh{xintFloatDiv}, \csh{XINTinFloatDiv}} |
| 34901 |
% \added{1.07} |
| 34902 |
% \changed{1.2f} |
| 34903 |
%\begin{lverb} |
| 34904 |
% Starting with 1.2f the arguments are rounded to the target precision P not |
| 34905 |
% P+2. |
| 34906 |
%\end{lverb} |
| 34907 |
% \changed{1.2g} |
| 34908 |
%\begin{lverb} |
| 34909 |
% 1.2g handles the inputs via \XINTinFloatS which will be more efficient when |
| 34910 |
% the precision is large and the input is for example a small constant like 2. |
| 34911 |
% |
| 34912 |
% The actual rounding of the quotient is handled via \xintfloat (or |
| 34913 |
% \XINTinfloatS). |
| 34914 |
%\end{lverb} |
| 34915 |
% \changed{1.2k} |
| 34916 |
%\begin{lverb} |
| 34917 |
% 1.2k does the same kind of improvement in \XINT_FL_div_b as for |
| 34918 |
% multiplication: earlier code was unnecessarily high level. |
| 34919 |
%\end{lverb} |
| 34920 |
% \begin{macrocode} |
| 34921 |
\def\xintFloatDiv {\romannumeral0\xintfloatdiv}% |
| 34922 |
\def\xintfloatdiv #1{\XINT_fldiv_chkopt \xintfloat #1\xint:}% |
| 34923 |
\def\XINTinFloatDiv{\romannumeral0\XINTinfloatdiv}% |
| 34924 |
\def\XINTinfloatdiv{\XINT_fldiv_opt_a\XINTdigits.\XINTinfloatS}% |
| 34925 |
\def\XINTinFloatDiv_wopt[#1]{\romannumeral0\XINT_fldiv_opt_a#1.\XINTinfloatS}% |
| 34926 |
\def\XINT_fldiv_chkopt #1#2% |
| 34927 |
{% |
| 34928 |
\ifx [#2\expandafter\XINT_fldiv_opt |
| 34929 |
\else\expandafter\XINT_fldiv_noopt |
| 34930 |
\fi #1#2% |
| 34931 |
}% |
| 34932 |
% \end{macrocode} |
| 34933 |
%\begin{lverb} |
| 34934 |
% 1.4g adds here intercept of second argument being zero, |
| 34935 |
% else a low level error will arise at later stage from the |
| 34936 |
% the fall-back value returned by core iidivision being 0 |
| 34937 |
% and not having expected number of digits at \XINT_infloat_Qq |
| 34938 |
% and split from left returning some empty value breaking the |
| 34939 |
% \ifnum test in \XINT_infloat_Rq. |
| 34940 |
%\end{lverb} |
| 34941 |
% \begin{macrocode} |
| 34942 |
\def\XINT_fldiv_noopt #1#2\xint:#3% |
| 34943 |
{% |
| 34944 |
#1[\XINTdigits]% |
| 34945 |
{\expandafter\XINT_FL_div_aa |
| 34946 |
\romannumeral0\XINTinfloatS[\XINTdigits]{#3}\XINTdigits.{#2}}% |
| 34947 |
}% |
| 34948 |
\def\XINT_FL_div_aa #1% |
| 34949 |
{% |
| 34950 |
\xint_gob_til_zero#1\XINT_FL_div_Bzero0\XINT_FL_div_a #1% |
| 34951 |
}% |
| 34952 |
\def\XINT_FL_div_Bzero0\XINT_FL_div_a#1[#2]#3.#4% |
| 34953 |
{% |
| 34954 |
\XINT_signalcondition{DivisionByZero}{Division by zero (#1[#2]) of #4}{}{ 0[0]}% |
| 34955 |
}% |
| 34956 |
\def\XINT_fldiv_opt #1[\xint:#2]%#3#4% |
| 34957 |
{% |
| 34958 |
\expandafter\XINT_fldiv_opt_a\the\numexpr #2.#1% |
| 34959 |
}% |
| 34960 |
% \end{macrocode} |
| 34961 |
%\begin{lverb} |
| 34962 |
% Also here added early check at 1.4g if divisor is zero. |
| 34963 |
%\end{lverb} |
| 34964 |
% \begin{macrocode} |
| 34965 |
\def\XINT_fldiv_opt_a #1.#2#3#4% |
| 34966 |
{% |
| 34967 |
#2[#1]{\expandafter\XINT_FL_div_aa\romannumeral0\XINTinfloatS[#1]{#4}#1.{#3}}% |
| 34968 |
}% |
| 34969 |
\def\XINT_FL_div_a #1[#2]#3.#4% |
| 34970 |
{% |
| 34971 |
\expandafter\XINT_FL_div_b\romannumeral0\XINTinfloatS[#3]{#4}/#1e#2% |
| 34972 |
}% |
| 34973 |
\def\XINT_FL_div_b #1[#2]{#1e#2}% |
| 34974 |
% \end{macrocode} |
| 34975 |
% \subsection{\csh{xintFloatPow}, \csh{XINTinFloatPow}} |
| 34976 |
% \added{1.07} |
| 34977 |
% |
| 34978 |
%\begin{lverb} |
| 34979 |
% 1.09j has re-organized the core loop. |
| 34980 |
% |
| 34981 |
% 2015/12/07. I have hesitated to map ^ in expressions to \xintFloatPow rather |
| 34982 |
% than \xintFloatPower. But for 1.234567890123456 to the power 2145678912 with |
| 34983 |
% P=16, using Pow rather than Power seems to bring only about 5$char37 $space |
| 34984 |
% gain. |
| 34985 |
% |
| 34986 |
% This routine requires the exponent x to be compatible with \numexpr parsing. |
| 34987 |
%\end{lverb} |
| 34988 |
% |
| 34989 |
% \changed{1.2f} |
| 34990 |
%\begin{lverb} |
| 34991 |
% 1.2f has rewritten the code for better efficiency. Also, now the argument A |
| 34992 |
% for A^x is first rounded to P digits before switching to the increased |
| 34993 |
% working precision (which depends upon x). |
| 34994 |
%\end{lverb} |
| 34995 |
% \begin{macrocode} |
| 34996 |
\def\xintFloatPow {\romannumeral0\xintfloatpow}% |
| 34997 |
\def\xintfloatpow #1{\XINT_flpow_chkopt \xintfloat #1\xint:}% |
| 34998 |
\def\XINTinFloatPow{\romannumeral0\XINTinfloatpow }% |
| 34999 |
\def\XINTinfloatpow{\XINT_flpow_opt_a\XINTdigits.\XINTinfloatS}% |
| 35000 |
\def\XINTinfloatpow_wopt[#1]{\expandafter\XINT_flpow_opt_a\the\numexpr#1.\XINTinfloatS}% |
| 35001 |
\def\XINT_flpow_chkopt #1#2% |
| 35002 |
{% |
| 35003 |
\ifx [#2\expandafter\XINT_flpow_opt |
| 35004 |
\else\expandafter\XINT_flpow_noopt |
| 35005 |
\fi |
| 35006 |
#1#2% |
| 35007 |
}% |
| 35008 |
\def\XINT_flpow_noopt #1#2\xint:#3% |
| 35009 |
{% |
| 35010 |
\expandafter\XINT_flpow_checkB_a |
| 35011 |
\the\numexpr #3.\XINTdigits.{#2}{#1[\XINTdigits]}% |
| 35012 |
}% |
| 35013 |
\def\XINT_flpow_opt #1[\xint:#2]% |
| 35014 |
{% |
| 35015 |
\expandafter\XINT_flpow_opt_a\the\numexpr #2.#1% |
| 35016 |
}% |
| 35017 |
\def\XINT_flpow_opt_a #1.#2#3#4% |
| 35018 |
{% |
| 35019 |
\expandafter\XINT_flpow_checkB_a\the\numexpr #4.#1.{#3}{#2[#1]}% |
| 35020 |
}% |
| 35021 |
\def\XINT_flpow_checkB_a #1% |
| 35022 |
{% |
| 35023 |
\xint_UDzerominusfork |
| 35024 |
#1-\XINT_flpow_BisZero |
| 35025 |
0#1{\XINT_flpow_checkB_b -}% |
| 35026 |
0-{\XINT_flpow_checkB_b {}#1}% |
| 35027 |
\krof |
| 35028 |
}% |
| 35029 |
\def\XINT_flpow_BisZero .#1.#2#3{#3{1[0]}}% |
| 35030 |
\def\XINT_flpow_checkB_b #1#2.#3.% |
| 35031 |
{% |
| 35032 |
\expandafter\XINT_flpow_checkB_c |
| 35033 |
\the\numexpr\xintLength{#2}+\xint_c_iii.#3.#2.{#1}% |
| 35034 |
}% |
| 35035 |
\def\XINT_flpow_checkB_c #1.#2.% |
| 35036 |
{% |
| 35037 |
\expandafter\XINT_flpow_checkB_d\the\numexpr#1+#2.#1.#2.% |
| 35038 |
}% |
| 35039 |
% \end{macrocode} |
| 35040 |
%\begin{lverb} |
| 35041 |
% |
| 35042 |
% 1.2f rounds input to P digits, first. |
| 35043 |
%\end{lverb} |
| 35044 |
% \begin{macrocode} |
| 35045 |
\def\XINT_flpow_checkB_d #1.#2.#3.#4.#5#6% |
| 35046 |
{% |
| 35047 |
\expandafter \XINT_flpow_aa |
| 35048 |
\romannumeral0\XINTinfloat [#3]{#6}{#2}{#1}{#4}{#5}% |
| 35049 |
}% |
| 35050 |
\def\XINT_flpow_aa #1[#2]#3% |
| 35051 |
{% |
| 35052 |
\expandafter\XINT_flpow_ab\the\numexpr #2-#3\expandafter.% |
| 35053 |
\romannumeral\XINT_rep #3\endcsname0.#1.% |
| 35054 |
}% |
| 35055 |
\def\XINT_flpow_ab #1.#2.#3.{\XINT_flpow_a #3#2[#1]}% |
| 35056 |
\def\XINT_flpow_a #1% |
| 35057 |
{% |
| 35058 |
\xint_UDzerominusfork |
| 35059 |
#1-\XINT_flpow_zero |
| 35060 |
0#1{\XINT_flpow_b \iftrue}% |
| 35061 |
0-{\XINT_flpow_b \iffalse#1}% |
| 35062 |
\krof |
| 35063 |
}% |
| 35064 |
\def\XINT_flpow_zero #1[#2]#3#4#5#6% |
| 35065 |
{% |
| 35066 |
#6{\if 1#51\xint_dothis {0[0]}\fi |
| 35067 |
\xint_orthat |
| 35068 |
{\XINT_signalcondition{DivisionByZero}{0 raised to power -#4.}{}{ 0[0]}}% |
| 35069 |
}% |
| 35070 |
}% |
| 35071 |
\def\XINT_flpow_b #1#2[#3]#4#5% |
| 35072 |
{% |
| 35073 |
\XINT_flpow_loopI #5.#3.#2.#4.{#1\ifodd #5 \xint_c_i\fi\fi}% |
| 35074 |
}% |
| 35075 |
\def\XINT_flpow_truncate #1.#2.#3.% |
| 35076 |
{% |
| 35077 |
\expandafter\XINT_flpow_truncate_a |
| 35078 |
\romannumeral0\XINT_split_fromleft |
| 35079 |
#3.#2\xint_bye2345678\xint_bye..#1.#3.% |
| 35080 |
}% |
| 35081 |
\def\XINT_flpow_truncate_a #1.#2.#3.{#3+\xintLength{#2}.#1.}% |
| 35082 |
\def\XINT_flpow_loopI #1.% |
| 35083 |
{% |
| 35084 |
\ifnum #1=\xint_c_i\expandafter\XINT_flpow_ItoIII\fi |
| 35085 |
\ifodd #1 |
| 35086 |
\expandafter\XINT_flpow_loopI_odd |
| 35087 |
\else |
| 35088 |
\expandafter\XINT_flpow_loopI_even |
| 35089 |
\fi |
| 35090 |
#1.% |
| 35091 |
}% |
| 35092 |
\def\XINT_flpow_ItoIII\ifodd #1\fi #2.#3.#4.#5.#6% |
| 35093 |
{% |
| 35094 |
\expandafter\XINT_flpow_III\the\numexpr #6+\xint_c_.#3.#4.#5.% |
| 35095 |
}% |
| 35096 |
\def\XINT_flpow_loopI_even #1.#2.#3.%#4.% |
| 35097 |
{% |
| 35098 |
\expandafter\XINT_flpow_loopI |
| 35099 |
\the\numexpr #1/\xint_c_ii\expandafter.% |
| 35100 |
\the\numexpr\expandafter\XINT_flpow_truncate |
| 35101 |
\the\numexpr\xint_c_ii*#2\expandafter.\romannumeral0\xintiisqr{#3}.% |
| 35102 |
}% |
| 35103 |
\def\XINT_flpow_loopI_odd #1.#2.#3.#4.% |
| 35104 |
{% |
| 35105 |
\expandafter\XINT_flpow_loopII |
| 35106 |
\the\numexpr #1/\xint_c_ii-\xint_c_i\expandafter.% |
| 35107 |
\the\numexpr\expandafter\XINT_flpow_truncate |
| 35108 |
\the\numexpr\xint_c_ii*#2\expandafter.\romannumeral0\xintiisqr{#3}.#4.#2.#3.% |
| 35109 |
}% |
| 35110 |
\def\XINT_flpow_loopII #1.% |
| 35111 |
{% |
| 35112 |
\ifnum #1 = \xint_c_i\expandafter\XINT_flpow_IItoIII\fi |
| 35113 |
\ifodd #1 |
| 35114 |
\expandafter\XINT_flpow_loopII_odd |
| 35115 |
\else |
| 35116 |
\expandafter\XINT_flpow_loopII_even |
| 35117 |
\fi |
| 35118 |
#1.% |
| 35119 |
}% |
| 35120 |
\def\XINT_flpow_loopII_even #1.#2.#3.%#4.% |
| 35121 |
{% |
| 35122 |
\expandafter\XINT_flpow_loopII |
| 35123 |
\the\numexpr #1/\xint_c_ii\expandafter.% |
| 35124 |
\the\numexpr\expandafter\XINT_flpow_truncate |
| 35125 |
\the\numexpr\xint_c_ii*#2\expandafter.\romannumeral0\xintiisqr{#3}.% |
| 35126 |
}% |
| 35127 |
\def\XINT_flpow_loopII_odd #1.#2.#3.#4.#5.#6.% |
| 35128 |
{% |
| 35129 |
\expandafter\XINT_flpow_loopII_odda |
| 35130 |
\the\numexpr\expandafter\XINT_flpow_truncate |
| 35131 |
\the\numexpr#2+#5\expandafter.\romannumeral0\xintiimul{#3}{#6}.#4.% |
| 35132 |
#1.#2.#3.% |
| 35133 |
}% |
| 35134 |
\def\XINT_flpow_loopII_odda #1.#2.#3.#4.#5.#6.% |
| 35135 |
{% |
| 35136 |
\expandafter\XINT_flpow_loopII |
| 35137 |
\the\numexpr #4/\xint_c_ii-\xint_c_i\expandafter.% |
| 35138 |
\the\numexpr\expandafter\XINT_flpow_truncate |
| 35139 |
\the\numexpr\xint_c_ii*#5\expandafter.\romannumeral0\xintiisqr{#6}.#3.% |
| 35140 |
#1.#2.% |
| 35141 |
}% |
| 35142 |
\def\XINT_flpow_IItoIII\ifodd #1\fi #2.#3.#4.#5.#6.#7.#8% |
| 35143 |
{% |
| 35144 |
\expandafter\XINT_flpow_III\the\numexpr #8+\xint_c_\expandafter.% |
| 35145 |
\the\numexpr\expandafter\XINT_flpow_truncate |
| 35146 |
\the\numexpr#3+#6\expandafter.\romannumeral0\xintiimul{#4}{#7}.#5.% |
| 35147 |
}% |
| 35148 |
% \end{macrocode} |
| 35149 |
%\begin{lverb} |
| 35150 |
% This ending is common with \xintFloatPower. |
| 35151 |
% |
| 35152 |
% In the case of negative exponent we need to inverse the Q-digits mantissa. |
| 35153 |
% This requires no special attention now as 1.2k's \xintFloat does correct |
| 35154 |
% rounding of fractions hence it is easy to bound the total error. It can be |
| 35155 |
% checked that the algorithm after final rounding to the target precision |
| 35156 |
% computes a value Z whose distance to the exact theoretical will be less than |
| 35157 |
% 0.52 ulp(Z) (and worst cases can only be slightly worse than 0.51 ulp(Z)). |
| 35158 |
% |
| 35159 |
% In the case of the half-integer exponent (only via the expression |
| 35160 |
% interface,) the computation (which proceeds via \XINTinFloatPowerH) ends |
| 35161 |
% with a square root. This square root extraction is done with 3 guard digits |
| 35162 |
% (the power operations were done with more.) Then the value is rounded to the |
| 35163 |
% target precision. There is thus this rounding to 3 guard digits (in the case |
| 35164 |
% of negative exponent the reciprocal is computed before the square-root), |
| 35165 |
% then the square root is (computed with exact rounding for these 3 guard |
| 35166 |
% digits), and then there is the final rounding of this to the target |
| 35167 |
% precision. The total error (for positive as well as negative exponent) has |
| 35168 |
% been estimated to at worst possibly exceed slightly 0.5125 ulp(Z), and at |
| 35169 |
% any rate it is less than 0.52 ulp(Z). |
| 35170 |
%\end{lverb} |
| 35171 |
% \begin{macrocode} |
| 35172 |
\def\XINT_flpow_III #1.#2.#3.#4.#5% |
| 35173 |
{% |
| 35174 |
\expandafter\XINT_flpow_IIIend |
| 35175 |
\xint_UDsignfork |
| 35176 |
#5{{1/#3[-#2]}}% |
| 35177 |
-{{#3[#2]}}% |
| 35178 |
\krof #1% |
| 35179 |
}% |
| 35180 |
\def\XINT_flpow_IIIend #1#2#3% |
| 35181 |
{#3{\if#21\xint_afterfi{\expandafter-\romannumeral`&&@}\fi#1}}% |
| 35182 |
% \end{macrocode} |
| 35183 |
% \subsection{\csh{xintFloatPower}, \csh{XINTinFloatPower}} |
| 35184 |
% \added{1.07} |
| 35185 |
%\begin{lverb} |
| 35186 |
% The core loop has been re-organized in 1.09j for some slight |
| 35187 |
% efficiency gain. The exponent B is given to \xintNum. The ^ in expressions |
| 35188 |
% is mapped to this routine. |
| 35189 |
%\end{lverb} |
| 35190 |
% \changed{1.2f} |
| 35191 |
%\begin{lverb} |
| 35192 |
% Same modifications as in \xintFloatPow for 1.2f. |
| 35193 |
% |
| 35194 |
% 1.2f \XINTinFloatPowerH (now moved to $xintlognameimp, and renamed). It |
| 35195 |
% truncated the exponent to an integer of half-integer, and in the latter case |
| 35196 |
% use Square-root extraction. At 1.2k this was improved as 1.2f stupidly |
| 35197 |
% rounded to Digits before, not after the square root extraction, 1.2k kept 3 |
| 35198 |
% guard digits for this last step. And the initial step was |
| 35199 |
% changed to a rounding rather than truncating. |
| 35200 |
%\end{lverb} |
| 35201 |
% \changed{1.4e} |
| 35202 |
%\begin{lverb} |
| 35203 |
% Until 1.4e this \XINTinFloatPowerH was the macro for a^b in expressions, |
| 35204 |
% but of course it behaved strangely for b not an integer or an half-integer! |
| 35205 |
% At 1.4e, the non-integer, non-half-integer exponents will be handled via |
| 35206 |
% log10() and pow10() support macros, see $xintlognameimp. The code |
| 35207 |
% has now been relocated there. |
| 35208 |
%\end{lverb} |
| 35209 |
% \begin{macrocode} |
| 35210 |
\def\xintFloatPower {\romannumeral0\xintfloatpower}% |
| 35211 |
\def\xintfloatpower #1{\XINT_flpower_chkopt \xintfloat #1\xint:}% |
| 35212 |
\def\XINTinFloatPower{\romannumeral0\XINTinfloatpower }% |
| 35213 |
\def\XINTinfloatpower{\XINT_flpower_opt_a\XINTdigits.\XINTinfloatS}% |
| 35214 |
% \end{macrocode} |
| 35215 |
%\begin{lverb} |
| 35216 |
% Start of macro. Check for optional argument. |
| 35217 |
%\end{lverb} |
| 35218 |
% \begin{macrocode} |
| 35219 |
\def\XINT_flpower_chkopt #1#2% |
| 35220 |
{% |
| 35221 |
\ifx [#2\expandafter\XINT_flpower_opt |
| 35222 |
\else\expandafter\XINT_flpower_noopt |
| 35223 |
\fi |
| 35224 |
#1#2% |
| 35225 |
}% |
| 35226 |
\def\XINT_flpower_noopt #1#2\xint:#3% |
| 35227 |
{% |
| 35228 |
\expandafter\XINT_flpower_checkB_a |
| 35229 |
\romannumeral0\xintnum{#3}.\XINTdigits.{#2}{#1[\XINTdigits]}% |
| 35230 |
}% |
| 35231 |
\def\XINT_flpower_opt #1[\xint:#2]% |
| 35232 |
{% |
| 35233 |
\expandafter\XINT_flpower_opt_a\the\numexpr #2.#1% |
| 35234 |
}% |
| 35235 |
\def\XINT_flpower_opt_a #1.#2#3#4% |
| 35236 |
{% |
| 35237 |
\expandafter\XINT_flpower_checkB_a |
| 35238 |
\romannumeral0\xintnum{#4}.#1.{#3}{#2[#1]}% |
| 35239 |
}% |
| 35240 |
\def\XINT_flpower_checkB_a #1% |
| 35241 |
{% |
| 35242 |
\xint_UDzerominusfork |
| 35243 |
#1-{\XINT_flpower_BisZero 0}% |
| 35244 |
0#1{\XINT_flpower_checkB_b -}% |
| 35245 |
0-{\XINT_flpower_checkB_b {}#1}% |
| 35246 |
\krof |
| 35247 |
}% |
| 35248 |
\def\XINT_flpower_BisZero 0.#1.#2#3{#3{1[0]}}% |
| 35249 |
\def\XINT_flpower_checkB_b #1#2.#3.% |
| 35250 |
{% |
| 35251 |
\expandafter\XINT_flpower_checkB_c |
| 35252 |
\the\numexpr\xintLength{#2}+\xint_c_iii.#3.#2.{#1}% |
| 35253 |
}% |
| 35254 |
\def\XINT_flpower_checkB_c #1.#2.% |
| 35255 |
{% |
| 35256 |
\expandafter\XINT_flpower_checkB_d\the\numexpr#1+#2.#1.#2.% |
| 35257 |
}% |
| 35258 |
\def\XINT_flpower_checkB_d #1.#2.#3.#4.#5#6% |
| 35259 |
{% |
| 35260 |
\expandafter \XINT_flpower_aa |
| 35261 |
\romannumeral0\XINTinfloat [#3]{#6}{#2}{#1}{#4}{#5}% |
| 35262 |
}% |
| 35263 |
\def\XINT_flpower_aa #1[#2]#3% |
| 35264 |
{% |
| 35265 |
\expandafter\XINT_flpower_ab\the\numexpr #2-#3\expandafter.% |
| 35266 |
\romannumeral\XINT_rep #3\endcsname0.#1.% |
| 35267 |
}% |
| 35268 |
\def\XINT_flpower_ab #1.#2.#3.{\XINT_flpower_a #3#2[#1]}% |
| 35269 |
\def\XINT_flpower_a #1% |
| 35270 |
{% |
| 35271 |
\xint_UDzerominusfork |
| 35272 |
#1-\XINT_flpow_zero |
| 35273 |
0#1{\XINT_flpower_b \iftrue}% |
| 35274 |
0-{\XINT_flpower_b \iffalse#1}% |
| 35275 |
\krof |
| 35276 |
}% |
| 35277 |
\def\XINT_flpower_b #1#2[#3]#4#5% |
| 35278 |
{% |
| 35279 |
\XINT_flpower_loopI #5.#3.#2.#4.{#1\xintiiOdd{#5}\fi}% |
| 35280 |
}% |
| 35281 |
\def\XINT_flpower_loopI #1.% |
| 35282 |
{% |
| 35283 |
\if1\XINT_isOne {#1}\xint_dothis\XINT_flpower_ItoIII\fi |
| 35284 |
\ifodd\xintLDg{#1} %<- intentional space |
| 35285 |
\xint_dothis{\expandafter\XINT_flpower_loopI_odd}\fi |
| 35286 |
\xint_orthat{\expandafter\XINT_flpower_loopI_even}% |
| 35287 |
\romannumeral0\XINT_half |
| 35288 |
#1\xint_bye\xint_Bye345678\xint_bye |
| 35289 |
*\xint_c_v+\xint_c_v)/\xint_c_x-\xint_c_i\relax.% |
| 35290 |
}% |
| 35291 |
\def\XINT_flpower_ItoIII #1.#2.#3.#4.#5% |
| 35292 |
{% |
| 35293 |
\expandafter\XINT_flpow_III\the\numexpr #5+\xint_c_.#2.#3.#4.% |
| 35294 |
}% |
| 35295 |
\def\XINT_flpower_loopI_even #1.#2.#3.#4.% |
| 35296 |
{% |
| 35297 |
\expandafter\XINT_flpower_toloopI |
| 35298 |
\the\numexpr\expandafter\XINT_flpow_truncate |
| 35299 |
\the\numexpr\xint_c_ii*#2\expandafter.\romannumeral0\xintiisqr{#3}.#4.#1.% |
| 35300 |
}% |
| 35301 |
\def\XINT_flpower_toloopI #1.#2.#3.#4.{\XINT_flpower_loopI #4.#1.#2.#3.}% |
| 35302 |
\def\XINT_flpower_loopI_odd #1.#2.#3.#4.% |
| 35303 |
{% |
| 35304 |
\expandafter\XINT_flpower_toloopII |
| 35305 |
\the\numexpr\expandafter\XINT_flpow_truncate |
| 35306 |
\the\numexpr\xint_c_ii*#2\expandafter.\romannumeral0\xintiisqr{#3}.#4.% |
| 35307 |
#1.#2.#3.% |
| 35308 |
}% |
| 35309 |
\def\XINT_flpower_toloopII #1.#2.#3.#4.{\XINT_flpower_loopII #4.#1.#2.#3.}% |
| 35310 |
\def\XINT_flpower_loopII #1.% |
| 35311 |
{% |
| 35312 |
\if1\XINT_isOne{#1}\xint_dothis\XINT_flpower_IItoIII\fi |
| 35313 |
\ifodd\xintLDg{#1} %<- intentional space |
| 35314 |
\xint_dothis{\expandafter\XINT_flpower_loopII_odd}\fi |
| 35315 |
\xint_orthat{\expandafter\XINT_flpower_loopII_even}% |
| 35316 |
\romannumeral0\XINT_half#1\xint_bye\xint_Bye345678\xint_bye |
| 35317 |
*\xint_c_v+\xint_c_v)/\xint_c_x-\xint_c_i\relax.% |
| 35318 |
}% |
| 35319 |
\def\XINT_flpower_loopII_even #1.#2.#3.#4.% |
| 35320 |
{% |
| 35321 |
\expandafter\XINT_flpower_toloopII |
| 35322 |
\the\numexpr\expandafter\XINT_flpow_truncate |
| 35323 |
\the\numexpr\xint_c_ii*#2\expandafter.\romannumeral0\xintiisqr{#3}.#4.#1.% |
| 35324 |
}% |
| 35325 |
\def\XINT_flpower_loopII_odd #1.#2.#3.#4.#5.#6.% |
| 35326 |
{% |
| 35327 |
\expandafter\XINT_flpower_loopII_odda |
| 35328 |
\the\numexpr\expandafter\XINT_flpow_truncate |
| 35329 |
\the\numexpr#2+#5\expandafter.\romannumeral0\xintiimul{#3}{#6}.#4.% |
| 35330 |
#1.#2.#3.% |
| 35331 |
}% |
| 35332 |
\def\XINT_flpower_loopII_odda #1.#2.#3.#4.#5.#6.% |
| 35333 |
{% |
| 35334 |
\expandafter\XINT_flpower_toloopII |
| 35335 |
\the\numexpr\expandafter\XINT_flpow_truncate |
| 35336 |
\the\numexpr\xint_c_ii*#5\expandafter.\romannumeral0\xintiisqr{#6}.#3.% |
| 35337 |
#4.#1.#2.% |
| 35338 |
}% |
| 35339 |
\def\XINT_flpower_IItoIII #1.#2.#3.#4.#5.#6.#7% |
| 35340 |
{% |
| 35341 |
\expandafter\XINT_flpow_III\the\numexpr #7+\xint_c_\expandafter.% |
| 35342 |
\the\numexpr\expandafter\XINT_flpow_truncate |
| 35343 |
\the\numexpr#2+#5\expandafter.\romannumeral0\xintiimul{#3}{#6}.#4.% |
| 35344 |
}% |
| 35345 |
% \end{macrocode} |
| 35346 |
% \subsection{\csh{xintFloatFac}, \csh{XINTFloatFac}} |
| 35347 |
% \added{1.2} |
| 35348 |
% \begin{macrocode} |
| 35349 |
\def\xintFloatFac {\romannumeral0\xintfloatfac}% |
| 35350 |
\def\xintfloatfac #1{\XINT_flfac_chkopt \xintfloat #1\xint:}% |
| 35351 |
\def\XINTinFloatFac{\romannumeral0\XINTinfloatfac}% |
| 35352 |
\def\XINTinfloatfac[#1]{\expandafter\XINT_flfac_opt_a\the\numexpr#1.\XINTinfloatS}% |
| 35353 |
\def\XINTinFloatFacdigits{\romannumeral0\XINT_flfac_opt_a\XINTdigits.\XINTinfloatS}% |
| 35354 |
\def\XINT_flfac_chkopt #1#2% |
| 35355 |
{% |
| 35356 |
\ifx [#2\expandafter\XINT_flfac_opt |
| 35357 |
\else\expandafter\XINT_flfac_noopt |
| 35358 |
\fi |
| 35359 |
#1#2% |
| 35360 |
}% |
| 35361 |
\def\XINT_flfac_noopt #1#2\xint: |
| 35362 |
{% |
| 35363 |
\expandafter\XINT_FL_fac_fork_a |
| 35364 |
\the\numexpr \xintNum{#2}.\xint_c_i \XINTdigits\XINT_FL_fac_out{#1[\XINTdigits]}% |
| 35365 |
}% |
| 35366 |
\def\XINT_flfac_opt #1[\xint:#2]% |
| 35367 |
{% |
| 35368 |
\expandafter\XINT_flfac_opt_a\the\numexpr #2.#1% |
| 35369 |
}% |
| 35370 |
\def\XINT_flfac_opt_a #1.#2#3% |
| 35371 |
{% |
| 35372 |
\expandafter\XINT_FL_fac_fork_a\the\numexpr \xintNum{#3}.\xint_c_i {#1}\XINT_FL_fac_out{#2[#1]}% |
| 35373 |
}% |
| 35374 |
\def\XINT_FL_fac_fork_a #1% |
| 35375 |
{% |
| 35376 |
\xint_UDzerominusfork |
| 35377 |
#1-\XINT_FL_fac_iszero |
| 35378 |
0#1\XINT_FL_fac_isneg |
| 35379 |
0-{\XINT_FL_fac_fork_b #1}% |
| 35380 |
\krof |
| 35381 |
}% |
| 35382 |
\def\XINT_FL_fac_iszero #1.#2#3#4#5{#5{1[0]}}% |
| 35383 |
% \end{macrocode} |
| 35384 |
%\begin{lverb} |
| 35385 |
% 1.2f XINT_FL_fac_isneg returns 0, earlier versions used 1 here. |
| 35386 |
%\end{lverb} |
| 35387 |
% \begin{macrocode} |
| 35388 |
\def\XINT_FL_fac_isneg #1.#2#3#4#5% |
| 35389 |
{% |
| 35390 |
#5{\XINT_signalcondition{InvalidOperation} |
| 35391 |
{Factorial argument is negative: -#1.}{}{ 0[0]}}% |
| 35392 |
}% |
| 35393 |
\def\XINT_FL_fac_fork_b #1.% |
| 35394 |
{% |
| 35395 |
\ifnum #1>\xint_c_x^viii_mone\xint_dothis\XINT_FL_fac_toobig\fi |
| 35396 |
\ifnum #1>\xint_c_x^iv\xint_dothis\XINT_FL_fac_vbig \fi |
| 35397 |
\ifnum #1>465 \xint_dothis\XINT_FL_fac_big\fi |
| 35398 |
\ifnum #1>101 \xint_dothis\XINT_FL_fac_med\fi |
| 35399 |
\xint_orthat\XINT_FL_fac_small |
| 35400 |
#1.% |
| 35401 |
}% |
| 35402 |
\def\XINT_FL_fac_toobig #1.#2#3#4#5% |
| 35403 |
{% |
| 35404 |
#5{\XINT_signalcondition{InvalidOperation} |
| 35405 |
{Factorial argument is too large: #1>=10^8.}{}{ 0[0]}}% |
| 35406 |
}% |
| 35407 |
% \end{macrocode} |
| 35408 |
%\begin{lverb} |
| 35409 |
% Computations are done with Q blocks of eight digits. When a |
| 35410 |
% multiplication has a carry, hence creates Q+1 blocks, the least significant |
| 35411 |
% one is dropped. The goal is to compute an approximate value X' to the exact |
| 35412 |
% value X, such that the final relative error (X-X')/X will be at most |
| 35413 |
% 10^{-P-1} with P the desired precision. Then, when we round X' to X'' with P |
| 35414 |
% significant digits, we can prove that the absolute error |X-X''| is bounded |
| 35415 |
% (strictly) by 0.6 ulp(X''). (ulp= unit in the last (significant) place). Let |
| 35416 |
% N be the number of such operations, the formula for Q deduces from the |
| 35417 |
% previous explanations is that 8Q should be at least P+9+k, with k the number |
| 35418 |
% of digits of N (in base 10). Note that 1.2 version used P+10+k, for 1.2f I |
| 35419 |
% reduced to P+9+k. Also, k should be the number of digits of the number N of |
| 35420 |
% multiplications done, hence for n<=10000 we can take N=n/2, or N/3, or N/4. |
| 35421 |
% This is rounded above by numexpr and always an overestimate of the actual |
| 35422 |
% number of approximate multiplications done (the first ones are exact). |
| 35423 |
% (vérifier ce que je raconte, j'ai la flemme là). |
| 35424 |
% |
| 35425 |
% We then want ceil((P+k+n)/8). Using \numexpr rounding division |
| 35426 |
% (ARRRRRGGGHHHH), if m is a positive integer, ceil(m/8) can be computed as |
| 35427 |
% (m+3)/8. Thus with m=P+10+k, this gives Q<-(P+13+k)/8. The routine actually |
| 35428 |
% computes 8(Q-1) for use in \XINT_FL_fac_addzeros. |
| 35429 |
% |
| 35430 |
% With 1.2f the formula is m=P+9+k, Q<-(P+12+k)/8, and we use now 4=12-8 rather |
| 35431 |
% than the earlier 5=13-8. Whatever happens, the value computed in |
| 35432 |
% \XINT_FL_fac_increaseP is at least 8. There will always be an extra block. |
| 35433 |
% |
| 35434 |
% Note: with Digits:=32; Maple gives for 200!:$bgroup$obeylines$obeyspaces$ttfamily |
| 35435 |
% > factorial(200.); |
| 35436 |
% $indent 375 |
| 35437 |
% $indent 0.78865786736479050355236321393218 10 |
| 35438 |
% My 1.2f routine (and also 1.2) outputs: |
| 35439 |
% $indent 7.8865786736479050355236321393219e374 |
| 35440 |
% and this is the correct rounding because for 40 digits it computes |
| 35441 |
% $indent 7.886578673647905035523632139321850622951e374 |
| 35442 |
% $egroup |
| 35443 |
% Maple's result (contrarily to xint) is thus not the correct rounding but |
| 35444 |
% still it is less than 0.6 ulp wrong. |
| 35445 |
%\end{lverb} |
| 35446 |
% \begin{macrocode} |
| 35447 |
\def\XINT_FL_fac_vbig |
| 35448 |
{\expandafter\XINT_FL_fac_vbigloop_a |
| 35449 |
\the\numexpr \XINT_FL_fac_increaseP \xint_c_i }% |
| 35450 |
\def\XINT_FL_fac_big |
| 35451 |
{\expandafter\XINT_FL_fac_bigloop_a |
| 35452 |
\the\numexpr \XINT_FL_fac_increaseP \xint_c_ii }% |
| 35453 |
\def\XINT_FL_fac_med |
| 35454 |
{\expandafter\XINT_FL_fac_medloop_a |
| 35455 |
\the\numexpr \XINT_FL_fac_increaseP \xint_c_iii }% |
| 35456 |
\def\XINT_FL_fac_small |
| 35457 |
{\expandafter\XINT_FL_fac_smallloop_a |
| 35458 |
\the\numexpr \XINT_FL_fac_increaseP \xint_c_iv }% |
| 35459 |
\def\XINT_FL_fac_increaseP #1#2.#3#4% |
| 35460 |
{% |
| 35461 |
#2\expandafter.\the\numexpr\xint_c_viii*% |
| 35462 |
((\xint_c_iv+#4+\expandafter\XINT_FL_fac_countdigits |
| 35463 |
\the\numexpr #2/(#1*#3)\relax 87654321\Z)/\xint_c_viii).% |
| 35464 |
}% |
| 35465 |
\def\XINT_FL_fac_countdigits #1#2#3#4#5#6#7#8{\XINT_FL_fac_countdone }% |
| 35466 |
\def\XINT_FL_fac_countdone #1#2\Z {#1}% |
| 35467 |
\def\XINT_FL_fac_out #1;![#2]#3% |
| 35468 |
{#3{\romannumeral0\XINT_mul_out |
| 35469 |
#1;!1\R!1\R!1\R!1\R!% |
| 35470 |
1\R!1\R!1\R!1\R!\W [#2]}}% |
| 35471 |
\def\XINT_FL_fac_vbigloop_a #1.#2.% |
| 35472 |
{% |
| 35473 |
\XINT_FL_fac_bigloop_a \xint_c_x^iv.#2.% |
| 35474 |
{\expandafter\XINT_FL_fac_vbigloop_loop\the\numexpr 100010001\expandafter.% |
| 35475 |
\the\numexpr \xint_c_x^viii+#1.}% |
| 35476 |
}% |
| 35477 |
\def\XINT_FL_fac_vbigloop_loop #1.#2.% |
| 35478 |
{% |
| 35479 |
\ifnum #1>#2 \expandafter\XINT_FL_fac_loop_exit\fi |
| 35480 |
\expandafter\XINT_FL_fac_vbigloop_loop |
| 35481 |
\the\numexpr #1+\xint_c_i\expandafter.% |
| 35482 |
\the\numexpr #2\expandafter.\the\numexpr\XINT_FL_fac_mul #1!% |
| 35483 |
}% |
| 35484 |
\def\XINT_FL_fac_bigloop_a #1.% |
| 35485 |
{% |
| 35486 |
\expandafter\XINT_FL_fac_bigloop_b \the\numexpr |
| 35487 |
#1+\xint_c_i-\xint_c_ii*((#1-464)/\xint_c_ii).#1.% |
| 35488 |
}% |
| 35489 |
\def\XINT_FL_fac_bigloop_b #1.#2.#3.% |
| 35490 |
{% |
| 35491 |
\expandafter\XINT_FL_fac_medloop_a |
| 35492 |
\the\numexpr #1-\xint_c_i.#3.{\XINT_FL_fac_bigloop_loop #1.#2.}% |
| 35493 |
}% |
| 35494 |
\def\XINT_FL_fac_bigloop_loop #1.#2.% |
| 35495 |
{% |
| 35496 |
\ifnum #1>#2 \expandafter\XINT_FL_fac_loop_exit\fi |
| 35497 |
\expandafter\XINT_FL_fac_bigloop_loop |
| 35498 |
\the\numexpr #1+\xint_c_ii\expandafter.% |
| 35499 |
\the\numexpr #2\expandafter.\the\numexpr\XINT_FL_fac_bigloop_mul #1!% |
| 35500 |
}% |
| 35501 |
\def\XINT_FL_fac_bigloop_mul #1!% |
| 35502 |
{% |
| 35503 |
\expandafter\XINT_FL_fac_mul |
| 35504 |
\the\numexpr \xint_c_x^viii+#1*(#1+\xint_c_i)!% |
| 35505 |
}% |
| 35506 |
\def\XINT_FL_fac_medloop_a #1.% |
| 35507 |
{% |
| 35508 |
\expandafter\XINT_FL_fac_medloop_b |
| 35509 |
\the\numexpr #1+\xint_c_i-\xint_c_iii*((#1-100)/\xint_c_iii).#1.% |
| 35510 |
}% |
| 35511 |
\def\XINT_FL_fac_medloop_b #1.#2.#3.% |
| 35512 |
{% |
| 35513 |
\expandafter\XINT_FL_fac_smallloop_a |
| 35514 |
\the\numexpr #1-\xint_c_i.#3.{\XINT_FL_fac_medloop_loop #1.#2.}% |
| 35515 |
}% |
| 35516 |
\def\XINT_FL_fac_medloop_loop #1.#2.% |
| 35517 |
{% |
| 35518 |
\ifnum #1>#2 \expandafter\XINT_FL_fac_loop_exit\fi |
| 35519 |
\expandafter\XINT_FL_fac_medloop_loop |
| 35520 |
\the\numexpr #1+\xint_c_iii\expandafter.% |
| 35521 |
\the\numexpr #2\expandafter.\the\numexpr\XINT_FL_fac_medloop_mul #1!% |
| 35522 |
}% |
| 35523 |
\def\XINT_FL_fac_medloop_mul #1!% |
| 35524 |
{% |
| 35525 |
\expandafter\XINT_FL_fac_mul |
| 35526 |
\the\numexpr |
| 35527 |
\xint_c_x^viii+#1*(#1+\xint_c_i)*(#1+\xint_c_ii)!% |
| 35528 |
}% |
| 35529 |
\def\XINT_FL_fac_smallloop_a #1.% |
| 35530 |
{% |
| 35531 |
\csname |
| 35532 |
XINT_FL_fac_smallloop_\the\numexpr #1-\xint_c_iv*(#1/\xint_c_iv)\relax |
| 35533 |
\endcsname #1.% |
| 35534 |
}% |
| 35535 |
\expandafter\def\csname XINT_FL_fac_smallloop_1\endcsname #1.#2.% |
| 35536 |
{% |
| 35537 |
\XINT_FL_fac_addzeros #2.100000001!.{2.#1.}{#2}% |
| 35538 |
}% |
| 35539 |
\expandafter\def\csname XINT_FL_fac_smallloop_-2\endcsname #1.#2.% |
| 35540 |
{% |
| 35541 |
\XINT_FL_fac_addzeros #2.100000002!.{3.#1.}{#2}% |
| 35542 |
}% |
| 35543 |
\expandafter\def\csname XINT_FL_fac_smallloop_-1\endcsname #1.#2.% |
| 35544 |
{% |
| 35545 |
\XINT_FL_fac_addzeros #2.100000006!.{4.#1.}{#2}% |
| 35546 |
}% |
| 35547 |
\expandafter\def\csname XINT_FL_fac_smallloop_0\endcsname #1.#2.% |
| 35548 |
{% |
| 35549 |
\XINT_FL_fac_addzeros #2.100000024!.{5.#1.}{#2}% |
| 35550 |
}% |
| 35551 |
\def\XINT_FL_fac_addzeros #1.% |
| 35552 |
{% |
| 35553 |
\ifnum #1=\xint_c_viii \expandafter\XINT_FL_fac_addzeros_exit\fi |
| 35554 |
\expandafter\XINT_FL_fac_addzeros |
| 35555 |
\the\numexpr #1-\xint_c_viii.100000000!% |
| 35556 |
}% |
| 35557 |
% \end{macrocode} |
| 35558 |
%\begin{lverb} |
| 35559 |
% We will manipulate by successive *small* multiplications Q blocks |
| 35560 |
% 1<8d>!, terminated by 1;!. We need a custom small multiplication which |
| 35561 |
% tells us when it has create a new block, and the least significant one |
| 35562 |
% should be dropped. |
| 35563 |
%\end{lverb} |
| 35564 |
% \begin{macrocode} |
| 35565 |
\def\XINT_FL_fac_addzeros_exit #1.#2.#3#4{\XINT_FL_fac_smallloop_loop #3#21;![-#4]}% |
| 35566 |
\def\XINT_FL_fac_smallloop_loop #1.#2.% |
| 35567 |
{% |
| 35568 |
\ifnum #1>#2 \expandafter\XINT_FL_fac_loop_exit\fi |
| 35569 |
\expandafter\XINT_FL_fac_smallloop_loop |
| 35570 |
\the\numexpr #1+\xint_c_iv\expandafter.% |
| 35571 |
\the\numexpr #2\expandafter.\romannumeral0\XINT_FL_fac_smallloop_mul #1!% |
| 35572 |
}% |
| 35573 |
\def\XINT_FL_fac_smallloop_mul #1!% |
| 35574 |
{% |
| 35575 |
\expandafter\XINT_FL_fac_mul |
| 35576 |
\the\numexpr |
| 35577 |
\xint_c_x^viii+#1*(#1+\xint_c_i)*(#1+\xint_c_ii)*(#1+\xint_c_iii)!% |
| 35578 |
}%[[ |
| 35579 |
\def\XINT_FL_fac_loop_exit #1!#2]#3{#3#2]}% |
| 35580 |
\def\XINT_FL_fac_mul 1#1!% |
| 35581 |
{\expandafter\XINT_FL_fac_mul_a\the\numexpr\XINT_FL_fac_smallmul 10!{#1}}% |
| 35582 |
\def\XINT_FL_fac_mul_a #1-#2% |
| 35583 |
{% |
| 35584 |
\if#21\xint_afterfi{\expandafter\space\xint_gob_til_exclam}\else |
| 35585 |
\expandafter\space\fi #11;!% |
| 35586 |
}% |
| 35587 |
\def\XINT_FL_fac_minimulwc_a #1#2#3#4#5!#6#7#8#9% |
| 35588 |
{% |
| 35589 |
\XINT_FL_fac_minimulwc_b {#1#2#3#4}{#5}{#6#7#8#9}% |
| 35590 |
}% |
| 35591 |
\def\XINT_FL_fac_minimulwc_b #1#2#3#4!#5% |
| 35592 |
{% |
| 35593 |
\expandafter\XINT_FL_fac_minimulwc_c |
| 35594 |
\the\numexpr \xint_c_x^ix+#5+#2*#4!{{#1}{#2}{#3}{#4}}% |
| 35595 |
}% |
| 35596 |
\def\XINT_FL_fac_minimulwc_c 1#1#2#3#4#5#6!#7% |
| 35597 |
{% |
| 35598 |
\expandafter\XINT_FL_fac_minimulwc_d {#1#2#3#4#5}#7{#6}% |
| 35599 |
}% |
| 35600 |
\def\XINT_FL_fac_minimulwc_d #1#2#3#4#5% |
| 35601 |
{% |
| 35602 |
\expandafter\XINT_FL_fac_minimulwc_e |
| 35603 |
\the\numexpr \xint_c_x^ix+#1+#2*#5+#3*#4!{#2}{#4}% |
| 35604 |
}% |
| 35605 |
\def\XINT_FL_fac_minimulwc_e 1#1#2#3#4#5#6!#7#8#9% |
| 35606 |
{% |
| 35607 |
1#6#9\expandafter!% |
| 35608 |
\the\numexpr\expandafter\XINT_FL_fac_smallmul |
| 35609 |
\the\numexpr \xint_c_x^viii+#1#2#3#4#5+#7*#8!% |
| 35610 |
}% |
| 35611 |
\def\XINT_FL_fac_smallmul 1#1!#21#3!% |
| 35612 |
{% |
| 35613 |
\xint_gob_til_sc #3\XINT_FL_fac_smallmul_end;% |
| 35614 |
\XINT_FL_fac_minimulwc_a #2!#3!{#1}{#2}% |
| 35615 |
}% |
| 35616 |
% \end{macrocode} |
| 35617 |
%\begin{lverb} |
| 35618 |
% This is the crucial ending. I note that I used here an \ifnum test |
| 35619 |
% rather than the gob_til_eightzeroes thing. Actually for eight digits there |
| 35620 |
% is much less difference than for only four. |
| 35621 |
% |
| 35622 |
% The "carry" situation is marked by a final !-1 rather than !-2 for no-carry. |
| 35623 |
% (a \numexpr muste be stopped, and leaving a - as delimiter is good as it |
| 35624 |
% will not arise earlier.) |
| 35625 |
%\end{lverb} |
| 35626 |
% \begin{macrocode} |
| 35627 |
\def\XINT_FL_fac_smallmul_end;\XINT_FL_fac_minimulwc_a #1!;!#2#3[#4]% |
| 35628 |
{% |
| 35629 |
\ifnum #2=\xint_c_ |
| 35630 |
\expandafter\xint_firstoftwo\else |
| 35631 |
\expandafter\xint_secondoftwo |
| 35632 |
\fi |
| 35633 |
{-2\relax[#4]}% |
| 35634 |
{1#2\expandafter!\expandafter-\expandafter1\expandafter |
| 35635 |
[\the\numexpr #4+\xint_c_viii]}% |
| 35636 |
}% |
| 35637 |
% \end{macrocode} |
| 35638 |
% \subsection{\csh{xintFloatPFactorial}, \csh{XINTinFloatPFactorial}} |
| 35639 |
% \added[2015/11/29]{1.2f} |
| 35640 |
%\begin{lverb} |
| 35641 |
% Partial factorial pfactorial(a,b)=(a+1)...b, |
| 35642 |
% only for non-negative integers with a<=b<10^8. |
| 35643 |
%\end{lverb} |
| 35644 |
% \changed[2016/11/20]{1.2h} |
| 35645 |
%\begin{lverb} |
| 35646 |
% Now avoids raising \xintError:OutOfRangePFac if the |
| 35647 |
% condition 0<=a<=b<10^8 is violated. Same as for \xintiiPFactorial. |
| 35648 |
%\end{lverb} |
| 35649 |
% \changed{1.4e} |
| 35650 |
%\begin{lverb} |
| 35651 |
% 1.4e extends the precision in floating point context adding some overhead |
| 35652 |
% but well. |
| 35653 |
%\end{lverb} |
| 35654 |
% \begin{macrocode} |
| 35655 |
\def\xintFloatPFactorial {\romannumeral0\xintfloatpfactorial}% |
| 35656 |
\def\xintfloatpfactorial #1{\XINT_flpfac_chkopt \xintfloat #1\xint:}% |
| 35657 |
\def\XINTinFloatPFactorial{\romannumeral0\XINTinfloatpfactorial }% |
| 35658 |
\def\XINTinfloatpfactorial{\XINT_flpfac_opt_a\XINTdigits.\XINTinfloatS}% |
| 35659 |
\def\XINT_flpfac_chkopt #1#2% |
| 35660 |
{% |
| 35661 |
\ifx [#2\expandafter\XINT_flpfac_opt |
| 35662 |
\else\expandafter\XINT_flpfac_noopt |
| 35663 |
\fi |
| 35664 |
#1#2% |
| 35665 |
}% |
| 35666 |
\def\XINT_flpfac_noopt #1#2\xint:#3% |
| 35667 |
{% |
| 35668 |
\expandafter\XINT_FL_pfac_fork |
| 35669 |
\the\numexpr \xintNum{#2}\expandafter.% |
| 35670 |
\the\numexpr \xintNum{#3}.\xint_c_i{\XINTdigits}{#1[\XINTdigits]}% |
| 35671 |
}% |
| 35672 |
\def\XINT_flpfac_opt #1[\xint:#2]% |
| 35673 |
{% |
| 35674 |
\expandafter\XINT_flpfac_opt_a\the\numexpr #2.#1% |
| 35675 |
}% |
| 35676 |
\def\XINT_flpfac_opt_a #1.#2#3#4% |
| 35677 |
{% |
| 35678 |
\expandafter\XINT_FL_pfac_fork |
| 35679 |
\the\numexpr \xintNum{#3}\expandafter.% |
| 35680 |
\the\numexpr \xintNum{#4}.\xint_c_i{#1}{#2[#1]}% |
| 35681 |
}% |
| 35682 |
\def\XINT_FL_pfac_fork #1#2.#3#4.% |
| 35683 |
{% |
| 35684 |
\unless\ifnum #1#2<#3#4 \xint_dothis\XINT_FL_pfac_one\fi |
| 35685 |
\if-#3\xint_dothis\XINT_FL_pfac_neg \fi |
| 35686 |
\if-#1\xint_dothis\XINT_FL_pfac_zero\fi |
| 35687 |
\ifnum #3#4>\xint_c_x^viii_mone\xint_dothis\XINT_FL_pfac_outofrange\fi |
| 35688 |
\xint_orthat \XINT_FL_pfac_increaseP #1#2.#3#4.% |
| 35689 |
}% |
| 35690 |
\def\XINT_FL_pfac_outofrange #1.#2.#3#4#5% |
| 35691 |
{% |
| 35692 |
#5{\XINT_signalcondition{InvalidOperation} |
| 35693 |
{pFactorial with too large argument: #2 >= 10^8.}{}{ 0[0]}}% |
| 35694 |
}% |
| 35695 |
\def\XINT_FL_pfac_one #1.#2.#3#4#5{#5{1[0]}}% |
| 35696 |
\def\XINT_FL_pfac_zero #1.#2.#3#4#5{#5{0[0]}}% |
| 35697 |
\def\XINT_FL_pfac_neg -#1.-#2.% |
| 35698 |
{% |
| 35699 |
\ifnum #1>\xint_c_x^viii\xint_dothis\XINT_FL_pfac_outofrange\fi |
| 35700 |
\xint_orthat {% |
| 35701 |
\ifodd\numexpr#2-#1\relax\xint_afterfi{\expandafter-\romannumeral`&&@}\fi |
| 35702 |
\expandafter\XINT_FL_pfac_increaseP}% |
| 35703 |
\the\numexpr #2-\xint_c_i\expandafter.\the\numexpr#1-\xint_c_i.% |
| 35704 |
}% |
| 35705 |
% \end{macrocode} |
| 35706 |
%\begin{lverb} |
| 35707 |
% See the comments for \XINT_FL_pfac_increaseP. Case of b=a+1 should be |
| 35708 |
% filtered out perhaps. We only needed here to copy the \xintPFactorial macros and |
| 35709 |
% re-use \XINT_FL_fac_mul/\XINT_FL_fac_out. Had to modify a bit |
| 35710 |
% \XINT_FL_pfac_addzeroes. We can enter here directly with #3 equal to specify |
| 35711 |
% the precision (the calculated value before final rounding has a relative |
| 35712 |
% error less than #3.10^{-#4-1}), and #5 would hold the macro doing the final |
| 35713 |
% rounding (or truncating, if I make a FloatTrunc available) to a given number |
| 35714 |
% of digits, possibly not #4. By default the #3 is 1, but FloatBinomial calls |
| 35715 |
% it with #3=4. |
| 35716 |
%\end{lverb} |
| 35717 |
% \begin{macrocode} |
| 35718 |
\def\XINT_FL_pfac_increaseP #1.#2.#3#4% |
| 35719 |
{% |
| 35720 |
\expandafter\XINT_FL_pfac_a |
| 35721 |
\the\numexpr \xint_c_viii*((\xint_c_iv+#4+\expandafter |
| 35722 |
\XINT_FL_fac_countdigits\the\numexpr (#2-#1-\xint_c_i)% |
| 35723 |
/\ifnum #2>\xint_c_x^iv #3\else(#3*\xint_c_ii)\fi\relax |
| 35724 |
87654321\Z)/\xint_c_viii).#1.#2.% |
| 35725 |
}% |
| 35726 |
\def\XINT_FL_pfac_a #1.#2.#3.% |
| 35727 |
{% |
| 35728 |
\expandafter\XINT_FL_pfac_b\the\numexpr \xint_c_i+#2\expandafter.% |
| 35729 |
\the\numexpr#3\expandafter.% |
| 35730 |
\romannumeral0\XINT_FL_pfac_addzeroes #1.100000001!1;![-#1]% |
| 35731 |
}% |
| 35732 |
\def\XINT_FL_pfac_addzeroes #1.% |
| 35733 |
{% |
| 35734 |
\ifnum #1=\xint_c_viii \expandafter\XINT_FL_pfac_addzeroes_exit\fi |
| 35735 |
\expandafter\XINT_FL_pfac_addzeroes\the\numexpr #1-\xint_c_viii.100000000!% |
| 35736 |
}% |
| 35737 |
\def\XINT_FL_pfac_addzeroes_exit #1.{ }% |
| 35738 |
\def\XINT_FL_pfac_b #1.% |
| 35739 |
{% |
| 35740 |
\ifnum #1>9999 \xint_dothis\XINT_FL_pfac_vbigloop \fi |
| 35741 |
\ifnum #1>463 \xint_dothis\XINT_FL_pfac_bigloop \fi |
| 35742 |
\ifnum #1>98 \xint_dothis\XINT_FL_pfac_medloop \fi |
| 35743 |
\xint_orthat\XINT_FL_pfac_smallloop #1.% |
| 35744 |
}% |
| 35745 |
\def\XINT_FL_pfac_smallloop #1.#2.% |
| 35746 |
{% |
| 35747 |
\ifcase\numexpr #2-#1\relax |
| 35748 |
\expandafter\XINT_FL_pfac_end_ |
| 35749 |
\or \expandafter\XINT_FL_pfac_end_i |
| 35750 |
\or \expandafter\XINT_FL_pfac_end_ii |
| 35751 |
\or \expandafter\XINT_FL_pfac_end_iii |
| 35752 |
\else\expandafter\XINT_FL_pfac_smallloop_a |
| 35753 |
\fi #1.#2.% |
| 35754 |
}% |
| 35755 |
\def\XINT_FL_pfac_smallloop_a #1.#2.% |
| 35756 |
{% |
| 35757 |
\expandafter\XINT_FL_pfac_smallloop_b |
| 35758 |
\the\numexpr #1+\xint_c_iv\expandafter.% |
| 35759 |
\the\numexpr #2\expandafter.% |
| 35760 |
\romannumeral0\expandafter\XINT_FL_fac_mul |
| 35761 |
\the\numexpr \xint_c_x^viii+#1*(#1+\xint_c_i)*(#1+\xint_c_ii)*(#1+\xint_c_iii)!% |
| 35762 |
}% |
| 35763 |
\def\XINT_FL_pfac_smallloop_b #1.% |
| 35764 |
{% |
| 35765 |
\ifnum #1>98 \expandafter\XINT_FL_pfac_medloop \else |
| 35766 |
\expandafter\XINT_FL_pfac_smallloop \fi #1.% |
| 35767 |
}% |
| 35768 |
\def\XINT_FL_pfac_medloop #1.#2.% |
| 35769 |
{% |
| 35770 |
\ifcase\numexpr #2-#1\relax |
| 35771 |
\expandafter\XINT_FL_pfac_end_ |
| 35772 |
\or \expandafter\XINT_FL_pfac_end_i |
| 35773 |
\or \expandafter\XINT_FL_pfac_end_ii |
| 35774 |
\else\expandafter\XINT_FL_pfac_medloop_a |
| 35775 |
\fi #1.#2.% |
| 35776 |
}% |
| 35777 |
\def\XINT_FL_pfac_medloop_a #1.#2.% |
| 35778 |
{% |
| 35779 |
\expandafter\XINT_FL_pfac_medloop_b |
| 35780 |
\the\numexpr #1+\xint_c_iii\expandafter.% |
| 35781 |
\the\numexpr #2\expandafter.% |
| 35782 |
\romannumeral0\expandafter\XINT_FL_fac_mul |
| 35783 |
\the\numexpr \xint_c_x^viii+#1*(#1+\xint_c_i)*(#1+\xint_c_ii)!% |
| 35784 |
}% |
| 35785 |
\def\XINT_FL_pfac_medloop_b #1.% |
| 35786 |
{% |
| 35787 |
\ifnum #1>463 \expandafter\XINT_FL_pfac_bigloop \else |
| 35788 |
\expandafter\XINT_FL_pfac_medloop \fi #1.% |
| 35789 |
}% |
| 35790 |
\def\XINT_FL_pfac_bigloop #1.#2.% |
| 35791 |
{% |
| 35792 |
\ifcase\numexpr #2-#1\relax |
| 35793 |
\expandafter\XINT_FL_pfac_end_ |
| 35794 |
\or \expandafter\XINT_FL_pfac_end_i |
| 35795 |
\else\expandafter\XINT_FL_pfac_bigloop_a |
| 35796 |
\fi #1.#2.% |
| 35797 |
}% |
| 35798 |
\def\XINT_FL_pfac_bigloop_a #1.#2.% |
| 35799 |
{% |
| 35800 |
\expandafter\XINT_FL_pfac_bigloop_b |
| 35801 |
\the\numexpr #1+\xint_c_ii\expandafter.% |
| 35802 |
\the\numexpr #2\expandafter.% |
| 35803 |
\romannumeral0\expandafter\XINT_FL_fac_mul |
| 35804 |
\the\numexpr \xint_c_x^viii+#1*(#1+\xint_c_i)!% |
| 35805 |
}% |
| 35806 |
\def\XINT_FL_pfac_bigloop_b #1.% |
| 35807 |
{% |
| 35808 |
\ifnum #1>9999 \expandafter\XINT_FL_pfac_vbigloop \else |
| 35809 |
\expandafter\XINT_FL_pfac_bigloop \fi #1.% |
| 35810 |
}% |
| 35811 |
\def\XINT_FL_pfac_vbigloop #1.#2.% |
| 35812 |
{% |
| 35813 |
\ifnum #2=#1 |
| 35814 |
\expandafter\XINT_FL_pfac_end_ |
| 35815 |
\else\expandafter\XINT_FL_pfac_vbigloop_a |
| 35816 |
\fi #1.#2.% |
| 35817 |
}% |
| 35818 |
\def\XINT_FL_pfac_vbigloop_a #1.#2.% |
| 35819 |
{% |
| 35820 |
\expandafter\XINT_FL_pfac_vbigloop |
| 35821 |
\the\numexpr #1+\xint_c_i\expandafter.% |
| 35822 |
\the\numexpr #2\expandafter.% |
| 35823 |
\romannumeral0\expandafter\XINT_FL_fac_mul |
| 35824 |
\the\numexpr\xint_c_x^viii+#1!% |
| 35825 |
}% |
| 35826 |
\def\XINT_FL_pfac_end_iii #1.#2.% |
| 35827 |
{% |
| 35828 |
\expandafter\XINT_FL_fac_out |
| 35829 |
\romannumeral0\expandafter\XINT_FL_fac_mul |
| 35830 |
\the\numexpr \xint_c_x^viii+#1*(#1+\xint_c_i)*(#1+\xint_c_ii)*(#1+\xint_c_iii)!% |
| 35831 |
}% |
| 35832 |
\def\XINT_FL_pfac_end_ii #1.#2.% |
| 35833 |
{% |
| 35834 |
\expandafter\XINT_FL_fac_out |
| 35835 |
\romannumeral0\expandafter\XINT_FL_fac_mul |
| 35836 |
\the\numexpr \xint_c_x^viii+#1*(#1+\xint_c_i)*(#1+\xint_c_ii)!% |
| 35837 |
}% |
| 35838 |
\def\XINT_FL_pfac_end_i #1.#2.% |
| 35839 |
{% |
| 35840 |
\expandafter\XINT_FL_fac_out |
| 35841 |
\romannumeral0\expandafter\XINT_FL_fac_mul |
| 35842 |
\the\numexpr \xint_c_x^viii+#1*(#1+\xint_c_i)!% |
| 35843 |
}% |
| 35844 |
\def\XINT_FL_pfac_end_ #1.#2.% |
| 35845 |
{% |
| 35846 |
\expandafter\XINT_FL_fac_out |
| 35847 |
\romannumeral0\expandafter\XINT_FL_fac_mul |
| 35848 |
\the\numexpr \xint_c_x^viii+#1!% |
| 35849 |
}% |
| 35850 |
% \end{macrocode} |
| 35851 |
% \subsection{\csh{xintFloatBinomial}, \csh{XINTinFloatBinomial}} |
| 35852 |
% \added[2015/12/01]{1.2f} |
| 35853 |
%\begin{lverb} |
| 35854 |
% We compute binomial(x,y) as pfac(x-y,x)/y!, where the numerator |
| 35855 |
% and denominator are computed with a relative error at most 4.10^{-P-2}, then |
| 35856 |
% rounded (once I have a float truncation, I will use truncation rather) to |
| 35857 |
% P+3 digits, and finally the quotient is correctly rounded to P digits. This |
| 35858 |
% will guarantee that the exact value X differs from the computed one Y by at |
| 35859 |
% most 0.6 ulp(Y). |
| 35860 |
%\end{lverb} |
| 35861 |
% \changed[2016/11/19]{1.2h} |
| 35862 |
%\begin{lverb} |
| 35863 |
% As for \xintiiBinomial, hard to understand why last |
| 35864 |
% year I coded this to raise an error if y<0 or y>x ! The question of the |
| 35865 |
% Gamma function is for another occasion, here x and y must be (small) |
| 35866 |
% integers. |
| 35867 |
% |
| 35868 |
% 1.4e: same remarks as for factorial and partial factorial about added |
| 35869 |
% overhead due to extra guard digits. |
| 35870 |
%\end{lverb} |
| 35871 |
% \begin{macrocode} |
| 35872 |
\def\xintFloatBinomial {\romannumeral0\xintfloatbinomial}% |
| 35873 |
\def\xintfloatbinomial #1{\XINT_flbinom_chkopt \xintfloat #1\xint:}% |
| 35874 |
\def\XINTinFloatBinomial{\romannumeral0\XINTinfloatbinomial }% |
| 35875 |
\def\XINTinfloatbinomial{\XINT_flbinom_opt\XINTinfloatS[\xint:\XINTdigits]}% |
| 35876 |
\def\XINT_flbinom_chkopt #1#2% |
| 35877 |
{% |
| 35878 |
\ifx [#2\expandafter\XINT_flbinom_opt |
| 35879 |
\else\expandafter\XINT_flbinom_noopt |
| 35880 |
\fi #1#2% |
| 35881 |
}% |
| 35882 |
\def\XINT_flbinom_noopt #1#2\xint:#3% |
| 35883 |
{% |
| 35884 |
\expandafter\XINT_FL_binom_a |
| 35885 |
\the\numexpr\xintNum{#2}\expandafter.\the\numexpr\xintNum{#3}.\XINTdigits.#1% |
| 35886 |
}% |
| 35887 |
\def\XINT_flbinom_opt #1[\xint:#2]#3#4% |
| 35888 |
{% |
| 35889 |
\expandafter\XINT_FL_binom_a |
| 35890 |
\the\numexpr\xintNum{#3}\expandafter.\the\numexpr\xintNum{#4}\expandafter.% |
| 35891 |
\the\numexpr #2.#1% |
| 35892 |
}% |
| 35893 |
\def\XINT_FL_binom_a #1.#2.% |
| 35894 |
{% |
| 35895 |
\expandafter\XINT_FL_binom_fork \the\numexpr #1-#2.#2.#1.% |
| 35896 |
}% |
| 35897 |
\def\XINT_FL_binom_fork #1#2.#3#4.#5#6.% |
| 35898 |
{% |
| 35899 |
\if-#5\xint_dothis \XINT_FL_binom_neg\fi |
| 35900 |
\if-#1\xint_dothis \XINT_FL_binom_zero\fi |
| 35901 |
\if-#3\xint_dothis \XINT_FL_binom_zero\fi |
| 35902 |
\if0#1\xint_dothis \XINT_FL_binom_one\fi |
| 35903 |
\if0#3\xint_dothis \XINT_FL_binom_one\fi |
| 35904 |
\ifnum #5#6>\xint_c_x^viii_mone \xint_dothis\XINT_FL_binom_toobig\fi |
| 35905 |
\ifnum #1#2>#3#4 \xint_dothis\XINT_FL_binom_ab \fi |
| 35906 |
\xint_orthat\XINT_FL_binom_aa |
| 35907 |
#1#2.#3#4.#5#6.% |
| 35908 |
}% |
| 35909 |
\def\XINT_FL_binom_neg #1.#2.#3.#4.#5% |
| 35910 |
{% |
| 35911 |
#5[#4]{\XINT_signalcondition{InvalidOperation} |
| 35912 |
{Binomial with negative argument: #3.}{}{ 0[0]}}% |
| 35913 |
}% |
| 35914 |
\def\XINT_FL_binom_toobig #1.#2.#3.#4.#5% |
| 35915 |
{% |
| 35916 |
#5[#4]{\XINT_signalcondition{InvalidOperation} |
| 35917 |
{Binomial with too large argument: #3 >= 10^8.}{}{ 0[0]}}% |
| 35918 |
}% |
| 35919 |
\def\XINT_FL_binom_one #1.#2.#3.#4.#5{#5[#4]{1[0]}}% |
| 35920 |
\def\XINT_FL_binom_zero #1.#2.#3.#4.#5{#5[#4]{0[0]}}% |
| 35921 |
\def\XINT_FL_binom_aa #1.#2.#3.#4.#5% |
| 35922 |
{% |
| 35923 |
#5[#4]{\xintDiv{\XINT_FL_pfac_increaseP |
| 35924 |
#2.#3.\xint_c_iv{#4+\xint_c_i}{\XINTinfloat[#4+\xint_c_iii]}}% |
| 35925 |
{\XINT_FL_fac_fork_b |
| 35926 |
#1.\xint_c_iv{#4+\xint_c_i}\XINT_FL_fac_out{\XINTinfloat[#4+\xint_c_iii]}}}% |
| 35927 |
}% |
| 35928 |
\def\XINT_FL_binom_ab #1.#2.#3.#4.#5% |
| 35929 |
{% |
| 35930 |
#5[#4]{\xintDiv{\XINT_FL_pfac_increaseP |
| 35931 |
#1.#3.\xint_c_iv{#4+\xint_c_i}{\XINTinfloat[#4+\xint_c_iii]}}% |
| 35932 |
{\XINT_FL_fac_fork_b |
| 35933 |
#2.\xint_c_iv{#4+\xint_c_i}\XINT_FL_fac_out{\XINTinfloat[#4+\xint_c_iii]}}}% |
| 35934 |
}% |
| 35935 |
% \end{macrocode} |
| 35936 |
% \subsection{\csh{xintFloatSqrt}, \csh{XINTinFloatSqrt}} |
| 35937 |
% \added{1.08} |
| 35938 |
% \changed{1.2f} |
| 35939 |
%\begin{lverb} |
| 35940 |
% |
| 35941 |
% The float version was developed at the same time as the integer one and even |
| 35942 |
% a bit earlier. As a result the integer variant had some sub-optimal parts. |
| 35943 |
% Anyway, for 1.2f I have rewritten the integer variant, and the float variant |
| 35944 |
% delegates all preparatory wrok for it until the last step. In particular the |
| 35945 |
% very low precisions are not penalized anymore from doing computations for at |
| 35946 |
% least 17 or 18 digits. Both the large and small precisions give quite |
| 35947 |
% shorter computation times. |
| 35948 |
% |
| 35949 |
% Also, after examining more closely the achieved precision I decided to |
| 35950 |
% extend the float version in order for it to obtain the correct rounding (for |
| 35951 |
% inputs already of at most P digits with P the precision) of the theoretical |
| 35952 |
% exact value. |
| 35953 |
% |
| 35954 |
% Beyond about 500 digits of precision the efficiency decreases swiftly, |
| 35955 |
% as is the case generally speaking with xintcore/xint/xintfrac arithmetic |
| 35956 |
% macros. |
| 35957 |
% |
| 35958 |
% Final note: with 1.2f the input is always first rounded to P significant |
| 35959 |
% places. |
| 35960 |
%\end{lverb} |
| 35961 |
% \begin{macrocode} |
| 35962 |
\def\xintFloatSqrt {\romannumeral0\xintfloatsqrt}% |
| 35963 |
\def\xintfloatsqrt #1{\XINT_flsqrt_chkopt \xintfloat #1\xint:}% |
| 35964 |
\def\XINTinFloatSqrt{\romannumeral0\XINTinfloatsqrt}% |
| 35965 |
\def\XINTinfloatsqrt[#1]{\expandafter\XINT_flsqrt_opt_a\the\numexpr#1.\XINTinfloatS}% |
| 35966 |
\def\XINTinFloatSqrtdigits{\romannumeral0\XINT_flsqrt_opt_a\XINTdigits.\XINTinfloatS}% |
| 35967 |
\def\XINT_flsqrt_chkopt #1#2% |
| 35968 |
{% |
| 35969 |
\ifx [#2\expandafter\XINT_flsqrt_opt |
| 35970 |
\else\expandafter\XINT_flsqrt_noopt |
| 35971 |
\fi #1#2% |
| 35972 |
}% |
| 35973 |
\def\XINT_flsqrt_noopt #1#2\xint:% |
| 35974 |
{% |
| 35975 |
\expandafter\XINT_FL_sqrt_a |
| 35976 |
\romannumeral0\XINTinfloat[\XINTdigits]{#2}\XINTdigits.#1% |
| 35977 |
}% |
| 35978 |
\def\XINT_flsqrt_opt #1[\xint:#2]%#3% |
| 35979 |
{% |
| 35980 |
\expandafter\XINT_flsqrt_opt_a\the\numexpr #2.#1% |
| 35981 |
}% |
| 35982 |
\def\XINT_flsqrt_opt_a #1.#2#3% |
| 35983 |
{% |
| 35984 |
\expandafter\XINT_FL_sqrt_a\romannumeral0\XINTinfloat[#1]{#3}#1.#2% |
| 35985 |
}% |
| 35986 |
\def\XINT_FL_sqrt_a #1% |
| 35987 |
{% |
| 35988 |
\xint_UDzerominusfork |
| 35989 |
#1-\XINT_FL_sqrt_iszero |
| 35990 |
0#1\XINT_FL_sqrt_isneg |
| 35991 |
0-{\XINT_FL_sqrt_pos #1}% |
| 35992 |
\krof |
| 35993 |
}%[ |
| 35994 |
\def\XINT_FL_sqrt_iszero #1]#2.#3{#3[#2]{0[0]}}% |
| 35995 |
\def\XINT_FL_sqrt_isneg #1]#2.#3% |
| 35996 |
{% |
| 35997 |
#3[#2]{\XINT_signalcondition{InvalidOperation} |
| 35998 |
{Square root of negative: -#1].}{}{ 0[0]}}% |
| 35999 |
}% |
| 36000 |
\def\XINT_FL_sqrt_pos #1[#2]#3.% |
| 36001 |
{% |
| 36002 |
\expandafter\XINT_flsqrt |
| 36003 |
\the\numexpr #3\ifodd #2 \xint_dothis {+\xint_c_iii.(#2+\xint_c_i).0}\fi |
| 36004 |
\xint_orthat {+\xint_c_ii.#2.{}}#100.#3.% |
| 36005 |
}% |
| 36006 |
\def\XINT_flsqrt #1.#2.% |
| 36007 |
{% |
| 36008 |
\expandafter\XINT_flsqrt_a |
| 36009 |
\the\numexpr #2/\xint_c_ii-(#1-\xint_c_i)/\xint_c_ii.#1.% |
| 36010 |
}% |
| 36011 |
\def\XINT_flsqrt_a #1.#2.#3#4.#5.% |
| 36012 |
{% |
| 36013 |
\expandafter\XINT_flsqrt_b |
| 36014 |
\the\numexpr (#2-\xint_c_i)/\xint_c_ii\expandafter.% |
| 36015 |
\romannumeral0\XINT_sqrt_start #2.#4#3.#5.#2.#4#3.#5.#1.% |
| 36016 |
}% |
| 36017 |
% \end{macrocode} |
| 36018 |
% |
| 36019 |
% \begin{macrocode} |
| 36020 |
\def\XINT_flsqrt_b #1.#2#3% |
| 36021 |
{% |
| 36022 |
\expandafter\XINT_flsqrt_c |
| 36023 |
\romannumeral0\xintiisub |
| 36024 |
{\XINT_dsx_addzeros {#1}#2;}% |
| 36025 |
{\xintiiDivRound{\XINT_dsx_addzeros {#1}#3;}% |
| 36026 |
{\XINT_dbl#2\xint_bye2345678\xint_bye*\xint_c_ii\relax}}.% |
| 36027 |
}% |
| 36028 |
\def\XINT_flsqrt_c #1.#2.% |
| 36029 |
{% |
| 36030 |
\expandafter\XINT_flsqrt_d |
| 36031 |
\romannumeral0\XINT_split_fromleft#2.#1\xint_bye2345678\xint_bye..% |
| 36032 |
}% |
| 36033 |
\def\XINT_flsqrt_d #1.#2#3.% |
| 36034 |
{% |
| 36035 |
\ifnum #2=\xint_c_v |
| 36036 |
\expandafter\XINT_flsqrt_f\else\expandafter\XINT_flsqrt_finish\fi |
| 36037 |
#2#3.#1.% |
| 36038 |
}% |
| 36039 |
\def\XINT_flsqrt_finish #1#2.#3.#4.#5.#6.#7.#8{#8[#6]{#3#1[#7]}}% |
| 36040 |
\def\XINT_flsqrt_f 5#1.% |
| 36041 |
{\expandafter\XINT_flsqrt_g\romannumeral0\xintinum{#1}\relax.}% |
| 36042 |
\def\XINT_flsqrt_g #1#2#3.{\if\relax#2\xint_dothis{\XINT_flsqrt_h #1}\fi |
| 36043 |
\xint_orthat{\XINT_flsqrt_finish 5.}}% |
| 36044 |
\def\XINT_flsqrt_h #1{\ifnum #1<\xint_c_iii\xint_dothis{\XINT_flsqrt_again}\fi |
| 36045 |
\xint_orthat{\XINT_flsqrt_finish 5.}}% |
| 36046 |
\def\XINT_flsqrt_again #1.#2.% |
| 36047 |
{% |
| 36048 |
\expandafter\XINT_flsqrt_again_a\the\numexpr #2+\xint_c_viii.% |
| 36049 |
}% |
| 36050 |
\def\XINT_flsqrt_again_a #1.#2.#3.% |
| 36051 |
{% |
| 36052 |
\expandafter\XINT_flsqrt_b |
| 36053 |
\the\numexpr (#1-\xint_c_i)/\xint_c_ii\expandafter.% |
| 36054 |
\romannumeral0\XINT_sqrt_start #1.#200000000.#3.% |
| 36055 |
#1.#200000000.#3.% |
| 36056 |
}% |
| 36057 |
% \end{macrocode} |
| 36058 |
% \subsection{\csh{xintFloatE}, \csh{XINTinFloatE}} |
| 36059 |
% \added{1.07} |
| 36060 |
%\begin{lverb} |
| 36061 |
% The fraction is the first argument contrarily to \xintTrunc and |
| 36062 |
% \xintRound. |
| 36063 |
%\end{lverb} |
| 36064 |
%\begin{lverb} |
| 36065 |
% Attention to \XINTinFloatE$empty: it is for use by $xintexprnameimp. |
| 36066 |
% With input 0 it produces on output an 0[N], not 0[0]. |
| 36067 |
%\end{lverb} |
| 36068 |
% \begin{macrocode} |
| 36069 |
\def\xintFloatE {\romannumeral0\xintfloate }% |
| 36070 |
\def\xintfloate #1{\XINT_floate_chkopt #1\xint:}% |
| 36071 |
\def\XINT_floate_chkopt #1% |
| 36072 |
{% |
| 36073 |
\ifx [#1\expandafter\XINT_floate_opt |
| 36074 |
\else\expandafter\XINT_floate_noopt |
| 36075 |
\fi #1% |
| 36076 |
}% |
| 36077 |
\def\XINT_floate_noopt #1\xint:% |
| 36078 |
{% |
| 36079 |
\expandafter\XINT_floate_post |
| 36080 |
\romannumeral0\XINTinfloat[\XINTdigits]{#1}\XINTdigits.% |
| 36081 |
}% |
| 36082 |
\def\XINT_floate_opt [\xint:#1]% |
| 36083 |
{% |
| 36084 |
\expandafter\XINT_floate_opt_a\the\numexpr #1.% |
| 36085 |
}% |
| 36086 |
\def\XINT_floate_opt_a #1.#2% |
| 36087 |
{% |
| 36088 |
\expandafter\XINT_floate_post |
| 36089 |
\romannumeral0\XINTinfloat[#1]{#2}#1.% |
| 36090 |
}% |
| 36091 |
\def\XINT_floate_post #1% |
| 36092 |
{% |
| 36093 |
\xint_UDzerominusfork |
| 36094 |
#1-\XINT_floate_zero |
| 36095 |
0#1\XINT_floate_neg |
| 36096 |
0-\XINT_floate_pos |
| 36097 |
\krof #1% |
| 36098 |
}%[ |
| 36099 |
\def\XINT_floate_zero #1]#2.#3{ 0.e0}% |
| 36100 |
\def\XINT_floate_neg-{\expandafter-\romannumeral0\XINT_floate_pos}% |
| 36101 |
\def\XINT_floate_pos #1#2[#3]#4.#5% |
| 36102 |
{% |
| 36103 |
\expandafter\XINT_float_pos_done\the\numexpr#3+#4+#5-\xint_c_i.#1.#2;% |
| 36104 |
}% |
| 36105 |
\def\XINTinFloatE {\romannumeral0\XINTinfloate }% |
| 36106 |
\def\XINTinfloate |
| 36107 |
{\expandafter\XINT_infloate\romannumeral0\XINTinfloat[\XINTdigits]}% |
| 36108 |
\def\XINT_infloate #1[#2]#3% |
| 36109 |
{\expandafter\XINT_infloate_end\the\numexpr #3+#2.{#1}}% |
| 36110 |
\def\XINT_infloate_end #1.#2{ #2[#1]}% |
| 36111 |
% \end{macrocode} |
| 36112 |
% \subsection{\csh{XINTinFloatMod}} |
| 36113 |
% \added{1.1} |
| 36114 |
%\begin{lverb} |
| 36115 |
% Pour emploi dans xintexpr. Code shortened at 1.2p. |
| 36116 |
%\end{lverb} |
| 36117 |
% \begin{macrocode} |
| 36118 |
\def\XINTinFloatMod {\romannumeral0\XINTinfloatmod [\XINTdigits]}% |
| 36119 |
\def\XINTinfloatmod [#1]#2#3% |
| 36120 |
{% |
| 36121 |
\XINTinfloat[#1]{\xintMod |
| 36122 |
{\romannumeral0\XINTinfloat[#1]{#2}}% |
| 36123 |
{\romannumeral0\XINTinfloat[#1]{#3}}}% |
| 36124 |
}% |
| 36125 |
% \end{macrocode} |
| 36126 |
% \subsection{\csh{XINTinFloatDivFloor}} |
| 36127 |
% \added{1.2p} |
| 36128 |
%\begin{lverb} |
| 36129 |
% Formerly // and /: in \xintfloatexpr used \xintDivFloor and |
| 36130 |
% \xintMod, hence did not round their operands to float precision beforehand. |
| 36131 |
%\end{lverb} |
| 36132 |
% \begin{macrocode} |
| 36133 |
\def\XINTinFloatDivFloor {\romannumeral0\XINTinfloatdivfloor [\XINTdigits]}% |
| 36134 |
\def\XINTinfloatdivfloor [#1]#2#3% |
| 36135 |
{% |
| 36136 |
\xintdivfloor |
| 36137 |
{\romannumeral0\XINTinfloat[#1]{#2}}% |
| 36138 |
{\romannumeral0\XINTinfloat[#1]{#3}}% |
| 36139 |
}% |
| 36140 |
% \end{macrocode} |
| 36141 |
% \subsection{\csh{XINTinFloatDivMod}} |
| 36142 |
% \added{1.2p} |
| 36143 |
%\begin{lverb} |
| 36144 |
% Pour emploi dans xintexpr, donc je ne prends pas la peine de |
| 36145 |
% faire l'expansion du modulo, qui se produira dans le \csname. |
| 36146 |
% |
| 36147 |
% Hésitation sur le quotient, faut-il l'arrondir immédiatement ? |
| 36148 |
% Finalement non, le produire comme un integer. |
| 36149 |
% |
| 36150 |
% Breaking change at 1.4 as output format is not comma separated anymore. |
| 36151 |
% Attention also that it uses \expanded. |
| 36152 |
% |
| 36153 |
% No time now at the time of completion of the big 1.4 rewrite of xintexpr |
| 36154 |
% to test whether code efficiency here can be improved to expand the second |
| 36155 |
% item of output. |
| 36156 |
%\end{lverb} |
| 36157 |
% \begin{macrocode} |
| 36158 |
\def\XINTinFloatDivMod {\romannumeral0\XINTinfloatdivmod [\XINTdigits]}% |
| 36159 |
\def\XINTinfloatdivmod [#1]#2#3% |
| 36160 |
{% |
| 36161 |
\expandafter\XINT_infloatdivmod |
| 36162 |
\romannumeral0\xintdivmod |
| 36163 |
{\romannumeral0\XINTinfloat[#1]{#2}}% |
| 36164 |
{\romannumeral0\XINTinfloat[#1]{#3}}% |
| 36165 |
{#1}% |
| 36166 |
}% |
| 36167 |
\def\XINT_infloatdivmod #1#2#3{\expanded{{#1}{\XINTinFloat[#3]{#2}}}}% |
| 36168 |
% \end{macrocode} |
| 36169 |
% \subsection{\csh{xintifFloatInt}} |
| 36170 |
% \added{1.3a} |
| 36171 |
%\begin{lverb} |
| 36172 |
% For ifint() function in \xintfloatexpr. |
| 36173 |
%\end{lverb} |
| 36174 |
% \begin{macrocode} |
| 36175 |
\def\xintifFloatInt {\romannumeral0\xintiffloatint}% |
| 36176 |
\def\xintiffloatint #1{\expandafter\XINT_iffloatint |
| 36177 |
\romannumeral0\xintrez{\XINTinFloatS[\XINTdigits]{#1}}}% |
| 36178 |
\def\XINT_iffloatint #1#2/1[#3]% |
| 36179 |
{% |
| 36180 |
\if 0#1\xint_dothis\xint_stop_atfirstoftwo\fi |
| 36181 |
\ifnum#3<\xint_c_\xint_dothis\xint_stop_atsecondoftwo\fi |
| 36182 |
\xint_orthat\xint_stop_atfirstoftwo |
| 36183 |
}% |
| 36184 |
% \end{macrocode} |
| 36185 |
% \subsection{\csh{xintFloatIsInt}} |
| 36186 |
% \added{1.3d} |
| 36187 |
%\begin{lverb} |
| 36188 |
% For isint() function in \xintfloatexpr. |
| 36189 |
%\end{lverb} |
| 36190 |
% \begin{macrocode} |
| 36191 |
\def\xintFloatIsInt {\romannumeral0\xintfloatisint}% |
| 36192 |
\def\xintfloatisint #1{\expandafter\XINT_iffloatint |
| 36193 |
\romannumeral0\xintrez{\XINTinFloatS[\XINTdigits]{#1}}10}% |
| 36194 |
% \end{macrocode} |
| 36195 |
% \subsection{\csh{xintFloatIntType}} |
| 36196 |
% \added{1.4e} |
| 36197 |
%\begin{lverb} |
| 36198 |
% For fractional powers. Expands to \xint_c_mone if argument is not an |
| 36199 |
% integer, to \xint_c_ if it is an even integer and to \xint_c_i if it is an |
| 36200 |
% odd integer. |
| 36201 |
%\end{lverb} |
| 36202 |
% \begin{macrocode} |
| 36203 |
\def\xintFloatIntType {\romannumeral`&&@\xintfloatinttype}% |
| 36204 |
\def\xintfloatinttype #1% |
| 36205 |
{% |
| 36206 |
\expandafter\XINT_floatinttype |
| 36207 |
\romannumeral0\xintrez{\XINTinFloatS[\XINTdigits]{#1}}% |
| 36208 |
}% |
| 36209 |
\def\XINT_floatinttype #1#2/1[#3]% |
| 36210 |
{% |
| 36211 |
\if 0#1\xint_dothis\xint_c_\fi |
| 36212 |
\ifnum#3<\xint_c_\xint_dothis\xint_c_mone\fi |
| 36213 |
\ifnum#3>\xint_c_\xint_dothis\xint_c_\fi |
| 36214 |
\ifodd\xintLDg{#1#2} \xint_dothis\xint_c_i\fi |
| 36215 |
\xint_orthat\xint_c_ |
| 36216 |
}% |
| 36217 |
% \end{macrocode} |
| 36218 |
% \subsection{\csh{XINTinFloatdigits}, \csh{XINTinFloatSdigits}} |
| 36219 |
% \begin{macrocode} |
| 36220 |
\def\XINTinFloatdigits {\XINTinFloat [\XINTdigits]}% |
| 36221 |
\def\XINTinFloatSdigits{\XINTinFloatS[\XINTdigits]}% |
| 36222 |
% \end{macrocode} |
| 36223 |
% \subsection{(WIP) \csh{XINTinRandomFloatS}, \csh{XINTinRandomFloatSdigits}} |
| 36224 |
% \added{1.3b} |
| 36225 |
%\begin{lverb} |
| 36226 |
% Support for random() function. |
| 36227 |
% |
| 36228 |
% Thus as it is a priori only for xintexpr usage, it expands inside \csname |
| 36229 |
% context, but as we need to get rid of initial zeros we use \xintRandomDigits |
| 36230 |
% not \xintXRandomDigits (\expanded would have a use case here). |
| 36231 |
% |
| 36232 |
% And anyway as we want to be able to use random() in |
| 36233 |
% \xintdeffunc/\xintNewExpr, it is good to have f-expandable macros, so we add |
| 36234 |
% the small overhead to make it f-expandable. |
| 36235 |
% |
| 36236 |
% We don't have to be very efficient in removing leading zeroes, as there is |
| 36237 |
% only 10$% |
| 36238 |
% chance for each successive one. Besides we use (current) internal storage |
| 36239 |
% format of the type A[N], where A is not required to be with \xintDigits |
| 36240 |
% digits, so N will simply be -\xintDigits and needs no adjustment. |
| 36241 |
% |
| 36242 |
% In case we use in future with #1 something else than \xintDigits we do |
| 36243 |
% the 0-(#1) construct. |
| 36244 |
% |
| 36245 |
% I had some qualms about doing a random float like this which means that |
| 36246 |
% when there are leading zeros in the random digits the (virtual) mantissa |
| 36247 |
% ends up with trailing zeros. That did not feel right but I checked random() |
| 36248 |
% in Python (which of course uses radix 2), and indeed this is what happens |
| 36249 |
% there. |
| 36250 |
%\end{lverb} |
| 36251 |
% \begin{macrocode} |
| 36252 |
\def\XINTinRandomFloatS{\romannumeral0\XINTinrandomfloatS}% |
| 36253 |
\def\XINTinRandomFloatSdigits{\XINTinRandomFloatS[\XINTdigits]}% |
| 36254 |
\def\XINTinrandomfloatS[#1]% |
| 36255 |
{% |
| 36256 |
\expandafter\XINT_inrandomfloatS\the\numexpr\xint_c_-(#1)\xint: |
| 36257 |
}% |
| 36258 |
\def\XINT_inrandomfloatS-#1\xint: |
| 36259 |
{% |
| 36260 |
\expandafter\XINT_inrandomfloatS_a |
| 36261 |
\romannumeral0\xintrandomdigits{#1}[-#1]% |
| 36262 |
}% |
| 36263 |
% \end{macrocode} |
| 36264 |
%\begin{lverb} |
| 36265 |
% We add one macro to handle a tiny bit faster 90$% |
| 36266 |
% of cases, after all |
| 36267 |
% we also use one extra macro for the completely improbable all 0 case. |
| 36268 |
%\end{lverb} |
| 36269 |
% \begin{macrocode} |
| 36270 |
\def\XINT_inrandomfloatS_a#1% |
| 36271 |
{% |
| 36272 |
\if#10\xint_dothis{\XINT_inrandomfloatS_b}\fi |
| 36273 |
\xint_orthat{ #1}% |
| 36274 |
}%[ |
| 36275 |
\def\XINT_inrandomfloatS_b#1% |
| 36276 |
{% |
| 36277 |
\if#1[\xint_dothis{\XINT_inrandomfloatS_zero}\fi% ] |
| 36278 |
\if#10\xint_dothis{\XINT_inrandomfloatS_b}\fi |
| 36279 |
\xint_orthat{ #1}% |
| 36280 |
}%[ |
| 36281 |
\def\XINT_inrandomfloatS_zero#1]{ 0[0]}% |
| 36282 |
% \end{macrocode} |
| 36283 |
% \subsection{(WIP) \csh{XINTinRandomFloatSixteen}} |
| 36284 |
% \added{1.3b} |
| 36285 |
%\begin{lverb} |
| 36286 |
% Support for qrand() function. |
| 36287 |
%\end{lverb} |
| 36288 |
% \begin{macrocode} |
| 36289 |
\def\XINTinRandomFloatSixteen% |
| 36290 |
{% |
| 36291 |
\romannumeral0\expandafter\XINT_inrandomfloatS_a |
| 36292 |
\romannumeral`&&@\expandafter\XINT_eightrandomdigits |
| 36293 |
\romannumeral`&&@\XINT_eightrandomdigits[-16]% |
| 36294 |
}% |
| 36295 |
\let\XINTinFloatMaxof\XINT_Maxof |
| 36296 |
\let\XINTinFloatMinof\XINT_Minof |
| 36297 |
\let\XINTinFloatSum\XINT_Sum |
| 36298 |
\let\XINTinFloatPrd\XINT_Prd |
| 36299 |
\XINTrestorecatcodesendinput% |
| 36300 |
% \end{macrocode} |
| 36301 |
% \StoreCodelineNo {xintfrac} |
| 36302 |
% \cleardoublepage\let\xintfracnameUp\undefined |
| 36303 |
%\gardesactifs |
| 36304 |
%\let</xintfrac>\relax |
| 36305 |
%\let<*xintseries>\gardesinactifs |
| 36306 |
%</xintfrac>^^A--------------------------------------------------- |
| 36307 |
%<*xintseries>^^A------------------------------------------------- |
| 36308 |
%^^A -*- coding: utf-8; mode: doctex; fill-column: 78; sentence-end-double-space: t; eval: (auto-fill-mode -1); fill-paragraph-function: nil; -*- |
| 36309 |
% \clearpage\csname xintseriesnameUp\endcsname |
| 36310 |
% \let\MakePrivateLetters\xintMakePrivateLetters |
| 36311 |
% \section{Package \xintseriesnameimp implementation} |
| 36312 |
% \RaisedLabel{sec:seriesimp} |
| 36313 |
% |
| 36314 |
% \localtableofcontents |
| 36315 |
% |
| 36316 |
% The commenting is currently (\xintdocdate) very sparse. |
| 36317 |
% |
| 36318 |
% \subsection{Catcodes, \protect\eTeX{} and reload detection} |
| 36319 |
% |
| 36320 |
% The code for reload detection was initially copied from \textsc{Heiko |
| 36321 |
% Oberdiek}'s packages, then modified. |
| 36322 |
% |
| 36323 |
% The method for catcodes was also initially directly inspired by these |
| 36324 |
% packages. |
| 36325 |
% |
| 36326 |
% \begin{macrocode} |
| 36327 |
\begingroup\catcode61\catcode48\catcode32=10\relax% |
| 36328 |
\catcode13=5 % ^^M |
| 36329 |
\endlinechar=13 % |
| 36330 |
\catcode123=1 % { |
| 36331 |
\catcode125=2 % } |
| 36332 |
\catcode64=11 % @ |
| 36333 |
\catcode44=12 % , |
| 36334 |
\catcode46=12 % . |
| 36335 |
\catcode58=12 % : |
| 36336 |
\catcode94=7 % ^ |
| 36337 |
\def\empty{}\def\space{ }\newlinechar10 |
| 36338 |
\def\z{\endgroup}% |
| 36339 |
\expandafter\let\expandafter\x\csname [email protected]\endcsname |
| 36340 |
\expandafter\let\expandafter\w\csname [email protected]\endcsname |
| 36341 |
\expandafter\ifx\csname numexpr\endcsname\relax |
| 36342 |
\expandafter\ifx\csname PackageWarningNoLine\endcsname\relax |
| 36343 |
\immediate\write128{^^JPackage xintseries Warning:^^J% |
| 36344 |
\space\space\space\space |
| 36345 |
\numexpr not available, aborting input.^^J}% |
| 36346 |
\else |
| 36347 |
\PackageWarningNoLine{xintseries}{\numexpr not available, aborting input}% |
| 36348 |
\fi |
| 36349 |
\def\z{\endgroup\endinput}% |
| 36350 |
\else |
| 36351 |
\ifx\x\relax % plain-TeX, first loading of xintseries.sty |
| 36352 |
\ifx\w\relax % but xintfrac.sty not yet loaded. |
| 36353 |
\def\z{\endgroup\input xintfrac.sty\relax}% |
| 36354 |
\fi |
| 36355 |
\else |
| 36356 |
\ifx\x\empty % LaTeX, first loading, |
| 36357 |
% variable is initialized, but \ProvidesPackage not yet seen |
| 36358 |
\ifx\w\relax % xintfrac.sty not yet loaded. |
| 36359 |
\def\z{\endgroup\RequirePackage{xintfrac}}% |
| 36360 |
\fi |
| 36361 |
\else |
| 36362 |
\def\z{\endgroup\endinput}% xintseries already loaded. |
| 36363 |
\fi |
| 36364 |
\fi |
| 36365 |
\fi |
| 36366 |
\z% |
| 36367 |
\XINTsetupcatcodes% defined in xintkernel.sty |
| 36368 |
% \end{macrocode} |
| 36369 |
% \subsection{Package identification} |
| 36370 |
% \begin{macrocode} |
| 36371 |
\XINT_providespackage |
| 36372 |
\ProvidesPackage{xintseries}% |
| 36373 |
[2025/09/06 v1.4o Expandable partial sums with xint package (JFB)]% |
| 36374 |
% \end{macrocode} |
| 36375 |
% \subsection{\csh{xintSeries}} |
| 36376 |
% \begin{macrocode} |
| 36377 |
\def\xintSeries {\romannumeral0\xintseries }% |
| 36378 |
\def\xintseries #1#2% |
| 36379 |
{% |
| 36380 |
\expandafter\XINT_series\expandafter |
| 36381 |
{\the\numexpr #1\expandafter}\expandafter{\the\numexpr #2}% |
| 36382 |
}% |
| 36383 |
\def\XINT_series #1#2#3% |
| 36384 |
{% |
| 36385 |
\ifnum #2<#1 |
| 36386 |
\xint_afterfi { 0/1[0]}% |
| 36387 |
\else |
| 36388 |
\xint_afterfi {\XINT_series_loop {#1}{0}{#2}{#3}}% |
| 36389 |
\fi |
| 36390 |
}% |
| 36391 |
\def\XINT_series_loop #1#2#3#4% |
| 36392 |
{% |
| 36393 |
\ifnum #3>#1 \else \XINT_series_exit \fi |
| 36394 |
\expandafter\XINT_series_loop\expandafter |
| 36395 |
{\the\numexpr #1+1\expandafter }\expandafter |
| 36396 |
{\romannumeral0\xintadd {#2}{#4{#1}}}% |
| 36397 |
{#3}{#4}% |
| 36398 |
}% |
| 36399 |
\def\XINT_series_exit \fi #1#2#3#4#5#6#7#8% |
| 36400 |
{% |
| 36401 |
\fi\xint_gobble_ii #6% |
| 36402 |
}% |
| 36403 |
% \end{macrocode} |
| 36404 |
% \subsection{\csh{xintiSeries}} |
| 36405 |
% \begin{macrocode} |
| 36406 |
\def\xintiSeries {\romannumeral0\xintiseries }% |
| 36407 |
\def\xintiseries #1#2% |
| 36408 |
{% |
| 36409 |
\expandafter\XINT_iseries\expandafter |
| 36410 |
{\the\numexpr #1\expandafter}\expandafter{\the\numexpr #2}% |
| 36411 |
}% |
| 36412 |
\def\XINT_iseries #1#2#3% |
| 36413 |
{% |
| 36414 |
\ifnum #2<#1 |
| 36415 |
\xint_afterfi { 0}% |
| 36416 |
\else |
| 36417 |
\xint_afterfi {\XINT_iseries_loop {#1}{0}{#2}{#3}}% |
| 36418 |
\fi |
| 36419 |
}% |
| 36420 |
\def\XINT_iseries_loop #1#2#3#4% |
| 36421 |
{% |
| 36422 |
\ifnum #3>#1 \else \XINT_iseries_exit \fi |
| 36423 |
\expandafter\XINT_iseries_loop\expandafter |
| 36424 |
{\the\numexpr #1+1\expandafter }\expandafter |
| 36425 |
{\romannumeral0\xintiiadd {#2}{#4{#1}}}% |
| 36426 |
{#3}{#4}% |
| 36427 |
}% |
| 36428 |
\def\XINT_iseries_exit \fi #1#2#3#4#5#6#7#8% |
| 36429 |
{% |
| 36430 |
\fi\xint_gobble_ii #6% |
| 36431 |
}% |
| 36432 |
% \end{macrocode} |
| 36433 |
% \subsection{\csh{xintPowerSeries}} |
| 36434 |
%\begin{lverb} |
| 36435 |
% The 1.03 version was very lame and created a build-up of denominators. |
| 36436 |
% (this was at a time \xintAdd always multiplied denominators, by the way) |
| 36437 |
% The Horner scheme for polynomial evaluation is used in 1.04, this |
| 36438 |
% cures the denominator problem and drastically improves the efficiency |
| 36439 |
% of the macro. |
| 36440 |
% Modified in 1.06 to give the indices first to a \numexpr rather than expanding |
| 36441 |
% twice. I just use \the\numexpr and maintain the previous code after that. |
| 36442 |
% 1.08a adds the forgotten optimization following that previous change. |
| 36443 |
%\end{lverb} |
| 36444 |
% \begin{macrocode} |
| 36445 |
\def\xintPowerSeries {\romannumeral0\xintpowerseries }% |
| 36446 |
\def\xintpowerseries #1#2% |
| 36447 |
{% |
| 36448 |
\expandafter\XINT_powseries\expandafter |
| 36449 |
{\the\numexpr #1\expandafter}\expandafter{\the\numexpr #2}% |
| 36450 |
}% |
| 36451 |
\def\XINT_powseries #1#2#3#4% |
| 36452 |
{% |
| 36453 |
\ifnum #2<#1 |
| 36454 |
\xint_afterfi { 0/1[0]}% |
| 36455 |
\else |
| 36456 |
\xint_afterfi |
| 36457 |
{\XINT_powseries_loop_i {#3{#2}}{#1}{#2}{#3}{#4}}% |
| 36458 |
\fi |
| 36459 |
}% |
| 36460 |
\def\XINT_powseries_loop_i #1#2#3#4#5% |
| 36461 |
{% |
| 36462 |
\ifnum #3>#2 \else\XINT_powseries_exit_i\fi |
| 36463 |
\expandafter\XINT_powseries_loop_ii\expandafter |
| 36464 |
{\the\numexpr #3-1\expandafter}\expandafter |
| 36465 |
{\romannumeral0\xintmul {#1}{#5}}{#2}{#4}{#5}% |
| 36466 |
}% |
| 36467 |
\def\XINT_powseries_loop_ii #1#2#3#4% |
| 36468 |
{% |
| 36469 |
\expandafter\XINT_powseries_loop_i\expandafter |
| 36470 |
{\romannumeral0\xintadd {#4{#1}}{#2}}{#3}{#1}{#4}% |
| 36471 |
}% |
| 36472 |
\def\XINT_powseries_exit_i\fi #1#2#3#4#5#6#7#8#9% |
| 36473 |
{% |
| 36474 |
\fi \XINT_powseries_exit_ii #6{#7}% |
| 36475 |
}% |
| 36476 |
\def\XINT_powseries_exit_ii #1#2#3#4#5#6% |
| 36477 |
{% |
| 36478 |
\xintmul{\xintPow {#5}{#6}}{#4}% |
| 36479 |
}% |
| 36480 |
% \end{macrocode} |
| 36481 |
% \subsection{\csh{xintPowerSeriesX}} |
| 36482 |
%\begin{lverb} |
| 36483 |
% Same as \xintPowerSeries except for the initial expansion of the x parameter. |
| 36484 |
% Modified in 1.06 to give the indices first to a \numexpr rather than expanding |
| 36485 |
% twice. I just use \the\numexpr and maintain the previous code after that. |
| 36486 |
% 1.08a adds the forgotten optimization following that previous change. |
| 36487 |
%\end{lverb} |
| 36488 |
% \begin{macrocode} |
| 36489 |
\def\xintPowerSeriesX {\romannumeral0\xintpowerseriesx }% |
| 36490 |
\def\xintpowerseriesx #1#2% |
| 36491 |
{% |
| 36492 |
\expandafter\XINT_powseriesx\expandafter |
| 36493 |
{\the\numexpr #1\expandafter}\expandafter{\the\numexpr #2}% |
| 36494 |
}% |
| 36495 |
\def\XINT_powseriesx #1#2#3#4% |
| 36496 |
{% |
| 36497 |
\ifnum #2<#1 |
| 36498 |
\xint_afterfi { 0/1[0]}% |
| 36499 |
\else |
| 36500 |
\xint_afterfi |
| 36501 |
{\expandafter\XINT_powseriesx_pre\expandafter |
| 36502 |
{\romannumeral`&&@#4}{#1}{#2}{#3}% |
| 36503 |
}% |
| 36504 |
\fi |
| 36505 |
}% |
| 36506 |
\def\XINT_powseriesx_pre #1#2#3#4% |
| 36507 |
{% |
| 36508 |
\XINT_powseries_loop_i {#4{#3}}{#2}{#3}{#4}{#1}% |
| 36509 |
}% |
| 36510 |
% \end{macrocode} |
| 36511 |
% \subsection{\csh{xintRationalSeries}} |
| 36512 |
%\begin{lverb} |
| 36513 |
% This computes F(a)+...+F(b) on the basis of the value of F(a) and the |
| 36514 |
% ratios F(n)/F(n-1). As in \xintPowerSeries we use an iterative scheme which |
| 36515 |
% has the great advantage to avoid denominator build-up. This makes exact |
| 36516 |
% computations possible with exponential type series, which would be completely |
| 36517 |
% inaccessible to \xintSeries. |
| 36518 |
% #1=a, #2=b, #3=F(a), #4=ratio function |
| 36519 |
% Modified in 1.06 to give the indices first to a \numexpr rather than expanding |
| 36520 |
% twice. I just use \the\numexpr and maintain the previous code after that. |
| 36521 |
% 1.08a adds the forgotten optimization following that previous change. |
| 36522 |
%\end{lverb} |
| 36523 |
% \begin{macrocode} |
| 36524 |
\def\xintRationalSeries {\romannumeral0\xintratseries }% |
| 36525 |
\def\xintratseries #1#2% |
| 36526 |
{% |
| 36527 |
\expandafter\XINT_ratseries\expandafter |
| 36528 |
{\the\numexpr #1\expandafter}\expandafter{\the\numexpr #2}% |
| 36529 |
}% |
| 36530 |
\def\XINT_ratseries #1#2#3#4% |
| 36531 |
{% |
| 36532 |
\ifnum #2<#1 |
| 36533 |
\xint_afterfi { 0/1[0]}% |
| 36534 |
\else |
| 36535 |
\xint_afterfi |
| 36536 |
{\XINT_ratseries_loop {#2}{1}{#1}{#4}{#3}}% |
| 36537 |
\fi |
| 36538 |
}% |
| 36539 |
\def\XINT_ratseries_loop #1#2#3#4% |
| 36540 |
{% |
| 36541 |
\ifnum #1>#3 \else\XINT_ratseries_exit_i\fi |
| 36542 |
\expandafter\XINT_ratseries_loop\expandafter |
| 36543 |
{\the\numexpr #1-1\expandafter}\expandafter |
| 36544 |
{\romannumeral0\xintadd {1}{\xintMul {#2}{#4{#1}}}}{#3}{#4}% |
| 36545 |
}% |
| 36546 |
\def\XINT_ratseries_exit_i\fi #1#2#3#4#5#6#7#8% |
| 36547 |
{% |
| 36548 |
\fi \XINT_ratseries_exit_ii #6% |
| 36549 |
}% |
| 36550 |
\def\XINT_ratseries_exit_ii #1#2#3#4#5% |
| 36551 |
{% |
| 36552 |
\XINT_ratseries_exit_iii #5% |
| 36553 |
}% |
| 36554 |
\def\XINT_ratseries_exit_iii #1#2#3#4% |
| 36555 |
{% |
| 36556 |
\xintmul{#2}{#4}% |
| 36557 |
}% |
| 36558 |
% \end{macrocode} |
| 36559 |
% \subsection{\csh{xintRationalSeriesX}} |
| 36560 |
%\begin{lverb} |
| 36561 |
% a,b,initial,ratiofunction,x$\ |
| 36562 |
% This computes F(a,x)+...+F(b,x) on the basis of the value of F(a,x) and the |
| 36563 |
% ratios F(n,x)/F(n-1,x). The argument x is first expanded and it is the value |
| 36564 |
% resulting from this which is used then throughout. The initial term F(a,x) |
| 36565 |
% must be defined as one-parameter macro which will be given x. |
| 36566 |
% Modified in 1.06 to give the indices first to a \numexpr rather than expanding |
| 36567 |
% twice. I just use \the\numexpr and maintain the previous code after that. |
| 36568 |
% 1.08a adds the forgotten optimization following that previous change. |
| 36569 |
%\end{lverb} |
| 36570 |
% \begin{macrocode} |
| 36571 |
\def\xintRationalSeriesX {\romannumeral0\xintratseriesx }% |
| 36572 |
\def\xintratseriesx #1#2% |
| 36573 |
{% |
| 36574 |
\expandafter\XINT_ratseriesx\expandafter |
| 36575 |
{\the\numexpr #1\expandafter}\expandafter{\the\numexpr #2}% |
| 36576 |
}% |
| 36577 |
\def\XINT_ratseriesx #1#2#3#4#5% |
| 36578 |
{% |
| 36579 |
\ifnum #2<#1 |
| 36580 |
\xint_afterfi { 0/1[0]}% |
| 36581 |
\else |
| 36582 |
\xint_afterfi |
| 36583 |
{\expandafter\XINT_ratseriesx_pre\expandafter |
| 36584 |
{\romannumeral`&&@#5}{#2}{#1}{#4}{#3}% |
| 36585 |
}% |
| 36586 |
\fi |
| 36587 |
}% |
| 36588 |
\def\XINT_ratseriesx_pre #1#2#3#4#5% |
| 36589 |
{% |
| 36590 |
\XINT_ratseries_loop {#2}{1}{#3}{#4{#1}}{#5{#1}}% |
| 36591 |
}% |
| 36592 |
% \end{macrocode} |
| 36593 |
% \subsection{\csh{xintFxPtPowerSeries}} |
| 36594 |
%\begin{lverb} |
| 36595 |
% I am not two happy with this piece of code. Will make it more economical |
| 36596 |
% another day. |
| 36597 |
% Modified in 1.06 to give the indices first to a \numexpr rather than expanding |
| 36598 |
% twice. I just use \the\numexpr and maintain the previous code after that. |
| 36599 |
% 1.08a: forgot last time some optimization from the change to \numexpr. |
| 36600 |
%\end{lverb} |
| 36601 |
% \begin{macrocode} |
| 36602 |
\def\xintFxPtPowerSeries {\romannumeral0\xintfxptpowerseries }% |
| 36603 |
\def\xintfxptpowerseries #1#2% |
| 36604 |
{% |
| 36605 |
\expandafter\XINT_fppowseries\expandafter |
| 36606 |
{\the\numexpr #1\expandafter}\expandafter{\the\numexpr #2}% |
| 36607 |
}% |
| 36608 |
\def\XINT_fppowseries #1#2#3#4#5% |
| 36609 |
{% |
| 36610 |
\ifnum #2<#1 |
| 36611 |
\xint_afterfi { 0}% |
| 36612 |
\else |
| 36613 |
\xint_afterfi |
| 36614 |
{\expandafter\XINT_fppowseries_loop_pre\expandafter |
| 36615 |
{\romannumeral0\xinttrunc {#5}{\xintPow {#4}{#1}}}% |
| 36616 |
{#1}{#4}{#2}{#3}{#5}% |
| 36617 |
}% |
| 36618 |
\fi |
| 36619 |
}% |
| 36620 |
\def\XINT_fppowseries_loop_pre #1#2#3#4#5#6% |
| 36621 |
{% |
| 36622 |
\ifnum #4>#2 \else\XINT_fppowseries_dont_i \fi |
| 36623 |
\expandafter\XINT_fppowseries_loop_i\expandafter |
| 36624 |
{\the\numexpr #2+\xint_c_i\expandafter}\expandafter |
| 36625 |
{\romannumeral0\xintitrunc {#6}{\xintMul {#5{#2}}{#1}}}% |
| 36626 |
{#1}{#3}{#4}{#5}{#6}% |
| 36627 |
}% |
| 36628 |
\def\XINT_fppowseries_dont_i \fi\expandafter\XINT_fppowseries_loop_i |
| 36629 |
{\fi \expandafter\XINT_fppowseries_dont_ii }% |
| 36630 |
\def\XINT_fppowseries_dont_ii #1#2#3#4#5#6#7{\xinttrunc {#7}{#2[-#7]}}% |
| 36631 |
\def\XINT_fppowseries_loop_i #1#2#3#4#5#6#7% |
| 36632 |
{% |
| 36633 |
\ifnum #5>#1 \else \XINT_fppowseries_exit_i \fi |
| 36634 |
\expandafter\XINT_fppowseries_loop_ii\expandafter |
| 36635 |
{\romannumeral0\xinttrunc {#7}{\xintMul {#3}{#4}}}% |
| 36636 |
{#1}{#4}{#2}{#5}{#6}{#7}% |
| 36637 |
}% |
| 36638 |
\def\XINT_fppowseries_loop_ii #1#2#3#4#5#6#7% |
| 36639 |
{% |
| 36640 |
\expandafter\XINT_fppowseries_loop_i\expandafter |
| 36641 |
{\the\numexpr #2+\xint_c_i\expandafter}\expandafter |
| 36642 |
{\romannumeral0\xintiiadd {#4}{\xintiTrunc {#7}{\xintMul {#6{#2}}{#1}}}}% |
| 36643 |
{#1}{#3}{#5}{#6}{#7}% |
| 36644 |
}% |
| 36645 |
\def\XINT_fppowseries_exit_i\fi\expandafter\XINT_fppowseries_loop_ii |
| 36646 |
{\fi \expandafter\XINT_fppowseries_exit_ii }% |
| 36647 |
\def\XINT_fppowseries_exit_ii #1#2#3#4#5#6#7% |
| 36648 |
{% |
| 36649 |
\xinttrunc {#7} |
| 36650 |
{\xintiiadd {#4}{\xintiTrunc {#7}{\xintMul {#6{#2}}{#1}}}[-#7]}% |
| 36651 |
}% |
| 36652 |
% \end{macrocode} |
| 36653 |
% \subsection{\csh{xintFxPtPowerSeriesX}} |
| 36654 |
%\begin{lverb} |
| 36655 |
% a,b,coeff,x,D$\ |
| 36656 |
% Modified in 1.06 to give the indices first to a \numexpr rather than expanding |
| 36657 |
% twice. I just use \the\numexpr and maintain the previous code after that. |
| 36658 |
% 1.08a adds the forgotten optimization following that previous change. |
| 36659 |
%\end{lverb} |
| 36660 |
% \begin{macrocode} |
| 36661 |
\def\xintFxPtPowerSeriesX {\romannumeral0\xintfxptpowerseriesx }% |
| 36662 |
\def\xintfxptpowerseriesx #1#2% |
| 36663 |
{% |
| 36664 |
\expandafter\XINT_fppowseriesx\expandafter |
| 36665 |
{\the\numexpr #1\expandafter}\expandafter{\the\numexpr #2}% |
| 36666 |
}% |
| 36667 |
\def\XINT_fppowseriesx #1#2#3#4#5% |
| 36668 |
{% |
| 36669 |
\ifnum #2<#1 |
| 36670 |
\xint_afterfi { 0}% |
| 36671 |
\else |
| 36672 |
\xint_afterfi |
| 36673 |
{\expandafter \XINT_fppowseriesx_pre \expandafter |
| 36674 |
{\romannumeral`&&@#4}{#1}{#2}{#3}{#5}% |
| 36675 |
}% |
| 36676 |
\fi |
| 36677 |
}% |
| 36678 |
\def\XINT_fppowseriesx_pre #1#2#3#4#5% |
| 36679 |
{% |
| 36680 |
\expandafter\XINT_fppowseries_loop_pre\expandafter |
| 36681 |
{\romannumeral0\xinttrunc {#5}{\xintPow {#1}{#2}}}% |
| 36682 |
{#2}{#1}{#3}{#4}{#5}% |
| 36683 |
}% |
| 36684 |
% \end{macrocode} |
| 36685 |
% \subsection{\csh{xintFloatPowerSeries}} |
| 36686 |
%\begin{lverb} |
| 36687 |
% 1.08a. I still have to re-visit \xintFxPtPowerSeries; temporarily I |
| 36688 |
% just adapted the code to the case of floats. |
| 36689 |
% |
| 36690 |
% Usage of new names |
| 36691 |
% \XINTinfloatpow_wopt \XINTinfloatmul_wopt, \XINTinfloatadd_wopt to track |
| 36692 |
% xintfrac.sty changes at 1.4e. |
| 36693 |
%\end{lverb} |
| 36694 |
% \begin{macrocode} |
| 36695 |
\def\xintFloatPowerSeries {\romannumeral0\xintfloatpowerseries }% |
| 36696 |
\def\xintfloatpowerseries #1{\XINT_flpowseries_chkopt #1\xint:}% |
| 36697 |
\def\XINT_flpowseries_chkopt #1% |
| 36698 |
{% |
| 36699 |
\ifx [#1\expandafter\XINT_flpowseries_opt |
| 36700 |
\else\expandafter\XINT_flpowseries_noopt |
| 36701 |
\fi |
| 36702 |
#1% |
| 36703 |
}% |
| 36704 |
\def\XINT_flpowseries_noopt #1\xint:#2% |
| 36705 |
{% |
| 36706 |
\expandafter\XINT_flpowseries\expandafter |
| 36707 |
{\the\numexpr #1\expandafter}\expandafter |
| 36708 |
{\the\numexpr #2}\XINTdigits |
| 36709 |
}% |
| 36710 |
\def\XINT_flpowseries_opt [\xint:#1]#2#3% |
| 36711 |
{% |
| 36712 |
\expandafter\XINT_flpowseries\expandafter |
| 36713 |
{\the\numexpr #2\expandafter}\expandafter |
| 36714 |
{\the\numexpr #3\expandafter}{\the\numexpr #1}% |
| 36715 |
}% |
| 36716 |
\def\XINT_flpowseries #1#2#3#4#5% |
| 36717 |
{% |
| 36718 |
\ifnum #2<#1 |
| 36719 |
\xint_afterfi { 0.e0}% |
| 36720 |
\else |
| 36721 |
\xint_afterfi |
| 36722 |
{\expandafter\XINT_flpowseries_loop_pre\expandafter |
| 36723 |
{\romannumeral0\XINTinfloatpow_wopt[#3]{#5}{#1}}% |
| 36724 |
{#1}{#5}{#2}{#4}{#3}% |
| 36725 |
}% |
| 36726 |
\fi |
| 36727 |
}% |
| 36728 |
\def\XINT_flpowseries_loop_pre #1#2#3#4#5#6% |
| 36729 |
{% |
| 36730 |
\ifnum #4>#2 \else\XINT_flpowseries_dont_i \fi |
| 36731 |
\expandafter\XINT_flpowseries_loop_i\expandafter |
| 36732 |
{\the\numexpr #2+\xint_c_i\expandafter}\expandafter |
| 36733 |
{\romannumeral0\XINTinfloatmul_wopt[#6]{#5{#2}}{#1}}% |
| 36734 |
{#1}{#3}{#4}{#5}{#6}% |
| 36735 |
}% |
| 36736 |
\def\XINT_flpowseries_dont_i \fi\expandafter\XINT_flpowseries_loop_i |
| 36737 |
{\fi \expandafter\XINT_flpowseries_dont_ii }% |
| 36738 |
\def\XINT_flpowseries_dont_ii #1#2#3#4#5#6#7{\xintfloat [#7]{#2}}% |
| 36739 |
\def\XINT_flpowseries_loop_i #1#2#3#4#5#6#7% |
| 36740 |
{% |
| 36741 |
\ifnum #5>#1 \else \XINT_flpowseries_exit_i \fi |
| 36742 |
\expandafter\XINT_flpowseries_loop_ii\expandafter |
| 36743 |
{\romannumeral0\XINTinfloatmul_wopt[#7]{#3}{#4}}% |
| 36744 |
{#1}{#4}{#2}{#5}{#6}{#7}% |
| 36745 |
}% |
| 36746 |
\def\XINT_flpowseries_loop_ii #1#2#3#4#5#6#7% |
| 36747 |
{% |
| 36748 |
\expandafter\XINT_flpowseries_loop_i\expandafter |
| 36749 |
{\the\numexpr #2+\xint_c_i\expandafter}\expandafter |
| 36750 |
{\romannumeral0\XINTinfloatadd_wopt[#7]{#4}% |
| 36751 |
{\XINTinfloatmul_wopt[#7]{#6{#2}}{#1}}}% |
| 36752 |
{#1}{#3}{#5}{#6}{#7}% |
| 36753 |
}% |
| 36754 |
\def\XINT_flpowseries_exit_i\fi\expandafter\XINT_flpowseries_loop_ii |
| 36755 |
{\fi \expandafter\XINT_flpowseries_exit_ii }% |
| 36756 |
\def\XINT_flpowseries_exit_ii #1#2#3#4#5#6#7% |
| 36757 |
{% |
| 36758 |
\xintfloatadd[#7]{#4}{\XINTinfloatmul_wopt[#7]{#6{#2}}{#1}}% |
| 36759 |
}% |
| 36760 |
% \end{macrocode} |
| 36761 |
% \subsection{\csh{xintFloatPowerSeriesX}} |
| 36762 |
%\begin{lverb} |
| 36763 |
% 1.08a |
| 36764 |
% |
| 36765 |
% See \xintFloatPowerSeries for 1.4e comments. |
| 36766 |
%\end{lverb} |
| 36767 |
% \begin{macrocode} |
| 36768 |
\def\xintFloatPowerSeriesX {\romannumeral0\xintfloatpowerseriesx }% |
| 36769 |
\def\xintfloatpowerseriesx #1{\XINT_flpowseriesx_chkopt #1\xint:}% |
| 36770 |
\def\XINT_flpowseriesx_chkopt #1% |
| 36771 |
{% |
| 36772 |
\ifx [#1\expandafter\XINT_flpowseriesx_opt |
| 36773 |
\else\expandafter\XINT_flpowseriesx_noopt |
| 36774 |
\fi |
| 36775 |
#1% |
| 36776 |
}% |
| 36777 |
\def\XINT_flpowseriesx_noopt #1\xint:#2% |
| 36778 |
{% |
| 36779 |
\expandafter\XINT_flpowseriesx\expandafter |
| 36780 |
{\the\numexpr #1\expandafter}\expandafter |
| 36781 |
{\the\numexpr #2}\XINTdigits |
| 36782 |
}% |
| 36783 |
\def\XINT_flpowseriesx_opt [\xint:#1]#2#3% |
| 36784 |
{% |
| 36785 |
\expandafter\XINT_flpowseriesx\expandafter |
| 36786 |
{\the\numexpr #2\expandafter}\expandafter |
| 36787 |
{\the\numexpr #3\expandafter}{\the\numexpr #1}% |
| 36788 |
}% |
| 36789 |
\def\XINT_flpowseriesx #1#2#3#4#5% |
| 36790 |
{% |
| 36791 |
\ifnum #2<#1 |
| 36792 |
\xint_afterfi { 0.e0}% |
| 36793 |
\else |
| 36794 |
\xint_afterfi |
| 36795 |
{\expandafter \XINT_flpowseriesx_pre \expandafter |
| 36796 |
{\romannumeral`&&@#5}{#1}{#2}{#4}{#3}% |
| 36797 |
}% |
| 36798 |
\fi |
| 36799 |
}% |
| 36800 |
\def\XINT_flpowseriesx_pre #1#2#3#4#5% |
| 36801 |
{% |
| 36802 |
\expandafter\XINT_flpowseries_loop_pre\expandafter |
| 36803 |
{\romannumeral0\XINTinfloatpow_wopt[#5]{#1}{#2}}% |
| 36804 |
{#2}{#1}{#3}{#4}{#5}% |
| 36805 |
}% |
| 36806 |
\XINTrestorecatcodesendinput% |
| 36807 |
% \end{macrocode} |
| 36808 |
% \StoreCodelineNo {xintseries} |
| 36809 |
% \cleardoublepage\let\xintseriesnameUp\undefined |
| 36810 |
%\gardesactifs |
| 36811 |
%\let</xintseries>\relax |
| 36812 |
%\let<*xintcfrac>\gardesinactifs |
| 36813 |
%</xintseries>^^A------------------------------------------------- |
| 36814 |
%<*xintcfrac>^^A-------------------------------------------------- |
| 36815 |
%^^A -*- coding: utf-8; mode: doctex; fill-column: 78; sentence-end-double-space: t; eval: (auto-fill-mode -1); fill-paragraph-function: nil; -*- |
| 36816 |
% \clearpage\csname xintcfracnameUp\endcsname |
| 36817 |
% \let\MakePrivateLetters\xintMakePrivateLetters |
| 36818 |
% \section{Package \xintcfracnameimp implementation} |
| 36819 |
% \RaisedLabel{sec:cfracimp} |
| 36820 |
% |
| 36821 |
% \localtableofcontents |
| 36822 |
% |
| 36823 |
% The commenting is currently (\xintdocdate) very sparse. Release |1.09m| |
| 36824 |
% (|2014/02/26|) has modified a few things: |\xintFtoCs| and |
| 36825 |
% |\xintCntoCs| insert spaces after the commas, |\xintCstoF| and |
| 36826 |
% |\xintCstoCv| authorize spaces in the input also before the commas, |
| 36827 |
% |\xintCntoCs| does not brace the produced coefficients, new macros |
| 36828 |
% |\xintFtoC|, |\xintCtoF|, |\xintCtoCv|, |\xintFGtoC|, and |
| 36829 |
% |\xintGGCFrac|. |
| 36830 |
% |
| 36831 |
% The macros |\xintCstoF| and |\xintCstoCv| use \xinttoolsnameimp's |
| 36832 |
% \csbxint{CSVtoList}. Formerly, it was up to user to load \xinttoolsnameimp |
| 36833 |
% to enable these macros. Starting at |1.4n| the loading is automatic. |
| 36834 |
% |
| 36835 |
% \subsection{Catcodes, \protect\eTeX{} and reload detection} |
| 36836 |
% |
| 36837 |
% The code for reload detection was initially copied from \textsc{Heiko |
| 36838 |
% Oberdiek}'s packages, then modified. |
| 36839 |
% |
| 36840 |
% The method for catcodes was also initially directly inspired by these |
| 36841 |
% packages. |
| 36842 |
% |
| 36843 |
% \begin{macrocode} |
| 36844 |
\begingroup\catcode61\catcode48\catcode32=10\relax% |
| 36845 |
\catcode13=5 % ^^M |
| 36846 |
\endlinechar=13 % |
| 36847 |
\catcode123=1 % { |
| 36848 |
\catcode125=2 % } |
| 36849 |
\catcode64=11 % @ |
| 36850 |
\catcode44=12 % , |
| 36851 |
\catcode46=12 % . |
| 36852 |
\catcode58=12 % : |
| 36853 |
\catcode94=7 % ^ |
| 36854 |
\def\empty{}\def\space{ }\newlinechar10 |
| 36855 |
\def\z{\endgroup}% |
| 36856 |
\expandafter\let\expandafter\x\csname [email protected]\endcsname |
| 36857 |
\expandafter\let\expandafter\w\csname [email protected]\endcsname |
| 36858 |
\expandafter\let\expandafter\t\csname [email protected]\endcsname |
| 36859 |
\expandafter\ifx\csname numexpr\endcsname\relax |
| 36860 |
\expandafter\ifx\csname PackageWarningNoLine\endcsname\relax |
| 36861 |
\immediate\write128{^^JPackage xintcfrac Warning:^^J% |
| 36862 |
\space\space\space\space |
| 36863 |
\numexpr not available, aborting input.^^J}% |
| 36864 |
\else |
| 36865 |
\PackageWarningNoLine{xintcfrac}{\numexpr not available, aborting input}% |
| 36866 |
\fi |
| 36867 |
\def\z{\endgroup\endinput}% |
| 36868 |
\else |
| 36869 |
\ifx\x\relax % not LaTeX, first loading of xintcfrac.sty |
| 36870 |
\ifx\w\relax % but xintfrac.sty not yet loaded. |
| 36871 |
\expandafter\def\expandafter\z\expandafter |
| 36872 |
{\z\input xintfrac.sty\relax}% |
| 36873 |
\fi |
| 36874 |
\ifx\t\relax % but xinttools.sty not yet loaded. |
| 36875 |
\expandafter\def\expandafter\z\expandafter |
| 36876 |
{\z\input xinttools.sty\relax}% |
| 36877 |
\fi |
| 36878 |
\else |
| 36879 |
\ifx\x\empty % LaTeX, first loading, |
| 36880 |
% variable is initialized, but \ProvidesPackage not yet seen |
| 36881 |
\ifx\w\relax % xintfrac not yet loaded. |
| 36882 |
\expandafter\def\expandafter\z\expandafter |
| 36883 |
{\z\RequirePackage{xintfrac}}% |
| 36884 |
\fi |
| 36885 |
\ifx\t\relax % xinttools not yet loaded. |
| 36886 |
\expandafter\def\expandafter\z\expandafter |
| 36887 |
{\z\RequirePackage{xinttools}}% |
| 36888 |
\fi |
| 36889 |
\else |
| 36890 |
\def\z{\endgroup\endinput}% xintcfrac already loaded. |
| 36891 |
\fi |
| 36892 |
\fi |
| 36893 |
\fi |
| 36894 |
\z% |
| 36895 |
\XINTsetupcatcodes% defined in xintkernel.sty |
| 36896 |
% \end{macrocode} |
| 36897 |
% \subsection{Package identification} |
| 36898 |
% \begin{macrocode} |
| 36899 |
\XINT_providespackage |
| 36900 |
\ProvidesPackage{xintcfrac}% |
| 36901 |
[2025/09/06 v1.4o Expandable continued fractions with xint package (JFB)]% |
| 36902 |
% \end{macrocode} |
| 36903 |
% \subsection{\csh{xintCFrac}} |
| 36904 |
% \begin{macrocode} |
| 36905 |
\def\xintCFrac {\romannumeral0\xintcfrac }% |
| 36906 |
\def\xintcfrac #1% |
| 36907 |
{% |
| 36908 |
\XINT_cfrac_opt_a #1\xint: |
| 36909 |
}% |
| 36910 |
\def\XINT_cfrac_opt_a #1% |
| 36911 |
{% |
| 36912 |
\ifx[#1\XINT_cfrac_opt_b\fi \XINT_cfrac_noopt #1% |
| 36913 |
}% |
| 36914 |
\def\XINT_cfrac_noopt #1\xint: |
| 36915 |
{% |
| 36916 |
\expandafter\XINT_cfrac_A\romannumeral0\xintrawwithzeros {#1}\Z |
| 36917 |
\relax\relax |
| 36918 |
}% |
| 36919 |
\def\XINT_cfrac_opt_b\fi\XINT_cfrac_noopt [\xint:#1]% |
| 36920 |
{% |
| 36921 |
\fi\csname XINT_cfrac_opt#1\endcsname |
| 36922 |
}% |
| 36923 |
\def\XINT_cfrac_optl #1% |
| 36924 |
{% |
| 36925 |
\expandafter\XINT_cfrac_A\romannumeral0\xintrawwithzeros {#1}\Z |
| 36926 |
\relax\hfill |
| 36927 |
}% |
| 36928 |
\def\XINT_cfrac_optc #1% |
| 36929 |
{% |
| 36930 |
\expandafter\XINT_cfrac_A\romannumeral0\xintrawwithzeros {#1}\Z |
| 36931 |
\relax\relax |
| 36932 |
}% |
| 36933 |
\def\XINT_cfrac_optr #1% |
| 36934 |
{% |
| 36935 |
\expandafter\XINT_cfrac_A\romannumeral0\xintrawwithzeros {#1}\Z |
| 36936 |
\hfill\relax |
| 36937 |
}% |
| 36938 |
\def\XINT_cfrac_A #1/#2\Z |
| 36939 |
{% |
| 36940 |
\expandafter\XINT_cfrac_B\romannumeral0\xintiidivision {#1}{#2}{#2}% |
| 36941 |
}% |
| 36942 |
\def\XINT_cfrac_B #1#2% |
| 36943 |
{% |
| 36944 |
\XINT_cfrac_C #2\Z {#1}% |
| 36945 |
}% |
| 36946 |
\def\XINT_cfrac_C #1% |
| 36947 |
{% |
| 36948 |
\xint_gob_til_zero #1\XINT_cfrac_integer 0\XINT_cfrac_D #1% |
| 36949 |
}% |
| 36950 |
\def\XINT_cfrac_integer 0\XINT_cfrac_D 0#1\Z #2#3#4#5{ #2}% |
| 36951 |
\def\XINT_cfrac_D #1\Z #2#3{\XINT_cfrac_loop_a {#1}{#3}{#1}{{#2}}}% |
| 36952 |
\def\XINT_cfrac_loop_a |
| 36953 |
{% |
| 36954 |
\expandafter\XINT_cfrac_loop_d\romannumeral0\XINT_div_prepare |
| 36955 |
}% |
| 36956 |
\def\XINT_cfrac_loop_d #1#2% |
| 36957 |
{% |
| 36958 |
\XINT_cfrac_loop_e #2.{#1}% |
| 36959 |
}% |
| 36960 |
\def\XINT_cfrac_loop_e #1% |
| 36961 |
{% |
| 36962 |
\xint_gob_til_zero #1\xint_cfrac_loop_exit0\XINT_cfrac_loop_f #1% |
| 36963 |
}% |
| 36964 |
\def\XINT_cfrac_loop_f #1.#2#3#4% |
| 36965 |
{% |
| 36966 |
\XINT_cfrac_loop_a {#1}{#3}{#1}{{#2}#4}% |
| 36967 |
}% |
| 36968 |
\def\xint_cfrac_loop_exit0\XINT_cfrac_loop_f #1.#2#3#4#5#6% |
| 36969 |
{\XINT_cfrac_T #5#6{#2}#4\Z }% |
| 36970 |
\def\XINT_cfrac_T #1#2#3#4% |
| 36971 |
{% |
| 36972 |
\xint_gob_til_Z #4\XINT_cfrac_end\Z\XINT_cfrac_T #1#2{#4+\cfrac{#11#2}{#3}}% |
| 36973 |
}% |
| 36974 |
\def\XINT_cfrac_end\Z\XINT_cfrac_T #1#2#3% |
| 36975 |
{% |
| 36976 |
\XINT_cfrac_end_b #3% |
| 36977 |
}% |
| 36978 |
\def\XINT_cfrac_end_b \Z+\cfrac#1#2{ #2}% |
| 36979 |
% \end{macrocode} |
| 36980 |
% \subsection{\csh{xintGCFrac}} |
| 36981 |
% Updated at |1.4g| to follow-up on renaming of |\xintFrac| into |\xintTeXFrac|. |
| 36982 |
% \begin{macrocode} |
| 36983 |
\def\xintGCFrac {\romannumeral0\xintgcfrac }% |
| 36984 |
\def\xintgcfrac #1{\XINT_gcfrac_opt_a #1\xint:}% |
| 36985 |
\def\XINT_gcfrac_opt_a #1% |
| 36986 |
{% |
| 36987 |
\ifx[#1\XINT_gcfrac_opt_b\fi \XINT_gcfrac_noopt #1% |
| 36988 |
}% |
| 36989 |
\def\XINT_gcfrac_noopt #1\xint:% |
| 36990 |
{% |
| 36991 |
\XINT_gcfrac #1+!/\relax\relax |
| 36992 |
}% |
| 36993 |
\def\XINT_gcfrac_opt_b\fi\XINT_gcfrac_noopt [\xint:#1]% |
| 36994 |
{% |
| 36995 |
\fi\csname XINT_gcfrac_opt#1\endcsname |
| 36996 |
}% |
| 36997 |
\def\XINT_gcfrac_optl #1% |
| 36998 |
{% |
| 36999 |
\XINT_gcfrac #1+!/\relax\hfill |
| 37000 |
}% |
| 37001 |
\def\XINT_gcfrac_optc #1% |
| 37002 |
{% |
| 37003 |
\XINT_gcfrac #1+!/\relax\relax |
| 37004 |
}% |
| 37005 |
\def\XINT_gcfrac_optr #1% |
| 37006 |
{% |
| 37007 |
\XINT_gcfrac #1+!/\hfill\relax |
| 37008 |
}% |
| 37009 |
\def\XINT_gcfrac |
| 37010 |
{% |
| 37011 |
\expandafter\XINT_gcfrac_enter\romannumeral`&&@% |
| 37012 |
}% |
| 37013 |
\def\XINT_gcfrac_enter {\XINT_gcfrac_loop {}}% |
| 37014 |
\def\XINT_gcfrac_loop #1#2+#3/% |
| 37015 |
{% |
| 37016 |
\xint_gob_til_exclam #3\XINT_gcfrac_endloop!% |
| 37017 |
\XINT_gcfrac_loop {{#3}{#2}#1}% |
| 37018 |
}% |
| 37019 |
\def\XINT_gcfrac_endloop!\XINT_gcfrac_loop #1#2#3% |
| 37020 |
{% |
| 37021 |
\XINT_gcfrac_T #2#3#1!!% |
| 37022 |
}% |
| 37023 |
\def\XINT_gcfrac_T #1#2#3#4{\XINT_gcfrac_U #1#2{\xintTeXFrac{#4}}}% |
| 37024 |
\def\XINT_gcfrac_U #1#2#3#4#5% |
| 37025 |
{% |
| 37026 |
\xint_gob_til_exclam #5\XINT_gcfrac_end!\XINT_gcfrac_U |
| 37027 |
#1#2{\xintTeXFrac{#5}% |
| 37028 |
\ifcase\xintSgn{#4} |
| 37029 |
+\or+\else-\fi |
| 37030 |
\cfrac{#1\xintTeXFrac{\xintAbs{#4}}#2}{#3}}% |
| 37031 |
}% |
| 37032 |
\def\XINT_gcfrac_end!\XINT_gcfrac_U #1#2#3% |
| 37033 |
{% |
| 37034 |
\XINT_gcfrac_end_b #3% |
| 37035 |
}% |
| 37036 |
\def\XINT_gcfrac_end_b #1\cfrac#2#3{ #3}% |
| 37037 |
% \end{macrocode} |
| 37038 |
% \subsection{\csh{xintGGCFrac}} |
| 37039 |
%\begin{lverb} |
| 37040 |
% New with 1.09m |
| 37041 |
%\end{lverb} |
| 37042 |
% \begin{macrocode} |
| 37043 |
\def\xintGGCFrac {\romannumeral0\xintggcfrac }% |
| 37044 |
\def\xintggcfrac #1{\XINT_ggcfrac_opt_a #1\xint:}% |
| 37045 |
\def\XINT_ggcfrac_opt_a #1% |
| 37046 |
{% |
| 37047 |
\ifx[#1\XINT_ggcfrac_opt_b\fi \XINT_ggcfrac_noopt #1% |
| 37048 |
}% |
| 37049 |
\def\XINT_ggcfrac_noopt #1\xint: |
| 37050 |
{% |
| 37051 |
\XINT_ggcfrac #1+!/\relax\relax |
| 37052 |
}% |
| 37053 |
\def\XINT_ggcfrac_opt_b\fi\XINT_ggcfrac_noopt [\xint:#1]% |
| 37054 |
{% |
| 37055 |
\fi\csname XINT_ggcfrac_opt#1\endcsname |
| 37056 |
}% |
| 37057 |
\def\XINT_ggcfrac_optl #1% |
| 37058 |
{% |
| 37059 |
\XINT_ggcfrac #1+!/\relax\hfill |
| 37060 |
}% |
| 37061 |
\def\XINT_ggcfrac_optc #1% |
| 37062 |
{% |
| 37063 |
\XINT_ggcfrac #1+!/\relax\relax |
| 37064 |
}% |
| 37065 |
\def\XINT_ggcfrac_optr #1% |
| 37066 |
{% |
| 37067 |
\XINT_ggcfrac #1+!/\hfill\relax |
| 37068 |
}% |
| 37069 |
\def\XINT_ggcfrac |
| 37070 |
{% |
| 37071 |
\expandafter\XINT_ggcfrac_enter\romannumeral`&&@% |
| 37072 |
}% |
| 37073 |
\def\XINT_ggcfrac_enter {\XINT_ggcfrac_loop {}}% |
| 37074 |
\def\XINT_ggcfrac_loop #1#2+#3/% |
| 37075 |
{% |
| 37076 |
\xint_gob_til_exclam #3\XINT_ggcfrac_endloop!% |
| 37077 |
\XINT_ggcfrac_loop {{#3}{#2}#1}% |
| 37078 |
}% |
| 37079 |
\def\XINT_ggcfrac_endloop!\XINT_ggcfrac_loop #1#2#3% |
| 37080 |
{% |
| 37081 |
\XINT_ggcfrac_T #2#3#1!!% |
| 37082 |
}% |
| 37083 |
\def\XINT_ggcfrac_T #1#2#3#4{\XINT_ggcfrac_U #1#2{#4}}% |
| 37084 |
\def\XINT_ggcfrac_U #1#2#3#4#5% |
| 37085 |
{% |
| 37086 |
\xint_gob_til_exclam #5\XINT_ggcfrac_end!\XINT_ggcfrac_U |
| 37087 |
#1#2{#5+\cfrac{#1#4#2}{#3}}% |
| 37088 |
}% |
| 37089 |
\def\XINT_ggcfrac_end!\XINT_ggcfrac_U #1#2#3% |
| 37090 |
{% |
| 37091 |
\XINT_ggcfrac_end_b #3% |
| 37092 |
}% |
| 37093 |
\def\XINT_ggcfrac_end_b #1\cfrac#2#3{ #3}% |
| 37094 |
% \end{macrocode} |
| 37095 |
% \subsection{\csh{xintGCtoGCx}} |
| 37096 |
% \begin{macrocode} |
| 37097 |
\def\xintGCtoGCx {\romannumeral0\xintgctogcx }% |
| 37098 |
\def\xintgctogcx #1#2#3% |
| 37099 |
{% |
| 37100 |
\expandafter\XINT_gctgcx_start\expandafter {\romannumeral`&&@#3}{#1}{#2}% |
| 37101 |
}% |
| 37102 |
\def\XINT_gctgcx_start #1#2#3{\XINT_gctgcx_loop_a {}{#2}{#3}#1+!/}% |
| 37103 |
\def\XINT_gctgcx_loop_a #1#2#3#4+#5/% |
| 37104 |
{% |
| 37105 |
\xint_gob_til_exclam #5\XINT_gctgcx_end!% |
| 37106 |
\XINT_gctgcx_loop_b {#1{#4}}{#2{#5}#3}{#2}{#3}% |
| 37107 |
}% |
| 37108 |
\def\XINT_gctgcx_loop_b #1#2% |
| 37109 |
{% |
| 37110 |
\XINT_gctgcx_loop_a {#1#2}% |
| 37111 |
}% |
| 37112 |
\def\XINT_gctgcx_end!\XINT_gctgcx_loop_b #1#2#3#4{ #1}% |
| 37113 |
% \end{macrocode} |
| 37114 |
% \subsection{\csh{xintFtoCs}} |
| 37115 |
%\begin{lverb} |
| 37116 |
% Modified in 1.09m: a space is added after the inserted commas. |
| 37117 |
%\end{lverb} |
| 37118 |
% \begin{macrocode} |
| 37119 |
\def\xintFtoCs {\romannumeral0\xintftocs }% |
| 37120 |
\def\xintftocs #1% |
| 37121 |
{% |
| 37122 |
\expandafter\XINT_ftc_A\romannumeral0\xintrawwithzeros {#1}\Z |
| 37123 |
}% |
| 37124 |
\def\XINT_ftc_A #1/#2\Z |
| 37125 |
{% |
| 37126 |
\expandafter\XINT_ftc_B\romannumeral0\xintiidivision {#1}{#2}{#2}% |
| 37127 |
}% |
| 37128 |
\def\XINT_ftc_B #1#2% |
| 37129 |
{% |
| 37130 |
\XINT_ftc_C #2.{#1}% |
| 37131 |
}% |
| 37132 |
\def\XINT_ftc_C #1% |
| 37133 |
{% |
| 37134 |
\xint_gob_til_zero #1\XINT_ftc_integer 0\XINT_ftc_D #1% |
| 37135 |
}% |
| 37136 |
\def\XINT_ftc_integer 0\XINT_ftc_D 0#1.#2#3{ #2}% |
| 37137 |
\def\XINT_ftc_D #1.#2#3{\XINT_ftc_loop_a {#1}{#3}{#1}{#2, }}% 1.09m adds a space |
| 37138 |
\def\XINT_ftc_loop_a |
| 37139 |
{% |
| 37140 |
\expandafter\XINT_ftc_loop_d\romannumeral0\XINT_div_prepare |
| 37141 |
}% |
| 37142 |
\def\XINT_ftc_loop_d #1#2% |
| 37143 |
{% |
| 37144 |
\XINT_ftc_loop_e #2.{#1}% |
| 37145 |
}% |
| 37146 |
\def\XINT_ftc_loop_e #1% |
| 37147 |
{% |
| 37148 |
\xint_gob_til_zero #1\xint_ftc_loop_exit0\XINT_ftc_loop_f #1% |
| 37149 |
}% |
| 37150 |
\def\XINT_ftc_loop_f #1.#2#3#4% |
| 37151 |
{% |
| 37152 |
\XINT_ftc_loop_a {#1}{#3}{#1}{#4#2, }% 1.09m has an added space here |
| 37153 |
}% |
| 37154 |
\def\xint_ftc_loop_exit0\XINT_ftc_loop_f #1.#2#3#4{ #4#2}% |
| 37155 |
% \end{macrocode} |
| 37156 |
% \subsection{\csh{xintFtoCx}} |
| 37157 |
% \begin{macrocode} |
| 37158 |
\def\xintFtoCx {\romannumeral0\xintftocx }% |
| 37159 |
\def\xintftocx #1#2% |
| 37160 |
{% |
| 37161 |
\expandafter\XINT_ftcx_A\romannumeral0\xintrawwithzeros {#2}\Z {#1}% |
| 37162 |
}% |
| 37163 |
\def\XINT_ftcx_A #1/#2\Z |
| 37164 |
{% |
| 37165 |
\expandafter\XINT_ftcx_B\romannumeral0\xintiidivision {#1}{#2}{#2}% |
| 37166 |
}% |
| 37167 |
\def\XINT_ftcx_B #1#2% |
| 37168 |
{% |
| 37169 |
\XINT_ftcx_C #2.{#1}% |
| 37170 |
}% |
| 37171 |
\def\XINT_ftcx_C #1% |
| 37172 |
{% |
| 37173 |
\xint_gob_til_zero #1\XINT_ftcx_integer 0\XINT_ftcx_D #1% |
| 37174 |
}% |
| 37175 |
\def\XINT_ftcx_integer 0\XINT_ftcx_D 0#1.#2#3#4{ #2}% |
| 37176 |
\def\XINT_ftcx_D #1.#2#3#4{\XINT_ftcx_loop_a {#1}{#3}{#1}{{#2}#4}{#4}}% |
| 37177 |
\def\XINT_ftcx_loop_a |
| 37178 |
{% |
| 37179 |
\expandafter\XINT_ftcx_loop_d\romannumeral0\XINT_div_prepare |
| 37180 |
}% |
| 37181 |
\def\XINT_ftcx_loop_d #1#2% |
| 37182 |
{% |
| 37183 |
\XINT_ftcx_loop_e #2.{#1}% |
| 37184 |
}% |
| 37185 |
\def\XINT_ftcx_loop_e #1% |
| 37186 |
{% |
| 37187 |
\xint_gob_til_zero #1\xint_ftcx_loop_exit0\XINT_ftcx_loop_f #1% |
| 37188 |
}% |
| 37189 |
\def\XINT_ftcx_loop_f #1.#2#3#4#5% |
| 37190 |
{% |
| 37191 |
\XINT_ftcx_loop_a {#1}{#3}{#1}{#4{#2}#5}{#5}% |
| 37192 |
}% |
| 37193 |
\def\xint_ftcx_loop_exit0\XINT_ftcx_loop_f #1.#2#3#4#5{ #4{#2}}% |
| 37194 |
% \end{macrocode} |
| 37195 |
% \subsection{\csh{xintFtoC}} |
| 37196 |
%\begin{lverb} |
| 37197 |
% New in 1.09m: this is the same as \xintFtoCx with empty separator. I |
| 37198 |
% had temporarily during preparation of 1.09m removed braces from \xintFtoCx, |
| 37199 |
% but I recalled later why that was useful (see doc), thus let's just here do |
| 37200 |
% \xintFtoCx {} |
| 37201 |
%\end{lverb} |
| 37202 |
% \begin{macrocode} |
| 37203 |
\def\xintFtoC {\romannumeral0\xintftoc }% |
| 37204 |
\def\xintftoc {\xintftocx {}}% |
| 37205 |
% \end{macrocode} |
| 37206 |
% \subsection{\csh{xintFtoGC}} |
| 37207 |
% \begin{macrocode} |
| 37208 |
\def\xintFtoGC {\romannumeral0\xintftogc }% |
| 37209 |
\def\xintftogc {\xintftocx {+1/}}% |
| 37210 |
% \end{macrocode} |
| 37211 |
% \subsection{\csh{xintFGtoC}} |
| 37212 |
%\begin{lverb} |
| 37213 |
% New with 1.09m of 2014/02/26. Computes the common initial coefficients |
| 37214 |
% for the two fractions f and g, and outputs them as a sequence of braced |
| 37215 |
% items. |
| 37216 |
%\end{lverb} |
| 37217 |
% \begin{macrocode} |
| 37218 |
\def\xintFGtoC {\romannumeral0\xintfgtoc}% |
| 37219 |
\def\xintfgtoc#1% |
| 37220 |
{% |
| 37221 |
\expandafter\XINT_fgtc_a\romannumeral0\xintrawwithzeros {#1}\Z |
| 37222 |
}% |
| 37223 |
\def\XINT_fgtc_a #1/#2\Z #3% |
| 37224 |
{% |
| 37225 |
\expandafter\XINT_fgtc_b\romannumeral0\xintrawwithzeros {#3}\Z #1/#2\Z { }% |
| 37226 |
}% |
| 37227 |
\def\XINT_fgtc_b #1/#2\Z |
| 37228 |
{% |
| 37229 |
\expandafter\XINT_fgtc_c\romannumeral0\xintiidivision {#1}{#2}{#2}% |
| 37230 |
}% |
| 37231 |
\def\XINT_fgtc_c #1#2#3#4/#5\Z |
| 37232 |
{% |
| 37233 |
\expandafter\XINT_fgtc_d\romannumeral0\xintiidivision |
| 37234 |
{#4}{#5}{#5}{#1}{#2}{#3}% |
| 37235 |
}% |
| 37236 |
\def\XINT_fgtc_d #1#2#3#4%#5#6#7% |
| 37237 |
{% |
| 37238 |
\xintifEq {#1}{#4}{\XINT_fgtc_da {#1}{#2}{#3}{#4}}% |
| 37239 |
{\xint_thirdofthree}% |
| 37240 |
}% |
| 37241 |
\def\XINT_fgtc_da #1#2#3#4#5#6#7% |
| 37242 |
{% |
| 37243 |
\XINT_fgtc_e {#2}{#5}{#3}{#6}{#7{#1}}% |
| 37244 |
}% |
| 37245 |
\def\XINT_fgtc_e #1% |
| 37246 |
{% |
| 37247 |
\xintiiifZero {#1}{\expandafter\xint_firstofone\xint_gobble_iii}% |
| 37248 |
{\XINT_fgtc_f {#1}}% |
| 37249 |
}% |
| 37250 |
\def\XINT_fgtc_f #1#2% |
| 37251 |
{% |
| 37252 |
\xintiiifZero {#2}{\xint_thirdofthree}{\XINT_fgtc_g {#1}{#2}}% |
| 37253 |
}% |
| 37254 |
\def\XINT_fgtc_g #1#2#3% |
| 37255 |
{% |
| 37256 |
\expandafter\XINT_fgtc_h\romannumeral0\XINT_div_prepare {#1}{#3}{#1}{#2}% |
| 37257 |
}% |
| 37258 |
\def\XINT_fgtc_h #1#2#3#4#5% |
| 37259 |
{% |
| 37260 |
\expandafter\XINT_fgtc_d\romannumeral0\XINT_div_prepare |
| 37261 |
{#4}{#5}{#4}{#1}{#2}{#3}% |
| 37262 |
}% |
| 37263 |
% \end{macrocode} |
| 37264 |
% \subsection{\csh{xintFtoCC}} |
| 37265 |
% \begin{macrocode} |
| 37266 |
\def\xintFtoCC {\romannumeral0\xintftocc }% |
| 37267 |
\def\xintftocc #1% |
| 37268 |
{% |
| 37269 |
\expandafter\XINT_ftcc_A\expandafter {\romannumeral0\xintrawwithzeros {#1}}% |
| 37270 |
}% |
| 37271 |
\def\XINT_ftcc_A #1% |
| 37272 |
{% |
| 37273 |
\expandafter\XINT_ftcc_B |
| 37274 |
\romannumeral0\xintrawwithzeros {\xintAdd {1/2[0]}{#1[0]}}\Z {#1[0]}% |
| 37275 |
}% |
| 37276 |
\def\XINT_ftcc_B #1/#2\Z |
| 37277 |
{% |
| 37278 |
\expandafter\XINT_ftcc_C\expandafter {\romannumeral0\xintiiquo {#1}{#2}}% |
| 37279 |
}% |
| 37280 |
\def\XINT_ftcc_C #1#2% |
| 37281 |
{% |
| 37282 |
\expandafter\XINT_ftcc_D\romannumeral0\xintsub {#2}{#1}\Z {#1}% |
| 37283 |
}% |
| 37284 |
\def\XINT_ftcc_D #1% |
| 37285 |
{% |
| 37286 |
\xint_UDzerominusfork |
| 37287 |
#1-\XINT_ftcc_integer |
| 37288 |
0#1\XINT_ftcc_En |
| 37289 |
0-{\XINT_ftcc_Ep #1}% |
| 37290 |
\krof |
| 37291 |
}% |
| 37292 |
\def\XINT_ftcc_Ep #1\Z #2% |
| 37293 |
{% |
| 37294 |
\expandafter\XINT_ftcc_loop_a\expandafter |
| 37295 |
{\romannumeral0\xintdiv {1[0]}{#1}}{#2+1/}% |
| 37296 |
}% |
| 37297 |
\def\XINT_ftcc_En #1\Z #2% |
| 37298 |
{% |
| 37299 |
\expandafter\XINT_ftcc_loop_a\expandafter |
| 37300 |
{\romannumeral0\xintdiv {1[0]}{#1}}{#2+-1/}% |
| 37301 |
}% |
| 37302 |
\def\XINT_ftcc_integer #1\Z #2{ #2}% |
| 37303 |
\def\XINT_ftcc_loop_a #1% |
| 37304 |
{% |
| 37305 |
\expandafter\XINT_ftcc_loop_b |
| 37306 |
\romannumeral0\xintrawwithzeros {\xintAdd {1/2[0]}{#1}}\Z {#1}% |
| 37307 |
}% |
| 37308 |
\def\XINT_ftcc_loop_b #1/#2\Z |
| 37309 |
{% |
| 37310 |
\expandafter\XINT_ftcc_loop_c\expandafter |
| 37311 |
{\romannumeral0\xintiiquo {#1}{#2}}% |
| 37312 |
}% |
| 37313 |
\def\XINT_ftcc_loop_c #1#2% |
| 37314 |
{% |
| 37315 |
\expandafter\XINT_ftcc_loop_d |
| 37316 |
\romannumeral0\xintsub {#2}{#1[0]}\Z {#1}% |
| 37317 |
}% |
| 37318 |
\def\XINT_ftcc_loop_d #1% |
| 37319 |
{% |
| 37320 |
\xint_UDzerominusfork |
| 37321 |
#1-\XINT_ftcc_end |
| 37322 |
0#1\XINT_ftcc_loop_N |
| 37323 |
0-{\XINT_ftcc_loop_P #1}% |
| 37324 |
\krof |
| 37325 |
}% |
| 37326 |
\def\XINT_ftcc_end #1\Z #2#3{ #3#2}% |
| 37327 |
\def\XINT_ftcc_loop_P #1\Z #2#3% |
| 37328 |
{% |
| 37329 |
\expandafter\XINT_ftcc_loop_a\expandafter |
| 37330 |
{\romannumeral0\xintdiv {1[0]}{#1}}{#3#2+1/}% |
| 37331 |
}% |
| 37332 |
\def\XINT_ftcc_loop_N #1\Z #2#3% |
| 37333 |
{% |
| 37334 |
\expandafter\XINT_ftcc_loop_a\expandafter |
| 37335 |
{\romannumeral0\xintdiv {1[0]}{#1}}{#3#2+-1/}% |
| 37336 |
}% |
| 37337 |
% \end{macrocode} |
| 37338 |
% \subsection{\csh{xintCtoF}, \csh{xintCstoF}} |
| 37339 |
% |
| 37340 |
% |1.09m| uses \xinttoolsnameimp's \csbxint{CSVtoList} on the argument of |
| 37341 |
% \csbxint{CstoF} to allow spaces also before the commas. And the original |
| 37342 |
% \csbxint{CstoF} code became the one of the new \csbxint{CtoF} dealing with a |
| 37343 |
% braced rather than comma separated list. |
| 37344 |
% \begin{macrocode} |
| 37345 |
\def\xintCstoF {\romannumeral0\xintcstof }% |
| 37346 |
\def\xintcstof #1% |
| 37347 |
{% |
| 37348 |
\expandafter\XINT_ctf_prep \romannumeral0\xintcsvtolist{#1}!% |
| 37349 |
}% |
| 37350 |
\def\xintCtoF {\romannumeral0\xintctof }% |
| 37351 |
\def\xintctof #1% |
| 37352 |
{% |
| 37353 |
\expandafter\XINT_ctf_prep \romannumeral`&&@#1!% |
| 37354 |
}% |
| 37355 |
\def\XINT_ctf_prep |
| 37356 |
{% |
| 37357 |
\XINT_ctf_loop_a 1001% |
| 37358 |
}% |
| 37359 |
\def\XINT_ctf_loop_a #1#2#3#4#5% |
| 37360 |
{% |
| 37361 |
\xint_gob_til_exclam #5\XINT_ctf_end!% |
| 37362 |
\expandafter\XINT_ctf_loop_b |
| 37363 |
\romannumeral0\xintrawwithzeros {#5}.{#1}{#2}{#3}{#4}% |
| 37364 |
}% |
| 37365 |
\def\XINT_ctf_loop_b #1/#2.#3#4#5#6% |
| 37366 |
{% |
| 37367 |
\expandafter\XINT_ctf_loop_c\expandafter |
| 37368 |
{\romannumeral0\XINT_mul_fork #2\xint:#4\xint:}% |
| 37369 |
{\romannumeral0\XINT_mul_fork #2\xint:#3\xint:}% |
| 37370 |
{\romannumeral0\xintiiadd {\XINT_mul_fork #2\xint:#6\xint:}% |
| 37371 |
{\XINT_mul_fork #1\xint:#4\xint:}}% |
| 37372 |
{\romannumeral0\xintiiadd {\XINT_mul_fork #2\xint:#5\xint:}% |
| 37373 |
{\XINT_mul_fork #1\xint:#3\xint:}}% |
| 37374 |
}% |
| 37375 |
\def\XINT_ctf_loop_c #1#2% |
| 37376 |
{% |
| 37377 |
\expandafter\XINT_ctf_loop_d\expandafter {\expandafter{#2}{#1}}% |
| 37378 |
}% |
| 37379 |
\def\XINT_ctf_loop_d #1#2% |
| 37380 |
{% |
| 37381 |
\expandafter\XINT_ctf_loop_e\expandafter {\expandafter{#2}#1}% |
| 37382 |
}% |
| 37383 |
\def\XINT_ctf_loop_e #1#2% |
| 37384 |
{% |
| 37385 |
\expandafter\XINT_ctf_loop_a\expandafter{#2}#1% |
| 37386 |
}% |
| 37387 |
\def\XINT_ctf_end #1.#2#3#4#5{\xintrawwithzeros {#2/#3}}% 1.09b removes [0] |
| 37388 |
% \end{macrocode} |
| 37389 |
% \subsection{\csh{xintiCstoF}} |
| 37390 |
% \begin{macrocode} |
| 37391 |
\def\xintiCstoF {\romannumeral0\xinticstof }% |
| 37392 |
\def\xinticstof #1% |
| 37393 |
{% |
| 37394 |
\expandafter\XINT_icstf_prep \romannumeral`&&@#1,!,% |
| 37395 |
}% |
| 37396 |
\def\XINT_icstf_prep |
| 37397 |
{% |
| 37398 |
\XINT_icstf_loop_a 1001% |
| 37399 |
}% |
| 37400 |
\def\XINT_icstf_loop_a #1#2#3#4#5,% |
| 37401 |
{% |
| 37402 |
\xint_gob_til_exclam #5\XINT_icstf_end!% |
| 37403 |
\expandafter |
| 37404 |
\XINT_icstf_loop_b \romannumeral`&&@#5.{#1}{#2}{#3}{#4}% |
| 37405 |
}% |
| 37406 |
\def\XINT_icstf_loop_b #1.#2#3#4#5% |
| 37407 |
{% |
| 37408 |
\expandafter\XINT_icstf_loop_c\expandafter |
| 37409 |
{\romannumeral0\xintiiadd {#5}{\XINT_mul_fork #1\xint:#3\xint:}}% |
| 37410 |
{\romannumeral0\xintiiadd {#4}{\XINT_mul_fork #1\xint:#2\xint:}}% |
| 37411 |
{#2}{#3}% |
| 37412 |
}% |
| 37413 |
\def\XINT_icstf_loop_c #1#2% |
| 37414 |
{% |
| 37415 |
\expandafter\XINT_icstf_loop_a\expandafter {#2}{#1}% |
| 37416 |
}% |
| 37417 |
\def\XINT_icstf_end#1.#2#3#4#5{\xintrawwithzeros {#2/#3}}% 1.09b removes [0] |
| 37418 |
% \end{macrocode} |
| 37419 |
% \subsection{\csh{xintGCtoF}} |
| 37420 |
% \begin{macrocode} |
| 37421 |
\def\xintGCtoF {\romannumeral0\xintgctof }% |
| 37422 |
\def\xintgctof #1% |
| 37423 |
{% |
| 37424 |
\expandafter\XINT_gctf_prep \romannumeral`&&@#1+!/% |
| 37425 |
}% |
| 37426 |
\def\XINT_gctf_prep |
| 37427 |
{% |
| 37428 |
\XINT_gctf_loop_a 1001% |
| 37429 |
}% |
| 37430 |
\def\XINT_gctf_loop_a #1#2#3#4#5+% |
| 37431 |
{% |
| 37432 |
\expandafter\XINT_gctf_loop_b |
| 37433 |
\romannumeral0\xintrawwithzeros {#5}.{#1}{#2}{#3}{#4}% |
| 37434 |
}% |
| 37435 |
\def\XINT_gctf_loop_b #1/#2.#3#4#5#6% |
| 37436 |
{% |
| 37437 |
\expandafter\XINT_gctf_loop_c\expandafter |
| 37438 |
{\romannumeral0\XINT_mul_fork #2\xint:#4\xint:}% |
| 37439 |
{\romannumeral0\XINT_mul_fork #2\xint:#3\xint:}% |
| 37440 |
{\romannumeral0\xintiiadd {\XINT_mul_fork #2\xint:#6\xint:}% |
| 37441 |
{\XINT_mul_fork #1\xint:#4\xint:}}% |
| 37442 |
{\romannumeral0\xintiiadd {\XINT_mul_fork #2\xint:#5\xint:}% |
| 37443 |
{\XINT_mul_fork #1\xint:#3\xint:}}% |
| 37444 |
}% |
| 37445 |
\def\XINT_gctf_loop_c #1#2% |
| 37446 |
{% |
| 37447 |
\expandafter\XINT_gctf_loop_d\expandafter {\expandafter{#2}{#1}}% |
| 37448 |
}% |
| 37449 |
\def\XINT_gctf_loop_d #1#2% |
| 37450 |
{% |
| 37451 |
\expandafter\XINT_gctf_loop_e\expandafter {\expandafter{#2}#1}% |
| 37452 |
}% |
| 37453 |
\def\XINT_gctf_loop_e #1#2% |
| 37454 |
{% |
| 37455 |
\expandafter\XINT_gctf_loop_f\expandafter {\expandafter{#2}#1}% |
| 37456 |
}% |
| 37457 |
\def\XINT_gctf_loop_f #1#2/% |
| 37458 |
{% |
| 37459 |
\xint_gob_til_exclam #2\XINT_gctf_end!% |
| 37460 |
\expandafter\XINT_gctf_loop_g |
| 37461 |
\romannumeral0\xintrawwithzeros {#2}.#1% |
| 37462 |
}% |
| 37463 |
\def\XINT_gctf_loop_g #1/#2.#3#4#5#6% |
| 37464 |
{% |
| 37465 |
\expandafter\XINT_gctf_loop_h\expandafter |
| 37466 |
{\romannumeral0\XINT_mul_fork #1\xint:#6\xint:}% |
| 37467 |
{\romannumeral0\XINT_mul_fork #1\xint:#5\xint:}% |
| 37468 |
{\romannumeral0\XINT_mul_fork #2\xint:#4\xint:}% |
| 37469 |
{\romannumeral0\XINT_mul_fork #2\xint:#3\xint:}% |
| 37470 |
}% |
| 37471 |
\def\XINT_gctf_loop_h #1#2% |
| 37472 |
{% |
| 37473 |
\expandafter\XINT_gctf_loop_i\expandafter {\expandafter{#2}{#1}}% |
| 37474 |
}% |
| 37475 |
\def\XINT_gctf_loop_i #1#2% |
| 37476 |
{% |
| 37477 |
\expandafter\XINT_gctf_loop_j\expandafter {\expandafter{#2}#1}% |
| 37478 |
}% |
| 37479 |
\def\XINT_gctf_loop_j #1#2% |
| 37480 |
{% |
| 37481 |
\expandafter\XINT_gctf_loop_a\expandafter {#2}#1% |
| 37482 |
}% |
| 37483 |
\def\XINT_gctf_end #1.#2#3#4#5{\xintrawwithzeros {#2/#3}}% 1.09b removes [0] |
| 37484 |
% \end{macrocode} |
| 37485 |
% \subsection{\csh{xintiGCtoF}} |
| 37486 |
% \begin{macrocode} |
| 37487 |
\def\xintiGCtoF {\romannumeral0\xintigctof }% |
| 37488 |
\def\xintigctof #1% |
| 37489 |
{% |
| 37490 |
\expandafter\XINT_igctf_prep \romannumeral`&&@#1+!/% |
| 37491 |
}% |
| 37492 |
\def\XINT_igctf_prep |
| 37493 |
{% |
| 37494 |
\XINT_igctf_loop_a 1001% |
| 37495 |
}% |
| 37496 |
\def\XINT_igctf_loop_a #1#2#3#4#5+% |
| 37497 |
{% |
| 37498 |
\expandafter\XINT_igctf_loop_b |
| 37499 |
\romannumeral`&&@#5.{#1}{#2}{#3}{#4}% |
| 37500 |
}% |
| 37501 |
\def\XINT_igctf_loop_b #1.#2#3#4#5% |
| 37502 |
{% |
| 37503 |
\expandafter\XINT_igctf_loop_c\expandafter |
| 37504 |
{\romannumeral0\xintiiadd {#5}{\XINT_mul_fork #1\xint:#3\xint:}}% |
| 37505 |
{\romannumeral0\xintiiadd {#4}{\XINT_mul_fork #1\xint:#2\xint:}}% |
| 37506 |
{#2}{#3}% |
| 37507 |
}% |
| 37508 |
\def\XINT_igctf_loop_c #1#2% |
| 37509 |
{% |
| 37510 |
\expandafter\XINT_igctf_loop_f\expandafter {\expandafter{#2}{#1}}% |
| 37511 |
}% |
| 37512 |
\def\XINT_igctf_loop_f #1#2#3#4/% |
| 37513 |
{% |
| 37514 |
\xint_gob_til_exclam #4\XINT_igctf_end!% |
| 37515 |
\expandafter\XINT_igctf_loop_g |
| 37516 |
\romannumeral`&&@#4.{#2}{#3}#1% |
| 37517 |
}% |
| 37518 |
\def\XINT_igctf_loop_g #1.#2#3% |
| 37519 |
{% |
| 37520 |
\expandafter\XINT_igctf_loop_h\expandafter |
| 37521 |
{\romannumeral0\XINT_mul_fork #1\xint:#3\xint:}% |
| 37522 |
{\romannumeral0\XINT_mul_fork #1\xint:#2\xint:}% |
| 37523 |
}% |
| 37524 |
\def\XINT_igctf_loop_h #1#2% |
| 37525 |
{% |
| 37526 |
\expandafter\XINT_igctf_loop_i\expandafter {#2}{#1}% |
| 37527 |
}% |
| 37528 |
\def\XINT_igctf_loop_i #1#2#3#4% |
| 37529 |
{% |
| 37530 |
\XINT_igctf_loop_a {#3}{#4}{#1}{#2}% |
| 37531 |
}% |
| 37532 |
\def\XINT_igctf_end #1.#2#3#4#5{\xintrawwithzeros {#4/#5}}% 1.09b removes [0] |
| 37533 |
% \end{macrocode} |
| 37534 |
% \subsection{\csh{xintCtoCv}, \csh{xintCstoCv}} |
| 37535 |
% |
| 37536 |
% |1.09m| uses \xinttoolsnameimp's \csbxint{CSVtoList} on the argument of |
| 37537 |
% \csbxint{CstoCv} to allow spaces also before the commas. The original |
| 37538 |
% \csbxint{CstoCv} code became the one of the new \csbxint{CtoF} dealing with |
| 37539 |
% a braced rather than comma separated list. |
| 37540 |
% \begin{macrocode} |
| 37541 |
\def\xintCstoCv {\romannumeral0\xintcstocv }% |
| 37542 |
\def\xintcstocv #1% |
| 37543 |
{% |
| 37544 |
\expandafter\XINT_ctcv_prep\romannumeral0\xintcsvtolist{#1}!% |
| 37545 |
}% |
| 37546 |
\def\xintCtoCv {\romannumeral0\xintctocv }% |
| 37547 |
\def\xintctocv #1% |
| 37548 |
{% |
| 37549 |
\expandafter\XINT_ctcv_prep\romannumeral`&&@#1!% |
| 37550 |
}% |
| 37551 |
\def\XINT_ctcv_prep |
| 37552 |
{% |
| 37553 |
\XINT_ctcv_loop_a {}1001% |
| 37554 |
}% |
| 37555 |
\def\XINT_ctcv_loop_a #1#2#3#4#5#6% |
| 37556 |
{% |
| 37557 |
\xint_gob_til_exclam #6\XINT_ctcv_end!% |
| 37558 |
\expandafter\XINT_ctcv_loop_b |
| 37559 |
\romannumeral0\xintrawwithzeros {#6}.{#2}{#3}{#4}{#5}{#1}% |
| 37560 |
}% |
| 37561 |
\def\XINT_ctcv_loop_b #1/#2.#3#4#5#6% |
| 37562 |
{% |
| 37563 |
\expandafter\XINT_ctcv_loop_c\expandafter |
| 37564 |
{\romannumeral0\XINT_mul_fork #2\xint:#4\xint:}% |
| 37565 |
{\romannumeral0\XINT_mul_fork #2\xint:#3\xint:}% |
| 37566 |
{\romannumeral0\xintiiadd {\XINT_mul_fork #2\xint:#6\xint:}% |
| 37567 |
{\XINT_mul_fork #1\xint:#4\xint:}}% |
| 37568 |
{\romannumeral0\xintiiadd {\XINT_mul_fork #2\xint:#5\xint:}% |
| 37569 |
{\XINT_mul_fork #1\xint:#3\xint:}}% |
| 37570 |
}% |
| 37571 |
\def\XINT_ctcv_loop_c #1#2% |
| 37572 |
{% |
| 37573 |
\expandafter\XINT_ctcv_loop_d\expandafter {\expandafter{#2}{#1}}% |
| 37574 |
}% |
| 37575 |
\def\XINT_ctcv_loop_d #1#2% |
| 37576 |
{% |
| 37577 |
\expandafter\XINT_ctcv_loop_e\expandafter {\expandafter{#2}#1}% |
| 37578 |
}% |
| 37579 |
\def\XINT_ctcv_loop_e #1#2% |
| 37580 |
{% |
| 37581 |
\expandafter\XINT_ctcv_loop_f\expandafter{#2}#1% |
| 37582 |
}% |
| 37583 |
\def\XINT_ctcv_loop_f #1#2#3#4#5% |
| 37584 |
{% |
| 37585 |
\expandafter\XINT_ctcv_loop_g\expandafter |
| 37586 |
{\romannumeral0\xintrawwithzeros {#1/#2}}{#5}{#1}{#2}{#3}{#4}% |
| 37587 |
}% |
| 37588 |
\def\XINT_ctcv_loop_g #1#2{\XINT_ctcv_loop_a {#2{#1}}}% 1.09b removes [0] |
| 37589 |
\def\XINT_ctcv_end #1.#2#3#4#5#6{ #6}% |
| 37590 |
% \end{macrocode} |
| 37591 |
% \subsection{\csh{xintiCstoCv}} |
| 37592 |
% \begin{macrocode} |
| 37593 |
\def\xintiCstoCv {\romannumeral0\xinticstocv }% |
| 37594 |
\def\xinticstocv #1% |
| 37595 |
{% |
| 37596 |
\expandafter\XINT_icstcv_prep \romannumeral`&&@#1,!,% |
| 37597 |
}% |
| 37598 |
\def\XINT_icstcv_prep |
| 37599 |
{% |
| 37600 |
\XINT_icstcv_loop_a {}1001% |
| 37601 |
}% |
| 37602 |
\def\XINT_icstcv_loop_a #1#2#3#4#5#6,% |
| 37603 |
{% |
| 37604 |
\xint_gob_til_exclam #6\XINT_icstcv_end!% |
| 37605 |
\expandafter |
| 37606 |
\XINT_icstcv_loop_b \romannumeral`&&@#6.{#2}{#3}{#4}{#5}{#1}% |
| 37607 |
}% |
| 37608 |
\def\XINT_icstcv_loop_b #1.#2#3#4#5% |
| 37609 |
{% |
| 37610 |
\expandafter\XINT_icstcv_loop_c\expandafter |
| 37611 |
{\romannumeral0\xintiiadd {#5}{\XINT_mul_fork #1\xint:#3\xint:}}% |
| 37612 |
{\romannumeral0\xintiiadd {#4}{\XINT_mul_fork #1\xint:#2\xint:}}% |
| 37613 |
{{#2}{#3}}% |
| 37614 |
}% |
| 37615 |
\def\XINT_icstcv_loop_c #1#2% |
| 37616 |
{% |
| 37617 |
\expandafter\XINT_icstcv_loop_d\expandafter {#2}{#1}% |
| 37618 |
}% |
| 37619 |
\def\XINT_icstcv_loop_d #1#2% |
| 37620 |
{% |
| 37621 |
\expandafter\XINT_icstcv_loop_e\expandafter |
| 37622 |
{\romannumeral0\xintrawwithzeros {#1/#2}}{{#1}{#2}}% |
| 37623 |
}% |
| 37624 |
\def\XINT_icstcv_loop_e #1#2#3#4{\XINT_icstcv_loop_a {#4{#1}}#2#3}% |
| 37625 |
\def\XINT_icstcv_end #1.#2#3#4#5#6{ #6}% 1.09b removes [0] |
| 37626 |
% \end{macrocode} |
| 37627 |
% \subsection{\csh{xintGCtoCv}} |
| 37628 |
% \begin{macrocode} |
| 37629 |
\def\xintGCtoCv {\romannumeral0\xintgctocv }% |
| 37630 |
\def\xintgctocv #1% |
| 37631 |
{% |
| 37632 |
\expandafter\XINT_gctcv_prep \romannumeral`&&@#1+!/% |
| 37633 |
}% |
| 37634 |
\def\XINT_gctcv_prep |
| 37635 |
{% |
| 37636 |
\XINT_gctcv_loop_a {}1001% |
| 37637 |
}% |
| 37638 |
\def\XINT_gctcv_loop_a #1#2#3#4#5#6+% |
| 37639 |
{% |
| 37640 |
\expandafter\XINT_gctcv_loop_b |
| 37641 |
\romannumeral0\xintrawwithzeros {#6}.{#2}{#3}{#4}{#5}{#1}% |
| 37642 |
}% |
| 37643 |
\def\XINT_gctcv_loop_b #1/#2.#3#4#5#6% |
| 37644 |
{% |
| 37645 |
\expandafter\XINT_gctcv_loop_c\expandafter |
| 37646 |
{\romannumeral0\XINT_mul_fork #2\xint:#4\xint:}% |
| 37647 |
{\romannumeral0\XINT_mul_fork #2\xint:#3\xint:}% |
| 37648 |
{\romannumeral0\xintiiadd {\XINT_mul_fork #2\xint:#6\xint:}% |
| 37649 |
{\XINT_mul_fork #1\xint:#4\xint:}}% |
| 37650 |
{\romannumeral0\xintiiadd {\XINT_mul_fork #2\xint:#5\xint:}% |
| 37651 |
{\XINT_mul_fork #1\xint:#3\xint:}}% |
| 37652 |
}% |
| 37653 |
\def\XINT_gctcv_loop_c #1#2% |
| 37654 |
{% |
| 37655 |
\expandafter\XINT_gctcv_loop_d\expandafter {\expandafter{#2}{#1}}% |
| 37656 |
}% |
| 37657 |
\def\XINT_gctcv_loop_d #1#2% |
| 37658 |
{% |
| 37659 |
\expandafter\XINT_gctcv_loop_e\expandafter {\expandafter{#2}{#1}}% |
| 37660 |
}% |
| 37661 |
\def\XINT_gctcv_loop_e #1#2% |
| 37662 |
{% |
| 37663 |
\expandafter\XINT_gctcv_loop_f\expandafter {#2}#1% |
| 37664 |
}% |
| 37665 |
\def\XINT_gctcv_loop_f #1#2% |
| 37666 |
{% |
| 37667 |
\expandafter\XINT_gctcv_loop_g\expandafter |
| 37668 |
{\romannumeral0\xintrawwithzeros {#1/#2}}{{#1}{#2}}% |
| 37669 |
}% |
| 37670 |
\def\XINT_gctcv_loop_g #1#2#3#4% |
| 37671 |
{% |
| 37672 |
\XINT_gctcv_loop_h {#4{#1}}{#2#3}% 1.09b removes [0] |
| 37673 |
}% |
| 37674 |
\def\XINT_gctcv_loop_h #1#2#3/% |
| 37675 |
{% |
| 37676 |
\xint_gob_til_exclam #3\XINT_gctcv_end!% |
| 37677 |
\expandafter\XINT_gctcv_loop_i |
| 37678 |
\romannumeral0\xintrawwithzeros {#3}.#2{#1}% |
| 37679 |
}% |
| 37680 |
\def\XINT_gctcv_loop_i #1/#2.#3#4#5#6% |
| 37681 |
{% |
| 37682 |
\expandafter\XINT_gctcv_loop_j\expandafter |
| 37683 |
{\romannumeral0\XINT_mul_fork #1\xint:#6\xint:}% |
| 37684 |
{\romannumeral0\XINT_mul_fork #1\xint:#5\xint:}% |
| 37685 |
{\romannumeral0\XINT_mul_fork #2\xint:#4\xint:}% |
| 37686 |
{\romannumeral0\XINT_mul_fork #2\xint:#3\xint:}% |
| 37687 |
}% |
| 37688 |
\def\XINT_gctcv_loop_j #1#2% |
| 37689 |
{% |
| 37690 |
\expandafter\XINT_gctcv_loop_k\expandafter {\expandafter{#2}{#1}}% |
| 37691 |
}% |
| 37692 |
\def\XINT_gctcv_loop_k #1#2% |
| 37693 |
{% |
| 37694 |
\expandafter\XINT_gctcv_loop_l\expandafter {\expandafter{#2}#1}% |
| 37695 |
}% |
| 37696 |
\def\XINT_gctcv_loop_l #1#2% |
| 37697 |
{% |
| 37698 |
\expandafter\XINT_gctcv_loop_m\expandafter {\expandafter{#2}#1}% |
| 37699 |
}% |
| 37700 |
\def\XINT_gctcv_loop_m #1#2{\XINT_gctcv_loop_a {#2}#1}% |
| 37701 |
\def\XINT_gctcv_end #1.#2#3#4#5#6{ #6}% |
| 37702 |
% \end{macrocode} |
| 37703 |
% \subsection{\csh{xintiGCtoCv}} |
| 37704 |
% \begin{macrocode} |
| 37705 |
\def\xintiGCtoCv {\romannumeral0\xintigctocv }% |
| 37706 |
\def\xintigctocv #1% |
| 37707 |
{% |
| 37708 |
\expandafter\XINT_igctcv_prep \romannumeral`&&@#1+!/% |
| 37709 |
}% |
| 37710 |
\def\XINT_igctcv_prep |
| 37711 |
{% |
| 37712 |
\XINT_igctcv_loop_a {}1001% |
| 37713 |
}% |
| 37714 |
\def\XINT_igctcv_loop_a #1#2#3#4#5#6+% |
| 37715 |
{% |
| 37716 |
\expandafter\XINT_igctcv_loop_b |
| 37717 |
\romannumeral`&&@#6.{#2}{#3}{#4}{#5}{#1}% |
| 37718 |
}% |
| 37719 |
\def\XINT_igctcv_loop_b #1.#2#3#4#5% |
| 37720 |
{% |
| 37721 |
\expandafter\XINT_igctcv_loop_c\expandafter |
| 37722 |
{\romannumeral0\xintiiadd {#5}{\XINT_mul_fork #1\xint:#3\xint:}}% |
| 37723 |
{\romannumeral0\xintiiadd {#4}{\XINT_mul_fork #1\xint:#2\xint:}}% |
| 37724 |
{{#2}{#3}}% |
| 37725 |
}% |
| 37726 |
\def\XINT_igctcv_loop_c #1#2% |
| 37727 |
{% |
| 37728 |
\expandafter\XINT_igctcv_loop_f\expandafter {\expandafter{#2}{#1}}% |
| 37729 |
}% |
| 37730 |
\def\XINT_igctcv_loop_f #1#2#3#4/% |
| 37731 |
{% |
| 37732 |
\xint_gob_til_exclam #4\XINT_igctcv_end_a!% |
| 37733 |
\expandafter\XINT_igctcv_loop_g |
| 37734 |
\romannumeral`&&@#4.#1#2{#3}% |
| 37735 |
}% |
| 37736 |
\def\XINT_igctcv_loop_g #1.#2#3#4#5% |
| 37737 |
{% |
| 37738 |
\expandafter\XINT_igctcv_loop_h\expandafter |
| 37739 |
{\romannumeral0\XINT_mul_fork #1\xint:#5\xint:}% |
| 37740 |
{\romannumeral0\XINT_mul_fork #1\xint:#4\xint:}% |
| 37741 |
{{#2}{#3}}% |
| 37742 |
}% |
| 37743 |
\def\XINT_igctcv_loop_h #1#2% |
| 37744 |
{% |
| 37745 |
\expandafter\XINT_igctcv_loop_i\expandafter {\expandafter{#2}{#1}}% |
| 37746 |
}% |
| 37747 |
\def\XINT_igctcv_loop_i #1#2{\XINT_igctcv_loop_k #2{#2#1}}% |
| 37748 |
\def\XINT_igctcv_loop_k #1#2% |
| 37749 |
{% |
| 37750 |
\expandafter\XINT_igctcv_loop_l\expandafter |
| 37751 |
{\romannumeral0\xintrawwithzeros {#1/#2}}% |
| 37752 |
}% |
| 37753 |
\def\XINT_igctcv_loop_l #1#2#3{\XINT_igctcv_loop_a {#3{#1}}#2}%1.09i removes [0] |
| 37754 |
\def\XINT_igctcv_end_a #1.#2#3#4#5% |
| 37755 |
{% |
| 37756 |
\expandafter\XINT_igctcv_end_b\expandafter |
| 37757 |
{\romannumeral0\xintrawwithzeros {#2/#3}}% |
| 37758 |
}% |
| 37759 |
\def\XINT_igctcv_end_b #1#2{ #2{#1}}% 1.09b removes [0] |
| 37760 |
% \end{macrocode} |
| 37761 |
% \subsection{\csh{xintFtoCv}} |
| 37762 |
%\begin{lverb} |
| 37763 |
% Still uses \xinticstocv \xintFtoCs rather than \xintctocv \xintFtoC. |
| 37764 |
%\end{lverb} |
| 37765 |
% \begin{macrocode} |
| 37766 |
\def\xintFtoCv {\romannumeral0\xintftocv }% |
| 37767 |
\def\xintftocv #1% |
| 37768 |
{% |
| 37769 |
\xinticstocv {\xintFtoCs {#1}}% |
| 37770 |
}% |
| 37771 |
% \end{macrocode} |
| 37772 |
% \subsection{\csh{xintFtoCCv}} |
| 37773 |
% \begin{macrocode} |
| 37774 |
\def\xintFtoCCv {\romannumeral0\xintftoccv }% |
| 37775 |
\def\xintftoccv #1% |
| 37776 |
{% |
| 37777 |
\xintigctocv {\xintFtoCC {#1}}% |
| 37778 |
}% |
| 37779 |
% \end{macrocode} |
| 37780 |
% \subsection{\csh{xintCntoF}} |
| 37781 |
%\begin{lverb} |
| 37782 |
% Modified in 1.06 to give the N first to a \numexpr rather than expanding |
| 37783 |
% twice. I just use \the\numexpr and maintain the previous code after that. |
| 37784 |
%\end{lverb} |
| 37785 |
% \begin{macrocode} |
| 37786 |
\def\xintCntoF {\romannumeral0\xintcntof }% |
| 37787 |
\def\xintcntof #1% |
| 37788 |
{% |
| 37789 |
\expandafter\XINT_cntf\expandafter {\the\numexpr #1}% |
| 37790 |
}% |
| 37791 |
\def\XINT_cntf #1#2% |
| 37792 |
{% |
| 37793 |
\ifnum #1>\xint_c_ |
| 37794 |
\xint_afterfi {\expandafter\XINT_cntf_loop\expandafter |
| 37795 |
{\the\numexpr #1-1\expandafter}\expandafter |
| 37796 |
{\romannumeral`&&@#2{#1}}{#2}}% |
| 37797 |
\else |
| 37798 |
\xint_afterfi |
| 37799 |
{\ifnum #1=\xint_c_ |
| 37800 |
\xint_afterfi {\expandafter\space \romannumeral`&&@#2{0}}% |
| 37801 |
\else \xint_afterfi { }% 1.09m now returns nothing. |
| 37802 |
\fi}% |
| 37803 |
\fi |
| 37804 |
}% |
| 37805 |
\def\XINT_cntf_loop #1#2#3% |
| 37806 |
{% |
| 37807 |
\ifnum #1>\xint_c_ \else \XINT_cntf_exit \fi |
| 37808 |
\expandafter\XINT_cntf_loop\expandafter |
| 37809 |
{\the\numexpr #1-1\expandafter }\expandafter |
| 37810 |
{\romannumeral0\xintadd {\xintDiv {1[0]}{#2}}{#3{#1}}}% |
| 37811 |
{#3}% |
| 37812 |
}% |
| 37813 |
\def\XINT_cntf_exit \fi |
| 37814 |
\expandafter\XINT_cntf_loop\expandafter |
| 37815 |
#1\expandafter #2#3% |
| 37816 |
{% |
| 37817 |
\fi\xint_gobble_ii #2% |
| 37818 |
}% |
| 37819 |
% \end{macrocode} |
| 37820 |
% \subsection{\csh{xintGCntoF}} |
| 37821 |
%\begin{lverb} |
| 37822 |
% Modified in 1.06 to give the N argument first to a \numexpr rather |
| 37823 |
% than expanding twice. I just use \the\numexpr and maintain the previous code |
| 37824 |
% after that. |
| 37825 |
%\end{lverb} |
| 37826 |
% \begin{macrocode} |
| 37827 |
\def\xintGCntoF {\romannumeral0\xintgcntof }% |
| 37828 |
\def\xintgcntof #1% |
| 37829 |
{% |
| 37830 |
\expandafter\XINT_gcntf\expandafter {\the\numexpr #1}% |
| 37831 |
}% |
| 37832 |
\def\XINT_gcntf #1#2#3% |
| 37833 |
{% |
| 37834 |
\ifnum #1>\xint_c_ |
| 37835 |
\xint_afterfi {\expandafter\XINT_gcntf_loop\expandafter |
| 37836 |
{\the\numexpr #1-1\expandafter}\expandafter |
| 37837 |
{\romannumeral`&&@#2{#1}}{#2}{#3}}% |
| 37838 |
\else |
| 37839 |
\xint_afterfi |
| 37840 |
{\ifnum #1=\xint_c_ |
| 37841 |
\xint_afterfi {\expandafter\space\romannumeral`&&@#2{0}}% |
| 37842 |
\else \xint_afterfi { }% 1.09m now returns nothing rather than 0/1[0] |
| 37843 |
\fi}% |
| 37844 |
\fi |
| 37845 |
}% |
| 37846 |
\def\XINT_gcntf_loop #1#2#3#4% |
| 37847 |
{% |
| 37848 |
\ifnum #1>\xint_c_ \else \XINT_gcntf_exit \fi |
| 37849 |
\expandafter\XINT_gcntf_loop\expandafter |
| 37850 |
{\the\numexpr #1-1\expandafter }\expandafter |
| 37851 |
{\romannumeral0\xintadd {\xintDiv {#4{#1}}{#2}}{#3{#1}}}% |
| 37852 |
{#3}{#4}% |
| 37853 |
}% |
| 37854 |
\def\XINT_gcntf_exit \fi |
| 37855 |
\expandafter\XINT_gcntf_loop\expandafter |
| 37856 |
#1\expandafter #2#3#4% |
| 37857 |
{% |
| 37858 |
\fi\xint_gobble_ii #2% |
| 37859 |
}% |
| 37860 |
% \end{macrocode} |
| 37861 |
% \subsection{\csh{xintCntoCs}} |
| 37862 |
%\begin{lverb} |
| 37863 |
% Modified in 1.09m: added spaces after the commas in the produced list. |
| 37864 |
% Moreover the coefficients are not braced anymore. A slight induced limitation |
| 37865 |
% is that the macro argument should not contain some explicit comma (cf. |
| 37866 |
% \XINT_cntcs_exit_b), hence \xintCntoCs {\macro,} with \def\macro,#1{<stuff>} |
| 37867 |
% would crash. Not a very serious limitation, I believe. |
| 37868 |
%\end{lverb} |
| 37869 |
% \begin{macrocode} |
| 37870 |
\def\xintCntoCs {\romannumeral0\xintcntocs }% |
| 37871 |
\def\xintcntocs #1% |
| 37872 |
{% |
| 37873 |
\expandafter\XINT_cntcs\expandafter {\the\numexpr #1}% |
| 37874 |
}% |
| 37875 |
\def\XINT_cntcs #1#2% |
| 37876 |
{% |
| 37877 |
\ifnum #1<0 |
| 37878 |
\xint_afterfi { }% 1.09i: a 0/1[0] was here, now the macro returns nothing |
| 37879 |
\else |
| 37880 |
\xint_afterfi {\expandafter\XINT_cntcs_loop\expandafter |
| 37881 |
{\the\numexpr #1-\xint_c_i\expandafter}\expandafter |
| 37882 |
{\romannumeral`&&@#2{#1}}{#2}}% produced coeff not braced |
| 37883 |
\fi |
| 37884 |
}% |
| 37885 |
\def\XINT_cntcs_loop #1#2#3% |
| 37886 |
{% |
| 37887 |
\ifnum #1>-\xint_c_i \else \XINT_cntcs_exit \fi |
| 37888 |
\expandafter\XINT_cntcs_loop\expandafter |
| 37889 |
{\the\numexpr #1-\xint_c_i\expandafter}\expandafter |
| 37890 |
{\romannumeral`&&@#3{#1}, #2}{#3}% space added, 1.09m |
| 37891 |
}% |
| 37892 |
\def\XINT_cntcs_exit \fi |
| 37893 |
\expandafter\XINT_cntcs_loop\expandafter |
| 37894 |
#1\expandafter #2#3% |
| 37895 |
{% |
| 37896 |
\fi\XINT_cntcs_exit_b #2% |
| 37897 |
}% |
| 37898 |
\def\XINT_cntcs_exit_b #1,{}% romannumeral stopping space already there |
| 37899 |
% \end{macrocode} |
| 37900 |
% \subsection{\csh{xintCntoGC}} |
| 37901 |
%\begin{lverb} |
| 37902 |
% Modified in 1.06 to give the N first to a \numexpr rather than expanding |
| 37903 |
% twice. I just use \the\numexpr and maintain the previous code after that. |
| 37904 |
% |
| 37905 |
% 1.09m maintains the braces, as the coeff are allowed to be fraction and the |
| 37906 |
% slash can not be naked in the GC format, contrarily to what happens in |
| 37907 |
% \xintCntoCs. Also the separators given to \xintGCtoGCx may then fetch the |
| 37908 |
% coefficients as argument, as they are braced. |
| 37909 |
%\end{lverb} |
| 37910 |
% \begin{macrocode} |
| 37911 |
\def\xintCntoGC {\romannumeral0\xintcntogc }% |
| 37912 |
\def\xintcntogc #1% |
| 37913 |
{% |
| 37914 |
\expandafter\XINT_cntgc\expandafter {\the\numexpr #1}% |
| 37915 |
}% |
| 37916 |
\def\XINT_cntgc #1#2% |
| 37917 |
{% |
| 37918 |
\ifnum #1<0 |
| 37919 |
\xint_afterfi { }% 1.09i there was as strange 0/1[0] here, removed |
| 37920 |
\else |
| 37921 |
\xint_afterfi {\expandafter\XINT_cntgc_loop\expandafter |
| 37922 |
{\the\numexpr #1-\xint_c_i\expandafter}\expandafter |
| 37923 |
{\expandafter{\romannumeral`&&@#2{#1}}}{#2}}% |
| 37924 |
\fi |
| 37925 |
}% |
| 37926 |
\def\XINT_cntgc_loop #1#2#3% |
| 37927 |
{% |
| 37928 |
\ifnum #1>-\xint_c_i \else \XINT_cntgc_exit \fi |
| 37929 |
\expandafter\XINT_cntgc_loop\expandafter |
| 37930 |
{\the\numexpr #1-\xint_c_i\expandafter }\expandafter |
| 37931 |
{\expandafter{\romannumeral`&&@#3{#1}}+1/#2}{#3}% |
| 37932 |
}% |
| 37933 |
\def\XINT_cntgc_exit \fi |
| 37934 |
\expandafter\XINT_cntgc_loop\expandafter |
| 37935 |
#1\expandafter #2#3% |
| 37936 |
{% |
| 37937 |
\fi\XINT_cntgc_exit_b #2% |
| 37938 |
}% |
| 37939 |
\def\XINT_cntgc_exit_b #1+1/{ }% |
| 37940 |
% \end{macrocode} |
| 37941 |
% \subsection{\csh{xintGCntoGC}} |
| 37942 |
%\begin{lverb} |
| 37943 |
% Modified in 1.06 to give the N first to a \numexpr rather than expanding |
| 37944 |
% twice. I just use \the\numexpr and maintain the previous code after that. |
| 37945 |
%\end{lverb} |
| 37946 |
% \begin{macrocode} |
| 37947 |
\def\xintGCntoGC {\romannumeral0\xintgcntogc }% |
| 37948 |
\def\xintgcntogc #1% |
| 37949 |
{% |
| 37950 |
\expandafter\XINT_gcntgc\expandafter {\the\numexpr #1}% |
| 37951 |
}% |
| 37952 |
\def\XINT_gcntgc #1#2#3% |
| 37953 |
{% |
| 37954 |
\ifnum #1<0 |
| 37955 |
\xint_afterfi { }% 1.09i now returns nothing |
| 37956 |
\else |
| 37957 |
\xint_afterfi {\expandafter\XINT_gcntgc_loop\expandafter |
| 37958 |
{\the\numexpr #1-\xint_c_i\expandafter}\expandafter |
| 37959 |
{\expandafter{\romannumeral`&&@#2{#1}}}{#2}{#3}}% |
| 37960 |
\fi |
| 37961 |
}% |
| 37962 |
\def\XINT_gcntgc_loop #1#2#3#4% |
| 37963 |
{% |
| 37964 |
\ifnum #1>-\xint_c_i \else \XINT_gcntgc_exit \fi |
| 37965 |
\expandafter\XINT_gcntgc_loop_b\expandafter |
| 37966 |
{\expandafter{\romannumeral`&&@#4{#1}}/#2}{#3{#1}}{#1}{#3}{#4}% |
| 37967 |
}% |
| 37968 |
\def\XINT_gcntgc_loop_b #1#2#3% |
| 37969 |
{% |
| 37970 |
\expandafter\XINT_gcntgc_loop\expandafter |
| 37971 |
{\the\numexpr #3-\xint_c_i \expandafter}\expandafter |
| 37972 |
{\expandafter{\romannumeral`&&@#2}+#1}% |
| 37973 |
}% |
| 37974 |
\def\XINT_gcntgc_exit \fi |
| 37975 |
\expandafter\XINT_gcntgc_loop_b\expandafter #1#2#3#4#5% |
| 37976 |
{% |
| 37977 |
\fi\XINT_gcntgc_exit_b #1% |
| 37978 |
}% |
| 37979 |
\def\XINT_gcntgc_exit_b #1/{ }% |
| 37980 |
% \end{macrocode} |
| 37981 |
% \subsection{\csh{xintCstoGC}} |
| 37982 |
% \begin{macrocode} |
| 37983 |
\def\xintCstoGC {\romannumeral0\xintcstogc }% |
| 37984 |
\def\xintcstogc #1% |
| 37985 |
{% |
| 37986 |
\expandafter\XINT_cstc_prep \romannumeral`&&@#1,!,% |
| 37987 |
}% |
| 37988 |
\def\XINT_cstc_prep #1,{\XINT_cstc_loop_a {{#1}}}% |
| 37989 |
\def\XINT_cstc_loop_a #1#2,% |
| 37990 |
{% |
| 37991 |
\xint_gob_til_exclam #2\XINT_cstc_end!% |
| 37992 |
\XINT_cstc_loop_b {#1}{#2}% |
| 37993 |
}% |
| 37994 |
\def\XINT_cstc_loop_b #1#2{\XINT_cstc_loop_a {#1+1/{#2}}}% |
| 37995 |
\def\XINT_cstc_end!\XINT_cstc_loop_b #1#2{ #1}% |
| 37996 |
% \end{macrocode} |
| 37997 |
% \subsection{\csh{xintGCtoGC}} |
| 37998 |
% \begin{macrocode} |
| 37999 |
\def\xintGCtoGC {\romannumeral0\xintgctogc }% |
| 38000 |
\def\xintgctogc #1% |
| 38001 |
{% |
| 38002 |
\expandafter\XINT_gctgc_start \romannumeral`&&@#1+!/% |
| 38003 |
}% |
| 38004 |
\def\XINT_gctgc_start {\XINT_gctgc_loop_a {}}% |
| 38005 |
\def\XINT_gctgc_loop_a #1#2+#3/% |
| 38006 |
{% |
| 38007 |
\xint_gob_til_exclam #3\XINT_gctgc_end!% |
| 38008 |
\expandafter\XINT_gctgc_loop_b\expandafter |
| 38009 |
{\romannumeral`&&@#2}{#3}{#1}% |
| 38010 |
}% |
| 38011 |
\def\XINT_gctgc_loop_b #1#2% |
| 38012 |
{% |
| 38013 |
\expandafter\XINT_gctgc_loop_c\expandafter |
| 38014 |
{\romannumeral`&&@#2}{#1}% |
| 38015 |
}% |
| 38016 |
\def\XINT_gctgc_loop_c #1#2#3% |
| 38017 |
{% |
| 38018 |
\XINT_gctgc_loop_a {#3{#2}+{#1}/}% |
| 38019 |
}% |
| 38020 |
\def\XINT_gctgc_end!\expandafter\XINT_gctgc_loop_b |
| 38021 |
{% |
| 38022 |
\expandafter\XINT_gctgc_end_b |
| 38023 |
}% |
| 38024 |
\def\XINT_gctgc_end_b #1#2#3{ #3{#1}}% |
| 38025 |
\XINTrestorecatcodesendinput% |
| 38026 |
% \end{macrocode} |
| 38027 |
% \StoreCodelineNo {xintcfrac} |
| 38028 |
% \cleardoublepage\let\xintcfracnameUp\undefined |
| 38029 |
%\gardesactifs |
| 38030 |
%\let</xintcfrac>\relax |
| 38031 |
%\let<*xintexpr>\gardesinactifs |
| 38032 |
%</xintcfrac>^^A-------------------------------------------------- |
| 38033 |
%<*xintexpr>^^A--------------------------------------------------- |
| 38034 |
%^^A -*- coding: utf-8; mode: doctex; fill-column: 78; sentence-end-double-space: t; eval: (auto-fill-mode -1); ; fill-paragraph-function: nil; -*- |
| 38035 |
% \clearpage\csname xintexprnameUp\endcsname |
| 38036 |
% \let\MakePrivateLetters\xintexprMakePrivateLetters |
| 38037 |
% \section{Package \xintexprnameimp implementation} |
| 38038 |
% \RaisedLabel{sec:exprimp} |
| 38039 |
% \etocarticlestylenomarks |
| 38040 |
% \etocstandardlines |
| 38041 |
% \etocsettocdepth {paragraph} |
| 38042 |
% |
| 38043 |
% This is release \expandafter|\xintbndlversion| of |
| 38044 |
% \expandafter|\xintbndldate|. |
| 38045 |
% |
| 38046 |
% \localtableofcontents |
| 38047 |
% |
| 38048 |
% \etocsettocstyle{}{} |
| 38049 |
% |
| 38050 |
% \subsection{READ ME! Important warnings and explanations relative to the |
| 38051 |
% status of the code source at the time of the 1.4 release} |
| 38052 |
% \def\mybeginitemize{\begin{itemize}\catcode`\% 9 }^^A |
| 38053 |
% \def\myenditemize{\end{itemize}}^^A |
| 38054 |
%\begin{lverb} |
| 38055 |
% At release 1.4 the csname encapsulation of intermediate evaluations during |
| 38056 |
% parsing of expressions is dropped, and $xintexprnameimp requires the |
| 38057 |
% \expanded primitive. This means that there is no more impact on the string |
| 38058 |
% pool. And as internal storage now uses simply core \TeX{} syntax with braces |
| 38059 |
% rather than comma separated items inside a csname dummy control sequence, |
| 38060 |
% it became much easier to let the [...] syntax be associated to a true internal type of «tuple» |
| 38061 |
% or «list». |
| 38062 |
% |
| 38063 |
% The output of \xintexpr (after \romannumeral0 or \romannumeral-`0 triggered |
| 38064 |
% expansion or double expansion) is thus modified at 1.4. It now looks like |
| 38065 |
% this:& |
| 38066 |
% $oneargcs$footnote{The \XINTfstop was a simple$noexpand |
| 38067 |
% \def\XINTfstop$string{\noexpand\XINTfstop$string} at 1.4 but has been$noexpand |
| 38068 |
% converted into a fancier token at 1.5, to avoid the $myenquote{blinking} effect$noexpand |
| 38069 |
% when submitted to finitely many expansions à la \expandafter as first token of a$noexpand |
| 38070 |
% replacement text.} |
| 38071 |
% |
| 38072 |
% \XINTfstop \XINTexprprint .{{<number>}} in simplest case |
| 38073 |
% |
| 38074 |
% \XINTfstop \XINTexprprint .{{...}...{...}} in general case |
| 38075 |
% |
| 38076 |
% where ... stands for nested braces ultimately ending in {<num. rep.>} leaves. |
| 38077 |
% The <num. rep.> stands for some internal representation of numeric data. It |
| 38078 |
% may be empty, and currently as well as probably in future uses only catcode |
| 38079 |
% 12 tokens (no spaces currently). |
| 38080 |
% |
| 38081 |
% {{}} corresponds (in input as in output) to []. The external TeX braces also |
| 38082 |
% serve as set-theoretical braces. The comma is concatenation, so for example |
| 38083 |
% [], [] will become {{}{}}, or rather {}{} if sub-unit of something else. |
| 38084 |
% |
| 38085 |
% The associated vocabulary is explained in the user manual and we avoid |
| 38086 |
% too much duplication here. $xintfracnameimp numerical macros receiving an |
| 38087 |
% empty argument usually handle it as being 0, but this is not the case of the |
| 38088 |
% $xintcorenameimp macros supporting \xintiiexpr, they usually break if |
| 38089 |
% exercised on some empty argument. |
| 38090 |
% |
| 38091 |
% The above expansion result \XINTfstop \XINTexprprint .{{<num1>}{<num2}...} |
| 38092 |
% uses only normal catcodes: the backslash, regular braces, ascii letters and |
| 38093 |
% catcode 12 characters. Scientific notation is internally converted to raw |
| 38094 |
% $xintfracnameimp representation [N]. |
| 38095 |
% |
| 38096 |
% Additional data may be located before the dot; this is the case only for |
| 38097 |
% \xintfloatexpr currently. As |
| 38098 |
% xintexpr actually defines three parsers \xintexpr, \xintiiexpr and |
| 38099 |
% \xintfloatexpr but tries to share as much code as possible, some overhead |
| 38100 |
% is induced to fit all into the same mold. |
| 38101 |
% |
| 38102 |
% \XINTfstop stops \romannumeral-`0 (or 0) type spanned expansion, and is |
| 38103 |
% invariant under \edef, but simply disappears in typesetting context.& |
| 38104 |
% $oneargcs$footnote{It is not \let to \relax as it must be distinguished$noexpand |
| 38105 |
% from it in \ifx tests.} |
| 38106 |
% It is |
| 38107 |
% thus now legal to use \xintexpr directly in typesetting flow. |
| 38108 |
% |
| 38109 |
% \XINTexprprint is \protected. |
| 38110 |
% |
| 38111 |
% The f-expansion of an \xintexpr <expression>\relax is a complete expansion, |
| 38112 |
% i.e. one whose result remains invariant under \edef. |
| 38113 |
% |
| 38114 |
% \xintthe\xintexpr <expression>\relax or \xinteval{<expression>} serve as |
| 38115 |
% formerly to deliver the explicit digits, or more exactly some prettifying |
| 38116 |
% view of the actual <internal number representation>. |
| 38117 |
% |
| 38118 |
% Nested contents like this |
| 38119 |
% |
| 38120 |
% {{1}{{2}{3}{{4}{5}{6}}}{9}} |
| 38121 |
% |
| 38122 |
% $noindent will get delivered using nested square brackets like that |
| 38123 |
% |
| 38124 |
% 1, [2, 3, [4, 5, 6]], 9 |
| 38125 |
% |
| 38126 |
% $noindent and as conversely \xintexpr 1, [2, 3, [4, 5, 6]], 9\relax expands to |
| 38127 |
% |
| 38128 |
% \XINTfstop \XINTexprprint .{{1}{{2}{3}{{4}{5}{6}}}{9}} |
| 38129 |
% |
| 38130 |
% $noindent we obtain the gratifying result that |
| 38131 |
% |
| 38132 |
% \xinteval{1, [2, 3, [4, 5, 6]], 9} |
| 38133 |
% |
| 38134 |
% $noindent expands to |
| 38135 |
% |
| 38136 |
% 1, [2, 3, [4, 5, 6]], 9 |
| 38137 |
% |
| 38138 |
% See user manual for explanations on the plasticity of \xintexpr syntax |
| 38139 |
% regarding functions with multiple arguments, and the 1.4 «unpacking» |
| 38140 |
% Python-like * prefix operator. |
| 38141 |
% |
| 38142 |
%\end{lverb} |
| 38143 |
% |
| 38144 |
% \begin{framed} |
| 38145 |
% I have suppressed (from the public dtx) many big chunks of |
| 38146 |
% comments. Some became obsolete and need to be updated, others are |
| 38147 |
% currently of value only to the author as a historical record. |
| 38148 |
% |
| 38149 |
% ATTENTION! As the removal process itself took too much time, I ended up |
| 38150 |
% leaving as is many comments which are obsoleted and wrong to various |
| 38151 |
% degrees after the |1.4| release. Precedence levels of operators have all |
| 38152 |
% been doubled to make room for new constructs |
| 38153 |
% |
| 38154 |
% Even comments added during 1.4 developement may now be obsolete because |
| 38155 |
% the preparation of 1.4 took a few weeks and that's enough of duration to |
| 38156 |
% provide the author many chances to contradict in the code what has been |
| 38157 |
% already commented upon. |
| 38158 |
% |
| 38159 |
% Thus don't believe (fully) anything which is said here!\IMPORTANTf{} |
| 38160 |
% \end{framed} |
| 38161 |
% |
| 38162 |
% |
| 38163 |
%\begin{lverb} |
| 38164 |
% Warning: in text below and also in left-over old comments I may refer |
| 38165 |
% to «until» and «op» macros; due to the change of data storage at 1.4, I |
| 38166 |
% needed to refactor a bit the way expansion is controlled, and the situation |
| 38167 |
% now is mainly governed by «op», «exec», «check-» and «checkp» macros the |
| 38168 |
% latter three replacing the two «until_a» and «until_b» of former code. This |
| 38169 |
% allows to diminish the number of times an accumulated result will be grabbed |
| 38170 |
% in order to propagate expansion to its right. Formerly this was not an issue |
| 38171 |
% because such things were only a single token! I do not describe here how |
| 38172 |
% this is all articulated but it is not hard to see it from the code (the |
| 38173 |
% hardest thing in all such matter was in 2013 to actually write how the |
| 38174 |
% expansion would be initially launched because to do that one basically has to |
| 38175 |
% understand the mechanism in its whole and such things are not easy to |
| 38176 |
% develop piecemeal). Another thing to keep in mind is that operators in truth |
| 38177 |
% have a left precedence (i.e. the precedence they show to operators arising |
| 38178 |
% earlier) and a right precedence (which determines how they react to |
| 38179 |
% operators coming after them from the right). Only the first one is usually |
| 38180 |
% encapsulated in a chardef, the second one is most of the times identical to |
| 38181 |
% the first one and if not it is only virtual but implemented via \ifcase of |
| 38182 |
% \ifnum branching. A final remark is that some things are achieved by special |
| 38183 |
% «op» macros, which are a favorite tool to hack into the normal regular flow |
| 38184 |
% of things, via injection of special syntax elements. I did not rename these |
| 38185 |
% macros for avoiding too large git diffs, and besides the nice thing is that |
| 38186 |
% the 1.4 refactoring minimally had to modify them, and all hacky things using |
| 38187 |
% them kept on working with not a single modification. And a post-scriptum is |
| 38188 |
% that advanced features crucially exploit injecting sub-\xintexpr-essions, as |
| 38189 |
% all is expandable there is no real «context» (only a minimal one) which one |
| 38190 |
% would have to perhaps store and restore and doing this sub-expression |
| 38191 |
% injection is rather cheap and efficient operation. |
| 38192 |
%\end{lverb} |
| 38193 |
% |
| 38194 |
% \subsection{Old comments} |
| 38195 |
% |
| 38196 |
% These general comments were last updated at the end of the |1.09x| series in |
| 38197 |
% 2014. The principles remain in place to this day but refer to |
| 38198 |
% \href{http://www.ctan.org/pkg/xint/CHANGES.html}{CHANGES.html} for some |
| 38199 |
% significant evolutions since. |
| 38200 |
% |
| 38201 |
% The first version was released in June 2013. I was greatly helped in this task |
| 38202 |
% of writing an expandable parser of infix operations by the comments provided |
| 38203 |
% in |l3fp-parse.dtx| (in its version as available in April-May 2013). One will |
| 38204 |
% recognize in particular the idea of the `until' macros; I have not looked into |
| 38205 |
% the actual |l3fp| code beyond the very useful comments provided in its |
| 38206 |
% documentation. |
| 38207 |
% |
| 38208 |
% A main worry was that my data has no a priori bound on its size; to keep the |
| 38209 |
% code reasonably efficient, I experimented with a technique of storing and |
| 38210 |
% retrieving data expandably as \emph{names} of control sequences. Intermediate |
| 38211 |
% computation results are stored as control sequences |\.=a/b[n]|. |
| 38212 |
% |
| 38213 |
% |
| 38214 |
% Roughly speaking, the parser mechanism is as follows: at any given time the |
| 38215 |
% last found ``operator'' has its associated |until| macro awaiting some news |
| 38216 |
% from the token flow; first |getnext| expands forward in the hope to construct |
| 38217 |
% some number, which may come from a parenthesized sub-expression, from some |
| 38218 |
% braced material, or from a digit by digit scan. After this number has been |
| 38219 |
% formed the next operator is looked for by the |getop| macro. Once |getop| has |
| 38220 |
% finished its job, |until| is presented with three tokens: the first one is the |
| 38221 |
% precedence level of the new found operator (which may be an end of expression |
| 38222 |
% marker), the second is the operator character token (earlier versions had here |
| 38223 |
% already some macro name, but in order to keep as much common code to expr and |
| 38224 |
% floatexpr common as possible, this was modified) of the new found operator, and |
| 38225 |
% the third one is the newly found number (which was encountered just before the |
| 38226 |
% new operator). |
| 38227 |
% |
| 38228 |
% The |until| macro of the earlier operator examines the precedence level of the |
| 38229 |
% new found one, and either executes the earlier operator (in the case of a |
| 38230 |
% binary operation, with the found number and a previously stored one) or it |
| 38231 |
% delays execution, giving the hand to the |until| macro of the operator having |
| 38232 |
% been found of higher precedence. |
| 38233 |
% |
| 38234 |
% A minus sign acting as prefix gets converted into a (unary) operator |
| 38235 |
% inheriting the precedence level of the previous operator. |
| 38236 |
% |
| 38237 |
% Once the end of the expression is found (it has to be marked by a |\relax|) |
| 38238 |
% the final result is output as four tokens (five tokens since |1.09j|) the |
| 38239 |
% first one a catcode 11 exclamation mark, the second one an error generating |
| 38240 |
% macro, the third one is a protection mechanism, the fourth one a printing |
| 38241 |
% macro and the fifth is |\.=a/b[n]|. The prefix |\xintthe| makes the output |
| 38242 |
% printable by killing the first three tokens. |
| 38243 |
% |
| 38244 |
% |
| 38245 |
% \subsection{Catcodes, \protect\eTeX{} and reload detection} |
| 38246 |
% |
| 38247 |
% The code for reload detection was initially copied from \textsc{Heiko |
| 38248 |
% Oberdiek}'s packages, then modified. |
| 38249 |
% |
| 38250 |
% The method for catcodes was also initially directly inspired by these |
| 38251 |
% packages. |
| 38252 |
% |
| 38253 |
% \begin{macrocode} |
| 38254 |
\begingroup\catcode61\catcode48\catcode32=10\relax% |
| 38255 |
\catcode13=5 % ^^M |
| 38256 |
\endlinechar=13 % |
| 38257 |
\catcode123=1 % { |
| 38258 |
\catcode125=2 % } |
| 38259 |
\catcode64=11 % @ |
| 38260 |
\catcode44=12 % , |
| 38261 |
\catcode46=12 % . |
| 38262 |
\catcode58=12 % : |
| 38263 |
\catcode94=7 % ^ |
| 38264 |
\def\empty{}\def\space{ }\newlinechar10 |
| 38265 |
\def\z{\endgroup}% |
| 38266 |
\expandafter\let\expandafter\x\csname [email protected]\endcsname |
| 38267 |
\expandafter\let\expandafter\w\csname [email protected]\endcsname |
| 38268 |
\expandafter\let\expandafter\t\csname [email protected]\endcsname |
| 38269 |
\expandafter\let\expandafter\b\csname [email protected]\endcsname |
| 38270 |
% I assume engines do not exist providing \expanded but not \numexpr |
| 38271 |
\expandafter\ifx\csname expanded\endcsname\relax |
| 38272 |
\expandafter\ifx\csname PackageWarningNoLine\endcsname\relax |
| 38273 |
\immediate\write128{^^JPackage xintexpr Warning:^^J% |
| 38274 |
\space\space\space\space |
| 38275 |
\expanded not available, aborting input.^^J}% |
| 38276 |
\else |
| 38277 |
\PackageWarningNoLine{xintexpr}{\expanded not available, aborting input}% |
| 38278 |
\fi |
| 38279 |
\def\z{\endgroup\endinput}% |
| 38280 |
\else |
| 38281 |
\ifx\x\relax % not LaTeX (perhaps Plain+miniltx), first loading of xintexpr.sty |
| 38282 |
\ifx\w\relax % but xintfrac.sty not yet loaded (made miniltx robust 2022/06/09) |
| 38283 |
\expandafter\def\expandafter\z\expandafter |
| 38284 |
{\z\input xintfrac.sty\relax}% |
| 38285 |
\fi |
| 38286 |
\ifx\t\relax % but xinttools.sty not yet loaded. |
| 38287 |
\expandafter\def\expandafter\z\expandafter |
| 38288 |
{\z\input xinttools.sty\relax}% |
| 38289 |
\fi |
| 38290 |
\ifx\b\relax % but xintbinhex.sty not yet loaded. |
| 38291 |
\expandafter\def\expandafter\z\expandafter |
| 38292 |
{\z\input xintbinhex.sty\relax}% |
| 38293 |
\fi |
| 38294 |
\else |
| 38295 |
\ifx\x\empty % LaTeX, first loading, |
| 38296 |
% variable is initialized, but \ProvidesPackage not yet seen |
| 38297 |
\ifx\w\relax % xintfrac not yet loaded. |
| 38298 |
\expandafter\def\expandafter\z\expandafter |
| 38299 |
{\z\RequirePackage{xintfrac}}% |
| 38300 |
\fi |
| 38301 |
\ifx\t\relax % xinttools not yet loaded. |
| 38302 |
\expandafter\def\expandafter\z\expandafter |
| 38303 |
{\z\RequirePackage{xinttools}}% |
| 38304 |
\fi |
| 38305 |
\ifx\b\relax % xintbinhex not yet loaded. |
| 38306 |
\expandafter\def\expandafter\z\expandafter |
| 38307 |
{\z\RequirePackage{xintbinhex}}% |
| 38308 |
\fi |
| 38309 |
\else |
| 38310 |
\def\z{\endgroup\endinput}% xintexpr already loaded. |
| 38311 |
\fi |
| 38312 |
\fi |
| 38313 |
\fi |
| 38314 |
\z% |
| 38315 |
\XINTsetupcatcodes% |
| 38316 |
% \end{macrocode} |
| 38317 |
% \subsection{Package identification} |
| 38318 |
% The |!| is of catcode LETTER for most of the duration of the package. Prior |
| 38319 |
% to |1.4| it was the first token in the complete expansion of |
| 38320 |
% |\xintexpr...\relax| (i.e. without |\xintthe| prefix). It has since lost to |
| 38321 |
% |\XINTfstop| this prominent rôle, but its usage in various places of the |
| 38322 |
% code as delimiter in otherwise catcode 12 contexts has stuck. |
| 38323 |
% \begin{macrocode} |
| 38324 |
\XINT_providespackage |
| 38325 |
\ProvidesPackage{xintexpr}% |
| 38326 |
[2025/09/06 v1.4o Expandable expression parser (JFB)]% |
| 38327 |
\catcode`! 11 |
| 38328 |
% \end{macrocode} |
| 38329 |
% \subsection{\csh{XINTfstop}} |
| 38330 |
% \added{1.4} |
| 38331 |
% |
| 38332 |
% This replaced in 2019 the legacy usage of a catcode 11 exclamation mark to |
| 38333 |
% signal the start of a sub-expression (it was followed by some other tokens). |
| 38334 |
% |
| 38335 |
% |
| 38336 |
% From 2022 (aiming at |1.5|) to 2025 (releasing |1.4n|) I had replaced the |
| 38337 |
% definition used here with a fancier one originating in a ``fake'' \cs{relax} |
| 38338 |
% from \ctanpackage{unravel}. |
| 38339 |
% I think in 2022, \ctanpackage{unravel} used a frozen let to |\the|, which I |
| 38340 |
% had transferred here as a definition of |\XINTfstop|, now reverted. When I |
| 38341 |
% checked again \ctanpackage{unravel} in 2025, I saw a definition of the type |
| 38342 |
% \centeredline{|\expandafter\let\expandafter\foo\noexpand\foo|} |
| 38343 |
% |
| 38344 |
% If I did that with \cs{foo} being |\XINTfstop| then |\XINTfstop| |
| 38345 |
% would test equal via \cs{ifx} to the \ctanpackage{unravel} or any |
| 38346 |
% such |\foo| (if |\foo| is at first undefined)... |
| 38347 |
% |
| 38348 |
% The inconvenience with our more naive |\XINTfstop| here, is that |
| 38349 |
% expanding a finite number of times |\xintexpr...\relax| depends |
| 38350 |
% on parity of number of expansions. Not really a problem as far as |
| 38351 |
% I can tell. The advantage is that |\ifx| will never confuse it |
| 38352 |
% with something else. |
| 38353 |
% \begin{macrocode} |
| 38354 |
\def\XINTfstop{\noexpand\XINTfstop}% |
| 38355 |
% \end{macrocode} |
| 38356 |
% \subsection{\csh{xintDigits*}, \csh{xintSetDigits*}, \csh{xintreloadscilibs}} |
| 38357 |
%\begin{lverb} |
| 38358 |
% 1.3f. 1.4e added some \xintGuardDigits and \XINTdigitsx mechanism but |
| 38359 |
% it was finally removed, due to pending issues of user interface, |
| 38360 |
% functionality, and documentation (the worst part) for whose resolution |
| 38361 |
% no time was left. |
| 38362 |
%\end{lverb} |
| 38363 |
% \begin{macrocode} |
| 38364 |
\def\xintreloadscilibs{\xintreloadxintlog\xintreloadxinttrig}% |
| 38365 |
\def\xintDigits {\futurelet\XINT_token\xintDigits_i}% |
| 38366 |
\def\xintDigits_i#1={\afterassignment\xintDigits_j\mathchardef\XINT_digits=}% |
| 38367 |
\def\xintDigits_j#1% |
| 38368 |
{% |
| 38369 |
\let\XINTdigits=\XINT_digits |
| 38370 |
\ifx*\XINT_token\expandafter\xintreloadscilibs\fi |
| 38371 |
}% |
| 38372 |
\let\xintfracSetDigits\xintSetDigits |
| 38373 |
\def\xintSetDigits#1#{\if\relax\detokenize{#1}\relax\expandafter\xintfracSetDigits |
| 38374 |
\else\expandafter\xintSetDigits_a\fi}% |
| 38375 |
\def\xintSetDigits_a#1% |
| 38376 |
{% |
| 38377 |
\mathchardef\XINT_digits=\numexpr#1\relax |
| 38378 |
\let\XINTdigits\XINT_digits |
| 38379 |
\xintreloadscilibs |
| 38380 |
}% |
| 38381 |
% \end{macrocode} |
| 38382 |
% |
| 38383 |
% \subsection{\csh{XINTdigitsormax}} |
| 38384 |
%\begin{lverb} |
| 38385 |
% 1.4f. To not let xintlog and xinttrig work with, and produce, |
| 38386 |
% long mantissas exceeeding the supported range for accuracy of the math |
| 38387 |
% functions. The official maximal value is 62, let's set the cut-off at 64. |
| 38388 |
% |
| 38389 |
% A priori, no need for \expandafter, always ends up expanded in \numexpr (I |
| 38390 |
% saw also in an \edef in xinttrig as argument to \xintReplicate prior |
| 38391 |
% to its \numexpr). |
| 38392 |
%\end{lverb} |
| 38393 |
% \begin{macrocode} |
| 38394 |
\def\XINTdigitsormax{\ifnum\XINTdigits>\xint_c_ii^vi\xint_c_ii^vi\else\XINTdigits\fi}% |
| 38395 |
% \end{macrocode} |
| 38396 |
% \subsection{Support for output and transform of nested braced contents as |
| 38397 |
% core data type} |
| 38398 |
% New at 1.4, of course. The former |\csname.=...\endcsname| encapsulation |
| 38399 |
% technique made very difficult implementation of nested structures. |
| 38400 |
% \subsubsection{Bracketed list rendering with prettifying of leaves from nested |
| 38401 |
% braced contents} |
| 38402 |
% \added{1.4} |
| 38403 |
% The braces in |\XINT:expr:toblistwith| are there because there is |
| 38404 |
% an |\expanded| trigger. |
| 38405 |
% \changed{1.4d} |
| 38406 |
%\begin{lverb} |
| 38407 |
% Add support for the polexpr 0.8 polynomial type. See \XINT:expr:toblist_a. |
| 38408 |
%\end{lverb} |
| 38409 |
% \changed{1.4l} |
| 38410 |
%\begin{lverb} |
| 38411 |
% Let \XINT:expr:toblist_b use #1{#2} with regular { and } in case |
| 38412 |
% macro #1 is \protected and things are output to external file where former |
| 38413 |
% #1<#2> would end up with catcode 12 < and >. |
| 38414 |
%\end{lverb} |
| 38415 |
% \begin{macrocode} |
| 38416 |
\def\XINT:expr:toblistwith#1#2% |
| 38417 |
{% |
| 38418 |
{\expandafter\XINT:expr:toblist_checkempty |
| 38419 |
\expanded{\noexpand#1!\expandafter}\detokenize{#2}^}% |
| 38420 |
}% |
| 38421 |
\def\XINT:expr:toblist_checkempty #1!#2% |
| 38422 |
{% |
| 38423 |
\if ^#2\expandafter\xint_gob_til_^\else\expandafter\XINT:expr:toblist_a\fi |
| 38424 |
#1!#2% |
| 38425 |
}% |
| 38426 |
\catcode`< 1 \catcode`> 2 \catcode`{ 12 \catcode`} 12 |
| 38427 |
\def\XINT:expr:toblist_a #1{#2% |
| 38428 |
<% |
| 38429 |
\if{#2\xint_dothis<[\XINT:expr:toblist_a>\fi |
| 38430 |
\if P#2\xint_dothis<\XINT:expr:toblist_pol>\fi |
| 38431 |
\xint_orthat\XINT:expr:toblist_b #1#2% |
| 38432 |
>% |
| 38433 |
\def\XINT:expr:toblist_pol #1!#2.{#3}}% |
| 38434 |
<% |
| 38435 |
pol([\XINT:expr:toblist_b #1!#3}^])\XINT:expr:toblist_c #1!}% |
| 38436 |
>% |
| 38437 |
\catcode`{ 1 \catcode`} 2 |
| 38438 |
\def\XINT:expr:toblist_b #1{% |
| 38439 |
\def\XINT:expr:toblist_b ##1!##2#1% |
| 38440 |
{% |
| 38441 |
\if\relax##2\relax\xintexprEmptyItem\else##1{##2}\fi\XINT:expr:toblist_c ##1!#1% |
| 38442 |
}}\catcode`{ 12 \catcode`} 12 \XINT:expr:toblist_b<}>% |
| 38443 |
\def\XINT:expr:toblist_c #1}#2% |
| 38444 |
<% |
| 38445 |
\if ^#2\xint_dothis<\xint_gob_til_^>\fi |
| 38446 |
\if{#2\xint_dothis<, \XINT:expr:toblist_a>\fi |
| 38447 |
\xint_orthat<]\XINT:expr:toblist_c>#1#2% |
| 38448 |
>% |
| 38449 |
\catcode`{ 1 \catcode`} 2 \catcode`< 12 \catcode`> 12 |
| 38450 |
% \end{macrocode} |
| 38451 |
% \subsubsection{Flattening nested |
| 38452 |
% braced contents} |
| 38453 |
%\begin{lverb} |
| 38454 |
% 1.4b I hesitated whether using this technique or some variation of |
| 38455 |
% the method of the ListSel macros. I chose this one which I downscaled from |
| 38456 |
% toblistwith, I will revisit later. I only have a few minutes right now. |
| 38457 |
% |
| 38458 |
% Call form is \expanded\XINT:expr:flatten |
| 38459 |
% |
| 38460 |
% See \XINT_expr_func_flat. I hesitated with «flattened», but short names |
| 38461 |
% are faster parsed. |
| 38462 |
%\end{lverb} |
| 38463 |
% \begin{macrocode} |
| 38464 |
\def\XINT:expr:flatten#1% |
| 38465 |
{% |
| 38466 |
{{\expandafter\XINT:expr:flatten_checkempty\detokenize{#1}^}}% |
| 38467 |
}% |
| 38468 |
\def\XINT:expr:flatten_checkempty #1% |
| 38469 |
{% |
| 38470 |
\if ^#1\expandafter\xint_gobble_i\else\expandafter\XINT:expr:flatten_a\fi |
| 38471 |
#1% |
| 38472 |
}% |
| 38473 |
\begingroup |
| 38474 |
\catcode`[ 1 \catcode`] 2 \lccode`[`{ \lccode`]`} |
| 38475 |
\catcode`< 1 \catcode`> 2 \catcode`{ 12 \catcode`} 12 |
| 38476 |
\lowercase<\endgroup |
| 38477 |
\def\XINT:expr:flatten_a {#1% |
| 38478 |
<% |
| 38479 |
\if{#1\xint_dothis<\XINT:expr:flatten_a>\fi |
| 38480 |
\xint_orthat\XINT:expr:flatten_b #1% |
| 38481 |
>% |
| 38482 |
\def\XINT:expr:flatten_b #1}% |
| 38483 |
<% |
| 38484 |
[#1]\XINT:expr:flatten_c }% |
| 38485 |
>% |
| 38486 |
\def\XINT:expr:flatten_c }#1% |
| 38487 |
<% |
| 38488 |
\if ^#1\xint_dothis<\xint_gobble_i>\fi |
| 38489 |
\if{#1\xint_dothis<\XINT:expr:flatten_a>\fi |
| 38490 |
\xint_orthat<\XINT:expr:flatten_c>#1% |
| 38491 |
>% |
| 38492 |
>% back to normal catcodes |
| 38493 |
% \end{macrocode} |
| 38494 |
% \subsubsection{Braced contents rendering via a \TeX{} alignment with prettifying of leaves} |
| 38495 |
%\begin{lverb} |
| 38496 |
% 1.4. |
| 38497 |
% |
| 38498 |
% Breaking change at 1.4a as helper macros were renamed and their meanings |
| 38499 |
% refactored: no more \xintexpraligntab nor \xintexpraligninnercomma or |
| 38500 |
% \xintexpralignoutercomma but \xintexpraligninnersep, etc... |
| 38501 |
% |
| 38502 |
% At 1.4c I remove the \protected from \xintexpralignend. I had made note a |
| 38503 |
% year ago that it served nothing. Let's trust myself on this one (risky one |
| 38504 |
% year later!). |
| 38505 |
%\end{lverb} |
| 38506 |
% \begin{macrocode} |
| 38507 |
\catcode`& 4 |
| 38508 |
\protected\def\xintexpralignbegin {\halign\bgroup\tabskip2ex\hfil##&&##\hfil\cr}% |
| 38509 |
\def\xintexpralignend {\crcr\egroup}% |
| 38510 |
\protected\def\xintexpralignlinesep {,\cr}% |
| 38511 |
\protected\def\xintexpralignleftbracket {[}% |
| 38512 |
\protected\def\xintexpralignrightbracket{]}% |
| 38513 |
\protected\def\xintexpralignleftsep {&}% |
| 38514 |
\protected\def\xintexpralignrightsep {&}% |
| 38515 |
\protected\def\xintexpraligninnersep {,&}% |
| 38516 |
\catcode`& 7 |
| 38517 |
\def\XINT:expr:toalignwith#1#2% |
| 38518 |
{% |
| 38519 |
{\expandafter\XINT:expr:toalign_checkempty |
| 38520 |
\expanded{\noexpand#1!\expandafter}\detokenize{#2}^\expandafter}% |
| 38521 |
\xintexpralignend |
| 38522 |
}% |
| 38523 |
\def\XINT:expr:toalign_checkempty #1!#2% |
| 38524 |
{% |
| 38525 |
\if ^#2\expandafter\xint_gob_til_^\else\expandafter\XINT:expr:toalign_a\fi |
| 38526 |
#1!#2% |
| 38527 |
}% |
| 38528 |
\catcode`< 1 \catcode`> 2 \catcode`{ 12 \catcode`} 12 |
| 38529 |
\def\XINT:expr:toalign_a #1{#2% |
| 38530 |
<% |
| 38531 |
\if{#2\xint_dothis<\xintexpralignleftbracket\XINT:expr:toalign_a>\fi |
| 38532 |
\xint_orthat<\xintexpralignleftsep\XINT:expr:toalign_b>#1#2% |
| 38533 |
>% |
| 38534 |
\def\XINT:expr:toalign_b #1!#2}% |
| 38535 |
<% |
| 38536 |
\if\relax#2\relax\xintexprEmptyItem\else#1<#2>\fi\XINT:expr:toalign_c #1!}% |
| 38537 |
>% |
| 38538 |
\def\XINT:expr:toalign_c #1}#2% |
| 38539 |
<% |
| 38540 |
\if ^#2\xint_dothis<\xint_gob_til_^>\fi |
| 38541 |
\if {#2\xint_dothis<\xintexpraligninnersep\XINT:expr:toalign_A>\fi |
| 38542 |
\xint_orthat<\xintexpralignrightsep\xintexpralignrightbracket\XINT:expr:toalign_C>#1#2% |
| 38543 |
>% |
| 38544 |
\def\XINT:expr:toalign_A #1{#2% |
| 38545 |
<% |
| 38546 |
\if{#2\xint_dothis<\xintexpralignleftbracket\XINT:expr:toalign_A>\fi |
| 38547 |
\xint_orthat\XINT:expr:toalign_b #1#2% |
| 38548 |
>% |
| 38549 |
\def\XINT:expr:toalign_C #1}#2% |
| 38550 |
<% |
| 38551 |
\if ^#2\xint_dothis<\xint_gob_til_^>\fi |
| 38552 |
\if {#2\xint_dothis<\xintexpralignlinesep\XINT:expr:toalign_a>\fi |
| 38553 |
\xint_orthat<\xintexpralignrightbracket\XINT:expr:toalign_C>#1#2% |
| 38554 |
>% |
| 38555 |
\catcode`{ 1 \catcode`} 2 \catcode`< 12 \catcode`> 12 |
| 38556 |
% \end{macrocode} |
| 38557 |
% \subsubsection{Transforming all leaves within nested |
| 38558 |
% braced contents} |
| 38559 |
% |
| 38560 |
%\begin{lverb} |
| 38561 |
% 1.4. Leaves must be of catcode 12... This is currently not a |
| 38562 |
% constraint (or rather not a new constraint) for xintexpr because formerly |
| 38563 |
% anyhow all data went through csname encapsulation and extraction via string. |
| 38564 |
% |
| 38565 |
% In order to share code with the functioning of universal functions, which |
| 38566 |
% will be allowed to transform a number into an ople, the applied macro |
| 38567 |
% is supposed to apply one level of bracing to its ouput. Thus to apply this |
| 38568 |
% with an xintfrac macro such as \xintiRound{0} one needs first to define |
| 38569 |
% a wrapper which will expand it inside an added brace pair: |
| 38570 |
% |
| 38571 |
% \def\foo#1{{\xintiRound{0}{#1}}} |
| 38572 |
% |
| 38573 |
% As the things will expand inside expanded, propagating expansion is not an |
| 38574 |
% issue. |
| 38575 |
% |
| 38576 |
% This code is used by \xintiexpr and \xintfloatexpr in case of optional |
| 38577 |
% argument and by the «Universal functions». |
| 38578 |
% |
| 38579 |
% Comment at 1.4l: this seems to be used only at private package level, else |
| 38580 |
% I should modify \XINT:expr:mapwithin_b like I did with \XINT:expr:toblist_b |
| 38581 |
% to use regular braces in case the applied macro is \protected and |
| 38582 |
% things end up in external file. |
| 38583 |
%\end{lverb} |
| 38584 |
% |
| 38585 |
% \begin{macrocode} |
| 38586 |
\def\XINT:expr:mapwithin#1#2% |
| 38587 |
{% |
| 38588 |
{{\expandafter\XINT:expr:mapwithin_checkempty |
| 38589 |
\expanded{\noexpand#1!\expandafter}\detokenize{#2}^}}% |
| 38590 |
}% |
| 38591 |
\def\XINT:expr:mapwithin_checkempty #1!#2% |
| 38592 |
{% |
| 38593 |
\if ^#2\expandafter\xint_gob_til_^\else\expandafter\XINT:expr:mapwithin_a\fi |
| 38594 |
#1!#2% |
| 38595 |
}% |
| 38596 |
\begingroup |
| 38597 |
\catcode`[ 1 \catcode`] 2 \lccode`[`{ \lccode`]`} |
| 38598 |
\catcode`< 1 \catcode`> 2 \catcode`{ 12 \catcode`} 12 |
| 38599 |
\lowercase<\endgroup |
| 38600 |
\def\XINT:expr:mapwithin_a #1{#2% |
| 38601 |
<% |
| 38602 |
\if{#2\xint_dothis<[\iffalse]\fi\XINT:expr:mapwithin_a>\fi% |
| 38603 |
\xint_orthat\XINT:expr:mapwithin_b #1#2% |
| 38604 |
>% |
| 38605 |
\def\XINT:expr:mapwithin_b #1!#2}% |
| 38606 |
<% |
| 38607 |
#1<#2>\XINT:expr:mapwithin_c #1!}% |
| 38608 |
>% |
| 38609 |
\def\XINT:expr:mapwithin_c #1}#2% |
| 38610 |
<% |
| 38611 |
\if ^#2\xint_dothis<\xint_gob_til_^>\fi |
| 38612 |
\if{#2\xint_dothis<\XINT:expr:mapwithin_a>\fi% |
| 38613 |
\xint_orthat<\iffalse[\fi]\XINT:expr:mapwithin_c>#1#2% |
| 38614 |
>% |
| 38615 |
>% back to normal catcodes |
| 38616 |
% \end{macrocode} |
| 38617 |
% \subsection{Top level user \TeX{} interface: \cshnolabel{xinteval}, |
| 38618 |
% \cshnolabel{xintfloateval}, \cshnolabel{xintiieval}} |
| 38619 |
% \localtableofcontents |
| 38620 |
% \subsubsection{\csh{xintexpr}, \csh{xintiexpr}, \csh{xintfloatexpr}, |
| 38621 |
% \csh{xintiiexpr}} |
| 38622 |
%\begin{lverb} |
| 38623 |
% |
| 38624 |
% \xintiexpr and \xintfloatexpr have an optional argument since 1.1. |
| 38625 |
% |
| 38626 |
% ATTENTION! 1.3d renamed \xinteval to \xintexpro etc... |
| 38627 |
% |
| 38628 |
% |
| 38629 |
% Usage of \xintiRound{0} for \xintiexpr without optional [D] means that |
| 38630 |
% \xintiexpr ... \relax wrapper can be used to insert rounded-to-integers |
| 38631 |
% values in \xintiiexpr context: no post-fix [0] which would break it. |
| 38632 |
% |
| 38633 |
% 1.4a add support for the optional argument [D] for \xintiexpr being negative |
| 38634 |
% D, with same meaning as the 1.4a modified \xintRound from xintfrac.sty. |
| 38635 |
% |
| 38636 |
% \xintiexpr mechanism was refactored at 1.4e so that rounding due to [D] |
| 38637 |
% optional argument uses raw format, not fixed point format on output, |
| 38638 |
% delegating fixed point conversion to an \XINTiexprprint now separated from |
| 38639 |
% \XINTexprprint. |
| 38640 |
% |
| 38641 |
% In case of negative [D], \xintiexpr [D]...\relax internally has the [0] |
| 38642 |
% post-fix so it can not be inserted as sub-expression in \xintiiexpr without |
| 38643 |
% a num() or \xintiexpr ...\relax (extra) wrapper. |
| 38644 |
% |
| 38645 |
%\end{lverb} |
| 38646 |
% |
| 38647 |
% \changed{1.4o} |
| 38648 |
% |
| 38649 |
% While preparing |1.4n| I had made changes to tame Babel active characters |
| 38650 |
% via a |\csname| trick. But at last minute I thought I had a way requiring |
| 38651 |
% not so many ``top level'' changes, but this was a grave logic error on my |
| 38652 |
% part, due to having a bit forgotten the way things are done here, and due |
| 38653 |
% also to external circumstances I released too hastily a |1.4n| which turned |
| 38654 |
% out to be faulty (except for \csbxint{iieval}). Any test other than simply |
| 38655 |
% evaluating |3!| with |!| Babel active would have revealed it but I was |
| 38656 |
% planning to add test units after (!) release (by the way one has to be |
| 38657 |
% careful to do such tests after a |\noindent| because the French active |!| |
| 38658 |
% in vertical mode does things not breaking the parser. Anyway, here I do it |
| 38659 |
% right. |
| 38660 |
% |
| 38661 |
% So this is why for example |\xintexpro| has a |\csname| construct. |
| 38662 |
% \begin{macrocode} |
| 38663 |
\def\xintexpr {\romannumeral0\xintexpro }% |
| 38664 |
\def\xintiexpr {\romannumeral0\xintiexpro }% |
| 38665 |
\def\xintfloatexpr {\romannumeral0\xintfloatexpro }% |
| 38666 |
\def\xintiiexpr {\romannumeral0\xintiiexpro }% |
| 38667 |
\def\xintexpro {\csname XINT_expr_wrap\expandafter\endcsname |
| 38668 |
\romannumeral0\xintbareeval }% |
| 38669 |
\def\xintiiexpro {\csname XINT_iiexpr_wrap\expandafter\endcsname |
| 38670 |
\romannumeral0\xintbareiieval }% |
| 38671 |
\def\xintiexpro #1% |
| 38672 |
{% |
| 38673 |
\ifx [#1\expandafter\XINT_iexpr_withopt\else\expandafter\XINT_iexpr_noopt |
| 38674 |
\fi #1% |
| 38675 |
}% |
| 38676 |
\def\XINT_iexpr_noopt |
| 38677 |
{% |
| 38678 |
\csname XINT_iexpr_iiround\expandafter\endcsname\romannumeral0\xintbareeval |
| 38679 |
}% |
| 38680 |
\def\XINT_iexpr_iiround |
| 38681 |
{% |
| 38682 |
\expandafter\XINT_expr_wrap |
| 38683 |
\expanded |
| 38684 |
\XINT:NEhook:x:mapwithin\XINT:expr:mapwithin{\XINTiRoundzero_braced}% |
| 38685 |
}% |
| 38686 |
\def\XINTiRoundzero_braced#1{{\xintiRound{0}{#1}}}% |
| 38687 |
\def\XINT_iexpr_withopt [#1]% |
| 38688 |
{% |
| 38689 |
\csname XINT_iexpr_round\expandafter\endcsname |
| 38690 |
\the\numexpr \xint_zapspaces #1 \xint_gobble_i\expandafter.% |
| 38691 |
\romannumeral0\xintbareeval |
| 38692 |
}% |
| 38693 |
\def\XINT_iexpr_round #1.% |
| 38694 |
{% |
| 38695 |
\ifnum#1=\xint_c_\xint_dothis{\XINT_iexpr_iiround}\fi |
| 38696 |
\xint_orthat{\XINT_iexpr_round_a #1.}% |
| 38697 |
}% |
| 38698 |
\def\XINT_iexpr_round_a #1.% |
| 38699 |
{% |
| 38700 |
\expandafter\XINT_iexpr_wrap |
| 38701 |
\expanded |
| 38702 |
\XINT:NEhook:x:mapwithin\XINT:expr:mapwithin{\XINTiRound_braced{#1}}% |
| 38703 |
}% |
| 38704 |
\def\XINTiRound_braced#1#2% |
| 38705 |
{{\xintiRound{#1}{#2}[\the\numexpr\ifnum#1<\xint_c_i0\else-#1\fi]}}% |
| 38706 |
\def\xintfloatexpro #1% |
| 38707 |
{% |
| 38708 |
\ifx [#1\expandafter\XINT_flexpr_withopt\else\expandafter\XINT_flexpr_noopt |
| 38709 |
\fi #1% |
| 38710 |
}% |
| 38711 |
\def\XINT_flexpr_noopt |
| 38712 |
{% |
| 38713 |
\csname XINT_flexpr_wrap\expandafter\endcsname |
| 38714 |
\the\numexpr\XINTdigits\expandafter.% |
| 38715 |
\romannumeral0\xintbarefloateval |
| 38716 |
}% |
| 38717 |
\def\XINT_flexpr_withopt [#1]% |
| 38718 |
{% |
| 38719 |
\csname XINT_flexpr_withopt_a\expandafter\endcsname |
| 38720 |
\the\numexpr\xint_zapspaces #1 \xint_gobble_i\expandafter.% |
| 38721 |
\romannumeral0\xintbarefloateval |
| 38722 |
}% |
| 38723 |
\def\XINT_flexpr_withopt_a #1#2.% |
| 38724 |
{% |
| 38725 |
\expandafter\XINT_flexpr_withopt_b\the\numexpr\if#1-\XINTdigits\fi#1#2.% |
| 38726 |
}% |
| 38727 |
\def\XINT_flexpr_withopt_b #1.% |
| 38728 |
{% |
| 38729 |
\expandafter\XINT_flexpr_wrap |
| 38730 |
\the\numexpr#1\expandafter.% |
| 38731 |
\expanded |
| 38732 |
\XINT:NEhook:x:mapwithin\XINT:expr:mapwithin{\XINTinFloat_braced[#1]}% |
| 38733 |
}% |
| 38734 |
\def\XINTinFloat_braced[#1]#2{{\XINTinFloat[#1]{#2}}}% |
| 38735 |
% \end{macrocode} |
| 38736 |
% \subsubsection{\csh{XINT_expr_wrap}, \csh{XINT_iiexpr_wrap}, \csh{XINT_flexpr_wrap}} |
| 38737 |
%\begin{lverb} |
| 38738 |
% 1.3e removes some leading space tokens which served nothing. There is |
| 38739 |
% no \XINT_iexpr_wrap, because \XINT_expr_wrap is used directly. |
| 38740 |
% |
| 38741 |
% 1.4e has \XINT_iexpr_wrap separated from \XINT_expr_wrap, thus simplifying |
| 38742 |
% internal matters as output printer for \xintexpr will not have to handle |
| 38743 |
% fixed point input but only extended-raw type input (i.e. A, A/B, A[N] or A/B[N]). |
| 38744 |
%\end{lverb} |
| 38745 |
% \begin{macrocode} |
| 38746 |
\def\XINT_expr_wrap {\XINTfstop\XINTexprprint.}% |
| 38747 |
\def\XINT_iexpr_wrap {\XINTfstop\XINTiexprprint.}% |
| 38748 |
\def\XINT_iiexpr_wrap {\XINTfstop\XINTiiexprprint.}% |
| 38749 |
\def\XINT_flexpr_wrap {\XINTfstop\XINTflexprprint}% |
| 38750 |
% \end{macrocode} |
| 38751 |
% \subsubsection{\csh{XINTexprprint}, \csh{XINTiexprprint}, \csh{XINTiiexprprint}, \csh{XINTflexprprint}} |
| 38752 |
% \label{\xintimplabelprefix xintexprPrintOne} |
| 38753 |
% \label{\xintimplabelprefix xintiexprPrintOne} |
| 38754 |
% \label{\xintimplabelprefix xintfloatexprPrintOne} |
| 38755 |
% \label{\xintimplabelprefix xintiiexprprintone} |
| 38756 |
% |
| 38757 |
% \changed{1.4} |
| 38758 |
% Requires |\expanded|. |
| 38759 |
% |
| 38760 |
% |
| 38761 |
% \changed{1.4e} |
| 38762 |
%\begin{lverb} |
| 38763 |
% 1.4e has a breaking change of \XINTflexprprint and \xintfloatexprPrintOne |
| 38764 |
% which now requires \xintfloatexprPrintOne[D]{x} syntax, with first argument |
| 38765 |
% in brackets. |
| 38766 |
% |
| 38767 |
%\end{lverb} |
| 38768 |
% \changed{1.4l} |
| 38769 |
% The code does |\let\xintexprPrintOne\xint_FracToSci_x| but the latter is not yet |
| 38770 |
% defined so this is delayed until |\xint_FracToSci_x| definition. |
| 38771 |
% \changed[2022/06/05]{1.4m} |
| 38772 |
% \csa{xintboolexprPrintOne} outputs |true| or |false|, not |True| or |False|. |
| 38773 |
% By the way (undocumented) all four keywords |true|, |false|, |True|, |
| 38774 |
% |False| are recognized as genuine variables since |1.4i|. |
| 38775 |
% \begin{macrocode} |
| 38776 |
\protected\def\XINTexprprint.% |
| 38777 |
{\XINT:NEhook:x:toblist\XINT:expr:toblistwith\xintexprPrintOne}% |
| 38778 |
\protected\def\XINTiexprprint.% |
| 38779 |
{\XINT:NEhook:x:toblist\XINT:expr:toblistwith\xintiexprPrintOne}% |
| 38780 |
\let\xintiexprPrintOne\xintDecToString |
| 38781 |
\def\xintexprEmptyItem{[]}% |
| 38782 |
\protected\def\XINTiiexprprint.% |
| 38783 |
{\XINT:NEhook:x:toblist\XINT:expr:toblistwith\xintiiexprPrintOne}% |
| 38784 |
\let\xintiiexprPrintOne\xint_firstofone |
| 38785 |
\protected\def\XINTflexprprint #1.% |
| 38786 |
{\XINT:NEhook:x:toblist\XINT:expr:toblistwith{\xintfloatexprPrintOne[#1]}}% |
| 38787 |
\let\xintfloatexprPrintOne\xintPFloat_wopt |
| 38788 |
\protected\def\XINTboolexprprint.% |
| 38789 |
{\XINT:NEhook:x:toblist\XINT:expr:toblistwith\xintboolexprPrintOne}% |
| 38790 |
\def\xintboolexprPrintOne#1{\xintiiifNotZero{#1}{true}{false}}% |
| 38791 |
% \end{macrocode} |
| 38792 |
% \subsubsection{\csh{xintthe}, \csh{xintthealign}, \csh{xinttheexpr}, \csh{xinttheiexpr}, \csh{xintthefloatexpr}, |
| 38793 |
% \csh{xinttheiiexpr}} |
| 38794 |
%\begin{lverb} |
| 38795 |
% The reason why \xinttheiexpr et \xintthefloatexpr are handled |
| 38796 |
% differently is that they admit an optional argument which acts via a custom |
| 38797 |
% «printing» stage. |
| 38798 |
% |
| 38799 |
% We exploit here that \expanded expands forward until finding an implicit or |
| 38800 |
% explicit brace, and that this expansion overrules \protected macros, forcing |
| 38801 |
% them to expand, similarly as \romannumeral expands \protected macros, and |
| 38802 |
% contrarily to what happens *within* the actual \expanded scope. I discovered |
| 38803 |
% this fact by testing (with pdftex) and I don't know where this is documented |
| 38804 |
% apart from the source code of the relevant engines. This is useful to us |
| 38805 |
% because there are contexts where we will want to apply a complete expansion |
| 38806 |
% before printing, but in purely numerical context this is not needed (if I |
| 38807 |
% converted correctly after dropping at 1.4 the \csname governed expansions; |
| 38808 |
% however I rely at various places on the fact that the xint macros are |
| 38809 |
% f-expandable, so I have tried to not use zillions of expanded all over the |
| 38810 |
% place), hence it is not needed to add the expansion overhead by default. But |
| 38811 |
% the \expanded here will allow \xintNewExpr to create macro with suitable |
| 38812 |
% modification or the printing step, via some hook rather than having to |
| 38813 |
% duplicate all macros here with some new «NE» meaning (aliasing does not work |
| 38814 |
% or causes big issues due to desire to support \xinteval also in «NE» context |
| 38815 |
% as sub-constituent. The \XINT:NEhook:x:toblist is something else which |
| 38816 |
% serves to achieve this support of *sub* \xinteval, it serves nothing for |
| 38817 |
% the actual produced macros. For \xintdeffunc, things are simpler, but still |
| 38818 |
% we support the [N] optional argument of \xintiexpr and \xintfloatexpr, which |
| 38819 |
% required some work... |
| 38820 |
% |
| 38821 |
% The \expanded upfront ensures \xintthe mechanism does expand |
| 38822 |
% completely in two steps. |
| 38823 |
%\end{lverb} |
| 38824 |
% |
| 38825 |
% The fact that |\xintthe| grabs a |#1| is legacy and I am not sure why. I |
| 38826 |
% vaguely remember thinking the overhead was minimal because |#1| will |
| 38827 |
% simply be one token such as \csbxint{expr} and that it could potentially |
| 38828 |
% be useful. Of course |\xintthealign| imitates |\xintthe| in that matter. |
| 38829 |
% |
| 38830 |
% \changed{1.4o} |
| 38831 |
% Again here some |\csname|'s to handle babel-active characters. |
| 38832 |
% \begin{macrocode} |
| 38833 |
\def\xintthe #1{\expanded\expandafter\xint_gobble_i\romannumeral`&&@#1}% |
| 38834 |
\def\xintthealign #1{\expandafter\xintexpralignbegin |
| 38835 |
\expanded\expandafter\XINT:expr:toalignwith |
| 38836 |
\romannumeral0\expandafter\expandafter\expandafter\expandafter |
| 38837 |
\expandafter\expandafter\expandafter\xint_gob_andstop_ii |
| 38838 |
\expandafter\xint_gobble_i\romannumeral`&&@#1}% |
| 38839 |
\def\xinttheexpr |
| 38840 |
{\expanded\csname XINTexprprint\expandafter\endcsname |
| 38841 |
\expandafter.\romannumeral0\xintbareeval}% |
| 38842 |
\def\xinttheiiexpr |
| 38843 |
{\expanded\csname XINTiiexprprint\expandafter\endcsname |
| 38844 |
\expandafter.\romannumeral0\xintbareiieval}% |
| 38845 |
% \end{macrocode} |
| 38846 |
% No need at |1.4o| of |\csname|'s for Babel here, as \csbxint{iexpr} and |
| 38847 |
% \csbxint{floatexpr} are already taken care off. |
| 38848 |
% \begin{macrocode} |
| 38849 |
\def\xinttheiexpr |
| 38850 |
{\expanded\expandafter\xint_gobble_i\romannumeral`&&@\xintiexpr}% |
| 38851 |
\def\xintthefloatexpr |
| 38852 |
{\expanded\expandafter\xint_gobble_i\romannumeral`&&@\xintfloatexpr}% |
| 38853 |
% \end{macrocode} |
| 38854 |
% \subsubsection{\csh{xintbareeval}, \csh{xintbarefloateval}, \csh{xintbareiieval}} |
| 38855 |
% |
| 38856 |
% \changed{1.4} |
| 38857 |
% one expansion step added via \csbXINT{_expr_start}, |
| 38858 |
% \csbXINT{_iiexpr_start}, \csbXINT{_flexpr_start}. Trigger is expected to be |
| 38859 |
% via |\romannumeral`^^@| or |\romannumeral0|. |
| 38860 |
% |
| 38861 |
% For the benefit of those who like the author while finishing |1.4n| looked |
| 38862 |
% in vain for where the ``|_start|'' macros were defined, this documentation |
| 38863 |
% was updated so that one can find the location via clicking on their names in |
| 38864 |
% the previous paragraph. Spoiler: they are in |
| 38865 |
% \autoref{ssec:expansionspanning}. This was hidden because the three are |
| 38866 |
% defined in an \csbxint{For} in one-go. |
| 38867 |
% \begin{macrocode} |
| 38868 |
\def\xintbareeval {\XINT_expr_start }% |
| 38869 |
\def\xintbarefloateval{\XINT_flexpr_start}% |
| 38870 |
\def\xintbareiieval {\XINT_iiexpr_start}% |
| 38871 |
% \end{macrocode} |
| 38872 |
% \subsubsection{\csh{xintthebareeval}, \csh{xintthebarefloateval}, |
| 38873 |
% \csh{xintthebareiieval}} |
| 38874 |
%\begin{lverb} |
| 38875 |
% For matters of \XINT_NewFunc |
| 38876 |
%\end{lverb} |
| 38877 |
% |
| 38878 |
% \changed{1.4o} |
| 38879 |
% The matter of Babel active here too, although they are used for \csbxint{deffunc} |
| 38880 |
% and \csbxint{NewExpr} which sanitize catcodes. But I already edited the |
| 38881 |
% user documentation to explain the case of contexts where changing catcodes |
| 38882 |
% is impossible, and would be too time-costly to re-edit that. So let's add |
| 38883 |
% some overhead. |
| 38884 |
% \begin{macrocode} |
| 38885 |
\def\XINT_expr_unlock {\expandafter\xint_firstofone\romannumeral`&&@}% |
| 38886 |
\def\xintthebareeval |
| 38887 |
{\romannumeral0\csname xint_stop_atfirstofone\expandafter\endcsname |
| 38888 |
\romannumeral0\xintbareeval}% |
| 38889 |
\def\xintthebareiieval |
| 38890 |
{\romannumeral0\csname xint_stop_atfirstofone\expandafter\endcsname |
| 38891 |
\romannumeral0\xintbareiieval}% |
| 38892 |
\def\xintthebarefloateval |
| 38893 |
{\romannumeral0\csname xint_stop_atfirstofone\expandafter\endcsname |
| 38894 |
\romannumeral0\xintbarefloateval}% |
| 38895 |
\def\xintthebareroundedfloateval |
| 38896 |
{% |
| 38897 |
\romannumeral0\csname xintthebareroundedfloateval_a\expandafter\endcsname |
| 38898 |
\romannumeral0\xintbarefloateval |
| 38899 |
}% |
| 38900 |
\def\xintthebareroundedfloateval_a |
| 38901 |
{% |
| 38902 |
\expandafter\xint_stop_atfirstofone |
| 38903 |
\expanded\XINT:NEhook:x:mapwithin\XINT:expr:mapwithin{\XINTinFloatSdigits_braced}% |
| 38904 |
}% |
| 38905 |
\def\XINTinFloatSdigits_braced#1{{\XINTinFloatS[\XINTdigits]{#1}}}% |
| 38906 |
% \end{macrocode} |
| 38907 |
% \subsubsection{\csh{xinteval}, \csh{xintieval}, \csh{xintfloateval}, |
| 38908 |
% \csh{xintiieval}} |
| 38909 |
%\begin{lverb} |
| 38910 |
% Refactored at 1.4. |
| 38911 |
% |
| 38912 |
% The \expanded upfront ensures \xinteval still expands |
| 38913 |
% completely in two steps. No \romannumeral trigger here, in relation to the |
| 38914 |
% fact that \XINTexprprint is not f-expandable, only e-expandable. |
| 38915 |
% |
| 38916 |
% (and attention that \xintexpr\relax is now legal, and an empty ople can be |
| 38917 |
% produced in output also from \xintexpr [17][1]\relax for example) |
| 38918 |
%\end{lverb} |
| 38919 |
% \changed[2022/05/16]{1.4k} |
| 38920 |
% |
| 38921 |
% The \csbxint{ieval} and \csbxint{floateval} optional bracketed argument can now |
| 38922 |
% be located outside the braces... took me years to finally make the step towards LaTeX |
| 38923 |
% users expectations for the interface. |
| 38924 |
% |
| 38925 |
% \changed{1.4o} |
| 38926 |
% Some |\csname|'s for the Babel-active feature which was botched at |1.4n|. |
| 38927 |
% \begin{macrocode} |
| 38928 |
\def\xinteval #1% |
| 38929 |
{\expanded\csname XINTexprprint\expandafter\endcsname |
| 38930 |
\expandafter.\romannumeral0\xintbareeval#1\relax}% |
| 38931 |
\def\xintieval{\expanded\expandafter\xint_ieval_chkopt\string}% |
| 38932 |
\def\xint_ieval_chkopt #1% |
| 38933 |
{% |
| 38934 |
\ifx [#1\expandafter\xint_ieval_opt |
| 38935 |
\else\expandafter\xint_ieval_noopt |
| 38936 |
\fi #1% |
| 38937 |
}% |
| 38938 |
\def\xint_ieval_opt [#1]#2% |
| 38939 |
{\expandafter\xint_gobble_i\romannumeral`&&@\xintiexpr[#1]#2\relax}% |
| 38940 |
\def\xint_ieval_noopt #1{\expandafter\xint_ieval\expandafter{\iffalse}\fi}% |
| 38941 |
\def\xint_ieval#1% |
| 38942 |
{\expandafter\xint_gobble_i\romannumeral`&&@\xintiexpr#1\relax}% |
| 38943 |
\def\xintfloateval {\expanded\expandafter\xint_floateval_chkopt\string}% |
| 38944 |
\def\xint_floateval_chkopt #1% |
| 38945 |
{% |
| 38946 |
\ifx [#1\expandafter\xint_floateval_opt |
| 38947 |
\else\expandafter\xint_floateval_noopt |
| 38948 |
\fi #1% |
| 38949 |
}% |
| 38950 |
\def\xint_floateval_opt [#1]#2% |
| 38951 |
{\expandafter\xint_gobble_i\romannumeral`&&@\xintfloatexpr[#1]#2\relax}% |
| 38952 |
\def\xint_floateval_noopt #1{\expandafter\xint_floateval\expandafter{\iffalse}\fi}% |
| 38953 |
\def\xint_floateval#1% |
| 38954 |
{\expandafter\xint_gobble_i\romannumeral`&&@\xintfloatexpr#1\relax}% |
| 38955 |
% \end{macrocode} |
| 38956 |
% \changed{1.4n} |
| 38957 |
% \csbxint{iieval} admits optional arguments |[h]|, |[o]| and |[b]|. |
| 38958 |
% The way this is implemented tames Babel active characters. |
| 38959 |
% \begin{macrocode} |
| 38960 |
\def\xintiieval #1#{\expanded\xintiieval_a{#1}}% |
| 38961 |
\def\xintiieval_a#1#2% |
| 38962 |
{% |
| 38963 |
\csname XINTiiexprprint\xint_zapspaces #1 \xint_gobble_i |
| 38964 |
\expandafter\endcsname |
| 38965 |
\expandafter.\romannumeral0\xintbareiieval#2\relax |
| 38966 |
}% |
| 38967 |
\expandafter\def\csname XINTiiexprprint[h]\endcsname.% |
| 38968 |
{\XINT:NEhook:x:toblist\XINT:expr:toblistwith\xintiiexprPrintOneHex}% |
| 38969 |
\expandafter\def\csname XINTiiexprprint[o]\endcsname.% |
| 38970 |
{\XINT:NEhook:x:toblist\XINT:expr:toblistwith\xintiiexprPrintOneOct}% |
| 38971 |
\expandafter\def\csname XINTiiexprprint[b]\endcsname.% |
| 38972 |
{\XINT:NEhook:x:toblist\XINT:expr:toblistwith\xintiiexprPrintOneBin}% |
| 38973 |
\expandafter\let\csname XINTiiexprprint[]\endcsname\XINTiiexprprint |
| 38974 |
\let\xintiiexprPrintOneHex\xintDecToHex |
| 38975 |
\let\xintiiexprPrintOneOct\xintDecToOct |
| 38976 |
\let\xintiiexprPrintOneBin\xintDecToBin |
| 38977 |
% \end{macrocode} |
| 38978 |
% \subsubsection{\csh{xintboolexpr}, \csh{XINT_boolexpr_print}, \csh{xinttheboolexpr}} |
| 38979 |
%\begin{lverb} |
| 38980 |
% ATTENTION! 1.3d renamed \xinteval to \xintexpro etc... |
| 38981 |
% |
| 38982 |
% Attention, the conversion to 1 or 0 is done only by the print macro. |
| 38983 |
% Perhaps I should force it also inside raw result. |
| 38984 |
% |
| 38985 |
% \changed{1.4o} Some |\csname| for |\xinttheboolexpr| for Babel. |
| 38986 |
%\end{lverb} |
| 38987 |
% \begin{macrocode} |
| 38988 |
\def\xintboolexpr |
| 38989 |
{% |
| 38990 |
\romannumeral0\expandafter\XINT_boolexpr_done\romannumeral0\xintexpro |
| 38991 |
}% |
| 38992 |
\def\XINT_boolexpr_done #1.{\XINTfstop\XINTboolexprprint.}% |
| 38993 |
\def\xinttheboolexpr |
| 38994 |
{% |
| 38995 |
\expanded\csname XINTboolexprprint\expandafter\endcsname |
| 38996 |
\expandafter.\romannumeral0\xintbareeval |
| 38997 |
}% |
| 38998 |
% \end{macrocode} |
| 38999 |
% \subsubsection{\csh{xintifboolexpr}, \csh{xintifboolfloatexpr}, \csh{xintifbooliiexpr}} |
| 39000 |
%\begin{lverb} |
| 39001 |
% They do not accept comma separated expressions input. |
| 39002 |
%\end{lverb} |
| 39003 |
% \begin{macrocode} |
| 39004 |
\def\xintifboolexpr #1{\romannumeral0\xintiiifnotzero {\xinttheexpr #1\relax}}% |
| 39005 |
\def\xintifboolfloatexpr #1{\romannumeral0\xintiiifnotzero {\xintthefloatexpr #1\relax}}% |
| 39006 |
\def\xintifbooliiexpr #1{\romannumeral0\xintiiifnotzero {\xinttheiiexpr #1\relax}}% |
| 39007 |
% \end{macrocode} |
| 39008 |
% \subsubsection{\csh{xintifsgnexpr}, \csh{xintifsgnfloatexpr}, \csh{xintifsgniiexpr}} |
| 39009 |
% \changed{1.3d} |
| 39010 |
%\begin{lverb} |
| 39011 |
% They do not accept comma separated expressions. |
| 39012 |
%\end{lverb} |
| 39013 |
% \begin{macrocode} |
| 39014 |
\def\xintifsgnexpr #1{\romannumeral0\xintiiifsgn {\xinttheexpr #1\relax}}% |
| 39015 |
\def\xintifsgnfloatexpr #1{\romannumeral0\xintiiifsgn {\xintthefloatexpr #1\relax}}% |
| 39016 |
\def\xintifsgniiexpr #1{\romannumeral0\xintiiifsgn {\xinttheiiexpr #1\relax}}% |
| 39017 |
% \end{macrocode} |
| 39018 |
% \subsubsection{\csh{xint_FracToSci_x}} |
| 39019 |
% \added{1.4} |
| 39020 |
% Under the name of |\xintFracToSci| and defined in \xintfracnameimp. |
| 39021 |
% \changed{1.4e} |
| 39022 |
%\begin{lverb} |
| 39023 |
% Refactored and much simplified |
| 39024 |
% |
| 39025 |
% It only needs to be x-expandable, and indeed the implementation here is only |
| 39026 |
% x-expandable. |
| 39027 |
%\end{lverb} |
| 39028 |
%\begin{lverb} |
| 39029 |
% |
| 39030 |
% Finally for 1.4e release I modify. This is breaking change for all |
| 39031 |
% \xinteval output in case of scientific notation: it will not be with an |
| 39032 |
% integer mantissa, but with regular scientific notation, using the same rules |
| 39033 |
% as \xintPFloat. |
| 39034 |
% |
| 39035 |
% Of course no float rounding! Also, as [0] will always or almost always be |
| 39036 |
% present from an \xinteval, we want then to use integer not scientific |
| 39037 |
% notation. But expression contained decimal fixed point input, or uses |
| 39038 |
% scientific functions, then probably the N will not be zero and this will |
| 39039 |
% trigger usage of scientific notation in output. |
| 39040 |
% |
| 39041 |
% Implementing these changes sort of ruin our previous efforts to minimize |
| 39042 |
% grabbing the argument, but well. So the rules now are |
| 39043 |
% |
| 39044 |
%( Input: A, A/B, A[N], A/B[N] |
| 39045 |
%: Output: A, A/B, A if N=0, A/B if N=0 |
| 39046 |
%: If N is not zero, scientific notation like \xintPFloat,& |
| 39047 |
% i.e. behaviour like \xintfloateval apart from the rounding& |
| 39048 |
% to significands of width Digits.& |
| 39049 |
% At 1.4k, trimming of zeros from A is always done, i.e.& |
| 39050 |
% the \xintPFloatMinTrimmed is ignored to keep behaviour.& |
| 39051 |
% unchanged. Trailing zeros of B are kept as is. |
| 39052 |
%: The zero gives 0, except in A[N] and A/B[N] cases, it may give& |
| 39053 |
% 0.0 |
| 39054 |
%) |
| 39055 |
%\end{lverb} |
| 39056 |
% \changed{1.4k} |
| 39057 |
% Moved from \xintfracnameimp to \xintexprnameimp. |
| 39058 |
% \changed{1.4l} |
| 39059 |
%\begin{lverb} |
| 39060 |
% Renamed to \xint_FracToSci_x to make it private and provide in |
| 39061 |
% $xintfracnameimp another \xintFracToSci with same output but which behaves |
| 39062 |
% like other macros there: f-expandable and accepting the whole range of |
| 39063 |
% inputs accepted by the xintfrac public macros. |
| 39064 |
% |
| 39065 |
% The private x-expandable macro here will have an empty output for an empty |
| 39066 |
% input but is never used for an empty input (see \xintexprEmptyItem). |
| 39067 |
%\end{lverb} |
| 39068 |
% \begin{macrocode} |
| 39069 |
\def\xint_FracToSci_x #1{\expandafter\XINT_FracToSci_x\romannumeral`&&@#1/\W[\R}% |
| 39070 |
\def\XINT_FracToSci_x #1/#2#3[#4% |
| 39071 |
{% |
| 39072 |
\xint_gob_til_W #2\XINT_FracToSci_x_noslash\W |
| 39073 |
\xint_gob_til_R #4\XINT_FracToSci_x_slash_noN\R |
| 39074 |
\XINT_FracToSci_x_slash_N #1/#2#3[#4% |
| 39075 |
}% |
| 39076 |
\def\XINT_FracToSci_x_noslash#1\XINT_FracToSci_x_slash_N #2[#3% |
| 39077 |
{% |
| 39078 |
\xint_gob_til_R #3\XINT_FracToSci_x_noslash_noN\R |
| 39079 |
\XINT_FracToSci_x_noslash_N #2[#3% |
| 39080 |
}% |
| 39081 |
\def\XINT_FracToSci_x_noslash_noN\R\XINT_FracToSci_x_noslash_N #1/\W[\R{#1}% |
| 39082 |
\def\XINT_FracToSci_x_noslash_N #1[#2]/\W[\R% |
| 39083 |
{% |
| 39084 |
\ifnum#2=\xint_c_ #1\else |
| 39085 |
\romannumeral0\expandafter\XINT_pfloat_a_fork\romannumeral0\xintrez{#1[#2]}% |
| 39086 |
\fi |
| 39087 |
}% |
| 39088 |
\def\XINT_FracToSci_x_slash_noN\R\XINT_FracToSci_x_slash_N #1#2/#3/\W[\R% |
| 39089 |
{% |
| 39090 |
#1\xint_gob_til_zero#1\expandafter\iffalse\xint_gobble_ii0\iftrue |
| 39091 |
#2\if\XINT_isOne{#3}1\else/#3\fi\fi |
| 39092 |
}% |
| 39093 |
\def\XINT_FracToSci_x_slash_N #1#2/#3[#4]/\W[\R% |
| 39094 |
{% |
| 39095 |
\ifnum#4=\xint_c_ #1#2\else |
| 39096 |
\romannumeral0\expandafter\XINT_pfloat_a_fork\romannumeral0\xintrez{#1#2[#4]}% |
| 39097 |
\fi |
| 39098 |
\if\XINT_isOne{#3}1\else\if#10\else/#3\fi\fi |
| 39099 |
}% |
| 39100 |
\let\xintexprPrintOne\xint_FracToSci_x |
| 39101 |
% \end{macrocode} |
| 39102 |
% \subsubsection{Small bits we have to put somewhere} |
| 39103 |
%\begin{lverb} |
| 39104 |
% Some renaming and modifications here with release 1.2 to switch from |
| 39105 |
% using chains of \romannumeral-`0 in order to gather numbers, possibly |
| 39106 |
% hexadecimals, to using a \csname governed expansion. In this way no more |
| 39107 |
% limit at 5000 digits, and besides this is a logical move because the |
| 39108 |
% \xintexpr parser is already based on \csname...\endcsname storage of numbers |
| 39109 |
% as one token. |
| 39110 |
% |
| 39111 |
% The limitation at 5000 digits didn't worry me too much because it was not |
| 39112 |
% very realistic to launch computations with thousands of digits... such |
| 39113 |
% computations are still slow with 1.2 but less so now. Chains or |
| 39114 |
% \romannumeral are still used for the gathering of function names and other |
| 39115 |
% stuff which I have half-forgotten because the parser does many things. |
| 39116 |
% |
| 39117 |
% In the earlier versions we used the lockscan macro after a chain of |
| 39118 |
% \romannumeral-`0 had ended gathering digits; this uses has been replaced by |
| 39119 |
% direct processing inside a \csname...\endcsname and the macro is kept only |
| 39120 |
% for matters of dummy variables. |
| 39121 |
% |
| 39122 |
% Currently, the parsing of hexadecimal numbers needs two nested |
| 39123 |
% \csname...\endcsname, first to gather the letters (possibly with a hexadecimal |
| 39124 |
% fractional part), and in a second stage to apply \xintHexToDec to do the |
| 39125 |
% actual conversion. This should be faster than updating on the fly the number |
| 39126 |
% (which would be hard for the fraction part...). |
| 39127 |
%\end{lverb} |
| 39128 |
% \begin{macrocode} |
| 39129 |
\def\XINT_embrace#1{{#1}}% |
| 39130 |
\def\xint_gob_til_! #1!{}% ! with catcode 11 |
| 39131 |
\def\xintError:noopening |
| 39132 |
{% |
| 39133 |
\XINT_expandableerror{Extra ). This is serious and prospects are bleak.}% |
| 39134 |
}% |
| 39135 |
% \end{macrocode} |
| 39136 |
% \paragraph{\csh{xintthecoords}} |
| 39137 |
%\begin{lverb} |
| 39138 |
% 1.1 Wraps up an even number of comma separated items into pairs of |
| 39139 |
% TikZ coordinates; for use in the following way: |
| 39140 |
% |
| 39141 |
% coordinates {\xintthecoords\xintfloatexpr ... \relax} |
| 39142 |
% |
| 39143 |
% The crazyness with the \csname and unlock is due to TikZ somewhat STRANGE |
| 39144 |
% control of the TOTAL number of expansions which should not exceed the very low |
| 39145 |
% value of 100 !! As we implemented \XINT_thecoords_b in an "inline" style for |
| 39146 |
% efficiency, we need to hide its expansions. |
| 39147 |
% |
| 39148 |
% Not to be used as \xintthecoords\xintthefloatexpr, only as |
| 39149 |
% \xintthecoords\xintfloatexpr (or \xintiexpr etc...). Perhaps \xintthecoords |
| 39150 |
% could make an extra check, but one should not accustom users to too loose |
| 39151 |
% requirements! |
| 39152 |
%\end{lverb} |
| 39153 |
% \begin{macrocode} |
| 39154 |
\def\xintthecoords#1% |
| 39155 |
{\romannumeral`&&@\expandafter\XINT_thecoords_a\romannumeral0#1}% |
| 39156 |
\def\XINT_thecoords_a #1#2.#3% #2.=\XINTfloatprint<digits>. etc... |
| 39157 |
{\expanded{\expandafter\XINT_thecoords_b\expanded#2.{#3},!,!,^}}% |
| 39158 |
\def\XINT_thecoords_b #1#2,#3#4,% |
| 39159 |
{\xint_gob_til_! #3\XINT_thecoords_c ! (#1#2, #3#4)\XINT_thecoords_b }% |
| 39160 |
\def\XINT_thecoords_c #1^{}% |
| 39161 |
% \end{macrocode} |
| 39162 |
% \paragraph{\csh{xintthespaceseparated}} |
| 39163 |
%\begin{lverb} |
| 39164 |
% 1.4a This is a utility macro which was distributed previously |
| 39165 |
% separately for usage with PSTricks \listplot |
| 39166 |
%\end{lverb} |
| 39167 |
% \begin{macrocode} |
| 39168 |
\def\xintthespaceseparated#1% |
| 39169 |
{\expanded\expandafter\xintthespaceseparated_a\romannumeral0#1}% |
| 39170 |
\def\xintthespaceseparated_a #1#2.#3% |
| 39171 |
{{\expandafter\xintthespaceseparated_b\expanded#2.{#3},!,!,!,!,!,!,!,!,!,^}}% |
| 39172 |
\def\xintthespaceseparated_b #1,#2,#3,#4,#5,#6,#7,#8,#9,% |
| 39173 |
{\xint_gob_til_! #9\xintthespaceseparated_c !% |
| 39174 |
#1#2#3#4#5#6#7#8#9% |
| 39175 |
\xintthespaceseparated_b}% |
| 39176 |
% \end{macrocode} |
| 39177 |
%\begin{lverb} |
| 39178 |
% 1.4c I add a space here to stop the \romannumeral`$&$&@ in case of |
| 39179 |
% empty input. |
| 39180 |
% But this space induces an extra un-needed space token after 9, 18, 27,... |
| 39181 |
% items before the last group of less than 9 items. |
| 39182 |
% |
| 39183 |
% Fix (at 1.4h) is simple because I already use \expanded anyhow: I don't need |
| 39184 |
% at all the \romannumeral`$&$&@ which was first in \xintthespaceseparated, |
| 39185 |
% let's move the first \expanded which was in \xintthespaceseparated_a to |
| 39186 |
% \xintthespaceseparated, and remove the extra space here in _c. |
| 39187 |
% |
| 39188 |
% (alternative would have been to put the space after #1 and accept a |
| 39189 |
% systematic trailing space, at least it is more aesthetic). |
| 39190 |
% |
| 39191 |
% Again, I did have a test file, but it was not incorporated in my test suite, |
| 39192 |
% so I discovered the problem accidentally by compiling all files in an archive. |
| 39193 |
%\end{lverb} |
| 39194 |
% \begin{macrocode} |
| 39195 |
\def\xintthespaceseparated_c !#1!#2^{#1}% |
| 39196 |
% \end{macrocode} |
| 39197 |
% \subsection{Hooks into the numeric parser for usage by the |
| 39198 |
% \cshnolabel{xintdeffunc} symbolic parser} |
| 39199 |
%\begin{lverb} |
| 39200 |
% This is new with 1.3 and considerably refactored at 1.4. See |
| 39201 |
% «Mysterious stuff». |
| 39202 |
%\end{lverb} |
| 39203 |
% \begin{macrocode} |
| 39204 |
\let\XINT:NEhook:f:one:from:one\expandafter |
| 39205 |
\let\XINT:NEhook:f:one:from:one:direct\empty |
| 39206 |
\let\XINT:NEhook:f:one:from:two\expandafter |
| 39207 |
\let\XINT:NEhook:f:one:from:two:direct\empty |
| 39208 |
\let\XINT:NEhook:x:one:from:two\empty |
| 39209 |
\let\XINT:NEhook:f:one:and:opt:direct \empty |
| 39210 |
\let\XINT:NEhook:f:tacitzeroifone:direct \empty |
| 39211 |
\let\XINT:NEhook:f:iitacitzeroifone:direct \empty |
| 39212 |
\let\XINT:NEhook:x:select:obey\empty |
| 39213 |
\let\XINT:NEhook:x:listsel\empty |
| 39214 |
\let\XINT:NEhook:f:reverse\empty |
| 39215 |
% \end{macrocode} |
| 39216 |
%\begin{lverb} |
| 39217 |
% At 1.4 it was \def\XINT:NEhook:f:from:delim:u #1#2^{#1#2^} |
| 39218 |
% which was trick to allow automatic unpacking of a nutple argument |
| 39219 |
% to multi-arguments functions such as gcd() or max(). But this |
| 39220 |
% sacrificied the usage with a single numeric argument. |
| 39221 |
%\end{lverb} |
| 39222 |
% \changed{1.4i} |
| 39223 |
%\begin{lverb} |
| 39224 |
% More sophisticated code to check if the argument ople |
| 39225 |
% was actually a single number. Notice that this forces numeric |
| 39226 |
% types to actually use catcode 12 tokens, and polexpr diverges |
| 39227 |
% a bit using P, but actually always testing with \if not \ifx. |
| 39228 |
% |
| 39229 |
% This is used by gcd(), lcm(), max(), min(), `+`(), `*`(), all(), any(), |
| 39230 |
% xor(). |
| 39231 |
% |
| 39232 |
% The nil and None will give the same result due to the initial brace |
| 39233 |
% stripping done by \XINT:NEhook:f:from:delim:u (there was even a prior brace |
| 39234 |
% stripping to provide the #2 which is empty here for the nil and {} for the |
| 39235 |
% None). |
| 39236 |
%\end{lverb} |
| 39237 |
% \begin{macrocode} |
| 39238 |
\def\XINT:NEhook:f:from:delim:u #1#2^% |
| 39239 |
{% |
| 39240 |
\expandafter\XINT_fooof_checkifnumber\expandafter#1\string#2^% |
| 39241 |
}% |
| 39242 |
\def\XINT_fooof_checkifnumber#1#2% |
| 39243 |
{% |
| 39244 |
\expandafter#1% |
| 39245 |
\romannumeral0\expanded{\if ^#2^\else |
| 39246 |
\if\bgroup#2\noexpand\XINT_fooof_no\else |
| 39247 |
\noexpand\XINT_fooof_yes#2\fi\fi}% |
| 39248 |
}% |
| 39249 |
\def\XINT_fooof_yes#1^{{#1}^}% |
| 39250 |
\def\XINT_fooof_no{\expandafter{\iffalse}\fi}% |
| 39251 |
% \end{macrocode} |
| 39252 |
% \changed{1.4i} |
| 39253 |
%\begin{lverb} |
| 39254 |
% Same changes as for the other multiple arguments functions, |
| 39255 |
% making them again usable with a single numeric input. |
| 39256 |
% |
| 39257 |
% Was at 1.4 \def\XINT:NEhook:f:noeval:from:braced:u#1#2^{#1{#2}} which |
| 39258 |
% is not compatible with a single numeric input. |
| 39259 |
% |
| 39260 |
% Used by len(), first(), last() but it is a potential implementation bug that |
| 39261 |
% the three share this as the location where expansion takes places is one |
| 39262 |
% level deeper for the support macro of len(). |
| 39263 |
% |
| 39264 |
% The None is here handled as nil, i.e. it is unpacked, which is fine |
| 39265 |
% as the documentations says nutples are unpacked. |
| 39266 |
% |
| 39267 |
%\end{lverb} |
| 39268 |
% \begin{macrocode} |
| 39269 |
\def\XINT:NEhook:f:LFL #1{\expandafter#1\expandafter}% |
| 39270 |
\def\XINT:NEhook:r:check #1^% |
| 39271 |
{% |
| 39272 |
\expandafter\XINT:NEhook:r:check_a\string#1^% |
| 39273 |
}% |
| 39274 |
\let\XINT:NEsaved:r:check \XINT:NEhook:r:check |
| 39275 |
\def\XINT:NEhook:r:check_a #1% |
| 39276 |
{% |
| 39277 |
\if ^#1\xint_dothis\xint_c_\fi |
| 39278 |
\if\bgroup#1\xint_dothis\XINT:NEhook:r:check_no\fi |
| 39279 |
\xint_orthat{\XINT:NEhook:r:check_yes#1}% |
| 39280 |
}% |
| 39281 |
\def\XINT:NEhook:r:check_no |
| 39282 |
{% |
| 39283 |
\expandafter\XINT:NEhook:r:check_no_b |
| 39284 |
\expandafter\xint_c_\expandafter{\iffalse}\fi |
| 39285 |
}% |
| 39286 |
\def\XINT:NEhook:r:check_no_b#1^{#1}% |
| 39287 |
\def\XINT:NEhook:r:check_yes#1^{\xint_c_{#1}}% |
| 39288 |
\let\XINT:NEhook:branch\expandafter |
| 39289 |
\let\XINT:NEhook:seqx\empty |
| 39290 |
\let\XINT:NEhook:iter\expandafter |
| 39291 |
\let\XINT:NEhook:opx\empty |
| 39292 |
\let\XINT:NEhook:rseq\expandafter |
| 39293 |
\let\XINT:NEhook:iterr\expandafter |
| 39294 |
\let\XINT:NEhook:rrseq\expandafter |
| 39295 |
\let\XINT:NEhook:x:toblist\empty |
| 39296 |
\let\XINT:NEhook:x:mapwithin\empty |
| 39297 |
\let\XINT:NEhook:x:ndmapx\empty |
| 39298 |
% \end{macrocode} |
| 39299 |
% \subsection{\csh{XINT_expr_getnext}: fetch some value then an operator and |
| 39300 |
% present them to last waiter with the found operator precedence, then |
| 39301 |
% the operator, then the value} |
| 39302 |
%\begin{lverb} |
| 39303 |
% Big change in 1.1, no attempt to detect braced stuff anymore as the |
| 39304 |
% [N] notation is implemented otherwise. Now, braces should not be used at |
| 39305 |
% all; one level removed, then \romannumeral-`0 expansion. |
| 39306 |
% |
| 39307 |
% Refactored at 1.4 to put expansion of \XINT_expr_getop after the fetched |
| 39308 |
% number, thus avoiding it to have to fetch it (which could happen then |
| 39309 |
% multiple times, it was not really important when it was only one token in |
| 39310 |
% pre-1.4 xintexpr). |
| 39311 |
% |
| 39312 |
% Allow \xintexpr\relax at 1.4. |
| 39313 |
% |
| 39314 |
% Refactored at 1.4 the articulation |
| 39315 |
% \XINT_expr_getnext/XINT_expr_func/XINT_expr_getop. For some legacy reason |
| 39316 |
% the first token picked by getnext was soon turned to catcode 12 The next |
| 39317 |
% ones after the first were not a priori stringified but the first token was, |
| 39318 |
% and this made allowing things such as \xintexpr\relax, \xintexpr,,\relax, |
| 39319 |
% [], 1+(), [:] etc... complicated and requiring each time specific measures. |
| 39320 |
% |
| 39321 |
% The \expandafter chain in \XINT_expr_put_op_first is an overhead related |
| 39322 |
% to an 1.4 attempt, the "varvalue" mechanism. I.e.: expansion of |
| 39323 |
% \XINT_expr_var_foo is {\XINT_expr_varvalue_foo } and then for example |
| 39324 |
% \XINT_expr_varvalue_foo expands to {4/1[0]}. The mechanism was originally |
| 39325 |
% conceived to have only one token with idea its makes things faster. But the |
| 39326 |
% xintfrac macros break with syntax such as \xintMul\foo\bar and \foo |
| 39327 |
% expansion giving braces. So at 1.4c I added here these \expandafter, but |
| 39328 |
% this is REALLY not satisfactory because the \expandafter are needed it seems |
| 39329 |
% only for this variable "varvalue" mechanism. |
| 39330 |
% |
| 39331 |
% See also the discussion of \XINT_expr_op__ which distinguishes variables from |
| 39332 |
% functions. |
| 39333 |
% |
| 39334 |
% After a 1.4g refactoring it would be possible to drop here the |
| 39335 |
% \expandafter if the \XINT_expr_var_foo macro was defined to f-expand to |
| 39336 |
% {actual expanded value (as ople)} for example explicit {{3}}. I have to |
| 39337 |
% balance the relative weights of doing always the \expandafter but they are |
| 39338 |
% needed only for the case the value was encapsulated in a variable, and of |
| 39339 |
% never doing the \expandafter and ensure f-expansion of the _var_foo gives |
| 39340 |
% explicit value (now that the refactoring let it be f-expanded, and the case |
| 39341 |
% of fake variables omit and abort in particular was safely separated instead |
| 39342 |
% of being treated like other and imposing restrictions on general variable |
| 39343 |
% handling), and then there is the overhead of possibly moving around many |
| 39344 |
% digits in the #1 of \XINT_expr_put_op_first. |
| 39345 |
% |
| 39346 |
%\end{lverb} |
| 39347 |
% \begin{macrocode} |
| 39348 |
\def\XINT_expr_getnext #1% |
| 39349 |
{% |
| 39350 |
\expandafter\XINT_expr_put_op_first\romannumeral`&&@% |
| 39351 |
\expandafter\XINT_expr_getnext_a\romannumeral`&&@#1% |
| 39352 |
}% |
| 39353 |
\def\XINT_expr_put_op_first #1#2#3{\expandafter#2\expandafter#3\expandafter{#1}}% |
| 39354 |
\def\XINT_expr_getnext_a #1% |
| 39355 |
{% |
| 39356 |
\ifx\relax #1\xint_dothis\XINT_expr_foundprematureend\fi |
| 39357 |
\ifx\XINTfstop#1\xint_dothis\XINT_expr_subexpr\fi |
| 39358 |
\ifcat\relax#1\xint_dothis\XINT_expr_countetc\fi |
| 39359 |
\xint_orthat{}\XINT_expr_getnextfork #1% |
| 39360 |
}% |
| 39361 |
\def\XINT_expr_foundprematureend\XINT_expr_getnextfork #1{{}\xint_c_\relax}% |
| 39362 |
\def\XINT_expr_subexpr #1.#2% |
| 39363 |
{% |
| 39364 |
\expanded{\xint_noxpd{{#2}}\expandafter}\romannumeral`&&@\XINT_expr_getop |
| 39365 |
}% |
| 39366 |
% \end{macrocode} |
| 39367 |
% |
| 39368 |
% The "fetch as number" must be avoided for those cases where \cs{number} |
| 39369 |
% can not be hoped to need only one token. Hence the liste of exceptions. |
| 39370 |
% |
| 39371 |
% \changed{1.2} |
| 39372 |
% Add \cs{ht}, \cs{dp}, \cs{wd} and the e\TeX{} font related primitives. |
| 39373 |
% |
| 39374 |
% \changed{1.4} |
| 39375 |
% Refactor for readability to avoid huge amounts of \cs{fi}'s. |
| 39376 |
% |
| 39377 |
% \changed{1.4g} |
| 39378 |
% Check also for \cs{catcode} so that |\xinteval{\catcode`@}| does not crash. |
| 39379 |
% But later I observed that |\fpeval{\catcode`@}| does crash, so in retrospect |
| 39380 |
% I wonder if I should have added the overhead. |
| 39381 |
% |
| 39382 |
% \changed[2025/08/09]{1.4n} |
| 39383 |
% Added \cs{_catcode} to the list for Op\TeX. This means though that an |
| 39384 |
% undefined token with other engines will be expanded via \cs{number}... |
| 39385 |
% \begin{macrocode} |
| 39386 |
\def\XINT_expr_countetc\XINT_expr_getnextfork#1% |
| 39387 |
{% |
| 39388 |
\if0\ifx\count#11\fi |
| 39389 |
\ifx\numexpr#11\fi |
| 39390 |
\ifx\catcode#11\fi |
| 39391 |
\ifx\dimen#11\fi |
| 39392 |
\ifx\dimexpr#11\fi |
| 39393 |
\ifx\skip#11\fi |
| 39394 |
\ifx\glueexpr#11\fi |
| 39395 |
\ifx\fontdimen#11\fi |
| 39396 |
\ifx\ht#11\fi |
| 39397 |
\ifx\dp#11\fi |
| 39398 |
\ifx\wd#11\fi |
| 39399 |
\ifx\fontcharht#11\fi |
| 39400 |
\ifx\fontcharwd#11\fi |
| 39401 |
\ifx\fontchardp#11\fi |
| 39402 |
\ifx\fontcharic#11\fi |
| 39403 |
\ifx\_catcode#11\fi |
| 39404 |
0\expandafter\XINT_expr_fetch_as_number\fi |
| 39405 |
\expandafter\XINT_expr_getnext_a\number #1% |
| 39406 |
}% |
| 39407 |
\def\XINT_expr_fetch_as_number |
| 39408 |
\expandafter\XINT_expr_getnext_a\number #1% |
| 39409 |
{% |
| 39410 |
\expanded{{{\number#1}}\expandafter}\romannumeral`&&@\XINT_expr_getop |
| 39411 |
}% |
| 39412 |
% \end{macrocode} |
| 39413 |
%\begin{lverb} |
| 39414 |
% This is the key initial dispatch component. It has been refactored at |
| 39415 |
% 1.4g to give priority to identifying letter and digit tokens first. It |
| 39416 |
% thus combines former \XINT_expr_getnextfork, \XINT_expr_scan_nbr_or_func and |
| 39417 |
% \XINT_expr_scanfunc. A branch of the latter having become |
| 39418 |
% \XINT_expr_startfunc. The handling of non-catcode 11 underscore _ has |
| 39419 |
% changed: it is now skipped completely like the +. Formerly it would cause an |
| 39420 |
% infinite loop because it triggered first insertion of a nil variable, (being |
| 39421 |
% confused with a possible operator at a location where one looks for a |
| 39422 |
% value), then tacit multiplication (being now interpreted as starting some |
| 39423 |
% name), and then it came back to getnextfork creating loop. The @ of catcode |
| 39424 |
% 12 could have caused the same issue if it was not handled especially because |
| 39425 |
% it is used in the syntax as special variable for recursion hence was |
| 39426 |
% recognized even if of catcode 12. Anyway I could have handled the _ like the |
| 39427 |
% @, to avoid this problem of infinite loop with a non-letter underscore used |
| 39428 |
% as first character but decided finally to have it be ignored (it is already |
| 39429 |
% ignored if among digits, but it can be a constituent of a function of |
| 39430 |
% variable name). It is not ignored of course if of catcode 11. It may then |
| 39431 |
% start a variable or function name, but only for use by the package (by |
| 39432 |
% polexpr for example), not by users. |
| 39433 |
% |
| 39434 |
% Then the matter is handed over to specialized routines: gathering digits |
| 39435 |
% of a number (inclusive of a decimal mark, an exponential part) or letters |
| 39436 |
% of a function or variable. And we have to intercept some tokens to implement |
| 39437 |
% various functionalities. |
| 39438 |
% |
| 39439 |
% In each dothis/orthat structure, the first encountered branches are usually |
| 39440 |
% handled slower than the next, because \if..\fi test cost less than grabbing |
| 39441 |
% tokens. The exception is in the first one where letters pass through |
| 39442 |
% slightly faster than digits, presumably because the \ifnum test is more |
| 39443 |
% costly. Prior to this 1.4g refactoring the case of a starting letter of |
| 39444 |
% a variable or function name was handled last, it is now handled first. Now, |
| 39445 |
% this is only first letter... |
| 39446 |
% |
| 39447 |
% Here are the various possibilities in order that they are appear below |
| 39448 |
% (the indicative order of speed of treatment is given as a number). |
| 39449 |
% |
| 39450 |
%( -1 tokens of catcode letter start a variable or function name |
| 39451 |
%: -2 digits (I apply \string for the test, but I will have to review,& |
| 39452 |
% it seems natural anyhow to require digits to be of catcode 12 and& |
| 39453 |
% this is in fact basically done by the package, \numexpr does not& |
| 39454 |
% work if not the case.), |
| 39455 |
%: -7 support for Python-like * "unpacking" unary operator (added at 1.4), |
| 39456 |
%: -6 support for [ as opener for the [..] nutple constructor (1.4), |
| 39457 |
%: -5 support for the minus as unary operator of variable precedence, |
| 39458 |
%: -4 support for @ as first character of special variables even if not letter, |
| 39459 |
%: -3 support for opening parentheses (possibly triggering tacit multiplication), |
| 39460 |
%: -13 support for skipping over ignored + character, |
| 39461 |
%: -12 support for numbers starting with a decimal point, |
| 39462 |
%: -11 support for the `+`() and `*`() functions, |
| 39463 |
%: -10 support for the !() function, |
| 39464 |
%: -9 support for the ?() function, |
| 39465 |
%: -8 support for " for input of hexadecimal numbers and (1.4n) of ' for octal numbers. |
| 39466 |
%: -17 support for \xintdeffunc via special handling of # token, |
| 39467 |
%: -16 support for ignoring _ if not of catcode 11 and at start of& |
| 39468 |
% numbers or names (this 1.4g change fixes \xinteval{_4} creating& |
| 39469 |
% infinite loop) |
| 39470 |
%: -15 support for inserting "nil" in front of operators, as needed in particular& |
| 39471 |
% for the Python slicing syntax. This covers the comma, the :, the ] and& |
| 39472 |
% the ) and also the ; although I don't think using ; to delimit nil is licit. |
| 39473 |
%: -14 support for inserting 0 as missing value if / or ^ are encountered& |
| 39474 |
% directly. This 1.4g changes avoids \xinteval{/3} causing& |
| 39475 |
% unrecoverable low level errors from \xintDiv receiving only one argument. |
| 39476 |
% I did not see here other bad syntax to protect. |
| 39477 |
%) |
| 39478 |
% |
| 39479 |
% The handling of "nil" insertion penalizes Python slicing but anyway time |
| 39480 |
% differences in the 14-15-16-17 group are less than |
| 39481 |
% 5$%. The alternative will be |
| 39482 |
% to do some positive test for the targets (:, ], the comma and closing |
| 39483 |
% parenthesis) and do this in the prior group but this then penalizes |
| 39484 |
% others. Anyway. This is all negligible compared to actual computations... |
| 39485 |
% |
| 39486 |
% Note: the above may not be in sync with code as it is extremely |
| 39487 |
% time-consuming to maintain correspondence in case of re-factoring. |
| 39488 |
%\end{lverb} |
| 39489 |
%\odef\MakePrivateLetters{\MakePrivateLetters\catcode`` 11 }^^A |
| 39490 |
% \begin{macrocode} |
| 39491 |
\def\XINT_expr_getnextfork #1% |
| 39492 |
{% |
| 39493 |
\ifcat a#1\xint_dothis\XINT_expr_startfunc\fi |
| 39494 |
\ifnum \xint_c_ix<1\string#1 \xint_dothis\XINT_expr_startint\fi |
| 39495 |
\xint_orthat\XINT_expr_getnextfork_a #1% |
| 39496 |
}% |
| 39497 |
\def\XINT_expr_getnextfork_a #1% |
| 39498 |
{% |
| 39499 |
\if#1*\xint_dothis {{}\xint_c_ii^v 0}\fi |
| 39500 |
\if#1[\xint_dothis {{}\xint_c_ii^v \XINT_expr_itself_obracket}\fi |
| 39501 |
\if#1-\xint_dothis {{}{}-}\fi |
| 39502 |
\if#1@\xint_dothis{\XINT_expr_startfunc @}\fi |
| 39503 |
\if#1(\xint_dothis {{}\xint_c_ii^v (}\fi |
| 39504 |
\xint_orthat{\XINT_expr_getnextfork_b#1}% |
| 39505 |
}% |
| 39506 |
\catcode96 11 % ` |
| 39507 |
\def\XINT_expr_getnextfork_b #1% |
| 39508 |
{% |
| 39509 |
\if#1+\xint_dothis \XINT_expr_getnext_a\fi |
| 39510 |
\if#1.\xint_dothis \XINT_expr_startdec\fi |
| 39511 |
\if#1`\xint_dothis {\XINT_expr_onliteral_`}\fi |
| 39512 |
\if#1!\xint_dothis {\XINT_expr_startfunc !}\fi |
| 39513 |
\if#1?\xint_dothis {\XINT_expr_startfunc ?}\fi |
| 39514 |
\if#1'\xint_dothis \XINT_expr_startoct\fi |
| 39515 |
\if#1"\xint_dothis \XINT_expr_starthex\fi |
| 39516 |
\xint_orthat{\XINT_expr_getnextfork_c#1}% |
| 39517 |
}% |
| 39518 |
\def\XINT_tmpa #1{% |
| 39519 |
\def\XINT_expr_getnextfork_c ##1% |
| 39520 |
{% |
| 39521 |
\if##1#1\xint_dothis \XINT_expr_getmacropar\fi |
| 39522 |
\if##1_\xint_dothis \XINT_expr_getnext_a\fi |
| 39523 |
\if0\if##1/1\fi\if##1^1\fi0\xint_dothis{\XINT_expr_insertnil##1}\fi |
| 39524 |
\xint_orthat{\XINT_expr_missing_arg##1}% |
| 39525 |
}% |
| 39526 |
}\expandafter\XINT_tmpa\string#% |
| 39527 |
% \end{macrocode} |
| 39528 |
%\begin{lverb} |
| 39529 |
% The ` syntax is here used for special constructs like `+`(..), `*`(..) where |
| 39530 |
% + or * will be treated as functions. Current implementation picks only one |
| 39531 |
% token (could have been braced stuff), here it will be + or *, and via |
| 39532 |
% \XINT_expr_op_` this then becomes a suitable |
| 39533 |
% \XINT_{expr|iiexpr|flexpr}_func_+ (or *). Documentation says to use |
| 39534 |
% `+`(...), but `+(...) is also valid. The opening parenthesis must be there, |
| 39535 |
% it is not allowed to require some expansion. |
| 39536 |
%\end{lverb} |
| 39537 |
% \begin{macrocode} |
| 39538 |
\def\XINT_expr_onliteral_` #1#2({{#1}\xint_c_ii^v `}% |
| 39539 |
\catcode96 12 % ` |
| 39540 |
% \end{macrocode} |
| 39541 |
% \let\MakePrivateLetters\xintexprMakePrivateLetters |
| 39542 |
%\begin{lverb} |
| 39543 |
% Prior to 1.4g, I was using a \lowercase technique to insert the |
| 39544 |
% catcode 12 #, but this is a bit risky when one does not ensure a priori control of all |
| 39545 |
% lccodes. |
| 39546 |
%\end{lverb} |
| 39547 |
% \begin{macrocode} |
| 39548 |
\def\XINT_tmpa #1{% |
| 39549 |
\def\XINT_expr_getmacropar ##1% |
| 39550 |
{% |
| 39551 |
\expandafter{\expandafter{\expandafter#1\expandafter |
| 39552 |
##1\expandafter}\expandafter}\romannumeral`&&@\XINT_expr_getop |
| 39553 |
}% |
| 39554 |
}\expandafter\XINT_tmpa\string#% |
| 39555 |
\def\XINT_expr_insertnil #1% |
| 39556 |
{% |
| 39557 |
\expandafter{\expandafter}\romannumeral`&&@\XINT_expr_getop_a#1% |
| 39558 |
}% |
| 39559 |
\def\XINT_expr_missing_arg#1% |
| 39560 |
{% |
| 39561 |
\expanded{\XINT_expandableerror |
| 39562 |
{Expected a value, got nothing before `#1'. Inserting 0.}{{0}}\expandafter}% |
| 39563 |
\romannumeral`&&@\XINT_expr_getop_a#1% |
| 39564 |
}% |
| 39565 |
% \end{macrocode} |
| 39566 |
% \subsection{\csh{XINT_expr_startint}} |
| 39567 |
% \localtableofcontents |
| 39568 |
% Following comments are in part OBSOLETE as the code was refactored |
| 39569 |
% at some stage to use \cs{expanded}. |
| 39570 |
% |
| 39571 |
%\begin{lverb} |
| 39572 |
% 1.2 release has replaced chains of \romannumeral-`0 by \csname |
| 39573 |
% governed expansion. Thus there is no more the limit at about 5000 digits for |
| 39574 |
% parsed numbers. |
| 39575 |
% |
| 39576 |
% In order to avoid having to lock and unlock in succession to handle the |
| 39577 |
% scientific part and adjust the exponent according to the number of digits of |
| 39578 |
% the decimal part, the parsing of this decimal part counts on the fly the |
| 39579 |
% number of digits it encounters. |
| 39580 |
% |
| 39581 |
% There is some slight annoyance with \xintiiexpr which should never be given |
| 39582 |
% a [n] inside its \csname.=<digits>\endcsname storage of numbers (because its |
| 39583 |
% arithmetic uses the ii macros which know nothing about the [N] notation). |
| 39584 |
% Hence if the parser has only seen digits when hitting something else than |
| 39585 |
% the dot or e (or E), it will not insert a [0]. Thus we very slightly |
| 39586 |
% compromise the efficiency of \xintexpr and \xintfloatexpr in order to be |
| 39587 |
% able to share the same code with \xintiiexpr. |
| 39588 |
% |
| 39589 |
% Indeed, the parser at this location is completely common to all, it does not |
| 39590 |
% know if it is working inside \xintexpr or \xintiiexpr. On the other hand if |
| 39591 |
% a dot or a e (or E) is met, then the (common) parser has no scrupules ending |
| 39592 |
% this number with a [n], this will provoke an error later if that was within |
| 39593 |
% an \xintiiexpr, as soon as an arithmetic macro is used. |
| 39594 |
% |
| 39595 |
% As the gathered numbers have no spaces, no pluses, no minuses, the only |
| 39596 |
% remaining issue is with leading zeroes, which are discarded on the fly. The |
| 39597 |
% hexadecimal numbers leading zeroes are stripped in a second stage by the |
| 39598 |
% \xintHexToDec macro. |
| 39599 |
% |
| 39600 |
% With 1.2, \xinttheexpr . \relax does not work anymore (it did in earlier |
| 39601 |
% releases). There must be digits either before or after the decimal mark. Thus |
| 39602 |
% both \xinttheexpr 1.\relax and \xinttheexpr .1\relax are legal. |
| 39603 |
% |
| 39604 |
% Attention at this location #1 was of catcode 12 in all versions prior to |
| 39605 |
% 1.4. |
| 39606 |
% |
| 39607 |
% We assume anyhow that catcodes of digits are 12... |
| 39608 |
%\end{lverb} |
| 39609 |
% |
| 39610 |
% Style of location of the braces around replacement text varies, |
| 39611 |
% but is kept as is to avoid wasting time on cosmetics. |
| 39612 |
% |
| 39613 |
% \changed[2025/09/01]{1.4n} Support for the |0b|, |0o| and |0x| prefixes! |
| 39614 |
% Implementation of this extension of the syntax was very easy. |
| 39615 |
% I may have thought of it briefly in the past but presumed it would |
| 39616 |
% break things. |
| 39617 |
% |
| 39618 |
% This change seems to only break stuff such as |+0bar+3| with |bar| a |
| 39619 |
% variable being interpreted |+0*bar+3| (tacit multiplication) and will cause |
| 39620 |
% the parser to raise then an error message, but this is not very serious |
| 39621 |
% breaking change. |
| 39622 |
% |
| 39623 |
% Supporting |0b| meant that like for octal |1.4n| needed to add the |
| 39624 |
% needed support macros, which opens this TODO: perhaps try to share |
| 39625 |
% code between binary, octal, hexadecimal more than currently. |
| 39626 |
% \begin{macrocode} |
| 39627 |
\def\XINT_expr_startint #1% |
| 39628 |
{% |
| 39629 |
\if #10\expandafter\XINT_expr_gobz_a\else\expandafter\XINT_expr_scanint_a\fi #1% |
| 39630 |
}% |
| 39631 |
\def\XINT_expr_scanint_a #1#2% |
| 39632 |
{\expanded\bgroup{{\iffalse}}\fi #1% spare a \string |
| 39633 |
\expandafter\XINT_expr_scanint_main\romannumeral`&&@#2}% |
| 39634 |
\def\XINT_expr_gobz_a #1#2% |
| 39635 |
{\expandafter\XINT_expr_gobz_b\romannumeral`&&@#2}% |
| 39636 |
% \end{macrocode} |
| 39637 |
% Perhaps use \cs{if} and not \cs{ifx} tests here? |
| 39638 |
% \begin{macrocode} |
| 39639 |
\def\XINT_expr_gobz_b #1%% |
| 39640 |
{% |
| 39641 |
\ifx b#1\xint_dothis \XINT_expr_startbin \fi |
| 39642 |
\ifx o#1\xint_dothis \XINT_expr_startoct \fi |
| 39643 |
\ifx x#1\xint_dothis \XINT_expr_starthex \fi |
| 39644 |
\xint_orthat {\XINT_expr_gobz_c #1}% |
| 39645 |
}% |
| 39646 |
\def\XINT_expr_gobz_c #1% |
| 39647 |
{\expanded\bgroup{{\iffalse}}\fi |
| 39648 |
\expandafter\XINT_expr_gobz_scanint_main#1}% |
| 39649 |
\def\XINT_expr_startdec #1% |
| 39650 |
{\expanded\bgroup{{\iffalse}}\fi |
| 39651 |
\expandafter\XINT_expr_scandec_a\romannumeral`&&@#1}% |
| 39652 |
% \end{macrocode} |
| 39653 |
% \subsubsection{Integral part (skipping zeroes)} |
| 39654 |
%\begin{lverb} |
| 39655 |
% 1.2 has modified the code to give highest priority to digits, the |
| 39656 |
% accelerating impact is non-negligeable. I don't think the doubled \string is |
| 39657 |
% a serious penalty. |
| 39658 |
% |
| 39659 |
% (reference to \string is obsolete: it is only used in the test but the |
| 39660 |
% tokens are not submitted to \string anymore) |
| 39661 |
%\end{lverb} |
| 39662 |
% \begin{macrocode} |
| 39663 |
\def\XINT_expr_scanint_main #1% |
| 39664 |
{% |
| 39665 |
\ifcat \relax #1\expandafter\XINT_expr_scanint_hit_cs \fi |
| 39666 |
\ifnum\xint_c_ix<1\string#1 \else\expandafter\XINT_expr_scanint_next\fi |
| 39667 |
#1\XINT_expr_scanint_again |
| 39668 |
}% |
| 39669 |
\def\XINT_expr_scanint_again #1% |
| 39670 |
{% |
| 39671 |
\expandafter\XINT_expr_scanint_main\romannumeral`&&@#1% |
| 39672 |
}% |
| 39673 |
% \end{macrocode} |
| 39674 |
% |1.4f| had |_getop| here, but let's jump directly to |_getop_a|. |
| 39675 |
% \begin{macrocode} |
| 39676 |
\def\XINT_expr_scanint_hit_cs \ifnum#1\fi#2\XINT_expr_scanint_again |
| 39677 |
{% |
| 39678 |
\iffalse{{{\fi}}\expandafter}\romannumeral`&&@\XINT_expr_getop_a#2% |
| 39679 |
}% |
| 39680 |
% \end{macrocode} |
| 39681 |
%\begin{lverb} |
| 39682 |
% With 1.2d the tacit multiplication in front of a variable name or |
| 39683 |
% function name is now done with a higher precedence, intermediate between the |
| 39684 |
% common one of * and / and the one of ^. Thus x/2y is like x/(2y), but x^2y |
| 39685 |
% is like x^2*y and 2y! is not (2y)! but 2*y!. |
| 39686 |
% |
| 39687 |
% Finally, 1.2d has moved away from the _scan macros all the business of the |
| 39688 |
% tacit multiplication in one unique place via \XINT_expr_getop. For this, the |
| 39689 |
% ending token is not first given to \string as was done earlier before |
| 39690 |
% handing over back control to \XINT_expr_getop. Earlier we had to identify |
| 39691 |
% the catcode 11 ! signaling a sub-expression here. With no \string applied |
| 39692 |
% we can do it in \XINT_expr_getop. As a corollary of this displacement, |
| 39693 |
% parsing of big numbers should be a tiny bit faster now. |
| 39694 |
% |
| 39695 |
% Extended for 1.2l to ignore underscore character _ if encountered within |
| 39696 |
% digits; so it can serve as separator for better readability. |
| 39697 |
%\end{lverb} |
| 39698 |
% |
| 39699 |
%\begin{lverb} |
| 39700 |
% It is not obvious at 1.4 to support [] for three things: packing, |
| 39701 |
% slicing, ... and raw xintfrac syntax A/B[N]. The only good way would be to |
| 39702 |
% actually really separate completely \xintexpr, \xintfloatexpr and |
| 39703 |
% \xintiiexpr code which would allow to handle both / and [] from A/B[N] as we |
| 39704 |
% handle e and E. But triplicating the code is something I need to think |
| 39705 |
% about. It is not possible as in pre 1.4 to consider [ only as an operator of |
| 39706 |
% same precedence as multiplication and division which was the way we did |
| 39707 |
% this, but we can use the technique of fake operators. Thus we intercept |
| 39708 |
% hitting a [ here, which is not too much of a problem as anyhow we dropped |
| 39709 |
% temporarily 3*[1,2,3]+5 syntax so we don't have to worry that 3[1,2,3] |
| 39710 |
% should do tacit multiplication. I think only way in future will be to really |
| 39711 |
% separate the code of the three parsers (or drop entirely support for A/B[N]; |
| 39712 |
% as 1.4 has modified output of \xinteval to not use this notation this is not |
| 39713 |
% too dramatic). |
| 39714 |
% |
| 39715 |
% Anyway we find a way to inject here the former handling of [N], which will |
| 39716 |
% use a delimited macro to directly fetch until the closing]. We do still need |
| 39717 |
% some fake operator because A/B[N] is (A/B) times 10^N and the /B is allowed |
| 39718 |
% to be missing. We hack this using the $textdollar$space which is not used currently as |
| 39719 |
% operator elsewhere in the syntax and need to hook into \XINT_expr_getop_b. |
| 39720 |
% No finally I use the null char. It must be of catcode 12. |
| 39721 |
% |
| 39722 |
% 1.4f had _getop here, but let's jump directly to _getop_a. |
| 39723 |
%\end{lverb} |
| 39724 |
% \begin{macrocode} |
| 39725 |
\def\XINT_expr_scanint_next #1\XINT_expr_scanint_again |
| 39726 |
{% |
| 39727 |
\if [#1\xint_dothis\XINT_expr_rawxintfrac\fi |
| 39728 |
\if _#1\xint_dothis\XINT_expr_scanint_again\fi |
| 39729 |
\if e#1\xint_dothis{[\the\numexpr0\XINT_expr_scanexp_a +}\fi |
| 39730 |
\if E#1\xint_dothis{[\the\numexpr0\XINT_expr_scanexp_a +}\fi |
| 39731 |
\if .#1\xint_dothis{\XINT_expr_startdec_a .}\fi |
| 39732 |
\xint_orthat |
| 39733 |
{\iffalse{{{\fi}}\expandafter}\romannumeral`&&@\XINT_expr_getop_a#1}% |
| 39734 |
}% |
| 39735 |
\def\XINT_expr_rawxintfrac |
| 39736 |
{% |
| 39737 |
\iffalse{{{\fi}}\expandafter}\csname XINT_expr_precedence_&&@\endcsname&&@% |
| 39738 |
}% |
| 39739 |
\def\XINT_expr_gobz_scanint_main #1% |
| 39740 |
{% |
| 39741 |
\ifcat \relax #1\expandafter\XINT_expr_gobz_scanint_hit_cs\fi |
| 39742 |
\ifnum\xint_c_x<1\string#1 \else\expandafter\XINT_expr_gobz_scanint_next\fi |
| 39743 |
#1\XINT_expr_scanint_again |
| 39744 |
}% |
| 39745 |
\def\XINT_expr_gobz_scanint_again #1% |
| 39746 |
{% |
| 39747 |
\expandafter\XINT_expr_gobz_scanint_main\romannumeral`&&@#1% |
| 39748 |
}% |
| 39749 |
% \end{macrocode} |
| 39750 |
% |1.4f| had |_getop| here, but let's jump directly to |_getop_a|. |
| 39751 |
% \begin{macrocode} |
| 39752 |
\def\XINT_expr_gobz_scanint_hit_cs\ifnum#1\fi#2\XINT_expr_scanint_again |
| 39753 |
{% |
| 39754 |
0\iffalse{{{\fi}}\expandafter}\romannumeral`&&@\XINT_expr_getop_a#2% |
| 39755 |
}% |
| 39756 |
\def\XINT_expr_gobz_scanint_next #1\XINT_expr_scanint_again |
| 39757 |
{% |
| 39758 |
\if [#1\xint_dothis{\expandafter0\XINT_expr_rawxintfrac}\fi |
| 39759 |
\if _#1\xint_dothis\XINT_expr_gobz_scanint_again\fi |
| 39760 |
\if e#1\xint_dothis{0[\the\numexpr0\XINT_expr_scanexp_a +}\fi |
| 39761 |
\if E#1\xint_dothis{0[\the\numexpr0\XINT_expr_scanexp_a +}\fi |
| 39762 |
\if .#1\xint_dothis{\XINT_expr_gobz_startdec_a .}\fi |
| 39763 |
\if 0#1\xint_dothis\XINT_expr_gobz_scanint_again\fi |
| 39764 |
\xint_orthat |
| 39765 |
{0\iffalse{{{\fi}}\expandafter}\romannumeral`&&@\XINT_expr_getop_a#1}% |
| 39766 |
}% |
| 39767 |
% \end{macrocode} |
| 39768 |
% \subsubsection{Fractional part} |
| 39769 |
%\begin{lverb} |
| 39770 |
% Annoying duplication of code to allow 0. as input. |
| 39771 |
% |
| 39772 |
% 1.2a corrects a very bad bug in 1.2 \XINT_expr_gobz_scandec_b which should |
| 39773 |
% have stripped leading zeroes in the fractional part but didn't; as a result |
| 39774 |
% \xinttheexpr 0.01\relax returned 0 =:-((( Thanks to Kroum Tzanev who |
| 39775 |
% reported the issue. Does it improve things if I say the bug was introduced |
| 39776 |
% in 1.2, it wasn't present before ? |
| 39777 |
% |
| 39778 |
% 1.4f had _getop here, but let's jump directly to _getop_a. |
| 39779 |
%\end{lverb} |
| 39780 |
% \begin{macrocode} |
| 39781 |
\def\XINT_expr_startdec_a .#1% |
| 39782 |
{% |
| 39783 |
\expandafter\XINT_expr_scandec_a\romannumeral`&&@#1% |
| 39784 |
}% |
| 39785 |
\def\XINT_expr_scandec_a #1% |
| 39786 |
{% |
| 39787 |
\if .#1\xint_dothis{\iffalse{{{\fi}}\expandafter}% |
| 39788 |
\romannumeral`&&@\XINT_expr_getop_a..}\fi |
| 39789 |
\xint_orthat {\XINT_expr_scandec_main 0.#1}% |
| 39790 |
}% |
| 39791 |
\def\XINT_expr_gobz_startdec_a .#1% |
| 39792 |
{% |
| 39793 |
\expandafter\XINT_expr_gobz_scandec_a\romannumeral`&&@#1% |
| 39794 |
}% |
| 39795 |
\def\XINT_expr_gobz_scandec_a #1% |
| 39796 |
{% |
| 39797 |
\if .#1\xint_dothis |
| 39798 |
{0\iffalse{{{\fi}}\expandafter}\romannumeral`&&@\XINT_expr_getop_a..}\fi |
| 39799 |
\xint_orthat {\XINT_expr_gobz_scandec_main 0.#1}% |
| 39800 |
}% |
| 39801 |
\def\XINT_expr_scandec_main #1.#2% |
| 39802 |
{% |
| 39803 |
\ifcat \relax #2\expandafter\XINT_expr_scandec_hit_cs\fi |
| 39804 |
\ifnum\xint_c_ix<1\string#2 \else\expandafter\XINT_expr_scandec_next\fi |
| 39805 |
#2\expandafter\XINT_expr_scandec_again\the\numexpr #1-\xint_c_i.% |
| 39806 |
}% |
| 39807 |
\def\XINT_expr_scandec_again #1.#2% |
| 39808 |
{% |
| 39809 |
\expandafter\XINT_expr_scandec_main |
| 39810 |
\the\numexpr #1\expandafter.\romannumeral`&&@#2% |
| 39811 |
}% |
| 39812 |
% \end{macrocode} |
| 39813 |
% |1.4f| had |_getop| here, but let's jump directly to |_getop_a|. |
| 39814 |
% \begin{macrocode} |
| 39815 |
\def\XINT_expr_scandec_hit_cs\ifnum#1\fi |
| 39816 |
#2\expandafter\XINT_expr_scandec_again\the\numexpr#3-\xint_c_i.% |
| 39817 |
{% |
| 39818 |
[#3]\iffalse{{{\fi}}\expandafter}\romannumeral`&&@\XINT_expr_getop_a#2% |
| 39819 |
}% |
| 39820 |
\def\XINT_expr_scandec_next #1#2\the\numexpr#3-\xint_c_i.% |
| 39821 |
{% |
| 39822 |
\if _#1\xint_dothis{\XINT_expr_scandec_again#3.}\fi |
| 39823 |
\if e#1\xint_dothis{[\the\numexpr#3\XINT_expr_scanexp_a +}\fi |
| 39824 |
\if E#1\xint_dothis{[\the\numexpr#3\XINT_expr_scanexp_a +}\fi |
| 39825 |
\xint_orthat |
| 39826 |
{[#3]\iffalse{{{\fi}}\expandafter}\romannumeral`&&@\XINT_expr_getop_a#1}% |
| 39827 |
}% |
| 39828 |
\def\XINT_expr_gobz_scandec_main #1.#2% |
| 39829 |
{% |
| 39830 |
\ifcat \relax #2\expandafter\XINT_expr_gobz_scandec_hit_cs\fi |
| 39831 |
\ifnum\xint_c_ix<1\string#2 \else\expandafter\XINT_expr_gobz_scandec_next\fi |
| 39832 |
\if0#2\expandafter\xint_firstoftwo\else\expandafter\xint_secondoftwo\fi |
| 39833 |
{\expandafter\XINT_expr_gobz_scandec_main}% |
| 39834 |
{#2\expandafter\XINT_expr_scandec_again}\the\numexpr#1-\xint_c_i.% |
| 39835 |
}% |
| 39836 |
% \end{macrocode} |
| 39837 |
% |1.4f| had |_getop| here, but let's jump directly to |_getop_a|. |
| 39838 |
% \begin{macrocode} |
| 39839 |
\def\XINT_expr_gobz_scandec_hit_cs \ifnum#1\fi\if0#2#3\xint_c_i.% |
| 39840 |
{% |
| 39841 |
0[0]\iffalse{{{\fi}}\expandafter}\romannumeral`&&@\XINT_expr_getop_a#2% |
| 39842 |
}% |
| 39843 |
\def\XINT_expr_gobz_scandec_next\if0#1#2\fi #3\numexpr#4-\xint_c_i.% |
| 39844 |
{% |
| 39845 |
\if _#1\xint_dothis{\XINT_expr_gobz_scandec_main #4.}\fi |
| 39846 |
\if e#1\xint_dothis{0[\the\numexpr0\XINT_expr_scanexp_a +}\fi |
| 39847 |
\if E#1\xint_dothis{0[\the\numexpr0\XINT_expr_scanexp_a +}\fi |
| 39848 |
\xint_orthat |
| 39849 |
{0[0]\iffalse{{{\fi}}\expandafter}\romannumeral`&&@\XINT_expr_getop_a#1}% |
| 39850 |
}% |
| 39851 |
% \end{macrocode} |
| 39852 |
% \subsubsection{Scientific notation} |
| 39853 |
%\begin{lverb} |
| 39854 |
% Some pluses and minuses are allowed at the start of the scientific |
| 39855 |
% part, however not later, and no parenthesis. |
| 39856 |
% |
| 39857 |
% ATTENTION! 1e\numexpr2+3\relax or 1e\xintiexpr i\relax, i=1..5 |
| 39858 |
% are not allowed and 1e1\numexpr2\relax does 1e1 * \numexpr2\relax. |
| 39859 |
% Use \the\numexpr, \xinttheiexpr, etc... |
| 39860 |
%\end{lverb} |
| 39861 |
% \begin{macrocode} |
| 39862 |
\def\XINT_expr_scanexp_a #1#2% |
| 39863 |
{% |
| 39864 |
#1\expandafter\XINT_expr_scanexp_main\romannumeral`&&@#2% |
| 39865 |
}% |
| 39866 |
\def\XINT_expr_scanexp_main #1% |
| 39867 |
{% |
| 39868 |
\ifcat \relax #1\expandafter\XINT_expr_scanexp_hit_cs\fi |
| 39869 |
\ifnum\xint_c_ix<1\string#1 \else\expandafter\XINT_expr_scanexp_next\fi |
| 39870 |
#1\XINT_expr_scanexp_again |
| 39871 |
}% |
| 39872 |
\def\XINT_expr_scanexp_again #1% |
| 39873 |
{% |
| 39874 |
\expandafter\XINT_expr_scanexp_main_b\romannumeral`&&@#1% |
| 39875 |
}% |
| 39876 |
% \end{macrocode} |
| 39877 |
% |1.4f| had |_getop| here, but let's jump directly to |_getop_a|. |
| 39878 |
% \begin{macrocode} |
| 39879 |
\def\XINT_expr_scanexp_hit_cs\ifnum#1\fi#2\XINT_expr_scanexp_again |
| 39880 |
{% |
| 39881 |
]\iffalse{{{\fi}}\expandafter}\romannumeral`&&@\XINT_expr_getop_a#2% |
| 39882 |
}% |
| 39883 |
\def\XINT_expr_scanexp_next #1\XINT_expr_scanexp_again |
| 39884 |
{% |
| 39885 |
\if _#1\xint_dothis \XINT_expr_scanexp_again \fi |
| 39886 |
\if +#1\xint_dothis {\XINT_expr_scanexp_a +}\fi |
| 39887 |
\if -#1\xint_dothis {\XINT_expr_scanexp_a -}\fi |
| 39888 |
\xint_orthat |
| 39889 |
{]\iffalse{{{\fi}}\expandafter}\romannumeral`&&@\XINT_expr_getop_a#1}% |
| 39890 |
}% |
| 39891 |
\def\XINT_expr_scanexp_main_b #1% |
| 39892 |
{% |
| 39893 |
\ifcat \relax #1\expandafter\XINT_expr_scanexp_hit_cs_b\fi |
| 39894 |
\ifnum\xint_c_ix<1\string#1 \else\expandafter\XINT_expr_scanexp_next_b\fi |
| 39895 |
#1\XINT_expr_scanexp_again_b |
| 39896 |
}% |
| 39897 |
% \end{macrocode} |
| 39898 |
% |1.4f| had |_getop| here, but let's jump directly to |_getop_a|. |
| 39899 |
% \begin{macrocode} |
| 39900 |
\def\XINT_expr_scanexp_hit_cs_b\ifnum#1\fi#2\XINT_expr_scanexp_again_b |
| 39901 |
{% |
| 39902 |
]\iffalse{{{\fi}}\expandafter}\romannumeral`&&@\XINT_expr_getop_a#2% |
| 39903 |
}% |
| 39904 |
\def\XINT_expr_scanexp_again_b #1% |
| 39905 |
{% |
| 39906 |
\expandafter\XINT_expr_scanexp_main_b\romannumeral`&&@#1% |
| 39907 |
}% |
| 39908 |
\def\XINT_expr_scanexp_next_b #1\XINT_expr_scanexp_again_b |
| 39909 |
{% |
| 39910 |
\if _#1\xint_dothis\XINT_expr_scanexp_again\fi |
| 39911 |
\xint_orthat |
| 39912 |
{]\iffalse{{{\fi}}\expandafter}\romannumeral`&&@\XINT_expr_getop_a#1}% |
| 39913 |
}% |
| 39914 |
% \end{macrocode} |
| 39915 |
% \subsubsection{Hexadecimal numbers} |
| 39916 |
%\begin{lverb} |
| 39917 |
% 1.2d has moved most of the handling of tacit multiplication to |
| 39918 |
% \XINT_expr_getop, but we have to do some of it here, because we apply |
| 39919 |
% \string before calling \XINT_expr_scanhexI_aa. I do not insert the * |
| 39920 |
% in \XINT_expr_scanhexI_a, because it is its higher precedence variant which |
| 39921 |
% will is expected, to do the same as when a non-hexadecimal number prefixes a |
| 39922 |
% sub-expression. Tacit multiplication in front of variable or function names |
| 39923 |
% will not work (because of this \string). |
| 39924 |
% |
| 39925 |
% Extended for 1.2l to ignore underscore character _ if encountered within |
| 39926 |
% digits. |
| 39927 |
% |
| 39928 |
% (some above remarks have been obsoleted for some long time, no more applied |
| 39929 |
% \string since 1.4) |
| 39930 |
% |
| 39931 |
% Notice that internal representation adds a [N] part only in case input |
| 39932 |
% used "DDD.dddd form, for compatibility with \xintiiexpr which is not |
| 39933 |
% compatible with such internal representation. |
| 39934 |
% |
| 39935 |
% At 1.4g a very long-standing bug was fixed: input such as "\foo broke the |
| 39936 |
% parser because (incredibly) the \foo token was picked up unexpanded and |
| 39937 |
% ended up as is in an \ifcat ! |
| 39938 |
% |
| 39939 |
% Another long-standing bug was fixed at 1.4g: contrarily to the decimal case, |
| 39940 |
% here in the hexadecimal input leading zeros were not trimmed. This was ok, |
| 39941 |
% because formerly \xintHexToDec trimmed leading zeros, but at 1.2m 2017/07/31 |
| 39942 |
% xintbinhex.sty was modified and this ceased being the case. But I forgot to |
| 39943 |
% upgrade the parser here at that time. Leading zeros would in many |
| 39944 |
% circumstances (presence of a fractional part, or \xintiiexpr context) lead |
| 39945 |
% to wrong results. Leading zeros are now trimmed during input. |
| 39946 |
% |
| 39947 |
%\end{lverb} |
| 39948 |
% \begin{macrocode} |
| 39949 |
\def\XINT_expr_hex_in #1.#2#3;% |
| 39950 |
{% |
| 39951 |
\expanded{{{\if#2>% |
| 39952 |
\xintHexToDec{#1}% |
| 39953 |
\else |
| 39954 |
\xintiiMul{\xintiiPow{625}{\xintLength{#3}}}{\xintHexToDec{#1#3}}% |
| 39955 |
[\the\numexpr-4*\xintLength{#3}]% |
| 39956 |
\fi}}\expandafter}\romannumeral`&&@\XINT_expr_getop |
| 39957 |
}% |
| 39958 |
% \end{macrocode} |
| 39959 |
%\begin{lverb} |
| 39960 |
% Let's not forget to grab-expand next token first as is normal rule |
| 39961 |
% of operation. Formerly called \XINT_expr_scanhex_I and had " upfront. |
| 39962 |
%\end{lverb} |
| 39963 |
% \begin{macrocode} |
| 39964 |
\def\XINT_expr_starthex #1% |
| 39965 |
{% |
| 39966 |
\expandafter\XINT_expr_hex_in\expanded\bgroup |
| 39967 |
\expandafter\XINT_expr_scanhexIgobz_a\romannumeral`&&@#1% |
| 39968 |
}% |
| 39969 |
\def\XINT_expr_scanhexIgobz_a #1% |
| 39970 |
{% |
| 39971 |
\ifcat #1\relax |
| 39972 |
0.>;\iffalse{\fi\expandafter}\expandafter\xint_gobble_i\fi |
| 39973 |
\XINT_expr_scanhexIgobz_aa #1% |
| 39974 |
}% |
| 39975 |
\def\XINT_expr_scanhexIgobz_aa #1% |
| 39976 |
{% |
| 39977 |
\if\ifnum`#1>`0 |
| 39978 |
\ifnum`#1>`9 |
| 39979 |
\ifnum`#1>`@ |
| 39980 |
\ifnum`#1>`F |
| 39981 |
0\else1\fi\else0\fi\else1\fi\else0\fi 1% |
| 39982 |
\xint_dothis\XINT_expr_scanhexI_b |
| 39983 |
\fi |
| 39984 |
\if 0#1\xint_dothis\XINT_expr_scanhexIgobz_bgob\fi |
| 39985 |
\if _#1\xint_dothis\XINT_expr_scanhexIgobz_bgob\fi |
| 39986 |
\if .#1\xint_dothis\XINT_expr_scanhexIgobz_toII\fi |
| 39987 |
\xint_orthat |
| 39988 |
{\XINT_expandableerror |
| 39989 |
{Expected hexadecimal digit, `_', or `.'. got `#1'. Using `0'.}% |
| 39990 |
0.>;\iffalse{\fi}}% |
| 39991 |
#1% |
| 39992 |
}% |
| 39993 |
\def\XINT_expr_scanhexIgobz_bgob #1#2% |
| 39994 |
{% |
| 39995 |
\expandafter\XINT_expr_scanhexIgobz_a\romannumeral`&&@#2% |
| 39996 |
}% |
| 39997 |
\def\XINT_expr_scanhexIgobz_toII .#1% |
| 39998 |
{% |
| 39999 |
0..\expandafter\XINT_expr_scanhexII_a\romannumeral`&&@#1% |
| 40000 |
}% |
| 40001 |
\def\XINT_expr_scanhexI_a #1% |
| 40002 |
{% |
| 40003 |
\ifcat #1\relax |
| 40004 |
.>;\iffalse{\fi\expandafter}\expandafter\xint_gobble_i\fi |
| 40005 |
\XINT_expr_scanhexI_aa #1% |
| 40006 |
}% |
| 40007 |
\def\XINT_expr_scanhexI_aa #1% |
| 40008 |
{% |
| 40009 |
\if\ifnum`#1>`/ |
| 40010 |
\ifnum`#1>`9 |
| 40011 |
\ifnum`#1>`@ |
| 40012 |
\ifnum`#1>`F |
| 40013 |
0\else1\fi\else0\fi\else1\fi\else0\fi 1% |
| 40014 |
\expandafter\XINT_expr_scanhexI_b |
| 40015 |
\else |
| 40016 |
\if _#1\xint_dothis{\expandafter\XINT_expr_scanhexI_bgob}\fi |
| 40017 |
\if .#1\xint_dothis{\expandafter\XINT_expr_scanhexI_toII}\fi |
| 40018 |
\xint_orthat {.>;\iffalse{\fi\expandafter}}% |
| 40019 |
\fi |
| 40020 |
#1% |
| 40021 |
}% |
| 40022 |
\def\XINT_expr_scanhexI_b #1#2% |
| 40023 |
{% |
| 40024 |
#1\expandafter\XINT_expr_scanhexI_a\romannumeral`&&@#2% |
| 40025 |
}% |
| 40026 |
\def\XINT_expr_scanhexI_bgob #1#2% |
| 40027 |
{% |
| 40028 |
\expandafter\XINT_expr_scanhexI_a\romannumeral`&&@#2% |
| 40029 |
}% |
| 40030 |
\def\XINT_expr_scanhexI_toII .#1% |
| 40031 |
{% |
| 40032 |
..\expandafter\XINT_expr_scanhexII_a\romannumeral`&&@#1% |
| 40033 |
}% |
| 40034 |
\def\XINT_expr_scanhexII_a #1% |
| 40035 |
{% |
| 40036 |
\ifcat #1\relax\xint_dothis{;\iffalse{\fi}#1}\fi |
| 40037 |
\xint_orthat {\XINT_expr_scanhexII_aa #1}% |
| 40038 |
}% |
| 40039 |
\def\XINT_expr_scanhexII_aa #1% |
| 40040 |
{% |
| 40041 |
\if\ifnum`#1>`/ |
| 40042 |
\ifnum`#1>`9 |
| 40043 |
\ifnum`#1>`@ |
| 40044 |
\ifnum`#1>`F |
| 40045 |
0\else1\fi\else0\fi\else1\fi\else0\fi 1% |
| 40046 |
\expandafter\XINT_expr_scanhexII_b |
| 40047 |
\else |
| 40048 |
\if _#1\xint_dothis{\expandafter\XINT_expr_scanhexII_bgob}\fi |
| 40049 |
\xint_orthat{;\iffalse{\fi\expandafter}}% |
| 40050 |
\fi |
| 40051 |
#1% |
| 40052 |
}% |
| 40053 |
\def\XINT_expr_scanhexII_b #1#2% |
| 40054 |
{% |
| 40055 |
#1\expandafter\XINT_expr_scanhexII_a\romannumeral`&&@#2% |
| 40056 |
}% |
| 40057 |
\def\XINT_expr_scanhexII_bgob #1#2% |
| 40058 |
{% |
| 40059 |
\expandafter\XINT_expr_scanhexII_a\romannumeral`&&@#2% |
| 40060 |
}% |
| 40061 |
% \end{macrocode} |
| 40062 |
% \subsubsection{Octal numbers} |
| 40063 |
% \added{1.4n} |
| 40064 |
% |
| 40065 |
% The parsing goes exactly as with hexadecimal inputs, |
| 40066 |
% except that we require an octal digit when expected. |
| 40067 |
% |
| 40068 |
% TODO: think about perhaps sharing code between binary, octal, and |
| 40069 |
% hexadecimal. |
| 40070 |
% \begin{macrocode} |
| 40071 |
\def\XINT_expr_oct_in #1.#2#3;% |
| 40072 |
{% |
| 40073 |
\expanded{{{\if#2>% |
| 40074 |
\xintOctToDec{#1}% |
| 40075 |
\else |
| 40076 |
\xintiiMul{\xintiiPow{125}{\xintLength{#3}}}{\xintOctToDec{#1#3}}% |
| 40077 |
[\the\numexpr-3*\xintLength{#3}]% |
| 40078 |
\fi}}\expandafter}\romannumeral`&&@\XINT_expr_getop |
| 40079 |
}% |
| 40080 |
% \begin{macrocode} |
| 40081 |
\def\XINT_expr_startoct #1% |
| 40082 |
{% |
| 40083 |
\expandafter\XINT_expr_oct_in\expanded\bgroup |
| 40084 |
\expandafter\XINT_expr_scanoctIgobz_a\romannumeral`&&@#1% |
| 40085 |
}% |
| 40086 |
\def\XINT_expr_scanoctIgobz_a #1% |
| 40087 |
{% |
| 40088 |
\ifcat #1\relax |
| 40089 |
0.>;\iffalse{\fi\expandafter}\expandafter\xint_gobble_i\fi |
| 40090 |
\XINT_expr_scanoctIgobz_aa #1% |
| 40091 |
}% |
| 40092 |
% \end{macrocode} |
| 40093 |
% Wondering if a bunch of \cs{if} tests comparing with 0 to 7 would |
| 40094 |
% not be more efficient here. But testing would take some time |
| 40095 |
% I am not motivated enough to use for that. In the code, also added |
| 40096 |
% at |1.4n| for parsing binary input, I do this, but of course then |
| 40097 |
% it was rather more natural to do. But I did not test either comparing |
| 40098 |
% with style as here. |
| 40099 |
% \begin{macrocode} |
| 40100 |
\def\XINT_expr_scanoctIgobz_aa #1% |
| 40101 |
{% |
| 40102 |
\if\ifnum`#1>`0 \ifnum`#1>`7 0\else1\fi\else0\fi 1% |
| 40103 |
\xint_dothis\XINT_expr_scanoctI_b |
| 40104 |
\fi |
| 40105 |
\if 0#1\xint_dothis\XINT_expr_scanoctIgobz_bgob\fi |
| 40106 |
\if _#1\xint_dothis\XINT_expr_scanoctIgobz_bgob\fi |
| 40107 |
\if .#1\xint_dothis\XINT_expr_scanoctIgobz_toII\fi |
| 40108 |
\xint_orthat |
| 40109 |
{\XINT_expandableerror |
| 40110 |
{Expected an octal digit, `_', or `.'. Got `#1'. Using `0'.}% |
| 40111 |
0.>;\iffalse{\fi}}% |
| 40112 |
#1% |
| 40113 |
}% |
| 40114 |
\def\XINT_expr_scanoctIgobz_bgob #1#2% |
| 40115 |
{% |
| 40116 |
\expandafter\XINT_expr_scanoctIgobz_a\romannumeral`&&@#2% |
| 40117 |
}% |
| 40118 |
\def\XINT_expr_scanoctIgobz_toII .#1% |
| 40119 |
{% |
| 40120 |
0..\expandafter\XINT_expr_scanoctII_a\romannumeral`&&@#1% |
| 40121 |
}% |
| 40122 |
\def\XINT_expr_scanoctI_a #1% |
| 40123 |
{% |
| 40124 |
\ifcat #1\relax |
| 40125 |
.>;\iffalse{\fi\expandafter}\expandafter\xint_gobble_i\fi |
| 40126 |
\XINT_expr_scanoctI_aa #1% |
| 40127 |
}% |
| 40128 |
\def\XINT_expr_scanoctI_aa #1% |
| 40129 |
{% |
| 40130 |
\if\ifnum`#1>`/ \ifnum`#1>`7 0\else1\fi\else0\fi 1% |
| 40131 |
\expandafter\XINT_expr_scanoctI_b |
| 40132 |
\else |
| 40133 |
\if _#1\xint_dothis{\expandafter\XINT_expr_scanoctI_bgob}\fi |
| 40134 |
\if .#1\xint_dothis{\expandafter\XINT_expr_scanoctI_toII}\fi |
| 40135 |
\xint_orthat {.>;\iffalse{\fi\expandafter}}% |
| 40136 |
\fi |
| 40137 |
#1% |
| 40138 |
}% |
| 40139 |
\def\XINT_expr_scanoctI_b #1#2% |
| 40140 |
{% |
| 40141 |
#1\expandafter\XINT_expr_scanoctI_a\romannumeral`&&@#2% |
| 40142 |
}% |
| 40143 |
\def\XINT_expr_scanoctI_bgob #1#2% |
| 40144 |
{% |
| 40145 |
\expandafter\XINT_expr_scanoctI_a\romannumeral`&&@#2% |
| 40146 |
}% |
| 40147 |
\def\XINT_expr_scanoctI_toII .#1% |
| 40148 |
{% |
| 40149 |
..\expandafter\XINT_expr_scanoctII_a\romannumeral`&&@#1% |
| 40150 |
}% |
| 40151 |
\def\XINT_expr_scanoctII_a #1% |
| 40152 |
{% |
| 40153 |
\ifcat #1\relax\xint_dothis{;\iffalse{\fi}#1}\fi |
| 40154 |
\xint_orthat {\XINT_expr_scanoctII_aa #1}% |
| 40155 |
}% |
| 40156 |
\def\XINT_expr_scanoctII_aa #1% |
| 40157 |
{% |
| 40158 |
\if\ifnum`#1>`/ \ifnum`#1>`7 0\else1\fi\else0\fi 1% |
| 40159 |
\expandafter\XINT_expr_scanoctII_b |
| 40160 |
\else |
| 40161 |
\if _#1\xint_dothis{\expandafter\XINT_expr_scanoctII_bgob}\fi |
| 40162 |
\xint_orthat{;\iffalse{\fi\expandafter}}% |
| 40163 |
\fi |
| 40164 |
#1% |
| 40165 |
}% |
| 40166 |
\def\XINT_expr_scanoctII_b #1#2% |
| 40167 |
{% |
| 40168 |
#1\expandafter\XINT_expr_scanoctII_a\romannumeral`&&@#2% |
| 40169 |
}% |
| 40170 |
\def\XINT_expr_scanoctII_bgob #1#2% |
| 40171 |
{% |
| 40172 |
\expandafter\XINT_expr_scanoctII_a\romannumeral`&&@#2% |
| 40173 |
}% |
| 40174 |
% \end{macrocode} |
| 40175 |
% \subsubsection{Binary numbers} |
| 40176 |
% \added{1.4n} |
| 40177 |
% Analogous to hexadecimal or octal with some simpler tests for digits. |
| 40178 |
% \begin{macrocode} |
| 40179 |
\def\XINT_expr_bin_in #1.#2#3;% |
| 40180 |
{% |
| 40181 |
\expanded{{{\if#2>% |
| 40182 |
\xintBinToDec{#1}% |
| 40183 |
\else |
| 40184 |
\xintiiMul{\xintiiPow{5}{\xintLength{#3}}}{\xintBinToDec{#1#3}}% |
| 40185 |
[\the\numexpr-\xintLength{#3}]% |
| 40186 |
\fi}}\expandafter}\romannumeral`&&@\XINT_expr_getop |
| 40187 |
}% |
| 40188 |
% \begin{macrocode} |
| 40189 |
\def\XINT_expr_startbin #1% |
| 40190 |
{% |
| 40191 |
\expandafter\XINT_expr_bin_in\expanded\bgroup |
| 40192 |
\expandafter\XINT_expr_scanbinIgobz_a\romannumeral`&&@#1% |
| 40193 |
}% |
| 40194 |
\def\XINT_expr_scanbinIgobz_a #1% |
| 40195 |
{% |
| 40196 |
\ifcat #1\relax |
| 40197 |
0.>;\iffalse{\fi\expandafter}\expandafter\xint_gobble_i\fi |
| 40198 |
\XINT_expr_scanbinIgobz_aa #1% |
| 40199 |
}% |
| 40200 |
\def\XINT_expr_scanbinIgobz_aa #1% |
| 40201 |
{% |
| 40202 |
\if _#1\xint_dothis\XINT_expr_scanbinIgobz_bgob\fi |
| 40203 |
\if .#1\xint_dothis\XINT_expr_scanbinIgobz_toII\fi |
| 40204 |
\if 0#1\xint_dothis\XINT_expr_scanbinIgobz_bgob\fi |
| 40205 |
\if 1#1\xint_dothis\XINT_expr_scanbinI_b\fi |
| 40206 |
\xint_orthat |
| 40207 |
{\XINT_expandableerror |
| 40208 |
{Expected a binary digit, `_', or `.'. Got `#1'. Using `0'.}% |
| 40209 |
0.>;\iffalse{\fi}}% |
| 40210 |
#1% |
| 40211 |
}% |
| 40212 |
\def\XINT_expr_scanbinIgobz_bgob #1#2% |
| 40213 |
{% |
| 40214 |
\expandafter\XINT_expr_scanbinIgobz_a\romannumeral`&&@#2% |
| 40215 |
}% |
| 40216 |
\def\XINT_expr_scanbinIgobz_toII .#1% |
| 40217 |
{% |
| 40218 |
0..\expandafter\XINT_expr_scanbinII_a\romannumeral`&&@#1% |
| 40219 |
}% |
| 40220 |
\def\XINT_expr_scanbinI_a #1% |
| 40221 |
{% |
| 40222 |
\ifcat #1\relax |
| 40223 |
.>;\iffalse{\fi\expandafter}\expandafter\xint_gobble_i\fi |
| 40224 |
\XINT_expr_scanbinI_aa #1% |
| 40225 |
}% |
| 40226 |
\def\XINT_expr_scanbinI_aa #1% |
| 40227 |
{% |
| 40228 |
\if _#1\xint_dothis\XINT_expr_scanbinI_bgob\fi |
| 40229 |
\if .#1\xint_dothis\XINT_expr_scanbinI_toII\fi |
| 40230 |
\if 0#1\xint_dothis\XINT_expr_scanbinI_b\fi |
| 40231 |
\if 1#1\xint_dothis\XINT_expr_scanbinI_b\fi |
| 40232 |
\xint_orthat {.>;\iffalse{\fi}}% |
| 40233 |
#1% |
| 40234 |
}% |
| 40235 |
\def\XINT_expr_scanbinI_b #1#2% |
| 40236 |
{% |
| 40237 |
#1\expandafter\XINT_expr_scanbinI_a\romannumeral`&&@#2% |
| 40238 |
}% |
| 40239 |
\def\XINT_expr_scanbinI_bgob #1#2% |
| 40240 |
{% |
| 40241 |
\expandafter\XINT_expr_scanbinI_a\romannumeral`&&@#2% |
| 40242 |
}% |
| 40243 |
\def\XINT_expr_scanbinI_toII .#1% |
| 40244 |
{% |
| 40245 |
..\expandafter\XINT_expr_scanbinII_a\romannumeral`&&@#1% |
| 40246 |
}% |
| 40247 |
\def\XINT_expr_scanbinII_a #1% |
| 40248 |
{% |
| 40249 |
\ifcat #1\relax\xint_dothis{;\iffalse{\fi}#1}\fi |
| 40250 |
\xint_orthat {\XINT_expr_scanbinII_aa #1}% |
| 40251 |
}% |
| 40252 |
\def\XINT_expr_scanbinII_aa #1% |
| 40253 |
{% |
| 40254 |
\if _#1\xint_dothis\XINT_expr_scanbinII_bgob\fi |
| 40255 |
\if 0#1\xint_dothis\XINT_expr_scanbinII_b\fi |
| 40256 |
\if 1#1\xint_dothis\XINT_expr_scanbinII_b\fi |
| 40257 |
\xint_orthat{;\iffalse{\fi}}% |
| 40258 |
#1% |
| 40259 |
}% |
| 40260 |
\def\XINT_expr_scanbinII_b #1#2% |
| 40261 |
{% |
| 40262 |
#1\expandafter\XINT_expr_scanbinII_a\romannumeral`&&@#2% |
| 40263 |
}% |
| 40264 |
\def\XINT_expr_scanbinII_bgob #1#2% |
| 40265 |
{% |
| 40266 |
\expandafter\XINT_expr_scanbinII_a\romannumeral`&&@#2% |
| 40267 |
}% |
| 40268 |
% \end{macrocode} |
| 40269 |
% \subsubsection{\csh{XINT_expr_startfunc}: collecting names of functions and |
| 40270 |
% variables} |
| 40271 |
% |
| 40272 |
%\begin{lverb} |
| 40273 |
% At 1.4 the first token left over has not been submitted to |
| 40274 |
% \string. We also know it is not a control sequence. So we can test catcode |
| 40275 |
% to identify if operator is found. And it is allowed to hit some operator |
| 40276 |
% such as a closing parenthesis we will then insert the «nil» value (edited: which |
| 40277 |
% however will cause certain breakage of the infix binary operators: I notice |
| 40278 |
% I did not insert None {{}} but nil {}, perhaps by oversight). |
| 40279 |
% |
| 40280 |
% There was prior to 1.4 solely the dispatch in \XINT_expr_scanfunc_b |
| 40281 |
% but now we do it immediately and issue \XINT_expr_func only in certain |
| 40282 |
% cases. |
| 40283 |
% |
| 40284 |
% Comments here have been removed because 1.4g did a refactoring |
| 40285 |
% and renamed \XINT_expr_scanfunc to \XINT_expr_startfunc, moving half of |
| 40286 |
% it earlier inside the getnextfork macros. |
| 40287 |
%\end{lverb} |
| 40288 |
% \begin{macrocode} |
| 40289 |
\def\XINT_expr_startfunc #1% |
| 40290 |
{\expandafter\XINT_expr_func\expanded\bgroup#1\XINT_expr_scanfunc_a}% |
| 40291 |
\def\XINT_expr_scanfunc_a #1% |
| 40292 |
{% |
| 40293 |
\expandafter\XINT_expr_scanfunc_b\romannumeral`&&@#1% |
| 40294 |
}% |
| 40295 |
% \end{macrocode} |
| 40296 |
%\begin{lverb} |
| 40297 |
% This handles: 1) (indirectly) tacit multiplication by a variable in |
| 40298 |
% front a of sub-expression, 2) (indirectly) tacit multiplication in front of |
| 40299 |
% a \count etc..., 3) functions which are recognized via an encountered opening |
| 40300 |
% parenthesis (but later this must be disambiguated from variables with tacit |
| 40301 |
% multiplication) 4) 5) 6) 7) acceptable components of a variable or function |
| 40302 |
% names: @, underscore, digits, letters (or chars of category code letter.) |
| 40303 |
% |
| 40304 |
% The short lived 1.2d which followed the even shorter lived 1.2c managed to |
| 40305 |
% introduce a bug here as it removed the check for catcode 11 !, which must be |
| 40306 |
% recognized if ! is not to be taken as part of a variable name. Don't know |
| 40307 |
% what I was thinking, it was the time when I was moving the handling of tacit |
| 40308 |
% mutliplication entirely to the \XINT_expr_getop side. Fixed in 1.2e. |
| 40309 |
% |
| 40310 |
% I almost decided to remove the \ifcat\relax test whose rôle is to avoid the |
| 40311 |
% \string#1 to do something bad is the escape char is a digit! Perhaps I will |
| 40312 |
% remove it at some point ! I truly almost did it, but also the case of no |
| 40313 |
% escape char is a problem (\string\0, if \0 is a count ...) |
| 40314 |
% |
| 40315 |
% The (indirectly) above means that via \XINT_expr_func then \XINT_expr_op__ |
| 40316 |
% one goes back to \XINT_expr_getop then \XINT_expr_getop_b which is the |
| 40317 |
% location where tacit multiplication is now centralized. This makes the |
| 40318 |
% treatment of tacit multiplication for situations such as <variable>\count or |
| 40319 |
% <variable>\xintexpr..\relax, perhaps a bit sub-optimal, but first the |
| 40320 |
% variable name must be gathered, second the variable must expand to its |
| 40321 |
% value. |
| 40322 |
%\end{lverb} |
| 40323 |
% \begin{macrocode} |
| 40324 |
\def\XINT_expr_scanfunc_b #1% |
| 40325 |
{% |
| 40326 |
\ifcat \relax#1\xint_dothis{\iffalse{\fi}(_#1}\fi |
| 40327 |
\if (#1\xint_dothis{\iffalse{\fi}(`}\fi |
| 40328 |
\if 1\ifcat a#10\fi |
| 40329 |
\ifnum\xint_c_ix<1\string#1 0\fi |
| 40330 |
\if @#10\fi |
| 40331 |
\if _#10\fi |
| 40332 |
1% |
| 40333 |
\xint_dothis{\iffalse{\fi}(_#1}\fi |
| 40334 |
\xint_orthat {#1\XINT_expr_scanfunc_a}% |
| 40335 |
}% |
| 40336 |
% \end{macrocode} |
| 40337 |
% \subsubsection{\csh{XINT_expr_func}: dispatch to variable replacement or to |
| 40338 |
% function execution} |
| 40339 |
%\begin{lverb} |
| 40340 |
% Comments written 2015/11/12: earlier there was an \ifcsname test for |
| 40341 |
% checking if we had a variable in front of a (, for tacit multiplication for |
| 40342 |
% example in x(y+z(x+w)) to work. But after I had implemented functions (that |
| 40343 |
% was yesterday...), I had the problem if was impossible to re-declare a |
| 40344 |
% variable name such as "f" as a function name. The problem is that here we |
| 40345 |
% can not test if the function is available because we don't know if we are in |
| 40346 |
% expr, iiexpr or floatexpr. The \xint_c_ii^v causes all fetching operations |
| 40347 |
% to stop and control is handed over to the routines which will be expr, |
| 40348 |
% iiexpr ou floatexpr specific, i.e. the \XINT_{expr|iiexpr|flexpr}_op_{`|_} |
| 40349 |
% which are invoked by the until_<op>_b macros earlier in the stream. |
| 40350 |
% Functions may exist for one but not the two other parsers. Variables are |
| 40351 |
% declared via one parser and usable in the others, but naturally \xintiiexpr |
| 40352 |
% has its restrictions. |
| 40353 |
% |
| 40354 |
% Thinking about this again I decided to treat a priori cases such as x(...) |
| 40355 |
% as functions, after having assigned to each variable a low-weight macro |
| 40356 |
% which will convert this into _getop\.=<value of x>*(...). To activate that |
| 40357 |
% macro at the right time I could for this exploit the "onliteral" intercept, |
| 40358 |
% which is parser independent (1.2c). |
| 40359 |
% |
| 40360 |
% This led to me necessarily to rewrite partially the seq, add, mul, subs, |
| 40361 |
% iter ... routines as now the variables fetch only one token. I think the |
| 40362 |
% thing is more efficient. |
| 40363 |
% |
| 40364 |
% 1.2c had \def\XINT_expr_func #1(#2{\xint_c_ii^v #2{#1}} |
| 40365 |
% |
| 40366 |
% In \XINT_expr_func the #2 is _ if #1 must be a variable name, or #2=` if #1 |
| 40367 |
% must be either a function name or possibly a variable name which will then |
| 40368 |
% have to be followed by tacit multiplication before the opening parenthesis. |
| 40369 |
% |
| 40370 |
% The \xint_c_ii^v is there because _op_` must know in which parser |
| 40371 |
% it works. Dispendious for _. Hence I modify for 1.2d. |
| 40372 |
%\end{lverb} |
| 40373 |
% \begin{macrocode} |
| 40374 |
\def\XINT_expr_func #1(#2{\if _#2\xint_dothis{\XINT_expr_op__{#1}}\fi |
| 40375 |
\xint_orthat{{#1}\xint_c_ii^v #2}}% |
| 40376 |
% \end{macrocode} |
| 40377 |
% \subsection{\csh{XINT_expr_op_`}: launch function or |
| 40378 |
% pseudo-function, or evaluate variable and insert operator of multiplication |
| 40379 |
% in front of parenthesized contents} |
| 40380 |
% |
| 40381 |
%\begin{lverb} |
| 40382 |
% The "onliteral" intercepts is for bool, togl, protect, ... but also |
| 40383 |
% for add, mul, seq, etc... Genuine functions have expr, iiexpr and flexpr |
| 40384 |
% versions (or only one or two of the three) and trigger here the use of the |
| 40385 |
% suitable parser-dependant form. The former (pseudo functions and functions |
| 40386 |
% handling dummy variables) first trigger a parser independent mechanism. |
| 40387 |
% |
| 40388 |
% With 1.2c "onliteral" is also used to disambiguate a variable followed |
| 40389 |
% by an opening parenthesis from a function and then apply tacit multiplication. |
| 40390 |
% However as I use only a \ifcsname test, in order to be able to |
| 40391 |
% re-define a variable as function, I move the check for being a function |
| 40392 |
% first. Each variable name now has its onliteral_<name> associated macro. |
| 40393 |
% This used to be decided much earlier at the time of |
| 40394 |
% \XINT_expr_func. |
| 40395 |
% |
| 40396 |
% The advantage of 1.2c code is that the same name can be used for |
| 40397 |
% a variable or a function. |
| 40398 |
%\end{lverb} |
| 40399 |
% |
| 40400 |
% \changed[2021/06/11]{1.4i} |
| 40401 |
%\begin{lverb} |
| 40402 |
% The 1.2c abuse of «onliteral» for both tacit multiplication in front |
| 40403 |
% of an opening parenthesis and «generic» functions or pseudo-functions meant |
| 40404 |
% that the latter were vulnerable against user redefinition of a function name |
| 40405 |
% as a variable name. This applied to subs, subsm, subsn, seq, add, mul, |
| 40406 |
% ndseq, ndmap, ndfillraw, bool, togl, protect, qint, qfrac, qfloat, qraw, |
| 40407 |
% random, qrand, rbit and the most susceptible in real life was probably "seq". |
| 40408 |
% |
| 40409 |
% Now variables have an associated «var*» named macro, not «onliteral». |
| 40410 |
% |
| 40411 |
% In passing I refactor here in a \romannumeral inspired way how \csname and |
| 40412 |
% TeX booleans are intertwined, minimizing \expandafter usage. |
| 40413 |
%\end{lverb} |
| 40414 |
% |
| 40415 |
% \begin{macrocode} |
| 40416 |
\def\XINT_tmpa #1#2#3{% |
| 40417 |
\def #1##1% |
| 40418 |
{% |
| 40419 |
\csname |
| 40420 |
XINT_\ifcsname XINT_#3_func_##1\endcsname |
| 40421 |
#3_func_##1\expandafter\endcsname\romannumeral`&&@\expandafter#2% |
| 40422 |
\romannumeral\else |
| 40423 |
\ifcsname XINT_expr_onliteral_##1\endcsname |
| 40424 |
expr_onliteral_##1\expandafter\endcsname\romannumeral |
| 40425 |
\else |
| 40426 |
\ifcsname XINT_expr_var*_##1\endcsname |
| 40427 |
expr_var*_##1\expandafter\endcsname\romannumeral |
| 40428 |
\else |
| 40429 |
#3_func_\XINT_expr_unknown_function {##1}% |
| 40430 |
\expandafter\endcsname\romannumeral`&&@\expandafter#2% |
| 40431 |
\romannumeral |
| 40432 |
\fi\fi\fi\xint_c_ |
| 40433 |
}% |
| 40434 |
}% |
| 40435 |
\xintFor #1 in {expr,flexpr,iiexpr} \do {% |
| 40436 |
\expandafter\XINT_tmpa |
| 40437 |
\csname XINT_#1_op_`\expandafter\endcsname |
| 40438 |
\csname XINT_#1_oparen\endcsname |
| 40439 |
{#1}% |
| 40440 |
}% |
| 40441 |
\def\XINT_expr_unknown_function #1% |
| 40442 |
{\XINT_expandableerror{`#1' is unknown, say `Isome_func' or I use 0.}}% |
| 40443 |
\def\XINT_expr_func_ #1#2#3{#1#2{{0}}}% |
| 40444 |
\let\XINT_flexpr_func_\XINT_expr_func_ |
| 40445 |
\let\XINT_iiexpr_func_\XINT_expr_func_ |
| 40446 |
% \end{macrocode} |
| 40447 |
% |
| 40448 |
% \subsection{\csh{XINT_expr_op__}: replace a variable by its value and |
| 40449 |
% then fetch next operator} |
| 40450 |
%\begin{lverb} |
| 40451 |
% The 1.1 mechanism for \XINT_expr_var_<varname> has been |
| 40452 |
% modified in 1.2c. The <varname> associated macro is now only expanded |
| 40453 |
% once, not twice. We arrive here via \XINT_expr_func. |
| 40454 |
% |
| 40455 |
% At 1.4 \XINT_expr_getop is launched with accumulated result on its left. |
| 40456 |
% But the omit and abort keywords are implemented via fake variables |
| 40457 |
% which rely on possibility to modify incoming upfront tokens. If we did here |
| 40458 |
% something such as |
| 40459 |
% $centeredline$bgroup_var_#1\expandafter\endcsname\romannumeral`^^@\XINT_expr_getop$egroup |
| 40460 |
% the premature expansion of getop would break the var_omit and |
| 40461 |
% var_abort mechanism. Thus we revert |
| 40462 |
% to former code which locates an \XINT_expr_getop (call it _legacy) |
| 40463 |
% before the tokens from the variable expansion (in xintexpr < 1.4 the |
| 40464 |
% normal variables expanded |
| 40465 |
% to a single token so the overhead was not serious) so we can expand fake |
| 40466 |
% variables first. |
| 40467 |
% |
| 40468 |
% Abusing variables to manipulate the incoming token stream is a bit bad, |
| 40469 |
% usually I prefer functions for this (such as the break() function) but then |
| 40470 |
% I have to define 3 macros for the 3 parsers. |
| 40471 |
% |
| 40472 |
% This trick of fake variables puts thus a general overhead at various |
| 40473 |
% locations, and the situation here is REALLY not satisfactory. But 1.4 has |
| 40474 |
% (had) to be released now. |
| 40475 |
% |
| 40476 |
% Even if I could put the \csname XINT_expr_var_foo\endcsname upfront, which |
| 40477 |
% would then be f-expanded, this would still need \XINT_expr_put_op_first to |
| 40478 |
% use its \expandafter's as long as \XINT_expr_var_foo expands to |
| 40479 |
% {\XINT_expr_varvalue_foo} with a not-yet expanded \XINT_expr_var_value. |
| 40480 |
% |
| 40481 |
% I could let \XINT_expr_var_foo expand to |
| 40482 |
% \expandafter{\XINT_expr_varvalue_foo} allowing then (if it gets f-expanded) |
| 40483 |
% probably to drop the \expandafter in \XINT_expr_put_op_first. But I can not |
| 40484 |
% consider this option in the form |
| 40485 |
% $centeredline$bgroup_var_foo\expandafter\endcsname\romannumeral`^^@\XINT_expr_getop$egroup |
| 40486 |
% until the issue with fake variables such as omit and |
| 40487 |
% abort which must act before \XINT_expr_getop has some workaround. |
| 40488 |
% This could be implemented here with some extra branch, i.e. there would not |
| 40489 |
% be some \XINT_expr_var_omit but something else filtered out in the \else |
| 40490 |
% branch here. |
| 40491 |
% |
| 40492 |
% The above comments mention only omit and abort, but the case of real dummy |
| 40493 |
% variables also needs consideration. |
| 40494 |
% |
| 40495 |
% At 1.4g, I test first for existence of \XINT_expr_onliteral_foo. |
| 40496 |
% |
| 40497 |
% Updated for 1.4i: now rather existence of \XINT_expr_var*_foo is tested. |
| 40498 |
% |
| 40499 |
% This is |
| 40500 |
% a trick which allows to distinguish actual or dummy variables from really |
| 40501 |
% fake variables omit and abort (must check if there are others). For the real |
| 40502 |
% or dummy variables we can trigger the expansion of the \XINT_expr_getop |
| 40503 |
% before the one of the variable. I could test vor varvalue_foo but this |
| 40504 |
% applies only to real variables not dummy variables. Actual and dummy |
| 40505 |
% variables are thus handled slightly faster at 1.4g as there is less |
| 40506 |
% induced moving around (the \expandafter chain in \XINT_expr_put_op_first |
| 40507 |
% still applies at this stage, as I have not yet re-examined the var/varlue |
| 40508 |
% mechanism). And the test for var_foo is moved directly inside the \csname |
| 40509 |
% construct in the \else branch which now handles together |
| 40510 |
% fake variables and non-existing variables. |
| 40511 |
% |
| 40512 |
% I only have to make sure dummy variables are really safe being handled this |
| 40513 |
% way with the getop action having being done before they expand, but it looks |
| 40514 |
% ok. Attention it is crucial that if \XINT_expr_getop finds a \relax it inserts |
| 40515 |
% \xint_c_\relax so the \relax token is still there! |
| 40516 |
% |
| 40517 |
% With this refactoring the \XINT_expr_getop_legacy is applied only in case |
| 40518 |
% of non-existent variables or fake variables omit/abort or things such as |
| 40519 |
% nil, None, false, true, False, True. |
| 40520 |
% |
| 40521 |
% If user in interactive mode fixes the variable name, the \XINT_expr_var_foo |
| 40522 |
% expanded once with deliver {\XINT_expr_varvalue_foo} (if not dummy), and the |
| 40523 |
% braces are maintained by \XINT_expr_getop_legacy. |
| 40524 |
% |
| 40525 |
%\end{lverb} |
| 40526 |
% \begin{macrocode} |
| 40527 |
\def\XINT_expr_op__ #1% op__ with two _'s |
| 40528 |
{% |
| 40529 |
\ifcsname XINT_expr_var*_#1\endcsname |
| 40530 |
\csname XINT_expr_var_#1\expandafter\endcsname |
| 40531 |
\romannumeral`&&@\expandafter\XINT_expr_getop |
| 40532 |
\else |
| 40533 |
\expandafter\expandafter\expandafter\XINT_expr_getop_legacy |
| 40534 |
\csname XINT_expr_var_% |
| 40535 |
\ifcsname XINT_expr_var_#1\endcsname#1\else\XINT_expr_unknown_variable{#1}\fi |
| 40536 |
\expandafter\endcsname |
| 40537 |
\fi |
| 40538 |
}% |
| 40539 |
\def\XINT_expr_unknown_variable #1% |
| 40540 |
{\XINT_expandableerror {`#1' unknown, say `Isome_var' or I use 0.}}% |
| 40541 |
\def\XINT_expr_var_{{{0}}}% |
| 40542 |
\let\XINT_flexpr_op__ \XINT_expr_op__ |
| 40543 |
\let\XINT_iiexpr_op__ \XINT_expr_op__ |
| 40544 |
\def\XINT_expr_getop_legacy #1% |
| 40545 |
{% |
| 40546 |
\expanded{\xint_noxpd{{#1}}\expandafter}\romannumeral`&&@\XINT_expr_getop |
| 40547 |
}% |
| 40548 |
% \end{macrocode} |
| 40549 |
% \subsection{\csh{XINT_expr_getop}: fetch the next operator or closing |
| 40550 |
% parenthesis or end of expression} |
| 40551 |
%\begin{lverb} |
| 40552 |
% Release 1.1 implements multi-character operators. |
| 40553 |
% |
| 40554 |
% 1.2d adds tacit mutiplication also in front of variable or functions names |
| 40555 |
% starting with a letter, not only a @ or a _ as was already the case. This is |
| 40556 |
% for (x+y)z situations. It also applies higher precedence in cases like x/2y |
| 40557 |
% or x/2@, or x/2max(3,5), or x/2\xintexpr 3\relax. |
| 40558 |
% |
| 40559 |
% In fact, finally I decide that all sorts of tacit multiplication will always |
| 40560 |
% use the higher precedence. |
| 40561 |
% |
| 40562 |
% Indeed I hesitated somewhat: with the current code one does not know if |
| 40563 |
% \XINT_expr_getop as invoked after a closing parenthesis or because a number |
| 40564 |
% parsing ended, and I felt distinguishing the two was unneeded extra stuff. |
| 40565 |
% This means cases like (a+b)/(c+d)(e+f) will first multiply the last two |
| 40566 |
% parenthesized terms. |
| 40567 |
% |
| 40568 |
% |
| 40569 |
% 1.2q adds tacit multiplication in cases such as (1+1)3 or 5!7! |
| 40570 |
% |
| 40571 |
% 1.4 has simplified coding here as \XINT_expr_getop expansion happens |
| 40572 |
% at a time when a fetched value has already being stored. |
| 40573 |
% |
| 40574 |
% Prior to 1.4g there was an \if _#1\xint_dothis\xint_secondofthree\fi |
| 40575 |
% because the _ can be used to start names, for private use by package (for |
| 40576 |
% example by polexpr). But this test was silly because these usages are only |
| 40577 |
% with a _ of catcode 11. And allowing non-catcode 11 _ also to trigger tacit |
| 40578 |
% multiplication caused an infinite loop in collaboration with |
| 40579 |
% \XINT_expr_scanfunc, see explanations there (now removed after refactoring, |
| 40580 |
% see \XINT_expr_startfunc). |
| 40581 |
% |
| 40582 |
% The situation with the @ is different because we must allow it even as |
| 40583 |
% catcode 12 as a name, as it used in the syntax and must work the same if of |
| 40584 |
% catcode 11 or 12. No infinite loop because it is filtered out by one of the |
| 40585 |
% \XINT_expr_getnextfork macros. |
| 40586 |
% |
| 40587 |
% The check for : to send it to thirdofthree "getop" branch is needed, last |
| 40588 |
% time I checked, because during some part of at least \xintdeffunc, some |
| 40589 |
% scantokens are done which need to work with the : of catcode 11, and it |
| 40590 |
% would be misconstrued to start a name if not filtered out. |
| 40591 |
% |
| 40592 |
%\end{lverb} |
| 40593 |
% \odef\MakePrivateLetters{\MakePrivateLetters\catcode`* 11 }^^A |
| 40594 |
% \begin{macrocode} |
| 40595 |
\def\XINT_expr_getop #1% |
| 40596 |
{% |
| 40597 |
\expandafter\XINT_expr_getop_a\romannumeral`&&@#1% |
| 40598 |
}% |
| 40599 |
\catcode`* 11 |
| 40600 |
\def\XINT_expr_getop_a #1% |
| 40601 |
{% |
| 40602 |
\ifx \relax #1\xint_dothis\xint_firstofthree\fi |
| 40603 |
\ifcat \relax #1\xint_dothis\xint_secondofthree\fi |
| 40604 |
\ifnum\xint_c_ix<1\string#1 \xint_dothis\xint_secondofthree\fi |
| 40605 |
\if :#1\xint_dothis \xint_thirdofthree\fi |
| 40606 |
\if @#1\xint_dothis \xint_secondofthree\fi |
| 40607 |
\if (#1\xint_dothis \xint_secondofthree\fi %) |
| 40608 |
\ifcat a#1\xint_dothis \xint_secondofthree\fi |
| 40609 |
\xint_orthat \xint_thirdofthree |
| 40610 |
% \end{macrocode} |
| 40611 |
%\begin{lverb} |
| 40612 |
% Formerly \XINT_expr_foundend as firstofthree but at 1.4g let's |
| 40613 |
% simply insert \xint_c_ as the #1 is \relax (and anyhow a place-holder |
| 40614 |
% according to remark in definition of \XINT_expr_foundend |
| 40615 |
%\end{lverb} |
| 40616 |
% \begin{macrocode} |
| 40617 |
\xint_c_ |
| 40618 |
% \end{macrocode} |
| 40619 |
%\begin{lverb} |
| 40620 |
% Tacit multiplication with higher precedence. Formerly |
| 40621 |
% \XINT_expr_precedence_*** was used, renamed to \XINT_expr_prec_tacit at |
| 40622 |
% 1.4g in case a backport is done of the \bnumdefinfix from bnumexpr. |
| 40623 |
%\end{lverb} |
| 40624 |
% \begin{macrocode} |
| 40625 |
{\XINT_expr_prec_tacit *}% |
| 40626 |
% \end{macrocode} |
| 40627 |
%\begin{lverb} |
| 40628 |
% This is only location which jumps to \XINT_expr_getop_b. At 1.4f and |
| 40629 |
% perhaps for old legacy reasons this was \expandafter\XINT_expr_getop_b |
| 40630 |
% \string#1 but I see no reason now for applying \string to #1. Removed at |
| 40631 |
% 1.4g. And the #1 now moved out of the secondofthree and thirdofthree |
| 40632 |
% branches. |
| 40633 |
%\end{lverb} |
| 40634 |
% \begin{macrocode} |
| 40635 |
\XINT_expr_getop_b |
| 40636 |
#1% |
| 40637 |
}% |
| 40638 |
\catcode`* 12 |
| 40639 |
% \end{macrocode} |
| 40640 |
% \let\MakePrivateLetters\xintexprMakePrivateLetters |
| 40641 |
%\begin{lverb} |
| 40642 |
% \relax is a place holder here. At 1.4g, we don't use |
| 40643 |
% \XINT_expr_foundend anymore in \XINT_expr_getop_a which was slightly |
| 40644 |
% refactored, but it is used elsewhere. |
| 40645 |
% |
| 40646 |
% Attention that keeping a \relax around if \XINT_expr_getop hits it is |
| 40647 |
% crucial to good functioning of dummy variables after 1.4g refactoring of |
| 40648 |
% \XINT_expr_op__, the \relax being used as delimiter by dummy variables, and |
| 40649 |
% \XINT_expr_getop is now expanded before the variable itself does its thing. |
| 40650 |
%\end{lverb} |
| 40651 |
% \begin{macrocode} |
| 40652 |
\def\XINT_expr_foundend {\xint_c_ \relax}% |
| 40653 |
% \end{macrocode} |
| 40654 |
%\begin{lverb} |
| 40655 |
% ? is a very special operator with top precedence which will check if |
| 40656 |
% the next token is another ?, while avoiding removing a brace pair from token |
| 40657 |
% stream due to its syntax. Pre 1.1 releases used : rather than ??, but we |
| 40658 |
% need : for Python like slices of lists. |
| 40659 |
%\end{lverb} |
| 40660 |
% |
| 40661 |
%\begin{lverb} |
| 40662 |
% null char is used as hack to implement A/B[N] raw input at 1.4. See |
| 40663 |
% also \XINT_expr_scanint_c. |
| 40664 |
%\end{lverb} |
| 40665 |
% |
| 40666 |
%\begin{lverb} |
| 40667 |
% Memo: 1.4g, the token fetched by \XINT_expr_getop_b has not anymore |
| 40668 |
% been previously submitted in \XINT_expr_getop_a to \string. |
| 40669 |
%\end{lverb} |
| 40670 |
% \begin{macrocode} |
| 40671 |
\def\XINT_expr_getop_b#1{\def\XINT_expr_getop_b ##1% |
| 40672 |
{% |
| 40673 |
\if &&@##1\xint_dothis{#1&&@}\fi |
| 40674 |
\if '##1\xint_dothis{\XINT_expr_binopwrd }\fi |
| 40675 |
\if ?##1\xint_dothis{\XINT_expr_precedence_? ?}\fi |
| 40676 |
\xint_orthat {\XINT_expr_scanop_a ##1}% |
| 40677 |
}}\expandafter\XINT_expr_getop_b\csname XINT_expr_precedence_&&@\endcsname |
| 40678 |
\def\XINT_expr_binopwrd #1'% |
| 40679 |
{% |
| 40680 |
\expandafter\XINT_expr_foundop_a |
| 40681 |
\csname XINT_expr_itself_\xint_zapspaces #1 \xint_gobble_i\endcsname |
| 40682 |
}% |
| 40683 |
\def\XINT_expr_scanop_a #1#2% |
| 40684 |
{% |
| 40685 |
\expandafter\XINT_expr_scanop_b\expandafter#1\romannumeral`&&@#2% |
| 40686 |
}% |
| 40687 |
% \end{macrocode} |
| 40688 |
%\begin{lverb} |
| 40689 |
% Multi-character operators have an associated itself macro at each |
| 40690 |
% stage of decomposition starting at two characters. Here, nothing imposes to |
| 40691 |
% the operator characters not to be of catcode letter, this constraint applies |
| 40692 |
% only on the first character and is done via \XINT_expr_getop_a, to handle in |
| 40693 |
% particular tacit multiplication in front of variable or function names. |
| 40694 |
% |
| 40695 |
% But it would be dangerous to allow letters in operator characters, again due |
| 40696 |
% to existence of variables and functions, and anyhow there is no user |
| 40697 |
% interface to add such custom operators. However in bnumexpr, such a |
| 40698 |
% constraint does not exist. |
| 40699 |
% |
| 40700 |
% I don't worry too much about efficiency here... and at 1.4g I have |
| 40701 |
% re-written for code readability only. Once we see that #1#2 is not a |
| 40702 |
% candidate to be or start an operator, we need to check if single-character |
| 40703 |
% operator #1 is really an operator and this is done via the existence of the |
| 40704 |
% precedence token. |
| 40705 |
% |
| 40706 |
% Unfortunately the 1.4g refactoring of the scanop macros had a bad bug: |
| 40707 |
% \XINT_expr_scanop_c inserted \romannumeral`^^@ in stream but did not grab a |
| 40708 |
% token first so a space would stop the \romannumeral and then the #2 in |
| 40709 |
% \XINT_expr_scanop_d was not pre-expanded and ended up alone in \ifcat. It |
| 40710 |
% is too distant in the past the time when I wrote the core of xintexpr in |
| 40711 |
% 2013... older and dumber now. |
| 40712 |
%\end{lverb} |
| 40713 |
% \begin{macrocode} |
| 40714 |
\def\XINT_expr_scanop_b #1#2% |
| 40715 |
{% |
| 40716 |
\unless\ifcat#2\relax |
| 40717 |
\ifcsname XINT_expr_itself_#1#2\endcsname |
| 40718 |
\XINT_expr_scanop_c |
| 40719 |
\fi\fi |
| 40720 |
\XINT_expr_foundop_a #1#2% |
| 40721 |
}% |
| 40722 |
\def\XINT_expr_scanop_c #1#2#3#4#5#6% #1#2=\fi\fi |
| 40723 |
{% |
| 40724 |
#1#2% |
| 40725 |
\expandafter\XINT_expr_scanop_d\csname XINT_expr_itself_#4#5\expandafter\endcsname |
| 40726 |
\romannumeral`&&@#6% |
| 40727 |
}% |
| 40728 |
\def\XINT_expr_scanop_d #1#2% |
| 40729 |
{% |
| 40730 |
\unless\ifcat#2\relax |
| 40731 |
\ifcsname XINT_expr_itself_#1#2\endcsname |
| 40732 |
\XINT_expr_scanop_c |
| 40733 |
\fi\fi |
| 40734 |
\XINT_expr_foundop #1#2% |
| 40735 |
}% |
| 40736 |
\def\XINT_expr_foundop_a #1% |
| 40737 |
{% |
| 40738 |
\ifcsname XINT_expr_precedence_#1\endcsname |
| 40739 |
\csname XINT_expr_precedence_#1\expandafter\endcsname |
| 40740 |
\expandafter #1% |
| 40741 |
\else |
| 40742 |
\expandafter\XINT_expr_getop\romannumeral`&&@% |
| 40743 |
\xint_afterfi{\XINT_expandableerror |
| 40744 |
{Expected an operator but got `#1'. Ignoring.}}% |
| 40745 |
\fi |
| 40746 |
}% |
| 40747 |
\def\XINT_expr_foundop #1{\csname XINT_expr_precedence_#1\endcsname #1}% |
| 40748 |
% \end{macrocode} |
| 40749 |
% \subsection{Expansion spanning; opening and closing parentheses} |
| 40750 |
% \label{ssec:expansionspanning} |
| 40751 |
% This is also where |\XINT_expr_start|, |\XINT_iiexpr_start| and |
| 40752 |
% |\XINT_flexpr_start| are defined. |
| 40753 |
% |
| 40754 |
% \xintFor #1 in {expr,flexpr,iiexpr} \do{\label{\xintimplabelprefix XINT_#1_start}} |
| 40755 |
%\begin{lverb} |
| 40756 |
% |
| 40757 |
% These comments apply to all definitions coming next relative |
| 40758 |
% to execution of operations from parsing of syntax. |
| 40759 |
% |
| 40760 |
% Refactored (and unified) at 1.4. In particular |
| 40761 |
% the 1.4 scheme uses op, exec, check-, and checkp. Formerly |
| 40762 |
% it was until_a (check-) and until_b (now split into checkp and exec). |
| 40763 |
% |
| 40764 |
% This way neither check- nor checkp have to |
| 40765 |
% grab the accumulated number so far (top of stack if you like) and besides |
| 40766 |
% one never has to go back to check- from checkp (and neither from check-). |
| 40767 |
% |
| 40768 |
% |
| 40769 |
% |
| 40770 |
% Prior to 1.4, accumulated |
| 40771 |
% intermediate results were stored as one token, but now we have to use |
| 40772 |
% \expanded to propagate expansion beyond possibly arbitrary long braced |
| 40773 |
% nested data. With the 1.4 refactoring we do this only once and only grab |
| 40774 |
% a second time the data if we actually have to act upon it. |
| 40775 |
% |
| 40776 |
% Version 1.1 had a hack inside the until macros for handling the omit |
| 40777 |
% and abort in iterations over dummy variables. This has been removed by |
| 40778 |
% 1.2c, see the subsection where omit and abort are discussed. |
| 40779 |
% |
| 40780 |
% Exceptionally, the check- is here abbreviated to check. |
| 40781 |
% |
| 40782 |
%\end{lverb} |
| 40783 |
% \odef\MakePrivateLetters{\MakePrivateLetters\catcode`) 11 }^^A |
| 40784 |
% \begin{macrocode} |
| 40785 |
\catcode`) 11 |
| 40786 |
\def\XINT_tmpa #1#2#3#4#5#6% |
| 40787 |
{% |
| 40788 |
\def#1% \XINT_expr_start, \XINT_iiexpr_start, \XINT_flexpr_start |
| 40789 |
{% |
| 40790 |
\expandafter#2\romannumeral`&&@\XINT_expr_getnext |
| 40791 |
}% |
| 40792 |
\def#2##1% check |
| 40793 |
{% |
| 40794 |
\xint_UDsignfork |
| 40795 |
##1{\expandafter#3\romannumeral`&&@#4}% |
| 40796 |
-{#3##1}% |
| 40797 |
\krof |
| 40798 |
}% |
| 40799 |
\def#3##1##2% checkp |
| 40800 |
{% |
| 40801 |
\ifcase ##1% |
| 40802 |
\expandafter\XINT_expr_done |
| 40803 |
\or\expandafter#5% |
| 40804 |
\else |
| 40805 |
\expandafter#3\romannumeral`&&@\csname XINT_#6_op_##2\expandafter\endcsname |
| 40806 |
\fi |
| 40807 |
}% |
| 40808 |
\def#5% |
| 40809 |
{% |
| 40810 |
\XINT_expandableerror |
| 40811 |
{Extra ) removed. Hit <return>, fingers crossed.}% |
| 40812 |
\expandafter#2\romannumeral`&&@\expandafter\XINT_expr_put_op_first |
| 40813 |
\romannumeral`&&@\XINT_expr_getop_legacy |
| 40814 |
}% |
| 40815 |
}% |
| 40816 |
\let\XINT_expr_done\space |
| 40817 |
\xintFor #1 in {expr,flexpr,iiexpr} \do {% |
| 40818 |
\expandafter\XINT_tmpa |
| 40819 |
\csname XINT_#1_start\expandafter\endcsname |
| 40820 |
\csname XINT_#1_check\expandafter\endcsname |
| 40821 |
\csname XINT_#1_checkp\expandafter\endcsname |
| 40822 |
\csname XINT_#1_op_-xii\expandafter\endcsname |
| 40823 |
\csname XINT_#1_extra_)\endcsname |
| 40824 |
{#1}% |
| 40825 |
}% |
| 40826 |
% \end{macrocode} |
| 40827 |
%\begin{lverb} |
| 40828 |
% Here also we take some shortcuts relative to general philosophy and have no explicit |
| 40829 |
% exec macro. |
| 40830 |
%\end{lverb} |
| 40831 |
% \begin{macrocode} |
| 40832 |
\def\XINT_tmpa #1#2#3#4#5#6#7% |
| 40833 |
{% |
| 40834 |
\def #1##1% op_( |
| 40835 |
{% |
| 40836 |
\expandafter #4\romannumeral`&&@\XINT_expr_getnext |
| 40837 |
}% |
| 40838 |
\def #2##1% op_) |
| 40839 |
{% |
| 40840 |
\expanded{\xint_noxpd{\XINT_expr_put_op_first{##1}}\expandafter}% |
| 40841 |
\romannumeral`&&@\XINT_expr_getop |
| 40842 |
}% |
| 40843 |
\def #3% oparen |
| 40844 |
{% |
| 40845 |
\expandafter #4\romannumeral`&&@\XINT_expr_getnext |
| 40846 |
}% |
| 40847 |
\def #4##1% check- |
| 40848 |
{% |
| 40849 |
\xint_UDsignfork |
| 40850 |
##1{\expandafter#5\romannumeral`&&@#6}% |
| 40851 |
-{#5##1}% |
| 40852 |
\krof |
| 40853 |
}% |
| 40854 |
\def #5##1##2% checkp |
| 40855 |
{% |
| 40856 |
\ifcase ##1\expandafter\XINT_expr_missing_) |
| 40857 |
\or \csname XINT_#7_op_##2\expandafter\endcsname |
| 40858 |
\else |
| 40859 |
\expandafter #5\romannumeral`&&@\csname XINT_#7_op_##2\expandafter\endcsname |
| 40860 |
\fi |
| 40861 |
}% |
| 40862 |
}% |
| 40863 |
\def\XINT_expr_missing_) |
| 40864 |
{\XINT_expandableerror{End of expression found, but some ) was missing there.}% |
| 40865 |
\xint_c_ \XINT_expr_done }% |
| 40866 |
\xintFor #1 in {expr,flexpr,iiexpr} \do {% |
| 40867 |
\expandafter\XINT_tmpa |
| 40868 |
\csname XINT_#1_op_(\expandafter\endcsname |
| 40869 |
\csname XINT_#1_op_)\expandafter\endcsname |
| 40870 |
\csname XINT_#1_oparen\expandafter\endcsname |
| 40871 |
\csname XINT_#1_check-_)\expandafter\endcsname |
| 40872 |
\csname XINT_#1_checkp_)\expandafter\endcsname |
| 40873 |
\csname XINT_#1_op_-xii\endcsname |
| 40874 |
{#1}% |
| 40875 |
}% |
| 40876 |
\let\XINT_expr_precedence_)\xint_c_i |
| 40877 |
\catcode`) 12 |
| 40878 |
% \end{macrocode} |
| 40879 |
% \let\MakePrivateLetters\xintexprMakePrivateLetters |
| 40880 |
% \subsection{The comma as binary operator} |
| 40881 |
%\begin{lverb} |
| 40882 |
% New with 1.09a. Refactored at 1.4. |
| 40883 |
%\end{lverb} |
| 40884 |
% \begin{macrocode} |
| 40885 |
\def\XINT_tmpa #1#2#3#4#5#6% |
| 40886 |
{% |
| 40887 |
\def #1##1% \XINT_expr_op_, |
| 40888 |
{% |
| 40889 |
\expanded{\xint_noxpd{#2{##1}}\expandafter}% |
| 40890 |
\romannumeral`&&@\expandafter#3\romannumeral`&&@\XINT_expr_getnext |
| 40891 |
}% |
| 40892 |
\def #2##1##2##3##4{##2##3{##1##4}}% \XINT_expr_exec_, |
| 40893 |
\def #3##1% \XINT_expr_check-_, |
| 40894 |
{% |
| 40895 |
\xint_UDsignfork |
| 40896 |
##1{\expandafter#4\romannumeral`&&@#5}% |
| 40897 |
-{#4##1}% |
| 40898 |
\krof |
| 40899 |
}% |
| 40900 |
\def #4##1##2% \XINT_expr_checkp_, |
| 40901 |
{% |
| 40902 |
\ifnum ##1>\xint_c_iii |
| 40903 |
\expandafter#4% |
| 40904 |
\romannumeral`&&@\csname XINT_#6_op_##2\expandafter\endcsname |
| 40905 |
\else |
| 40906 |
\expandafter##1\expandafter##2% |
| 40907 |
\fi |
| 40908 |
}% |
| 40909 |
}% |
| 40910 |
\xintFor #1 in {expr,flexpr,iiexpr} \do {% |
| 40911 |
\expandafter\XINT_tmpa |
| 40912 |
\csname XINT_#1_op_,\expandafter\endcsname |
| 40913 |
\csname XINT_#1_exec_,\expandafter\endcsname |
| 40914 |
\csname XINT_#1_check-_,\expandafter\endcsname |
| 40915 |
\csname XINT_#1_checkp_,\expandafter\endcsname |
| 40916 |
\csname XINT_#1_op_-xii\endcsname {#1}% |
| 40917 |
}% |
| 40918 |
\expandafter\let\csname XINT_expr_precedence_,\endcsname\xint_c_iii |
| 40919 |
% \end{macrocode} |
| 40920 |
% \subsection{The minus as prefix operator of variable precedence level} |
| 40921 |
%\begin{lverb} |
| 40922 |
% Inherits the precedence level of the previous infix operator, if the |
| 40923 |
% latter has at least the precedence level of binary + and -, i.e. currently |
| 40924 |
% 12. |
| 40925 |
% |
| 40926 |
% Refactored at 1.4. |
| 40927 |
% |
| 40928 |
% At 1.4g I belatedly observe that I have been defining architecture for |
| 40929 |
% op_-xvi but such operator can never be created, because there are no infix |
| 40930 |
% operators of precedence level 16. Perhaps in the past this was really |
| 40931 |
% needed? But now such 16 is precedence level of tacit multiplication which |
| 40932 |
% is implemented simply by the \XINT_expr_prec_tacit token, there is no macro |
| 40933 |
% check-_*** which would need an op_-xvi. |
| 40934 |
% |
| 40935 |
% For the record: at least one scenario exists |
| 40936 |
% which creates tacit multiplication in front of a unary -, it is 2\count0 |
| 40937 |
% which first generates tacit multiplication then applies \number to \count0, |
| 40938 |
% but the operator |
| 40939 |
% is still *, so this triggers only \XINT_expr_op_-xiv, not -xvi. |
| 40940 |
% |
| 40941 |
% At 1.4g we need 17 and not 18 anymore as the precedence of unary minus |
| 40942 |
% following power operators ^ and **. The needed \xint_c_xvii creation was |
| 40943 |
% added to xintkernel.sty. |
| 40944 |
%\end{lverb} |
| 40945 |
% \begin{macrocode} |
| 40946 |
\def\XINT_tmpb #1#2#3#4#5#6#7% |
| 40947 |
{% |
| 40948 |
\def #1% \XINT_expr_op_-<level> |
| 40949 |
{% |
| 40950 |
\expandafter #2\romannumeral`&&@\expandafter#3% |
| 40951 |
\romannumeral`&&@\XINT_expr_getnext |
| 40952 |
}% |
| 40953 |
\def #2##1##2##3% \XINT_expr_exec_-<level> |
| 40954 |
{% |
| 40955 |
\expandafter ##1\expandafter ##2\expandafter |
| 40956 |
{% |
| 40957 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 40958 |
{\romannumeral`&&@#7##3}% |
| 40959 |
}% |
| 40960 |
}% |
| 40961 |
\def #3##1% \XINT_expr_check-_-<level> |
| 40962 |
{% |
| 40963 |
\xint_UDsignfork |
| 40964 |
##1{\expandafter #4\romannumeral`&&@#1}% |
| 40965 |
-{#4##1}% |
| 40966 |
\krof |
| 40967 |
}% |
| 40968 |
\def #4##1##2% \XINT_expr_checkp_-<level> |
| 40969 |
{% |
| 40970 |
\ifnum ##1>#5% |
| 40971 |
\expandafter #4% |
| 40972 |
\romannumeral`&&@\csname XINT_#6_op_##2\expandafter\endcsname |
| 40973 |
\else |
| 40974 |
\expandafter ##1\expandafter ##2% |
| 40975 |
\fi |
| 40976 |
}% |
| 40977 |
}% |
| 40978 |
\def\XINT_tmpa #1#2#3% |
| 40979 |
{% |
| 40980 |
\expandafter\XINT_tmpb |
| 40981 |
\csname XINT_#1_op_-#3\expandafter\endcsname |
| 40982 |
\csname XINT_#1_exec_-#3\expandafter\endcsname |
| 40983 |
\csname XINT_#1_check-_-#3\expandafter\endcsname |
| 40984 |
\csname XINT_#1_checkp_-#3\expandafter\endcsname |
| 40985 |
\csname xint_c_#3\endcsname {#1}#2% |
| 40986 |
}% |
| 40987 |
\xintApplyInline{\XINT_tmpa {expr}\xintOpp}{{xii}{xiv}{xvii}}% |
| 40988 |
\xintApplyInline{\XINT_tmpa {flexpr}\xintOpp}{{xii}{xiv}{xvii}}% |
| 40989 |
\xintApplyInline{\XINT_tmpa {iiexpr}\xintiiOpp}{{xii}{xiv}{xvii}}% |
| 40990 |
% \end{macrocode} |
| 40991 |
% \subsection{The \texorpdfstring{\protect\lowast}{*}{} as Python-like «unpacking» prefix operator} |
| 40992 |
% |
| 40993 |
%\begin{lverb} |
| 40994 |
% New with 1.4. Prior to 1.4 the internal data structure was |
| 40995 |
% the one of \csname encapsulated comma separated numbers. No hierarchical |
| 40996 |
% structure was (easily) possible. At 1.4, we can use TeX braces because there |
| 40997 |
% is no detokenization to catcode 12. |
| 40998 |
%\end{lverb} |
| 40999 |
% |
| 41000 |
% |
| 41001 |
% \begin{macrocode} |
| 41002 |
\def\XINT_tmpa#1#2#3% |
| 41003 |
{% |
| 41004 |
\def#1##1{\expandafter#2\romannumeral`&&@\XINT_expr_getnext}% |
| 41005 |
\def#2##1##2% |
| 41006 |
{% |
| 41007 |
\ifnum ##1>\xint_c_xx |
| 41008 |
\expandafter #2% |
| 41009 |
\romannumeral`&&@\csname XINT_#3_op_##2\expandafter\endcsname |
| 41010 |
\else |
| 41011 |
\expandafter##1\expandafter##2\romannumeral0\expandafter\XINT:NEhook:unpack |
| 41012 |
\fi |
| 41013 |
}% |
| 41014 |
}% |
| 41015 |
\def\XINT:NEhook:unpack{\xint_stop_atfirstofone}% |
| 41016 |
\xintFor* #1 in {{expr}{flexpr}{iiexpr}}: |
| 41017 |
{\expandafter\XINT_tmpa\csname XINT_#1_op_0\expandafter\endcsname |
| 41018 |
\csname XINT_#1_until_unpack\endcsname {#1}}% |
| 41019 |
% \end{macrocode} |
| 41020 |
% \subsection{Infix operators} |
| 41021 |
% |
| 41022 |
% \localtableofcontents |
| 41023 |
% |
| 41024 |
%\begin{lverb} |
| 41025 |
% 1.2d adds the *** for tying via tacit multiplication, for example |
| 41026 |
% x/2y. Actually I don't need the _itself mechanism for ***, only a |
| 41027 |
% precedence. |
| 41028 |
% |
| 41029 |
% At 1.4b we must make sure that the ! in expansion of \XINT_expr_itself_!= is |
| 41030 |
% of catcode 12 and not of catcode 11. This is because implementation of |
| 41031 |
% chaining of comparison operators proceeds via inserting the itself macro |
| 41032 |
% directly into upcoming token stream, whereas formerly such itself macros |
| 41033 |
% would be expanded only in a \csname...\endcsname context. |
| 41034 |
%\end{lverb} |
| 41035 |
% \begin{macrocode} |
| 41036 |
\catcode`& 12 \catcode`! 12 |
| 41037 |
\xintFor* #1 in {{==}{!=}{<=}{>=}{&&}{||}{//}{/:}{..}{..[}{].}{]..}}% |
| 41038 |
\do {\expandafter\def\csname XINT_expr_itself_#1\endcsname {#1}}% |
| 41039 |
\catcode`& 7 \catcode`! 11 |
| 41040 |
% \end{macrocode} |
| 41041 |
% \subsubsection{\&\&, \textbar\textbar, //, /:, +, |
| 41042 |
% \textendash, \texorpdfstring{\protect\lowast}{*}, /, \textasciicircum, |
| 41043 |
% \texorpdfstring{\protect\lowast\protect\lowast}{**}{}, \textquotesingle and\textquotesingle, \textquotesingle |
| 41044 |
% or\textquotesingle, \textquotesingle xor\textquotesingle, and |
| 41045 |
% \textquotesingle mod\textquotesingle} |
| 41046 |
% |
| 41047 |
%\begin{lverb} |
| 41048 |
% At 1.4g I finally decide to enact the switch to right |
| 41049 |
% associativity for the power operators ^ and **. |
| 41050 |
% |
| 41051 |
% This goes via inserting into the checkp macros not anymore the precedence |
| 41052 |
% chardef token (which now only serves as left precedence, inserted in the |
| 41053 |
% token stream) but in its place an \xint_c_<roman> token holding the right |
| 41054 |
% precedence. Which is also transmitted to spanned unary minus operators. |
| 41055 |
% |
| 41056 |
% Here only levels 12, 14, and 17 are created as right precedences. |
| 41057 |
% |
| 41058 |
% #6 and #7 got permuted and the new #7 is directly a control sequence. |
| 41059 |
% Also #3 and #4 are now integers which need \romannumeral. The change in |
| 41060 |
% \XINT_expr_defbin_c does not propagate as it is re-defined shortly thereafter. |
| 41061 |
%\end{lverb} |
| 41062 |
% \begin{macrocode} |
| 41063 |
\def\XINT_expr_defbin_c #1#2#3#4#5#6#7#8% |
| 41064 |
{% |
| 41065 |
\def #1##1% \XINT_expr_op_<op> |
| 41066 |
{% |
| 41067 |
\expanded{\xint_noxpd{#2{##1}}\expandafter}% |
| 41068 |
\romannumeral`&&@\expandafter#3\romannumeral`&&@\XINT_expr_getnext |
| 41069 |
}% |
| 41070 |
\def #2##1##2##3##4% \XINT_expr_exec_<op> |
| 41071 |
{% |
| 41072 |
\expandafter##2\expandafter##3\expandafter |
| 41073 |
{\romannumeral`&&@\XINT:NEhook:f:one:from:two{\romannumeral`&&@#7##1##4}}% |
| 41074 |
}% |
| 41075 |
\def #3##1% \XINT_expr_check-_<op> |
| 41076 |
{% |
| 41077 |
\xint_UDsignfork |
| 41078 |
##1{\expandafter#4\romannumeral`&&@#5}% |
| 41079 |
-{#4##1}% |
| 41080 |
\krof |
| 41081 |
}% |
| 41082 |
\def #4##1##2% \XINT_expr_checkp_<op> |
| 41083 |
{% |
| 41084 |
\ifnum ##1>#6% |
| 41085 |
\expandafter#4% |
| 41086 |
\romannumeral`&&@\csname XINT_#8_op_##2\expandafter\endcsname |
| 41087 |
\else |
| 41088 |
\expandafter ##1\expandafter ##2% |
| 41089 |
\fi |
| 41090 |
}% |
| 41091 |
}% |
| 41092 |
\def\XINT_expr_defbin_b #1#2#3#4#5% |
| 41093 |
{% |
| 41094 |
\expandafter\XINT_expr_defbin_c |
| 41095 |
\csname XINT_#1_op_#2\expandafter\endcsname |
| 41096 |
\csname XINT_#1_exec_#2\expandafter\endcsname |
| 41097 |
\csname XINT_#1_check-_#2\expandafter\endcsname |
| 41098 |
\csname XINT_#1_checkp_#2\expandafter\endcsname |
| 41099 |
\csname XINT_#1_op_-\romannumeral\ifnum#4>12 #4\else12\fi\expandafter\endcsname |
| 41100 |
\csname xint_c_\romannumeral#4\endcsname |
| 41101 |
#5% |
| 41102 |
{#1}% |
| 41103 |
\expandafter % done 3 times but well |
| 41104 |
\let\csname XINT_expr_precedence_#2\expandafter\endcsname |
| 41105 |
\csname xint_c_\romannumeral#3\endcsname |
| 41106 |
}% |
| 41107 |
\XINT_expr_defbin_b {expr} {||} {6} {6} \xintOR |
| 41108 |
\XINT_expr_defbin_b {flexpr}{||} {6} {6} \xintOR |
| 41109 |
\XINT_expr_defbin_b {iiexpr}{||} {6} {6} \xintOR |
| 41110 |
\catcode`& 12 |
| 41111 |
\XINT_expr_defbin_b {expr} {&&} {8} {8} \xintAND |
| 41112 |
\XINT_expr_defbin_b {flexpr}{&&} {8} {8} \xintAND |
| 41113 |
\XINT_expr_defbin_b {iiexpr}{&&} {8} {8} \xintAND |
| 41114 |
\catcode`& 7 |
| 41115 |
\XINT_expr_defbin_b {expr} {xor}{6} {6} \xintXOR |
| 41116 |
\XINT_expr_defbin_b {flexpr}{xor}{6} {6} \xintXOR |
| 41117 |
\XINT_expr_defbin_b {iiexpr}{xor}{6} {6} \xintXOR |
| 41118 |
\XINT_expr_defbin_b {expr} {//} {14}{14}\xintDivFloor |
| 41119 |
\XINT_expr_defbin_b {flexpr}{//} {14}{14}\XINTinFloatDivFloor |
| 41120 |
\XINT_expr_defbin_b {iiexpr}{//} {14}{14}\xintiiDivFloor |
| 41121 |
\XINT_expr_defbin_b {expr} {/:} {14}{14}\xintMod |
| 41122 |
\XINT_expr_defbin_b {flexpr}{/:} {14}{14}\XINTinFloatMod |
| 41123 |
\XINT_expr_defbin_b {iiexpr}{/:} {14}{14}\xintiiMod |
| 41124 |
\XINT_expr_defbin_b {expr} + {12}{12}\xintAdd |
| 41125 |
\XINT_expr_defbin_b {flexpr} + {12}{12}\XINTinFloatAdd |
| 41126 |
\XINT_expr_defbin_b {iiexpr} + {12}{12}\xintiiAdd |
| 41127 |
\XINT_expr_defbin_b {expr} - {12}{12}\xintSub |
| 41128 |
\XINT_expr_defbin_b {flexpr} - {12}{12}\XINTinFloatSub |
| 41129 |
\XINT_expr_defbin_b {iiexpr} - {12}{12}\xintiiSub |
| 41130 |
\XINT_expr_defbin_b {expr} * {14}{14}\xintMul |
| 41131 |
\XINT_expr_defbin_b {flexpr} * {14}{14}\XINTinFloatMul |
| 41132 |
\XINT_expr_defbin_b {iiexpr} * {14}{14}\xintiiMul |
| 41133 |
\let\XINT_expr_prec_tacit \xint_c_xvi |
| 41134 |
\XINT_expr_defbin_b {expr} / {14}{14}\xintDiv |
| 41135 |
\XINT_expr_defbin_b {flexpr} / {14}{14}\XINTinFloatDiv |
| 41136 |
\XINT_expr_defbin_b {iiexpr} / {14}{14}\xintiiDivRound |
| 41137 |
% \end{macrocode} |
| 41138 |
%\begin{lverb} |
| 41139 |
% At 1.4g, right associativity is implemented via |
| 41140 |
% a lowered right precedence here. |
| 41141 |
%\end{lverb} |
| 41142 |
% \begin{macrocode} |
| 41143 |
\XINT_expr_defbin_b {expr} ^ {18}{17}\xintPow |
| 41144 |
\XINT_expr_defbin_b {flexpr} ^ {18}{17}\XINTinFloatSciPow |
| 41145 |
\XINT_expr_defbin_b {iiexpr} ^ {18}{17}\xintiiPow |
| 41146 |
% \end{macrocode} |
| 41147 |
%\begin{lverb} |
| 41148 |
% 1.4g This is a trick (which was in old version of bnumexpr, I |
| 41149 |
% wonder why I did not have it here) but it will make error messages in case |
| 41150 |
% of **<token> confusing. The ^ here is of catcode 11 but it does not matter. |
| 41151 |
%\end{lverb} |
| 41152 |
% \begin{macrocode} |
| 41153 |
\expandafter\def\csname XINT_expr_itself_**\endcsname{^}% |
| 41154 |
\catcode`& 12 |
| 41155 |
% \end{macrocode} |
| 41156 |
%\begin{lverb} |
| 41157 |
% For this which contributes to implementing 'and', 'or', etc... see |
| 41158 |
% \XINT_expr_binopwrd. |
| 41159 |
%\end{lverb} |
| 41160 |
% \begin{macrocode} |
| 41161 |
\xintFor #1 in {and,or,xor,mod} \do |
| 41162 |
{% |
| 41163 |
\expandafter\def\csname XINT_expr_itself_#1\endcsname {#1}% |
| 41164 |
}% |
| 41165 |
\expandafter\let\csname XINT_expr_precedence_and\expandafter\endcsname |
| 41166 |
\csname XINT_expr_precedence_&&\endcsname |
| 41167 |
\expandafter\let\csname XINT_expr_precedence_or\expandafter\endcsname |
| 41168 |
\csname XINT_expr_precedence_||\endcsname |
| 41169 |
\expandafter\let\csname XINT_expr_precedence_mod\expandafter\endcsname |
| 41170 |
\csname XINT_expr_precedence_/:\endcsname |
| 41171 |
\xintFor #1 in {expr, flexpr, iiexpr} \do |
| 41172 |
{% |
| 41173 |
\expandafter\let\csname XINT_#1_op_and\expandafter\endcsname |
| 41174 |
\csname XINT_#1_op_&&\endcsname |
| 41175 |
\expandafter\let\csname XINT_#1_op_or\expandafter\endcsname |
| 41176 |
\csname XINT_#1_op_||\endcsname |
| 41177 |
\expandafter\let\csname XINT_#1_op_mod\expandafter\endcsname |
| 41178 |
\csname XINT_#1_op_/:\endcsname |
| 41179 |
}% |
| 41180 |
\catcode`& 7 |
| 41181 |
% \end{macrocode} |
| 41182 |
% \subsubsection{.., ..[, and ].. for a..b and a..[b]..c syntax} |
| 41183 |
%\begin{lverb} |
| 41184 |
% The 1.4 exec_..[ macros (which do no further expansion!) had silly |
| 41185 |
% \expandafter doing nothing for the sole reason of sharing a common |
| 41186 |
% \XINT_expr_defbin_c as used previously for the +, - etc... operators. At |
| 41187 |
% 1.4b we take the time to set things straight and do other similar |
| 41188 |
% simplifications. |
| 41189 |
%\end{lverb} |
| 41190 |
% \begin{macrocode} |
| 41191 |
\def\XINT_expr_defbin_c #1#2#3#4#5#6#7% |
| 41192 |
{% |
| 41193 |
\def #1##1% \XINT_expr_op_..[ |
| 41194 |
{% |
| 41195 |
\expanded{\xint_noxpd{#2{##1}}\expandafter}% |
| 41196 |
\romannumeral`&&@\expandafter#3\romannumeral`&&@\XINT_expr_getnext |
| 41197 |
}% |
| 41198 |
\def #2##1##2##3##4% \XINT_expr_exec_..[ |
| 41199 |
{% |
| 41200 |
##2##3{{##1##4}}% |
| 41201 |
}% |
| 41202 |
\def #3##1% \XINT_expr_check-_..[ |
| 41203 |
{% |
| 41204 |
\xint_UDsignfork |
| 41205 |
##1{\expandafter#4\romannumeral`&&@#5}% |
| 41206 |
-{#4##1}% |
| 41207 |
\krof |
| 41208 |
}% |
| 41209 |
\def #4##1##2% \XINT_expr_checkp_..[ |
| 41210 |
{% |
| 41211 |
\ifnum ##1>#6% |
| 41212 |
\expandafter#4% |
| 41213 |
\romannumeral`&&@\csname XINT_#7_op_##2\expandafter\endcsname |
| 41214 |
\else |
| 41215 |
\expandafter ##1\expandafter ##2% |
| 41216 |
\fi |
| 41217 |
}% |
| 41218 |
}% |
| 41219 |
\def\XINT_expr_defbin_b #1% |
| 41220 |
{% |
| 41221 |
\expandafter\XINT_expr_defbin_c |
| 41222 |
\csname XINT_#1_op_..[\expandafter\endcsname |
| 41223 |
\csname XINT_#1_exec_..[\expandafter\endcsname |
| 41224 |
\csname XINT_#1_check-_..[\expandafter\endcsname |
| 41225 |
\csname XINT_#1_checkp_..[\expandafter\endcsname |
| 41226 |
\csname XINT_#1_op_-xii\expandafter\endcsname |
| 41227 |
\csname XINT_expr_precedence_..[\endcsname |
| 41228 |
{#1}% |
| 41229 |
}% |
| 41230 |
\XINT_expr_defbin_b {expr}% |
| 41231 |
\XINT_expr_defbin_b {flexpr}% |
| 41232 |
\XINT_expr_defbin_b {iiexpr}% |
| 41233 |
\expandafter\let\csname XINT_expr_precedence_..[\endcsname\xint_c_vi |
| 41234 |
\def\XINT_expr_defbin_c #1#2#3#4#5#6#7#8% |
| 41235 |
{% |
| 41236 |
\def #1##1% \XINT_expr_op_<op> |
| 41237 |
{% |
| 41238 |
\expanded{\xint_noxpd{#2{##1}}\expandafter}% |
| 41239 |
\romannumeral`&&@\expandafter#3\romannumeral`&&@\XINT_expr_getnext |
| 41240 |
}% |
| 41241 |
\def #2##1##2##3##4% \XINT_expr_exec_<op> |
| 41242 |
{% |
| 41243 |
\expandafter##2\expandafter##3\expanded |
| 41244 |
{{\XINT:NEhook:x:one:from:two#8##1##4}}% |
| 41245 |
}% |
| 41246 |
\def #3##1% \XINT_expr_check-_<op> |
| 41247 |
{% |
| 41248 |
\xint_UDsignfork |
| 41249 |
##1{\expandafter#4\romannumeral`&&@#5}% |
| 41250 |
-{#4##1}% |
| 41251 |
\krof |
| 41252 |
}% |
| 41253 |
\def #4##1##2% \XINT_expr_checkp_<op> |
| 41254 |
{% |
| 41255 |
\ifnum ##1>#6% |
| 41256 |
\expandafter#4% |
| 41257 |
\romannumeral`&&@\csname XINT_#7_op_##2\expandafter\endcsname |
| 41258 |
\else |
| 41259 |
\expandafter ##1\expandafter ##2% |
| 41260 |
\fi |
| 41261 |
}% |
| 41262 |
}% |
| 41263 |
\def\XINT_expr_defbin_b #1#2#3% |
| 41264 |
{% |
| 41265 |
\expandafter\XINT_expr_defbin_c |
| 41266 |
\csname XINT_#1_op_#2\expandafter\endcsname |
| 41267 |
\csname XINT_#1_exec_#2\expandafter\endcsname |
| 41268 |
\csname XINT_#1_check-_#2\expandafter\endcsname |
| 41269 |
\csname XINT_#1_checkp_#2\expandafter\endcsname |
| 41270 |
\csname XINT_#1_op_-xii\expandafter\endcsname |
| 41271 |
\csname XINT_expr_precedence_#2\endcsname |
| 41272 |
{#1}#3% |
| 41273 |
\expandafter\let |
| 41274 |
\csname XINT_expr_precedence_#2\expandafter\endcsname\xint_c_vi |
| 41275 |
}% |
| 41276 |
\XINT_expr_defbin_b {expr} {..}\xintSeq:tl:x |
| 41277 |
\XINT_expr_defbin_b {flexpr} {..}\xintSeq:tl:x |
| 41278 |
\XINT_expr_defbin_b {iiexpr} {..}\xintiiSeq:tl:x |
| 41279 |
\XINT_expr_defbin_b {expr} {]..}\xintSeqB:tl:x |
| 41280 |
\XINT_expr_defbin_b {flexpr}{]..}\xintSeqB:tl:x |
| 41281 |
\XINT_expr_defbin_b {iiexpr}{]..}\xintiiSeqB:tl:x |
| 41282 |
% \end{macrocode} |
| 41283 |
% \subsubsection{<, >, ==, <=, >=, != with Python-like chaining} |
| 41284 |
%\begin{lverb} |
| 41285 |
% 1.4b |
| 41286 |
% This is preliminary implementation of chaining of comparison |
| 41287 |
% operators like Python and (I think) l3fp do. I am not too happy |
| 41288 |
% with how many times the (second) operand (already evaluated) is fetched. |
| 41289 |
% |
| 41290 |
%\end{lverb} |
| 41291 |
% \begin{macrocode} |
| 41292 |
\def\XINT_expr_defbin_d #1#2% |
| 41293 |
{% |
| 41294 |
\def #1##1##2##3##4% \XINT_expr_exec_<op> |
| 41295 |
{% |
| 41296 |
\expandafter##2\expandafter##3\expandafter |
| 41297 |
{\romannumeral`&&@\XINT:NEhook:f:one:from:two{\romannumeral`&&@#2##1##4}}% |
| 41298 |
}% |
| 41299 |
}% |
| 41300 |
\def\XINT_expr_defbin_c #1#2#3#4#5#6#7#8#9% |
| 41301 |
{% |
| 41302 |
\def #1##1% \XINT_expr_op_<op> |
| 41303 |
{% |
| 41304 |
\expanded{\xint_noxpd{#2{##1}}\expandafter}% |
| 41305 |
\romannumeral`&&@\expandafter#7% |
| 41306 |
\romannumeral`&&@\expandafter#3\romannumeral`&&@\XINT_expr_getnext |
| 41307 |
}% |
| 41308 |
\def #3##1% \XINT_expr_check-_<op> |
| 41309 |
{% |
| 41310 |
\xint_UDsignfork |
| 41311 |
##1{\expandafter#4\romannumeral`&&@#5}% |
| 41312 |
-{#4##1}% |
| 41313 |
\krof |
| 41314 |
}% |
| 41315 |
\def #4##1##2% \XINT_expr_checkp_<op> |
| 41316 |
{% |
| 41317 |
\ifnum ##1>#6% |
| 41318 |
\expandafter#4% |
| 41319 |
\romannumeral`&&@\csname XINT_#9_op_##2\expandafter\endcsname |
| 41320 |
\else |
| 41321 |
\expandafter ##1\expandafter ##2% |
| 41322 |
\fi |
| 41323 |
}% |
| 41324 |
\let #6\xint_c_x |
| 41325 |
\def #7##1% \XINT_expr_checkc_<op> |
| 41326 |
{% |
| 41327 |
\ifnum ##1=\xint_c_x\expandafter#8\fi ##1% |
| 41328 |
}% |
| 41329 |
\edef #8##1##2##3% \XINT_expr_execc_<op> |
| 41330 |
{% |
| 41331 |
\csname XINT_#9_precedence_\string&\string&\endcsname |
| 41332 |
\expandafter\noexpand\csname XINT_#9_itself_\string&\string&\endcsname |
| 41333 |
{##3}% |
| 41334 |
\XINTfstop.{##3}##2% |
| 41335 |
}% |
| 41336 |
\XINT_expr_defbin_d #2% \XINT_expr_exec_<op> |
| 41337 |
}% |
| 41338 |
\def\XINT_expr_defbin_b #1#2%#3% |
| 41339 |
{% |
| 41340 |
\expandafter\XINT_expr_defbin_c |
| 41341 |
\csname XINT_#1_op_#2\expandafter\endcsname |
| 41342 |
\csname XINT_#1_exec_#2\expandafter\endcsname |
| 41343 |
\csname XINT_#1_check-_#2\expandafter\endcsname |
| 41344 |
\csname XINT_#1_checkp_#2\expandafter\endcsname |
| 41345 |
\csname XINT_#1_op_-xii\expandafter\endcsname |
| 41346 |
\csname XINT_expr_precedence_#2\expandafter\endcsname |
| 41347 |
\csname XINT_#1_checkc_#2\expandafter\endcsname |
| 41348 |
\csname XINT_#1_execc_#2\endcsname |
| 41349 |
{#1}%#3% |
| 41350 |
}% |
| 41351 |
% \end{macrocode} |
| 41352 |
%\begin{lverb} |
| 41353 |
% Attention that third token here is left in stream by defbin_b, then |
| 41354 |
% also by defbin_c and is picked up as #2 of defbin_d. Had to work around TeX |
| 41355 |
% accepting only 9 arguments. Why did it not start counting at #0 like all |
| 41356 |
% decent mathematicians do? |
| 41357 |
%\end{lverb} |
| 41358 |
% \begin{macrocode} |
| 41359 |
\XINT_expr_defbin_b {expr} <\xintLt |
| 41360 |
\XINT_expr_defbin_b {flexpr}<\xintLt |
| 41361 |
\XINT_expr_defbin_b {iiexpr}<\xintiiLt |
| 41362 |
\XINT_expr_defbin_b {expr} >\xintGt |
| 41363 |
\XINT_expr_defbin_b {flexpr}>\xintGt |
| 41364 |
\XINT_expr_defbin_b {iiexpr}>\xintiiGt |
| 41365 |
\XINT_expr_defbin_b {expr} {==}\xintEq |
| 41366 |
\XINT_expr_defbin_b {flexpr}{==}\xintEq |
| 41367 |
\XINT_expr_defbin_b {iiexpr}{==}\xintiiEq |
| 41368 |
\XINT_expr_defbin_b {expr} {<=}\xintLtorEq |
| 41369 |
\XINT_expr_defbin_b {flexpr}{<=}\xintLtorEq |
| 41370 |
\XINT_expr_defbin_b {iiexpr}{<=}\xintiiLtorEq |
| 41371 |
\XINT_expr_defbin_b {expr} {>=}\xintGtorEq |
| 41372 |
\XINT_expr_defbin_b {flexpr}{>=}\xintGtorEq |
| 41373 |
\XINT_expr_defbin_b {iiexpr}{>=}\xintiiGtorEq |
| 41374 |
\XINT_expr_defbin_b {expr} {!=}\xintNotEq |
| 41375 |
\XINT_expr_defbin_b {flexpr}{!=}\xintNotEq |
| 41376 |
\XINT_expr_defbin_b {iiexpr}{!=}\xintiiNotEq |
| 41377 |
% \end{macrocode} |
| 41378 |
% \subsubsection{Support macros for .., ..[ and ]..} |
| 41379 |
% \localtableofcontents |
| 41380 |
% |
| 41381 |
% \paragraph{\csh{xintSeq:tl:x}} |
| 41382 |
%\begin{lverb} |
| 41383 |
% Commence par remplacer a par ceil(a) et b par floor(b) et renvoie |
| 41384 |
% ensuite les entiers entre les deux, possiblement en décroissant, et |
| 41385 |
% extrémités comprises. Si a=b est non entier en obtient donc ceil(a) et |
| 41386 |
% floor(a). Ne renvoie jamais une liste vide. |
| 41387 |
% |
| 41388 |
% Note: le a..b dans \xintfloatexpr utilise cette routine. |
| 41389 |
%\end{lverb} |
| 41390 |
% \begin{macrocode} |
| 41391 |
\def\xintSeq:tl:x #1#2% |
| 41392 |
{% |
| 41393 |
\expandafter\XINT_Seq:tl:x |
| 41394 |
\the\numexpr \xintiCeil{#1}\expandafter.\the\numexpr \xintiFloor{#2}.% |
| 41395 |
}% |
| 41396 |
\def\XINT_Seq:tl:x #1.#2.% |
| 41397 |
{% |
| 41398 |
\ifnum #2=#1 \xint_dothis\XINT_Seq:tl:x_z\fi |
| 41399 |
\ifnum #2<#1 \xint_dothis\XINT_Seq:tl:x_n\fi |
| 41400 |
\xint_orthat\XINT_Seq:tl:x_p |
| 41401 |
#1.#2.% |
| 41402 |
}% |
| 41403 |
\def\XINT_Seq:tl:x_z #1.#2.{{#1/1[0]}}% |
| 41404 |
\def\XINT_Seq:tl:x_p #1.#2.% |
| 41405 |
{% |
| 41406 |
{#1/1[0]}\ifnum #1=#2 \XINT_Seq:tl:x_e\fi |
| 41407 |
\expandafter\XINT_Seq:tl:x_p \the\numexpr #1+\xint_c_i.#2.% |
| 41408 |
}% |
| 41409 |
\def\XINT_Seq:tl:x_n #1.#2.% |
| 41410 |
{% |
| 41411 |
{#1/1[0]}\ifnum #1=#2 \XINT_Seq:tl:x_e\fi |
| 41412 |
\expandafter\XINT_Seq:tl:x_n \the\numexpr #1-\xint_c_i.#2.% |
| 41413 |
}% |
| 41414 |
\def\XINT_Seq:tl:x_e#1#2.#3.{#1}% |
| 41415 |
% \end{macrocode} |
| 41416 |
% \paragraph{\csh{xintiiSeq:tl:x}} |
| 41417 |
% \begin{macrocode} |
| 41418 |
\def\xintiiSeq:tl:x #1#2% |
| 41419 |
{% |
| 41420 |
\expandafter\XINT_iiSeq:tl:x |
| 41421 |
\the\numexpr \xintiCeil{#1}\expandafter.\the\numexpr \xintiFloor{#2}.% |
| 41422 |
}% |
| 41423 |
\def\XINT_iiSeq:tl:x #1.#2.% |
| 41424 |
{% |
| 41425 |
\ifnum #2=#1 \xint_dothis\XINT_iiSeq:tl:x_z\fi |
| 41426 |
\ifnum #2<#1 \xint_dothis\XINT_iiSeq:tl:x_n\fi |
| 41427 |
\xint_orthat\XINT_iiSeq:tl:x_p |
| 41428 |
#1.#2.% |
| 41429 |
}% |
| 41430 |
\def\XINT_iiSeq:tl:x_z #1.#2.{{#1}}% |
| 41431 |
\def\XINT_iiSeq:tl:x_p #1.#2.% |
| 41432 |
{% |
| 41433 |
{#1}\ifnum #1=#2 \XINT_Seq:tl:x_e\fi |
| 41434 |
\expandafter\XINT_iiSeq:tl:x_p \the\numexpr #1+\xint_c_i.#2.% |
| 41435 |
}% |
| 41436 |
\def\XINT_iiSeq:tl:x_n #1.#2.% |
| 41437 |
{% |
| 41438 |
{#1}\ifnum #1=#2 \XINT_Seq:tl:x_e\fi |
| 41439 |
\expandafter\XINT_iiSeq:tl:x_n \the\numexpr #1-\xint_c_i.#2.% |
| 41440 |
}% |
| 41441 |
% \end{macrocode} |
| 41442 |
%\begin{lverb} |
| 41443 |
% Contrarily to a..b which is limited to small integers, this works |
| 41444 |
% with a, b, and d (big) fractions. It will produce a «nil» list, if a>b and |
| 41445 |
% d<0 or a<b and d>0. |
| 41446 |
%\end{lverb} |
| 41447 |
% |
| 41448 |
% \paragraph{\csh{xintSeqA}, \csh{xintiiSeqA}} |
| 41449 |
% |
| 41450 |
% \begin{macrocode} |
| 41451 |
\def\xintSeqA {\expandafter\XINT_SeqA\romannumeral0\xintraw}% |
| 41452 |
\def\xintiiSeqA #1{\expandafter\XINT_iiSeqA\romannumeral`&&@#1;}% |
| 41453 |
\def\XINT_SeqA #1]#2{\expandafter\XINT_SeqA_a\romannumeral0\xintraw {#2}#1]}% |
| 41454 |
\def\XINT_iiSeqA#1;#2{\expandafter\XINT_SeqA_a\romannumeral`&&@#2;#1;}% |
| 41455 |
\def\XINT_SeqA_a #1{\xint_UDzerominusfork |
| 41456 |
#1-{z}% |
| 41457 |
0#1{n}% |
| 41458 |
0-{p}% |
| 41459 |
\krof #1}% |
| 41460 |
% \end{macrocode} |
| 41461 |
% \paragraph{\csh{xintSeqB:tl:x}} |
| 41462 |
%\begin{lverb} |
| 41463 |
% At 1.4, delayed expansion of start and step done here and not before, |
| 41464 |
% for matters of \xintdeffunc and «NEhooks». |
| 41465 |
% |
| 41466 |
% The float variant at 1.4 is made identical to the exact variant. I.e. |
| 41467 |
% stepping is exact and comparison to the range limit too. But recall that a/b |
| 41468 |
% input will be converted to a float. To handle 1/3 step for example still |
| 41469 |
% better to use \xintexpr 1..1/3..10\relax for example inside the \xintfloateval. |
| 41470 |
% |
| 41471 |
%\end{lverb} |
| 41472 |
% \begin{macrocode} |
| 41473 |
\def\xintSeqB:tl:x #1{\expandafter\XINT_SeqB:tl:x\romannumeral`&&@\xintSeqA#1}% |
| 41474 |
\def\XINT_SeqB:tl:x #1{\csname XINT_SeqB#1:tl:x\endcsname}% |
| 41475 |
\def\XINT_SeqBz:tl:x #1]#2]#3{{#2]}}% |
| 41476 |
\def\XINT_SeqBp:tl:x #1]#2]#3% |
| 41477 |
{\expandafter\XINT_SeqBp:tl:x_a\romannumeral0\xintraw{#3}#2]#1]}% |
| 41478 |
\def\XINT_SeqBp:tl:x_a #1]#2]#3]% |
| 41479 |
{% |
| 41480 |
\xintifCmp{#1]}{#2]}% |
| 41481 |
{}{{#2]}}{{#2]}\expandafter\XINT_SeqBp:tl:x_b\romannumeral0\xintadd{#3]}{#2]}#1]#3]}% |
| 41482 |
}% |
| 41483 |
\def\XINT_SeqBp:tl:x_b #1]#2]#3]% |
| 41484 |
{% |
| 41485 |
\xintifCmp{#1]}{#2]}% |
| 41486 |
{{#1]}\expandafter\XINT_SeqBp:tl:x_b\romannumeral0\xintadd{#3]}{#1]}#2]#3]}{{#1]}}{}% |
| 41487 |
}% |
| 41488 |
\def\XINT_SeqBn:tl:x #1]#2]#3% |
| 41489 |
{\expandafter\XINT_SeqBn:tl:x_a\romannumeral0\xintraw{#3}#2]#1]}% |
| 41490 |
\def\XINT_SeqBn:tl:x_a #1]#2]#3]% |
| 41491 |
{% |
| 41492 |
\xintifCmp{#1]}{#2]}% |
| 41493 |
{{#2]}\expandafter\XINT_SeqBn:tl:x_b\romannumeral0\xintadd{#3]}{#2]}#1]#3]}{{#2]}}{}% |
| 41494 |
}% |
| 41495 |
\def\XINT_SeqBn:tl:x_b #1]#2]#3]% |
| 41496 |
{% |
| 41497 |
\xintifCmp{#1]}{#2]}% |
| 41498 |
{}{{#1]}}{{#1]}\expandafter\XINT_SeqBn:tl:x_b\romannumeral0\xintadd{#3]}{#1]}#2]#3]}% |
| 41499 |
}% |
| 41500 |
% \end{macrocode} |
| 41501 |
% \paragraph{\csh{xintiiSeqB:tl:x}} |
| 41502 |
% \begin{macrocode} |
| 41503 |
\def\xintiiSeqB:tl:x #1{\expandafter\XINT_iiSeqB:tl:x\romannumeral`&&@\xintiiSeqA#1}% |
| 41504 |
\def\XINT_iiSeqB:tl:x #1{\csname XINT_iiSeqB#1:tl:x\endcsname}% |
| 41505 |
\def\XINT_iiSeqBz:tl:x #1;#2;#3{{#2}}% |
| 41506 |
\def\XINT_iiSeqBp:tl:x #1;#2;#3{\expandafter\XINT_iiSeqBp:tl:x_a\romannumeral`&&@#3;#2;#1;}% |
| 41507 |
\def\XINT_iiSeqBp:tl:x_a #1;#2;#3;% |
| 41508 |
{% |
| 41509 |
\xintiiifCmp{#1}{#2}% |
| 41510 |
{}{{#2}}{{#2}\expandafter\XINT_iiSeqBp:tl:x_b\romannumeral0\xintiiadd{#3}{#2};#1;#3;}% |
| 41511 |
}% |
| 41512 |
\def\XINT_iiSeqBp:tl:x_b #1;#2;#3;% |
| 41513 |
{% |
| 41514 |
\xintiiifCmp{#1}{#2}% |
| 41515 |
{{#1}\expandafter\XINT_iiSeqBp:tl:x_b\romannumeral0\xintiiadd{#3}{#1};#2;#3;}{{#1}}{}% |
| 41516 |
}% |
| 41517 |
\def\XINT_iiSeqBn:tl:x #1;#2;#3{\expandafter\XINT_iiSeqBn:tl:x_a\romannumeral`&&@#3;#2;#1;}% |
| 41518 |
\def\XINT_iiSeqBn:tl:x_a #1;#2;#3;% |
| 41519 |
{% |
| 41520 |
\xintiiifCmp{#1}{#2}% |
| 41521 |
{{#2}\expandafter\XINT_iiSeqBn:tl:x_b\romannumeral0\xintiiadd{#3}{#2};#1;#3;}{{#2}}{}% |
| 41522 |
}% |
| 41523 |
\def\XINT_iiSeqBn:tl:x_b #1;#2;#3;% |
| 41524 |
{% |
| 41525 |
\xintiiifCmp{#1}{#2}% |
| 41526 |
{}{{#1}}{{#1}\expandafter\XINT_iiSeqBn:tl:x_b\romannumeral0\xintiiadd{#3}{#1};#2;#3;}% |
| 41527 |
}% |
| 41528 |
% \end{macrocode} |
| 41529 |
% \subsection{Square brackets [\texorpdfstring{\,}{ }] both as a container and a Python slicer} |
| 41530 |
% Refactored at |1.4| |
| 41531 |
% |
| 41532 |
%\begin{lverb} |
| 41533 |
% The architecture allows to implement separately a «left» and a «right» |
| 41534 |
% precedence and this is crucial. |
| 41535 |
%\end{lverb} |
| 41536 |
% \localtableofcontents |
| 41537 |
% |
| 41538 |
% |
| 41539 |
% \subsubsection{[...] as «oneple» constructor} |
| 41540 |
% |
| 41541 |
%\begin{lverb} |
| 41542 |
% In the definition of \XINT_expr_op_obracket the parameter |
| 41543 |
% is trash {}. The [ is intercepted by the getnextfork and handled |
| 41544 |
% via the \xint_c_ii^v highest precedence trick to get op_obracket |
| 41545 |
% executed. |
| 41546 |
%\end{lverb} |
| 41547 |
% \odef\MakePrivateLetters{\MakePrivateLetters\catcode`[ 11 \catcode`] 11 }^^A |
| 41548 |
% \begin{macrocode} |
| 41549 |
\def\XINT_expr_itself_obracket{obracket}% |
| 41550 |
\catcode`] 11 \catcode`[ 11 |
| 41551 |
\def\XINT_expr_defbin_c #1#2#3#4#5#6% |
| 41552 |
{% |
| 41553 |
\def #1##1% |
| 41554 |
{% |
| 41555 |
\expandafter#3\romannumeral`&&@\XINT_expr_getnext |
| 41556 |
}% |
| 41557 |
\def #2##1% op_] |
| 41558 |
{% |
| 41559 |
\expanded{\xint_noxpd{\XINT_expr_put_op_first{{##1}}}\expandafter}% |
| 41560 |
\romannumeral`&&@\XINT_expr_getop |
| 41561 |
}% |
| 41562 |
\def #3##1% until_cbracket_a |
| 41563 |
{% |
| 41564 |
\xint_UDsignfork |
| 41565 |
##1{\expandafter#4\romannumeral`&&@#5}% #5 = op_-xii |
| 41566 |
-{#4##1}% |
| 41567 |
\krof |
| 41568 |
}% |
| 41569 |
\def #4##1##2% until_cbracket_b |
| 41570 |
{% |
| 41571 |
\ifcase ##1\expandafter\XINT_expr_missing_] |
| 41572 |
\or \expandafter\XINT_expr_missing_] |
| 41573 |
\or \expandafter#2% |
| 41574 |
\else |
| 41575 |
\expandafter #4% |
| 41576 |
\romannumeral`&&@\csname XINT_#6_op_##2\expandafter\endcsname |
| 41577 |
\fi |
| 41578 |
}% |
| 41579 |
}% |
| 41580 |
\def\XINT_expr_defbin_b #1% |
| 41581 |
{% |
| 41582 |
\expandafter\XINT_expr_defbin_c |
| 41583 |
\csname XINT_#1_op_obracket\expandafter\endcsname |
| 41584 |
\csname XINT_#1_op_]\expandafter\endcsname |
| 41585 |
\csname XINT_#1_until_cbracket_a\expandafter\endcsname |
| 41586 |
\csname XINT_#1_until_cbracket_b\expandafter\endcsname |
| 41587 |
\csname XINT_#1_op_-xii\endcsname |
| 41588 |
{#1}% |
| 41589 |
}% |
| 41590 |
\XINT_expr_defbin_b {expr}% |
| 41591 |
\XINT_expr_defbin_b {flexpr}% |
| 41592 |
\XINT_expr_defbin_b {iiexpr}% |
| 41593 |
\def\XINT_expr_missing_] |
| 41594 |
{\XINT_expandableerror{Ooops, looks like we are missing a ]. Aborting!}% |
| 41595 |
\xint_c_ \XINT_expr_done}% |
| 41596 |
\let\XINT_expr_precedence_]\xint_c_ii |
| 41597 |
% \end{macrocode} |
| 41598 |
% \subsubsection{[...] brackets and : operator for NumPy-like slicing and item |
| 41599 |
% indexing syntax} |
| 41600 |
%\begin{lverb} |
| 41601 |
% The opening bracket [ for the nutple constructor is filtered out by |
| 41602 |
% \XINT_expr_getnextfork and becomes «obracket» which behaves with |
| 41603 |
% precedence level 2. For the [..] Python slicer on the other hand, a real |
| 41604 |
% operator [ is defined with precedence level 4 (it must be higher than |
| 41605 |
% precedence level of commas) on its right and maximal precedence on its left. |
| 41606 |
% |
| 41607 |
% Important: although slicing and indexing shares many rules with Python/NumPy |
| 41608 |
% there are some significant differences: in particular there can not be any |
| 41609 |
% out-of-range error generated, slicing applies also to «oples» and not only |
| 41610 |
% to «nutple», and nested lists do not have to have their leaves at a constant |
| 41611 |
% depth. See the user manual. |
| 41612 |
% |
| 41613 |
% Currently, NumPy-like nested (basic) slicing is implemented, i.e [a:b, c:d, |
| 41614 |
% N, e:f, M] type syntax with Python rules regarding negative integers. This |
| 41615 |
% is parsed as an expression and can arise from expansion or contain |
| 41616 |
% calculations. |
| 41617 |
% |
| 41618 |
% Currently stepping, Ellipsis, and simultaneous multi-index extracting are |
| 41619 |
% not yet implemented. |
| 41620 |
% |
| 41621 |
% There are some subtle things here with possibility of variables been passed |
| 41622 |
% by reference. |
| 41623 |
%\end{lverb} |
| 41624 |
% \begin{macrocode} |
| 41625 |
\def\XINT_expr_defbin_c #1#2#3#4#5#6% |
| 41626 |
{% |
| 41627 |
\def #1##1% \XINT_expr_op_[ |
| 41628 |
{% |
| 41629 |
\expanded{\xint_noxpd{#2{##1}}\expandafter}% |
| 41630 |
\romannumeral`&&@\expandafter#3\romannumeral`&&@\XINT_expr_getnext |
| 41631 |
}% |
| 41632 |
\def #2##1##2##3##4% \XINT_expr_exec_] |
| 41633 |
{% |
| 41634 |
\expandafter\XINT_expr_put_op_first |
| 41635 |
\expanded |
| 41636 |
{% |
| 41637 |
{\XINT:NEhook:x:listsel\XINT_ListSel_top ##1__##4&({##1}\expandafter}% |
| 41638 |
\expandafter |
| 41639 |
}% |
| 41640 |
\romannumeral`&&@\XINT_expr_getop |
| 41641 |
}% |
| 41642 |
\def #3##1% \XINT_expr_check-_] |
| 41643 |
{% |
| 41644 |
\xint_UDsignfork |
| 41645 |
##1{\expandafter#4\romannumeral`&&@#5}% |
| 41646 |
-{#4##1}% |
| 41647 |
\krof |
| 41648 |
}% |
| 41649 |
\def #4##1##2% \XINT_expr_checkp_] |
| 41650 |
{% |
| 41651 |
\ifcase ##1\XINT_expr_missing_] |
| 41652 |
\or \XINT_expr_missing_] |
| 41653 |
\or \expandafter##1\expandafter##2% |
| 41654 |
\else \expandafter#4% |
| 41655 |
\romannumeral`&&@\csname XINT_#6_op_##2\expandafter\endcsname |
| 41656 |
\fi |
| 41657 |
}% |
| 41658 |
}% |
| 41659 |
\let\XINT_expr_precedence_[ \xint_c_xx |
| 41660 |
\def\XINT_expr_defbin_b #1% |
| 41661 |
{% |
| 41662 |
\expandafter\XINT_expr_defbin_c |
| 41663 |
\csname XINT_#1_op_[\expandafter\endcsname |
| 41664 |
\csname XINT_#1_exec_]\expandafter\endcsname |
| 41665 |
\csname XINT_#1_check-_]\expandafter\endcsname |
| 41666 |
\csname XINT_#1_checkp_]\expandafter\endcsname |
| 41667 |
\csname XINT_#1_op_-xii\endcsname |
| 41668 |
{#1}% |
| 41669 |
}% |
| 41670 |
\XINT_expr_defbin_b {expr}% |
| 41671 |
\XINT_expr_defbin_b {flexpr}% |
| 41672 |
\XINT_expr_defbin_b {iiexpr}% |
| 41673 |
\catcode`] 12 \catcode`[ 12 |
| 41674 |
% \end{macrocode} |
| 41675 |
% \let\MakePrivateLetters\xintexprMakePrivateLetters |
| 41676 |
%\begin{lverb} |
| 41677 |
% At 1.4 the getnext, scanint, scanfunc, getop chain got revisited to |
| 41678 |
% trigger automatic insertion of the nil variable if needed, without having in |
| 41679 |
% situations like here to define operators to support «[:» or «:]». And as we |
| 41680 |
% want to implement nested slicing à la NumPy, we would have had to handle |
| 41681 |
% also «:,» for example. Thus here we simply have to define the sole operator |
| 41682 |
% «:» and it will be some sort of inert joiner preparing a slicing spec. |
| 41683 |
%\end{lverb} |
| 41684 |
% \begin{macrocode} |
| 41685 |
\def\XINT_expr_defbin_c #1#2#3#4#5#6% |
| 41686 |
{% |
| 41687 |
\def #1##1% \XINT_expr_op_: |
| 41688 |
{% |
| 41689 |
\expanded{\xint_noxpd{#2{##1}}\expandafter}% |
| 41690 |
\romannumeral`&&@\expandafter#3\romannumeral`&&@\XINT_expr_getnext |
| 41691 |
}% |
| 41692 |
\def #2##1##2##3##4% \XINT_expr_exec_: |
| 41693 |
{% |
| 41694 |
##2##3{:##1{0};##4:_}% |
| 41695 |
}% |
| 41696 |
\def #3##1% \XINT_expr_check-_: |
| 41697 |
{\xint_UDsignfork |
| 41698 |
##1{\expandafter#4\romannumeral`&&@#5}% |
| 41699 |
-{#4##1}% |
| 41700 |
\krof |
| 41701 |
}% |
| 41702 |
\def #4##1##2% \XINT_expr_checkp_: |
| 41703 |
{% |
| 41704 |
\ifnum ##1>\XINT_expr_precedence_: |
| 41705 |
\expandafter #4\romannumeral`&&@% |
| 41706 |
\csname XINT_#6_op_##2\expandafter\endcsname |
| 41707 |
\else |
| 41708 |
\expandafter##1\expandafter##2% |
| 41709 |
\fi |
| 41710 |
}% |
| 41711 |
}% |
| 41712 |
\let\XINT_expr_precedence_: \xint_c_vi |
| 41713 |
\def\XINT_expr_defbin_b #1% |
| 41714 |
{% |
| 41715 |
\expandafter\XINT_expr_defbin_c |
| 41716 |
\csname XINT_#1_op_:\expandafter\endcsname |
| 41717 |
\csname XINT_#1_exec_:\expandafter\endcsname |
| 41718 |
\csname XINT_#1_check-_:\expandafter\endcsname |
| 41719 |
\csname XINT_#1_checkp_:\expandafter\endcsname |
| 41720 |
\csname XINT_#1_op_-xii\endcsname {#1}% |
| 41721 |
}% |
| 41722 |
\XINT_expr_defbin_b {expr}% |
| 41723 |
\XINT_expr_defbin_b {flexpr}% |
| 41724 |
\XINT_expr_defbin_b {iiexpr}% |
| 41725 |
% \end{macrocode} |
| 41726 |
% \subsubsection{Macro layer implementing indexing and slicing} |
| 41727 |
%\begin{lverb} |
| 41728 |
% xintexpr applies slicing not only to «objects» (which can be passed |
| 41729 |
% as arguments to functions) but also to «oples». |
| 41730 |
% |
| 41731 |
% Our «nlists» are not necessarily regular N-dimensional arrays à la NumPy. |
| 41732 |
% Leaves can be at arbitrary depths. If we were handling regular «ndarrays», |
| 41733 |
% we could proceed a bit differently. |
| 41734 |
% |
| 41735 |
% For the related |
| 41736 |
% explanations, refer to the user manual. |
| 41737 |
% |
| 41738 |
% Notice that currently the code uses f-expandable (and not using \expanded) |
| 41739 |
% macros \xintApply, \xintApplyUnbraced, \xintKeep, \xintTrim, \xintNthOne from |
| 41740 |
% $xinttoolsnameimp. |
| 41741 |
% |
| 41742 |
% But the whole expansion happens inside an \expanded context, so possibly |
| 41743 |
% some gain could be achieved with x-expandable variants (xintexpr < 1.4 |
| 41744 |
% had an \xintKeep:x:csv). |
| 41745 |
% |
| 41746 |
% I coded \xintApply:x and \xintApplyUnbraced:x in $xinttoolsnameimp, Brief |
| 41747 |
% testing indicated they were perhaps a bit better for 5x5x5x5 and 15x15x15x15 |
| 41748 |
% arrays of 8 digits numbers and for 30x30x15 with 16 digits numbers: say |
| 41749 |
% 1$% gain... this seems to raise to between 4$% and |
| 41750 |
% 5$% for 400x400 array of 1 digit... |
| 41751 |
% |
| 41752 |
% Currently sticking with old macros. |
| 41753 |
%\end{lverb} |
| 41754 |
% \begin{macrocode} |
| 41755 |
\def\XINT_ListSel_deeper #1% |
| 41756 |
{% |
| 41757 |
\if :#1\xint_dothis\XINT_ListSel_slice_next\fi |
| 41758 |
\xint_orthat {\XINT_ListSel_extract_next {#1}}% |
| 41759 |
}% |
| 41760 |
\def\XINT_ListSel_slice_next #1(% |
| 41761 |
{% |
| 41762 |
\xintApply{\XINT_ListSel_recurse{:#1}}% |
| 41763 |
}% |
| 41764 |
\def\XINT_ListSel_extract_next #1(% |
| 41765 |
{% |
| 41766 |
\xintApplyUnbraced{\XINT_ListSel_recurse{#1}}% |
| 41767 |
}% |
| 41768 |
\def\XINT_ListSel_recurse #1#2% |
| 41769 |
{% |
| 41770 |
\XINT_ListSel_check #2__#1({#2}\expandafter\empty\empty |
| 41771 |
}% |
| 41772 |
\def\XINT_ListSel_check{\expandafter\XINT_ListSel_check_a \string}% |
| 41773 |
\def\XINT_ListSel_check_a #1% |
| 41774 |
{% |
| 41775 |
\if #1\bgroup\xint_dothis\XINT_ListSel_check_is_ok\fi |
| 41776 |
\xint_orthat\XINT_ListSel_check_leaf |
| 41777 |
}% |
| 41778 |
\def\XINT_ListSel_check_leaf #1\expandafter{\expandafter}% |
| 41779 |
\def\XINT_ListSel_check_is_ok |
| 41780 |
{% |
| 41781 |
\expandafter\XINT_ListSel_check_is_ok_a\expandafter{\string}% |
| 41782 |
}% |
| 41783 |
\def\XINT_ListSel_check_is_ok_a #1__#2% |
| 41784 |
{% |
| 41785 |
\if :#2\xint_dothis{\XINT_ListSel_slice}\fi |
| 41786 |
\xint_orthat {\XINT_ListSel_nthone {#2}}% |
| 41787 |
}% |
| 41788 |
\def\XINT_ListSel_top #1#2% |
| 41789 |
{% |
| 41790 |
\if _\noexpand#2% |
| 41791 |
\expandafter\XINT_ListSel_top_one_or_none\string#1.\else |
| 41792 |
\expandafter\XINT_ListSel_top_at_least_two\fi |
| 41793 |
}% |
| 41794 |
\def\XINT_ListSel_top_at_least_two #1__{\XINT_ListSel_top_ople}% |
| 41795 |
\def\XINT_ListSel_top_one_or_none #1% |
| 41796 |
{% |
| 41797 |
\if #1_\xint_dothis\XINT_ListSel_top_nil\fi |
| 41798 |
\if #1.\xint_dothis\XINT_ListSel_top_nutple_a\fi |
| 41799 |
\if #1\bgroup\xint_dothis\XINT_ListSel_top_nutple\fi |
| 41800 |
\xint_orthat\XINT_ListSel_top_number |
| 41801 |
}% |
| 41802 |
\def\XINT_ListSel_top_nil #1\expandafter#2\expandafter{\fi\expandafter}% |
| 41803 |
\def\XINT_ListSel_top_nutple |
| 41804 |
{% |
| 41805 |
\expandafter\XINT_ListSel_top_nutple_a\expandafter{\string}% |
| 41806 |
}% |
| 41807 |
\def\XINT_ListSel_top_nutple_a #1_#2#3(#4% |
| 41808 |
{% |
| 41809 |
\fi\if :#2\xint_dothis{{\XINT_ListSel_slice #3(#4}}\fi |
| 41810 |
\xint_orthat {\XINT_ListSel_nthone {#2}#3(#4}% |
| 41811 |
}% |
| 41812 |
\def\XINT_ListSel_top_number #1_{\fi\XINT_ListSel_top_ople}% |
| 41813 |
\def\XINT_ListSel_top_ople #1% |
| 41814 |
{% |
| 41815 |
\if :#1\xint_dothis\XINT_ListSel_slice\fi |
| 41816 |
\xint_orthat {\XINT_ListSel_nthone {#1}}% |
| 41817 |
}% |
| 41818 |
\def\XINT_ListSel_slice #1% |
| 41819 |
{% |
| 41820 |
\expandafter\XINT_ListSel_slice_a \expandafter{\romannumeral0\xintnum{#1}}% |
| 41821 |
}% |
| 41822 |
\def\XINT_ListSel_slice_a #1#2;#3#4% |
| 41823 |
{% |
| 41824 |
\if _#4\expandafter\XINT_ListSel_s_b |
| 41825 |
\else\expandafter\XINT_ListSel_slice_b\fi |
| 41826 |
#1;#3% |
| 41827 |
}% |
| 41828 |
\def\XINT_ListSel_s_b #1#2;#3#4% |
| 41829 |
{% |
| 41830 |
\if \expandafter\XINT_ListSel_s_last\fi |
| 41831 |
\XINT_ListSel_s_c #1{#1#2}{#4}% |
| 41832 |
}% |
| 41833 |
\def\XINT_ListSel_s_last\XINT_ListSel_s_c #1#2#3(#4% |
| 41834 |
{% |
| 41835 |
\if-#1\expandafter\xintKeep\else\expandafter\xintTrim\fi {#2}{#4}% |
| 41836 |
}% |
| 41837 |
\def\XINT_ListSel_s_c #1#2#3(#4% |
| 41838 |
{% |
| 41839 |
\expandafter\XINT_ListSel_deeper |
| 41840 |
\expanded{\xint_noxpd{#3}(\expandafter}\expandafter{% |
| 41841 |
\romannumeral0% |
| 41842 |
\if-#1\expandafter\xintkeep\else\expandafter\xinttrim\fi {#2}{#4}}% |
| 41843 |
}% |
| 41844 |
% \end{macrocode} |
| 41845 |
%\begin{lverb} |
| 41846 |
% |
| 41847 |
% \xintNthElt from xinttools (knowingly) strips one level of |
| 41848 |
% braces when fetching kth «item» from {v1}...{vN}. If we expand |
| 41849 |
% {\xintNthElt{k}{{v1}...{vN}}} (notice external braces): |
| 41850 |
% |
| 41851 |
%( if k is out of range we end up with {} |
| 41852 |
%: if k is in range and the kth braced item was {} we end up with {} |
| 41853 |
%: if k is in range and the kth braced item was {17} we end up with {17} |
| 41854 |
%) |
| 41855 |
% |
| 41856 |
% Problem is that individual numbers such as 17 are stored {{17}}. So |
| 41857 |
% we must have one more brace pair and in the first two cases we end up |
| 41858 |
% with {{}}. But in the first case we should end up with the empty ople |
| 41859 |
% {}, not the empty bracketed ople {{}}. |
| 41860 |
% |
| 41861 |
% I have thus added \xintNthOne to $xinttoolsnameimp which does not |
| 41862 |
% strip brace pair from an extracted item. |
| 41863 |
% |
| 41864 |
% Attention: \XINT_nthonepy_a does no expansion on second argument. |
| 41865 |
% But here arguments are either numerical or already expanded. |
| 41866 |
% Normally. |
| 41867 |
% |
| 41868 |
%\end{lverb} |
| 41869 |
% \begin{macrocode} |
| 41870 |
\def\XINT_ListSel_nthone #1#2% |
| 41871 |
{% |
| 41872 |
\if \expandafter\XINT_ListSel_nthone_last\fi |
| 41873 |
\XINT_ListSel_nthone_a {#1}{#2}% |
| 41874 |
}% |
| 41875 |
\def\XINT_ListSel_nthone_a #1#2(#3% |
| 41876 |
{% |
| 41877 |
\expandafter\XINT_ListSel_deeper |
| 41878 |
\expanded{\xint_noxpd{#2}(\expandafter}\expandafter{% |
| 41879 |
\romannumeral0\expandafter\XINT_nthonepy_a\the\numexpr\xintNum{#1}.{#3}}% |
| 41880 |
}% |
| 41881 |
\def\XINT_ListSel_nthone_last\XINT_ListSel_nthone_a #1#2(%#3% |
| 41882 |
{% |
| 41883 |
\romannumeral0\expandafter\XINT_nthonepy_a\the\numexpr\xintNum{#1}.%{#3} |
| 41884 |
}% |
| 41885 |
% \end{macrocode} |
| 41886 |
%\begin{lverb} |
| 41887 |
% The macros here are basically f-expandable and use the |
| 41888 |
% f-expandable \xintKeep and \xintTrim. Prior to xint 1.4, there was |
| 41889 |
% here an x-expandable \xintKeep:x:csv dealing with comma separated |
| 41890 |
% items, for time being we make do with our f-expandable toolkit. |
| 41891 |
%\end{lverb} |
| 41892 |
% \begin{macrocode} |
| 41893 |
\def\XINT_ListSel_slice_b #1;#2_#3% |
| 41894 |
{% |
| 41895 |
\if \expandafter\XINT_ListSel_slice_last\fi |
| 41896 |
\expandafter\XINT_ListSel_slice_c \expandafter{\romannumeral0\xintnum{#2}};#1;{#3}% |
| 41897 |
}% |
| 41898 |
\def\XINT_ListSel_slice_last\expandafter\XINT_ListSel_slice_c #1;#2;#3(%#4 |
| 41899 |
{% |
| 41900 |
\expandafter\XINT_ListSel_slice_last_c #1;#2;%{#4} |
| 41901 |
}% |
| 41902 |
% \end{macrocode} |
| 41903 |
% \changed{1.4n} |
| 41904 |
% Compatibility with LuaMeta\TeX{} regarding |;| not usable as \cs{numexpr} |
| 41905 |
% delimiter. Fortunately I had mostly used \cs{xint:} or a dot in the past |
| 41906 |
% throughout the code base, so not many locations needed adjustments. Here I |
| 41907 |
% simpy replaced all semi-colons by fullstops starting here with how |
| 41908 |
% \csbXINT{_ListSel_slice_d} receives arguments. Fortuntely |
| 41909 |
% \csbxint{_gob_til_sc} was not used around here. |
| 41910 |
% \begin{macrocode} |
| 41911 |
\def\XINT_ListSel_slice_last_c #1;#2;#3% |
| 41912 |
{% |
| 41913 |
\romannumeral0\XINT_ListSel_slice_d #2.#1.{#3}% |
| 41914 |
}% |
| 41915 |
\def\XINT_ListSel_slice_c #1;#2;#3(#4% |
| 41916 |
{% |
| 41917 |
\expandafter\XINT_ListSel_deeper |
| 41918 |
\expanded{\xint_noxpd{#3}(\expandafter}\expandafter{% |
| 41919 |
\romannumeral0\XINT_ListSel_slice_d #2.#1.{#4}}% |
| 41920 |
}% |
| 41921 |
\def\XINT_ListSel_slice_d #1#2.#3#4.% |
| 41922 |
{% |
| 41923 |
\xint_UDsignsfork |
| 41924 |
#1#3\XINT_ListSel_N:N |
| 41925 |
#1-\XINT_ListSel_N:P |
| 41926 |
-#3\XINT_ListSel_P:N |
| 41927 |
--\XINT_ListSel_P:P |
| 41928 |
\krof #1#2.#3#4.% |
| 41929 |
}% |
| 41930 |
\def\XINT_ListSel_P:P #1.#2.#3% |
| 41931 |
{% |
| 41932 |
\unless\ifnum #1<#2 \expandafter\xint_gob_andstop_iii\fi |
| 41933 |
\xintkeep{#2-#1}{\xintTrim{#1}{#3}}% |
| 41934 |
}% |
| 41935 |
\def\XINT_ListSel_N:N #1.#2.#3% |
| 41936 |
{% |
| 41937 |
\expandafter\XINT_ListSel_N:N_a |
| 41938 |
\the\numexpr #2-#1\expandafter.\the\numexpr#1+\xintLength{#3}.{#3}% |
| 41939 |
}% |
| 41940 |
\def\XINT_ListSel_N:N_a #1.#2.#3% |
| 41941 |
{% |
| 41942 |
\unless\ifnum #1>\xint_c_ \expandafter\xint_gob_andstop_iii\fi |
| 41943 |
\xintkeep{#1}{\xintTrim{\ifnum#2<\xint_c_\xint_c_\else#2\fi}{#3}}% |
| 41944 |
}% |
| 41945 |
\def\XINT_ListSel_N:P #1.#2.#3% |
| 41946 |
{% |
| 41947 |
\expandafter\XINT_ListSel_N:P_a |
| 41948 |
\the\numexpr #1+\xintLength{#3}.#2.{#3}% |
| 41949 |
}% |
| 41950 |
\def\XINT_ListSel_N:P_a #1#2.% |
| 41951 |
{\if -#1\expandafter\XINT_ListSel_O:P\fi\XINT_ListSel_P:P #1#2.}% |
| 41952 |
\def\XINT_ListSel_O:P\XINT_ListSel_P:P #1.{\XINT_ListSel_P:P 0.}% |
| 41953 |
\def\XINT_ListSel_P:N #1.#2.#3% |
| 41954 |
{% |
| 41955 |
\expandafter\XINT_ListSel_P:N_a |
| 41956 |
\the\numexpr #2+\xintLength{#3}.#1.{#3}% |
| 41957 |
}% |
| 41958 |
\def\XINT_ListSel_P:N_a #1#2.#3.% |
| 41959 |
{\if -#1\expandafter\XINT_ListSel_P:O\fi\XINT_ListSel_P:P #3.#1#2.}% |
| 41960 |
\def\XINT_ListSel_P:O\XINT_ListSel_P:P #1.#2.{\XINT_ListSel_P:P #1.0.}% |
| 41961 |
% \end{macrocode} |
| 41962 |
% \subsection{Support for raw A/B[N]} |
| 41963 |
%\begin{lverb} |
| 41964 |
% Releases earlier than 1.1 required the use of braces around A/B[N] |
| 41965 |
% input. The [N] is now implemented directly. *BUT* this uses a delimited macro! |
| 41966 |
% thus N is not allowed to be itself an expression (I could add it...). |
| 41967 |
% \xintE, \xintiiE, and \XINTinFloatE all put #2 in a \numexpr. But attention |
| 41968 |
% to the fact that \numexpr stops at spaces separating digits: |
| 41969 |
% \the\numexpr 3 + 7 9\relax gives 109\relax !! Hence we have to be |
| 41970 |
% careful. |
| 41971 |
% |
| 41972 |
% \numexpr will not handle catcode 11 digits, but adding a \detokenize will |
| 41973 |
% suddenly make illicit for N to rely on macro expansion. |
| 41974 |
% |
| 41975 |
% At 1.4, [ is already overloaded and it is not easy to support this. We do |
| 41976 |
% this by a kludge maintaining more or less former (very not efficient) way |
| 41977 |
% but using $$ sign which is free for time being. No, finally I use the null |
| 41978 |
% character, should be safe enough! (I hesitated about using R with catcode |
| 41979 |
% 12). |
| 41980 |
% |
| 41981 |
% As for ? operator we needed |
| 41982 |
% to hack into \XINT_expr_getop_b for intercepting that pseudo operator. See |
| 41983 |
% also \XINT_expr_scanint_c (\XINT_expr_rawxintfrac). |
| 41984 |
%\end{lverb} |
| 41985 |
% \odef\MakePrivateLetters{\MakePrivateLetters\catcode`& 11 }^^A |
| 41986 |
% \begin{macrocode} |
| 41987 |
\catcode0 11 |
| 41988 |
\let\XINT_expr_precedence_&&@ \xint_c_xiv |
| 41989 |
\def\XINT_expr_op_&&@ #1#2]% |
| 41990 |
{% |
| 41991 |
\expandafter\XINT_expr_put_op_first |
| 41992 |
\expanded{{{\xintE#1{\xint_zapspaces #2 \xint_gobble_i}}}% |
| 41993 |
\expandafter}\romannumeral`&&@\XINT_expr_getop |
| 41994 |
}% |
| 41995 |
\def\XINT_iiexpr_op_&&@ #1#2]% |
| 41996 |
{% |
| 41997 |
\expandafter\XINT_expr_put_op_first |
| 41998 |
\expanded{{{\xintiiE#1{\xint_zapspaces #2 \xint_gobble_i}}}% |
| 41999 |
\expandafter}\romannumeral`&&@\XINT_expr_getop |
| 42000 |
}% |
| 42001 |
\def\XINT_flexpr_op_&&@ #1#2]% |
| 42002 |
{% |
| 42003 |
\expandafter\XINT_expr_put_op_first |
| 42004 |
\expanded{{{\XINTinFloatE#1{\xint_zapspaces #2 \xint_gobble_i}}}% |
| 42005 |
\expandafter}\romannumeral`&&@\XINT_expr_getop |
| 42006 |
}% |
| 42007 |
\catcode0 12 |
| 42008 |
% \end{macrocode} |
| 42009 |
% \let\MakePrivateLetters\xintexprMakePrivateLetters |
| 42010 |
% \subsection{? as two-way and ?? as three-way «short-circuit» conditionals} |
| 42011 |
%\begin{lverb} |
| 42012 |
% Comments undergoing reconstruction. |
| 42013 |
%\end{lverb} |
| 42014 |
% |
| 42015 |
% \begin{macrocode} |
| 42016 |
\let\XINT_expr_precedence_? \xint_c_xx |
| 42017 |
\catcode`- 11 |
| 42018 |
% \end{macrocode} |
| 42019 |
% \odef\MakePrivateLetters{\MakePrivateLetters\catcode`- 11 }\FixInterMacrocodeVspace |
| 42020 |
% \begin{macrocode} |
| 42021 |
\def\XINT_expr_op_? {\XINT_expr_op__? \XINT_expr_op_-xii}% |
| 42022 |
\def\XINT_flexpr_op_?{\XINT_expr_op__? \XINT_flexpr_op_-xii}% |
| 42023 |
\def\XINT_iiexpr_op_?{\XINT_expr_op__? \XINT_iiexpr_op_-xii}% |
| 42024 |
\catcode`- 12 |
| 42025 |
\def\XINT_expr_op__? #1#2#3% |
| 42026 |
{\XINT_expr_op__?_a #3!\xint_bye\XINT_expr_exec_? {#1}{#2}{#3}}% |
| 42027 |
\def\XINT_expr_op__?_a #1{\expandafter\XINT_expr_op__?_b\detokenize{#1}}% |
| 42028 |
\def\XINT_expr_op__?_b #1% |
| 42029 |
{\if ?#1\expandafter\XINT_expr_op__?_c\else\expandafter\xint_bye\fi }% |
| 42030 |
\def\XINT_expr_op__?_c #1{\xint_gob_til_! #1\XINT_expr_op_?? !\xint_bye}% |
| 42031 |
\def\XINT_expr_op_?? !\xint_bye\xint_bye\XINT_expr_exec_?{\XINT_expr_exec_??}% |
| 42032 |
\catcode`- 11 |
| 42033 |
\def\XINT_expr_exec_? #1#2% |
| 42034 |
{% |
| 42035 |
\expandafter\XINT_expr_check-_after?\expandafter#1% |
| 42036 |
\romannumeral`&&@\expandafter\XINT_expr_getnext\romannumeral0\xintiiifnotzero#2% |
| 42037 |
}% |
| 42038 |
\def\XINT_expr_exec_?? #1#2#3% |
| 42039 |
{% |
| 42040 |
\expandafter\XINT_expr_check-_after?\expandafter#1% |
| 42041 |
\romannumeral`&&@\expandafter\XINT_expr_getnext\romannumeral0\xintiiifsgn#2% |
| 42042 |
}% |
| 42043 |
\def\XINT_expr_check-_after? #1{% |
| 42044 |
\def\XINT_expr_check-_after? ##1##2% |
| 42045 |
{% |
| 42046 |
\xint_UDsignfork |
| 42047 |
##2{##1}% |
| 42048 |
#1{##2}% |
| 42049 |
\krof |
| 42050 |
}}\expandafter\XINT_expr_check-_after?\string -% |
| 42051 |
\catcode`- 12 |
| 42052 |
% \end{macrocode} |
| 42053 |
% \let\MakePrivateLetters\xintexprMakePrivateLetters |
| 42054 |
% \subsection{! as postfix factorial operator} |
| 42055 |
% \begin{macrocode} |
| 42056 |
\let\XINT_expr_precedence_! \xint_c_xx |
| 42057 |
\def\XINT_expr_op_! #1% |
| 42058 |
{% |
| 42059 |
\expandafter\XINT_expr_put_op_first |
| 42060 |
\expanded{{\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 42061 |
{\romannumeral`&&@\xintFac#1}}\expandafter}\romannumeral`&&@\XINT_expr_getop |
| 42062 |
}% |
| 42063 |
\def\XINT_flexpr_op_! #1% |
| 42064 |
{% |
| 42065 |
\expandafter\XINT_expr_put_op_first |
| 42066 |
\expanded{{\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 42067 |
{\romannumeral`&&@\XINTinFloatFacdigits#1}}\expandafter}% |
| 42068 |
\romannumeral`&&@\XINT_expr_getop |
| 42069 |
}% |
| 42070 |
\def\XINT_iiexpr_op_! #1% |
| 42071 |
{% |
| 42072 |
\expandafter\XINT_expr_put_op_first |
| 42073 |
\expanded{{\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 42074 |
{\romannumeral`&&@\xintiiFac#1}}\expandafter}\romannumeral`&&@\XINT_expr_getop |
| 42075 |
}% |
| 42076 |
% \end{macrocode} |
| 42077 |
%\begin{lverb} |
| 42078 |
% At 1.4g, fix for input "x! == y" via a fake operator !==. The ! |
| 42079 |
% is of catcode 11 but this does not matter here. The definition of |
| 42080 |
% \XINT_expr_itself_!== is required by the functioning of the scanop macros. |
| 42081 |
% |
| 42082 |
% We don't have to worry about "x! = y" as the single-character Boolean |
| 42083 |
% comparison = operator has been removed from syntax. Fixing it would have |
| 42084 |
% required obeying space tokens when parsing operators. For "x! == y" case, |
| 42085 |
% obeying space tokens would not solve "x!==y" input case anyhow. |
| 42086 |
%\end{lverb} |
| 42087 |
% \begin{macrocode} |
| 42088 |
\expandafter |
| 42089 |
\def\csname XINT_expr_precedence_!==\expandafter\endcsname |
| 42090 |
\csname XINT_expr_itself_!==\endcsname {\XINT_expr_precedence_! !==}% |
| 42091 |
\expandafter\def\csname XINT_expr_itself_!==\endcsname{!==}% |
| 42092 |
% \end{macrocode} |
| 42093 |
% \subsection{User defined variables} |
| 42094 |
% \localtableofcontents |
| 42095 |
% |
| 42096 |
% \subsubsection{\csh{xintdefvar}, \csh{xintdefiivar}, |
| 42097 |
% \csh{xintdeffloatvar}} |
| 42098 |
% \changed{1.1} |
| 42099 |
% \changed[2017/12/01]{1.2p} Extends |\xintdefvar| et al.\@{} to accept |
| 42100 |
% simultaneous assignments to multiple variables. |
| 42101 |
% \changed[2018/06/17]{1.3c} |
| 42102 |
% Use \csbxint{exprSafeCatcodes} (to palliate issue with |
| 42103 |
% active semi-colon from Babel+French if in body of a \LaTeX{} document). |
| 42104 |
% |
| 42105 |
% And allow usage with both syntaxes |name:=expr;| or |name=expr;|. Also the |
| 42106 |
% colon may have catcode 11, 12, or 13 with no issue. |
| 42107 |
% Variable names may contain letters, digits, underscores, and must not start |
| 42108 |
% with a digit. Names starting with |@| or an underscore are reserved. |
| 42109 |
% |
| 42110 |
% \begin{itemize}[nosep] |
| 42111 |
% \item currently |@|, |@1|, |@2|, |@3|, and |@4| are reserved because they |
| 42112 |
% have special meanings for use in iterations, |
| 42113 |
% \item |@@|, |@@@|, |@@@@| are also reserved but |
| 42114 |
% are technically functions, not variables: a user may possibly define |@@| as |
| 42115 |
% a variable name, but if it is followed by parentheses, the function |
| 42116 |
% interpretation will be applied (rather than the variable interpretation |
| 42117 |
% followed by a tacit multiplication), |
| 42118 |
% \item since |1.2l|, the underscore |_| may be used as separator of digits in |
| 42119 |
% long numbers. |
| 42120 |
% Hence a variable whose name starts with |_| will not play well with the |
| 42121 |
% mechanism of tacit multiplication of variables by numbers: the underscore |
| 42122 |
% will be removed from input stream by the number scanner, thus creating |
| 42123 |
% an undefined or wrong variable name, or none at all if the variable |
| 42124 |
% name was an initial |_| followed by digits. |
| 42125 |
% \end{itemize} |
| 42126 |
% |
| 42127 |
%\begin{lverb} |
| 42128 |
% Note that the optional argument [P] as usable with |
| 42129 |
% \xintfloatexpr is **not** |
| 42130 |
% supported by \xintdeffloatvar. One must do \xintdeffloatvar |
| 42131 |
% foo = \xintfloatexpr[16] blabla \relax; to achieve the effect. |
| 42132 |
%\end{lverb} |
| 42133 |
% |
| 42134 |
% \changed[2020/01/27]{1.4} |
| 42135 |
% The expression will be fetched up to final semi-colon in a manner |
| 42136 |
% allowing inner semi-colons as used in the iter(), rseq(), subsm(), |
| 42137 |
% subsn() etc... syntax. They don't need to be hidden within a |
| 42138 |
% braced pair anymore. |
| 42139 |
% |
| 42140 |
% \changed{1.4} |
| 42141 |
% Automatic unpacking in case of simultaneous assignments if the expression |
| 42142 |
% evaluates to a nutple. |
| 42143 |
% |
| 42144 |
% Notes (added much later on 2021/06/10 during preparation of |1.4i|): |
| 42145 |
% \begin{enumerate} |
| 42146 |
% \item the code did not try to intercept illicit syntax such as |
| 42147 |
% |\xintdefvar a,b,c:=<number>;|. It blindly «unpacked» the number handling it as if |
| 42148 |
% it was a nutple. The extended functionality added at |1.4i| requires to |
| 42149 |
% check for such a situation, as the syntax is not illicit anymore. |
| 42150 |
% \item the code was broken in case the expression to evaluate was an ople of |
| 42151 |
% length 10 or more, due to a silly mistake at some point during |1.4| |
| 42152 |
% development which replaced some |\ifnum| by an |\if|, perhaps due to |
| 42153 |
% mental confusion with the fact that functions can have at most 9 |
| 42154 |
% arguments, but here the code is about defining variables. Anyway this got |
| 42155 |
% fixed as corollary to the |1.4i| extension. |
| 42156 |
% \end{enumerate} |
| 42157 |
% |
| 42158 |
% |
| 42159 |
% \changed[2021/02/20]{1.4c} One year later I realized I had broken tacit |
| 42160 |
% multiplication for situations such as |variable(1+2)|. As hinted at in |
| 42161 |
% comments above before |1.4| release I had been doing some deep refactoring |
| 42162 |
% here, which I cancelled almost completely in the end... but not quite, and |
| 42163 |
% as a result there was a problem that some macro holding braced contents was |
| 42164 |
% expanded to late, once it was in old core routines of xintfrac not expecting |
| 42165 |
% other things than digits. I do an emergency bugfix here with some |
| 42166 |
% |\expandafter|'s but I don't have the code in my brain at this time, and |
| 42167 |
% don't have the luxury now to invest into it. Let's hope this does not induce |
| 42168 |
% breakage elsewhere, and that the February 2020 |1.4| did not break something |
| 42169 |
% else. |
| 42170 |
% |
| 42171 |
% \changed[2021/04/17]{1.4e} |
| 42172 |
%\begin{lverb} |
| 42173 |
% Modifies \xintdeffloatvar to round to the prevailing |
| 42174 |
% precision (formerly, any operation would induce rounding, but in case of |
| 42175 |
% things such as \xintdeffloatvar foo:=\xintexpr 1/100!\relax; there was no |
| 42176 |
% automatic rounding. One could use 0+ syntax to trigger it, and for oples, |
| 42177 |
% some trick like \xintfloatexpr[\XINTdigits]...\relax extra wrapper. |
| 42178 |
%\end{lverb} |
| 42179 |
% \changed[2021/05/22]{1.4g} |
| 42180 |
%\begin{lverb} |
| 42181 |
% The \expandafter\expandafter\expandafter et al. chain |
| 42182 |
% which was kept by \XINT_expr_defvar_one_b for expanding only at time of use |
| 42183 |
% the \XINT_expr_var_foo in \XINT_expr_onliteral_foo were senseless overhead |
| 42184 |
% added at 1.4c. This is used only for real variables, not dummy variables or |
| 42185 |
% fake variables and it is simpler to have the \XINT_expr_var_foo |
| 42186 |
% pre-expanded. So let's use some \edef here. |
| 42187 |
% |
| 42188 |
% The \XINT_expr_onliteral_foo is expanded as result of action of \XINT_expr_op_` |
| 42189 |
% (or \XINT_flexpr_op_`, \XINT_iiexpr_op_`) which itself was triggered consuming |
| 42190 |
% already an \XINT_expr_put_op_first, so its expansion has to produce tokens |
| 42191 |
% as expected after \XINT_expr_put_op_first$empty: |
| 42192 |
% <precedence token><op token>{expanded value}. |
| 42193 |
%\end{lverb} |
| 42194 |
% |
| 42195 |
% \changed[2021/06/10]{1.4i} |
| 42196 |
% Implement extended notion of simultaneous assignments: if there are more |
| 42197 |
% variables than values, define the extra variables to be nil. If there are |
| 42198 |
% less variables than values let the last variable |
| 42199 |
% be defined as the ople concatenating all non reclaimed values. |
| 42200 |
% |
| 42201 |
% If there are at least two variables, the right hand side, if it turns out to |
| 42202 |
% be a nutple, is (as since |1.4|) automatically unpacked, then the above |
| 42203 |
% rules apply. |
| 42204 |
% |
| 42205 |
% \changed[2021/06/11]{1.4i} |
| 42206 |
%\begin{lverb} |
| 42207 |
% Fix the long-standing «seq renaming bug» via a change here of the |
| 42208 |
% name of auxiliary macro. Previously «onliteral_<varname>» now |
| 42209 |
% «var*_<varname>». I hesitated with using «var_varname*» rather. |
| 42210 |
% |
| 42211 |
% Hesitated adding \XINT_expr_letvar_one (motivation: case of simultaneous |
| 42212 |
% assignments leading to defining «nil» variables). Finally, no. |
| 42213 |
%\end{lverb} |
| 42214 |
% |
| 42215 |
% \odef\MakePrivateLetters{\MakePrivateLetters\catcode`* 11 }^^A |
| 42216 |
% \begin{macrocode} |
| 42217 |
\catcode`* 11 |
| 42218 |
\def\XINT_expr_defvar_one #1#2% |
| 42219 |
{% |
| 42220 |
\XINT_global |
| 42221 |
\expandafter\edef\csname XINT_expr_varvalue_#1\endcsname {#2}% |
| 42222 |
\XINT_expr_defvar_one_b {#1}% |
| 42223 |
}% |
| 42224 |
\def\XINT_expr_defvar_one_b #1% |
| 42225 |
{% |
| 42226 |
\XINT_global |
| 42227 |
\expandafter\edef\csname XINT_expr_var_#1\endcsname |
| 42228 |
{{\expandafter\noexpand\csname XINT_expr_varvalue_#1\endcsname}}% |
| 42229 |
\XINT_global |
| 42230 |
\expandafter\edef\csname XINT_expr_var*_#1\endcsname |
| 42231 |
{\XINT_expr_prec_tacit *\csname XINT_expr_var_#1\endcsname(}% |
| 42232 |
\ifxintverbose\xintMessage{xintexpr}{Info}% |
| 42233 |
{Variable #1 \ifxintglobaldefs globally \fi |
| 42234 |
defined with value \csname XINT_expr_varvalue_#1\endcsname.}% |
| 42235 |
\fi |
| 42236 |
}% |
| 42237 |
\catcode`* 12 |
| 42238 |
\catcode`~ 13 |
| 42239 |
\catcode`: 12 |
| 42240 |
\def\XINT_expr_defvar_getname #1:#2~% |
| 42241 |
{% |
| 42242 |
\endgroup |
| 42243 |
\def\XINT_defvar_tmpa{#1}\edef\XINT_defvar_tmpc{\xintCSVLength{#1}}% |
| 42244 |
}% |
| 42245 |
\def\XINT_expr_defvar #1#2% |
| 42246 |
{% |
| 42247 |
\def\XINT_defvar_tmpa{#2}% |
| 42248 |
\expandafter\XINT_expr_defvar_a\expanded{\xint_noxpd{{#1}}\expandafter}% |
| 42249 |
\romannumeral\XINT_expr_fetch_to_semicolon |
| 42250 |
}% |
| 42251 |
\def\XINT_expr_defvar_a #1#2% |
| 42252 |
{% |
| 42253 |
\xintexprRestoreCatcodes |
| 42254 |
% \end{macrocode} |
| 42255 |
% \let\MakePrivateLetters\xintexprMakePrivateLetters |
| 42256 |
%\begin{lverb} |
| 42257 |
% Maybe SafeCatcodes was without effect because the colon and the rest |
| 42258 |
% are from some earlier macro definition. Give a safe definition to active |
| 42259 |
% colon (even if in math mode with a math active colon..). |
| 42260 |
% |
| 42261 |
% The \XINT_expr_defvar_getname closes the group opened here. |
| 42262 |
%\end{lverb} |
| 42263 |
% \begin{macrocode} |
| 42264 |
\begingroup\lccode`~`: \lowercase{\let~}\empty |
| 42265 |
\edef\XINT_defvar_tmpa{\XINT_defvar_tmpa}% |
| 42266 |
\edef\XINT_defvar_tmpa{\xint_zapspaces_o\XINT_defvar_tmpa}% |
| 42267 |
\expandafter\XINT_expr_defvar_getname |
| 42268 |
\detokenize\expandafter{\XINT_defvar_tmpa}:~% |
| 42269 |
\ifcase\XINT_defvar_tmpc\space |
| 42270 |
\xintMessage {xintexpr}{Error} |
| 42271 |
{Aborting: not allowed to declare variable with empty name.}% |
| 42272 |
\or |
| 42273 |
\XINT_global |
| 42274 |
\expandafter |
| 42275 |
\edef\csname XINT_expr_varvalue_\XINT_defvar_tmpa\endcsname{#1#2\relax}% |
| 42276 |
\XINT_expr_defvar_one_b\XINT_defvar_tmpa |
| 42277 |
\else |
| 42278 |
\edef\XINT_defvar_tmpb{#1#2\relax}% |
| 42279 |
\edef\XINT_defvar_tmpd{\expandafter\xintLength\expandafter{\XINT_defvar_tmpb}}% |
| 42280 |
\ifnum\XINT_defvar_tmpd=\xint_c_i |
| 42281 |
\oodef\XINT_defvar_tmpb{\expandafter\xint_firstofone\XINT_defvar_tmpb}% |
| 42282 |
\if0\expandafter\expandafter\expandafter\XINT_defvar_checkifnutple |
| 42283 |
\expandafter\string\XINT_defvar_tmpb _\xint_bye |
| 42284 |
\odef\XINT_defvar_tmpb{\expandafter{\XINT_defvar_tmpb}}% |
| 42285 |
\else |
| 42286 |
\edef\XINT_defvar_tmpd{\expandafter\xintLength\expandafter{\XINT_defvar_tmpb}}% |
| 42287 |
\fi |
| 42288 |
\fi |
| 42289 |
\xintAssignArray\xintCSVtoList\XINT_defvar_tmpa\to\XINT_defvar_tmpvar |
| 42290 |
\def\XINT_defvar_tmpe{1}% |
| 42291 |
\expandafter\XINT_expr_defvar_multiple\XINT_defvar_tmpb\relax |
| 42292 |
\fi |
| 42293 |
}% |
| 42294 |
\def\XINT_defvar_checkifnutple#1% |
| 42295 |
{% |
| 42296 |
\if#1_1\fi |
| 42297 |
\if#1\bgroup1\fi |
| 42298 |
0\xint_bye |
| 42299 |
}% |
| 42300 |
\def\XINT_expr_defvar_multiple |
| 42301 |
{% |
| 42302 |
\ifnum\XINT_defvar_tmpe<\XINT_defvar_tmpc\space |
| 42303 |
\expandafter\XINT_expr_defvar_multiple_one |
| 42304 |
\else |
| 42305 |
\expandafter\XINT_expr_defvar_multiple_last\expandafter\empty |
| 42306 |
\fi |
| 42307 |
}% |
| 42308 |
\def\XINT_expr_defvar_multiple_one |
| 42309 |
{% |
| 42310 |
\ifnum\XINT_defvar_tmpe>\XINT_defvar_tmpd\space |
| 42311 |
\expandafter\XINT_expr_defvar_one |
| 42312 |
\csname XINT_defvar_tmpvar\XINT_defvar_tmpe\endcsname{}% |
| 42313 |
\edef\XINT_defvar_tmpe{\the\numexpr\XINT_defvar_tmpe+1}% |
| 42314 |
\expandafter\XINT_expr_defvar_multiple |
| 42315 |
\else |
| 42316 |
\expandafter\XINT_expr_defvar_multiple_one_a |
| 42317 |
\fi |
| 42318 |
}% |
| 42319 |
\def\XINT_expr_defvar_multiple_one_a #1% |
| 42320 |
{% |
| 42321 |
\expandafter\XINT_expr_defvar_one |
| 42322 |
\csname XINT_defvar_tmpvar\XINT_defvar_tmpe\endcsname{{#1}}% |
| 42323 |
\edef\XINT_defvar_tmpe{\the\numexpr\XINT_defvar_tmpe+1}% |
| 42324 |
\XINT_expr_defvar_multiple |
| 42325 |
}% |
| 42326 |
\def\XINT_expr_defvar_multiple_last #1\relax |
| 42327 |
{% |
| 42328 |
\expandafter\XINT_expr_defvar_one |
| 42329 |
\csname XINT_defvar_tmpvar\XINT_defvar_tmpe\endcsname{#1}% |
| 42330 |
\xintRelaxArray\XINT_defvar_tmpvar |
| 42331 |
\let\XINT_defvar_tmpa\empty |
| 42332 |
\let\XINT_defvar_tmpb\empty |
| 42333 |
\let\XINT_defvar_tmpc\empty |
| 42334 |
\let\XINT_defvar_tmpd\empty |
| 42335 |
\let\XINT_defvar_tmpe\empty |
| 42336 |
}% |
| 42337 |
\catcode`~ 3 |
| 42338 |
\catcode`: 11 |
| 42339 |
% \end{macrocode} |
| 42340 |
%\begin{lverb} |
| 42341 |
% This SafeCatcodes is mainly in the hope that semi-colon ending the |
| 42342 |
% expression can still be sanitized. |
| 42343 |
% |
| 42344 |
% Pre 1.4e definition: |
| 42345 |
%(\def\xintdeffloatvar {\xintexprSafeCatcodes\xintdeffloatvar_a}% |
| 42346 |
%:\def\xintdeffloatvar_a #1={\XINT_expr_defvar\xintthebarefloateval{#1}}% |
| 42347 |
%) |
| 42348 |
% This would keep the value (or values) with extra digits, now. |
| 42349 |
% If this is actually wanted one can use |
| 42350 |
% \xintdefvar foo:=\xintfloatexpr...\relax; |
| 42351 |
% syntax, but recalling that only operations trigger the rounding inside |
| 42352 |
% \xintfloatexpr. Some tricks are needed for no operations case if multiple or |
| 42353 |
% nested values. But for a single one, one can use simply the float() |
| 42354 |
% function. |
| 42355 |
% |
| 42356 |
%\end{lverb} |
| 42357 |
% \begin{macrocode} |
| 42358 |
\def\xintdefvar {\xintexprSafeCatcodes\xintdefvar_a}% |
| 42359 |
\def\xintdefvar_a#1={\XINT_expr_defvar\xintthebareeval{#1}}% |
| 42360 |
\def\xintdefiivar {\xintexprSafeCatcodes\xintdefiivar_a}% |
| 42361 |
\def\xintdefiivar_a#1={\XINT_expr_defvar\xintthebareiieval{#1}}% |
| 42362 |
\def\xintdeffloatvar {\xintexprSafeCatcodes\xintdeffloatvar_a}% |
| 42363 |
\def\xintdeffloatvar_a #1={\XINT_expr_defvar\xintthebareroundedfloateval{#1}}% |
| 42364 |
% \end{macrocode} |
| 42365 |
% \subsubsection{\csh{xintunassignvar}} |
| 42366 |
% \changed{1.2e} |
| 42367 |
% \changed{1.3d} |
| 42368 |
% Embarrassingly I had for a long time a misunderstanding of |\ifcsname| |
| 42369 |
% (let's blame its documentation) and I was not aware that it chooses FALSE |
| 42370 |
% branch if tested control sequence has been |\let| to |\undefined|... So |
| 42371 |
% earlier version didn't do the right thing (and had another bug: failure to |
| 42372 |
% protect |\.=0| from expansion). |
| 42373 |
% |
| 42374 |
% The |\ifcsname| tests are done in \csbXINT{_expr_op__} and |
| 42375 |
% \csbXINT{_expr_op_`}. |
| 42376 |
% |
| 42377 |
% \changed{1.4i} |
| 42378 |
% Track |s/onliteral/var*/| change in macro names. |
| 42379 |
% \begin{macrocode} |
| 42380 |
\def\xintunassignvar #1{% |
| 42381 |
\edef\XINT_unvar_tmpa{#1}% |
| 42382 |
\edef\XINT_unvar_tmpa {\xint_zapspaces_o\XINT_unvar_tmpa}% |
| 42383 |
\ifcsname XINT_expr_var_\XINT_unvar_tmpa\endcsname |
| 42384 |
\ifnum\expandafter\xintLength\expandafter{\XINT_unvar_tmpa}=\@ne |
| 42385 |
\expandafter\xintnewdummy\XINT_unvar_tmpa |
| 42386 |
\else |
| 42387 |
\XINT_global\expandafter |
| 42388 |
\let\csname XINT_expr_varvalue_\XINT_unvar_tmpa\endcsname\xint_undefined |
| 42389 |
\XINT_global\expandafter |
| 42390 |
\let\csname XINT_expr_var_\XINT_unvar_tmpa\endcsname\xint_undefined |
| 42391 |
\XINT_global\expandafter |
| 42392 |
\let\csname XINT_expr_var*_\XINT_unvar_tmpa\endcsname\xint_undefined |
| 42393 |
\ifxintverbose\xintMessage {xintexpr}{Info}% |
| 42394 |
{Variable \XINT_unvar_tmpa\space has been |
| 42395 |
\ifxintglobaldefs globally \fi ``unassigned''.}% |
| 42396 |
\fi |
| 42397 |
\fi |
| 42398 |
\else |
| 42399 |
\xintMessage {xintexpr}{Warning} |
| 42400 |
{Error: there was no such variable \XINT_unvar_tmpa\space to unassign.}% |
| 42401 |
\fi |
| 42402 |
}% |
| 42403 |
% \end{macrocode} |
| 42404 |
% \subsection{Support for dummy variables} |
| 42405 |
% \localtableofcontents |
| 42406 |
% \subsubsection{\csh{xintnewdummy}} |
| 42407 |
%\begin{lverb} |
| 42408 |
% Comments under reconstruction. |
| 42409 |
% |
| 42410 |
% 1.4 adds multi-letter names as usable dummy variables! |
| 42411 |
%\end{lverb} |
| 42412 |
% \changed[2021/06/11]{1.4i} |
| 42413 |
%\begin{lverb} |
| 42414 |
% s/onliteral/var*/ to fix the «seq renaming bug». |
| 42415 |
%\end{lverb} |
| 42416 |
% \begin{macrocode} |
| 42417 |
\catcode`* 11 |
| 42418 |
\def\XINT_expr_makedummy #1% |
| 42419 |
{% |
| 42420 |
\edef\XINT_tmpa{\xint_zapspaces #1 \xint_gobble_i}% |
| 42421 |
\ifcsname XINT_expr_var_\XINT_tmpa\endcsname |
| 42422 |
\XINT_global |
| 42423 |
\expandafter\let\csname XINT_expr_var_\XINT_tmpa/old\expandafter\endcsname |
| 42424 |
\csname XINT_expr_var_\XINT_tmpa\expandafter\endcsname |
| 42425 |
\fi |
| 42426 |
\ifcsname XINT_expr_var*_\XINT_tmpa\endcsname |
| 42427 |
\XINT_global |
| 42428 |
\expandafter\let\csname XINT_expr_var*_\XINT_tmpa/old\expandafter\endcsname |
| 42429 |
\csname XINT_expr_var*_\XINT_tmpa\expandafter\endcsname |
| 42430 |
\fi |
| 42431 |
\expandafter\XINT_global |
| 42432 |
\expanded |
| 42433 |
{\edef\expandafter\noexpand |
| 42434 |
\csname XINT_expr_var_\XINT_tmpa\endcsname ##1\relax !\XINT_tmpa##2}% |
| 42435 |
{{##2}##1\relax !\XINT_tmpa{##2}}% |
| 42436 |
\expandafter\XINT_global |
| 42437 |
\expanded |
| 42438 |
{\edef\expandafter\noexpand |
| 42439 |
\csname XINT_expr_var*_\XINT_tmpa\endcsname ##1\relax !\XINT_tmpa##2}% |
| 42440 |
{\XINT_expr_prec_tacit *{##2}(##1\relax !\XINT_tmpa{##2}}%) |
| 42441 |
}% |
| 42442 |
\xintApplyUnbraced \XINT_expr_makedummy {abcdefghijklmnopqrstuvwxyz}% |
| 42443 |
\xintApplyUnbraced \XINT_expr_makedummy {ABCDEFGHIJKLMNOPQRSTUVWXYZ}% |
| 42444 |
\def\xintnewdummy #1{% |
| 42445 |
\XINT_expr_makedummy{#1}% |
| 42446 |
\ifxintverbose\xintMessage {xintexpr}{Info}% |
| 42447 |
{\XINT_tmpa\space now |
| 42448 |
\ifxintglobaldefs globally \fi usable as dummy variable.}% |
| 42449 |
\fi |
| 42450 |
}% |
| 42451 |
\catcode`* 12 |
| 42452 |
% \end{macrocode} |
| 42453 |
% The |nil| variable was need in |xint < 1.4| (with some other meaning) |
| 42454 |
% in places the syntax could not allow emptiness, such as |,,|, and |
| 42455 |
% other things, but at |1.4| meaning as changed. |
| 42456 |
% |
| 42457 |
% The other variables are new with |1.4|. |
| 42458 |
% Don't use the |None|, it is tentative, and may be input as |[]|. |
| 42459 |
% |
| 42460 |
% Refactored at |1.4i| to define them as really genuine variables, |
| 42461 |
% i.e. also with associated |var*| macros involved in tacit multiplication |
| 42462 |
% (even though it will be broken with |nil|, and with |None| in |\xintiiexpr|). |
| 42463 |
% No real reason, because |\XINT_expr_op__| managed them fine even in absence |
| 42464 |
% of |var*| macros. |
| 42465 |
% \begin{macrocode} |
| 42466 |
\XINT_expr_defvar_one{nil}{}% |
| 42467 |
\XINT_expr_defvar_one{None}{{}}% ? tentative |
| 42468 |
\XINT_expr_defvar_one{false}{{0}}% Maple, TeX |
| 42469 |
\XINT_expr_defvar_one{true}{{1}}% |
| 42470 |
\XINT_expr_defvar_one{False}{{0}}% Python |
| 42471 |
\XINT_expr_defvar_one{True}{{1}}% |
| 42472 |
% \end{macrocode} |
| 42473 |
% \subsubsection{\csh{xintensuredummy}, \csh{xintrestorevariable}} |
| 42474 |
%\begin{lverb} |
| 42475 |
% 1.3e \xintensuredummy differs from \xintnewdummy only in the informational message... |
| 42476 |
% Attention that this is not meant to be nested. |
| 42477 |
% |
| 42478 |
% 1.4 fixes that the message mentioned non-existent \xintrestoredummy (real |
| 42479 |
% name was \xintrestorelettervar and renames the latter to |
| 42480 |
% \xintrestorevariable as it applies also to multi-letter names. |
| 42481 |
%\end{lverb} |
| 42482 |
% \begin{macrocode} |
| 42483 |
\def\xintensuredummy #1{% |
| 42484 |
\XINT_expr_makedummy{#1}% |
| 42485 |
\ifxintverbose\xintMessage {xintexpr}{Info}% |
| 42486 |
{\XINT_tmpa\space now |
| 42487 |
\ifxintglobaldefs globally \fi usable as dummy variable.&&J |
| 42488 |
Issue \string\xintrestorevariable{\XINT_tmpa} to restore former meaning.}% |
| 42489 |
\fi |
| 42490 |
}% |
| 42491 |
\def\xintrestorevariablesilently #1{% |
| 42492 |
\edef\XINT_tmpa{\xint_zapspaces #1 \xint_gobble_i}% |
| 42493 |
\ifcsname XINT_expr_var_\XINT_tmpa/old\endcsname |
| 42494 |
\XINT_global |
| 42495 |
\expandafter\let\csname XINT_expr_var_\XINT_tmpa\expandafter\endcsname |
| 42496 |
\csname XINT_expr_var_\XINT_tmpa/old\expandafter\endcsname |
| 42497 |
\fi |
| 42498 |
\ifcsname XINT_expr_var*_\XINT_tmpa/old\endcsname |
| 42499 |
\XINT_global |
| 42500 |
\expandafter\let\csname XINT_expr_var*_\XINT_tmpa\expandafter\endcsname |
| 42501 |
\csname XINT_expr_var*_\XINT_tmpa/old\expandafter\endcsname |
| 42502 |
\fi |
| 42503 |
}% |
| 42504 |
\def\xintrestorevariable #1{% |
| 42505 |
\xintrestorevariablesilently {#1}% |
| 42506 |
\ifxintverbose\xintMessage {xintexpr}{Info}% |
| 42507 |
{\XINT_tmpa\space |
| 42508 |
\ifxintglobaldefs globally \fi restored to its earlier status, if any.}% |
| 42509 |
\fi |
| 42510 |
}% |
| 42511 |
% \end{macrocode} |
| 42512 |
% \subsubsection{Checking (without expansion) that a symbolic expression |
| 42513 |
% contains correctly nested parentheses} |
| 42514 |
% |
| 42515 |
%\begin{lverb} |
| 42516 |
% Expands to \xint_c_mone in case a closing ) had no opening ( matching |
| 42517 |
% it, to \@ne if opening ( had no closing ) matching it, to \z@ if expression |
| 42518 |
% was balanced. Call it as: |
| 42519 |
% |
| 42520 |
% \XINT_isbalanced_a \relax #1(\xint_bye)\xint_bye |
| 42521 |
% |
| 42522 |
% This is legacy f-expandable code not using \expanded even at 1.4. |
| 42523 |
%\end{lverb} |
| 42524 |
% \begin{macrocode} |
| 42525 |
\def\XINT_isbalanced_a #1({\XINT_isbalanced_b #1)\xint_bye }% |
| 42526 |
\def\XINT_isbalanced_b #1)#2% |
| 42527 |
{\xint_bye #2\XINT_isbalanced_c\xint_bye\XINT_isbalanced_error }% |
| 42528 |
% \end{macrocode} |
| 42529 |
%\begin{lverb} |
| 42530 |
% if #2 is not \xint_bye, a ) was found, but there was no (. Hence error -> -1 |
| 42531 |
%\end{lverb} |
| 42532 |
% \begin{macrocode} |
| 42533 |
\def\XINT_isbalanced_error #1)\xint_bye {\xint_c_mone}% |
| 42534 |
% \end{macrocode} |
| 42535 |
%\begin{lverb} |
| 42536 |
% #2 was \xint_bye, was there a ) in original #1? |
| 42537 |
%\end{lverb} |
| 42538 |
% \begin{macrocode} |
| 42539 |
\def\XINT_isbalanced_c\xint_bye\XINT_isbalanced_error #1% |
| 42540 |
{\xint_bye #1\XINT_isbalanced_yes\xint_bye\XINT_isbalanced_d #1}% |
| 42541 |
% \end{macrocode} |
| 42542 |
%\begin{lverb} |
| 42543 |
% #1 is \xint_bye, there was never ( nor ) in original #1, hence OK. |
| 42544 |
%\end{lverb} |
| 42545 |
% \begin{macrocode} |
| 42546 |
\def\XINT_isbalanced_yes\xint_bye\XINT_isbalanced_d\xint_bye )\xint_bye {\xint_c_ }% |
| 42547 |
% \end{macrocode} |
| 42548 |
%\begin{lverb} |
| 42549 |
% #1 is not \xint_bye, there was indeed a ( in original #1. We check if |
| 42550 |
% we see a ). If we do, we then loop until no ( nor ) is to be found. |
| 42551 |
%\end{lverb} |
| 42552 |
% \begin{macrocode} |
| 42553 |
\def\XINT_isbalanced_d #1)#2% |
| 42554 |
{\xint_bye #2\XINT_isbalanced_no\xint_bye\XINT_isbalanced_a #1#2}% |
| 42555 |
% \end{macrocode} |
| 42556 |
%\begin{lverb} |
| 42557 |
% #2 was \xint_bye, we did not find a closing ) in original #1. Error. |
| 42558 |
%\end{lverb} |
| 42559 |
% \begin{macrocode} |
| 42560 |
\def\XINT_isbalanced_no\xint_bye #1\xint_bye\xint_bye {\xint_c_i }% |
| 42561 |
% \end{macrocode} |
| 42562 |
% \subsubsection{Fetching balanced expressions E1, E2 and a variable name Name from E1, Name=E2)} |
| 42563 |
% |
| 42564 |
% Multi-letter dummy variables added at |1.4|. |
| 42565 |
% \begin{macrocode} |
| 42566 |
\def\XINT_expr_fetch_E_comma_V_equal_E_a #1#2,% |
| 42567 |
{% |
| 42568 |
\ifcase\XINT_isbalanced_a \relax #1#2(\xint_bye)\xint_bye |
| 42569 |
\expandafter\XINT_expr_fetch_E_comma_V_equal_E_c |
| 42570 |
\or\expandafter\XINT_expr_fetch_E_comma_V_equal_E_b |
| 42571 |
\else\expandafter\xintError:noopening |
| 42572 |
\fi {#1#2},% |
| 42573 |
}% |
| 42574 |
\def\XINT_expr_fetch_E_comma_V_equal_E_b #1,% |
| 42575 |
{\XINT_expr_fetch_E_comma_V_equal_E_a {#1,}}% |
| 42576 |
\def\XINT_expr_fetch_E_comma_V_equal_E_c #1,#2#3=% |
| 42577 |
{% |
| 42578 |
\expandafter\XINT_expr_fetch_E_comma_V_equal_E_d\expandafter |
| 42579 |
{\expanded{{\xint_zapspaces #2#3 \xint_gobble_i}}{#1}}{}% |
| 42580 |
}% |
| 42581 |
\def\XINT_expr_fetch_E_comma_V_equal_E_d #1#2#3)% |
| 42582 |
{% |
| 42583 |
\ifcase\XINT_isbalanced_a \relax #2#3(\xint_bye)\xint_bye |
| 42584 |
\or\expandafter\XINT_expr_fetch_E_comma_V_equal_E_e |
| 42585 |
\else\expandafter\xintError:noopening |
| 42586 |
\fi |
| 42587 |
{#1}{#2#3}% |
| 42588 |
}% |
| 42589 |
\def\XINT_expr_fetch_E_comma_V_equal_E_e #1#2% |
| 42590 |
{\XINT_expr_fetch_E_comma_V_equal_E_d {#1}{#2)}}% |
| 42591 |
% \end{macrocode} |
| 42592 |
% \subsubsection{Fetching a balanced expression delimited by a semi-colon} |
| 42593 |
% |
| 42594 |
%\begin{lverb} |
| 42595 |
% 1.4. For subsn() leaner syntax of nested substitutions. |
| 42596 |
% |
| 42597 |
% Will also serve to \xintdeffunc, to not have to hide inner semi-colons in |
| 42598 |
% for example an iter() from \xintdeffunc. |
| 42599 |
% |
| 42600 |
% Adding brace removal protection for no serious reason, anyhow the xintexpr |
| 42601 |
% parsers always removes braces when moving forward, but well. |
| 42602 |
% |
| 42603 |
% Trigger by \romannumeral\XINT_expr_fetch_to_semicolon upfront. |
| 42604 |
%\end{lverb} |
| 42605 |
% |
| 42606 |
% \begin{macrocode} |
| 42607 |
\def\XINT_expr_fetch_to_semicolon {\XINT_expr_fetch_to_semicolon_a {}\empty}% |
| 42608 |
\def\XINT_expr_fetch_to_semicolon_a #1#2;% |
| 42609 |
{% |
| 42610 |
\ifcase\XINT_isbalanced_a \relax #1#2(\xint_bye)\xint_bye |
| 42611 |
\xint_dothis{\expandafter\XINT_expr_fetch_to_semicolon_c}% |
| 42612 |
\or\xint_dothis{\expandafter\XINT_expr_fetch_to_semicolon_b}% |
| 42613 |
\else\expandafter\xintError:noopening |
| 42614 |
\fi\xint_orthat{}\expandafter{#2}{#1}% |
| 42615 |
}% |
| 42616 |
\def\XINT_expr_fetch_to_semicolon_b #1#2{\XINT_expr_fetch_to_semicolon_a {#2#1;}\empty}% |
| 42617 |
\def\XINT_expr_fetch_to_semicolon_c #1#2{\xint_c_{#2#1}}% |
| 42618 |
% \end{macrocode} |
| 42619 |
% \subsubsection{Low-level support for omit and abort keywords, the break() |
| 42620 |
% function, the n++ construct and the semi-colon as used in the syntax of |
| 42621 |
% seq(), add(), mul(), iter(), rseq(), iterr(), rrseq(), subsm(), subsn(), ndseq(), |
| 42622 |
% ndmap()} |
| 42623 |
%\begin{lverb} |
| 42624 |
% There is some clever play simply based on setting suitable precedence |
| 42625 |
% levels combined with special meanings given to op macros. |
| 42626 |
% |
| 42627 |
% The special !? internal operator is a helper for omit and abort keywords in |
| 42628 |
% list generators. |
| 42629 |
% |
| 42630 |
% Prior to 1.4 support for +[, *[, ..., ]+, ]*, had some elements here. |
| 42631 |
%\end{lverb} |
| 42632 |
% \paragraph{The n++ construct} |
| 42633 |
%\begin{lverb} |
| 42634 |
% 1.1 2014/10/29 did \expandafter\.=+\xintiCeil which transformed it into |
| 42635 |
% \romannumeral0\xinticeil, which seems a bit weird. This exploited the fact |
| 42636 |
% that dummy variables macros could back then pick braced material (which in the |
| 42637 |
% case at hand here ended being {\romannumeral0\xinticeil...} and were submitted |
| 42638 |
% to two expansions. The result of this was to provide a not value which got |
| 42639 |
% expanded only in the first loop of the :_A and following macros of seq, |
| 42640 |
% iter, rseq, etc... |
| 42641 |
% |
| 42642 |
% Anyhow with 1.2c I have changed the implementation of dummy variables which |
| 42643 |
% now need to fetch a single locked token, which they do not expand. |
| 42644 |
% |
| 42645 |
% The \xintiCeil appears a bit dispendious, but I need the starting value in a |
| 42646 |
% \numexpr compatible form in the iteration loops. |
| 42647 |
%\end{lverb} |
| 42648 |
% \begin{macrocode} |
| 42649 |
\expandafter\def\csname XINT_expr_itself_++\endcsname {++}% |
| 42650 |
\expandafter\def\csname XINT_expr_itself_++)\endcsname {++)}% |
| 42651 |
\expandafter\let\csname XINT_expr_precedence_++)\endcsname \xint_c_i |
| 42652 |
\xintFor #1 in {expr,flexpr,iiexpr} \do {% |
| 42653 |
\expandafter\def\csname XINT_#1_op_++)\endcsname ##1##2\relax |
| 42654 |
{\expandafter\XINT_expr_foundend |
| 42655 |
\expanded{{+{\XINT:NEhook:f:one:from:one:direct\xintiCeil##1}}}% |
| 42656 |
}% |
| 42657 |
}% |
| 42658 |
% \end{macrocode} |
| 42659 |
% \paragraph{The \cshn{break()} function} |
| 42660 |
%\begin{lverb} |
| 42661 |
% break is a true function, the parsing via expansion of the enclosed |
| 42662 |
% material proceeds via _oparen macros as with any other function. |
| 42663 |
%\end{lverb} |
| 42664 |
% \begin{macrocode} |
| 42665 |
\catcode`? 3 |
| 42666 |
\def\XINT_expr_func_break #1#2#3{#1#2{?#3}}% |
| 42667 |
\catcode`? 11 |
| 42668 |
\let\XINT_flexpr_func_break \XINT_expr_func_break |
| 42669 |
\let\XINT_iiexpr_func_break \XINT_expr_func_break |
| 42670 |
% \end{macrocode} |
| 42671 |
% \paragraph{The \cshn{omit} and \cshn{abort} keywords} |
| 42672 |
%\begin{lverb} |
| 42673 |
% Comments are currently undergoing reconstruction. |
| 42674 |
% |
| 42675 |
% The mechanism is somewhat complex. The operator !? will fetch a dummy value |
| 42676 |
% ! or ^ which is then recognized int the loops implementing the various seq |
| 42677 |
% etc... construct using dummy variables and implement omit and abort. |
| 42678 |
% |
| 42679 |
% In May 2021 I realized that the January 2020 1.4 had broken omit and abort |
| 42680 |
% if used inside a subs(). The definition |
| 42681 |
%(\edef\XINT_expr_var_omit #1\relax !{1\string !?!\relax !}% |
| 42682 |
%) |
| 42683 |
% conflicted with the 1.4 refactoring of «subs» and similar things |
| 42684 |
% which had replaced formerly clean-up macros (of ! and what's next, as in |
| 42685 |
% now defunct |
| 42686 |
% \def\XINT_expr_subx:_end #1!#2#3{#1} which was involved in subs mechanism, |
| 42687 |
% and by the way would be incompatible with multi-letter dummy variables) by usage |
| 42688 |
% of an \iffalse as in "\relax\iffalse\relax !" to delimite a sub-expression, which was |
| 42689 |
% supposed to be clever (the "\relax !" being delimiter for dummy variables). |
| 42690 |
% |
| 42691 |
% This \iffalse from subs mechanism ended up being gobbled by omit/abort thus |
| 42692 |
% inducing breakage. |
| 42693 |
% |
| 42694 |
% Grabbing \relax #2! would be a fix but looks a bit dangerous, as there can |
| 42695 |
% be a subexpression after the omit or abort bringing its own \relax, although |
| 42696 |
% this is very very unlikely. |
| 42697 |
% |
| 42698 |
% I considered to modify the dummy variables delimiter from \relax ! to |
| 42699 |
% \xint_Bye ! for example but got afraid from the ramifications, as all |
| 42700 |
% structures handling dummy variables would have needed refactoring. |
| 42701 |
% |
| 42702 |
% So finally things here remain unchanged and the refactoring to fix this |
| 42703 |
% breakage was done in \XINT_allexpr_subsx (and also subsm). |
| 42704 |
% Done at 1.4h. See \XINT_allexpr_subsx for comments. |
| 42705 |
%\end{lverb} |
| 42706 |
% |
| 42707 |
% \begin{macrocode} |
| 42708 |
\edef\XINT_expr_var_omit #1\relax !{1\string !?!\relax !}% |
| 42709 |
\edef\XINT_expr_var_abort #1\relax !{1\string !?^\relax !}% |
| 42710 |
\def\XINT_expr_itself_!? {!?}% |
| 42711 |
\def\XINT_expr_op_!? #1#2\relax{\XINT_expr_foundend{#2}}% |
| 42712 |
\let\XINT_iiexpr_op_!? \XINT_expr_op_!? |
| 42713 |
\let\XINT_flexpr_op_!? \XINT_expr_op_!? |
| 42714 |
\let\XINT_expr_precedence_!? \xint_c_iv |
| 42715 |
% \end{macrocode} |
| 42716 |
% \paragraph{The semi-colon} |
| 42717 |
% |
| 42718 |
%\begin{lverb} |
| 42719 |
% Obsolete comments undergoing re-construction |
| 42720 |
%\end{lverb} |
| 42721 |
% |
| 42722 |
% \begin{macrocode} |
| 42723 |
\xintFor #1 in {expr,flexpr,iiexpr} \do {% |
| 42724 |
\expandafter\def\csname XINT_#1_op_;\endcsname {\xint_c_i ;}% |
| 42725 |
}% |
| 42726 |
\expandafter\let\csname XINT_expr_precedence_;\endcsname\xint_c_i |
| 42727 |
\expandafter\def\csname XINT_expr_itself_;)\endcsname {)}% |
| 42728 |
\expandafter\let\csname XINT_expr_precedence_;)\endcsname\xint_c_i |
| 42729 |
% \end{macrocode} |
| 42730 |
% \subsubsection{Reserved dummy variables @, @1, @2, @3, @4, @@, @@(1), \dots, @@@, |
| 42731 |
% @@@(1), \dots{} for recursions} |
| 42732 |
%\begin{lverb} |
| 42733 |
% Comments currently under reconstruction. |
| 42734 |
% |
| 42735 |
% 1.4 breaking change: @ and @1 behave differently and one can not use @ in |
| 42736 |
% place of @1 in iterr() and rrseq(). Formerly @ and @1 had the same |
| 42737 |
% definition. |
| 42738 |
% |
| 42739 |
% Brace stripping in \XINT_expr_func_@@ |
| 42740 |
% is prevented by some ending 0 or other token see iterr() and rrseq() code. |
| 42741 |
% |
| 42742 |
% For the record, the ~ and ? have catcode 3 in this code. |
| 42743 |
% |
| 42744 |
%\end{lverb} |
| 42745 |
% |
| 42746 |
% \odef\MakePrivateLetters{\MakePrivateLetters\catcode`* 11 }^^A |
| 42747 |
% \begin{macrocode} |
| 42748 |
\catcode`* 11 |
| 42749 |
\def\XINT_expr_var_@ #1~#2{{#2}#1~{#2}}% |
| 42750 |
\def\XINT_expr_var*_@ #1~#2{\XINT_expr_prec_tacit *{#2}(#1~{#2}}% |
| 42751 |
\expandafter |
| 42752 |
\def\csname XINT_expr_var_@1\endcsname #1~#2{{{#2}}#1~{#2}}% |
| 42753 |
\expandafter |
| 42754 |
\def\csname XINT_expr_var_@2\endcsname #1~#2#3{{{#3}}#1~{#2}{#3}}% |
| 42755 |
\expandafter |
| 42756 |
\def\csname XINT_expr_var_@3\endcsname #1~#2#3#4{{{#4}}#1~{#2}{#3}{#4}}% |
| 42757 |
\expandafter |
| 42758 |
\def\csname XINT_expr_var_@4\endcsname #1~#2#3#4#5{{{#5}}#1~{#2}{#3}{#4}{#5}}% |
| 42759 |
\expandafter\def\csname XINT_expr_var*_@1\endcsname #1~#2% |
| 42760 |
{\XINT_expr_prec_tacit *{{#2}}(#1~{#2}}% |
| 42761 |
\expandafter\def\csname XINT_expr_var*_@2\endcsname #1~#2#3% |
| 42762 |
{\XINT_expr_prec_tacit *{{#3}}(#1~{#2}{#3}}% |
| 42763 |
\expandafter\def\csname XINT_expr_var*_@3\endcsname #1~#2#3#4% |
| 42764 |
{\XINT_expr_prec_tacit *{{#4}}(#1~{#2}{#3}{#4}}% |
| 42765 |
\expandafter\def\csname XINT_expr_var*_@4\endcsname #1~#2#3#4#5% |
| 42766 |
{\XINT_expr_prec_tacit *{{#5}}(#1~{#2}{#3}{#4}{#5}}% |
| 42767 |
\catcode`* 12 |
| 42768 |
% \end{macrocode} |
| 42769 |
% \let\MakePrivateLetters\xintexprMakePrivateLetters\FixInterMacrocodeVspace |
| 42770 |
% \begin{macrocode} |
| 42771 |
\catcode`? 3 |
| 42772 |
\def\XINT_expr_func_@@ #1#2#3#4~#5?% |
| 42773 |
{% |
| 42774 |
\expandafter#1\expandafter#2\expandafter{\expandafter{% |
| 42775 |
\romannumeral0\xintntheltnoexpand{\xintNum#3}{#5}}}#4~#5?% |
| 42776 |
}% |
| 42777 |
\def\XINT_expr_func_@@@ #1#2#3#4~#5~#6?% |
| 42778 |
{% |
| 42779 |
\expandafter#1\expandafter#2\expandafter{\expandafter{% |
| 42780 |
\romannumeral0\xintntheltnoexpand{\xintNum#3}{#6}}}#4~#5~#6?% |
| 42781 |
}% |
| 42782 |
\def\XINT_expr_func_@@@@ #1#2#3#4~#5~#6~#7?% |
| 42783 |
{% |
| 42784 |
\expandafter#1\expandafter#2\expandafter{\expandafter{% |
| 42785 |
\romannumeral0\xintntheltnoexpand{\xintNum#3}{#7}}}#4~#5~#6~#7?% |
| 42786 |
}% |
| 42787 |
\let\XINT_flexpr_func_@@\XINT_expr_func_@@ |
| 42788 |
\let\XINT_flexpr_func_@@@\XINT_expr_func_@@@ |
| 42789 |
\let\XINT_flexpr_func_@@@@\XINT_expr_func_@@@@ |
| 42790 |
\def\XINT_iiexpr_func_@@ #1#2#3#4~#5?% |
| 42791 |
{% |
| 42792 |
\expandafter#1\expandafter#2\expandafter{\expandafter{% |
| 42793 |
\romannumeral0\xintntheltnoexpand{\xint_firstofone#3}{#5}}}#4~#5?% |
| 42794 |
}% |
| 42795 |
\def\XINT_iiexpr_func_@@@ #1#2#3#4~#5~#6?% |
| 42796 |
{% |
| 42797 |
\expandafter#1\expandafter#2\expandafter{\expandafter{% |
| 42798 |
\romannumeral0\xintntheltnoexpand{\xint_firstofone#3}{#6}}}#4~#5~#6?% |
| 42799 |
}% |
| 42800 |
\def\XINT_iiexpr_func_@@@@ #1#2#3#4~#5~#6~#7?% |
| 42801 |
{% |
| 42802 |
\expandafter#1\expandafter#2\expandafter{\expandafter{% |
| 42803 |
\romannumeral0\xintntheltnoexpand{\xint_firstofone#3}{#7}}}#4~#5~#6~#7?% |
| 42804 |
}% |
| 42805 |
\catcode`? 11 |
| 42806 |
% \end{macrocode} |
| 42807 |
% \subsection{Pseudo-functions involving dummy variables and generating scalars or sequences} |
| 42808 |
% \localtableofcontents |
| 42809 |
% |
| 42810 |
% \subsubsection{Comments} |
| 42811 |
%\begin{lverb} |
| 42812 |
% Comments added 2020/01/16. |
| 42813 |
% |
| 42814 |
% The mechanism for «seq» is the following. When the parser encounters «seq», |
| 42815 |
% which means it parsed these letters and encountered (from expansion) an |
| 42816 |
% opening parenthesis, the \XINT_expr_func mechanism triggers the «`» operator |
| 42817 |
% which realizes that «seq» is a pseudo-function (there is no _func_seq) and |
| 42818 |
% thus spans the \XINT_expr_onliteral_seq macro (currently this means however |
| 42819 |
% that the knowledge of which parser we are in is lost, see comments of |
| 42820 |
% \XINT_expr_op_` code). The latter will use delimited macros and parenthesis |
| 42821 |
% check to fetch (without any expansion), the symbolic expression ExprSeq to |
| 42822 |
% evaluate, the Name (now possibly multi-letter) of the variable and the |
| 42823 |
% expression ExprValues to evaluate which will give the values to assign to |
| 42824 |
% the dummy variable Name. It then positions upstream ExprValues suitably |
| 42825 |
% terminated (see next) and after it {{Name}{ExprSeq}}. Then it inserts a |
| 42826 |
% second call to the «`» operator with now «seqx» as argument hence |
| 42827 |
% the appropriate «{,fl,ii}expr_func_seqx» macros gets executed. The general |
| 42828 |
% way function macros work is that first all their arguments are evaluated via |
| 42829 |
% a call not to \xintbare{,float,ii}eval but to the suitable |
| 42830 |
% \XINT_{expr,flexpr,iiexpr}_oparen core macro which does almost same excepts |
| 42831 |
% it expects a final closing parenthesis (of course allowing nested |
| 42832 |
% parenthesis in-between) and stops there. Here, this closing parenthesis got positioned |
| 42833 |
% deliberately with a \relax after it, so the parser, which always after |
| 42834 |
% having gathered a value looks ahead to find the next operator, thinks it has |
| 42835 |
% hit the end of the expression and as result inserts a \xint_c_ (i.e. \z@) |
| 42836 |
% token for precedence level and a dummy \relax token (place-holder for a |
| 42837 |
% non-existing operator). Generally speaking «func_foo» macros expect to |
| 42838 |
% be executed with three parameters #1#2#3, #1 = precedence, #2 = operator, #3 |
| 42839 |
% = values (call it «args») i.e. the fully evaluated list of all its |
| 42840 |
% arguments. The special «func_seqx» and cousins know that the first two |
| 42841 |
% tokens are trash and they now proceed forward, having thus lying before them |
| 42842 |
% upstream the values to loop over, now fully evaluated, and |
| 42843 |
% {{Name}{ExprSeq}}. It then positions appropriately ExprSeq inside a |
| 42844 |
% sub-expression and after it, following suitable delimiter, Name and the |
| 42845 |
% evaluated values to assign to Name. |
| 42846 |
% |
| 42847 |
% Dummy variables are essentially simply delimited macros where the delimiter |
| 42848 |
% is the variable name preceded by a \relax token and a catcode 11 exclamation |
| 42849 |
% point. Thus the various «subsx», «seqx», «iterx» position the tokens |
| 42850 |
% appropriately and launch suitable loops. |
| 42851 |
% |
| 42852 |
% All of this nests well, inner «seq»'s (or more often in practice «subs»'s) |
| 42853 |
% being allowed to refer to the dummy variables used by outer «seq»'s because |
| 42854 |
% the outer «seq»'s have the values to assign to their variables evaluated |
| 42855 |
% first and their ExprSeq evaluated last. For inner dummy variables to be able |
| 42856 |
% to refer to outer dummy variables the author must be careful of course to |
| 42857 |
% not use in the implementation braces { and } which would break dummy |
| 42858 |
% variables to fetch values beyond the closing brace. |
| 42859 |
% |
| 42860 |
% The above «seq» mechanism was done around June 15-25th 2014 at the time of |
| 42861 |
% the transition from 1.09n to 1.1 but already in October 2014 I made a note |
| 42862 |
% that I had a hard time to understand it again: |
| 42863 |
% |
| 42864 |
% « [START OF YEAR 2014 COMMENTS] |
| 42865 |
% |
| 42866 |
% All of seq, add, mul, rseq, etc... (actually all of the extensive |
| 42867 |
% changes from xintexpr 1.09n to 1.1) was done around June 15-25th 2014, but the |
| 42868 |
% problem is that I did not document the code enough, and I had a hard time |
| 42869 |
% understanding in October what I had done in June. Despite the lesson, again |
| 42870 |
% being short on time, I do not document enough my current understanding of the |
| 42871 |
% innards of the beast... |
| 42872 |
% |
| 42873 |
% I added subs, and iter in October (also the [:n], [n:] list extractors), |
| 42874 |
% proving I did at least understand a bit (or rather could imitate) my earlier |
| 42875 |
% code (but don't ask me to explain \xintNewExpr !) |
| 42876 |
% |
| 42877 |
% The \XINT_expr_fetch_E_comma_V_equal_E_a parses: "expression, variable=list)" |
| 42878 |
% (when it is called the opening ( has been swallowed, and it looks for |
| 42879 |
% the ending one.) Both expression and list may themselves contain |
| 42880 |
% parentheses and commas, we allow nesting. For example "x^2,x=1..10)", |
| 42881 |
% at the end of seq_a we have {variable{expression}}{list}, in this |
| 42882 |
% example {x{x^2}}{1..10}, or more complicated |
| 42883 |
% "seq(add(y,y=1..x),x=1..10)" will work too. The variable is a single |
| 42884 |
% lowercase Latin letter. |
| 42885 |
% |
| 42886 |
% The complications with \xint_c_ii^v in seq_f is for the recurrent |
| 42887 |
% thing that we don't know in what type of expressions we are, hence we |
| 42888 |
% must move back up, with some loss of efficiency (superfluous check for |
| 42889 |
% minus sign, etc...). But the code manages simultaneously expr, flexpr |
| 42890 |
% and iiexpr. |
| 42891 |
% |
| 42892 |
% [END OF YEAR 2014 OLD COMMENTS]» |
| 42893 |
% |
| 42894 |
% On Jeudi 16 janvier 2020 à 15:13:32 I finally did the documentation as |
| 42895 |
% above. |
| 42896 |
% |
| 42897 |
% The case of «iter», «rseq», «iterr», «rrseq» differs slightly because the |
| 42898 |
% initial values need evaluation. This is done by genuine functions |
| 42899 |
% \XINT_<parser>_func_iter etc... (there was no \XINT_<parser>_func_seq). The |
| 42900 |
% trick is via the semi-colon ; which is a genuine operator having the |
| 42901 |
% precedence of a closing parenthesis and whose action is only to stop |
| 42902 |
% expansion. Thus this first step of gathering the initial values is done as |
| 42903 |
% part of the reguler expansion job of the parser not using delimited macros |
| 42904 |
% and the ; can be hidden in braces {;} because the three parsers when moving |
| 42905 |
% forward remove one level of braces always. Thus |
| 42906 |
% \XINT_<parser>_func_seq simply hand over to \XINT_allexpr_iter which will |
| 42907 |
% then trigger the fetching without expansion of ExprIter, Name=ExprValues as |
| 42908 |
% described previously for «seq». |
| 42909 |
% |
| 42910 |
% With 1.4, multi-letter names for dummy variables are allowed. |
| 42911 |
% |
| 42912 |
% Also there is the additional 1.4 ambition to make the whole thing parsable |
| 42913 |
% by \xintNewExpr/\xintdeffunc. This is done by checking if all is numerical, |
| 42914 |
% because the omit, abort and break() mechanisms have no translation into |
| 42915 |
% macros, and the only solution for symbolic material is to simply keep it as |
| 42916 |
% is, so that expansion will again activate the xintexpr parsers. At 1.4 this |
| 42917 |
% approach is fine although the initial goals of \xintNewExpr/\xintdeffunc was |
| 42918 |
% to completely replace the parsers (whose storage method hit the string pool |
| 42919 |
% formerly) by macros. Now that 1.4 does not impact the string pool we can |
| 42920 |
% make \xintdeffunc much more powerful but it will not be a construct using |
| 42921 |
% only xintfrac macros, it will still be partially the \xintexpr etc... |
| 42922 |
% parsers in such cases. |
| 42923 |
%\end{lverb} |
| 42924 |
% |
| 42925 |
%\begin{lverb} |
| 42926 |
% Got simpler with 1.2c as now the dummy variable fetches an |
| 42927 |
% already encapsulated value, which is anyhow the form in which we get |
| 42928 |
% it. |
| 42929 |
% |
| 42930 |
% Refactored at 1.4 using \expanded rather than \csname. |
| 42931 |
% |
| 42932 |
% And support for multi-letter variables, which means function declarations |
| 42933 |
% can now use multi-letter variables ! |
| 42934 |
%\end{lverb} |
| 42935 |
% \subsubsection{\cshn{subs()}: substitution of one variable} |
| 42936 |
% \begin{macrocode} |
| 42937 |
\def\XINT_expr_onliteral_subs |
| 42938 |
{% |
| 42939 |
\expandafter\XINT_allexpr_subs_f |
| 42940 |
\romannumeral`&&@\XINT_expr_fetch_E_comma_V_equal_E_a {}% |
| 42941 |
}% |
| 42942 |
\def\XINT_allexpr_subs_f #1#2{\xint_c_ii^v `{subsx}#2)\relax #1}% |
| 42943 |
\def\XINT_expr_func_subsx #1#2{\XINT_allexpr_subsx \xintbareeval }% |
| 42944 |
\def\XINT_flexpr_func_subsx #1#2{\XINT_allexpr_subsx \xintbarefloateval}% |
| 42945 |
\def\XINT_iiexpr_func_subsx #1#2{\XINT_allexpr_subsx \xintbareiieval }% |
| 42946 |
% \end{macrocode} |
| 42947 |
%\begin{lverb} |
| 42948 |
% #2 is the value to assign to the dummy variable |
| 42949 |
% #3 is the dummy variable name (possibly multi-letter), #4 is the expression |
| 42950 |
% to evaluate |
| 42951 |
% |
| 42952 |
% 1.4 was doing something clever to get rid of the ! and tokens following it, |
| 42953 |
% via an \iffalse...\fi which erased them and propagated the expansion to |
| 42954 |
% trigger the getopt: |
| 42955 |
% |
| 42956 |
%(\expanded\bgroup\romannumeral0#1#4\relax \iffalse\relax !#3{#2}{\fi\expandafter} |
| 42957 |
%) |
| 42958 |
% |
| 42959 |
% But sadly, with a delay of more than one year later (right after having |
| 42960 |
% released 1.4g) I realized that this had broken omit and abort if inside a |
| 42961 |
% subs. As omit and abort would clean all up to \relax !, this meant here |
| 42962 |
% swallowing in particular the above \iffalse, leaving a dangling \fi. I had |
| 42963 |
% the files which show this bug already at time of 1.4 release but did not |
| 42964 |
% compile them, and they were not included in my test suite. |
| 42965 |
% |
| 42966 |
% I hesitated with modifying the delimiter from "\relax !<varname>" (catcode |
| 42967 |
% 11 !) to "\relax \xint_Bye<varname>" for the dummy variables which would |
| 42968 |
% have allowed some trickery using \xint_Bye...\xint_bye clean-up but got |
| 42969 |
% afraid from the breakage potential of such refactoring with many induced |
| 42970 |
% changes. |
| 42971 |
% |
| 42972 |
% A variant like this: |
| 42973 |
%( \def\XINT_allexpr_subsx #1#2#3#4% |
| 42974 |
%: {% |
| 42975 |
%: \expandafter\XINT_expr_clean_and_put_op_first |
| 42976 |
%: \expanded |
| 42977 |
%: {\romannumeral0#1#4\relax !#3{#2}\xint:\expandafter}\romannumeral`$&$&\XINT_expr_getop |
| 42978 |
%: }% |
| 42979 |
%: \def\XINT_expr_clean_and_put_op_first #1#2\xint:#3#4{#3#4{#1}}% |
| 42980 |
%) |
| 42981 |
% breaks nesting: the braces make variables encountered in #4 unable to |
| 42982 |
% match their definition. This would work: |
| 42983 |
% |
| 42984 |
%( \def\XINT_allexpr_subsx #1#2#3#4% |
| 42985 |
%: {% |
| 42986 |
%: \expandafter\XINT_allexpr_subsx_clean\romannumeral0#1#4\relax !#3{#2}\xint: |
| 42987 |
%: }% |
| 42988 |
%: \def\XINT_allexpr_subsx_clean #1#2\xint: |
| 42989 |
%: {% |
| 42990 |
%: \expandafter\XINT_expr_put_op_first |
| 42991 |
%: \expanded{\xint_noxpd{{#1}}\expandafter}\romannumeral`$&$&@\XINT_expr_getop |
| 42992 |
%: }% |
| 42993 |
%) |
| 42994 |
% (not tested). |
| 42995 |
% |
| 42996 |
% But in the end I decided to simply fix the first envisioned code above. |
| 42997 |
% This accepts expansion of supposedly inert #3{#2}. There is again the |
| 42998 |
% \iffalse but it is moved to the right. This change limits possibly hacky |
| 42999 |
% future developments. Done at 1.4h (2021/01/27). |
| 43000 |
% |
| 43001 |
% No need for the \expandafter's from \XINT_expr_put_op_first in |
| 43002 |
% \XINT_expr_clean_and_put_op_first. |
| 43003 |
%\end{lverb} |
| 43004 |
% \begin{macrocode} |
| 43005 |
\def\XINT_allexpr_subsx #1#2#3#4% |
| 43006 |
{% |
| 43007 |
\expandafter\XINT_expr_clean_and_put_op_first |
| 43008 |
\expanded |
| 43009 |
\bgroup\romannumeral0#1#4\relax !#3{#2}\xint:\iffalse{\fi\expandafter}% |
| 43010 |
\romannumeral`&&@\XINT_expr_getop |
| 43011 |
}% |
| 43012 |
\def\XINT_expr_clean_and_put_op_first #1#2\xint:#3#4{#3#4{#1}}% |
| 43013 |
% \end{macrocode} |
| 43014 |
% \subsubsection{\cshn{subsm()}: simultaneous independent substitutions} |
| 43015 |
%\begin{lverb} |
| 43016 |
% New with 1.4. Globally the var1=expr1; var2=expr2; var2=expr3;... |
| 43017 |
% part can arise from expansion, except that once a semi-colon has been found |
| 43018 |
% (from expansion) the varK= thing following it must be there. And as for |
| 43019 |
% subs() the final parenthesis must be there from the start. |
| 43020 |
% |
| 43021 |
%\end{lverb} |
| 43022 |
% \begin{macrocode} |
| 43023 |
\def\XINT_expr_onliteral_subsm |
| 43024 |
{% |
| 43025 |
\expandafter\XINT_allexpr_subsm_f |
| 43026 |
\romannumeral`&&@\XINT_expr_fetch_E_comma_V_equal_E_a {}% |
| 43027 |
}% |
| 43028 |
\def\XINT_allexpr_subsm_f #1#2{\xint_c_ii^v `{subsmx}#2)\relax #1}% |
| 43029 |
\def\XINT_expr_func_subsmx |
| 43030 |
{% |
| 43031 |
\expandafter\XINT_allexpr_subsmx\expandafter\xintbareeval |
| 43032 |
\expanded\bgroup{\iffalse}\fi\XINT_allexpr_subsm_A\XINT_expr_oparen |
| 43033 |
}% |
| 43034 |
\def\XINT_flexpr_func_subsmx |
| 43035 |
{% |
| 43036 |
\expandafter\XINT_allexpr_subsmx\expandafter\xintbarefloateval |
| 43037 |
\expanded\bgroup{\iffalse}\fi\XINT_allexpr_subsm_A\XINT_flexpr_oparen |
| 43038 |
}% |
| 43039 |
\def\XINT_iiexpr_func_subsmx |
| 43040 |
{% |
| 43041 |
\expandafter\XINT_allexpr_subsmx\expandafter\xintbareiieval |
| 43042 |
\expanded\bgroup{\iffalse}\fi\XINT_allexpr_subsm_A\XINT_iiexpr_oparen |
| 43043 |
}% |
| 43044 |
\def\XINT_allexpr_subsm_A #1#2#3% |
| 43045 |
{% |
| 43046 |
\ifx#2\xint_c_ |
| 43047 |
\expandafter\XINT_allexpr_subsm_done |
| 43048 |
\else |
| 43049 |
\expandafter\XINT_allexpr_subsm_B |
| 43050 |
\fi #1% |
| 43051 |
}% |
| 43052 |
\def\XINT_allexpr_subsm_B #1#2#3#4=% |
| 43053 |
{% |
| 43054 |
{#2}\relax !\xint_zapspaces#3#4 \xint_gobble_i |
| 43055 |
\expandafter\XINT_allexpr_subsm_A\expandafter#1\romannumeral`&&@#1% |
| 43056 |
}% |
| 43057 |
% \end{macrocode} |
| 43058 |
%\begin{lverb} |
| 43059 |
%( #1 = \xintbareeval, or \xintbarefloateval or \xintbareiieval |
| 43060 |
%: #2 = evaluation of last variable assignment |
| 43061 |
%) |
| 43062 |
%\end{lverb} |
| 43063 |
% \begin{macrocode} |
| 43064 |
\def\XINT_allexpr_subsm_done #1#2{{#2}\iffalse{{\fi}}}% |
| 43065 |
% \end{macrocode} |
| 43066 |
%\begin{lverb} |
| 43067 |
%( #1 = \xintbareeval or \xintbarefloateval or \xintbareiieval |
| 43068 |
%: #2 = {value1}\relax !var2{value2}....\relax !varN{valueN} (value's may be oples) |
| 43069 |
%: #3 = {var1} |
| 43070 |
%: #4 = the expression to evaluate |
| 43071 |
%) |
| 43072 |
% Refactored at 1.4h as for \XINT_allexpr_subsx, see comments there related |
| 43073 |
% to the omit/abort conundrum. |
| 43074 |
%\end{lverb} |
| 43075 |
% \begin{macrocode} |
| 43076 |
\def\XINT_allexpr_subsmx #1#2#3#4% |
| 43077 |
{% |
| 43078 |
\expandafter\XINT_expr_clean_and_put_op_first |
| 43079 |
\expanded |
| 43080 |
\bgroup\romannumeral0#1#4\relax !#3#2\xint:\iffalse{\fi\expandafter}% |
| 43081 |
\romannumeral`&&@\XINT_expr_getop |
| 43082 |
}% |
| 43083 |
% \end{macrocode} |
| 43084 |
% \subsubsection{\cshn{subsn()}: leaner syntax for nesting (possibly dependent) substitutions} |
| 43085 |
%\begin{lverb} |
| 43086 |
% New with 1.4. 2020/01/24 |
| 43087 |
% |
| 43088 |
%\end{lverb} |
| 43089 |
% \begin{macrocode} |
| 43090 |
\def\XINT_expr_onliteral_subsn |
| 43091 |
{% |
| 43092 |
\expandafter\XINT_allexpr_subsn_f |
| 43093 |
\romannumeral`&&@\XINT_expr_fetch_E_comma_V_equal_E_a {}% |
| 43094 |
}% |
| 43095 |
\def\XINT_allexpr_subsn_f #1{\XINT_allexpr_subsn_g #1}% |
| 43096 |
% \end{macrocode} |
| 43097 |
%\begin{lverb} |
| 43098 |
%( #1 = Name1 |
| 43099 |
%: #2 = Expression in all variables which is to evaluate |
| 43100 |
%: #3 = all the stuff after Name1 = and up to final parenthesis |
| 43101 |
%) |
| 43102 |
% |
| 43103 |
% This one needed no reactoring at 1.4h to fix the omit/abort problem, as |
| 43104 |
% there was no \iffalse..\fi clean-up: the clean-up is done directly via |
| 43105 |
% \XINT_allexpr_subsnx_J. |
| 43106 |
% |
| 43107 |
% I only added usage of \XINT_expr_put_op_first_noexpand. There may be other |
| 43108 |
% locations where it could be used, but I can't afford now reviewing |
| 43109 |
% usage. For next release after 1.4h bugfix. |
| 43110 |
%\end{lverb} |
| 43111 |
% \begin{macrocode} |
| 43112 |
\def\XINT_allexpr_subsn_g #1#2#3% |
| 43113 |
{% |
| 43114 |
\expandafter\XINT_allexpr_subsn_h |
| 43115 |
\expanded\bgroup{\iffalse}\fi\expandafter\XINT_allexpr_subsn_B |
| 43116 |
\romannumeral\XINT_expr_fetch_to_semicolon #1=#3;\hbox=;;^{#2}% |
| 43117 |
}% |
| 43118 |
\def\XINT_allexpr_subsn_B #1{\XINT_allexpr_subsn_C #1\vbox}% |
| 43119 |
\def\XINT_allexpr_subsn_C #1#2=#3\vbox |
| 43120 |
{% |
| 43121 |
\ifx\hbox#1\iffalse{{\fi}\expandafter}\else |
| 43122 |
{{\xint_zapspaces #1#2 \xint_gobble_i}};\xint_noxpd{{{#3}}}% |
| 43123 |
\expandafter\XINT_allexpr_subsn_B |
| 43124 |
\romannumeral\expandafter\XINT_expr_fetch_to_semicolon\fi |
| 43125 |
}% |
| 43126 |
\def\XINT_allexpr_subsn_h |
| 43127 |
{% |
| 43128 |
\xint_c_ii^v `{subsnx}\romannumeral0\xintreverseorder |
| 43129 |
}% |
| 43130 |
\def\XINT_expr_func_subsnx #1#2#3#4#5;#6% |
| 43131 |
{% |
| 43132 |
\xint_gob_til_^ #6\XINT_allexpr_subsnx_H ^% |
| 43133 |
\expandafter\XINT_allexpr_subsnx\expandafter |
| 43134 |
\xintbareeval\romannumeral0\xintbareeval #5\relax !#4{#3}\xintundefined |
| 43135 |
{\relax !#4{#3}\relax !#6}% |
| 43136 |
}% |
| 43137 |
\def\XINT_iiexpr_func_subsnx #1#2#3#4#5;#6% |
| 43138 |
{% |
| 43139 |
\xint_gob_til_^ #6\XINT_allexpr_subsnx_H ^% |
| 43140 |
\expandafter\XINT_allexpr_subsnx\expandafter |
| 43141 |
\xintbareiieval\romannumeral0\xintbareiieval #5\relax !#4{#3}\xintundefined |
| 43142 |
{\relax !#4{#3}\relax !#6}% |
| 43143 |
}% |
| 43144 |
\def\XINT_flexpr_func_subsnx #1#2#3#4#5;#6% |
| 43145 |
{% |
| 43146 |
\xint_gob_til_^ #6\XINT_allexpr_subsnx_H ^% |
| 43147 |
\expandafter\XINT_allexpr_subsnx\expandafter |
| 43148 |
\xintbarefloateval\romannumeral0\xintbarefloateval #5\relax !#4{#3}\xintundefined |
| 43149 |
{\relax !#4{#3}\relax !#6}% |
| 43150 |
}% |
| 43151 |
\def\XINT_allexpr_subsnx #1#2!#3\xintundefined#4#5;#6% |
| 43152 |
{% |
| 43153 |
\xint_gob_til_^ #6\XINT_allexpr_subsnx_I ^% |
| 43154 |
\expandafter\XINT_allexpr_subsnx\expandafter |
| 43155 |
#1\romannumeral0#1#5\relax !#4{#2}\xintundefined |
| 43156 |
{\relax !#4{#2}\relax !#6}% |
| 43157 |
}% |
| 43158 |
\def\XINT_allexpr_subsnx_H ^#1\romannumeral0#2#3!#4\xintundefined #5#6% |
| 43159 |
{% |
| 43160 |
\expandafter\XINT_allexpr_subsnx_J\romannumeral0#2#6#5% |
| 43161 |
}% |
| 43162 |
\def\XINT_allexpr_subsnx_I ^#1\romannumeral0#2#3\xintundefined #4#5% |
| 43163 |
{% |
| 43164 |
\expandafter\XINT_allexpr_subsnx_J\romannumeral0#2#5#4% |
| 43165 |
}% |
| 43166 |
\def\XINT_allexpr_subsnx_J #1#2^% |
| 43167 |
{% |
| 43168 |
\expandafter\XINT_expr_put_op_first_noexpand |
| 43169 |
\expanded{\xint_noxpd{{#1}}\expandafter}\romannumeral`&&@\XINT_expr_getop |
| 43170 |
}% |
| 43171 |
\def\XINT_expr_put_op_first_noexpand#1#2#3{#2#3{#1}}% |
| 43172 |
% \end{macrocode} |
| 43173 |
% \subsubsection{\cshn{seq()}: sequences from assigning values to a |
| 43174 |
% dummy variable} |
| 43175 |
%\begin{lverb} |
| 43176 |
% In seq_f, the #2 is the ExprValues expression which needs evaluation to |
| 43177 |
% provide the values to the dummy variable and #1 is {Name}{ExprSeq} |
| 43178 |
% where Name is the name of dummy variable and {ExprSeq} the expression |
| 43179 |
% which will have to be evaluated. |
| 43180 |
%\end{lverb} |
| 43181 |
% |
| 43182 |
% |
| 43183 |
% \begin{macrocode} |
| 43184 |
\def\XINT_allexpr_seq_f #1#2{\xint_c_ii^v `{seqx}#2)\relax #1}% |
| 43185 |
\def\XINT_expr_onliteral_seq |
| 43186 |
{\expandafter\XINT_allexpr_seq_f\romannumeral`&&@\XINT_expr_fetch_E_comma_V_equal_E_a {}}% |
| 43187 |
\def\XINT_expr_func_seqx #1#2{\XINT:NEhook:seqx\XINT_allexpr_seqx\xintbareeval }% |
| 43188 |
\def\XINT_flexpr_func_seqx #1#2{\XINT:NEhook:seqx\XINT_allexpr_seqx\xintbarefloateval}% |
| 43189 |
\def\XINT_iiexpr_func_seqx #1#2{\XINT:NEhook:seqx\XINT_allexpr_seqx\xintbareiieval }% |
| 43190 |
\def\XINT_allexpr_seqx #1#2#3#4% |
| 43191 |
{% |
| 43192 |
\expandafter\XINT_expr_put_op_first |
| 43193 |
\expanded \bgroup {\iffalse}\fi\XINT_expr_seq:_b {#1#4\relax !#3}#2^% |
| 43194 |
\XINT_expr_cb_and_getop |
| 43195 |
}% |
| 43196 |
\def\XINT_expr_cb_and_getop{\iffalse{\fi\expandafter}\romannumeral`&&@\XINT_expr_getop}% |
| 43197 |
% \end{macrocode} |
| 43198 |
% |
| 43199 |
%\begin{lverb} |
| 43200 |
% Comments undergoing reconstruction. |
| 43201 |
%\end{lverb} |
| 43202 |
% \begin{macrocode} |
| 43203 |
\catcode`? 3 |
| 43204 |
\def\XINT_expr_seq:_b #1#2% |
| 43205 |
{% |
| 43206 |
\ifx +#2\xint_dothis\XINT_expr_seq:_Ca\fi |
| 43207 |
\ifx !#2!\xint_dothis\XINT_expr_seq:_noop\fi |
| 43208 |
\ifx ^#2\xint_dothis\XINT_expr_seq:_end\fi |
| 43209 |
\xint_orthat{\XINT_expr_seq:_c}{#2}{#1}% |
| 43210 |
}% |
| 43211 |
\def\XINT_expr_seq:_noop #1{\XINT_expr_seq:_b }% |
| 43212 |
\def\XINT_expr_seq:_end #1#2{\iffalse{\fi}}% |
| 43213 |
\def\XINT_expr_seq:_c #1#2{\expandafter\XINT_expr_seq:_d\romannumeral0#2{{#1}}{#2}}% |
| 43214 |
\def\XINT_expr_seq:_d #1{\ifx ^#1\xint_dothis\XINT_expr_seq:_abort\fi |
| 43215 |
\ifx ?#1\xint_dothis\XINT_expr_seq:_break\fi |
| 43216 |
\ifx !#1\xint_dothis\XINT_expr_seq:_omit\fi |
| 43217 |
\xint_orthat{\XINT_expr_seq:_goon {#1}}}% |
| 43218 |
\def\XINT_expr_seq:_abort #1!#2^{\iffalse{\fi}}% |
| 43219 |
\def\XINT_expr_seq:_break #1!#2^{#1\iffalse{\fi}}% |
| 43220 |
\def\XINT_expr_seq:_omit #1!#2#{\expandafter\XINT_expr_seq:_b\xint_gobble_i}% |
| 43221 |
\def\XINT_expr_seq:_goon #1!#2#{#1\expandafter\XINT_expr_seq:_b\xint_gobble_i}% |
| 43222 |
\def\XINT_expr_seq:_Ca #1#2#3{\XINT_expr_seq:_Cc#3.{#2}}% |
| 43223 |
\def\XINT_expr_seq:_Cb #1{\expandafter\XINT_expr_seq:_Cc\the\numexpr#1+\xint_c_i.}% |
| 43224 |
\def\XINT_expr_seq:_Cc #1.#2{\expandafter\XINT_expr_seq:_D\romannumeral0#2{{#1}}{#1}{#2}}% |
| 43225 |
\def\XINT_expr_seq:_D #1{\ifx ^#1\xint_dothis\XINT_expr_seq:_abort\fi |
| 43226 |
\ifx ?#1\xint_dothis\XINT_expr_seq:_break\fi |
| 43227 |
\ifx !#1\xint_dothis\XINT_expr_seq:_Omit\fi |
| 43228 |
\xint_orthat{\XINT_expr_seq:_Goon {#1}}}% |
| 43229 |
\def\XINT_expr_seq:_Omit #1!#2#{\expandafter\XINT_expr_seq:_Cb\xint_gobble_i}% |
| 43230 |
\def\XINT_expr_seq:_Goon #1!#2#{#1\expandafter\XINT_expr_seq:_Cb\xint_gobble_i}% |
| 43231 |
% \end{macrocode} |
| 43232 |
% \subsubsection{\cshn{iter()}} |
| 43233 |
% |
| 43234 |
%\begin{lverb} |
| 43235 |
% Prior to 1.2g, the iter keyword was what is now called iterr, |
| 43236 |
% analogous with rrseq. Somehow I forgot an iter functioning like rseq |
| 43237 |
% with the sole difference of printing only the last iteration. Both rseq and |
| 43238 |
% iter work well with list selectors, as @ refers to the whole comma separated |
| 43239 |
% sequence of the initial values. I have thus deliberately done the backwards |
| 43240 |
% incompatible renaming of iter to iterr, and the new iter. |
| 43241 |
% |
| 43242 |
% To understand the tokens which are presented to \XINT_allexpr_iter it is |
| 43243 |
% needed to check elsewhere in the source code how the ; hack is done. |
| 43244 |
% |
| 43245 |
% The #2 in \XINT_allexpr_iter is \xint_c_i from the ; hack. Formerly (xint < |
| 43246 |
% 1.4) there was no such token. The change is motivated to using ; also in |
| 43247 |
% subsm() syntax. |
| 43248 |
% |
| 43249 |
%\end{lverb} |
| 43250 |
% \begin{macrocode} |
| 43251 |
\def\XINT_expr_func_iter {\XINT_allexpr_iter \xintbareeval }% |
| 43252 |
\def\XINT_flexpr_func_iter {\XINT_allexpr_iter \xintbarefloateval }% |
| 43253 |
\def\XINT_iiexpr_func_iter {\XINT_allexpr_iter \xintbareiieval }% |
| 43254 |
\def\XINT_allexpr_iter #1#2#3#4% |
| 43255 |
{% |
| 43256 |
\expandafter\XINT_expr_iterx |
| 43257 |
\expandafter#1\expanded{\xint_noxpd{{#4}}\expandafter}% |
| 43258 |
\romannumeral`&&@\XINT_expr_fetch_E_comma_V_equal_E_a {}% |
| 43259 |
}% |
| 43260 |
\def\XINT_expr_iterx #1#2#3#4% |
| 43261 |
{% |
| 43262 |
\XINT:NEhook:iter\XINT_expr_itery\romannumeral0#1(#4)\relax {#2}#3#1% |
| 43263 |
}% |
| 43264 |
\def\XINT_expr_itery #1#2#3#4#5% |
| 43265 |
{% |
| 43266 |
\expandafter\XINT_expr_put_op_first |
| 43267 |
\expanded \bgroup {\iffalse}\fi |
| 43268 |
\XINT_expr_iter:_b {#5#4\relax !#3}#1^~{#2}\XINT_expr_cb_and_getop |
| 43269 |
}% |
| 43270 |
\def\XINT_expr_iter:_b #1#2% |
| 43271 |
{% |
| 43272 |
\ifx +#2\xint_dothis\XINT_expr_iter:_Ca\fi |
| 43273 |
\ifx !#2!\xint_dothis\XINT_expr_iter:_noop\fi |
| 43274 |
\ifx ^#2\xint_dothis\XINT_expr_iter:_end\fi |
| 43275 |
\xint_orthat{\XINT_expr_iter:_c}{#2}{#1}% |
| 43276 |
}% |
| 43277 |
\def\XINT_expr_iter:_noop #1{\XINT_expr_iter:_b }% |
| 43278 |
\def\XINT_expr_iter:_end #1#2~#3{#3\iffalse{\fi}}% |
| 43279 |
\def\XINT_expr_iter:_c #1#2{\expandafter\XINT_expr_iter:_d\romannumeral0#2{{#1}}{#2}}% |
| 43280 |
\def\XINT_expr_iter:_d #1{\ifx ^#1\xint_dothis\XINT_expr_iter:_abort\fi |
| 43281 |
\ifx ?#1\xint_dothis\XINT_expr_iter:_break\fi |
| 43282 |
\ifx !#1\xint_dothis\XINT_expr_iter:_omit\fi |
| 43283 |
\xint_orthat{\XINT_expr_iter:_goon {#1}}}% |
| 43284 |
\def\XINT_expr_iter:_abort #1!#2^~#3{#3\iffalse{\fi}}% |
| 43285 |
\def\XINT_expr_iter:_break #1!#2^~#3{#1\iffalse{\fi}}% |
| 43286 |
\def\XINT_expr_iter:_omit #1!#2#{\expandafter\XINT_expr_iter:_b\xint_gobble_i}% |
| 43287 |
\def\XINT_expr_iter:_goon #1!#2#{\XINT_expr_iter:_goon_a {#1}}% |
| 43288 |
\def\XINT_expr_iter:_goon_a #1#2#3~#4{\XINT_expr_iter:_b #3~{#1}}% |
| 43289 |
\def\XINT_expr_iter:_Ca #1#2#3{\XINT_expr_iter:_Cc#3.{#2}}% |
| 43290 |
\def\XINT_expr_iter:_Cb #1{\expandafter\XINT_expr_iter:_Cc\the\numexpr#1+\xint_c_i.}% |
| 43291 |
\def\XINT_expr_iter:_Cc #1.#2{\expandafter\XINT_expr_iter:_D\romannumeral0#2{{#1}}{#1}{#2}}% |
| 43292 |
\def\XINT_expr_iter:_D #1{\ifx ^#1\xint_dothis\XINT_expr_iter:_abort\fi |
| 43293 |
\ifx ?#1\xint_dothis\XINT_expr_iter:_break\fi |
| 43294 |
\ifx !#1\xint_dothis\XINT_expr_iter:_Omit\fi |
| 43295 |
\xint_orthat{\XINT_expr_iter:_Goon {#1}}}% |
| 43296 |
\def\XINT_expr_iter:_Omit #1!#2#{\expandafter\XINT_expr_iter:_Cb\xint_gobble_i}% |
| 43297 |
\def\XINT_expr_iter:_Goon #1!#2#{\XINT_expr_iter:_Goon_a {#1}}% |
| 43298 |
\def\XINT_expr_iter:_Goon_a #1#2#3~#4{\XINT_expr_iter:_Cb #3~{#1}}% |
| 43299 |
% \end{macrocode} |
| 43300 |
% \subsubsection{\cshn{add()}, \cshn{mul()}} |
| 43301 |
%\begin{lverb} |
| 43302 |
% Comments under reconstruction. |
| 43303 |
% |
| 43304 |
% These were a bit anomalous as they did not implement omit and abort keyword |
| 43305 |
% and the break() function (and per force then neither the n++ syntax). |
| 43306 |
% |
| 43307 |
% At 1.4 they are simply mapped to using adequately |
| 43308 |
% iter(). Thus, there is small loss in efficiency, but supporting omit, abort |
| 43309 |
% and break is important. Using dedicated macros here would have caused also |
| 43310 |
% slight efficiency drop. Simpler to remove the old approach. |
| 43311 |
%\end{lverb} |
| 43312 |
% |
| 43313 |
% \begin{macrocode} |
| 43314 |
\def\XINT_expr_onliteral_add |
| 43315 |
{\expandafter\XINT_allexpr_add_f\romannumeral`&&@\XINT_expr_fetch_E_comma_V_equal_E_a {}}% |
| 43316 |
\def\XINT_allexpr_add_f #1#2{\xint_c_ii^v `{opx}#2)\relax #1{+}{0}}% |
| 43317 |
\def\XINT_expr_onliteral_mul |
| 43318 |
{\expandafter\XINT_allexpr_mul_f\romannumeral`&&@\XINT_expr_fetch_E_comma_V_equal_E_a {}}% |
| 43319 |
\def\XINT_allexpr_mul_f #1#2{\xint_c_ii^v `{opx}#2)\relax #1{*}{1}}% |
| 43320 |
\def\XINT_expr_func_opx {\XINT:NEhook:opx \XINT_allexpr_opx \xintbareeval }% |
| 43321 |
\def\XINT_flexpr_func_opx {\XINT:NEhook:opx \XINT_allexpr_opx \xintbarefloateval}% |
| 43322 |
\def\XINT_iiexpr_func_opx {\XINT:NEhook:opx \XINT_allexpr_opx \xintbareiieval }% |
| 43323 |
% \end{macrocode} |
| 43324 |
%\begin{lverb} |
| 43325 |
% 1.4a In case of usage of omit (did I not test it? obviously |
| 43326 |
% I didn't as neither omit nor abort could work; and break neither), |
| 43327 |
% 1.4 code using (#6) syntax caused a |
| 43328 |
% (somewhat misleading) «missing )» error message which originated in the |
| 43329 |
% #6. This is non-obvious problem (perhaps explained why prior to 1.4 I had |
| 43330 |
% not added support for omit and break() to add() and mul()... |
| 43331 |
% |
| 43332 |
% Allowing () is not enough as it would have to be 0 or 1 depending on |
| 43333 |
% whether we are using add() or mul(). Hence the somewhat complicated |
| 43334 |
% detour (relying on precise way var_omit and var_abort work) via |
| 43335 |
% \XINT_allexpr_opx_ifnotomitted. |
| 43336 |
% |
| 43337 |
% \break() has special meaning here as it is used as last operand, not as last |
| 43338 |
% value. The code is very unsatisfactory and inefficient but this is hotfix |
| 43339 |
% for 1.4a. |
| 43340 |
%\end{lverb} |
| 43341 |
% \begin{macrocode} |
| 43342 |
\def\XINT_allexpr_opx #1#2#3#4#5#6#7#8% |
| 43343 |
{% |
| 43344 |
\expandafter\XINT_expr_put_op_first |
| 43345 |
\expanded \bgroup {\iffalse}\fi |
| 43346 |
\XINT_expr_iter:_b {#1% |
| 43347 |
\expandafter\XINT_allexpr_opx_ifnotomitted |
| 43348 |
\romannumeral0#1#6\relax#7@\relax !#5}#4^~{{#8}}\XINT_expr_cb_and_getop |
| 43349 |
}% |
| 43350 |
\def\XINT_allexpr_opx_ifnotomitted #1% |
| 43351 |
{% |
| 43352 |
\ifx !#1\xint_dothis{@\relax}\fi |
| 43353 |
\ifx ^#1\xint_dothis{\XINTfstop. ^\relax}\fi |
| 43354 |
\if ?\xintFirstItem{#1}\xint_dothis{\XINT_allexpr_opx_break{#1}}\fi |
| 43355 |
\xint_orthat{\XINTfstop.{#1}}% |
| 43356 |
}% |
| 43357 |
\def\XINT_allexpr_opx_break #1#2\relax |
| 43358 |
{% |
| 43359 |
break(\expandafter\XINTfstop\expandafter.\expandafter{\xint_gobble_i#1}#2)\relax |
| 43360 |
}% |
| 43361 |
% \end{macrocode} |
| 43362 |
% \subsubsection{\cshn{rseq()}} |
| 43363 |
% |
| 43364 |
%\begin{lverb} |
| 43365 |
% When func_rseq has its turn, initial segment has been scanned by |
| 43366 |
% oparen, the ; mimicking the rôle of a closing parenthesis, and stopping |
| 43367 |
% further expansion (and leaving a \xint_c_i left-over token since 1.4). The ; |
| 43368 |
% is discovered during standard parsing mode, it may be for example {;} or |
| 43369 |
% arise from expansion as rseq does not use a delimited macro to locate it. |
| 43370 |
%\end{lverb} |
| 43371 |
% \begin{macrocode} |
| 43372 |
\def\XINT_expr_func_rseq {\XINT_allexpr_rseq \xintbareeval }% |
| 43373 |
\def\XINT_flexpr_func_rseq {\XINT_allexpr_rseq \xintbarefloateval }% |
| 43374 |
\def\XINT_iiexpr_func_rseq {\XINT_allexpr_rseq \xintbareiieval }% |
| 43375 |
\def\XINT_allexpr_rseq #1#2#3#4% |
| 43376 |
{% |
| 43377 |
\expandafter\XINT_expr_rseqx |
| 43378 |
\expandafter #1\expanded{\xint_noxpd{{#4}}\expandafter}% |
| 43379 |
\romannumeral`&&@\XINT_expr_fetch_E_comma_V_equal_E_a {}% |
| 43380 |
}% |
| 43381 |
\def\XINT_expr_rseqx #1#2#3#4% |
| 43382 |
{% |
| 43383 |
\XINT:NEhook:rseq \XINT_expr_rseqy\romannumeral0#1(#4)\relax {#2}#3#1% |
| 43384 |
}% |
| 43385 |
\def\XINT_expr_rseqy #1#2#3#4#5% |
| 43386 |
{% |
| 43387 |
\expandafter\XINT_expr_put_op_first |
| 43388 |
\expanded \bgroup {\iffalse}\fi |
| 43389 |
#2% |
| 43390 |
\XINT_expr_rseq:_b {#5#4\relax !#3}#1^~{#2}\XINT_expr_cb_and_getop |
| 43391 |
}% |
| 43392 |
\def\XINT_expr_rseq:_b #1#2% |
| 43393 |
{% |
| 43394 |
\ifx +#2\xint_dothis\XINT_expr_rseq:_Ca\fi |
| 43395 |
\ifx !#2!\xint_dothis\XINT_expr_rseq:_noop\fi |
| 43396 |
\ifx ^#2\xint_dothis\XINT_expr_rseq:_end\fi |
| 43397 |
\xint_orthat{\XINT_expr_rseq:_c}{#2}{#1}% |
| 43398 |
}% |
| 43399 |
\def\XINT_expr_rseq:_noop #1{\XINT_expr_rseq:_b }% |
| 43400 |
\def\XINT_expr_rseq:_end #1#2~#3{\iffalse{\fi}}% |
| 43401 |
\def\XINT_expr_rseq:_c #1#2{\expandafter\XINT_expr_rseq:_d\romannumeral0#2{{#1}}{#2}}% |
| 43402 |
\def\XINT_expr_rseq:_d #1{\ifx ^#1\xint_dothis\XINT_expr_rseq:_abort\fi |
| 43403 |
\ifx ?#1\xint_dothis\XINT_expr_rseq:_break\fi |
| 43404 |
\ifx !#1\xint_dothis\XINT_expr_rseq:_omit\fi |
| 43405 |
\xint_orthat{\XINT_expr_rseq:_goon {#1}}}% |
| 43406 |
\def\XINT_expr_rseq:_abort #1!#2^~#3{\iffalse{\fi}}% |
| 43407 |
\def\XINT_expr_rseq:_break #1!#2^~#3{#1\iffalse{\fi}}% |
| 43408 |
\def\XINT_expr_rseq:_omit #1!#2#{\expandafter\XINT_expr_rseq:_b\xint_gobble_i}% |
| 43409 |
\def\XINT_expr_rseq:_goon #1!#2#{\XINT_expr_rseq:_goon_a {#1}}% |
| 43410 |
\def\XINT_expr_rseq:_goon_a #1#2#3~#4{#1\XINT_expr_rseq:_b #3~{#1}}% |
| 43411 |
\def\XINT_expr_rseq:_Ca #1#2#3{\XINT_expr_rseq:_Cc#3.{#2}}% |
| 43412 |
\def\XINT_expr_rseq:_Cb #1{\expandafter\XINT_expr_rseq:_Cc\the\numexpr#1+\xint_c_i.}% |
| 43413 |
\def\XINT_expr_rseq:_Cc #1.#2{\expandafter\XINT_expr_rseq:_D\romannumeral0#2{{#1}}{#1}{#2}}% |
| 43414 |
\def\XINT_expr_rseq:_D #1{\ifx ^#1\xint_dothis\XINT_expr_rseq:_abort\fi |
| 43415 |
\ifx ?#1\xint_dothis\XINT_expr_rseq:_break\fi |
| 43416 |
\ifx !#1\xint_dothis\XINT_expr_rseq:_Omit\fi |
| 43417 |
\xint_orthat{\XINT_expr_rseq:_Goon {#1}}}% |
| 43418 |
\def\XINT_expr_rseq:_Omit #1!#2#{\expandafter\XINT_expr_rseq:_Cb\xint_gobble_i}% |
| 43419 |
\def\XINT_expr_rseq:_Goon #1!#2#{\XINT_expr_rseq:_Goon_a {#1}}% |
| 43420 |
\def\XINT_expr_rseq:_Goon_a #1#2#3~#4{#1\XINT_expr_rseq:_Cb #3~{#1}}% |
| 43421 |
% \end{macrocode} |
| 43422 |
% \subsubsection{\cshn{iterr()}} |
| 43423 |
%\begin{lverb} |
| 43424 |
% ATTENTION! at 1.4 the @ and @1 are not synonymous anymore. One *must* use |
| 43425 |
% @1 in iterr() context. |
| 43426 |
%\end{lverb} |
| 43427 |
% \begin{macrocode} |
| 43428 |
\def\XINT_expr_func_iterr {\XINT_allexpr_iterr \xintbareeval }% |
| 43429 |
\def\XINT_flexpr_func_iterr {\XINT_allexpr_iterr \xintbarefloateval }% |
| 43430 |
\def\XINT_iiexpr_func_iterr {\XINT_allexpr_iterr \xintbareiieval }% |
| 43431 |
\def\XINT_allexpr_iterr #1#2#3#4% |
| 43432 |
{% |
| 43433 |
\expandafter\XINT_expr_iterrx |
| 43434 |
\expandafter #1\expanded{{\xintRevWithBraces{#4}}\expandafter}% |
| 43435 |
\romannumeral`&&@\XINT_expr_fetch_E_comma_V_equal_E_a {}% |
| 43436 |
}% |
| 43437 |
\def\XINT_expr_iterrx #1#2#3#4% |
| 43438 |
{% |
| 43439 |
\XINT:NEhook:iterr\XINT_expr_iterry\romannumeral0#1(#4)\relax {#2}#3#1% |
| 43440 |
}% |
| 43441 |
\def\XINT_expr_iterry #1#2#3#4#5% |
| 43442 |
{% |
| 43443 |
\expandafter\XINT_expr_put_op_first |
| 43444 |
\expanded \bgroup {\iffalse}\fi |
| 43445 |
\XINT_expr_iterr:_b {#5#4\relax !#3}#1^~#20?\XINT_expr_cb_and_getop |
| 43446 |
}% |
| 43447 |
\def\XINT_expr_iterr:_b #1#2% |
| 43448 |
{% |
| 43449 |
\ifx +#2\xint_dothis\XINT_expr_iterr:_Ca\fi |
| 43450 |
\ifx !#2!\xint_dothis\XINT_expr_iterr:_noop\fi |
| 43451 |
\ifx ^#2\xint_dothis\XINT_expr_iterr:_end\fi |
| 43452 |
\xint_orthat{\XINT_expr_iterr:_c}{#2}{#1}% |
| 43453 |
}% |
| 43454 |
\def\XINT_expr_iterr:_noop #1{\XINT_expr_iterr:_b }% |
| 43455 |
\def\XINT_expr_iterr:_end #1#2~#3#4?{{#3}\iffalse{\fi}}% |
| 43456 |
\def\XINT_expr_iterr:_c #1#2{\expandafter\XINT_expr_iterr:_d\romannumeral0#2{{#1}}{#2}}% |
| 43457 |
\def\XINT_expr_iterr:_d #1{\ifx ^#1\xint_dothis\XINT_expr_iterr:_abort\fi |
| 43458 |
\ifx ?#1\xint_dothis\XINT_expr_iterr:_break\fi |
| 43459 |
\ifx !#1\xint_dothis\XINT_expr_iterr:_omit\fi |
| 43460 |
\xint_orthat{\XINT_expr_iterr:_goon {#1}}}% |
| 43461 |
\def\XINT_expr_iterr:_abort #1!#2^~#3?{\iffalse{\fi}}% |
| 43462 |
\def\XINT_expr_iterr:_break #1!#2^~#3?{#1\iffalse{\fi}}% |
| 43463 |
\def\XINT_expr_iterr:_omit #1!#2#{\expandafter\XINT_expr_iterr:_b\xint_gobble_i}% |
| 43464 |
\def\XINT_expr_iterr:_goon #1!#2#{\XINT_expr_iterr:_goon_a{#1}}% |
| 43465 |
\def\XINT_expr_iterr:_goon_a #1#2#3~#4?% |
| 43466 |
{% |
| 43467 |
\expandafter\XINT_expr_iterr:_b \expanded{\xint_noxpd{#3~}\xintTrim{-2}{#1#4}}0?% |
| 43468 |
}% |
| 43469 |
\def\XINT_expr_iterr:_Ca #1#2#3{\XINT_expr_iterr:_Cc#3.{#2}}% |
| 43470 |
\def\XINT_expr_iterr:_Cb #1{\expandafter\XINT_expr_iterr:_Cc\the\numexpr#1+\xint_c_i.}% |
| 43471 |
\def\XINT_expr_iterr:_Cc #1.#2% |
| 43472 |
{\expandafter\XINT_expr_iterr:_D\romannumeral0#2{{#1}}{#1}{#2}}% |
| 43473 |
\def\XINT_expr_iterr:_D #1{\ifx ^#1\xint_dothis\XINT_expr_iterr:_abort\fi |
| 43474 |
\ifx ?#1\xint_dothis\XINT_expr_iterr:_break\fi |
| 43475 |
\ifx !#1\xint_dothis\XINT_expr_iterr:_Omit\fi |
| 43476 |
\xint_orthat{\XINT_expr_iterr:_Goon {#1}}}% |
| 43477 |
\def\XINT_expr_iterr:_Omit #1!#2#{\expandafter\XINT_expr_iterr:_Cb\xint_gooble_i}% |
| 43478 |
\def\XINT_expr_iterr:_Goon #1!#2#{\XINT_expr_iterr:_Goon_a{#1}}% |
| 43479 |
\def\XINT_expr_iterr:_Goon_a #1#2#3~#4?% |
| 43480 |
{% |
| 43481 |
\expandafter\XINT_expr_iterr:_Cb \expanded{\xint_noxpd{#3~}\xintTrim{-2}{#1#4}}0?% |
| 43482 |
}% |
| 43483 |
% \end{macrocode} |
| 43484 |
% \subsubsection{\cshn{rrseq()}} |
| 43485 |
% |
| 43486 |
%\begin{lverb} |
| 43487 |
% When func_rrseq has its turn, initial segment has been scanned |
| 43488 |
% by oparen, the ; mimicking the rôle of a closing parenthesis, and |
| 43489 |
% stopping further expansion. #2 = \xint_c_i and #3 are left-over trash. |
| 43490 |
%\end{lverb} |
| 43491 |
% \begin{macrocode} |
| 43492 |
\def\XINT_expr_func_rrseq {\XINT_allexpr_rrseq \xintbareeval }% |
| 43493 |
\def\XINT_flexpr_func_rrseq {\XINT_allexpr_rrseq \xintbarefloateval }% |
| 43494 |
\def\XINT_iiexpr_func_rrseq {\XINT_allexpr_rrseq \xintbareiieval }% |
| 43495 |
\def\XINT_allexpr_rrseq #1#2#3#4% |
| 43496 |
{% |
| 43497 |
\expandafter\XINT_expr_rrseqx\expandafter#1\expanded |
| 43498 |
{\xint_noxpd{{#4}}{\xintRevWithBraces{#4}}\expandafter}% |
| 43499 |
\romannumeral`&&@\XINT_expr_fetch_E_comma_V_equal_E_a {}% |
| 43500 |
}% |
| 43501 |
\def\XINT_expr_rrseqx #1#2#3#4#5% |
| 43502 |
{% |
| 43503 |
\XINT:NEhook:rrseq\XINT_expr_rrseqy\romannumeral0#1(#5)\relax {#2}{#3}#4#1% |
| 43504 |
}% |
| 43505 |
\def\XINT_expr_rrseqy #1#2#3#4#5#6% |
| 43506 |
{% |
| 43507 |
\expandafter\XINT_expr_put_op_first |
| 43508 |
\expanded \bgroup {\iffalse}\fi |
| 43509 |
#2\XINT_expr_rrseq:_b {#6#5\relax !#4}#1^~#30?\XINT_expr_cb_and_getop |
| 43510 |
}% |
| 43511 |
\def\XINT_expr_rrseq:_b #1#2% |
| 43512 |
{% |
| 43513 |
\ifx +#2\xint_dothis\XINT_expr_rrseq:_Ca\fi |
| 43514 |
\ifx !#2!\xint_dothis\XINT_expr_rrseq:_noop\fi |
| 43515 |
\ifx ^#2\xint_dothis\XINT_expr_rrseq:_end\fi |
| 43516 |
\xint_orthat{\XINT_expr_rrseq:_c}{#2}{#1}% |
| 43517 |
}% |
| 43518 |
\def\XINT_expr_rrseq:_noop #1{\XINT_expr_rrseq:_b }% |
| 43519 |
\def\XINT_expr_rrseq:_end #1#2~#3?{\iffalse{\fi}}% |
| 43520 |
\def\XINT_expr_rrseq:_c #1#2{\expandafter\XINT_expr_rrseq:_d\romannumeral0#2{{#1}}{#2}}% |
| 43521 |
\def\XINT_expr_rrseq:_d #1{\ifx ^#1\xint_dothis\XINT_expr_rrseq:_abort\fi |
| 43522 |
\ifx ?#1\xint_dothis\XINT_expr_rrseq:_break\fi |
| 43523 |
\ifx !#1\xint_dothis\XINT_expr_rrseq:_omit\fi |
| 43524 |
\xint_orthat{\XINT_expr_rrseq:_goon {#1}}}% |
| 43525 |
\def\XINT_expr_rrseq:_abort #1!#2^~#3?{\iffalse{\fi}}% |
| 43526 |
\def\XINT_expr_rrseq:_break #1!#2^~#3?{#1\iffalse{\fi}}% |
| 43527 |
\def\XINT_expr_rrseq:_omit #1!#2#{\expandafter\XINT_expr_rrseq:_b\xint_gobble_i}% |
| 43528 |
\def\XINT_expr_rrseq:_goon #1!#2#{\XINT_expr_rrseq:_goon_a {#1}}% |
| 43529 |
\def\XINT_expr_rrseq:_goon_a #1#2#3~#4?% |
| 43530 |
{% |
| 43531 |
#1\expandafter\XINT_expr_rrseq:_b\expanded{\xint_noxpd{#3~}\xintTrim{-2}{#1#4}}0?% |
| 43532 |
}% |
| 43533 |
\def\XINT_expr_rrseq:_Ca #1#2#3{\XINT_expr_rrseq:_Cc#3.{#2}}% |
| 43534 |
\def\XINT_expr_rrseq:_Cb #1{\expandafter\XINT_expr_rrseq:_Cc\the\numexpr#1+\xint_c_i.}% |
| 43535 |
\def\XINT_expr_rrseq:_Cc #1.#2% |
| 43536 |
{\expandafter\XINT_expr_rrseq:_D\romannumeral0#2{{#1}}{#1}{#2}}% |
| 43537 |
\def\XINT_expr_rrseq:_D #1{\ifx ^#1\xint_dothis\XINT_expr_rrseq:_abort\fi |
| 43538 |
\ifx ?#1\xint_dothis\XINT_expr_rrseq:_break\fi |
| 43539 |
\ifx !#1\xint_dothis\XINT_expr_rrseq:_Omit\fi |
| 43540 |
\xint_orthat{\XINT_expr_rrseq:_Goon {#1}}}% |
| 43541 |
\def\XINT_expr_rrseq:_Omit #1!#2#{\expandafter\XINT_expr_rrseq:_Cb\xint_gobble_i}% |
| 43542 |
\def\XINT_expr_rrseq:_Goon #1!#2#{\XINT_expr_rrseq:_Goon_a {#1}}% |
| 43543 |
\def\XINT_expr_rrseq:_Goon_a #1#2#3~#4?% |
| 43544 |
{% |
| 43545 |
#1\expandafter\XINT_expr_rrseq:_Cb\expanded{\xint_noxpd{#3~}\xintTrim{-2}{#1#4}}0?% |
| 43546 |
}% |
| 43547 |
\catcode`? 11 |
| 43548 |
% \end{macrocode} |
| 43549 |
% \subsection{Pseudo-functions related to N-dimensional hypercubic lists} |
| 43550 |
% \subsubsection{\cshn{ndseq()}} |
| 43551 |
%\begin{lverb} |
| 43552 |
% New with 1.4. 2020/01/23. It is derived from subsm() but instead of |
| 43553 |
% evaluating one expression according to one value per variable, it constructs |
| 43554 |
% a nested bracketed seq... this means the expression is parsed each time ! |
| 43555 |
% Anyway, proof of concept. Nota Bene : omit, abort, break() work ! |
| 43556 |
%\end{lverb} |
| 43557 |
% \begin{macrocode} |
| 43558 |
\def\XINT_expr_onliteral_ndseq |
| 43559 |
{% |
| 43560 |
\expandafter\XINT_allexpr_ndseq_f |
| 43561 |
\romannumeral`&&@\XINT_expr_fetch_E_comma_V_equal_E_a {}% |
| 43562 |
}% |
| 43563 |
\def\XINT_allexpr_ndseq_f #1#2{\xint_c_ii^v `{ndseqx}#2)\relax #1}% |
| 43564 |
\def\XINT_expr_func_ndseqx |
| 43565 |
{% |
| 43566 |
\expandafter\XINT_allexpr_ndseqx\expandafter\xintbareeval |
| 43567 |
\expandafter{\romannumeral0\expandafter\xint_gobble_i\string}% |
| 43568 |
\expandafter\xintrevwithbraces |
| 43569 |
\expanded\bgroup{\iffalse}\fi\XINT_allexpr_ndseq_A\XINT_expr_oparen |
| 43570 |
}% |
| 43571 |
\def\XINT_flexpr_func_ndseqx |
| 43572 |
{% |
| 43573 |
\expandafter\XINT_allexpr_ndseqx\expandafter\xintbarefloateval |
| 43574 |
\expandafter{\romannumeral0\expandafter\xint_gobble_i\string}% |
| 43575 |
\expandafter\xintrevwithbraces |
| 43576 |
\expanded\bgroup{\iffalse}\fi\XINT_allexpr_ndseq_A\XINT_flexpr_oparen |
| 43577 |
}% |
| 43578 |
\def\XINT_iiexpr_func_ndseqx |
| 43579 |
{% |
| 43580 |
\expandafter\XINT_allexpr_ndseqx\expandafter\xintbareiieval |
| 43581 |
\expandafter{\romannumeral0\expandafter\xint_gobble_i\string}% |
| 43582 |
\expandafter\xintrevwithbraces |
| 43583 |
\expanded\bgroup{\iffalse}\fi\XINT_allexpr_ndseq_A\XINT_iiexpr_oparen |
| 43584 |
}% |
| 43585 |
\def\XINT_allexpr_ndseq_A #1#2#3% |
| 43586 |
{% |
| 43587 |
\ifx#2\xint_c_ |
| 43588 |
\expandafter\XINT_allexpr_ndseq_C |
| 43589 |
\else |
| 43590 |
\expandafter\XINT_allexpr_ndseq_B |
| 43591 |
\fi #1% |
| 43592 |
}% |
| 43593 |
\def\XINT_allexpr_ndseq_B #1#2#3#4=% |
| 43594 |
{% |
| 43595 |
{#2}{\xint_zapspaces#3#4 \xint_gobble_i}% |
| 43596 |
\expandafter\XINT_allexpr_ndseq_A\expandafter#1\romannumeral`&&@#1% |
| 43597 |
}% |
| 43598 |
% \end{macrocode} |
| 43599 |
%\begin{lverb} |
| 43600 |
% #1 = \xintbareeval, or \xintbarefloateval or \xintbareiieval |
| 43601 |
% #2 = values for last coordinate |
| 43602 |
%\end{lverb} |
| 43603 |
% \begin{macrocode} |
| 43604 |
\def\XINT_allexpr_ndseq_C #1#2{{#2}\iffalse{{{\fi}}}}% |
| 43605 |
% \end{macrocode} |
| 43606 |
%\begin{lverb} |
| 43607 |
% #1 = \xintbareeval or \xintbarefloateval or \xintbareiieval |
| 43608 |
% #2 = {valuesN}...{values2}{var2}{values1} |
| 43609 |
% #3 = {var1} |
| 43610 |
% #4 = the expression to evaluate |
| 43611 |
%\end{lverb} |
| 43612 |
% \begin{macrocode} |
| 43613 |
\def\XINT_allexpr_ndseqx #1#2#3#4% |
| 43614 |
{% |
| 43615 |
\expandafter\XINT_expr_put_op_first |
| 43616 |
\expanded |
| 43617 |
\bgroup |
| 43618 |
\romannumeral0#1\empty |
| 43619 |
\expanded{\xintReplicate{\xintLength{{#3}#2}/2}{[seq(}% |
| 43620 |
\xint_noxpd{#4}% |
| 43621 |
\XINT_allexpr_ndseqx_a #2{#3}^^% |
| 43622 |
}% |
| 43623 |
\relax |
| 43624 |
\iffalse{\fi\expandafter}\romannumeral`&&@\XINT_expr_getop |
| 43625 |
}% |
| 43626 |
\def\XINT_allexpr_ndseqx_a #1#2% |
| 43627 |
{% |
| 43628 |
\xint_gob_til_^ #1\XINT_allexpr_ndseqx_e ^% |
| 43629 |
\xint_noxpd{,#2=\XINTfstop.{#1})]}\XINT_allexpr_ndseqx_a |
| 43630 |
}% |
| 43631 |
\def\XINT_allexpr_ndseqx_e ^#1\XINT_allexpr_ndseqx_a{}% |
| 43632 |
% \end{macrocode} |
| 43633 |
% \subsubsection{\cshn{ndmap()}} |
| 43634 |
%\begin{lverb} |
| 43635 |
% New with 1.4. 2020/01/24. |
| 43636 |
%\end{lverb} |
| 43637 |
% \begin{macrocode} |
| 43638 |
\def\XINT_expr_onliteral_ndmap #1,{\xint_c_ii^v `{ndmapx}\XINTfstop.{#1};}% |
| 43639 |
\def\XINT_expr_func_ndmapx #1#2#3% |
| 43640 |
{% |
| 43641 |
\expandafter\XINT_allexpr_ndmapx |
| 43642 |
\csname XINT_expr_func_\xint_zapspaces #3 \xint_gobble_i\endcsname |
| 43643 |
\XINT_expr_oparen |
| 43644 |
}% |
| 43645 |
\def\XINT_flexpr_func_ndmapx #1#2#3% |
| 43646 |
{% |
| 43647 |
\expandafter\XINT_allexpr_ndmapx |
| 43648 |
\csname XINT_flexpr_func_\xint_zapspaces #3 \xint_gobble_i\endcsname |
| 43649 |
\XINT_flexpr_oparen |
| 43650 |
}% |
| 43651 |
\def\XINT_iiexpr_func_ndmapx #1#2#3% |
| 43652 |
{% |
| 43653 |
\expandafter\XINT_allexpr_ndmapx |
| 43654 |
\csname XINT_iiexpr_func_\xint_zapspaces #3 \xint_gobble_i\endcsname |
| 43655 |
\XINT_iiexpr_oparen |
| 43656 |
}% |
| 43657 |
\def\XINT_allexpr_ndmapx #1#2% |
| 43658 |
{% |
| 43659 |
\expandafter\XINT_expr_put_op_first |
| 43660 |
\expanded\bgroup{\iffalse}\fi |
| 43661 |
\expanded |
| 43662 |
{\noexpand\XINT:NEhook:x:ndmapx |
| 43663 |
\noexpand\XINT_allexpr_ndmapx_a |
| 43664 |
\noexpand#1{}\expandafter}% |
| 43665 |
\expanded\bgroup\expandafter\XINT_allexpr_ndmap_A |
| 43666 |
\expandafter#2\romannumeral`&&@#2% |
| 43667 |
}% |
| 43668 |
\def\XINT_allexpr_ndmap_A #1#2#3% |
| 43669 |
{% |
| 43670 |
\ifx#3;% |
| 43671 |
\expandafter\XINT_allexpr_ndmap_B |
| 43672 |
\else |
| 43673 |
\xint_afterfi{\XINT_allexpr_ndmap_C#2#3}% |
| 43674 |
\fi #1% |
| 43675 |
}% |
| 43676 |
\def\XINT_allexpr_ndmap_B #1#2% |
| 43677 |
{% |
| 43678 |
{#2}\expandafter\XINT_allexpr_ndmap_A\expandafter#1\romannumeral`&&@#1% |
| 43679 |
}% |
| 43680 |
\def\XINT_allexpr_ndmap_C #1#2#3#4% |
| 43681 |
{% |
| 43682 |
{#4}^\relax\iffalse{{{\fi}}}#1#2% |
| 43683 |
}% |
| 43684 |
\def\XINT_allexpr_ndmapx_a #1#2#3% |
| 43685 |
{% |
| 43686 |
\xint_gob_til_^ #3\XINT_allexpr_ndmapx_l ^% |
| 43687 |
\XINT_allexpr_ndmapx_b #1{#2}{#3}% |
| 43688 |
}% |
| 43689 |
\def\XINT_allexpr_ndmapx_l ^#1\XINT_allexpr_ndmapx_b #2#3#4\relax |
| 43690 |
{% |
| 43691 |
#2\empty\xint_firstofone{#3}% |
| 43692 |
}% |
| 43693 |
\def\XINT_allexpr_ndmapx_b #1#2#3#4\relax |
| 43694 |
{% |
| 43695 |
{\iffalse}\fi\XINT_allexpr_ndmapx_c {#4\relax}#1{#2}#3^% |
| 43696 |
}% |
| 43697 |
\def\XINT_allexpr_ndmapx_c #1#2#3#4% |
| 43698 |
{% |
| 43699 |
\xint_gob_til_^ #4\XINT_allexpr_ndmapx_e ^% |
| 43700 |
\XINT_allexpr_ndmapx_a #2{#3{#4}}#1% |
| 43701 |
\XINT_allexpr_ndmapx_c {#1}#2{#3}% |
| 43702 |
}% |
| 43703 |
\def\XINT_allexpr_ndmapx_e ^#1\XINT_allexpr_ndmapx_c |
| 43704 |
{\iffalse{\fi}\xint_gobble_iii}% |
| 43705 |
% \end{macrocode} |
| 43706 |
% \subsubsection{\cshn{ndfillraw()}} |
| 43707 |
%\begin{lverb} |
| 43708 |
% New with 1.4. 2020/01/24. J'hésite à autoriser un #1 quelconque, |
| 43709 |
% ou plutôt à le wrapper dans un \xintbareval. Mais il faut alors distinguer |
| 43710 |
% les trois. De toute façon les variables ne marcheraient pas donc j'hésite |
| 43711 |
% à mettre un wrapper automatique. Mais ce n'est pas bien d'autoriser l'injection |
| 43712 |
% de choses quelconques. |
| 43713 |
% |
| 43714 |
% Pour des choses comme ndfillraw(\xintRandomBit,[10,10]). |
| 43715 |
% |
| 43716 |
% Je n'aime pas le nom !. Le changer. ndconst? Surtout je n'aime pas |
| 43717 |
% que dans le premier argument il faut rajouter explicitement si nécessaire |
| 43718 |
% \xintiiexpr wrap. |
| 43719 |
%\end{lverb} |
| 43720 |
% \begin{macrocode} |
| 43721 |
\def\XINT_expr_onliteral_ndfillraw #1,{\xint_c_ii^v `{ndfillrawx}\XINTfstop.{{#1}},}% |
| 43722 |
\def\XINT_expr_func_ndfillrawx #1#2#3% |
| 43723 |
{% |
| 43724 |
\expandafter#1\expandafter#2\expanded{{{\XINT_allexpr_ndfillrawx_a #3}}}% |
| 43725 |
}% |
| 43726 |
\let\XINT_iiexpr_func_ndfillrawx\XINT_expr_func_ndfillrawx |
| 43727 |
\let\XINT_flexpr_func_ndfillrawx\XINT_expr_func_ndfillrawx |
| 43728 |
\def\XINT_allexpr_ndfillrawx_a #1#2% |
| 43729 |
{% |
| 43730 |
\expandafter\XINT_allexpr_ndfillrawx_b |
| 43731 |
\romannumeral0\xintApply{\xintNum}{#2}^\relax {#1}% |
| 43732 |
}% |
| 43733 |
\def\XINT_allexpr_ndfillrawx_b #1#2\relax#3% |
| 43734 |
{% |
| 43735 |
\xint_gob_til_^ #1\XINT_allexpr_ndfillrawx_c ^% |
| 43736 |
\xintReplicate{#1}{{\XINT_allexpr_ndfillrawx_b #2\relax {#3}}}% |
| 43737 |
}% |
| 43738 |
\def\XINT_allexpr_ndfillrawx_c ^\xintReplicate #1#2% |
| 43739 |
{% |
| 43740 |
\expandafter\XINT_allexpr_ndfillrawx_d\xint_firstofone #2% |
| 43741 |
}% |
| 43742 |
\def\XINT_allexpr_ndfillrawx_d\XINT_allexpr_ndfillrawx_b \relax #1{#1}% |
| 43743 |
% \end{macrocode} |
| 43744 |
% \subsection{Other pseudo-functions: \cshn{bool()}, \cshn{togl()}, \cshn{protect()}, |
| 43745 |
% \cshn{qraw()}, \cshn{qint()}, \cshn{qfrac()}, \cshn{qfloat()}, \cshn{qrand()}, |
| 43746 |
% \cshn{random()}, \cshn{rbit()}} |
| 43747 |
% |
| 43748 |
%\begin{lverb} |
| 43749 |
% bool, togl and protect use delimited macros. They are not true |
| 43750 |
% functions, they turn off the parser to gather their "variable". |
| 43751 |
%\end{lverb} |
| 43752 |
% |
| 43753 |
% \changed{1.2} Adds |qint()|, |qfrac()|, |qfloat()|. |
| 43754 |
% |
| 43755 |
% \changed{1.3c} Adds |qraw()|. Useful to limit impact on \TeX{} memory |
| 43756 |
% from abuse of |\csname|'s storage when generating many comma separated |
| 43757 |
% values from a loop. |
| 43758 |
% |
| 43759 |
% \changed{1.3e} |qfloat()| keeps a short mantissa if possible. |
| 43760 |
% |
| 43761 |
%\begin{lverb} |
| 43762 |
% They allow the user to hand over quickly a big number to the parser, |
| 43763 |
% spaces not immediately removed but should be harmless in general. The qraw() |
| 43764 |
% does no post-processing at all apart complete expansion, useful for |
| 43765 |
% comma-separated values, but must be obedient to (non really documented) |
| 43766 |
% expected format. Each uses a delimited macro, the closing parenthesis can |
| 43767 |
% not emerge from expansion. |
| 43768 |
%\end{lverb} |
| 43769 |
% |
| 43770 |
%\begin{lverb} |
| 43771 |
% 1.3b. random(), qrand() |
| 43772 |
% Function-like syntax but with no argument currently, so let's |
| 43773 |
% use fast parsing which requires though the closing parenthesis to be |
| 43774 |
% explicit. |
| 43775 |
%\end{lverb} |
| 43776 |
% |
| 43777 |
%\begin{lverb} |
| 43778 |
% Attention that qraw() |
| 43779 |
% which pre-supposes knowledge of internal storage model is fragile |
| 43780 |
% and may break at any release. |
| 43781 |
% |
| 43782 |
% 1.4 adds rbit(). Short for random bit. |
| 43783 |
%\end{lverb} |
| 43784 |
% \begin{macrocode} |
| 43785 |
\def\XINT_expr_onliteral_bool #1)% |
| 43786 |
{\expandafter\XINT_expr_put_op_first\expanded{{{\xintBool{#1}}}\expandafter |
| 43787 |
}\romannumeral`&&@\XINT_expr_getop}% |
| 43788 |
\def\XINT_expr_onliteral_togl #1)% |
| 43789 |
{\expandafter\XINT_expr_put_op_first\expanded{{{\xintToggle{#1}}}\expandafter |
| 43790 |
}\romannumeral`&&@\XINT_expr_getop}% |
| 43791 |
\def\XINT_expr_onliteral_protect #1)% |
| 43792 |
{\expandafter\XINT_expr_put_op_first\expanded{{{\detokenize{#1}}}\expandafter |
| 43793 |
}\romannumeral`&&@\XINT_expr_getop}% |
| 43794 |
\def\XINT_expr_onliteral_qint #1)% |
| 43795 |
{\expandafter\XINT_expr_put_op_first\expanded{{{\xintiNum{#1}}}\expandafter |
| 43796 |
}\romannumeral`&&@\XINT_expr_getop}% |
| 43797 |
\def\XINT_expr_onliteral_qfrac #1)% |
| 43798 |
{\expandafter\XINT_expr_put_op_first\expanded{{{\xintRaw{#1}}}\expandafter |
| 43799 |
}\romannumeral`&&@\XINT_expr_getop}% |
| 43800 |
\def\XINT_expr_onliteral_qfloat #1)% |
| 43801 |
{\expandafter\XINT_expr_put_op_first\expanded{{{\XINTinFloatSdigits{#1}}}\expandafter |
| 43802 |
}\romannumeral`&&@\XINT_expr_getop}% |
| 43803 |
\def\XINT_expr_onliteral_qraw #1)% |
| 43804 |
{\expandafter\XINT_expr_put_op_first\expanded{{#1}\expandafter |
| 43805 |
}\romannumeral`&&@\XINT_expr_getop}% |
| 43806 |
\def\XINT_expr_onliteral_random #1)% |
| 43807 |
{\expandafter\XINT_expr_put_op_first\expanded{{{\XINTinRandomFloatSdigits}}\expandafter |
| 43808 |
}\romannumeral`&&@\XINT_expr_getop}% |
| 43809 |
\def\XINT_expr_onliteral_qrand #1)% |
| 43810 |
{\expandafter\XINT_expr_put_op_first\expanded{{{\XINTinRandomFloatSixteen}}\expandafter |
| 43811 |
}\romannumeral`&&@\XINT_expr_getop}% |
| 43812 |
\def\XINT_expr_onliteral_rbit #1)% |
| 43813 |
{\expandafter\XINT_expr_put_op_first\expanded{{{\xintRandBit}}\expandafter |
| 43814 |
}\romannumeral`&&@\XINT_expr_getop}% |
| 43815 |
% \end{macrocode} |
| 43816 |
% \def\auxiliarymacro#1{ \noexpand\cshn{#1()}} |
| 43817 |
% \edef\zzz{Regular built-in functions: \xintListWithSep{, }{\xintApply\auxiliarymacro |
| 43818 |
% {{num}{reduce}{preduce} |
| 43819 |
% {abs}{sgn}{frac}{floor}{ceil}{sqr} |
| 43820 |
% {?}{!}{not}{odd}{even}{isint}{isone} |
| 43821 |
% {factorial}{sqrt}{sqrtr} |
| 43822 |
% {inv}{round}{trunc} |
| 43823 |
% {float}{sfloat}{ilog10} |
| 43824 |
% {divmod}{mod}{binomial}{pfactorial} |
| 43825 |
% {randrange} |
| 43826 |
% {iquo}{irem}{gcd}{lcm}{max}{min} |
| 43827 |
% {`+`}{`*`} |
| 43828 |
% {all}{any}{xor} |
| 43829 |
% {len}{first}{last}{reversed} |
| 43830 |
% {if}{ifint}{ifone}{ifsgn} |
| 43831 |
% {nuple}{unpack}{flat}}} |
| 43832 |
% and \noexpand\cshn{zip()}} |
| 43833 |
% \expandafter\subsection\expandafter{\zzz} |
| 43834 |
% \begin{macrocode} |
| 43835 |
\def\XINT:expr:f:one:and:opt #1#2#3!#4#5% |
| 43836 |
{% |
| 43837 |
\if\relax#3\relax\expandafter\xint_firstoftwo\else |
| 43838 |
\expandafter\xint_secondoftwo\fi |
| 43839 |
{#4}{#5[\xintNum{#2}]}{#1}% |
| 43840 |
}% |
| 43841 |
\def\XINT:expr:f:tacitzeroifone #1#2#3!#4#5% |
| 43842 |
{% |
| 43843 |
\if\relax#3\relax\expandafter\xint_firstoftwo\else |
| 43844 |
\expandafter\xint_secondoftwo\fi |
| 43845 |
{#4{0}}{#5{\xintNum{#2}}}{#1}% |
| 43846 |
}% |
| 43847 |
\def\XINT:expr:f:iitacitzeroifone #1#2#3!#4% |
| 43848 |
{% |
| 43849 |
\if\relax#3\relax\expandafter\xint_firstoftwo\else |
| 43850 |
\expandafter\xint_secondoftwo\fi |
| 43851 |
{#4{0}}{#4{#2}}{#1}% |
| 43852 |
}% |
| 43853 |
\def\XINT_expr_func_num #1#2#3% |
| 43854 |
{% |
| 43855 |
\expandafter #1\expandafter #2\expandafter{% |
| 43856 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 43857 |
{\romannumeral`&&@\xintNum#3}}% |
| 43858 |
}% |
| 43859 |
\let\XINT_flexpr_func_num\XINT_expr_func_num |
| 43860 |
\let\XINT_iiexpr_func_num\XINT_expr_func_num |
| 43861 |
\def\XINT_expr_func_reduce #1#2#3% |
| 43862 |
{% |
| 43863 |
\expandafter #1\expandafter #2\expandafter{% |
| 43864 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 43865 |
{\romannumeral`&&@\xintIrr#3}}% |
| 43866 |
}% |
| 43867 |
\let\XINT_flexpr_func_reduce\XINT_expr_func_reduce |
| 43868 |
\def\XINT_expr_func_preduce #1#2#3% |
| 43869 |
{% |
| 43870 |
\expandafter #1\expandafter #2\expandafter{% |
| 43871 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 43872 |
{\romannumeral`&&@\xintPIrr#3}}% |
| 43873 |
}% |
| 43874 |
\let\XINT_flexpr_func_preduce\XINT_expr_func_preduce |
| 43875 |
\def\XINT_expr_func_abs #1#2#3% |
| 43876 |
{% |
| 43877 |
\expandafter #1\expandafter #2\expandafter{% |
| 43878 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 43879 |
{\romannumeral`&&@\xintAbs#3}}% |
| 43880 |
}% |
| 43881 |
\let\XINT_flexpr_func_abs\XINT_expr_func_abs |
| 43882 |
\def\XINT_iiexpr_func_abs #1#2#3% |
| 43883 |
{% |
| 43884 |
\expandafter #1\expandafter #2\expandafter{% |
| 43885 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 43886 |
{\romannumeral`&&@\xintiiAbs#3}}% |
| 43887 |
}% |
| 43888 |
\def\XINT_expr_func_sgn #1#2#3% |
| 43889 |
{% |
| 43890 |
\expandafter #1\expandafter #2\expandafter{% |
| 43891 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 43892 |
{\romannumeral`&&@\xintSgn#3}}% |
| 43893 |
}% |
| 43894 |
\let\XINT_flexpr_func_sgn\XINT_expr_func_sgn |
| 43895 |
\def\XINT_iiexpr_func_sgn #1#2#3% |
| 43896 |
{% |
| 43897 |
\expandafter #1\expandafter #2\expandafter{% |
| 43898 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 43899 |
{\romannumeral`&&@\xintiiSgn#3}}% |
| 43900 |
}% |
| 43901 |
\def\XINT_expr_func_frac #1#2#3% |
| 43902 |
{% |
| 43903 |
\expandafter #1\expandafter #2\expandafter{% |
| 43904 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 43905 |
{\romannumeral`&&@\xintTFrac#3}}% |
| 43906 |
}% |
| 43907 |
\def\XINT_flexpr_func_frac #1#2#3% |
| 43908 |
{% |
| 43909 |
\expandafter #1\expandafter #2\expandafter{% |
| 43910 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 43911 |
{\romannumeral`&&@\XINTinFloatFrac#3}}% |
| 43912 |
}% |
| 43913 |
% \end{macrocode} |
| 43914 |
%\begin{lverb} |
| 43915 |
% no \XINT_iiexpr_func_frac |
| 43916 |
%\end{lverb} |
| 43917 |
% \begin{macrocode} |
| 43918 |
\def\XINT_expr_func_floor #1#2#3% |
| 43919 |
{% |
| 43920 |
\expandafter #1\expandafter #2\expandafter{% |
| 43921 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 43922 |
{\romannumeral`&&@\xintFloor#3}}% |
| 43923 |
}% |
| 43924 |
\let\XINT_flexpr_func_floor\XINT_expr_func_floor |
| 43925 |
% \end{macrocode} |
| 43926 |
%\begin{lverb} |
| 43927 |
% The floor and ceil functions in \xintiiexpr require protect(a/b) or, |
| 43928 |
% better, \qfrac(a/b); else the / will be executed first and do an integer |
| 43929 |
% rounded division. |
| 43930 |
%\end{lverb} |
| 43931 |
% \begin{macrocode} |
| 43932 |
\def\XINT_iiexpr_func_floor #1#2#3% |
| 43933 |
{% |
| 43934 |
\expandafter #1\expandafter #2\expandafter{% |
| 43935 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 43936 |
{\romannumeral`&&@\xintiFloor#3}}% |
| 43937 |
}% |
| 43938 |
\def\XINT_expr_func_ceil #1#2#3% |
| 43939 |
{% |
| 43940 |
\expandafter #1\expandafter #2\expandafter{% |
| 43941 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 43942 |
{\romannumeral`&&@\xintCeil#3}}% |
| 43943 |
}% |
| 43944 |
\let\XINT_flexpr_func_ceil\XINT_expr_func_ceil |
| 43945 |
\def\XINT_iiexpr_func_ceil #1#2#3% |
| 43946 |
{% |
| 43947 |
\expandafter #1\expandafter #2\expandafter{% |
| 43948 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 43949 |
{\romannumeral`&&@\xintiCeil#3}}% |
| 43950 |
}% |
| 43951 |
\def\XINT_expr_func_sqr #1#2#3% |
| 43952 |
{% |
| 43953 |
\expandafter #1\expandafter #2\expandafter{% |
| 43954 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 43955 |
{\romannumeral`&&@\xintSqr#3}}% |
| 43956 |
}% |
| 43957 |
\def\XINT_flexpr_func_sqr #1#2#3% |
| 43958 |
{% |
| 43959 |
\expandafter #1\expandafter #2\expandafter{% |
| 43960 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 43961 |
{\romannumeral`&&@\XINTinFloatSqr#3}}% |
| 43962 |
}% |
| 43963 |
\def\XINT_iiexpr_func_sqr #1#2#3% |
| 43964 |
{% |
| 43965 |
\expandafter #1\expandafter #2\expandafter{% |
| 43966 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 43967 |
{\romannumeral`&&@\xintiiSqr#3}}% |
| 43968 |
}% |
| 43969 |
\def\XINT_expr_func_? #1#2#3% |
| 43970 |
{% |
| 43971 |
\expandafter #1\expandafter #2\expandafter{% |
| 43972 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 43973 |
{\romannumeral`&&@\xintiiIsNotZero#3}}% |
| 43974 |
}% |
| 43975 |
\let\XINT_flexpr_func_? \XINT_expr_func_? |
| 43976 |
\let\XINT_iiexpr_func_? \XINT_expr_func_? |
| 43977 |
\def\XINT_expr_func_! #1#2#3% |
| 43978 |
{% |
| 43979 |
\expandafter #1\expandafter #2\expandafter{% |
| 43980 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 43981 |
{\romannumeral`&&@\xintiiIsZero#3}}% |
| 43982 |
}% |
| 43983 |
\let\XINT_flexpr_func_! \XINT_expr_func_! |
| 43984 |
\let\XINT_iiexpr_func_! \XINT_expr_func_! |
| 43985 |
\def\XINT_expr_func_not #1#2#3% |
| 43986 |
{% |
| 43987 |
\expandafter #1\expandafter #2\expandafter{% |
| 43988 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 43989 |
{\romannumeral`&&@\xintiiIsZero#3}}% |
| 43990 |
}% |
| 43991 |
\let\XINT_flexpr_func_not \XINT_expr_func_not |
| 43992 |
\let\XINT_iiexpr_func_not \XINT_expr_func_not |
| 43993 |
\def\XINT_expr_func_odd #1#2#3% |
| 43994 |
{% |
| 43995 |
\expandafter #1\expandafter #2\expandafter{% |
| 43996 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 43997 |
{\romannumeral`&&@\xintOdd#3}}% |
| 43998 |
}% |
| 43999 |
\let\XINT_flexpr_func_odd\XINT_expr_func_odd |
| 44000 |
\def\XINT_iiexpr_func_odd #1#2#3% |
| 44001 |
{% |
| 44002 |
\expandafter #1\expandafter #2\expandafter{% |
| 44003 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 44004 |
{\romannumeral`&&@\xintiiOdd#3}}% |
| 44005 |
}% |
| 44006 |
\def\XINT_expr_func_even #1#2#3% |
| 44007 |
{% |
| 44008 |
\expandafter #1\expandafter #2\expandafter{% |
| 44009 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 44010 |
{\romannumeral`&&@\xintEven#3}}% |
| 44011 |
}% |
| 44012 |
\let\XINT_flexpr_func_even\XINT_expr_func_even |
| 44013 |
\def\XINT_iiexpr_func_even #1#2#3% |
| 44014 |
{% |
| 44015 |
\expandafter #1\expandafter #2\expandafter{% |
| 44016 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 44017 |
{\romannumeral`&&@\xintiiEven#3}}% |
| 44018 |
}% |
| 44019 |
\def\XINT_expr_func_isint #1#2#3% |
| 44020 |
{% |
| 44021 |
\expandafter #1\expandafter #2\expandafter{% |
| 44022 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 44023 |
{\romannumeral`&&@\xintIsInt#3}}% |
| 44024 |
}% |
| 44025 |
\def\XINT_flexpr_func_isint #1#2#3% |
| 44026 |
{% |
| 44027 |
\expandafter #1\expandafter #2\expandafter{% |
| 44028 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 44029 |
{\romannumeral`&&@\xintFloatIsInt#3}}% |
| 44030 |
}% |
| 44031 |
\let\XINT_iiexpr_func_isint\XINT_expr_func_isint % ? perhaps rather always 1 |
| 44032 |
\def\XINT_expr_func_isone #1#2#3% |
| 44033 |
{% |
| 44034 |
\expandafter #1\expandafter #2\expandafter{% |
| 44035 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 44036 |
{\romannumeral`&&@\xintIsOne#3}}% |
| 44037 |
}% |
| 44038 |
\let\XINT_flexpr_func_isone\XINT_expr_func_isone |
| 44039 |
\def\XINT_iiexpr_func_isone #1#2#3% |
| 44040 |
{% |
| 44041 |
\expandafter #1\expandafter #2\expandafter{% |
| 44042 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 44043 |
{\romannumeral`&&@\xintiiIsOne#3}}% |
| 44044 |
}% |
| 44045 |
\def\XINT_expr_func_factorial #1#2#3% |
| 44046 |
{% |
| 44047 |
\expandafter #1\expandafter #2\expandafter{\expandafter{% |
| 44048 |
\romannumeral`&&@\XINT:NEhook:f:one:and:opt:direct |
| 44049 |
\XINT:expr:f:one:and:opt #3,!\xintFac\XINTinFloatFac |
| 44050 |
}}% |
| 44051 |
}% |
| 44052 |
\def\XINT_flexpr_func_factorial #1#2#3% |
| 44053 |
{% |
| 44054 |
\expandafter #1\expandafter #2\expandafter{\expandafter{% |
| 44055 |
\romannumeral`&&@\XINT:NEhook:f:one:and:opt:direct |
| 44056 |
\XINT:expr:f:one:and:opt#3,!\XINTinFloatFacdigits\XINTinFloatFac |
| 44057 |
}}% |
| 44058 |
}% |
| 44059 |
\def\XINT_iiexpr_func_factorial #1#2#3% |
| 44060 |
{% |
| 44061 |
\expandafter #1\expandafter #2\expandafter{% |
| 44062 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 44063 |
{\romannumeral`&&@\xintiiFac#3}}% |
| 44064 |
}% |
| 44065 |
\def\XINT_expr_func_sqrt #1#2#3% |
| 44066 |
{% |
| 44067 |
\expandafter #1\expandafter #2\expandafter{\expandafter{% |
| 44068 |
\romannumeral`&&@\XINT:NEhook:f:one:and:opt:direct |
| 44069 |
\XINT:expr:f:one:and:opt #3,!\XINTinFloatSqrtdigits\XINTinFloatSqrt |
| 44070 |
}}% |
| 44071 |
}% |
| 44072 |
\let\XINT_flexpr_func_sqrt\XINT_expr_func_sqrt |
| 44073 |
\def\XINT_iiexpr_func_sqrt #1#2#3% |
| 44074 |
{% |
| 44075 |
\expandafter #1\expandafter #2\expandafter{% |
| 44076 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 44077 |
{\romannumeral`&&@\xintiiSqrt#3}}% |
| 44078 |
}% |
| 44079 |
\def\XINT_iiexpr_func_sqrtr #1#2#3% |
| 44080 |
{% |
| 44081 |
\expandafter #1\expandafter #2\expandafter{% |
| 44082 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 44083 |
{\romannumeral`&&@\xintiiSqrtR#3}}% |
| 44084 |
}% |
| 44085 |
\def\XINT_expr_func_inv #1#2#3% |
| 44086 |
{% |
| 44087 |
\expandafter #1\expandafter #2\expandafter{% |
| 44088 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 44089 |
{\romannumeral`&&@\xintInv#3}}% |
| 44090 |
}% |
| 44091 |
\def\XINT_flexpr_func_inv #1#2#3% |
| 44092 |
{% |
| 44093 |
\expandafter #1\expandafter #2\expandafter{% |
| 44094 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 44095 |
{\romannumeral`&&@\XINTinFloatInv#3}}% |
| 44096 |
}% |
| 44097 |
\def\XINT_expr_func_round #1#2#3% |
| 44098 |
{% |
| 44099 |
\expandafter #1\expandafter #2\expandafter{\expandafter{% |
| 44100 |
\romannumeral`&&@\XINT:NEhook:f:tacitzeroifone:direct |
| 44101 |
\XINT:expr:f:tacitzeroifone #3,!\xintiRound\xintRound |
| 44102 |
}}% |
| 44103 |
}% |
| 44104 |
\let\XINT_flexpr_func_round\XINT_expr_func_round |
| 44105 |
\def\XINT_iiexpr_func_round #1#2#3% |
| 44106 |
{% |
| 44107 |
\expandafter #1\expandafter #2\expandafter{\expandafter{% |
| 44108 |
\romannumeral`&&@\XINT:NEhook:f:iitacitzeroifone:direct |
| 44109 |
\XINT:expr:f:iitacitzeroifone #3,!\xintiRound |
| 44110 |
}}% |
| 44111 |
}% |
| 44112 |
\def\XINT_expr_func_trunc #1#2#3% |
| 44113 |
{% |
| 44114 |
\expandafter #1\expandafter #2\expandafter{\expandafter{% |
| 44115 |
\romannumeral`&&@\XINT:NEhook:f:tacitzeroifone:direct |
| 44116 |
\XINT:expr:f:tacitzeroifone #3,!\xintiTrunc\xintTrunc |
| 44117 |
}}% |
| 44118 |
}% |
| 44119 |
\let\XINT_flexpr_func_trunc\XINT_expr_func_trunc |
| 44120 |
\def\XINT_iiexpr_func_trunc #1#2#3% |
| 44121 |
{% |
| 44122 |
\expandafter #1\expandafter #2\expandafter{\expandafter{% |
| 44123 |
\romannumeral`&&@\XINT:NEhook:f:iitacitzeroifone:direct |
| 44124 |
\XINT:expr:f:iitacitzeroifone #3,!\xintiTrunc |
| 44125 |
}}% |
| 44126 |
}% |
| 44127 |
% \end{macrocode} |
| 44128 |
%\begin{lverb} |
| 44129 |
% Hesitation at 1.3e about using \XINTinFloatSdigits and \XINTinFloatS. |
| 44130 |
% Finally I add a sfloat() function. It helps for xinttrig.sty. |
| 44131 |
%\end{lverb} |
| 44132 |
% \begin{macrocode} |
| 44133 |
\def\XINT_expr_func_float #1#2#3% |
| 44134 |
{% |
| 44135 |
\expandafter #1\expandafter #2\expandafter{\expandafter{% |
| 44136 |
\romannumeral`&&@\XINT:NEhook:f:one:and:opt:direct |
| 44137 |
\XINT:expr:f:one:and:opt #3,!\XINTinFloatdigits\XINTinFloat |
| 44138 |
}}% |
| 44139 |
}% |
| 44140 |
\let\XINT_flexpr_func_float\XINT_expr_func_float |
| 44141 |
% \end{macrocode} |
| 44142 |
%\begin{lverb} |
| 44143 |
% float_() was added at 1.4, as a shortcut alias to float() skipping the check |
| 44144 |
% for an optional second argument. This is useful to transfer function |
| 44145 |
% definitions between \xintexpr and \xintfloatexpr contexts. |
| 44146 |
% |
| 44147 |
% |
| 44148 |
% No need for a similar shortcut for sfloat() as currently used in |
| 44149 |
% xinttrig.sty to go from float to expr: as it is used there as sfloat(x) with |
| 44150 |
% dummy x, it sees there is no optional argument, contrarily to for example |
| 44151 |
% float(\xintexpr...\relax) which has to allow for the inner expression to |
| 44152 |
% expand to an ople with two items, so does not know in which branch it is at |
| 44153 |
% time of definiion. |
| 44154 |
% |
| 44155 |
% |
| 44156 |
% After some hesitation at 1.4e regarding guard digits mechanism the float_() |
| 44157 |
% got renamed to float_dgt(), but then renamed back to float_() to avoid a |
| 44158 |
% breaking change and having to document it. |
| 44159 |
% |
| 44160 |
% Nevertheless the documentation of 1.4e mentioned float_dgt()... but it was still |
| 44161 |
% float_()... now changed into float_dgt() for real at 1.4f. |
| 44162 |
% |
| 44163 |
% 1.4f also adds private float_dgtormax and sfloat_dgtormax for matters of xinttrig. |
| 44164 |
% |
| 44165 |
%\end{lverb} |
| 44166 |
% \begin{macrocode} |
| 44167 |
\def\XINT_expr_func_float_dgt #1#2#3% |
| 44168 |
{% |
| 44169 |
\expandafter #1\expandafter #2\expandafter{% |
| 44170 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 44171 |
{\romannumeral`&&@\XINTinFloatdigits#3}}% |
| 44172 |
}% |
| 44173 |
\let\XINT_flexpr_func_float_dgt\XINT_expr_func_float_dgt |
| 44174 |
% no \XINT_iiexpr_func_float_dgt |
| 44175 |
\def\XINT_expr_func_float_dgtormax #1#2#3% |
| 44176 |
{% |
| 44177 |
\expandafter #1\expandafter #2\expandafter{% |
| 44178 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 44179 |
{\romannumeral`&&@\XINTinFloatdigitsormax#3}}% |
| 44180 |
}% |
| 44181 |
\let\XINT_flexpr_func_float_dgtormax\XINT_expr_func_float_dgtormax |
| 44182 |
\def\XINT_expr_func_sfloat #1#2#3% |
| 44183 |
{% |
| 44184 |
\expandafter #1\expandafter #2\expandafter{\expandafter{% |
| 44185 |
\romannumeral`&&@\XINT:NEhook:f:one:and:opt:direct |
| 44186 |
\XINT:expr:f:one:and:opt #3,!\XINTinFloatSdigits\XINTinFloatS |
| 44187 |
}}% |
| 44188 |
}% |
| 44189 |
\let\XINT_flexpr_func_sfloat\XINT_expr_func_sfloat |
| 44190 |
% no \XINT_iiexpr_func_sfloat |
| 44191 |
\def\XINT_expr_func_sfloat_dgtormax #1#2#3% |
| 44192 |
{% |
| 44193 |
\expandafter #1\expandafter #2\expandafter{% |
| 44194 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 44195 |
{\romannumeral`&&@\XINTinFloatSdigitsormax#3}}% |
| 44196 |
}% |
| 44197 |
\let\XINT_flexpr_func_sfloat_dgtormax\XINT_expr_func_sfloat_dgtormax |
| 44198 |
\expandafter\def\csname XINT_expr_func_ilog10\endcsname #1#2#3% |
| 44199 |
{% |
| 44200 |
\expandafter #1\expandafter #2\expandafter{\expandafter{% |
| 44201 |
\romannumeral`&&@\XINT:NEhook:f:one:and:opt:direct |
| 44202 |
\XINT:expr:f:one:and:opt #3,!\xintiLogTen\XINTFloatiLogTen |
| 44203 |
}}% |
| 44204 |
}% |
| 44205 |
\expandafter\def\csname XINT_flexpr_func_ilog10\endcsname #1#2#3% |
| 44206 |
{% |
| 44207 |
\expandafter #1\expandafter #2\expandafter{\expandafter{% |
| 44208 |
\romannumeral`&&@\XINT:NEhook:f:one:and:opt:direct |
| 44209 |
\XINT:expr:f:one:and:opt #3,!\XINTFloatiLogTendigits\XINTFloatiLogTen |
| 44210 |
}}% |
| 44211 |
}% |
| 44212 |
\expandafter\def\csname XINT_iiexpr_func_ilog10\endcsname #1#2#3% |
| 44213 |
{% |
| 44214 |
\expandafter #1\expandafter #2\expandafter{% |
| 44215 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 44216 |
{\romannumeral`&&@\xintiiLogTen#3}}% |
| 44217 |
}% |
| 44218 |
\def\XINT_expr_func_divmod #1#2#3% |
| 44219 |
{% |
| 44220 |
\expandafter #1\expandafter #2\expandafter{\romannumeral`&&@% |
| 44221 |
\XINT:NEhook:f:one:from:two |
| 44222 |
{\romannumeral`&&@\xintDivMod #3}}% |
| 44223 |
}% |
| 44224 |
\def\XINT_flexpr_func_divmod #1#2#3% |
| 44225 |
{% |
| 44226 |
\expandafter #1\expandafter #2\expandafter{\romannumeral`&&@% |
| 44227 |
\XINT:NEhook:f:one:from:two |
| 44228 |
{\romannumeral`&&@\XINTinFloatDivMod #3}}% |
| 44229 |
}% |
| 44230 |
\def\XINT_iiexpr_func_divmod #1#2#3% |
| 44231 |
{% |
| 44232 |
\expandafter #1\expandafter #2\expandafter{\romannumeral`&&@% |
| 44233 |
\XINT:NEhook:f:one:from:two |
| 44234 |
{\romannumeral`&&@\xintiiDivMod #3}}% |
| 44235 |
}% |
| 44236 |
\def\XINT_expr_func_mod #1#2#3% |
| 44237 |
{% |
| 44238 |
\expandafter #1\expandafter #2\expandafter{\romannumeral`&&@% |
| 44239 |
\XINT:NEhook:f:one:from:two |
| 44240 |
{\romannumeral`&&@\xintMod#3}}% |
| 44241 |
}% |
| 44242 |
\def\XINT_flexpr_func_mod #1#2#3% |
| 44243 |
{% |
| 44244 |
\expandafter #1\expandafter #2\expandafter{\romannumeral`&&@% |
| 44245 |
\XINT:NEhook:f:one:from:two |
| 44246 |
{\romannumeral`&&@\XINTinFloatMod#3}}% |
| 44247 |
}% |
| 44248 |
\def\XINT_iiexpr_func_mod #1#2#3% |
| 44249 |
{% |
| 44250 |
\expandafter #1\expandafter #2\expandafter{\romannumeral`&&@% |
| 44251 |
\XINT:NEhook:f:one:from:two |
| 44252 |
{\romannumeral`&&@\xintiiMod#3}}% |
| 44253 |
}% |
| 44254 |
\def\XINT_expr_func_binomial #1#2#3% |
| 44255 |
{% |
| 44256 |
\expandafter #1\expandafter #2\expandafter{\romannumeral`&&@% |
| 44257 |
\XINT:NEhook:f:one:from:two |
| 44258 |
{\romannumeral`&&@\xintBinomial #3}}% |
| 44259 |
}% |
| 44260 |
\def\XINT_flexpr_func_binomial #1#2#3% |
| 44261 |
{% |
| 44262 |
\expandafter #1\expandafter #2\expandafter{\romannumeral`&&@% |
| 44263 |
\XINT:NEhook:f:one:from:two |
| 44264 |
{\romannumeral`&&@\XINTinFloatBinomial #3}}% |
| 44265 |
}% |
| 44266 |
\def\XINT_iiexpr_func_binomial #1#2#3% |
| 44267 |
{% |
| 44268 |
\expandafter #1\expandafter #2\expandafter{\romannumeral`&&@% |
| 44269 |
\XINT:NEhook:f:one:from:two |
| 44270 |
{\romannumeral`&&@\xintiiBinomial #3}}% |
| 44271 |
}% |
| 44272 |
\def\XINT_expr_func_pfactorial #1#2#3% |
| 44273 |
{% |
| 44274 |
\expandafter #1\expandafter #2\expandafter{\romannumeral`&&@% |
| 44275 |
\XINT:NEhook:f:one:from:two |
| 44276 |
{\romannumeral`&&@\xintPFactorial #3}}% |
| 44277 |
}% |
| 44278 |
\def\XINT_flexpr_func_pfactorial #1#2#3% |
| 44279 |
{% |
| 44280 |
\expandafter #1\expandafter #2\expandafter{\romannumeral`&&@% |
| 44281 |
\XINT:NEhook:f:one:from:two |
| 44282 |
{\romannumeral`&&@\XINTinFloatPFactorial #3}}% |
| 44283 |
}% |
| 44284 |
\def\XINT_iiexpr_func_pfactorial #1#2#3% |
| 44285 |
{% |
| 44286 |
\expandafter #1\expandafter #2\expandafter{\romannumeral`&&@% |
| 44287 |
\XINT:NEhook:f:one:from:two |
| 44288 |
{\romannumeral`&&@\xintiiPFactorial #3}}% |
| 44289 |
}% |
| 44290 |
\def\XINT_expr_func_randrange #1#2#3% |
| 44291 |
{% |
| 44292 |
\expandafter #1\expandafter #2\expanded{{{% |
| 44293 |
\XINT:expr:randrange #3,!% |
| 44294 |
}}}% |
| 44295 |
}% |
| 44296 |
\let\XINT_flexpr_func_randrange\XINT_expr_func_randrange |
| 44297 |
\def\XINT_iiexpr_func_randrange #1#2#3% |
| 44298 |
{% |
| 44299 |
\expandafter #1\expandafter #2\expanded{{{% |
| 44300 |
\XINT:iiexpr:randrange #3,!% |
| 44301 |
}}}% |
| 44302 |
}% |
| 44303 |
\def\XINT:expr:randrange #1#2#3!% |
| 44304 |
{% |
| 44305 |
\if\relax#3\relax\expandafter\xint_firstoftwo\else |
| 44306 |
\expandafter\xint_secondoftwo\fi |
| 44307 |
{\xintiiRandRange{\XINT:NEhook:f:one:from:one:direct\xintNum{#1}}}% |
| 44308 |
{\xintiiRandRangeAtoB{\XINT:NEhook:f:one:from:one:direct\xintNum{#1}}% |
| 44309 |
{\XINT:NEhook:f:one:from:one:direct\xintNum{#2}}% |
| 44310 |
}% |
| 44311 |
}% |
| 44312 |
\def\XINT:iiexpr:randrange #1#2#3!% |
| 44313 |
{% |
| 44314 |
\if\relax#3\relax\expandafter\xint_firstoftwo\else |
| 44315 |
\expandafter\xint_secondoftwo\fi |
| 44316 |
{\xintiiRandRange{#1}}% |
| 44317 |
{\xintiiRandRangeAtoB{#1}{#2}}% |
| 44318 |
}% |
| 44319 |
\def\XINT_iiexpr_func_iquo #1#2#3% |
| 44320 |
{% |
| 44321 |
\expandafter #1\expandafter #2\expandafter{\romannumeral`&&@% |
| 44322 |
\XINT:NEhook:f:one:from:two |
| 44323 |
{\romannumeral`&&@\xintiiQuo #3}}% |
| 44324 |
}% |
| 44325 |
\def\XINT_iiexpr_func_irem #1#2#3% |
| 44326 |
{% |
| 44327 |
\expandafter #1\expandafter #2\expandafter{\romannumeral`&&@% |
| 44328 |
\XINT:NEhook:f:one:from:two |
| 44329 |
{\romannumeral`&&@\xintiiRem #3}}% |
| 44330 |
}% |
| 44331 |
\def\XINT_expr_func_gcd #1#2#3% |
| 44332 |
{% |
| 44333 |
\expandafter #1\expandafter #2\expandafter{\expandafter |
| 44334 |
{\romannumeral`&&@\XINT:NEhook:f:from:delim:u\XINT_GCDof#3^}}% |
| 44335 |
}% |
| 44336 |
\let\XINT_flexpr_func_gcd\XINT_expr_func_gcd |
| 44337 |
\def\XINT_iiexpr_func_gcd #1#2#3% |
| 44338 |
{% |
| 44339 |
\expandafter #1\expandafter #2\expandafter{\expandafter |
| 44340 |
{\romannumeral`&&@\XINT:NEhook:f:from:delim:u\XINT_iiGCDof#3^}}% |
| 44341 |
}% |
| 44342 |
\def\XINT_expr_func_lcm #1#2#3% |
| 44343 |
{% |
| 44344 |
\expandafter #1\expandafter #2\expandafter{\expandafter |
| 44345 |
{\romannumeral`&&@\XINT:NEhook:f:from:delim:u\XINT_LCMof#3^}}% |
| 44346 |
}% |
| 44347 |
\let\XINT_flexpr_func_lcm\XINT_expr_func_lcm |
| 44348 |
\def\XINT_iiexpr_func_lcm #1#2#3% |
| 44349 |
{% |
| 44350 |
\expandafter #1\expandafter #2\expandafter{\expandafter |
| 44351 |
{\romannumeral`&&@\XINT:NEhook:f:from:delim:u\XINT_iiLCMof#3^}}% |
| 44352 |
}% |
| 44353 |
\def\XINT_expr_func_max #1#2#3% |
| 44354 |
{% |
| 44355 |
\expandafter #1\expandafter #2\expandafter{\expandafter |
| 44356 |
{\romannumeral`&&@\XINT:NEhook:f:from:delim:u\XINT_Maxof#3^}}% |
| 44357 |
}% |
| 44358 |
\def\XINT_iiexpr_func_max #1#2#3% |
| 44359 |
{% |
| 44360 |
\expandafter #1\expandafter #2\expandafter{\expandafter |
| 44361 |
{\romannumeral`&&@\XINT:NEhook:f:from:delim:u\XINT_iiMaxof#3^}}% |
| 44362 |
}% |
| 44363 |
\def\XINT_flexpr_func_max #1#2#3% |
| 44364 |
{% |
| 44365 |
\expandafter #1\expandafter #2\expandafter{\expandafter |
| 44366 |
{\romannumeral`&&@\XINT:NEhook:f:from:delim:u\XINTinFloatMaxof#3^}}% |
| 44367 |
}% |
| 44368 |
\def\XINT_expr_func_min #1#2#3% |
| 44369 |
{% |
| 44370 |
\expandafter #1\expandafter #2\expandafter{\expandafter |
| 44371 |
{\romannumeral`&&@\XINT:NEhook:f:from:delim:u\XINT_Minof#3^}}% |
| 44372 |
}% |
| 44373 |
\def\XINT_iiexpr_func_min #1#2#3% |
| 44374 |
{% |
| 44375 |
\expandafter #1\expandafter #2\expandafter{\expandafter |
| 44376 |
{\romannumeral`&&@\XINT:NEhook:f:from:delim:u\XINT_iiMinof#3^}}% |
| 44377 |
}% |
| 44378 |
\def\XINT_flexpr_func_min #1#2#3% |
| 44379 |
{% |
| 44380 |
\expandafter #1\expandafter #2\expandafter{\expandafter |
| 44381 |
{\romannumeral`&&@\XINT:NEhook:f:from:delim:u\XINTinFloatMinof#3^}}% |
| 44382 |
}% |
| 44383 |
\expandafter |
| 44384 |
\def\csname XINT_expr_func_+\endcsname #1#2#3% |
| 44385 |
{% |
| 44386 |
\expandafter #1\expandafter #2\expandafter{\expandafter |
| 44387 |
{\romannumeral`&&@\XINT:NEhook:f:from:delim:u\XINT_Sum#3^}}% |
| 44388 |
}% |
| 44389 |
\expandafter |
| 44390 |
\def\csname XINT_flexpr_func_+\endcsname #1#2#3% |
| 44391 |
{% |
| 44392 |
\expandafter #1\expandafter #2\expandafter{\expandafter |
| 44393 |
{\romannumeral`&&@\XINT:NEhook:f:from:delim:u\XINTinFloatSum#3^}}% |
| 44394 |
}% |
| 44395 |
\expandafter |
| 44396 |
\def\csname XINT_iiexpr_func_+\endcsname #1#2#3% |
| 44397 |
{% |
| 44398 |
\expandafter #1\expandafter #2\expandafter{\expandafter |
| 44399 |
{\romannumeral`&&@\XINT:NEhook:f:from:delim:u\XINT_iiSum#3^}}% |
| 44400 |
}% |
| 44401 |
\expandafter |
| 44402 |
\def\csname XINT_expr_func_*\endcsname #1#2#3% |
| 44403 |
{% |
| 44404 |
\expandafter #1\expandafter #2\expandafter{\expandafter |
| 44405 |
{\romannumeral`&&@\XINT:NEhook:f:from:delim:u\XINT_Prd#3^}}% |
| 44406 |
}% |
| 44407 |
\expandafter |
| 44408 |
\def\csname XINT_flexpr_func_*\endcsname #1#2#3% |
| 44409 |
{% |
| 44410 |
\expandafter #1\expandafter #2\expandafter{\expandafter |
| 44411 |
{\romannumeral`&&@\XINT:NEhook:f:from:delim:u\XINTinFloatPrd#3^}}% |
| 44412 |
}% |
| 44413 |
\expandafter |
| 44414 |
\def\csname XINT_iiexpr_func_*\endcsname #1#2#3% |
| 44415 |
{% |
| 44416 |
\expandafter #1\expandafter #2\expandafter{\expandafter |
| 44417 |
{\romannumeral`&&@\XINT:NEhook:f:from:delim:u\XINT_iiPrd#3^}}% |
| 44418 |
}% |
| 44419 |
\def\XINT_expr_func_all #1#2#3% |
| 44420 |
{% |
| 44421 |
\expandafter #1\expandafter #2\expandafter{\expandafter |
| 44422 |
{\romannumeral`&&@\XINT:NEhook:f:from:delim:u\XINT_ANDof#3^}}% |
| 44423 |
}% |
| 44424 |
\let\XINT_flexpr_func_all\XINT_expr_func_all |
| 44425 |
\let\XINT_iiexpr_func_all\XINT_expr_func_all |
| 44426 |
\def\XINT_expr_func_any #1#2#3% |
| 44427 |
{% |
| 44428 |
\expandafter #1\expandafter #2\expandafter{\expandafter |
| 44429 |
{\romannumeral`&&@\XINT:NEhook:f:from:delim:u\XINT_ORof#3^}}% |
| 44430 |
}% |
| 44431 |
\let\XINT_flexpr_func_any\XINT_expr_func_any |
| 44432 |
\let\XINT_iiexpr_func_any\XINT_expr_func_any |
| 44433 |
\def\XINT_expr_func_xor #1#2#3% |
| 44434 |
{% |
| 44435 |
\expandafter #1\expandafter #2\expandafter{\expandafter |
| 44436 |
{\romannumeral`&&@\XINT:NEhook:f:from:delim:u\XINT_XORof#3^}}% |
| 44437 |
}% |
| 44438 |
\let\XINT_flexpr_func_xor\XINT_expr_func_xor |
| 44439 |
\let\XINT_iiexpr_func_xor\XINT_expr_func_xor |
| 44440 |
\def\XINT_expr_func_len #1#2#3% |
| 44441 |
{% |
| 44442 |
\expandafter#1\expandafter#2\expandafter{\expandafter{% |
| 44443 |
\romannumeral`&&@\XINT:NEhook:f:LFL\xintLength |
| 44444 |
{\romannumeral\XINT:NEhook:r:check#3^}% |
| 44445 |
}}% |
| 44446 |
}% |
| 44447 |
\let\XINT_flexpr_func_len \XINT_expr_func_len |
| 44448 |
\let\XINT_iiexpr_func_len \XINT_expr_func_len |
| 44449 |
\def\XINT_expr_func_first #1#2#3% |
| 44450 |
{% |
| 44451 |
\expandafter #1\expandafter #2\expandafter{% |
| 44452 |
\romannumeral`&&@\XINT:NEhook:f:LFL\xintFirstOne |
| 44453 |
{\romannumeral\XINT:NEhook:r:check#3^}% |
| 44454 |
}% |
| 44455 |
}% |
| 44456 |
\let\XINT_flexpr_func_first\XINT_expr_func_first |
| 44457 |
\let\XINT_iiexpr_func_first\XINT_expr_func_first |
| 44458 |
\def\XINT_expr_func_last #1#2#3% |
| 44459 |
{% |
| 44460 |
\expandafter #1\expandafter #2\expandafter{% |
| 44461 |
\romannumeral`&&@\XINT:NEhook:f:LFL\xintLastOne |
| 44462 |
{\romannumeral\XINT:NEhook:r:check#3^}% |
| 44463 |
}% |
| 44464 |
}% |
| 44465 |
\let\XINT_flexpr_func_last\XINT_expr_func_last |
| 44466 |
\let\XINT_iiexpr_func_last\XINT_expr_func_last |
| 44467 |
\def\XINT_expr_func_reversed #1#2#3% |
| 44468 |
{% |
| 44469 |
\expandafter #1\expandafter #2\expandafter{% |
| 44470 |
\romannumeral`&&@\XINT:NEhook:f:reverse\XINT_expr_reverse |
| 44471 |
#3^^#3\xint:\xint:\xint:\xint: |
| 44472 |
\xint:\xint:\xint:\xint:\xint_bye |
| 44473 |
}% |
| 44474 |
}% |
| 44475 |
\def\XINT_expr_reverse #1#2% |
| 44476 |
{% |
| 44477 |
\if ^\noexpand#2% |
| 44478 |
\expandafter\XINT_expr_reverse:_one_or_none\string#1.% |
| 44479 |
\else |
| 44480 |
\expandafter\XINT_expr_reverse:_at_least_two |
| 44481 |
\fi |
| 44482 |
}% |
| 44483 |
\def\XINT_expr_reverse:_at_least_two #1^^{\XINT_revwbr_loop {}}% |
| 44484 |
\def\XINT_expr_reverse:_one_or_none #1% |
| 44485 |
{% |
| 44486 |
\if #1\bgroup\xint_dothis\XINT_expr_reverse:_nutple\fi |
| 44487 |
\if #1^\xint_dothis\XINT_expr_reverse:_nil\fi |
| 44488 |
\xint_orthat\XINT_expr_reverse:_leaf |
| 44489 |
}% |
| 44490 |
\edef\XINT_expr_reverse:_nil #1\xint_bye{\noexpand\fi\space}% |
| 44491 |
\def\XINT_expr_reverse:_leaf#1\fi #2\xint:#3\xint_bye{\fi\xint_gob_andstop_i#2}% |
| 44492 |
\def\XINT_expr_reverse:_nutple% |
| 44493 |
{% |
| 44494 |
\expandafter\XINT_expr_reverse:_nutple_a\expandafter{\string}% |
| 44495 |
}% |
| 44496 |
\def\XINT_expr_reverse:_nutple_a #1^#2\xint:#3\xint_bye |
| 44497 |
{% |
| 44498 |
\fi\expandafter |
| 44499 |
{\romannumeral0\XINT_revwbr_loop{}#2\xint:#3\xint_bye}% |
| 44500 |
}% |
| 44501 |
\let\XINT_flexpr_func_reversed\XINT_expr_func_reversed |
| 44502 |
\let\XINT_iiexpr_func_reversed\XINT_expr_func_reversed |
| 44503 |
\def\XINT_expr_func_if #1#2#3% |
| 44504 |
{% |
| 44505 |
\expandafter #1\expandafter #2\expandafter{% |
| 44506 |
\romannumeral`&&@\XINT:NEhook:branch{\romannumeral`&&@\xintiiifNotZero #3}}% |
| 44507 |
}% |
| 44508 |
\let\XINT_flexpr_func_if\XINT_expr_func_if |
| 44509 |
\let\XINT_iiexpr_func_if\XINT_expr_func_if |
| 44510 |
\def\XINT_expr_func_ifint #1#2#3% |
| 44511 |
{% |
| 44512 |
\expandafter #1\expandafter #2\expandafter{% |
| 44513 |
\romannumeral`&&@\XINT:NEhook:branch{\romannumeral`&&@\xintifInt #3}}% |
| 44514 |
}% |
| 44515 |
\let\XINT_iiexpr_func_ifint\XINT_expr_func_ifint |
| 44516 |
\def\XINT_flexpr_func_ifint #1#2#3% |
| 44517 |
{% |
| 44518 |
\expandafter #1\expandafter #2\expandafter{% |
| 44519 |
\romannumeral`&&@\XINT:NEhook:branch{\romannumeral`&&@\xintifFloatInt #3}}% |
| 44520 |
}% |
| 44521 |
\def\XINT_expr_func_ifone #1#2#3% |
| 44522 |
{% |
| 44523 |
\expandafter #1\expandafter #2\expandafter{% |
| 44524 |
\romannumeral`&&@\XINT:NEhook:branch{\romannumeral`&&@\xintifOne #3}}% |
| 44525 |
}% |
| 44526 |
\let\XINT_flexpr_func_ifone\XINT_expr_func_ifone |
| 44527 |
\def\XINT_iiexpr_func_ifone #1#2#3% |
| 44528 |
{% |
| 44529 |
\expandafter #1\expandafter #2\expandafter{% |
| 44530 |
\romannumeral`&&@\XINT:NEhook:branch{\romannumeral`&&@\xintiiifOne #3}}% |
| 44531 |
}% |
| 44532 |
\def\XINT_expr_func_ifsgn #1#2#3% |
| 44533 |
{% |
| 44534 |
\expandafter #1\expandafter #2\expandafter{% |
| 44535 |
\romannumeral`&&@\XINT:NEhook:branch{\romannumeral`&&@\xintiiifSgn #3}}% |
| 44536 |
}% |
| 44537 |
\let\XINT_flexpr_func_ifsgn\XINT_expr_func_ifsgn |
| 44538 |
\let\XINT_iiexpr_func_ifsgn\XINT_expr_func_ifsgn |
| 44539 |
\def\XINT_expr_func_nuple #1#2#3{#1#2{{#3}}}% |
| 44540 |
\let\XINT_flexpr_func_nuple\XINT_expr_func_nuple |
| 44541 |
\let\XINT_iiexpr_func_nuple\XINT_expr_func_nuple |
| 44542 |
\def\XINT_expr_func_unpack #1#2%#3% |
| 44543 |
{\expandafter#1\expandafter#2\romannumeral0\XINT:NEhook:unpack}% |
| 44544 |
\let\XINT_flexpr_func_unpack\XINT_expr_func_unpack |
| 44545 |
\let\XINT_iiexpr_func_unpack\XINT_expr_func_unpack |
| 44546 |
\def\XINT_expr_func_flat #1#2%#3% |
| 44547 |
{% |
| 44548 |
\expandafter#1\expandafter#2\expanded |
| 44549 |
\XINT:NEhook:x:flatten\XINT:expr:flatten |
| 44550 |
}% |
| 44551 |
\let\XINT_flexpr_func_flat\XINT_expr_func_flat |
| 44552 |
\let\XINT_iiexpr_func_flat\XINT_expr_func_flat |
| 44553 |
\let\XINT:NEhook:x:flatten\empty |
| 44554 |
\def\XINT_expr_func_zip #1#2%#3% |
| 44555 |
{% |
| 44556 |
\expandafter#1\expandafter#2\romannumeral`&&@% |
| 44557 |
\XINT:NEhook:x:zip\XINT:expr:zip |
| 44558 |
}% |
| 44559 |
\let\XINT_flexpr_func_zip\XINT_expr_func_zip |
| 44560 |
\let\XINT_iiexpr_func_zip\XINT_expr_func_zip |
| 44561 |
\let\XINT:NEhook:x:zip\empty |
| 44562 |
\def\XINT:expr:zip#1{\expandafter{\expanded\XINT_zip_A#1\xint_bye\xint_bye}}% |
| 44563 |
% \end{macrocode} |
| 44564 |
% \subsection{User declared functions} |
| 44565 |
%\begin{lverb} |
| 44566 |
% It is possible that |
| 44567 |
% the author actually does understand at this time the |
| 44568 |
% \xintNewExpr/\xintdeffunc refactored code and mechanisms for the first time |
| 44569 |
% since 2014: past evolutions such as the 2018 1.3 refactoring were done a bit |
| 44570 |
% in the fog (although they did accomplish a crucial step). |
| 44571 |
% |
| 44572 |
% The 1.4 version of function and macro definitions is much more powerful than |
| 44573 |
% 1.3 one. But the mechanisms such as «omit», «abort» and «break()» in iter() |
| 44574 |
% et al. can't be translated into much else than their actual code when they |
| 44575 |
% potentially have to apply to non-numeric only context. The 1.4 \xintdeffunc |
| 44576 |
% is thus apparently able to digest them but its pre-parsing benefits are |
| 44577 |
% limited compared to simply assigning such parts of an expression to a |
| 44578 |
% mock-function created by \xintNewFunction (which creates simply a TeX macro |
| 44579 |
% from its substitution expression in macro parameters and add |
| 44580 |
% syntactic sugar to let it appear to \xintexpr as a genuine «function» |
| 44581 |
% although nothing of the syntax has really been pre-parsed.) |
| 44582 |
% |
| 44583 |
% At 1.4 fetching the expression up to final semi-colon is done using |
| 44584 |
% \XINT_expr_fetch_to_semicolon, hence semi-colons arising in the syntax do |
| 44585 |
% not need to be hidden inside braces. |
| 44586 |
%\end{lverb} |
| 44587 |
% |
| 44588 |
% \localtableofcontents |
| 44589 |
% |
| 44590 |
% \subsubsection{\csh{xintdeffunc}, \csh{xintdefiifunc}, |
| 44591 |
% \csh{xintdeffloatfunc}} |
| 44592 |
% |
| 44593 |
% \changed[2015/11/12]{1.2c} |
| 44594 |
%\begin{lverb} |
| 44595 |
% Note: it is possible to have same name assigned both to a variable |
| 44596 |
% and a function: things such as add(f(f), f=1..10) are possible. |
| 44597 |
%\end{lverb} |
| 44598 |
% |
| 44599 |
% \changed[2015/11/13]{1.2c} |
| 44600 |
%\begin{lverb} |
| 44601 |
% Function names first expanded then detokenized and cleaned of spaces. |
| 44602 |
%\end{lverb} |
| 44603 |
% |
| 44604 |
% \changed[2015/11/21]{1.2e} |
| 44605 |
%\begin{lverb} |
| 44606 |
% No \detokenize anymore on the function |
| 44607 |
% names. And #1(#2)#3=#4 parameter pattern to avoid to have to worry if a : is |
| 44608 |
% there and it is active. |
| 44609 |
%\end{lverb} |
| 44610 |
% |
| 44611 |
% \changed[2016/02/22]{1.2f} |
| 44612 |
%\begin{lverb} |
| 44613 |
% La macro associée à la fonction ne débute |
| 44614 |
% plus par un \romannumeral, car de toute façon elle est pour emploi dans |
| 44615 |
% \csname..\endcsname. |
| 44616 |
%\end{lverb} |
| 44617 |
% |
| 44618 |
% \changed[2016/03/08]{1.2f} |
| 44619 |
%\begin{lverb} |
| 44620 |
% Comma separated expressions allowed (formerly this required using |
| 44621 |
% parenthesis \xintdeffunc foo(x,..):=(.., .., ..); |
| 44622 |
%\end{lverb} |
| 44623 |
% |
| 44624 |
% \changed[2018/06/17]{1.3c} |
| 44625 |
%\begin{lverb} |
| 44626 |
% Usage of \xintexprSafeCatcodes to be compatible with an active |
| 44627 |
% semi-colon at time of use; the colon was not a problem (see ##3) already. |
| 44628 |
%\end{lverb} |
| 44629 |
% |
| 44630 |
% \changed{1.3e} |
| 44631 |
%\begin{lverb} |
| 44632 |
% \xintdefefunc variant added for functions which will expand |
| 44633 |
% completely if used with numeric arguments in other function definitions. |
| 44634 |
% They can't be used for recursive definitions. |
| 44635 |
% |
| 44636 |
% Their functionality was merged into \xintdeffunc et al. at 1.4. The |
| 44637 |
% original macros were removed at 1.4m. |
| 44638 |
%\end{lverb} |
| 44639 |
% |
| 44640 |
% \changed[2020/01/10]{1.4} |
| 44641 |
%\begin{lverb} |
| 44642 |
% Multi-letter variables can be used (with no prior declaration) |
| 44643 |
%\end{lverb} |
| 44644 |
% |
| 44645 |
% \changed[2020/01/11]{1.4} |
| 44646 |
%\begin{lverb} |
| 44647 |
% The new internal data model has caused many worries initially (such |
| 44648 |
% as whether to allow functions with «ople» outputs in contrast to «numbers» |
| 44649 |
% or «nutples») but in the end all is simpler again and the refactoring of ? |
| 44650 |
% and ?? in function definitions allows to fuse inert functions (allowing |
| 44651 |
% recursive definitions) and expanding functions (expanding completely if with |
| 44652 |
% numeric arguments) into a single entity. |
| 44653 |
% |
| 44654 |
% A special situation is with |
| 44655 |
% functions of no variables. In that case it will be handled as an inert |
| 44656 |
% entity, else they would not be different from variables. |
| 44657 |
% |
| 44658 |
%\end{lverb} |
| 44659 |
% |
| 44660 |
% \changed[2020/01/19]{1.4} |
| 44661 |
%\begin{lverb} |
| 44662 |
% Addition de la syntaxe déclarative \xintdeffunc foo(a,b,...,*z) = ...; |
| 44663 |
% |
| 44664 |
%\end{lverb} |
| 44665 |
% |
| 44666 |
% \changed[2022/06/05]{1.4m} |
| 44667 |
%\begin{lverb} |
| 44668 |
% Removal of the \xintdefefunc et al.$@ macros deprecated at 1.4. |
| 44669 |
%\end{lverb} |
| 44670 |
% \begin{macrocode} |
| 44671 |
\def\XINT_tmpa #1#2#3#4#5% |
| 44672 |
{% |
| 44673 |
\def #1##1(##2)##3={% |
| 44674 |
\edef\XINT_deffunc_tmpa {##1}% |
| 44675 |
\edef\XINT_deffunc_tmpa {\xint_zapspaces_o \XINT_deffunc_tmpa}% |
| 44676 |
\def\XINT_deffunc_tmpb {0}% |
| 44677 |
\edef\XINT_deffunc_tmpd {##2}% |
| 44678 |
\edef\XINT_deffunc_tmpd {\xint_zapspaces_o\XINT_deffunc_tmpd}% |
| 44679 |
\def\XINT_deffunc_tmpe {0}% |
| 44680 |
\expandafter#5\romannumeral\XINT_expr_fetch_to_semicolon |
| 44681 |
}% end of \xintdeffunc_a definition |
| 44682 |
\def#5##1{% |
| 44683 |
\def\XINT_deffunc_tmpc{(##1)}% |
| 44684 |
\ifnum\xintLength:f:csv{\XINT_deffunc_tmpd}>\xint_c_ |
| 44685 |
\xintFor ####1 in {\XINT_deffunc_tmpd}\do |
| 44686 |
{% |
| 44687 |
\xintifForFirst{\let\XINT_deffunc_tmpd\empty}{}% |
| 44688 |
\def\XINT_deffunc_tmpf{####1}% |
| 44689 |
\if*\xintFirstItem{####1}% |
| 44690 |
\xintifForLast |
| 44691 |
{% |
| 44692 |
\def\XINT_deffunc_tmpe{1}% |
| 44693 |
\edef\XINT_deffunc_tmpf{\xintTrim{1}{####1}}% |
| 44694 |
}% |
| 44695 |
{% |
| 44696 |
\edef\XINT_deffunc_tmpf{\xintTrim{1}{####1}}% |
| 44697 |
\xintMessage{xintexpr}{Error} |
| 44698 |
{Only the last positional argument can be variadic. Trimmed ####1 to |
| 44699 |
\XINT_deffunc_tmpf}% |
| 44700 |
}% |
| 44701 |
\fi |
| 44702 |
\XINT_expr_makedummy{\XINT_deffunc_tmpf}% |
| 44703 |
\edef\XINT_deffunc_tmpd{\XINT_deffunc_tmpd{\XINT_deffunc_tmpf}}% |
| 44704 |
\edef\XINT_deffunc_tmpb {\the\numexpr\XINT_deffunc_tmpb+\xint_c_i}% |
| 44705 |
\edef\XINT_deffunc_tmpc {subs(\xint_noxpd\expandafter{\XINT_deffunc_tmpc},% |
| 44706 |
\XINT_deffunc_tmpf=################\XINT_deffunc_tmpb)}% |
| 44707 |
}% |
| 44708 |
\fi |
| 44709 |
% \end{macrocode} |
| 44710 |
% Logic at |1.4| is simplified here compared to |
| 44711 |
% earlier releases. |
| 44712 |
% |
| 44713 |
% \changed{1.4n} |
| 44714 |
% Usage of \cs{xintmeaning} wrapper of engine's \cs{meaning}. See near |
| 44715 |
% \csbXINT{_NewExpr} for explanations. |
| 44716 |
% |
| 44717 |
% \begin{macrocode} |
| 44718 |
\ifcase\XINT_deffunc_tmpb\space |
| 44719 |
\expandafter\XINT_expr_defuserfunc_none\csname |
| 44720 |
\else |
| 44721 |
\expandafter\XINT_expr_defuserfunc\csname |
| 44722 |
\fi |
| 44723 |
XINT_#2_func_\XINT_deffunc_tmpa\expandafter\endcsname |
| 44724 |
\csname XINT_#2_userfunc_\XINT_deffunc_tmpa\expandafter\endcsname |
| 44725 |
\expandafter{\XINT_deffunc_tmpa}{#2}% |
| 44726 |
\expandafter#3\csname XINT_#2_userfunc_\XINT_deffunc_tmpa\endcsname |
| 44727 |
[\XINT_deffunc_tmpb]{\XINT_deffunc_tmpc}% |
| 44728 |
\ifxintverbose\xintMessage {xintexpr}{Info}% |
| 44729 |
{Function \XINT_deffunc_tmpa\space for \string\xint #4 parser |
| 44730 |
associated to \string\XINT_#2_userfunc_\XINT_deffunc_tmpa\space |
| 44731 |
with \ifxintglobaldefs global \fi meaning \expandafter\xintmeaning |
| 44732 |
\csname XINT_#2_userfunc_\XINT_deffunc_tmpa\endcsname}% |
| 44733 |
\fi |
| 44734 |
\xintFor* ####1 in {\XINT_deffunc_tmpd}:{\xintrestorevariablesilently{####1}}% |
| 44735 |
\xintexprRestoreCatcodes |
| 44736 |
}% end of \xintdeffunc_b definition |
| 44737 |
}% |
| 44738 |
\def\xintdeffunc {\xintexprSafeCatcodes\xintdeffunc_a}% |
| 44739 |
\def\xintdefiifunc {\xintexprSafeCatcodes\xintdefiifunc_a}% |
| 44740 |
\def\xintdeffloatfunc {\xintexprSafeCatcodes\xintdeffloatfunc_a}% |
| 44741 |
\XINT_tmpa\xintdeffunc_a {expr} \XINT_NewFunc {expr}\xintdeffunc_b |
| 44742 |
\XINT_tmpa\xintdefiifunc_a {iiexpr}\XINT_NewIIFunc {iiexpr}\xintdefiifunc_b |
| 44743 |
\XINT_tmpa\xintdeffloatfunc_a{flexpr}\XINT_NewFloatFunc{floatexpr}\xintdeffloatfunc_b |
| 44744 |
\def\XINT_expr_defuserfunc_none #1#2#3#4% |
| 44745 |
{% |
| 44746 |
\XINT_global |
| 44747 |
\def #1##1##2##3% |
| 44748 |
{% |
| 44749 |
\expandafter##1\expandafter##2\expanded{% |
| 44750 |
{\XINT:NEhook:usernoargfunc\csname XINT_#4_userfunc_#3\endcsname}% |
| 44751 |
}% |
| 44752 |
}% |
| 44753 |
}% |
| 44754 |
\let\XINT:NEhook:usernoargfunc \empty |
| 44755 |
\def\XINT_expr_defuserfunc #1#2#3#4% |
| 44756 |
{% |
| 44757 |
\if0\XINT_deffunc_tmpe |
| 44758 |
\XINT_global |
| 44759 |
\def #1##1##2%##3% |
| 44760 |
{% |
| 44761 |
\expandafter ##1\expandafter##2\expanded\bgroup{\iffalse}\fi |
| 44762 |
\XINT:NEhook:userfunc{XINT_#4_userfunc_#3}#2%##3% |
| 44763 |
}% |
| 44764 |
\else |
| 44765 |
% \end{macrocode} |
| 44766 |
%\begin{lverb} |
| 44767 |
% Last argument in the call signature is variadic (was prefixed by *). |
| 44768 |
%\end{lverb} |
| 44769 |
% \begin{macrocode} |
| 44770 |
\def #1##1{% |
| 44771 |
\XINT_global\def #1####1####2%####3% |
| 44772 |
{% |
| 44773 |
\expandafter ####1\expandafter####2\expanded\bgroup{\iffalse}\fi |
| 44774 |
\XINT:NEhook:userfunc:argv{##1}{XINT_#4_userfunc_#3}#2%####3% |
| 44775 |
}}\expandafter#1\expandafter{\the\numexpr\XINT_deffunc_tmpb-1}% |
| 44776 |
\fi |
| 44777 |
}% |
| 44778 |
% \end{macrocode} |
| 44779 |
%\begin{lverb} |
| 44780 |
% Deliberate brace stripping of #3 to reveal the elements of the ople, |
| 44781 |
% which may be atoms i.e. numeric data such as {1}, or again oples, which |
| 44782 |
% means that the corresponding item was a nutple, for example it came from |
| 44783 |
% input syntax such as foo(1, 2, [1, 2], 3), so (up to details of raw |
| 44784 |
% encoding) {1}{2}{{1}{2}}{3}, which gives 4 braced arguments to macro #2. |
| 44785 |
%\end{lverb} |
| 44786 |
% \begin{macrocode} |
| 44787 |
\def\XINT:NEhook:userfunc #1#2#3{#2#3\iffalse{{\fi}}}% |
| 44788 |
% \end{macrocode} |
| 44789 |
%\begin{lverb} |
| 44790 |
% Here #1 indicates the number k-1 of standard positional arguments of |
| 44791 |
% the call signature, the kth and last one having been declared of variadic |
| 44792 |
% type. The braces around \xintTrim{#1}{#4} have the effect to gather all |
| 44793 |
% these remaining elements to provide a single one to the TeX macro. |
| 44794 |
% |
| 44795 |
% For example input was foo(1,2,3,4,5) and call signature was foo(a,b,*z). |
| 44796 |
% Then #4 will fetch {{1}{2}{3}{4}{5}}, with one level of brace removal. |
| 44797 |
% We will have \xintKeep{2}{{1}{2}{3}{4}{5}} which produces {1}{2}. |
| 44798 |
% Then {\xintTrim{2}{{1}{2}{3}{4}{5}}} which produces {{3}{4}{5}}. |
| 44799 |
% So the macro will be used as \macro{1}{2}{{3}{4}{5}} having been |
| 44800 |
% declared as a macro with 3 arguments. |
| 44801 |
% |
| 44802 |
% The above comments were added in June 2021 but the code was done on January |
| 44803 |
% 19, 2020 for 1.4. |
| 44804 |
% |
| 44805 |
% Note on June 10, 2021: at core level \XINT_NewFunc is used which is derived |
| 44806 |
% from \XINT_NewExpr which has always prepared TeX macros with non-delimited |
| 44807 |
% parameters. A refactoring could add a final delimiter, for example \relax. |
| 44808 |
% The macro with 3 arguments would be defined as \def\macro#1#2#3\relax{...} |
| 44809 |
% for example. Then we could transfer to TeX core processing what is achieved |
| 44810 |
% here via \xintKeep/\xintTrim, of course adding efficiency, via insertion of |
| 44811 |
% the delimiter. In the case of foo(1,2,3,4,5) we would have the #3 of |
| 44812 |
% delimited \macro fetch {3}{4}{5}, no brace removal, which is equivalent to |
| 44813 |
% current situation fetching {{3}{4}{5}} with brace removal. But let's see in |
| 44814 |
% case of foo(1,2,3) then. This would lead to delimited \macro{1}{2}{3}\relax |
| 44815 |
% and #3 will fetch {3}, removing one brace pair. Whereas current |
| 44816 |
% non-delimited \macro is used as \macro{1}{2}{{3}} from the Keep/Trim, then |
| 44817 |
% #3 fetches {{3}}, removing one brace pair. Not the same thing. So it seems |
| 44818 |
% there is a stumbling-block here to adopt such an alternative method, in |
| 44819 |
% relation with brace removal. Rather relieved in fact, as my head starts |
| 44820 |
% spinning in ople world. Seems better to stop thinking about doing something |
| 44821 |
% like that, and what it would imply as consequences for user declarative |
| 44822 |
% interface also. Oples are dangerous to mental health, let's stick with |
| 44823 |
% one-ples: « named arguments in function body declaration must stand for |
| 44824 |
% one-ples », even the last one, although a priori it could be envisioned if |
| 44825 |
% foo has been declared with call signature (x,y,z) and is used with more |
| 44826 |
% items that z is mapped to the ople of extra elements beyond the first |
| 44827 |
% two ones. For my sanity I stick with my January 2020 concept of (x,y,*z) |
| 44828 |
% which makes z stand for a nutple always and having to be used as such in the |
| 44829 |
% function body (possibly unpacked there using *z). |
| 44830 |
%\end{lverb} |
| 44831 |
% \begin{macrocode} |
| 44832 |
\def\XINT:NEhook:userfunc:argv #1#2#3#4% |
| 44833 |
{\expandafter#3\expanded{\xintKeep{#1}{#4}{\xintTrim{#1}{#4}}}\iffalse{{\fi}}}% |
| 44834 |
% \end{macrocode} |
| 44835 |
% \subsubsection{\csh{xintdefufunc}, \csh{xintdefiiufunc}, |
| 44836 |
% \csh{xintdeffloatufunc}} |
| 44837 |
% |
| 44838 |
%\begin{lverb} |
| 44839 |
% Added at 1.4 |
| 44840 |
%\end{lverb} |
| 44841 |
% \changed[2022/05/15]{1.4k} |
| 44842 |
%\begin{lverb} |
| 44843 |
% \xintexprRestoreCatcodes was in only one branch of \xint_defufunc_b, |
| 44844 |
% and as a result sanitization of catcodes via \xintexprSafeCatcodes |
| 44845 |
% was never reverted. That the |
| 44846 |
% bug remained unseen and in particular did not break compilation of |
| 44847 |
% user manual (where the | must be active), was a sort of unhappy miracle |
| 44848 |
% due to the | ending up recovering its active catcode from some ulterior |
| 44849 |
% \xintdefiifunc whose Safe/Restore behaved as described in the user manual, |
| 44850 |
% i.e. it did a restore to the state before the first unpaired Safe, and this |
| 44851 |
% miraculous recovery happened before breakage had happened, by sheer luck, |
| 44852 |
% or rather lack of luck, else I would have seen and solved |
| 44853 |
% the problem two years ago... |
| 44854 |
%\end{lverb} |
| 44855 |
% \begin{macrocode} |
| 44856 |
\def\XINT_tmpa #1#2#3#4#5#6% |
| 44857 |
{% |
| 44858 |
\def #1##1(##2)##3={% |
| 44859 |
\edef\XINT_defufunc_tmpa {##1}% |
| 44860 |
\edef\XINT_defufunc_tmpa {\xint_zapspaces_o \XINT_defufunc_tmpa}% |
| 44861 |
\edef\XINT_defufunc_tmpd {##2}% |
| 44862 |
\edef\XINT_defufunc_tmpd {\xint_zapspaces_o\XINT_defufunc_tmpd}% |
| 44863 |
\expandafter#5\romannumeral\XINT_expr_fetch_to_semicolon |
| 44864 |
}% end of \xint_defufunc_a |
| 44865 |
\def#5##1{% |
| 44866 |
\def\XINT_defufunc_tmpc{(##1)}% |
| 44867 |
\ifnum\xintLength:f:csv{\XINT_defufunc_tmpd}=\xint_c_i |
| 44868 |
\expandafter#6% |
| 44869 |
\else |
| 44870 |
\xintMessage {xintexpr}{ERROR} |
| 44871 |
{Universal functions must be functions of one argument only, |
| 44872 |
but the declaration of \XINT_defufunc_tmpa\space |
| 44873 |
has \xintLength:f:csv{\XINT_defufunc_tmpd} of them. Canceled.}% |
| 44874 |
\xintexprRestoreCatcodes |
| 44875 |
\fi |
| 44876 |
}% end of \xint_defufunc_b |
| 44877 |
\def #6{% |
| 44878 |
\XINT_expr_makedummy{\XINT_defufunc_tmpd}% |
| 44879 |
\edef\XINT_defufunc_tmpc {subs(\xint_noxpd\expandafter{\XINT_defufunc_tmpc},% |
| 44880 |
\XINT_defufunc_tmpd=########1)}% |
| 44881 |
\expandafter\XINT_expr_defuserufunc |
| 44882 |
\csname XINT_#2_func_\XINT_defufunc_tmpa\expandafter\endcsname |
| 44883 |
\csname XINT_#2_userufunc_\XINT_defufunc_tmpa\expandafter\endcsname |
| 44884 |
\expandafter{\XINT_defufunc_tmpa}{#2}% |
| 44885 |
\expandafter#3\csname XINT_#2_userufunc_\XINT_defufunc_tmpa\endcsname |
| 44886 |
[1]{\XINT_defufunc_tmpc}% |
| 44887 |
\ifxintverbose\xintMessage {xintexpr}{Info}% |
| 44888 |
{Universal function \XINT_defufunc_tmpa\space for \string\xint #4 parser |
| 44889 |
associated to \string\XINT_#2_userufunc_\XINT_defufunc_tmpa\space |
| 44890 |
with \ifxintglobaldefs global \fi meaning \expandafter\xintmeaning |
| 44891 |
\csname XINT_#2_userufunc_\XINT_defufunc_tmpa\endcsname}% |
| 44892 |
\fi |
| 44893 |
\xintexprRestoreCatcodes |
| 44894 |
}% end of \xint_defufunc_c |
| 44895 |
}% |
| 44896 |
\def\xintdefufunc {\xintexprSafeCatcodes\xintdefufunc_a}% |
| 44897 |
\def\xintdefiiufunc {\xintexprSafeCatcodes\xintdefiiufunc_a}% |
| 44898 |
\def\xintdeffloatufunc {\xintexprSafeCatcodes\xintdeffloatufunc_a}% |
| 44899 |
\XINT_tmpa\xintdefufunc_a {expr} \XINT_NewFunc {expr}% |
| 44900 |
\xintdefufunc_b\xintdefufunc_c |
| 44901 |
\XINT_tmpa\xintdefiiufunc_a {iiexpr}\XINT_NewIIFunc {iiexpr}% |
| 44902 |
\xintdefiiufunc_b\xintdefiiufunc_c |
| 44903 |
\XINT_tmpa\xintdeffloatufunc_a{flexpr}\XINT_NewFloatFunc{floatexpr}% |
| 44904 |
\xintdeffloatufunc_b\xintdeffloatufunc_c |
| 44905 |
\def\XINT_expr_defuserufunc #1#2#3#4% |
| 44906 |
{% |
| 44907 |
\XINT_global |
| 44908 |
\def #1##1##2%##3% |
| 44909 |
{% |
| 44910 |
\expandafter ##1\expandafter##2\expanded |
| 44911 |
\XINT:NEhook:userufunc{XINT_#4_userufunc_#3}#2%##3% |
| 44912 |
}% |
| 44913 |
}% |
| 44914 |
\def\XINT:NEhook:userufunc #1{\XINT:expr:mapwithin}% |
| 44915 |
% \end{macrocode} |
| 44916 |
% |
| 44917 |
% \subsubsection{\csh{xintunassignexprfunc}, \csh{xintunassigniiexprfunc}, \csh{xintunassignfloatexprfunc}} |
| 44918 |
% See the \csbxint{unassignvar} for the embarrassing explanations why I had |
| 44919 |
% not done that earlier. A bit lazy here, no warning if undefining something |
| 44920 |
% not defined, and attention no precaution respective built-in functions. |
| 44921 |
% |
| 44922 |
% \begin{macrocode} |
| 44923 |
\def\XINT_tmpa #1{\expandafter\def\csname xintunassign#1func\endcsname ##1{% |
| 44924 |
\edef\XINT_unfunc_tmpa{##1}% |
| 44925 |
\edef\XINT_unfunc_tmpa {\xint_zapspaces_o\XINT_unfunc_tmpa}% |
| 44926 |
\XINT_global\expandafter |
| 44927 |
\let\csname XINT_#1_func_\XINT_unfunc_tmpa\endcsname\xint_undefined |
| 44928 |
\XINT_global\expandafter |
| 44929 |
\let\csname XINT_#1_userfunc_\XINT_unfunc_tmpa\endcsname\xint_undefined |
| 44930 |
\XINT_global\expandafter |
| 44931 |
\let\csname XINT_#1_userufunc_\XINT_unfunc_tmpa\endcsname\xint_undefined |
| 44932 |
\ifxintverbose\xintMessage {xintexpr}{Info}% |
| 44933 |
{Function \XINT_unfunc_tmpa\space for \string\xint #1 parser now |
| 44934 |
\ifxintglobaldefs globally \fi undefined.}% |
| 44935 |
\fi}}% |
| 44936 |
\XINT_tmpa{expr}\XINT_tmpa{iiexpr}\XINT_tmpa{floatexpr}% |
| 44937 |
% \end{macrocode} |
| 44938 |
% \subsubsection{\csh{xintNewFunction}} |
| 44939 |
%\begin{lverb} |
| 44940 |
% 1.2h (2016/11/20). Syntax is \xintNewFunction{<name>}[nb of |
| 44941 |
% arguments]{expression with #1, #2,... as in \xintNewExpr}. This defines |
| 44942 |
% a function for all three parsers but the expression parsing is delayed until |
| 44943 |
% function execution. Hence the expression admits all constructs, contrarily |
| 44944 |
% to \xintNewExpr or \xintdeffunc. |
| 44945 |
% |
| 44946 |
% As the letters used for variables in \xintdeffunc, #1, #2, etc... can not |
| 44947 |
% stand for non numeric «oples», because at time of function call f(a, b, c, |
| 44948 |
% ...) how to decide if #1 stands for a or a, b etc... ? Or course «a» can be |
| 44949 |
% packed and thus the macro function can handle #1 as a «nutple» and for this |
| 44950 |
% be defined with the * unpacking operator being applied to it. |
| 44951 |
%\end{lverb} |
| 44952 |
% \begin{macrocode} |
| 44953 |
\def\xintNewFunction #1#2[#3]#4% |
| 44954 |
{% |
| 44955 |
\edef\XINT_newfunc_tmpa {#1}% |
| 44956 |
\edef\XINT_newfunc_tmpa {\xint_zapspaces_o \XINT_newfunc_tmpa}% |
| 44957 |
\def\XINT_newfunc_tmpb ##1##2##3##4##5##6##7##8##9{#4}% |
| 44958 |
\begingroup |
| 44959 |
\ifcase #3\relax |
| 44960 |
\toks0{}% |
| 44961 |
\or \toks0{##1}% |
| 44962 |
\or \toks0{##1##2}% |
| 44963 |
\or \toks0{##1##2##3}% |
| 44964 |
\or \toks0{##1##2##3##4}% |
| 44965 |
\or \toks0{##1##2##3##4##5}% |
| 44966 |
\or \toks0{##1##2##3##4##5##6}% |
| 44967 |
\or \toks0{##1##2##3##4##5##6##7}% |
| 44968 |
\or \toks0{##1##2##3##4##5##6##7##8}% |
| 44969 |
\else \toks0{##1##2##3##4##5##6##7##8##9}% |
| 44970 |
\fi |
| 44971 |
\expandafter |
| 44972 |
\endgroup\expandafter |
| 44973 |
\XINT_global\expandafter |
| 44974 |
\def\csname XINT_expr_macrofunc_\XINT_newfunc_tmpa\expandafter\endcsname |
| 44975 |
\the\toks0\expandafter{\XINT_newfunc_tmpb |
| 44976 |
{\XINTfstop.{{##1}}}{\XINTfstop.{{##2}}}{\XINTfstop.{{##3}}}% |
| 44977 |
{\XINTfstop.{{##4}}}{\XINTfstop.{{##5}}}{\XINTfstop.{{##6}}}% |
| 44978 |
{\XINTfstop.{{##7}}}{\XINTfstop.{{##8}}}{\XINTfstop.{{##9}}}}% |
| 44979 |
\expandafter\XINT_expr_newfunction |
| 44980 |
\csname XINT_expr_func_\XINT_newfunc_tmpa\expandafter\endcsname |
| 44981 |
\expandafter{\XINT_newfunc_tmpa}\xintbareeval |
| 44982 |
\expandafter\XINT_expr_newfunction |
| 44983 |
\csname XINT_iiexpr_func_\XINT_newfunc_tmpa\expandafter\endcsname |
| 44984 |
\expandafter{\XINT_newfunc_tmpa}\xintbareiieval |
| 44985 |
\expandafter\XINT_expr_newfunction |
| 44986 |
\csname XINT_flexpr_func_\XINT_newfunc_tmpa\expandafter\endcsname |
| 44987 |
\expandafter{\XINT_newfunc_tmpa}\xintbarefloateval |
| 44988 |
\ifxintverbose |
| 44989 |
\xintMessage {xintexpr}{Info}% |
| 44990 |
{Function \XINT_newfunc_tmpa\space for the expression parsers is |
| 44991 |
associated to \string\XINT_expr_macrofunc_\XINT_newfunc_tmpa\space |
| 44992 |
with \ifxintglobaldefs global \fi meaning \expandafter\xintmeaning |
| 44993 |
\csname XINT_expr_macrofunc_\XINT_newfunc_tmpa\endcsname}% |
| 44994 |
\fi |
| 44995 |
}% |
| 44996 |
\def\XINT_expr_newfunction #1#2#3% |
| 44997 |
{% |
| 44998 |
\XINT_global |
| 44999 |
\def#1##1##2##3% |
| 45000 |
{\expandafter ##1\expandafter ##2% |
| 45001 |
\romannumeral0\XINT:NEhook:macrofunc |
| 45002 |
#3{\csname XINT_expr_macrofunc_#2\endcsname##3}\relax |
| 45003 |
}% |
| 45004 |
}% |
| 45005 |
\let\XINT:NEhook:macrofunc\empty |
| 45006 |
% \end{macrocode} |
| 45007 |
% \subsubsection{Mysterious stuff} |
| 45008 |
% |
| 45009 |
% There was an |\xintNewExpr| already in 1.07 from May 2013, which was |
| 45010 |
% modified in September 2013 to work with the \# macro parameter character, |
| 45011 |
% and then refactored into a more powerful version in June 2014 for 1.1 |
| 45012 |
% release of 2014/10/28. |
| 45013 |
% |
| 45014 |
% It is always too soon to try to comment and explain. In brief, this attempts |
| 45015 |
% to hack into the \emph{purely numeric} |\xintexpr| parsers to transform them |
| 45016 |
% into \emph{symbolic} parsers, allowing to do once and for all the parsing |
| 45017 |
% job and inherit a gigantic nested macro. Originally only f-expandable |
| 45018 |
% nesting. The initial motivation was that the |\csname| encapsulation impacted |
| 45019 |
% the string pool memory. Later this work proved to be the basis to provide |
| 45020 |
% support for implementing |
| 45021 |
% user-defined functions and it is now its main purpose. |
| 45022 |
% |
| 45023 |
% Deep refactorings happened at 1.3 and 1.4. |
| 45024 |
% |
| 45025 |
% At 1.3 the crucial idea of the «hook» macros was introduced, reducing |
| 45026 |
% considerably the preparatory work done by |\xintNewExpr|. |
| 45027 |
% |
| 45028 |
% At 1.4 further considerable simplifications happened, and it is possible |
| 45029 |
% that the author currently does at long last understand the code! |
| 45030 |
% |
| 45031 |
% The 1.3 code had serious complications with trying |
| 45032 |
% to identify would-be «list» arguments, distinguishing them from «single» |
| 45033 |
% arguments (things like parsing |#2+[[#1..[#3]..#4][#5:#6]]*#7| and convert |
| 45034 |
% it to a single nested f-exandable macro...) |
| 45035 |
% |
| 45036 |
% The conversion at 1.4 is both more powerful and simpler, due in part to the |
| 45037 |
% new storage model which from |\csname| encapsulated comma separated values |
| 45038 |
% up to 1.3f became simply a braced list of braced values, and also crucially |
| 45039 |
% due to the possibilities opened up by usage of |\expanded| primitive. |
| 45040 |
% |
| 45041 |
% \begin{macrocode} |
| 45042 |
\catcode`~ 12 |
| 45043 |
\def\XINT:NE:hastilde#1~#2#3\relax{\unless\if !#21\fi}% |
| 45044 |
\def\XINT:NE:hashash#1{% |
| 45045 |
\def\XINT:NE:hashash##1#1##2##3\relax{\unless\if !##21\fi}% |
| 45046 |
}\expandafter\XINT:NE:hashash\string#% |
| 45047 |
\def\XINT:NE:unpack #1{% |
| 45048 |
\def\XINT:NE:unpack ##1% |
| 45049 |
{% |
| 45050 |
\if0\XINT:NE:hastilde ##1~!\relax |
| 45051 |
\XINT:NE:hashash ##1#1!\relax 0\else |
| 45052 |
\expandafter\XINT:NE:unpack:p\fi |
| 45053 |
\xint_stop_atfirstofone{##1}% |
| 45054 |
}}\expandafter\XINT:NE:unpack\string#% |
| 45055 |
\def\XINT:NE:unpack:p#1#2% |
| 45056 |
{{~romannumeral0~expandafter~xint_stop_atfirstofone~expanded{#2}}}% |
| 45057 |
\def\XINT:NE:f:one:from:one #1{% |
| 45058 |
\def\XINT:NE:f:one:from:one ##1% |
| 45059 |
{% |
| 45060 |
\if0\XINT:NE:hastilde ##1~!\relax |
| 45061 |
\XINT:NE:hashash ##1#1!\relax 0\else |
| 45062 |
\xint_dothis\XINT:NE:f:one:from:one_a\fi |
| 45063 |
\xint_orthat\XINT:NE:f:one:from:one_b |
| 45064 |
##1&&A% |
| 45065 |
}}\expandafter\XINT:NE:f:one:from:one\string#% |
| 45066 |
\def\XINT:NE:f:one:from:one_a\romannumeral`&&@#1#2&&A% |
| 45067 |
{% |
| 45068 |
\expandafter{\detokenize{\expandafter#1}#2}% |
| 45069 |
}% |
| 45070 |
\def\XINT:NE:f:one:from:one_b#1{% |
| 45071 |
\def\XINT:NE:f:one:from:one_b\romannumeral`&&@##1##2&&A% |
| 45072 |
{% |
| 45073 |
\expandafter{\romannumeral`&&@% |
| 45074 |
\if0\XINT:NE:hastilde ##2~!\relax |
| 45075 |
\XINT:NE:hashash ##2#1!\relax 0\else |
| 45076 |
\expandafter\string\fi |
| 45077 |
##1{##2}}% |
| 45078 |
}}\expandafter\XINT:NE:f:one:from:one_b\string#% |
| 45079 |
\def\XINT:NE:f:one:from:one:direct #1#2{\XINT:NE:f:one:from:one:direct_a #2&&A{#1}}% |
| 45080 |
\def\XINT:NE:f:one:from:one:direct_a #1#2&&A#3% |
| 45081 |
{% |
| 45082 |
\if ###1\xint_dothis {\detokenize{#3}}\fi |
| 45083 |
\if ~#1\xint_dothis {\detokenize{#3}}\fi |
| 45084 |
\xint_orthat {#3}{#1#2}% |
| 45085 |
}% |
| 45086 |
\def\XINT:NE:f:one:from:two #1{% |
| 45087 |
\def\XINT:NE:f:one:from:two ##1% |
| 45088 |
{% |
| 45089 |
\if0\XINT:NE:hastilde ##1~!\relax |
| 45090 |
\XINT:NE:hashash ##1#1!\relax 0\else |
| 45091 |
\xint_dothis\XINT:NE:f:one:from:two_a\fi |
| 45092 |
\xint_orthat\XINT:NE:f:one:from:two_b ##1&&A% |
| 45093 |
}}\expandafter\XINT:NE:f:one:from:two\string#% |
| 45094 |
\def\XINT:NE:f:one:from:two_a\romannumeral`&&@#1#2&&A% |
| 45095 |
{% |
| 45096 |
\expandafter{\detokenize{\expandafter#1\expanded}{#2}}% |
| 45097 |
}% |
| 45098 |
\def\XINT:NE:f:one:from:two_b#1{% |
| 45099 |
\def\XINT:NE:f:one:from:two_b\romannumeral`&&@##1##2##3&&A% |
| 45100 |
{% |
| 45101 |
\expandafter{\romannumeral`&&@% |
| 45102 |
\if0\XINT:NE:hastilde ##2##3~!\relax |
| 45103 |
\XINT:NE:hashash ##2##3#1!\relax 0\else |
| 45104 |
\expandafter\string\fi |
| 45105 |
##1{##2}{##3}}% |
| 45106 |
}}\expandafter\XINT:NE:f:one:from:two_b\string#% |
| 45107 |
\def\XINT:NE:f:one:from:two:direct #1#2#3{\XINT:NE:two_fork #2&&A#3&&A#1{#2}{#3}}% |
| 45108 |
\def\XINT:NE:two_fork #1#2&&A#3#4&&A{\XINT:NE:two_fork_nn#1#3}% |
| 45109 |
\def\XINT:NE:two_fork_nn #1#2% |
| 45110 |
{% |
| 45111 |
\if #1##\xint_dothis\string\fi |
| 45112 |
\if #1~\xint_dothis\string\fi |
| 45113 |
\if #2##\xint_dothis\string\fi |
| 45114 |
\if #2~\xint_dothis\string\fi |
| 45115 |
\xint_orthat{}% |
| 45116 |
}% |
| 45117 |
\def\XINT:NE:f:one:and:opt:direct#1{% |
| 45118 |
\def\XINT:NE:f:one:and:opt:direct##1!% |
| 45119 |
{% |
| 45120 |
\if0\XINT:NE:hastilde ##1~!\relax |
| 45121 |
\XINT:NE:hashash ##1#1!\relax 0\else |
| 45122 |
\xint_dothis\XINT:NE:f:one:and:opt_a\fi |
| 45123 |
\xint_orthat\XINT:NE:f:one:and:opt_b ##1&&A% |
| 45124 |
}}\expandafter\XINT:NE:f:one:and:opt:direct\string#% |
| 45125 |
\def\XINT:NE:f:one:and:opt_a #1#2&&A#3#4% |
| 45126 |
{% |
| 45127 |
\detokenize{\romannumeral-`0\expandafter#1\expanded{#2}$XINT_expr_exclam#3#4}%$ |
| 45128 |
}% |
| 45129 |
\def\XINT:NE:f:one:and:opt_b\XINT:expr:f:one:and:opt #1#2#3&&A#4#5% |
| 45130 |
{% |
| 45131 |
\if\relax#3\relax\expandafter\xint_firstoftwo\else |
| 45132 |
\expandafter\xint_secondoftwo\fi |
| 45133 |
{\XINT:NE:f:one:from:one:direct#4}% |
| 45134 |
{\expandafter\XINT:NE:f:onewithopttoone\expandafter#5% |
| 45135 |
\expanded{{\XINT:NE:f:one:from:one:direct\xintNum{#2}}}}% |
| 45136 |
{#1}% |
| 45137 |
}% |
| 45138 |
\def\XINT:NE:f:onewithopttoone#1#2#3{\XINT:NE:two_fork #2&&A#3&&A#1[#2]{#3}}% |
| 45139 |
\def\XINT:NE:f:tacitzeroifone:direct#1{% |
| 45140 |
\def\XINT:NE:f:tacitzeroifone:direct##1!% |
| 45141 |
{% |
| 45142 |
\if0\XINT:NE:hastilde ##1~!\relax |
| 45143 |
\XINT:NE:hashash ##1#1!\relax 0\else |
| 45144 |
\xint_dothis\XINT:NE:f:one:and:opt_a\fi |
| 45145 |
\xint_orthat\XINT:NE:f:tacitzeroifone_b ##1&&A% |
| 45146 |
}}\expandafter\XINT:NE:f:tacitzeroifone:direct\string#% |
| 45147 |
\def\XINT:NE:f:tacitzeroifone_b\XINT:expr:f:tacitzeroifone #1#2#3&&A#4#5% |
| 45148 |
{% |
| 45149 |
\if\relax#3\relax\expandafter\xint_firstoftwo\else |
| 45150 |
\expandafter\xint_secondoftwo\fi |
| 45151 |
{\XINT:NE:f:one:from:two:direct#4{0}}% |
| 45152 |
{\expandafter\XINT:NE:f:one:from:two:direct\expandafter#5% |
| 45153 |
\expanded{{\XINT:NE:f:one:from:one:direct\xintNum{#2}}}}% |
| 45154 |
{#1}% |
| 45155 |
}% |
| 45156 |
\def\XINT:NE:f:iitacitzeroifone:direct#1{% |
| 45157 |
\def\XINT:NE:f:iitacitzeroifone:direct##1!% |
| 45158 |
{% |
| 45159 |
\if0\XINT:NE:hastilde ##1~!\relax |
| 45160 |
\XINT:NE:hashash ##1#1!\relax 0\else |
| 45161 |
\xint_dothis\XINT:NE:f:iitacitzeroifone_a\fi |
| 45162 |
\xint_orthat\XINT:NE:f:iitacitzeroifone_b ##1&&A% |
| 45163 |
}}\expandafter\XINT:NE:f:iitacitzeroifone:direct\string#% |
| 45164 |
\def\XINT:NE:f:iitacitzeroifone_a #1#2&&A#3% |
| 45165 |
{% |
| 45166 |
\detokenize |
| 45167 |
{\romannumeral`$XINT_expr_null\expandafter#1\expanded{#2}$XINT_expr_exclam#3}% |
| 45168 |
}% |
| 45169 |
\def\XINT:NE:f:iitacitzeroifone_b\XINT:expr:f:iitacitzeroifone #1#2#3&&A#4% |
| 45170 |
{% |
| 45171 |
\if\relax#3\relax\expandafter\xint_firstoftwo\else |
| 45172 |
\expandafter\xint_secondoftwo\fi |
| 45173 |
{\XINT:NE:f:one:from:two:direct#4{0}}% |
| 45174 |
{\XINT:NE:f:one:from:two:direct#4{#2}}% |
| 45175 |
{#1}% |
| 45176 |
}% |
| 45177 |
\def\XINT:NE:x:one:from:two #1#2#3{\XINT:NE:x:one:from:two_fork #2&&A#3&&A#1{#2}{#3}}% |
| 45178 |
\def\XINT:NE:x:one:from:two_fork #1{% |
| 45179 |
\def\XINT:NE:x:one:from:two_fork ##1##2&&A##3##4&&A% |
| 45180 |
{% |
| 45181 |
\if0\XINT:NE:hastilde ##1##3~!\relax\XINT:NE:hashash ##1##3#1!\relax 0% |
| 45182 |
\else |
| 45183 |
\expandafter\XINT:NE:x:one:from:two:p |
| 45184 |
\fi |
| 45185 |
}}\expandafter\XINT:NE:x:one:from:two_fork\string#% |
| 45186 |
\def\XINT:NE:x:one:from:two:p #1#2#3% |
| 45187 |
{~expanded{\detokenize{\expandafter#1}~expanded{{#2}{#3}}}}% |
| 45188 |
\def\XINT:NE:x:listsel #1{% |
| 45189 |
\def\XINT:NE:x:listsel ##1##2&% |
| 45190 |
{% |
| 45191 |
\if0\expandafter\XINT:NE:hastilde\detokenize{##2}~!\relax |
| 45192 |
\expandafter\XINT:NE:hashash\detokenize{##2}#1!\relax 0% |
| 45193 |
\else |
| 45194 |
\expandafter\XINT:NE:x:listsel:p |
| 45195 |
\fi |
| 45196 |
##1##2&% |
| 45197 |
}}\expandafter\XINT:NE:x:listsel\string#% |
| 45198 |
\def\XINT:NE:x:listsel:p #1#2_#3&(#4% |
| 45199 |
{% |
| 45200 |
\detokenize{\expanded\XINT:expr:ListSel{{#3}{#4}}}% |
| 45201 |
}% |
| 45202 |
\def\XINT:expr:ListSel{\expandafter\XINT:expr:ListSel_i\expanded}% |
| 45203 |
\def\XINT:expr:ListSel_i #1#2{{\XINT_ListSel_top #2_#1&({#2}}}% |
| 45204 |
\def\XINT:NE:f:reverse #1{% |
| 45205 |
\def\XINT:NE:f:reverse ##1^% |
| 45206 |
{% |
| 45207 |
\if0\expandafter\XINT:NE:hastilde\detokenize\expandafter{\xint_gobble_i##1}~!\relax |
| 45208 |
\expandafter\XINT:NE:hashash\detokenize{##1}#1!\relax 0% |
| 45209 |
\else |
| 45210 |
\expandafter\XINT:NE:f:reverse:p |
| 45211 |
\fi |
| 45212 |
##1^% |
| 45213 |
}}\expandafter\XINT:NE:f:reverse\string#% |
| 45214 |
\def\XINT:NE:f:reverse:p #1^#2\xint_bye |
| 45215 |
{% |
| 45216 |
\expandafter\XINT:NE:f:reverse:p_i\expandafter{\xint_gobble_i#1}% |
| 45217 |
}% |
| 45218 |
\def\XINT:NE:f:reverse:p_i #1% |
| 45219 |
{% |
| 45220 |
\detokenize{\romannumeral0\XINT:expr:f:reverse{{#1}}}% |
| 45221 |
}% |
| 45222 |
\def\XINT:expr:f:reverse{\expandafter\XINT:expr:f:reverse_i\expanded}% |
| 45223 |
\def\XINT:expr:f:reverse_i #1% |
| 45224 |
{% |
| 45225 |
\XINT_expr_reverse #1^^#1\xint:\xint:\xint:\xint: |
| 45226 |
\xint:\xint:\xint:\xint:\xint_bye |
| 45227 |
}% |
| 45228 |
\def\XINT:NE:f:from:delim:u #1{% |
| 45229 |
\def\XINT:NE:f:from:delim:u ##1##2^% |
| 45230 |
{% |
| 45231 |
\if0\expandafter\XINT:NE:hastilde\detokenize{##2}~!\relax |
| 45232 |
\expandafter\XINT:NE:hashash\detokenize{##2}#1!\relax 0% |
| 45233 |
\xint_afterfi{\expandafter\XINT_fooof_checkifnumber\expandafter##1\string}% |
| 45234 |
\else |
| 45235 |
\xint_afterfi{\XINT:NE:f:from:delim:u:p##1\empty}% |
| 45236 |
\fi |
| 45237 |
##2^% |
| 45238 |
}}\expandafter\XINT:NE:f:from:delim:u\string#% |
| 45239 |
\def\XINT:NE:f:from:delim:u:p #1#2^% |
| 45240 |
{% |
| 45241 |
\detokenize |
| 45242 |
{\expandafter\XINT:fooof:checkifnumber\expandafter#1}~expanded{#2}$XINT_expr_caret%$ |
| 45243 |
}% |
| 45244 |
\def\XINT:fooof:checkifnumber#1{\expandafter\XINT_fooof_checkifnumber\expandafter#1\string}% |
| 45245 |
\def\XINT:NE:f:LFL#1#2{\expandafter\XINT:NE:f:LFL_a\expandafter#1#2\XINT:NE:f:LFL_a}% |
| 45246 |
\def\XINT:NE:f:LFL_a#1#2% |
| 45247 |
{% |
| 45248 |
\if#2i\else\expandafter\XINT:NE:f:LFL_p |
| 45249 |
\fi #1% |
| 45250 |
}% |
| 45251 |
\def\XINT:NE:r:check#1{% |
| 45252 |
\def\XINT:NE:r:check##1\XINT:NE:f:LFL_a |
| 45253 |
{% |
| 45254 |
\if0\expandafter\XINT:NE:hastilde\detokenize{##1}~!\relax% |
| 45255 |
\expandafter\XINT:NE:hashash\detokenize{##1}#1!\relax 0% |
| 45256 |
\else |
| 45257 |
\expandafter\XINT:NE:r:check:p |
| 45258 |
\fi |
| 45259 |
1\expandafter{\romannumeral\XINT:NEsaved:r:check##1}% |
| 45260 |
}}\expandafter\XINT:NE:r:check\string#% |
| 45261 |
\def\XINT:NE:r:check:p 1\expandafter#1{\XINT:NE:r:check:p_i#1}% |
| 45262 |
\def\XINT:NE:r:check:p_i\romannumeral\XINT:NEsaved:r:check{\XINT:NE:r:check:p_ii\empty}% |
| 45263 |
\def\XINT:NE:r:check:p_ii#1^% |
| 45264 |
{% |
| 45265 |
5~expanded{{~romannumeral~XINT:NEsaved:r:check#1$XINT_expr_caret}}%$ |
| 45266 |
}% |
| 45267 |
\def\XINT:NE:f:LFL_p#1% |
| 45268 |
{% |
| 45269 |
\detokenize{\romannumeral`$XINT_expr_null\expandafter#1}%$ |
| 45270 |
}% |
| 45271 |
\catcode`- 11 |
| 45272 |
\def\XINT:NE:exec_? #1#2% |
| 45273 |
{% |
| 45274 |
\XINT:NE:exec_?_b #2&&A#1{#2}% |
| 45275 |
}% |
| 45276 |
% \end{macrocode} |
| 45277 |
% \odef\MakePrivateLetters{\MakePrivateLetters\catcode`- 11 }\FixInterMacrocodeVspace |
| 45278 |
% \begin{macrocode} |
| 45279 |
\def\XINT:NE:exec_?_b #1{% |
| 45280 |
\def\XINT:NE:exec_?_b ##1&&A% |
| 45281 |
{% |
| 45282 |
\if0\XINT:NE:hastilde ##1~!\relax |
| 45283 |
\XINT:NE:hashash ##1#1!\relax 0% |
| 45284 |
\xint_dothis\XINT:NE:exec_?:x\fi |
| 45285 |
\xint_orthat\XINT:NE:exec_?:p |
| 45286 |
}}\expandafter\XINT:NE:exec_?_b\string#% |
| 45287 |
\def\XINT:NE:exec_?:x #1#2#3% |
| 45288 |
{% |
| 45289 |
\expandafter\XINT_expr_check-_after?\expandafter#1% |
| 45290 |
\romannumeral`&&@\expandafter\XINT_expr_getnext\romannumeral0\xintiiifnotzero#3% |
| 45291 |
}% |
| 45292 |
\def\XINT:NE:exec_?:p #1#2#3#4#5% |
| 45293 |
{% |
| 45294 |
\csname XINT_expr_func_*If\expandafter\endcsname |
| 45295 |
\romannumeral`&&@#2\XINTfstop.{#3},[#4],[#5])% |
| 45296 |
}% |
| 45297 |
\expandafter\def\csname XINT_expr_func_*If\endcsname #1#2#3% |
| 45298 |
{% |
| 45299 |
#1#2{~expanded{~xintiiifNotZero#3}}% |
| 45300 |
}% |
| 45301 |
\def\XINT:NE:exec_?? #1#2#3% |
| 45302 |
{% |
| 45303 |
\XINT:NE:exec_??_b #2&&A#1{#2}% |
| 45304 |
}% |
| 45305 |
\def\XINT:NE:exec_??_b #1{% |
| 45306 |
\def\XINT:NE:exec_??_b ##1&&A% |
| 45307 |
{% |
| 45308 |
\if0\XINT:NE:hastilde ##1~!\relax |
| 45309 |
\XINT:NE:hashash ##1#1!\relax 0% |
| 45310 |
\xint_dothis\XINT:NE:exec_??:x\fi |
| 45311 |
\xint_orthat\XINT:NE:exec_??:p |
| 45312 |
}}\expandafter\XINT:NE:exec_??_b\string#% |
| 45313 |
\def\XINT:NE:exec_??:x #1#2#3% |
| 45314 |
{% |
| 45315 |
\expandafter\XINT_expr_check-_after?\expandafter#1% |
| 45316 |
\romannumeral`&&@\expandafter\XINT_expr_getnext\romannumeral0\xintiiifsgn#3% |
| 45317 |
}% |
| 45318 |
\def\XINT:NE:exec_??:p #1#2#3#4#5#6% |
| 45319 |
{% |
| 45320 |
\csname XINT_expr_func_*IfSgn\expandafter\endcsname |
| 45321 |
\romannumeral`&&@#2\XINTfstop.{#3},[#4],[#5],[#6])% |
| 45322 |
}% |
| 45323 |
\expandafter\def\csname XINT_expr_func_*IfSgn\endcsname #1#2#3% |
| 45324 |
{% |
| 45325 |
#1#2{~expanded{~xintiiifSgn#3}}% |
| 45326 |
}% |
| 45327 |
\catcode`- 12 |
| 45328 |
% \end{macrocode} |
| 45329 |
% \let\MakePrivateLetters\xintexprMakePrivateLetters\FixInterMacrocodeVspace |
| 45330 |
% \begin{macrocode} |
| 45331 |
\def\XINT:NE:branch #1% |
| 45332 |
{% |
| 45333 |
\if0\XINT:NE:hastilde #1~!\relax 0\else |
| 45334 |
\xint_dothis\XINT:NE:branch_a\fi |
| 45335 |
\xint_orthat\XINT:NE:branch_b #1&&A% |
| 45336 |
}% |
| 45337 |
\def\XINT:NE:branch_a\romannumeral`&&@#1#2&&A% |
| 45338 |
{% |
| 45339 |
\expandafter{\detokenize{\expandafter#1\expanded}{#2}}% |
| 45340 |
}% |
| 45341 |
\def\XINT:NE:branch_b#1{% |
| 45342 |
\def\XINT:NE:branch_b\romannumeral`&&@##1##2##3&&A% |
| 45343 |
{% |
| 45344 |
\expandafter{\romannumeral`&&@% |
| 45345 |
\if0\XINT:NE:hastilde ##2~!\relax |
| 45346 |
\XINT:NE:hashash ##2#1!\relax 0\else |
| 45347 |
\expandafter\string\fi |
| 45348 |
##1{##2}##3}% |
| 45349 |
}}\expandafter\XINT:NE:branch_b\string#% |
| 45350 |
\def\XINT:NE:seqx#1{% |
| 45351 |
\def\XINT:NE:seqx\XINT_allexpr_seqx##1##2% |
| 45352 |
{% |
| 45353 |
\if 0\expandafter\XINT:NE:hastilde\detokenize{##2}~!\relax |
| 45354 |
\expandafter\XINT:NE:hashash \detokenize{##2}#1!\relax 0% |
| 45355 |
\else |
| 45356 |
\expandafter\XINT:NE:seqx:p |
| 45357 |
\fi \XINT_allexpr_seqx{##1}{##2}% |
| 45358 |
}}\expandafter\XINT:NE:seqx\string#% |
| 45359 |
\def\XINT:NE:seqx:p\XINT_allexpr_seqx #1#2#3#4% |
| 45360 |
{% |
| 45361 |
\expandafter\XINT_expr_put_op_first |
| 45362 |
\expanded {% |
| 45363 |
{% |
| 45364 |
\detokenize |
| 45365 |
{% |
| 45366 |
\expanded\bgroup |
| 45367 |
\expanded |
| 45368 |
{\xint_noxpd{\XINT_expr_seq:_b{#1#4\relax $XINT_expr_exclam #3}}% |
| 45369 |
#2$XINT_expr_caret}% |
| 45370 |
}% |
| 45371 |
}% |
| 45372 |
\expandafter}\romannumeral`&&@\XINT_expr_getop |
| 45373 |
}% |
| 45374 |
\def\XINT:NE:opx#1{% |
| 45375 |
\def\XINT:NE:opx\XINT_allexpr_opx ##1##2##3##4%##5##6##7##8% |
| 45376 |
{% |
| 45377 |
\if 0\expandafter\XINT:NE:hastilde\detokenize{##4}~!\relax |
| 45378 |
\expandafter\XINT:NE:hashash \detokenize{##4}#1!\relax 0% |
| 45379 |
\else |
| 45380 |
\expandafter\XINT:NE:opx:p |
| 45381 |
\fi \XINT_allexpr_opx ##1{##2}{##3}{##4}% en fait ##2 = \xint_c_, ##3 = \relax |
| 45382 |
}}\expandafter\XINT:NE:opx\string#% |
| 45383 |
\def\XINT:NE:opx:p\XINT_allexpr_opx #1#2#3#4#5#6#7#8% |
| 45384 |
{% |
| 45385 |
\expandafter\XINT_expr_put_op_first |
| 45386 |
\expanded {% |
| 45387 |
{% |
| 45388 |
\detokenize |
| 45389 |
{% |
| 45390 |
\expanded\bgroup |
| 45391 |
\expanded{\xint_noxpd{\XINT_expr_iter:_b |
| 45392 |
{#1\expandafter\XINT_allexpr_opx_ifnotomitted |
| 45393 |
\romannumeral0#1#6\relax#7@\relax $XINT_expr_exclam #5}}% |
| 45394 |
#4$XINT_expr_caret$XINT_expr_tilde{{#8}}}%$ |
| 45395 |
}% |
| 45396 |
}% |
| 45397 |
\expandafter}\romannumeral`&&@\XINT_expr_getop |
| 45398 |
}% |
| 45399 |
\def\XINT:NE:iter{\expandafter\XINT:NE:itery\expandafter}% |
| 45400 |
\def\XINT:NE:itery#1{% |
| 45401 |
\def\XINT:NE:itery\XINT_expr_itery##1##2% |
| 45402 |
{% |
| 45403 |
\if 0\expandafter\XINT:NE:hastilde\detokenize{##1##2}~!\relax |
| 45404 |
\expandafter\XINT:NE:hashash \detokenize{##1##2}#1!\relax 0% |
| 45405 |
\else |
| 45406 |
\expandafter\XINT:NE:itery:p |
| 45407 |
\fi \XINT_expr_itery{##1}{##2}% |
| 45408 |
}}\expandafter\XINT:NE:itery\string#% |
| 45409 |
\def\XINT:NE:itery:p\XINT_expr_itery #1#2#3#4#5% |
| 45410 |
{% |
| 45411 |
\expandafter\XINT_expr_put_op_first |
| 45412 |
\expanded {% |
| 45413 |
{% |
| 45414 |
\detokenize |
| 45415 |
{% |
| 45416 |
\expanded\bgroup |
| 45417 |
\expanded{\xint_noxpd{\XINT_expr_iter:_b {#5#4\relax $XINT_expr_exclam #3}}% |
| 45418 |
#1$XINT_expr_caret$XINT_expr_tilde{#2}}%$ |
| 45419 |
}% |
| 45420 |
}% |
| 45421 |
\expandafter}\romannumeral`&&@\XINT_expr_getop |
| 45422 |
}% |
| 45423 |
\def\XINT:NE:rseq{\expandafter\XINT:NE:rseqy\expandafter}% |
| 45424 |
\def\XINT:NE:rseqy#1{% |
| 45425 |
\def\XINT:NE:rseqy\XINT_expr_rseqy##1##2% |
| 45426 |
{% |
| 45427 |
\if 0\expandafter\XINT:NE:hastilde\detokenize{##1##2}~!\relax |
| 45428 |
\expandafter\XINT:NE:hashash \detokenize{##1##2}#1!\relax 0% |
| 45429 |
\else |
| 45430 |
\expandafter\XINT:NE:rseqy:p |
| 45431 |
\fi \XINT_expr_rseqy{##1}{##2}% |
| 45432 |
}}\expandafter\XINT:NE:rseqy\string#% |
| 45433 |
\def\XINT:NE:rseqy:p\XINT_expr_rseqy #1#2#3#4#5% |
| 45434 |
{% |
| 45435 |
\expandafter\XINT_expr_put_op_first |
| 45436 |
\expanded {% |
| 45437 |
{% |
| 45438 |
\detokenize |
| 45439 |
{% |
| 45440 |
\expanded\bgroup |
| 45441 |
\expanded{#2\xint_noxpd{\XINT_expr_rseq:_b {#5#4\relax $XINT_expr_exclam #3}}% |
| 45442 |
#1$XINT_expr_caret$XINT_expr_tilde{#2}}%$ |
| 45443 |
}% |
| 45444 |
}% |
| 45445 |
\expandafter}\romannumeral`&&@\XINT_expr_getop |
| 45446 |
}% |
| 45447 |
\def\XINT:NE:iterr{\expandafter\XINT:NE:iterry\expandafter}% |
| 45448 |
\def\XINT:NE:iterry#1{% |
| 45449 |
\def\XINT:NE:iterry\XINT_expr_iterry##1##2% |
| 45450 |
{% |
| 45451 |
\if 0\expandafter\XINT:NE:hastilde\detokenize{##1##2}~!\relax |
| 45452 |
\expandafter\XINT:NE:hashash \detokenize{##1##2}#1!\relax 0% |
| 45453 |
\else |
| 45454 |
\expandafter\XINT:NE:iterry:p |
| 45455 |
\fi \XINT_expr_iterry{##1}{##2}% |
| 45456 |
}}\expandafter\XINT:NE:iterry\string#% |
| 45457 |
\def\XINT:NE:iterry:p\XINT_expr_iterry #1#2#3#4#5% |
| 45458 |
{% |
| 45459 |
\expandafter\XINT_expr_put_op_first |
| 45460 |
\expanded {% |
| 45461 |
{% |
| 45462 |
\detokenize |
| 45463 |
{% |
| 45464 |
\expanded\bgroup |
| 45465 |
\expanded{\xint_noxpd{\XINT_expr_iterr:_b {#5#4\relax $XINT_expr_exclam #3}}% |
| 45466 |
#1$XINT_expr_caret$XINT_expr_tilde #20$XINT_expr_qmark}% |
| 45467 |
}% |
| 45468 |
}% |
| 45469 |
\expandafter}\romannumeral`&&@\XINT_expr_getop |
| 45470 |
}% |
| 45471 |
\def\XINT:NE:rrseq{\expandafter\XINT:NE:rrseqy\expandafter}% |
| 45472 |
\def\XINT:NE:rrseqy#1{% |
| 45473 |
\def\XINT:NE:rrseqy\XINT_expr_rrseqy##1##2% |
| 45474 |
{% |
| 45475 |
\if 0\expandafter\XINT:NE:hastilde\detokenize{##1##2}~!\relax |
| 45476 |
\expandafter\XINT:NE:hashash \detokenize{##1##2}#1!\relax 0% |
| 45477 |
\else |
| 45478 |
\expandafter\XINT:NE:rrseqy:p |
| 45479 |
\fi \XINT_expr_rrseqy{##1}{##2}% |
| 45480 |
}}\expandafter\XINT:NE:rrseqy\string#% |
| 45481 |
\def\XINT:NE:rrseqy:p\XINT_expr_rrseqy #1#2#3#4#5#6% |
| 45482 |
{% |
| 45483 |
\expandafter\XINT_expr_put_op_first |
| 45484 |
\expanded {% |
| 45485 |
{% |
| 45486 |
\detokenize |
| 45487 |
{% |
| 45488 |
\expanded\bgroup |
| 45489 |
\expanded{#2\xint_noxpd{\XINT_expr_rrseq:_b {#6#5\relax $XINT_expr_exclam #4}}% |
| 45490 |
#1$XINT_expr_caret$XINT_expr_tilde #30$XINT_expr_qmark}% |
| 45491 |
}% |
| 45492 |
}% |
| 45493 |
\expandafter}\romannumeral`&&@\XINT_expr_getop |
| 45494 |
}% |
| 45495 |
\def\XINT:NE:x:toblist#1{% |
| 45496 |
\def\XINT:NE:x:toblist\XINT:expr:toblistwith##1##2% |
| 45497 |
{% |
| 45498 |
\if 0\expandafter\XINT:NE:hastilde\detokenize{##2}~!\relax |
| 45499 |
\expandafter\XINT:NE:hashash \detokenize{##2}#1!\relax 0% |
| 45500 |
\else |
| 45501 |
\expandafter\XINT:NE:x:toblist:p |
| 45502 |
\fi \XINT:expr:toblistwith{##1}{##2}% |
| 45503 |
}}\expandafter\XINT:NE:x:toblist\string#% |
| 45504 |
\def\XINT:NE:x:toblist:p\XINT:expr:toblistwith #1#2{{\XINTfstop.{#2}}}% |
| 45505 |
\def\XINT:NE:x:flatten#1{% |
| 45506 |
\def\XINT:NE:x:flatten\XINT:expr:flatten##1% |
| 45507 |
{% |
| 45508 |
\if 0\expandafter\XINT:NE:hastilde\detokenize{##1}~!\relax |
| 45509 |
\expandafter\XINT:NE:hashash \detokenize{##1}#1!\relax 0% |
| 45510 |
\else |
| 45511 |
\expandafter\XINT:NE:x:flatten:p |
| 45512 |
\fi \XINT:expr:flatten{##1}% |
| 45513 |
}}\expandafter\XINT:NE:x:flatten\string#% |
| 45514 |
\def\XINT:NE:x:flatten:p\XINT:expr:flatten #1% |
| 45515 |
{% |
| 45516 |
{{% |
| 45517 |
\detokenize |
| 45518 |
{% |
| 45519 |
\expandafter\XINT:expr:flatten_checkempty |
| 45520 |
\detokenize\expandafter{\expanded{#1}}$XINT_expr_caret%$ |
| 45521 |
}% |
| 45522 |
}}% |
| 45523 |
}% |
| 45524 |
\def\XINT:NE:x:zip#1{% |
| 45525 |
\def\XINT:NE:x:zip\XINT:expr:zip##1% |
| 45526 |
{% |
| 45527 |
\if 0\expandafter\XINT:NE:hastilde\detokenize{##1}~!\relax |
| 45528 |
\expandafter\XINT:NE:hashash \detokenize{##1}#1!\relax 0% |
| 45529 |
\else |
| 45530 |
\expandafter\XINT:NE:x:zip:p |
| 45531 |
\fi \XINT:expr:zip{##1}% |
| 45532 |
}}\expandafter\XINT:NE:x:zip\string#% |
| 45533 |
\def\XINT:NE:x:zip:p\XINT:expr:zip #1% |
| 45534 |
{% |
| 45535 |
\expandafter{% |
| 45536 |
\detokenize |
| 45537 |
{% |
| 45538 |
\expanded\expandafter\XINT_zip_A\expanded{#1}\xint_bye\xint_bye |
| 45539 |
}% |
| 45540 |
}% |
| 45541 |
}% |
| 45542 |
\def\XINT:NE:x:mapwithin#1{% |
| 45543 |
\def\XINT:NE:x:mapwithin\XINT:expr:mapwithin ##1##2% |
| 45544 |
{% |
| 45545 |
\if 0\expandafter\XINT:NE:hastilde\detokenize{##2}~!\relax |
| 45546 |
\expandafter\XINT:NE:hashash \detokenize{##2}#1!\relax 0% |
| 45547 |
\else |
| 45548 |
\expandafter\XINT:NE:x:mapwithin:p |
| 45549 |
\fi \XINT:expr:mapwithin {##1}{##2}% |
| 45550 |
}}\expandafter\XINT:NE:x:mapwithin\string#% |
| 45551 |
\def\XINT:NE:x:mapwithin:p \XINT:expr:mapwithin #1#2% |
| 45552 |
{% |
| 45553 |
{{% |
| 45554 |
\detokenize |
| 45555 |
{% |
| 45556 |
% \end{macrocode} |
| 45557 |
% Attention (2022/06/10) I do not remember why I left these two commented |
| 45558 |
% lines which docstrip will not remove, I hope this is not a forgotten |
| 45559 |
% left=over from some debugging session. |
| 45560 |
% \begin{macrocode} |
| 45561 |
%% \expanded |
| 45562 |
%% {% |
| 45563 |
\expandafter\XINT:expr:mapwithin_checkempty |
| 45564 |
\expanded{\noexpand#1$XINT_expr_exclam\expandafter}%$ |
| 45565 |
\detokenize\expandafter{\expanded{#2}}$XINT_expr_caret%$ |
| 45566 |
% \end{macrocode} |
| 45567 |
% This is is the matching one. |
| 45568 |
% \begin{macrocode} |
| 45569 |
%% }% |
| 45570 |
}% |
| 45571 |
}}% |
| 45572 |
}% |
| 45573 |
\def\XINT:NE:x:ndmapx#1{% |
| 45574 |
\def\XINT:NE:x:ndmapx\XINT_allexpr_ndmapx_a ##1##2^% |
| 45575 |
{% |
| 45576 |
\if 0\expandafter\XINT:NE:hastilde\detokenize{##2}~!\relax |
| 45577 |
\expandafter\XINT:NE:hashash \detokenize{##2}#1!\relax 0% |
| 45578 |
\else |
| 45579 |
\expandafter\XINT:NE:x:ndmapx:p |
| 45580 |
\fi \XINT_allexpr_ndmapx_a ##1##2^% |
| 45581 |
}}\expandafter\XINT:NE:x:ndmapx\string#% |
| 45582 |
\def\XINT:NE:x:ndmapx:p #1#2#3^\relax |
| 45583 |
{% |
| 45584 |
\detokenize |
| 45585 |
{% |
| 45586 |
\expanded{% |
| 45587 |
\expandafter#1\expandafter#2\expanded{#3}$XINT_expr_caret\relax %$ |
| 45588 |
}% |
| 45589 |
}% |
| 45590 |
}% |
| 45591 |
% \end{macrocode} |
| 45592 |
%\begin{lverb} |
| 45593 |
% Attention here that user function |
| 45594 |
% names may contain digits, so we don't use a \detokenize or ~ approach. |
| 45595 |
% |
| 45596 |
% This syntax means that a function defined by \xintdeffunc never expands |
| 45597 |
% when used in another definition, so it can implement recursive definitions. |
| 45598 |
% |
| 45599 |
% \XINT:NE:userefunc et al. added at 1.3e. |
| 45600 |
% |
| 45601 |
% I added at \xintdefefunc, \xintdefiiefunc, \xintdeffloatefunc at 1.3e to on |
| 45602 |
% the contrary expand if possible (i.e. if used only with numeric arguments) |
| 45603 |
% in another definition. |
| 45604 |
% |
| 45605 |
% The \XINTusefunc |
| 45606 |
% uses \expanded. Its ancestor \xintExpandArgs (xinttools 1.3) |
| 45607 |
% had some more primitive f-expansion technique. |
| 45608 |
%\end{lverb} |
| 45609 |
% \begin{macrocode} |
| 45610 |
\def\XINTusenoargfunc #1% |
| 45611 |
{% |
| 45612 |
0\csname #1\endcsname |
| 45613 |
}% |
| 45614 |
\def\XINT:NE:usernoargfunc\csname #1\endcsname |
| 45615 |
{% |
| 45616 |
~romannumeral~XINTusenoargfunc{#1}% |
| 45617 |
}% |
| 45618 |
\def\XINTusefunc #1% |
| 45619 |
{% |
| 45620 |
0\csname #1\expandafter\endcsname\expanded |
| 45621 |
}% |
| 45622 |
\def\XINT:NE:usefunc #1#2#3% |
| 45623 |
{% |
| 45624 |
~romannumeral~XINTusefunc{#1}{#3}\iffalse{{\fi}}% |
| 45625 |
}% |
| 45626 |
\def\XINTuseufunc #1% |
| 45627 |
{% |
| 45628 |
\expanded\expandafter\XINT:expr:mapwithin\csname #1\expandafter\endcsname\expanded |
| 45629 |
}% |
| 45630 |
\def\XINT:NE:useufunc #1#2#3% |
| 45631 |
{% |
| 45632 |
{{~expanded~XINTuseufunc{#1}{#3}}}% |
| 45633 |
}% |
| 45634 |
\def\XINT:NE:userfunc #1{% |
| 45635 |
\def\XINT:NE:userfunc ##1##2##3% |
| 45636 |
{% |
| 45637 |
\if0\expandafter\XINT:NE:hastilde\detokenize{##3}~!\relax |
| 45638 |
\expandafter\XINT:NE:hashash\detokenize{##3}#1!\relax 0% |
| 45639 |
\expandafter\XINT:NE:userfunc_x |
| 45640 |
\else |
| 45641 |
\expandafter\XINT:NE:usefunc |
| 45642 |
\fi {##1}{##2}{##3}% |
| 45643 |
}}\expandafter\XINT:NE:userfunc\string#% |
| 45644 |
\def\XINT:NE:userfunc_x #1#2#3{#2#3\iffalse{{\fi}}}% |
| 45645 |
\def\XINT:NE:userufunc #1{% |
| 45646 |
\def\XINT:NE:userufunc ##1##2##3% |
| 45647 |
{% |
| 45648 |
\if0\expandafter\XINT:NE:hastilde\detokenize{##3}~!\relax |
| 45649 |
\expandafter\XINT:NE:hashash\detokenize{##3}#1!\relax 0% |
| 45650 |
\expandafter\XINT:NE:userufunc_x |
| 45651 |
\else |
| 45652 |
\expandafter\XINT:NE:useufunc |
| 45653 |
\fi {##1}{##2}{##3}% |
| 45654 |
}}\expandafter\XINT:NE:userufunc\string#% |
| 45655 |
\def\XINT:NE:userufunc_x #1{\XINT:expr:mapwithin}% |
| 45656 |
\def\XINT:NE:macrofunc #1#2% |
| 45657 |
{\expandafter\XINT:NE:macrofunc:a\string#1#2\empty&}% |
| 45658 |
\def\XINT:NE:macrofunc:a#1\csname #2\endcsname#3&% |
| 45659 |
{{~XINTusemacrofunc{#1}{#2}{#3}}}% |
| 45660 |
\def\XINTusemacrofunc #1#2#3% |
| 45661 |
{% |
| 45662 |
\romannumeral0\expandafter\xint_stop_atfirstofone |
| 45663 |
\romannumeral0#1\csname #2\endcsname#3\relax |
| 45664 |
}% |
| 45665 |
% \end{macrocode} |
| 45666 |
% \subsubsection{\csh{XINT_expr_redefinemacros}} |
| 45667 |
%\begin{lverb} |
| 45668 |
% Completely refactored at 1.3. |
| 45669 |
% |
| 45670 |
% Again refactored at 1.4. The availability of \expanded allows more powerful |
| 45671 |
% mechanisms and more importantly I better thought out the root problems |
| 45672 |
% caused by the handling of list operations in this context and this helped |
| 45673 |
% simplify considerably the code. |
| 45674 |
%\end{lverb} |
| 45675 |
% \odef\MakePrivateLetters{\MakePrivateLetters\catcode`- 11 }^^A |
| 45676 |
% \begin{macrocode} |
| 45677 |
\catcode`- 11 |
| 45678 |
\def\XINT_expr_redefinemacros {% |
| 45679 |
\let\XINT:NEhook:unpack \XINT:NE:unpack |
| 45680 |
\let\XINT:NEhook:f:one:from:one \XINT:NE:f:one:from:one |
| 45681 |
\let\XINT:NEhook:f:one:from:one:direct \XINT:NE:f:one:from:one:direct |
| 45682 |
\let\XINT:NEhook:f:one:from:two \XINT:NE:f:one:from:two |
| 45683 |
\let\XINT:NEhook:f:one:from:two:direct \XINT:NE:f:one:from:two:direct |
| 45684 |
\let\XINT:NEhook:x:one:from:two \XINT:NE:x:one:from:two |
| 45685 |
\let\XINT:NEhook:f:one:and:opt:direct \XINT:NE:f:one:and:opt:direct |
| 45686 |
\let\XINT:NEhook:f:tacitzeroifone:direct \XINT:NE:f:tacitzeroifone:direct |
| 45687 |
\let\XINT:NEhook:f:iitacitzeroifone:direct \XINT:NE:f:iitacitzeroifone:direct |
| 45688 |
\let\XINT:NEhook:x:listsel \XINT:NE:x:listsel |
| 45689 |
\let\XINT:NEhook:f:reverse \XINT:NE:f:reverse |
| 45690 |
\let\XINT:NEhook:f:from:delim:u \XINT:NE:f:from:delim:u |
| 45691 |
\let\XINT:NEhook:f:LFL \XINT:NE:f:LFL |
| 45692 |
\let\XINT:NEhook:r:check \XINT:NE:r:check |
| 45693 |
\let\XINT:NEhook:branch \XINT:NE:branch |
| 45694 |
\let\XINT:NEhook:seqx \XINT:NE:seqx |
| 45695 |
\let\XINT:NEhook:opx \XINT:NE:opx |
| 45696 |
\let\XINT:NEhook:rseq \XINT:NE:rseq |
| 45697 |
\let\XINT:NEhook:iter \XINT:NE:iter |
| 45698 |
\let\XINT:NEhook:rrseq \XINT:NE:rrseq |
| 45699 |
\let\XINT:NEhook:iterr \XINT:NE:iterr |
| 45700 |
\let\XINT:NEhook:x:toblist \XINT:NE:x:toblist |
| 45701 |
\let\XINT:NEhook:x:flatten \XINT:NE:x:flatten |
| 45702 |
\let\XINT:NEhook:x:zip \XINT:NE:x:zip |
| 45703 |
\let\XINT:NEhook:x:mapwithin \XINT:NE:x:mapwithin |
| 45704 |
\let\XINT:NEhook:x:ndmapx \XINT:NE:x:ndmapx |
| 45705 |
\let\XINT:NEhook:userfunc \XINT:NE:userfunc |
| 45706 |
\let\XINT:NEhook:userufunc \XINT:NE:userufunc |
| 45707 |
\let\XINT:NEhook:usernoargfunc \XINT:NE:usernoargfunc |
| 45708 |
\let\XINT:NEhook:macrofunc \XINT:NE:macrofunc |
| 45709 |
\def\XINTinRandomFloatSdigits{~XINTinRandomFloatSdigits }% |
| 45710 |
\def\XINTinRandomFloatSixteen{~XINTinRandomFloatSixteen }% |
| 45711 |
\def\xintiiRandRange{~xintiiRandRange }% |
| 45712 |
\def\xintiiRandRangeAtoB{~xintiiRandRangeAtoB }% |
| 45713 |
\def\xintRandBit{~xintRandBit }% |
| 45714 |
\let\XINT_expr_exec_? \XINT:NE:exec_? |
| 45715 |
\let\XINT_expr_exec_?? \XINT:NE:exec_?? |
| 45716 |
\def\XINT_expr_op_? {\XINT_expr_op__?{\XINT_expr_op_-xii\XINT_expr_oparen}}% |
| 45717 |
\def\XINT_flexpr_op_?{\XINT_expr_op__?{\XINT_flexpr_op_-xii\XINT_flexpr_oparen}}% |
| 45718 |
\def\XINT_iiexpr_op_?{\XINT_expr_op__?{\XINT_iiexpr_op_-xii\XINT_iiexpr_oparen}}% |
| 45719 |
}% |
| 45720 |
\catcode`- 12 |
| 45721 |
% \end{macrocode} |
| 45722 |
% \let\MakePrivateLetters\xintexprMakePrivateLetters |
| 45723 |
% \subsubsection{\csh{xintNewExpr}, \csh{xintNewIExpr}, \csh{xintNewFloatExpr}, |
| 45724 |
% \csh{xintNewIIExpr}} |
| 45725 |
% \label{\xintimplabelprefix XINT_NewExpr} |
| 45726 |
% \label{\xintimplabelprefix XINT_NewExpr_a} |
| 45727 |
%\begin{lverb} |
| 45728 |
% 1.2c modifications to accomodate \XINT_expr_deffunc_newexpr etc.. |
| 45729 |
% |
| 45730 |
% 1.2f adds token \XINT_newexpr_clean to be able to have a different |
| 45731 |
% \XINT_newfunc_clean. |
| 45732 |
% |
| 45733 |
% As \XINT_NewExpr always execute \XINT_expr_redefineprints since 1.3e whether |
| 45734 |
% with \xintNewExpr or \XINT_NewFunc, it has been moved from argument to |
| 45735 |
% hardcoded in replacement text. |
| 45736 |
% |
| 45737 |
% NO MORE \XINT_expr_redefineprints at 1.4 ! This allows better support for |
| 45738 |
% \xinteval, \xinttheexpr as sub-entities inside an \xintNewExpr. And the |
| 45739 |
% «cleaning» will remove the new \XINTfstop , to maintain backwards |
| 45740 |
% compatibility with former behaviour that created macros expand to explicit |
| 45741 |
% digits and not an encapsulated result. |
| 45742 |
% |
| 45743 |
% (obsolete:) The #2#3 in clean stands for \noexpand\XINTfstop. |
| 45744 |
%\end{lverb} |
| 45745 |
% \changed{1.4n} |
| 45746 |
%\begin{lverb} |
| 45747 |
% The #2#3 in previous paragraph is obsolete, the pattern used for |
| 45748 |
% \XINT_newexpr_clean was formerly #1>#2#3 (not optimal, but legacy), but is |
| 45749 |
% now simply #1\XINTfstop. This is simpler and allows compatibility with |
| 45750 |
% LuaMetaTeX whose \meaning output differs from the one of other engines. |
| 45751 |
%\end{lverb} |
| 45752 |
% \begin{macrocode} |
| 45753 |
\def\xintNewExpr {\XINT_NewExpr\xint_firstofone\xintexpr \XINT_newexpr_clean}% |
| 45754 |
\def\xintNewFloatExpr{\XINT_NewExpr\xint_firstofone\xintfloatexpr\XINT_newexpr_clean}% |
| 45755 |
\def\xintNewIExpr {\XINT_NewExpr\xint_firstofone\xintiexpr \XINT_newexpr_clean}% |
| 45756 |
\def\xintNewIIExpr {\XINT_NewExpr\xint_firstofone\xintiiexpr \XINT_newexpr_clean}% |
| 45757 |
\def\xintNewBoolExpr {\XINT_NewExpr\xint_firstofone\xintboolexpr \XINT_newexpr_clean}% |
| 45758 |
\def\XINT_newexpr_clean #1\XINTfstop{\noexpand\expanded\noexpand\xintNEprinthook}% |
| 45759 |
\def\xintNEprinthook#1.#2{\expanded{\xint_noxpd{#1.}{#2}}}% |
| 45760 |
% \end{macrocode} |
| 45761 |
%\begin{lverb} |
| 45762 |
% 1.2c for \xintdeffunc, \xintdefiifunc, \xintdeffloatfunc. |
| 45763 |
% |
| 45764 |
% At 1.3, NewFunc does not use anymore a comma delimited pattern for the |
| 45765 |
% arguments to the macro being defined. |
| 45766 |
% |
| 45767 |
% At 1.4 we use \xintthebareeval, whose meaning now does not mean unlock |
| 45768 |
% from csname but firstofone to remove a level of braces |
| 45769 |
% This is involved in functioning of expr:userfunc and expr:userefunc |
| 45770 |
%\end{lverb} |
| 45771 |
% \begin{macrocode} |
| 45772 |
\def\XINT_NewFunc {\XINT_NewExpr\xint_gobble_i\xintthebareeval\XINT_newfunc_clean}% |
| 45773 |
\def\XINT_NewFloatFunc{\XINT_NewExpr\xint_gobble_i\xintthebarefloateval\XINT_newfunc_clean}% |
| 45774 |
\def\XINT_NewIIFunc {\XINT_NewExpr\xint_gobble_i\xintthebareiieval\XINT_newfunc_clean}% |
| 45775 |
\def\XINT_newfunc_clean #1>{}% |
| 45776 |
\ifdefined\notexpanded\let\XINT_newfunc_clean\xint_gobble_vi\fi% |
| 45777 |
% \end{macrocode} |
| 45778 |
%\begin{lverb} |
| 45779 |
% 1.2c adds optional logging. For this needed to pass to _NewExpr_a the |
| 45780 |
% macro name as parameter. |
| 45781 |
% |
| 45782 |
% Up to and including 1.2c the definition was global. Starting with 1.2d it is |
| 45783 |
% done locally. |
| 45784 |
% |
| 45785 |
% The \xintexprSafeCatcodes inserted here by \xintNewExpr |
| 45786 |
% is not paired with an \xintexprRestoreCatcodes, |
| 45787 |
% but this happens within a scope limiting group so does not matter. |
| 45788 |
% At 1.3c, \XINT_NewFunc et al. do not even execute the |
| 45789 |
% \xintexprSafeCatcodes, as it gets already done by \xintdeffunc prior |
| 45790 |
% to arriving here. |
| 45791 |
% |
| 45792 |
%\end{lverb} |
| 45793 |
% \begin{macrocode} |
| 45794 |
\def\XINT_NewExpr #1#2#3#4#5[#6]% |
| 45795 |
{% |
| 45796 |
\begingroup |
| 45797 |
\ifcase #6\relax |
| 45798 |
\toks0 {\endgroup\XINT_global\def#4}% |
| 45799 |
\or \toks0 {\endgroup\XINT_global\def#4##1}% |
| 45800 |
\or \toks0 {\endgroup\XINT_global\def#4##1##2}% |
| 45801 |
\or \toks0 {\endgroup\XINT_global\def#4##1##2##3}% |
| 45802 |
\or \toks0 {\endgroup\XINT_global\def#4##1##2##3##4}% |
| 45803 |
\or \toks0 {\endgroup\XINT_global\def#4##1##2##3##4##5}% |
| 45804 |
\or \toks0 {\endgroup\XINT_global\def#4##1##2##3##4##5##6}% |
| 45805 |
\or \toks0 {\endgroup\XINT_global\def#4##1##2##3##4##5##6##7}% |
| 45806 |
\or \toks0 {\endgroup\XINT_global\def#4##1##2##3##4##5##6##7##8}% |
| 45807 |
\or \toks0 {\endgroup\XINT_global\def#4##1##2##3##4##5##6##7##8##9}% |
| 45808 |
\fi |
| 45809 |
#1\xintexprSafeCatcodes |
| 45810 |
\XINT_expr_redefinemacros |
| 45811 |
\XINT_NewExpr_a #1#2#3#4% |
| 45812 |
}% |
| 45813 |
% \end{macrocode} |
| 45814 |
%\begin{lverb} |
| 45815 |
% $catcode38 12 |
| 45816 |
% |
| 45817 |
% 1.2d's \xintNewExpr makes a local definition. In earlier releases, the |
| 45818 |
% definition was global. |
| 45819 |
% |
| 45820 |
% \the\toks0 inserts the \endgroup, but this will happen |
| 45821 |
% after \XINT_tmpa has already been expanded... |
| 45822 |
% |
| 45823 |
% The $%1 is \xint_firstofone for \xintNewExpr, \xint_gobble_i |
| 45824 |
% for \xintdeffunc. |
| 45825 |
% |
| 45826 |
% Attention that at 1.4, there might be entire sub-xintexpressions embedded in |
| 45827 |
% detokenized form. They are re-tokenized and the main thing is that the |
| 45828 |
% parser should not mis-interpret catcode 11 characters as starting variable |
| 45829 |
% names. As some macros use : in their names, the retokenization must be done |
| 45830 |
% with : having catcode 11. To not break embedded non-evaluated |
| 45831 |
% sub-expressions, the \XINT_expr_getop was extended to intercept the : |
| 45832 |
% (alternative would have been to never inject any macro with : in its name... |
| 45833 |
% too late now). On the other hand the ! is not used in the macro names |
| 45834 |
% potentially kept as is non expanded by the \xintNewExpr/\xintdeffunc |
| 45835 |
% process; it can thus be retokenized with catcode 12. But the «hooks» of |
| 45836 |
% seq(), iter(), etc... if deciding they can't evaluate immediately will |
| 45837 |
% inject a full sub-expression (possibly arbitrarily complicated) and append |
| 45838 |
% to it for its delayed expansion a catcode 11 ! character (as well as |
| 45839 |
% possibly catcode 3 ~ and ? and catcode 11 caret ^ and even catcode 7 $&). |
| 45840 |
% The macros \XINT_expr_tilde etc... below serve for this injection (there are |
| 45841 |
% *two* successive \scantokens using different catcode regimes and these |
| 45842 |
% macros remain detokenized during the first pass!) and as consequence the |
| 45843 |
% final meaning may have characters such as ! or & present with both standard |
| 45844 |
% and special catcodes depending on where they are located. It may thus not be |
| 45845 |
% possible to (easily) retokenize the meaning as printed in the log file if |
| 45846 |
% \xintverbosetrue was issued. |
| 45847 |
% |
| 45848 |
% If a defined function is used in another expression it would thus break |
| 45849 |
% things if its meaning was included pre-expanded ; a mechanism exists which |
| 45850 |
% keeps only the name of the macro associated to the function (this name may |
| 45851 |
% contain digits by the way), when the macro can not be immediately fully |
| 45852 |
% expanded. Thus its meaning (with its possibly funny catcodes) is not |
| 45853 |
% exposed. And this gives opportunity to pre-expand its arguments before |
| 45854 |
% actually expanding the macro. |
| 45855 |
% |
| 45856 |
% There is a problem with xetex -8bit which will convert ^^@ possibly present |
| 45857 |
% in the meaning written to log if \xintverbosetrue into a null byte. It |
| 45858 |
% surprises at first, but perhaps because I am too much used to pdftex and luatex |
| 45859 |
% converting the zero byte perhaps produced meaning internally to ^^@ notation |
| 45860 |
% at the "output" stage. |
| 45861 |
% |
| 45862 |
% I observed that ConTeXt will spit out such null byte "as is", as does xetex |
| 45863 |
% -8bit. This is a bit annoying because contrarily to xetex no option is |
| 45864 |
% needed, and such output lets some software consider the output file is a |
| 45865 |
% binary one (for example git diff). |
| 45866 |
%\end{lverb} |
| 45867 |
% \begin{macrocode} |
| 45868 |
\catcode`~ 3 \catcode`? 3 |
| 45869 |
\def\XINT_expr_tilde{~}\def\XINT_expr_qmark{?}% catcode 3 |
| 45870 |
\def\XINT_expr_caret{^}\def\XINT_expr_exclam{!}% catcode 11 |
| 45871 |
\def\XINT_expr_tab{&}% catcode 7 |
| 45872 |
\def\XINT_expr_null{&&@}% |
| 45873 |
% \end{macrocode} |
| 45874 |
% \added{1.4n} Add \cs{xintmeaning} for matters of package test suite. |
| 45875 |
% At user level, a priori simply expands to \cs{meaning}. It gets |
| 45876 |
% redefined during execution of the test suite to keep logged expectations |
| 45877 |
% the same also with LMTX engine. |
| 45878 |
% \begin{macrocode} |
| 45879 |
\ifdefined\xintmeaning\else\def\xintmeaning{\meaning}\fi |
| 45880 |
% \end{macrocode} |
| 45881 |
% \added{1.4n} |
| 45882 |
%\begin{lverb} |
| 45883 |
% Add \XINT_expr_set_tilde to address LuaMeta$TeX$ specifics. |
| 45884 |
% We won't need to restore because we will be in a group and \toks0 will |
| 45885 |
% bring the \endgroup. |
| 45886 |
%\end{lverb} |
| 45887 |
% |
| 45888 |
% When I observed that the whole \csbxint{deffunc} thing was broken with |
| 45889 |
% Con\TeX t due to what appeared to be some weirdness during expansion, I |
| 45890 |
% realized much to my surprise that the active tilde was not expanding inside |
| 45891 |
% \cs{edef}! I got lucky I could quickly find a then recent discussion |
| 45892 |
% precisely about this on |
| 45893 |
% \href{https://tex.stackexchange.com/q/749050}{tex.sx}, from which I picked |
| 45894 |
% up the \cs{amcode} workaround. Such a trick is quite hidden in Con\TeX t |
| 45895 |
% documentation, from which it is a long shot to deduce it behaves as it |
| 45896 |
% actually does. |
| 45897 |
% |
| 45898 |
% Replacing about 130 occurrences of |~| in this file which are a core part of |
| 45899 |
% the mysterious dealings underpinning \csbxint{deffunc} is not really an |
| 45900 |
% option. I don't have that many available ascii characters and I do not want |
| 45901 |
% to go into mass replacements and have to update unit tests sometimes |
| 45902 |
% checking internals. What a relief there is the \cs{amcode} way! (and seemingly |
| 45903 |
% no other way...). |
| 45904 |
% \begin{macrocode} |
| 45905 |
\catcode`~ 13 \catcode`$ 11 %$ |
| 45906 |
\def\XINT_NewExpr_set_tilde{\def~{$noexpand$}}% |
| 45907 |
\ifdefined\contextversion |
| 45908 |
\ifdefined\amcode |
| 45909 |
\def\XINT_NewExpr_set_tilde{\amcode`\~0\def~{$noexpand$}}% |
| 45910 |
\else |
| 45911 |
\xintMessage{xintexpr}{Error}{This ConTeXt is incompatible.}% |
| 45912 |
\errhelp{xintexpr requires ConTeXt-LMTX to have its \string\amcode.}% |
| 45913 |
\errmessage{The \noexpand\amcode primitive does not exist.}% |
| 45914 |
\fi |
| 45915 |
\fi |
| 45916 |
\catcode`@ 14 \catcode`\% 6 \catcode`# 12 |
| 45917 |
\def\XINT_NewExpr_a %1%2%3%4%5@ |
| 45918 |
{@ |
| 45919 |
\def\XINT_tmpa %%1%%2%%3%%4%%5%%6%%7%%8%%9{%5}@ |
| 45920 |
\XINT_NewExpr_set_tilde |
| 45921 |
\catcode`: 11 \catcode`_ 11 \catcode`\@ 11 |
| 45922 |
\catcode`# 12 \catcode`~ 13 \escapechar 126 |
| 45923 |
\endlinechar -1 \everyeof {\noexpand }@ |
| 45924 |
\edef\XINT_tmpb |
| 45925 |
{\scantokens\expandafter{\romannumeral`&&@\expandafter |
| 45926 |
%2\XINT_tmpa{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}{#9}\relax}@ |
| 45927 |
}@ |
| 45928 |
\escapechar 92 \catcode`# 6 \catcode`$ 0 @ $ |
| 45929 |
\edef\XINT_tmpa %%1%%2%%3%%4%%5%%6%%7%%8%%9@ |
| 45930 |
{\scantokens\expandafter{\expandafter%3\meaning\XINT_tmpb}}@ |
| 45931 |
\the\toks0\expandafter |
| 45932 |
{\XINT_tmpa{%%1}{%%2}{%%3}{%%4}{%%5}{%%6}{%%7}{%%8}{%%9}}@ |
| 45933 |
%1{\ifxintverbose |
| 45934 |
\xintMessage{xintexpr}{Info}@ |
| 45935 |
{\string%4\space now with @ |
| 45936 |
\ifxintglobaldefs global \fi meaning \xintmeaning%4}@ |
| 45937 |
\fi}@ |
| 45938 |
}@ |
| 45939 |
\catcode`% 14 |
| 45940 |
\XINTsetcatcodes % clean up to avoid surprises if something changes |
| 45941 |
% \end{macrocode} |
| 45942 |
% \subsubsection{\csh{xintexprSafeCatcodes}, \csh{xintexprRestoreCatcodes}} |
| 45943 |
% \changed[2018/06/17]{1.3c} |
| 45944 |
%\begin{lverb} |
| 45945 |
% Added \ifxintexprsafecatcodes to allow nesting |
| 45946 |
%\end{lverb} |
| 45947 |
% \changed[2022/05/15]{1.4k} |
| 45948 |
%\begin{lverb} |
| 45949 |
% The "allow nesting" from the 2018 comment was strange, because |
| 45950 |
% the behaviour, as correctly documented in user manual, was that |
| 45951 |
% in case of a series of \xintexprSafeCatcodes, the \xintexprRestoreCatcodes |
| 45952 |
% would set catcodes to what they were before the *first* sanitization. |
| 45953 |
% But as \xintdefvar and \xintdeffunc used such a pair this meant |
| 45954 |
% that they would incomprehensibly for user reset catcodes to what |
| 45955 |
% they were before a possible user \xintexprSafeCatcodes located before... |
| 45956 |
% very lame situation. Anyway. I finally |
| 45957 |
% fix at 1.4k that by removing the silly \ifxintexprsafecatcodes thing |
| 45958 |
% and replace it by some stack-like method, avoiding extra macros |
| 45959 |
% thanks to the help of \unexpanded. |
| 45960 |
%\end{lverb} |
| 45961 |
% \changed{1.4m} Use |\protected| rather than |\unexpanded| mechanism, |
| 45962 |
% for lisibility. |
| 45963 |
% \begin{macrocode} |
| 45964 |
\protected\def\xintexprRestoreCatcodes{}% |
| 45965 |
\def\xintexprSafeCatcodes |
| 45966 |
{% |
| 45967 |
\protected\edef\xintexprRestoreCatcodes{% |
| 45968 |
\endlinechar=\the\endlinechar |
| 45969 |
\catcode59=\the\catcode59 % ; |
| 45970 |
\catcode34=\the\catcode34 % " |
| 45971 |
\catcode63=\the\catcode63 % ? |
| 45972 |
\catcode124=\the\catcode124 % | |
| 45973 |
\catcode38=\the\catcode38 % & |
| 45974 |
\catcode33=\the\catcode33 % ! |
| 45975 |
\catcode93=\the\catcode93 % ] |
| 45976 |
\catcode91=\the\catcode91 % [ |
| 45977 |
\catcode94=\the\catcode94 % ^ |
| 45978 |
\catcode95=\the\catcode95 % _ |
| 45979 |
\catcode47=\the\catcode47 % / |
| 45980 |
\catcode41=\the\catcode41 % ) |
| 45981 |
\catcode40=\the\catcode40 % ( |
| 45982 |
\catcode42=\the\catcode42 % * |
| 45983 |
\catcode43=\the\catcode43 % + |
| 45984 |
\catcode62=\the\catcode62 % > |
| 45985 |
\catcode60=\the\catcode60 % < |
| 45986 |
\catcode58=\the\catcode58 % : |
| 45987 |
\catcode46=\the\catcode46 % . |
| 45988 |
\catcode45=\the\catcode45 % - |
| 45989 |
\catcode44=\the\catcode44 % , |
| 45990 |
\catcode61=\the\catcode61 % = |
| 45991 |
\catcode96=\the\catcode96 % ` |
| 45992 |
\catcode32=\the\catcode32\relax % space |
| 45993 |
\protected\odef\xintexprRestoreCatcodes{\xintexprRestoreCatcodes}% |
| 45994 |
}% |
| 45995 |
\endlinechar=13 % |
| 45996 |
\catcode59=12 % ; |
| 45997 |
\catcode34=12 % " |
| 45998 |
\catcode63=12 % ? |
| 45999 |
\catcode124=12 % | |
| 46000 |
\catcode38=4 % & |
| 46001 |
\catcode33=12 % ! |
| 46002 |
\catcode93=12 % ] |
| 46003 |
\catcode91=12 % [ |
| 46004 |
\catcode94=7 % ^ |
| 46005 |
\catcode95=8 % _ |
| 46006 |
\catcode47=12 % / |
| 46007 |
\catcode41=12 % ) |
| 46008 |
\catcode40=12 % ( |
| 46009 |
\catcode42=12 % * |
| 46010 |
\catcode43=12 % + |
| 46011 |
\catcode62=12 % > |
| 46012 |
\catcode60=12 % < |
| 46013 |
\catcode58=12 % : |
| 46014 |
\catcode46=12 % . |
| 46015 |
\catcode45=12 % - |
| 46016 |
\catcode44=12 % , |
| 46017 |
\catcode61=12 % = |
| 46018 |
\catcode96=12 % ` |
| 46019 |
\catcode32=10 % space |
| 46020 |
}% |
| 46021 |
\let\XINT_tmpa\undefined \let\XINT_tmpb\undefined \let\XINT_tmpc\undefined |
| 46022 |
\let\XINT_tmpd\undefined \let\XINT_tmpe\undefined |
| 46023 |
% \end{macrocode} |
| 46024 |
%\subsection{Matters related to loading log and trig libraries} |
| 46025 |
%\begin{lverb} |
| 46026 |
% 1.4l makes a user level \usepackage{$xintlognameimp} (not the one done via |
| 46027 |
% \usepackage{$xintexprnameimp} attempt to do the right thing (in place of |
| 46028 |
% aborting). We have to work-around the fact that LaTeX will ignore a |
| 46029 |
% \usepackage here. Simpler for non-LaTeX. |
| 46030 |
% |
| 46031 |
% In all cases, the input of $xintlognameimp.sty and $xinttrignameimp.sty is |
| 46032 |
% done with $xintexprnameimp catcodes in place. And $xintlognameimp will |
| 46033 |
% sanitize catcodes at time of loading poormanlog. Attention also to not |
| 46034 |
% mix-up things at time of restoring catcodes. This is reason why |
| 46035 |
% $xintlognameimp.sty and $xinttrignameimp.sty have their own endinput |
| 46036 |
% wrappers. And that the rescue attempt of loading $xintexprnameimp (which |
| 46037 |
% will load $xintlognameimp) from $xintlognameimp itself is done carefully. |
| 46038 |
% |
| 46039 |
%\end{lverb} |
| 46040 |
% \begin{macrocode} |
| 46041 |
\ifdefined\RequirePackage |
| 46042 |
\ifcsname [email protected]\endcsname |
| 46043 |
% \end{macrocode} |
| 46044 |
% We end up here since |1.4l| with \LaTeX{} if the user has issued |
| 46045 |
% |\usepackage{xinttrig}| or |\RequirePackage{xinttrig}| with no prior loading |
| 46046 |
% of \xintexprnameimp. In such (not officially supported) case, the loading |
| 46047 |
% of |xintexpr| was launched from this first instance of \xinttrignameimp. |
| 46048 |
% This first \xinttrignameimp will abort itself, once this input concludes. |
| 46049 |
% But before that a second instance of \xinttrignameimp is |\input| and will |
| 46050 |
% do all its macro definitions. We can not do |\RequirePackage{xinttrig}| or |
| 46051 |
% |\usepackage{xinttrig}| as it has occurred already under the user |
| 46052 |
% responsability, so we use |\@@input|. |
| 46053 |
% \begin{macrocode} |
| 46054 |
\@@input xinttrig.sty\relax |
| 46055 |
\else |
| 46056 |
% \end{macrocode} |
| 46057 |
% Here this is either the normal case with \LaTeX{} (or other formats |
| 46058 |
% providing |\RequirePackage|) and \xintexprnameimp requested by user |
| 46059 |
% directly, or some more exotic possibility such as \eTeX{} with the |
| 46060 |
% \ctanpackage{miniltx} loaded and then |\input xintexpr.sty\relax| was done. |
| 46061 |
% As |\RequirePackage| appears to be defined we use it. |
| 46062 |
% \begin{macrocode} |
| 46063 |
\RequirePackage{xinttrig}% |
| 46064 |
\fi |
| 46065 |
% \end{macrocode} |
| 46066 |
% Same situation with \xintlognameimp. |
| 46067 |
% \begin{macrocode} |
| 46068 |
\ifcsname [email protected]\endcsname |
| 46069 |
\@@input xintlog.sty\relax |
| 46070 |
\else |
| 46071 |
\RequirePackage{xintlog}% |
| 46072 |
\fi |
| 46073 |
\else |
| 46074 |
% \end{macrocode} |
| 46075 |
% Here we are not with \LaTeX{} and not with \ctanpackage{miniltx} either. |
| 46076 |
% Let's just use |\input|. Perhaps there was an |\input xinttrig.sty| earlier |
| 46077 |
% which triggered |\input xintexpr.sty| after a warning to the user. The |
| 46078 |
% second |\input xinttrig.sty| issued here will execute the macro definitions, |
| 46079 |
% and the former one will abort its own input after that. |
| 46080 |
% \begin{macrocode} |
| 46081 |
\input xinttrig.sty |
| 46082 |
\input xintlog.sty |
| 46083 |
\fi |
| 46084 |
\XINTrestorecatcodesendinput% |
| 46085 |
% \end{macrocode} |
| 46086 |
% \setcounter{xintMacroCnt}{\the\numexpr452+\value{xintMacroCnt}\relax} |
| 46087 |
% \StoreCodelineNo {xintexpr} |
| 46088 |
% \etocsettocdepth{subsubsection} |
| 46089 |
% \cleardoublepage\let\xintexprnameUp\undefined |
| 46090 |
%\gardesactifs |
| 46091 |
%\let</xintexpr>\relax |
| 46092 |
%\let<*xinttrig>\gardesinactifs |
| 46093 |
%</xintexpr>^^A-------------------------------------------------- |
| 46094 |
%<*xinttrig>^^A--------------------------------------------------- |
| 46095 |
%^^A -*- coding: utf-8; mode: doctex; fill-column: 78; sentence-end-double-space: t; eval: (auto-fill-mode -1); fill-paragraph-function: nil; -*- |
| 46096 |
% \clearpage\csname xinttrignameUp\endcsname |
| 46097 |
% \let\MakePrivateLetters\xintMakePrivateLetters |
| 46098 |
% \section{Package \xinttrignameimp implementation} |
| 46099 |
% \RaisedLabel{sec:trigimp} |
| 46100 |
% \etocarticlestylenomarks |
| 46101 |
% \etocsetnexttocdepth {subsubsection} |
| 46102 |
% |
| 46103 |
% \localtableofcontents |
| 46104 |
% |
| 46105 |
% A preliminary implementation was done only late in the development of |
| 46106 |
% \xintexprnameimp, as an example of the high level user interface, in January |
| 46107 |
% 2019. In March and April 2019 I improved the algorithm for the inverse |
| 46108 |
% trigonometrical functions and included the whole as a new \csbxint{expr} |
| 46109 |
% module. But, as the high level interface provided no way to have |
| 46110 |
% intermediate steps executed with guard digits, the whole scheme could only |
| 46111 |
% target say P-2 digits where P is the prevailing precision, and only with a |
| 46112 |
% moderate requirement on what it means to have P-2 digits about correct. |
| 46113 |
% |
| 46114 |
% Finally in April 2021, after having at long last added exponential and |
| 46115 |
% logarithm up to 62 digits and at a rather strong precision requirement |
| 46116 |
% (something like, say with inputs in normal ranges: targeting at most 0.505ulp |
| 46117 |
% distance to exact result), I revisited the code here. |
| 46118 |
% |
| 46119 |
% We keep most of the high level usage of \csbxint{deffloatfunc}, but hack |
| 46120 |
% into its process in order to let it map the 4 operations and some functions |
| 46121 |
% such as square-root to macros using 4 extra digits. This hack is enough to |
| 46122 |
% support the used syntax here, but is not usable generally. All functions and |
| 46123 |
% their auxiliaries defined during the time the hack applies are named with |
| 46124 |
% |@| as first letter. |
| 46125 |
% |
| 46126 |
% Later the public functions, without the |@|, are defined as wrappers of the |
| 46127 |
% |@|-named ones, which float-round to P digits on output. |
| 46128 |
% |
| 46129 |
% Apart from that the sine and cosine series were implemented at macro level, |
| 46130 |
% bypassing the \csbxint{deffloatfunc} interface. This is done mainly for |
| 46131 |
% handling Digits at high value (24 or more) as it then becomes beneficial to |
| 46132 |
% float-round the variable to less and less digits, the deeper one goes into |
| 46133 |
% the series. |
| 46134 |
% |
| 46135 |
% And regarding the arcsine I modified a bit my original idea in order to |
| 46136 |
% execute the first step in a single \cs{numexpr}. It turns out that that for |
| 46137 |
% 16 digits the algorithm then ``only'' needs one sine and one cosine |
| 46138 |
% evaluation (and a square-root), and there is no need for an arcsine series |
| 46139 |
% auxiliary then. I am aware this is by far not the ``best'' approach but the |
| 46140 |
% problem is that I am a bit enamored into the idea of the algorithm even |
| 46141 |
% though it is at least twice as costly than a sine evaluation! Actually, for |
| 46142 |
% many digits, it turns out the arcsine is less costly than two random sine |
| 46143 |
% evaluations, probably because the latter have the overhead of range |
| 46144 |
% reduction. |
| 46145 |
% |
| 46146 |
% Speaking of this, the range reduction is rather naive and not extremely |
| 46147 |
% ambitious. I wrote it initially having only |sind()| and |cosd()| in mind, |
| 46148 |
% and in 2019 reduced degrees to radians in the most naive way possible. I |
| 46149 |
% have only slighly improved this for this |1.4e| 2021 release, the announced |
| 46150 |
% precision for inputs less than say |1e6|, but at |1e8| and higher, one will |
| 46151 |
% start feeling the gradual loss of precision compared to the task of |
| 46152 |
% computing the exact mathematical result correctly rounded. Also, I do not |
| 46153 |
% worry here about what happens when the input is very near a big multiple of |
| 46154 |
% $\pi$, and one computes a sine for example. Maybe I will improve in future |
| 46155 |
% this aspect but I decided I was seriously running out of steam for the |
| 46156 |
% |1.4e| release. |
| 46157 |
% |
| 46158 |
% As commented in \xintlognameimp regarding exponential and logarithms, even |
| 46159 |
% though we have instilled here some dose of lower level coding, the whole |
| 46160 |
% suffers from \xintfracnameimp not yet having made floating point numbers a |
| 46161 |
% native type. Thus inefficiencies accumulate... |
| 46162 |
% |
| 46163 |
% At 8 digits, the gain was only about 40\% compared to 16 digits. So at the |
| 46164 |
% last minute, on the day I was going to do the release I decided to implement |
| 46165 |
% a poorman way for sine and cosine, for "speed". I transferred the idea from |
| 46166 |
% the arcsine numexpr to sine and cosine. Indeed there is an interesting speed |
| 46167 |
% again of about 4X compared to applying the same approach as for higher |
| 46168 |
% values of Digits. Correct rounding during random testing is still obtained |
| 46169 |
% reasonably often (at any rate more than 95\% of cases near 45 degrees and |
| 46170 |
% always faithful rounding), although at less than the 99\% reached for the |
| 46171 |
% main branch handling Digits up to 62. But the precision is more than enough |
| 46172 |
% for usage in plots for example. I am keeping the guard digits, as removing |
| 46173 |
% then would add a further speed gain of about 20\% to 40\% but the precision |
| 46174 |
% then would drop dramatically, and this is not acceptable at the time of our |
| 46175 |
% 2021 standards (not a period of enlightenment generally speaking, though). |
| 46176 |
% |
| 46177 |
% \subsection{Catcodes, \protect\eTeX{} and reload detection} |
| 46178 |
% \changed{1.4l} |
| 46179 |
%\begin{lverb} |
| 46180 |
% Silly paranoid modification of \z in case { and } do not have their |
| 46181 |
% normal catcodes when xinttrig.sty is reloaded (initial loading via |
| 46182 |
% xintexpr.sty does not need this), to define \XINTtrigendinput there and not |
| 46183 |
% after the \endgroup from \z has already restored possibly bad catcodes. |
| 46184 |
% |
| 46185 |
% 1.4l handles much better the situation with \usepackage{xinttrig} without |
| 46186 |
% previous loading of xintexpr (or same with \input and etex). cf comments in |
| 46187 |
% xintlog.sty. |
| 46188 |
% |
| 46189 |
%\end{lverb} |
| 46190 |
% \begin{macrocode} |
| 46191 |
\begingroup\catcode61\catcode48\catcode32=10\relax% |
| 46192 |
\catcode13=5 % ^^M |
| 46193 |
\endlinechar=13 % |
| 46194 |
\catcode123=1 % { |
| 46195 |
\catcode125=2 % } |
| 46196 |
\catcode64=11 % @ |
| 46197 |
\catcode35=6 % # |
| 46198 |
\catcode44=12 % , |
| 46199 |
\catcode46=12 % . |
| 46200 |
\catcode58=12 % : |
| 46201 |
\catcode94=7 % ^ |
| 46202 |
\def\empty{}\def\space{ }\newlinechar10 |
| 46203 |
\def\z{\endgroup}% |
| 46204 |
\expandafter\let\expandafter\x\csname [email protected]\endcsname |
| 46205 |
\expandafter\let\expandafter\w\csname [email protected]\endcsname |
| 46206 |
\expandafter |
| 46207 |
\ifx\csname PackageWarningNoLine\endcsname\relax |
| 46208 |
\def\y#1#2{\immediate\write128{^^JPackage #1 Warning:^^J% |
| 46209 |
\space\space\space\space#2.^^J}}% |
| 46210 |
\else |
| 46211 |
\def\y#1#2{\PackageWarningNoLine{#1}{#2}}% |
| 46212 |
\fi |
| 46213 |
\expandafter |
| 46214 |
\ifx\csname numexpr\endcsname\relax |
| 46215 |
\y{xinttrig}{\numexpr not available, aborting input}% |
| 46216 |
\def\z{\endgroup\endinput}% |
| 46217 |
\else |
| 46218 |
\ifx\w\relax % xintexpr.sty not yet loaded. |
| 46219 |
\edef\MsgBrk{^^J\space\space\space\space}% |
| 46220 |
\y{xinttrig}% |
| 46221 |
{\ifx\x\empty |
| 46222 |
xinttrig should not be loaded directly\MessageBreak |
| 46223 |
The correct way is \string\usepackage{xintexpr}.\MessageBreak |
| 46224 |
Will try that now% |
| 46225 |
\else |
| 46226 |
First loading of xinttrig.sty should be via |
| 46227 |
\string\input\space xintexpr.sty\relax\MsgBrk |
| 46228 |
Will try that now% |
| 46229 |
\fi |
| 46230 |
}% |
| 46231 |
\ifx\x\empty |
| 46232 |
\def\z{\endgroup\RequirePackage{xintexpr}\endinput}% |
| 46233 |
\else |
| 46234 |
\def\z{\endgroup\input xintexpr.sty\relax\endinput}% |
| 46235 |
\fi |
| 46236 |
\else |
| 46237 |
\def\z{\endgroup\edef\XINTtrigendinput{\XINTrestorecatcodes\noexpand\endinput}}% |
| 46238 |
\fi |
| 46239 |
\fi |
| 46240 |
\z% |
| 46241 |
\XINTsetcatcodes% |
| 46242 |
\catcode`? 12 |
| 46243 |
% \end{macrocode} |
| 46244 |
% \subsection{Library identification} |
| 46245 |
% If the file has already been loaded, let's skip the |\ProvidesPackage|. |
| 46246 |
% Else let's do it and set a flag to indicate loading happened at least once |
| 46247 |
% already. |
| 46248 |
% \changed{1.4l} |
| 46249 |
% Message also to Terminal not only log file. |
| 46250 |
% \begin{macrocode} |
| 46251 |
\ifcsname xintlibver@trig\endcsname |
| 46252 |
\expandafter\xint_firstoftwo |
| 46253 |
\else |
| 46254 |
\expandafter\xint_secondoftwo |
| 46255 |
\fi |
| 46256 |
{\immediate\write128{Reloading xinttrig library using Digits=\xinttheDigits.}}% |
| 46257 |
{\expandafter\gdef\csname xintlibver@trig\endcsname{2025/09/06 v1.4o}% |
| 46258 |
\XINT_providespackage |
| 46259 |
\ProvidesPackage{xinttrig}% |
| 46260 |
[2025/09/06 v1.4o Trigonometrical functions for xintexpr (JFB)]% |
| 46261 |
}% |
| 46262 |
% \end{macrocode} |
| 46263 |
% \subsection{Ensure used letters are dummy letters} |
| 46264 |
% \begin{macrocode} |
| 46265 |
\xintFor* #1 in {iDTVtuwxyzX}\do{\xintensuredummy{#1}}% |
| 46266 |
% \end{macrocode} |
| 46267 |
% \subsection{\csh{xintreloadxinttrig}} |
| 46268 |
%\begin{lverb} |
| 46269 |
% Much simplified at 1.4e, from a modified catcode regime management. |
| 46270 |
%\end{lverb} |
| 46271 |
% \begin{macrocode} |
| 46272 |
\def\xintreloadxinttrig{\input xinttrig.sty }% |
| 46273 |
% \end{macrocode} |
| 46274 |
% \subsection{Auxiliary variables} |
| 46275 |
%\begin{lverb} |
| 46276 |
% The variables with private names have extra digits. Whether private or |
| 46277 |
% public, the variables can all be redefined without impacting the defined |
| 46278 |
% functions, whose meanings will contain already the variable values. |
| 46279 |
% |
| 46280 |
% Formerly variables holding the 1/n! were defined, but this got removed at 1.4e. |
| 46281 |
%\end{lverb} |
| 46282 |
% \subsubsection{\cshn{@twoPi}, \cshn{@threePiover2}, \cshn{@Pi}, \cshn{@Piover2}} |
| 46283 |
%\begin{lverb} |
| 46284 |
% At 1.4e we need more digits, also \xintdeffloatvar changed and always rounds |
| 46285 |
% to P=Digits precision so we use another path to store values with extra digits. |
| 46286 |
%\end{lverb} |
| 46287 |
% \begin{macrocode} |
| 46288 |
\xintdefvar @twoPi := |
| 46289 |
float( |
| 46290 |
6.2831853071795864769252867665590057683943387987502116419498891846156328125724180 |
| 46291 |
,\XINTdigitsormax+4);% |
| 46292 |
\xintdefvar @threePiover2 := |
| 46293 |
float( |
| 46294 |
4.7123889803846898576939650749192543262957540990626587314624168884617246094293135 |
| 46295 |
,\XINTdigitsormax+4);% |
| 46296 |
\xintdefvar @Pi := |
| 46297 |
float( |
| 46298 |
3.1415926535897932384626433832795028841971693993751058209749445923078164062862090 |
| 46299 |
,\XINTdigitsormax+4);% |
| 46300 |
\xintdefvar @Piover2 := |
| 46301 |
float( |
| 46302 |
1.5707963267948966192313216916397514420985846996875529104874722961539082031431045 |
| 46303 |
,\XINTdigitsormax+4);% |
| 46304 |
% \end{macrocode} |
| 46305 |
% \subsubsection{\cshn{@oneDegree}, \cshn{@oneRadian}} |
| 46306 |
%\begin{lverb} |
| 46307 |
% Those are needed for range reduction, particularly @oneRadian. We define |
| 46308 |
% it with 12 extra digits. But the whole process of range reduction in radians |
| 46309 |
% is very naive one. |
| 46310 |
%\end{lverb} |
| 46311 |
% \begin{macrocode} |
| 46312 |
\xintdefvar @oneDegree := |
| 46313 |
float( |
| 46314 |
0.017453292519943295769236907684886127134428718885417254560971914401710091146034494 |
| 46315 |
,\XINTdigitsormax+4);% |
| 46316 |
\xintdefvar @oneRadian := |
| 46317 |
float( |
| 46318 |
57.295779513082320876798154814105170332405472466564321549160243861202847148321553 |
| 46319 |
,\XINTdigitsormax+12);% |
| 46320 |
% \end{macrocode} |
| 46321 |
% \subsection{Hack \cs{xintdeffloatfunc} for inserting usage of guard digits} |
| 46322 |
%\begin{lverb} |
| 46323 |
% 1.4e. This is not a general approach, but it sufficient for the |
| 46324 |
% limited use case done here of \xintdeffloatfunc. What it does is to let |
| 46325 |
% \xintdeffloatfunc hardcode usage of macros which will execute computations |
| 46326 |
% with an elevated number of digits. But for example if 5/3 is encountered in |
| 46327 |
% a float expression it will remain unevaluated so one would have to use |
| 46328 |
% alternate input syntax for efficiency (\xintexpr |
| 46329 |
% float(5/3,\xinttheDigits+4)\relax as a subexpression, for example). |
| 46330 |
%\end{lverb} |
| 46331 |
% \begin{macrocode} |
| 46332 |
\catcode`~ 12 |
| 46333 |
\def\XINT_tmpa#1#2#3.#4.% |
| 46334 |
{% |
| 46335 |
\let #1#2% |
| 46336 |
\def #2##1##2##3##4% |
| 46337 |
{##2##3{{~expanded{~xint_noxpd{#4[#3]}~expandafter}~expanded{##1##4}}}}% |
| 46338 |
}% |
| 46339 |
\expandafter\XINT_tmpa |
| 46340 |
\csname XINT_flexpr_exec_+_\expandafter\endcsname |
| 46341 |
\csname XINT_flexpr_exec_+\expandafter\endcsname |
| 46342 |
\the\numexpr\XINTdigitsormax+4.~XINTinFloatAdd_wopt.% |
| 46343 |
\expandafter\XINT_tmpa |
| 46344 |
\csname XINT_flexpr_exec_-_\expandafter\endcsname |
| 46345 |
\csname XINT_flexpr_exec_-\expandafter\endcsname |
| 46346 |
\the\numexpr\XINTdigitsormax+4.~XINTinFloatSub_wopt.% |
| 46347 |
\expandafter\XINT_tmpa |
| 46348 |
\csname XINT_flexpr_exec_*_\expandafter\endcsname |
| 46349 |
\csname XINT_flexpr_exec_*\expandafter\endcsname |
| 46350 |
\the\numexpr\XINTdigitsormax+4.~XINTinFloatMul_wopt.% |
| 46351 |
\expandafter\XINT_tmpa |
| 46352 |
\csname XINT_flexpr_exec_/_\expandafter\endcsname |
| 46353 |
\csname XINT_flexpr_exec_/\expandafter\endcsname |
| 46354 |
\the\numexpr\XINTdigitsormax+4.~XINTinFloatDiv_wopt.% |
| 46355 |
\def\XINT_tmpa#1#2#3.#4.% |
| 46356 |
{% |
| 46357 |
\let #1#2% |
| 46358 |
\def #2##1##2##3{##1##2{{~expanded{~xint_noxpd{#4[#3]}~expandafter}##3}}}% |
| 46359 |
}% |
| 46360 |
\expandafter\XINT_tmpa |
| 46361 |
\csname XINT_flexpr_sqrfunc\expandafter\endcsname |
| 46362 |
\csname XINT_flexpr_func_sqr\expandafter\endcsname |
| 46363 |
\the\numexpr\XINTdigitsormax+4.~XINTinFloatSqr_wopt.% |
| 46364 |
\expandafter\XINT_tmpa |
| 46365 |
\csname XINT_flexpr_sqrtfunc\expandafter\endcsname |
| 46366 |
\csname XINT_flexpr_func_sqrt\expandafter\endcsname |
| 46367 |
\the\numexpr\XINTdigitsormax+4.~XINTinFloatSqrt.% |
| 46368 |
\expandafter\XINT_tmpa |
| 46369 |
\csname XINT_flexpr_invfunc\expandafter\endcsname |
| 46370 |
\csname XINT_flexpr_func_inv\expandafter\endcsname |
| 46371 |
\the\numexpr\XINTdigitsormax+4.~XINTinFloatInv_wopt.% |
| 46372 |
\catcode`~ 3 |
| 46373 |
% \end{macrocode} |
| 46374 |
% \subsection{The sine and cosine series} |
| 46375 |
%\begin{lverb} |
| 46376 |
% Old pending question: should I rather use successive divisions by (2n+1)(2n), or rather |
| 46377 |
% multiplication by their precomputed inverses, in a modified Horner scheme ? |
| 46378 |
% The \ifnum tests are executed at time of definition. |
| 46379 |
% |
| 46380 |
% Update at last minute: this is actually exactly what I do if Digits is at |
| 46381 |
% most 8. |
| 46382 |
% |
| 46383 |
% Small values of the variable are very badly handled here because a much |
| 46384 |
% shorter truncation of the series should be used. |
| 46385 |
% |
| 46386 |
% At 1.4e the original \xintdeffloatfunc was converted into macros, whose |
| 46387 |
% principle can be seen also at work in xintlog.sty. We prepare the input |
| 46388 |
% variables with shorter and shorter mantissas for usage deep in the series. |
| 46389 |
% |
| 46390 |
% This divided by about 3 the execution cost of the series for P about 60. |
| 46391 |
% |
| 46392 |
% Originally, the thresholds were computed a priori with 0.79 as upper bound |
| 46393 |
% of the variable, but then for 1.4e I developped enough test files to try to |
| 46394 |
% adjust heuristically with a target of say |
| 46395 |
% 99,5$% of correct rounding, and always at most |
| 46396 |
% 1ulp error. The numerical analysis is not easy due to the complications of |
| 46397 |
% the implementation... |
| 46398 |
% |
| 46399 |
% Also, random testing never explores the weak spots... |
| 46400 |
% |
| 46401 |
% The 0.79 (a bit more than Pi/4) upper bound induces a costly check of |
| 46402 |
% variable on input, if Digits is big. Much faster would be to check if input |
| 46403 |
% is less than 10 degrees or 1 radian as done in xfp. But using enough |
| 46404 |
% coefficients for allowing up to 1 radian, which is without pain for |
| 46405 |
% Digits=16 starts being annoying for higher values such as Digits=48. |
| 46406 |
% |
| 46407 |
% But the main reason I don't do it now is that I spend too much time |
| 46408 |
% fine-tuning the table of thresholds... maybe in next release. |
| 46409 |
%\end{lverb} |
| 46410 |
% \subsubsection{Support macros for the sine and cosine series} |
| 46411 |
% |
| 46412 |
%\begin{lverb} |
| 46413 |
% Computing the 1/n! from n! then inverting would require |
| 46414 |
% costly divisions and significantly increase the loading time. |
| 46415 |
% |
| 46416 |
% So a method is employed to simply divide by 2k(2k-1) or (2k+1)(2k) |
| 46417 |
% step by step, with what we hope are enough 8 security digits, and |
| 46418 |
% reducing the sizes of the mantissas at each step. |
| 46419 |
% |
| 46420 |
% This whole section is conditional on Digits being at least nine. |
| 46421 |
%\end{lverb} |
| 46422 |
% |
| 46423 |
% \begin{macrocode} |
| 46424 |
\ifnum\XINTdigits>8 |
| 46425 |
\edef\XINT_tmpG % 1/3! |
| 46426 |
{1\xintReplicate{\XINTdigitsormax+2}{6}7[\the\numexpr-\XINTdigitsormax-4]}% |
| 46427 |
\edef\XINT_tmpH % 1/5! |
| 46428 |
{8\xintReplicate{\XINTdigitsormax+1}{3}[\the\numexpr-\XINTdigitsormax-4]}% |
| 46429 |
\edef\XINT_tmpd % 1/5! |
| 46430 |
{8\xintReplicate{\XINTdigitsormax+9}{3}[\the\numexpr-\XINTdigitsormax-12]}% |
| 46431 |
\def\XINT_tmpe#1.#2.#3.#4.#5#6#7% |
| 46432 |
{% |
| 46433 |
\def#5##1\xint: |
| 46434 |
{% |
| 46435 |
\expandafter#6\romannumeral0\XINTinfloatS[#2]{##1}\xint:##1\xint: |
| 46436 |
}% |
| 46437 |
\def#6##1\xint: |
| 46438 |
{% |
| 46439 |
\expandafter#7\romannumeral0\xintsub{#4}{\XINTinFloat[#2]{\xintMul{#3}{##1}}}\xint: |
| 46440 |
}% |
| 46441 |
\def#7##1\xint:##2\xint: |
| 46442 |
{% |
| 46443 |
\xintSub{1/1[0]}{\XINTinFloat[#1]{\xintMul{##1}{##2}}}% |
| 46444 |
}% |
| 46445 |
}% |
| 46446 |
\expandafter\XINT_tmpe |
| 46447 |
\the\numexpr\XINTdigitsormax+4\expandafter.% |
| 46448 |
\the\numexpr\XINTdigitsormax+2\expandafter.\expanded{% |
| 46449 |
\XINT_tmpH.% 1/5! |
| 46450 |
\XINT_tmpG.% 1/3! |
| 46451 |
\expandafter}% |
| 46452 |
\csname XINT_SinAux_series_a_iii\expandafter\endcsname |
| 46453 |
\csname XINT_SinAux_series_b\expandafter\endcsname |
| 46454 |
\csname XINT_SinAux_series_c_i\endcsname |
| 46455 |
\def\XINT_tmpa #1 #2 #3 #4 #5 #6 #7 #8 % |
| 46456 |
{% |
| 46457 |
\def\XINT_tmpb ##1##2##3##4##5% |
| 46458 |
{% |
| 46459 |
\def\XINT_tmpc####1.####2.####3.####4.####5.% |
| 46460 |
{% |
| 46461 |
\def##1########1\xint: |
| 46462 |
{% |
| 46463 |
\expandafter##2% |
| 46464 |
\romannumeral0\XINTinfloatS[####1]{########1}\xint:########1\xint: |
| 46465 |
}% |
| 46466 |
\def##2########1\xint: |
| 46467 |
{% |
| 46468 |
\expandafter##3% |
| 46469 |
\romannumeral0\XINTinfloatS[####2]{########1}\xint:########1\xint: |
| 46470 |
}% |
| 46471 |
\def##3########1\xint: |
| 46472 |
{% |
| 46473 |
\expandafter##4% |
| 46474 |
\romannumeral0\xintsub{####4}{\XINTinFloat[####2]{\xintMul{####3}{########1}}}\xint: |
| 46475 |
}% |
| 46476 |
\def##4########1\xint:########2\xint: |
| 46477 |
{% |
| 46478 |
\expandafter##5% |
| 46479 |
\romannumeral0\xintsub{####5}% |
| 46480 |
{\XINTinFloat[####1]{\xintMul{########1}{########2}}}\xint: |
| 46481 |
}% |
| 46482 |
}% |
| 46483 |
}% |
| 46484 |
\expandafter\XINT_tmpb |
| 46485 |
\csname XINT_#8Aux_series_a_\romannumeral\numexpr#1-1\expandafter\endcsname |
| 46486 |
\csname XINT_#8Aux_series_a_\romannumeral\numexpr#1\expandafter\endcsname |
| 46487 |
\csname XINT_#8Aux_series_b\expandafter\endcsname |
| 46488 |
\csname XINT_#8Aux_series_c_\romannumeral\numexpr#1-2\expandafter\endcsname |
| 46489 |
\csname XINT_#8Aux_series_c_\romannumeral\numexpr#1-3\endcsname |
| 46490 |
\edef\XINT_tmpd |
| 46491 |
{\XINTinFloat[\XINTdigitsormax-#2+8]{\xintDiv{\XINT_tmpd}{\the\numexpr#5*(#5-1)\relax}}}% |
| 46492 |
\let\XINT_tmpF\XINT_tmpG |
| 46493 |
\let\XINT_tmpG\XINT_tmpH |
| 46494 |
\edef\XINT_tmpH{\XINTinFloat[\XINTdigitsormax-#2]{\XINT_tmpd}}% |
| 46495 |
\expandafter\XINT_tmpc |
| 46496 |
\the\numexpr\XINTdigitsormax-#3\expandafter.% |
| 46497 |
\the\numexpr\XINTdigitsormax-#2\expandafter.\expanded{% |
| 46498 |
\XINT_tmpH.% |
| 46499 |
\XINT_tmpG.% |
| 46500 |
\XINT_tmpF.% |
| 46501 |
}% |
| 46502 |
}% |
| 46503 |
\XINT_tmpa 4 -1 -2 -4 7 5 3 Sin % |
| 46504 |
\ifnum\XINTdigits>3 \XINT_tmpa 5 1 -1 -2 9 7 5 Sin \fi |
| 46505 |
\ifnum\XINTdigits>5 \XINT_tmpa 6 3 1 -1 11 9 7 Sin \fi |
| 46506 |
\ifnum\XINTdigits>8 \XINT_tmpa 7 6 3 1 13 11 9 Sin \fi |
| 46507 |
\ifnum\XINTdigits>11 \XINT_tmpa 8 9 6 3 15 13 11 Sin \fi |
| 46508 |
\ifnum\XINTdigits>14 \XINT_tmpa 9 12 9 6 17 15 13 Sin \fi |
| 46509 |
\ifnum\XINTdigits>16 \XINT_tmpa 10 14 12 9 19 17 15 Sin \fi |
| 46510 |
\ifnum\XINTdigits>19 \XINT_tmpa 11 17 14 12 21 19 17 Sin \fi |
| 46511 |
\ifnum\XINTdigits>22 \XINT_tmpa 12 20 17 14 23 21 19 Sin \fi |
| 46512 |
\ifnum\XINTdigits>25 \XINT_tmpa 13 23 20 17 25 23 21 Sin \fi |
| 46513 |
\ifnum\XINTdigits>28 \XINT_tmpa 14 26 23 20 27 25 23 Sin \fi |
| 46514 |
\ifnum\XINTdigits>31 \XINT_tmpa 15 29 26 23 29 27 25 Sin \fi |
| 46515 |
\ifnum\XINTdigits>34 \XINT_tmpa 16 32 29 26 31 29 27 Sin \fi |
| 46516 |
\ifnum\XINTdigits>37 \XINT_tmpa 17 35 32 29 33 31 29 Sin \fi |
| 46517 |
\ifnum\XINTdigits>40 \XINT_tmpa 18 38 35 32 35 33 31 Sin \fi |
| 46518 |
\ifnum\XINTdigits>44 \XINT_tmpa 19 42 38 35 37 35 33 Sin \fi |
| 46519 |
\ifnum\XINTdigits>47 \XINT_tmpa 20 45 42 38 39 37 35 Sin \fi |
| 46520 |
\ifnum\XINTdigits>51 \XINT_tmpa 21 49 45 42 41 39 37 Sin \fi |
| 46521 |
\ifnum\XINTdigits>55 \XINT_tmpa 22 53 49 45 43 41 39 Sin \fi |
| 46522 |
\ifnum\XINTdigits>58 \XINT_tmpa 23 56 53 49 45 43 41 Sin \fi |
| 46523 |
\edef\XINT_tmpd % 1/4! |
| 46524 |
{41\xintReplicate{\XINTdigitsormax+8}{6}7[\the\numexpr-\XINTdigitsormax-12]}% |
| 46525 |
\edef\XINT_tmpH % 1/4! |
| 46526 |
{41\xintReplicate{\XINTdigitsormax}{6}7[\the\numexpr-\XINTdigitsormax-4]}% |
| 46527 |
\def\XINT_tmpG{5[-1]}% 1/2! |
| 46528 |
\expandafter\XINT_tmpe |
| 46529 |
\the\numexpr\XINTdigitsormax+4\expandafter.% |
| 46530 |
\the\numexpr\XINTdigitsormax+3\expandafter.\expanded{% |
| 46531 |
\XINT_tmpH.% |
| 46532 |
\XINT_tmpG.% |
| 46533 |
\expandafter}% |
| 46534 |
\csname XINT_CosAux_series_a_iii\expandafter\endcsname |
| 46535 |
\csname XINT_CosAux_series_b\expandafter\endcsname |
| 46536 |
\csname XINT_CosAux_series_c_i\endcsname |
| 46537 |
\XINT_tmpa 4 -2 -3 -4 6 4 2 Cos % |
| 46538 |
\ifnum\XINTdigits>2 \XINT_tmpa 5 0 -2 -3 8 6 4 Cos \fi |
| 46539 |
\ifnum\XINTdigits>4 \XINT_tmpa 6 2 0 -2 10 8 6 Cos \fi |
| 46540 |
\ifnum\XINTdigits>7 \XINT_tmpa 7 5 2 0 12 10 8 Cos \fi |
| 46541 |
\ifnum\XINTdigits>9 \XINT_tmpa 8 7 5 2 14 12 10 Cos \fi |
| 46542 |
\ifnum\XINTdigits>12 \XINT_tmpa 9 10 7 5 16 14 12 Cos \fi |
| 46543 |
\ifnum\XINTdigits>15 \XINT_tmpa 10 13 10 7 18 16 14 Cos \fi |
| 46544 |
\ifnum\XINTdigits>18 \XINT_tmpa 11 16 13 10 20 18 16 Cos \fi |
| 46545 |
\ifnum\XINTdigits>20 \XINT_tmpa 12 18 16 13 22 20 18 Cos \fi |
| 46546 |
\ifnum\XINTdigits>24 \XINT_tmpa 13 22 18 16 24 22 20 Cos \fi |
| 46547 |
\ifnum\XINTdigits>27 \XINT_tmpa 14 25 22 18 26 24 22 Cos \fi |
| 46548 |
\ifnum\XINTdigits>30 \XINT_tmpa 15 28 25 22 28 26 24 Cos \fi |
| 46549 |
\ifnum\XINTdigits>33 \XINT_tmpa 16 31 28 25 30 28 26 Cos \fi |
| 46550 |
\ifnum\XINTdigits>36 \XINT_tmpa 17 34 31 28 32 30 28 Cos \fi |
| 46551 |
\ifnum\XINTdigits>39 \XINT_tmpa 18 37 34 31 34 32 30 Cos \fi |
| 46552 |
\ifnum\XINTdigits>42 \XINT_tmpa 19 40 37 34 36 34 32 Cos \fi |
| 46553 |
\ifnum\XINTdigits>45 \XINT_tmpa 20 43 40 37 38 36 34 Cos \fi |
| 46554 |
\ifnum\XINTdigits>49 \XINT_tmpa 21 47 43 40 40 38 36 Cos \fi |
| 46555 |
\ifnum\XINTdigits>53 \XINT_tmpa 22 51 47 43 42 40 38 Cos \fi |
| 46556 |
\ifnum\XINTdigits>57 \XINT_tmpa 23 55 51 47 44 42 40 Cos \fi |
| 46557 |
\ifnum\XINTdigits>60 \XINT_tmpa 24 58 55 51 46 44 42 Cos \fi |
| 46558 |
\let\XINT_tmpH\xint_undefined\let\XINT_tmpG\xint_undefined\let\XINT_tmpF\xint_undefined |
| 46559 |
\let\XINT_tmpd\xint_undefined\let\XINT_tmpe\xint_undefined |
| 46560 |
\def\XINT_SinAux_series#1% |
| 46561 |
{% |
| 46562 |
\expandafter\XINT_SinAux_series_a_iii |
| 46563 |
\romannumeral0\XINTinfloatS[\XINTdigitsormax+4]{#1}\xint: |
| 46564 |
}% |
| 46565 |
\def\XINT_CosAux_series#1% |
| 46566 |
{% |
| 46567 |
\expandafter\XINT_CosAux_series_a_iii |
| 46568 |
\romannumeral0\XINTinfloatS[\XINTdigitsormax+4]{#1}\xint: |
| 46569 |
}% |
| 46570 |
\fi % end of \XINTdigits>8 |
| 46571 |
% \end{macrocode} |
| 46572 |
% \subsubsection{The poor man approximate but speedier approach for Digits at most 8} |
| 46573 |
% \begin{macrocode} |
| 46574 |
\ifnum\XINTdigits<9 |
| 46575 |
\def\XINT_SinAux_series#1% |
| 46576 |
{% |
| 46577 |
\the\numexpr\expandafter\XINT_SinAux_b\romannumeral0\xintiround9{#1}.[-9]% |
| 46578 |
}% |
| 46579 |
\def\XINT_SinAux_b#1.% |
| 46580 |
{% |
| 46581 |
((((((((((((%(\xint_c_x^ix/-210) |
| 46582 |
-4761905*#1/\xint_c_x^ix+\xint_c_x^ix)/% |
| 46583 |
-156)*#1/\xint_c_x^ix+\xint_c_x^ix)/% |
| 46584 |
-110)*#1/\xint_c_x^ix+\xint_c_x^ix)/% |
| 46585 |
-72)*#1/\xint_c_x^ix+\xint_c_x^ix)/% |
| 46586 |
-42)*#1/\xint_c_x^ix+\xint_c_x^ix)/% |
| 46587 |
-20)*#1/\xint_c_x^ix+\xint_c_x^ix)/% |
| 46588 |
-6)*#1/\xint_c_x^ix+\xint_c_x^ix |
| 46589 |
}% |
| 46590 |
\def\XINT_CosAux_series#1% |
| 46591 |
{% |
| 46592 |
\the\numexpr\expandafter\XINT_CosAux_b\romannumeral0\xintiround9{#1}.[-9]% |
| 46593 |
}% |
| 46594 |
\def\XINT_CosAux_b#1.% |
| 46595 |
{% |
| 46596 |
((((((((((((((%(\xint_c_x^ix/-240) |
| 46597 |
-4166667*#1/\xint_c_x^ix+\xint_c_x^ix)/% |
| 46598 |
-182)*#1/\xint_c_x^ix+\xint_c_x^ix)/% |
| 46599 |
-132)*#1/\xint_c_x^ix+\xint_c_x^ix)/% |
| 46600 |
-90)*#1/\xint_c_x^ix+\xint_c_x^ix)/% |
| 46601 |
-56)*#1/\xint_c_x^ix+\xint_c_x^ix)/% |
| 46602 |
-30)*#1/\xint_c_x^ix+\xint_c_x^ix)/% |
| 46603 |
-12)*#1/\xint_c_x^ix+\xint_c_x^ix)/% |
| 46604 |
-2)*#1/\xint_c_x^ix+\xint_c_x^ix |
| 46605 |
}% |
| 46606 |
\fi |
| 46607 |
% \end{macrocode} |
| 46608 |
% \subsubsection{Declarations of the \cshn{@sin_aux()} and \cshn{@cos_aux()} functions} |
| 46609 |
% \begin{macrocode} |
| 46610 |
\def\XINT_flexpr_func_@sin_aux#1#2#3% |
| 46611 |
{% |
| 46612 |
\expandafter #1\expandafter #2\expandafter{% |
| 46613 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 46614 |
{\romannumeral`&&@\XINT_SinAux_series#3}}% |
| 46615 |
}% |
| 46616 |
\def\XINT_flexpr_func_@cos_aux#1#2#3% |
| 46617 |
{% |
| 46618 |
\expandafter #1\expandafter #2\expandafter{% |
| 46619 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 46620 |
{\romannumeral`&&@\XINT_CosAux_series#3}}% |
| 46621 |
}% |
| 46622 |
% \end{macrocode} |
| 46623 |
% \subsubsection{\cshn{@sin_series()}, \cshn{@cos_series()}} |
| 46624 |
% \begin{macrocode} |
| 46625 |
\xintdeffloatfunc @sin_series(x) := x * @sin_aux(sqr(x));% |
| 46626 |
\xintdeffloatfunc @cos_series(x) := @cos_aux(sqr(x));% |
| 46627 |
% \end{macrocode} |
| 46628 |
% \subsection{Range reduction for sine and cosine using degrees} |
| 46629 |
% |
| 46630 |
%\begin{lverb} |
| 46631 |
% As commented in the package introduction, Range reduction is a demanding |
| 46632 |
% domain and we handle it semi-satisfactorily. The main problem is that in |
| 46633 |
% January 2019 I had done only support for degrees, and when I added radians I |
| 46634 |
% used the most naive approach. But one can find worse: in 2019 I was |
| 46635 |
% surprised to observe important divergences with Maple's results at 16 digits |
| 46636 |
% near -π. Turns out that Maple probably adds π |
| 46637 |
% in the floating point sense causing catastrophic loss of digits when one is |
| 46638 |
% near -π. On the other hand even though the approach here is still naive, it |
| 46639 |
% behaves much better. |
| 46640 |
% |
| 46641 |
% The @sind_rr() and @cosd_rr() sine and cosine "doing range reduction" are |
| 46642 |
% coded directly at macro level via \xintSind and \xintCosd which will |
| 46643 |
% dispatch to usage of the sine or cosine series, depending on case. |
| 46644 |
% |
| 46645 |
% Old note from 2019: attention that \xintSind and \xintCosd must be used |
| 46646 |
% with a positive argument. |
| 46647 |
% |
| 46648 |
% We start with an auxiliary macro to reduce modulo 360 quickly. |
| 46649 |
%\end{lverb} |
| 46650 |
% \subsubsection{Low level modulo 360 helper macro \csh{XINT_mod_ccclx_i}} |
| 46651 |
%\begin{lverb} |
| 46652 |
% input: \the\numexpr\XINT_mod_ccclx_i k.N. (delimited by dots) |
| 46653 |
% |
| 46654 |
% output: (N times 10^k) modulo 360. (with a final dot) |
| 46655 |
% |
| 46656 |
% Attention that N must be non-negative (I could make it accept negative |
| 46657 |
% but the fact that numexpr / is not periodical in numerator |
| 46658 |
% adds overhead). |
| 46659 |
% |
| 46660 |
% 360 divides 9000 hence 10^{k} is 280 for k at least 3 and the additive |
| 46661 |
% group generated by it modulo 360 is the set of multiples of 40. |
| 46662 |
%\end{lverb} |
| 46663 |
% \begin{macrocode} |
| 46664 |
\def\XINT_mod_ccclx_i #1.% |
| 46665 |
{% |
| 46666 |
\expandafter\XINT_mod_ccclx_e\the\numexpr |
| 46667 |
\expandafter\XINT_mod_ccclx_j\the\numexpr1\ifcase#1 \or0\or00\else000\fi.% |
| 46668 |
}% |
| 46669 |
\def\XINT_mod_ccclx_j 1#1.#2.% |
| 46670 |
{% |
| 46671 |
(\XINT_mod_ccclx_ja {++}#2#1\XINT_mod_ccclx_jb 0000000\relax |
| 46672 |
}% |
| 46673 |
\def\XINT_mod_ccclx_ja #1#2#3#4#5#6#7#8#9% |
| 46674 |
{% |
| 46675 |
#9+#8+#7+#6+#5+#4+#3+#2\xint_firstoftwo{+\XINT_mod_ccclx_ja{+#9+#8+#7}}{#1}% |
| 46676 |
}% |
| 46677 |
\def\XINT_mod_ccclx_jb #1\xint_firstoftwo#2#3{#1+0)*280\XINT_mod_ccclx_jc #1#3}% |
| 46678 |
% \end{macrocode} |
| 46679 |
%\begin{lverb} |
| 46680 |
% Attention that \XINT_cclcx_e wants non negative input because \numexpr |
| 46681 |
% division is not periodical ... |
| 46682 |
%\end{lverb} |
| 46683 |
% \begin{macrocode} |
| 46684 |
\def\XINT_mod_ccclx_jc +#1+#2+#3#4\relax{+80*(#3+#2+#1)+#3#2#1.}% |
| 46685 |
\def\XINT_mod_ccclx_e#1.{\expandafter\XINT_mod_ccclx_z\the\numexpr(#1+180)/360-1.#1.}% |
| 46686 |
\def\XINT_mod_ccclx_z#1.#2.{#2-360*#1.}% |
| 46687 |
% \end{macrocode} |
| 46688 |
% \subsubsection{\cshn{@sind_rr()} function and its support macro \csh{xintSind}} |
| 46689 |
% \begin{macrocode} |
| 46690 |
\def\XINT_flexpr_func_@sind_rr #1#2#3% |
| 46691 |
{% |
| 46692 |
\expandafter #1\expandafter #2\expandafter{% |
| 46693 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one{\romannumeral`&&@\xintSind#3}}% |
| 46694 |
}% |
| 46695 |
% \end{macrocode} |
| 46696 |
%\begin{lverb} |
| 46697 |
% old comment: Must be f-expandable for nesting macros from \xintNewExpr |
| 46698 |
% |
| 46699 |
% This is where the prize of using the same macros for two distinct use cases |
| 46700 |
% has serious disadvantages. The reason of Digits+12 is only to support an |
| 46701 |
% input which contains a multiplication by @oneRadian with its extended |
| 46702 |
% digits. |
| 46703 |
% |
| 46704 |
% Then we do a somewhat strange truncation to a fixed point of fractional |
| 46705 |
% digits, which is ok in the "Degrees" case, but causes issues of its own in |
| 46706 |
% the "Radians" case. Please consider this whole thing as marked for future |
| 46707 |
% improvement, when times allows. |
| 46708 |
% |
| 46709 |
% ATTENTION \xintSind ONLY FOR POSITIVE ARGUMENTS |
| 46710 |
%\end{lverb} |
| 46711 |
% \begin{macrocode} |
| 46712 |
\def\XINT_tmpa #1.{% |
| 46713 |
\def\xintSind##1% |
| 46714 |
{% |
| 46715 |
\romannumeral`&&@\expandafter\xintsind\romannumeral0\XINTinfloatS[#1]{##1}}% |
| 46716 |
}\expandafter\XINT_tmpa\the\numexpr\XINTdigitsormax+12.% |
| 46717 |
\def\xintsind #1[#2#3]% |
| 46718 |
{% |
| 46719 |
\xint_UDsignfork |
| 46720 |
#2\XINT_sind |
| 46721 |
-\XINT_sind_int |
| 46722 |
\krof#2#3.#1..% |
| 46723 |
}% |
| 46724 |
\def\XINT_tmpa #1.{% |
| 46725 |
\def\XINT_sind ##1.##2.% |
| 46726 |
{% |
| 46727 |
\expandafter\XINT_sind_a |
| 46728 |
\romannumeral0\xinttrunc{#1}{##2[##1]}% |
| 46729 |
}% |
| 46730 |
}\expandafter\XINT_tmpa\the\numexpr\XINTdigitsormax+5.% |
| 46731 |
\def\XINT_sind_a{\expandafter\XINT_sind_i\the\numexpr\XINT_mod_ccclx_i0.}% |
| 46732 |
\def\XINT_sind_int |
| 46733 |
{% |
| 46734 |
\expandafter\XINT_sind_i\the\numexpr\expandafter\XINT_mod_ccclx_i |
| 46735 |
}% |
| 46736 |
\def\XINT_sind_i #1.% |
| 46737 |
{% |
| 46738 |
\ifcase\numexpr#1/90\relax |
| 46739 |
\expandafter\XINT_sind_A |
| 46740 |
\or\expandafter\XINT_sind_B\the\numexpr-90+% |
| 46741 |
\or\expandafter\XINT_sind_C\the\numexpr-180+% |
| 46742 |
\or\expandafter\XINT_sind_D\the\numexpr-270+% |
| 46743 |
\else\expandafter\XINT_sind_E\the\numexpr-360+% |
| 46744 |
\fi#1.% |
| 46745 |
}% |
| 46746 |
\def\XINT_tmpa #1.#2.{% |
| 46747 |
\def\XINT_sind_A##1.##2.% |
| 46748 |
{% |
| 46749 |
\XINT_expr_unlock\expandafter\XINT_flexpr_userfunc_@sin_series\expandafter |
| 46750 |
{\romannumeral0\XINTinfloat[#1]{\xintMul{##1.##2}#2}}% |
| 46751 |
}% |
| 46752 |
\def\XINT_sind_B_n-##1.##2.% |
| 46753 |
{% |
| 46754 |
\XINT_expr_unlock\expandafter\XINT_flexpr_userfunc_@cos_series\expandafter |
| 46755 |
{\romannumeral0\XINTinfloat[#1]{\xintMul{\xintSub{##1[0]}{.##2}}#2}}% |
| 46756 |
}% |
| 46757 |
\def\XINT_sind_B_p##1.##2.% |
| 46758 |
{% |
| 46759 |
\XINT_expr_unlock\expandafter\XINT_flexpr_userfunc_@cos_series\expandafter |
| 46760 |
{\romannumeral0\XINTinfloat[#1]{\xintMul{##1.##2}#2}}% |
| 46761 |
}% |
| 46762 |
\def\XINT_sind_C_n-##1.##2.% |
| 46763 |
{% |
| 46764 |
\XINT_expr_unlock\expandafter\XINT_flexpr_userfunc_@sin_series\expandafter |
| 46765 |
{\romannumeral0\XINTinfloat[#1]{\xintMul{\xintSub{##1[0]}{.##2}}#2}}% |
| 46766 |
}% |
| 46767 |
\def\XINT_sind_C_p##1.##2.% |
| 46768 |
{% |
| 46769 |
\xintiiopp\XINT_expr_unlock\expandafter\XINT_flexpr_userfunc_@sin_series\expandafter |
| 46770 |
{\romannumeral0\XINTinfloat[#1]{\xintMul{##1.##2}#2}}% |
| 46771 |
}% |
| 46772 |
\def\XINT_sind_D_n-##1.##2.% |
| 46773 |
{% |
| 46774 |
\xintiiopp\XINT_expr_unlock\expandafter\XINT_flexpr_userfunc_@cos_series\expandafter |
| 46775 |
{\romannumeral0\XINTinfloat[#1]{\xintMul{\xintSub{##1[0]}{.##2}}#2}}% |
| 46776 |
}% |
| 46777 |
\def\XINT_sind_D_p##1.##2.% |
| 46778 |
{% |
| 46779 |
\xintiiopp\XINT_expr_unlock\expandafter\XINT_flexpr_userfunc_@cos_series\expandafter |
| 46780 |
{\romannumeral0\XINTinfloat[#1]{\xintMul{##1.##2}#2}}% |
| 46781 |
}% |
| 46782 |
\def\XINT_sind_E-##1.##2.% |
| 46783 |
{% |
| 46784 |
\xintiiopp\XINT_expr_unlock\expandafter\XINT_flexpr_userfunc_@sin_series\expandafter |
| 46785 |
{\romannumeral0\XINTinfloat[#1]{\xintMul{\xintSub{##1[0]}{.##2}}#2}}% |
| 46786 |
}% |
| 46787 |
}\expandafter\XINT_tmpa |
| 46788 |
\the\numexpr\XINTdigitsormax+4\expandafter.% |
| 46789 |
\romannumeral`&&@\xintbarefloateval @oneDegree\relax.% |
| 46790 |
\def\XINT_sind_B#1{\xint_UDsignfork#1\XINT_sind_B_n-\XINT_sind_B_p\krof #1}% |
| 46791 |
\def\XINT_sind_C#1{\xint_UDsignfork#1\XINT_sind_C_n-\XINT_sind_C_p\krof #1}% |
| 46792 |
\def\XINT_sind_D#1{\xint_UDsignfork#1\XINT_sind_D_n-\XINT_sind_D_p\krof #1}% |
| 46793 |
% \end{macrocode} |
| 46794 |
% \subsubsection{\cshn{@cosd_rr()} function and its support macro \csh{xintCosd}} |
| 46795 |
% \begin{macrocode} |
| 46796 |
\def\XINT_flexpr_func_@cosd_rr #1#2#3% |
| 46797 |
{% |
| 46798 |
\expandafter #1\expandafter #2\expandafter{% |
| 46799 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one{\romannumeral`&&@\xintCosd#3}}% |
| 46800 |
}% |
| 46801 |
% \end{macrocode} |
| 46802 |
%\begin{lverb} |
| 46803 |
% ATTENTION ONLY FOR POSITIVE ARGUMENTS |
| 46804 |
%\end{lverb} |
| 46805 |
% \begin{macrocode} |
| 46806 |
\def\XINT_tmpa #1.{% |
| 46807 |
\def\xintCosd##1% |
| 46808 |
{% |
| 46809 |
\romannumeral`&&@\expandafter\xintcosd\romannumeral0\XINTinfloatS[#1]{##1}}% |
| 46810 |
}\expandafter\XINT_tmpa\the\numexpr\XINTdigitsormax+12.% |
| 46811 |
\def\xintcosd #1[#2#3]% |
| 46812 |
{% |
| 46813 |
\xint_UDsignfork |
| 46814 |
#2\XINT_cosd |
| 46815 |
-\XINT_cosd_int |
| 46816 |
\krof#2#3.#1..% |
| 46817 |
}% |
| 46818 |
\def\XINT_tmpa #1.{% |
| 46819 |
\def\XINT_cosd ##1.##2.% |
| 46820 |
{% |
| 46821 |
\expandafter\XINT_cosd_a |
| 46822 |
\romannumeral0\xinttrunc{#1}{##2[##1]}% |
| 46823 |
}% |
| 46824 |
}\expandafter\XINT_tmpa\the\numexpr\XINTdigitsormax+5.% |
| 46825 |
\def\XINT_cosd_a{\expandafter\XINT_cosd_i\the\numexpr\XINT_mod_ccclx_i0.}% |
| 46826 |
\def\XINT_cosd_int |
| 46827 |
{% |
| 46828 |
\expandafter\XINT_cosd_i\the\numexpr\expandafter\XINT_mod_ccclx_i |
| 46829 |
}% |
| 46830 |
\def\XINT_cosd_i #1.% |
| 46831 |
{% |
| 46832 |
\ifcase\numexpr#1/90\relax |
| 46833 |
\expandafter\XINT_cosd_A |
| 46834 |
\or\expandafter\XINT_cosd_B\the\numexpr-90+% |
| 46835 |
\or\expandafter\XINT_cosd_C\the\numexpr-180+% |
| 46836 |
\or\expandafter\XINT_cosd_D\the\numexpr-270+% |
| 46837 |
\else\expandafter\XINT_cosd_E\the\numexpr-360+% |
| 46838 |
\fi#1.% |
| 46839 |
}% |
| 46840 |
% \end{macrocode} |
| 46841 |
%\begin{lverb} |
| 46842 |
% #2 will be empty in the "integer" branch, but attention in general |
| 46843 |
% branch to handling of negative integer part after the subtraction of 90, |
| 46844 |
% 180, 270, or 360. |
| 46845 |
%\end{lverb} |
| 46846 |
% \begin{macrocode} |
| 46847 |
\def\XINT_tmpa#1.#2.{% |
| 46848 |
\def\XINT_cosd_A##1.##2.% |
| 46849 |
{% |
| 46850 |
\XINT_expr_unlock\expandafter\XINT_flexpr_userfunc_@cos_series\expandafter |
| 46851 |
{\romannumeral0\XINTinfloat[#1]{\xintMul{##1.##2}#2}}% |
| 46852 |
}% |
| 46853 |
\def\XINT_cosd_B_n-##1.##2.% |
| 46854 |
{% |
| 46855 |
\XINT_expr_unlock\expandafter\XINT_flexpr_userfunc_@sin_series\expandafter |
| 46856 |
{\romannumeral0\XINTinfloat[#1]{\xintMul{\xintSub{##1[0]}{.##2}}#2}}% |
| 46857 |
}% |
| 46858 |
\def\XINT_cosd_B_p##1.##2.% |
| 46859 |
{% |
| 46860 |
\xintiiopp\XINT_expr_unlock\expandafter\XINT_flexpr_userfunc_@sin_series\expandafter |
| 46861 |
{\romannumeral0\XINTinfloat[#1]{\xintMul{##1.##2}#2}}% |
| 46862 |
}% |
| 46863 |
\def\XINT_cosd_C_n-##1.##2.% |
| 46864 |
{% |
| 46865 |
\xintiiopp\XINT_expr_unlock\expandafter\XINT_flexpr_userfunc_@cos_series\expandafter |
| 46866 |
{\romannumeral0\XINTinfloat[#1]{\xintMul{\xintSub{##1[0]}{.##2}}#2}}% |
| 46867 |
}% |
| 46868 |
\def\XINT_cosd_C_p##1.##2.% |
| 46869 |
{% |
| 46870 |
\xintiiopp\XINT_expr_unlock\expandafter\XINT_flexpr_userfunc_@cos_series\expandafter |
| 46871 |
{\romannumeral0\XINTinfloat[#1]{\xintMul{##1.##2}#2}}% |
| 46872 |
}% |
| 46873 |
\def\XINT_cosd_D_n-##1.##2.% |
| 46874 |
{% |
| 46875 |
\xintiiopp\XINT_expr_unlock\expandafter\XINT_flexpr_userfunc_@sin_series\expandafter |
| 46876 |
{\romannumeral0\XINTinfloat[#1]{\xintMul{\xintSub{##1[0]}{.##2}}#2}}% |
| 46877 |
}% |
| 46878 |
\def\XINT_cosd_D_p##1.##2.% |
| 46879 |
{% |
| 46880 |
\XINT_expr_unlock\expandafter\XINT_flexpr_userfunc_@sin_series\expandafter |
| 46881 |
{\romannumeral0\XINTinfloat[#1]{\xintMul{##1.##2}#2}}% |
| 46882 |
}% |
| 46883 |
\def\XINT_cosd_E-##1.##2.% |
| 46884 |
{% |
| 46885 |
\XINT_expr_unlock\expandafter\XINT_flexpr_userfunc_@cos_series\expandafter |
| 46886 |
{\romannumeral0\XINTinfloat[#1]{\xintMul{\xintSub{##1[0]}{.##2}}#2}}% |
| 46887 |
}% |
| 46888 |
}\expandafter\XINT_tmpa |
| 46889 |
\the\numexpr\XINTdigitsormax+4\expandafter.% |
| 46890 |
\romannumeral`&&@\xintbarefloateval @oneDegree\relax.% |
| 46891 |
\def\XINT_cosd_B#1{\xint_UDsignfork#1\XINT_cosd_B_n-\XINT_cosd_B_p\krof #1}% |
| 46892 |
\def\XINT_cosd_C#1{\xint_UDsignfork#1\XINT_cosd_C_n-\XINT_cosd_C_p\krof #1}% |
| 46893 |
\def\XINT_cosd_D#1{\xint_UDsignfork#1\XINT_cosd_D_n-\XINT_cosd_D_p\krof #1}% |
| 46894 |
% \end{macrocode} |
| 46895 |
% \subsection{\cshn{@sind()}, \cshn{@cosd()}} |
| 46896 |
%\begin{lverb} |
| 46897 |
% The -45 is stored internally as -45/1[0] from the action of the unary minus |
| 46898 |
% operator, which float macros then parse faster. The 45e0 is to let it become |
| 46899 |
% 45[0] and not simply 45. |
| 46900 |
% |
| 46901 |
% Here and below the \ifnum\XINTdigits>8 45\else60\fi will all be resolved |
| 46902 |
% at time of definition. This is the charm and power of expandable parsers! |
| 46903 |
%\end{lverb} |
| 46904 |
% \begin{macrocode} |
| 46905 |
\xintdeffloatfunc @sind(x) := (x)?? |
| 46906 |
{(x>=-\ifnum\XINTdigits>8 45\else60\fi)? |
| 46907 |
{@sin_series(x*@oneDegree)} |
| 46908 |
{-@sind_rr(-x)} |
| 46909 |
} |
| 46910 |
{0e0} |
| 46911 |
{(x<=\ifnum\XINTdigits>8 45\else60\fi e0)? |
| 46912 |
{@sin_series(x*@oneDegree)} |
| 46913 |
{@sind_rr(x)} |
| 46914 |
} |
| 46915 |
;% |
| 46916 |
\xintdeffloatfunc @cosd(x) := (x)?? |
| 46917 |
{(x>=-\ifnum\XINTdigits>8 45\else60\fi)? |
| 46918 |
{@cos_series(x*@oneDegree)} |
| 46919 |
{@cosd_rr(-x)} |
| 46920 |
} |
| 46921 |
{1e0} |
| 46922 |
{(x<=\ifnum\XINTdigits>8 45\else60\fi e0)? |
| 46923 |
{@cos_series(x*@oneDegree)} |
| 46924 |
{@cosd_rr(x)} |
| 46925 |
} |
| 46926 |
;% |
| 46927 |
% \end{macrocode} |
| 46928 |
% \subsection{\cshn{@sin()}, \cshn{@cos()}} |
| 46929 |
%\begin{lverb} |
| 46930 |
% For some reason I did not define sin() and cos() in January 2019 ?? |
| 46931 |
% |
| 46932 |
% The sub \xintexpr x*@oneRadian\relax means that the multiplication will be |
| 46933 |
% done exactly @oneRadian having its 12 extra digits (and x its 4 extra |
| 46934 |
% digits), before being rounded in entrance of \xintSind, respectively |
| 46935 |
% \xintCosd, to P+12 mantissa. |
| 46936 |
% |
| 46937 |
% The strange 79e-2 could be 0.79 which would give 79[-2] internally too. |
| 46938 |
%\end{lverb} |
| 46939 |
% \begin{macrocode} |
| 46940 |
\xintdeffloatfunc @sin(x):= (abs(x)<\ifnum\XINTdigits>8 79e-2\else1e0\fi)? |
| 46941 |
{@sin_series(x)} |
| 46942 |
{(x)?? |
| 46943 |
{-@sind_rr(-\xintexpr x*@oneRadian\relax)} |
| 46944 |
{0} |
| 46945 |
{@sind_rr(\xintexpr x*@oneRadian\relax)} |
| 46946 |
} |
| 46947 |
;% |
| 46948 |
\xintdeffloatfunc @cos(x):= (abs(x)<\ifnum\XINTdigits>8 79e-2\else1e0\fi)? |
| 46949 |
{@cos_series(x)} |
| 46950 |
{@cosd_rr(abs(\xintexpr x*@oneRadian\relax))} |
| 46951 |
;% |
| 46952 |
% \end{macrocode} |
| 46953 |
% \subsection{\cshn{@sinc()}} |
| 46954 |
%\begin{lverb} |
| 46955 |
% Should I also consider adding (1-cos(x))/(x^2/2) ? it is sinc^2(x/2) but |
| 46956 |
% avoids a square. |
| 46957 |
%\end{lverb} |
| 46958 |
% \begin{macrocode} |
| 46959 |
\xintdeffloatfunc @sinc(x):= (abs(x)<\ifnum\XINTdigits>8 79e-2\else1e0\fi) ? |
| 46960 |
{@sin_aux(sqr(x))} |
| 46961 |
{@sind_rr(\xintexpr abs(x)*@oneRadian\relax)/abs(x)} |
| 46962 |
;% |
| 46963 |
% \end{macrocode} |
| 46964 |
% \subsection{\cshn{@tan()}, \cshn{@tand()}, \cshn{@cot()}, \cshn{@cotd()}} |
| 46965 |
%\begin{lverb} |
| 46966 |
% The 0 in cot(x) is a dummy place holder. We don't have a notion of |
| 46967 |
% Inf yet. |
| 46968 |
%\end{lverb} |
| 46969 |
% \begin{macrocode} |
| 46970 |
\xintdeffloatfunc @tand(x):= @sind(x)/@cosd(x);% |
| 46971 |
\xintdeffloatfunc @cotd(x):= @cosd(x)/@sind(x);% |
| 46972 |
\xintdeffloatfunc @tan(x) := (x)?? |
| 46973 |
{(x>-\ifnum\XINTdigits>8 79e-2\else1e0\fi)? |
| 46974 |
{@sin(x)/@cos(x)} |
| 46975 |
{-@cotd(\xintexpr9e1+x*@oneRadian\relax) |
| 46976 |
} |
| 46977 |
} |
| 46978 |
{0e0} |
| 46979 |
{(x<\ifnum\XINTdigits>8 79e-2\else1e0\fi)? |
| 46980 |
{@sin(x)/@cos(x)} |
| 46981 |
{@cotd(\xintexpr9e1-x*@oneRadian\relax)} |
| 46982 |
} |
| 46983 |
;% |
| 46984 |
\xintdeffloatfunc @cot(x) := (abs(x)<\ifnum\XINTdigits>8 79e-2\else1e0\fi)? |
| 46985 |
{@cos(x)/@sin(x)} |
| 46986 |
{(x)?? |
| 46987 |
{-@tand(\xintexpr9e1+x*@oneRadian\relax)} |
| 46988 |
{0} |
| 46989 |
{@tand(\xintexpr9e1-x*@oneRadian\relax)} |
| 46990 |
};% |
| 46991 |
% \end{macrocode} |
| 46992 |
% \subsection{\cshn{@sec()}, \cshn{@secd()}, \cshn{@csc()}, \cshn{@cscd()}} |
| 46993 |
% \begin{macrocode} |
| 46994 |
\xintdeffloatfunc @sec(x) := inv(@cos(x));% |
| 46995 |
\xintdeffloatfunc @csc(x) := inv(@sin(x));% |
| 46996 |
\xintdeffloatfunc @secd(x):= inv(@cosd(x));% |
| 46997 |
\xintdeffloatfunc @cscd(x):= inv(@sind(x));% |
| 46998 |
% \end{macrocode} |
| 46999 |
% \subsection{Core routine for inverse trigonometry} |
| 47000 |
% |
| 47001 |
%\begin{lverb} |
| 47002 |
% I always liked very much the general algorithm whose idea I found |
| 47003 |
% in 2019. But it costs a square root plus a sine plus a cosine all |
| 47004 |
% at target precision. For the arctangent the square root will be |
| 47005 |
% avoided by a trick. (memo: it is replaced by a division and I am not so sure |
| 47006 |
% now this is advantageous in fact) |
| 47007 |
% |
| 47008 |
% And now I like it even more as I have re-done the first step entirely |
| 47009 |
% in a single \numexpr... Thus the inverse trigonometry got a serious |
| 47010 |
% improvement at 1.4e... |
| 47011 |
% |
| 47012 |
% Here is the idea. We have 0<t<sqrt(2)/2 and we want a = Arcsin t. |
| 47013 |
% |
| 47014 |
% Imagine we have some very good approximation b = a - h. We know b, |
| 47015 |
% and don't know yet h. No problem h is a-b so sin(h)=sin(a)cos(b)- |
| 47016 |
% cos(a)sin(b). And we know everything here: sin(a) is t, cos(a) is |
| 47017 |
% u = sqrt(1-t^2), and we can compute cos(b) and sin(b). |
| 47018 |
% |
| 47019 |
% I said h was small so the computation of sin(a)cos(b)-cos(a)sin(b) will |
| 47020 |
% involve a lot of cancellation, no problem with xint, as it knows how to |
| 47021 |
% compute exactly... and if we wanted to go very low level we could do |
| 47022 |
% cos(a)sin(b) paying attention only on least significant digits. |
| 47023 |
% |
| 47024 |
% Ok, so we have sin(h), but h is small, so the series of Arcsine can be used |
| 47025 |
% with few terms! |
| 47026 |
% |
| 47027 |
% In fact h will be at most of the order of 1e-9, so it is no problem to |
| 47028 |
% simply replace sin(h) with h if the target precision is 16 ! |
| 47029 |
% |
| 47030 |
% Ok, so how do we obtain b, the good approximation to Arcsin t ? Simply by |
| 47031 |
% using its Taylor series, embedded in a single \numexpr working with nine |
| 47032 |
% digits numbers... I like this one! Notice that it reminisces with my |
| 47033 |
% questioning about how to best do Horner like for sine and cosine. Here in |
| 47034 |
% \numexpr we can only manipulate whole integers and simply can't do things |
| 47035 |
% such as ...)*x + 5/112)*x + 3/40)*x + 1/6)*x +1 .... But I found another |
| 47036 |
% way, see the code, which uses extensively the "scaling" operations in |
| 47037 |
% \numexpr. |
| 47038 |
% |
| 47039 |
% I have not proven rigorously that b-a is always less or equal in absolute |
| 47040 |
% value than 1e-9, but it is possible for example in Python to program it and |
| 47041 |
% go through all possible (less than) 1e9 inputs and check what happens. |
| 47042 |
% |
| 47043 |
% Very small inputs will give b=0 (first step is a fixed point rounding of t to |
| 47044 |
% nine fractional digits, so this rounding gives zero for input <0.5e-9, |
| 47045 |
% others will give b=t, because the arcsine numexpr will end up with |
| 47046 |
% 1000000000 (last time I checked that was for t a bit less than 5e-5, |
| 47047 |
% the latter gives 1000000001). |
| 47048 |
% All seems to work perfectly fine, in practice... |
| 47049 |
% |
| 47050 |
% |
| 47051 |
%\end{lverb} |
| 47052 |
% |
| 47053 |
%\begin{lverb} |
| 47054 |
% First we let the @sin_aux() and @cos_aux() functions be usable in exact |
| 47055 |
% \xintexpr context. |
| 47056 |
% |
| 47057 |
% The @asin_II() function will be used only for Digits>16. |
| 47058 |
%\end{lverb} |
| 47059 |
% \begin{macrocode} |
| 47060 |
\expandafter\let\csname XINT_expr_func_@sin_aux\expandafter\endcsname |
| 47061 |
\csname XINT_flexpr_func_@sin_aux\endcsname |
| 47062 |
\expandafter\let\csname XINT_expr_func_@cos_aux\expandafter\endcsname |
| 47063 |
\csname XINT_flexpr_func_@cos_aux\endcsname |
| 47064 |
\ifnum\XINTdigits>16 |
| 47065 |
\def\XINT_flexpr_func_@asin_II#1#2#3% |
| 47066 |
{% |
| 47067 |
\expandafter #1\expandafter #2\expandafter{% |
| 47068 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 47069 |
{\romannumeral`&&@\XINT_Arcsin_II_a#3}}% |
| 47070 |
}% |
| 47071 |
\def\XINT_tmpc#1.% |
| 47072 |
{% |
| 47073 |
\def\XINT_Arcsin_II_a##1% |
| 47074 |
{% |
| 47075 |
\expandafter\XINT_Arcsin_II_c_i\romannumeral0\XINTinfloatS[#1]{##1}% |
| 47076 |
}% |
| 47077 |
\def\XINT_Arcsin_II_c_i##1[##2]% |
| 47078 |
{% |
| 47079 |
\xintAdd{1/1[0]}{##1/6[##2]}% |
| 47080 |
}% |
| 47081 |
}% |
| 47082 |
\expandafter\XINT_tmpc\the\numexpr\XINTdigitsormax-14.% |
| 47083 |
\fi |
| 47084 |
\ifnum\XINTdigits>34 |
| 47085 |
\def\XINT_tmpc#1.#2.#3.#4.% |
| 47086 |
{% |
| 47087 |
\def\XINT_Arcsin_II_a##1% |
| 47088 |
{% |
| 47089 |
\expandafter\XINT_Arcsin_II_a_iii\romannumeral0\XINTinfloatS[#1]{##1}\xint: |
| 47090 |
}% |
| 47091 |
\def\XINT_Arcsin_II_a_iii##1\xint: |
| 47092 |
{% |
| 47093 |
\expandafter\XINT_Arcsin_II_b\romannumeral0\XINTinfloatS[#2]{##1}\xint:##1\xint: |
| 47094 |
}% |
| 47095 |
\def\XINT_Arcsin_II_b##1\xint: |
| 47096 |
{% |
| 47097 |
\expandafter\XINT_Arcsin_II_c_i |
| 47098 |
\romannumeral0\xintadd{#4}{\XINTinFloat[#2]{\xintMul{#3}{##1}}}\xint: |
| 47099 |
}% |
| 47100 |
\def\XINT_Arcsin_II_c_i##1\xint:##2\xint: |
| 47101 |
{% |
| 47102 |
\xintAdd{1/1[0]}{\XINTinFloat[#1]{\xintMul{##1}{##2}}}% |
| 47103 |
}% |
| 47104 |
}% |
| 47105 |
\expandafter\XINT_tmpc |
| 47106 |
\the\numexpr\XINTdigitsormax-14\expandafter.% |
| 47107 |
\the\numexpr\XINTdigitsormax-32\expandafter.\expanded{% |
| 47108 |
\XINTinFloat[\XINTdigitsormax-32]{3/40[0]}.% |
| 47109 |
\XINTinFloat[\XINTdigitsormax-14]{1/6[0]}.% |
| 47110 |
}% |
| 47111 |
\fi |
| 47112 |
\ifnum\XINTdigits>52 |
| 47113 |
\def\XINT_tmpc#1.#2.#3.#4.#5.% |
| 47114 |
{% |
| 47115 |
\def\XINT_Arcsin_II_a_iii##1\xint: |
| 47116 |
{% |
| 47117 |
\expandafter\XINT_Arcsin_II_a_iv\romannumeral0\XINTinfloatS[#1]{##1}\xint:##1\xint: |
| 47118 |
}% |
| 47119 |
\def\XINT_Arcsin_II_a_iv##1\xint: |
| 47120 |
{% |
| 47121 |
\expandafter\XINT_Arcsin_II_b\romannumeral0\XINTinfloatS[#2]{##1}\xint:##1\xint: |
| 47122 |
}% |
| 47123 |
\def\XINT_Arcsin_II_b##1\xint: |
| 47124 |
{% |
| 47125 |
\expandafter\XINT_Arcsin_II_c_ii |
| 47126 |
\romannumeral0\xintadd{#4}{\XINTinfloat[#2]{\xintMul{#3}{##1}}}\xint: |
| 47127 |
}% |
| 47128 |
\def\XINT_Arcsin_II_c_ii##1\xint:##2\xint: |
| 47129 |
{% |
| 47130 |
\expandafter\XINT_Arcsin_II_c_i |
| 47131 |
\romannumeral0\xintadd{#5}{\XINTinFloat[#1]{\xintMul{##1}{##2}}}\xint: |
| 47132 |
}% |
| 47133 |
}% |
| 47134 |
\expandafter\XINT_tmpc |
| 47135 |
\the\numexpr\XINTdigitsormax-32\expandafter.% |
| 47136 |
\the\numexpr\XINTdigitsormax-50\expandafter.\expanded{% |
| 47137 |
\XINTinFloat[\XINTdigitsormax-50]{5/112[0]}.% |
| 47138 |
\XINTinFloat[\XINTdigitsormax-32]{3/40[0]}.% |
| 47139 |
\XINTinFloat[\XINTdigitsormax-14]{1/6[0]}.% |
| 47140 |
}% |
| 47141 |
\fi |
| 47142 |
\def\XINT_flexpr_func_@asin_I#1#2#3% |
| 47143 |
{% |
| 47144 |
\expandafter #1\expandafter #2\expandafter{% |
| 47145 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 47146 |
{\romannumeral`&&@\XINT_Arcsin_I#3}}% |
| 47147 |
}% |
| 47148 |
\def\XINT_Arcsin_I#1% |
| 47149 |
{% |
| 47150 |
\the\numexpr\expandafter\XINT_Arcsin_Ia\romannumeral0\xintiround9{#1}.% |
| 47151 |
}% |
| 47152 |
\def\XINT_Arcsin_Ia#1.% |
| 47153 |
{% |
| 47154 |
(\expandafter\XINT_Arcsin_Ib\the\numexpr#1*#1/\xint_c_x^ix.)*% |
| 47155 |
#1/\xint_c_x^ix[-9]% |
| 47156 |
}% |
| 47157 |
\def\XINT_Arcsin_Ib#1.% |
| 47158 |
{%(((((((((((((((( |
| 47159 |
% 3481/3660)*#1/\xint_c_x^ix+\xint_c_x^ix)*% |
| 47160 |
% 3249/3422)*#1/\xint_c_x^ix+\xint_c_x^ix)*% |
| 47161 |
% 3025/3192)*#1/\xint_c_x^ix+\xint_c_x^ix)*% |
| 47162 |
% 2809/2970)*#1/\xint_c_x^ix+\xint_c_x^ix)*% |
| 47163 |
% 2601/2756)*#1/\xint_c_x^ix+\xint_c_x^ix)*% |
| 47164 |
% 2401/2550)*#1/\xint_c_x^ix+\xint_c_x^ix)*% |
| 47165 |
% 2209/2352)*#1/\xint_c_x^ix+\xint_c_x^ix)*% |
| 47166 |
% 2025/2162)*#1/\xint_c_x^ix+\xint_c_x^ix)*% |
| 47167 |
((((((((((((((((((((((((((((((((((((((((((% |
| 47168 |
%(\xint_c_x^ix*1849/1980)*% |
| 47169 |
933838384*#1/\xint_c_x^ix+\xint_c_x^ix)*% |
| 47170 |
1681/1806)*#1/\xint_c_x^ix+\xint_c_x^ix)*% |
| 47171 |
1521/1640)*#1/\xint_c_x^ix+\xint_c_x^ix)*% |
| 47172 |
1369/1482)*#1/\xint_c_x^ix+\xint_c_x^ix)*% |
| 47173 |
1225/1332)*#1/\xint_c_x^ix+\xint_c_x^ix)*% |
| 47174 |
1089/1190)*#1/\xint_c_x^ix+\xint_c_x^ix)*% |
| 47175 |
961/1056)*#1/\xint_c_x^ix+\xint_c_x^ix)*% |
| 47176 |
841/930)*#1/\xint_c_x^ix+\xint_c_x^ix)*% |
| 47177 |
729/812)*#1/\xint_c_x^ix+\xint_c_x^ix)*% |
| 47178 |
625/702)*#1/\xint_c_x^ix+\xint_c_x^ix)*% |
| 47179 |
529/600)*#1/\xint_c_x^ix+\xint_c_x^ix)*% |
| 47180 |
441/506)*#1/\xint_c_x^ix+\xint_c_x^ix)*% |
| 47181 |
361/420)*#1/\xint_c_x^ix+\xint_c_x^ix)*% |
| 47182 |
289/342)*#1/\xint_c_x^ix+\xint_c_x^ix)*% |
| 47183 |
225/272)*#1/\xint_c_x^ix+\xint_c_x^ix)*% |
| 47184 |
169/210)*#1/\xint_c_x^ix+\xint_c_x^ix)*% |
| 47185 |
121/156)*#1/\xint_c_x^ix+\xint_c_x^ix)*% |
| 47186 |
81/110)*#1/\xint_c_x^ix+\xint_c_x^ix)*% |
| 47187 |
49/72)*#1/\xint_c_x^ix+\xint_c_x^ix)*% |
| 47188 |
25/42)*#1/\xint_c_x^ix+\xint_c_x^ix)*% |
| 47189 |
9/20)*#1/\xint_c_x^ix+\xint_c_x^ix)*% |
| 47190 |
1/6)*#1/\xint_c_x^ix+\xint_c_x^ix |
| 47191 |
}% |
| 47192 |
\ifnum\XINTdigits>16 |
| 47193 |
\xintdeffloatfunc @asin_o(D, T) := T + D*@asin_II(sqr(D));% |
| 47194 |
\xintdeffloatfunc @asin_n(V, T, t, u) :=% |
| 47195 |
@asin_o(\xintexpr t*@cos_aux(V) - u*T*@sin_aux(V)\relax, T);% |
| 47196 |
\else |
| 47197 |
\xintdeffloatfunc @asin_n(V, T, t, u) :=% |
| 47198 |
\xintexpr t*@cos_aux(V) - u*T*@sin_aux(V)\relax + T;% |
| 47199 |
\fi |
| 47200 |
\xintdeffloatfunc @asin_m(T, t, u) := @asin_n(sqr(T), T, t, u);% |
| 47201 |
\xintdeffloatfunc @asin_l(t, u) := @asin_m(@asin_I(t), t, u);% |
| 47202 |
% \end{macrocode} |
| 47203 |
% \subsection{\cshn{@asin()}, \cshn{@asind()}} |
| 47204 |
%\begin{lverb} |
| 47205 |
% Only non-negative arguments t and u for asin_a(t,u), and asind_a(t,u). |
| 47206 |
%\end{lverb} |
| 47207 |
% \begin{macrocode} |
| 47208 |
\xintdeffloatfunc @asin_a(t, u) := (t<u)? |
| 47209 |
{@asin_l(t, u)} |
| 47210 |
{@Piover2 - @asin_l(u, t)} |
| 47211 |
;% |
| 47212 |
\xintdeffloatfunc @asind_a(t, u):= (t<u)? |
| 47213 |
{@asin_l(t, u) * @oneRadian} |
| 47214 |
{9e1 - @asin_l(u, t) * @oneRadian} |
| 47215 |
;% |
| 47216 |
\xintdeffloatfunc @asin(t) := (t)?? |
| 47217 |
{-@asin_a(-t, sqrt(1e0-sqr(t)))} |
| 47218 |
{0e0} |
| 47219 |
{@asin_a(t, sqrt(1e0-sqr(t)))} |
| 47220 |
;% |
| 47221 |
\xintdeffloatfunc @asind(t) := (t)?? |
| 47222 |
{-@asind_a(-t, sqrt(1e0-sqr(t)))} |
| 47223 |
{0e0} |
| 47224 |
{@asind_a(t, sqrt(1e0-sqr(t)))} |
| 47225 |
;% |
| 47226 |
% \end{macrocode} |
| 47227 |
% \subsection{\cshn{@acos()}, \cshn{@acosd()}} |
| 47228 |
% \begin{macrocode} |
| 47229 |
\xintdeffloatfunc @acos(t) := @Piover2 - @asin(t);% |
| 47230 |
\xintdeffloatfunc @acosd(t):= 9e1 - @asind(t);% |
| 47231 |
% \end{macrocode} |
| 47232 |
% \subsection{\cshn{@atan()}, \cshn{@atand()}} |
| 47233 |
%\begin{lverb} |
| 47234 |
% Uses same core routine asin_l() as for asin(), but avoiding a square-root |
| 47235 |
% extraction in preparing its arguments (to the cost of computing an inverse, |
| 47236 |
% rather). |
| 47237 |
%\end{lverb} |
| 47238 |
%\begin{lverb} |
| 47239 |
% radians |
| 47240 |
%\end{lverb} |
| 47241 |
% \begin{macrocode} |
| 47242 |
\xintdeffloatfunc @atan_b(t, w, z):= 5e-1 * (w< 0)? |
| 47243 |
{@Pi - @asin_a(2e0*z * t, -w*z)} |
| 47244 |
{@asin_a(2e0*z * t, w*z)} |
| 47245 |
;% |
| 47246 |
\xintdeffloatfunc @atan_a(t, T) := @atan_b(t, 1e0-T, inv(1e0+T));% |
| 47247 |
\xintdeffloatfunc @atan(t):= (t)?? |
| 47248 |
{-@atan_a(-t, sqr(t))} |
| 47249 |
{0} |
| 47250 |
{@atan_a(t, sqr(t))} |
| 47251 |
;% |
| 47252 |
% \end{macrocode} |
| 47253 |
%\begin{lverb} |
| 47254 |
% degrees |
| 47255 |
%\end{lverb} |
| 47256 |
% \begin{macrocode} |
| 47257 |
\xintdeffloatfunc @atand_b(t, w, z) := 5e-1 * (w< 0)? |
| 47258 |
{18e1 - @asind_a(2e0*z * t, -w*z)} |
| 47259 |
{@asind_a(2e0*z * t, w*z)} |
| 47260 |
;% |
| 47261 |
\xintdeffloatfunc @atand_a(t, T) := @atand_b(t, 1e0-T, inv(1e0+T));% |
| 47262 |
\xintdeffloatfunc @atand(t) := (t)?? |
| 47263 |
{-@atand_a(-t, sqr(t))} |
| 47264 |
{0} |
| 47265 |
{@atand_a(t, sqr(t))} |
| 47266 |
;% |
| 47267 |
% \end{macrocode} |
| 47268 |
% \subsection{\cshn{@Arg()}, \cshn{@atan2()}, \cshn{@Argd()}, \cshn{@atan2d()}, \cshn{@pArg()}, \cshn{@pArgd()}} |
| 47269 |
%\begin{lverb} |
| 47270 |
% Arg(x,y) function from -π (excluded) to +π (included) |
| 47271 |
%\end{lverb} |
| 47272 |
% \begin{macrocode} |
| 47273 |
\xintdeffloatfunc @Arg(x, y):= (y>x)? |
| 47274 |
{(y>-x)? |
| 47275 |
{@Piover2 - @atan(x/y)} |
| 47276 |
{(y<0)? |
| 47277 |
{-@Pi + @atan(y/x)} |
| 47278 |
{@Pi + @atan(y/x)} |
| 47279 |
} |
| 47280 |
} |
| 47281 |
{(y>-x)? |
| 47282 |
{@atan(y/x)} |
| 47283 |
{-@Piover2 + @atan(x/-y)} |
| 47284 |
} |
| 47285 |
;% |
| 47286 |
% \end{macrocode} |
| 47287 |
%\begin{lverb} |
| 47288 |
% atan2(y,x) = Arg(x,y) ... (some people have atan2 with arguments reversed |
| 47289 |
% but the convention here seems the most often encountered) |
| 47290 |
%\end{lverb} |
| 47291 |
% \begin{macrocode} |
| 47292 |
\xintdeffloatfunc @atan2(y,x) := @Arg(x, y);% |
| 47293 |
% \end{macrocode} |
| 47294 |
%\begin{lverb} |
| 47295 |
% Argd(x,y) function from -180 (excluded) to +180 (included) |
| 47296 |
%\end{lverb} |
| 47297 |
% \begin{macrocode} |
| 47298 |
\xintdeffloatfunc @Argd(x, y):= (y>x)? |
| 47299 |
{(y>-x)? |
| 47300 |
{9e1 - @atand(x/y)} |
| 47301 |
{(y<0)? |
| 47302 |
{-18e1 + @atand(y/x)} |
| 47303 |
{18e1 + @atand(y/x)} |
| 47304 |
} |
| 47305 |
} |
| 47306 |
{(y>-x)? |
| 47307 |
{@atand(y/x)} |
| 47308 |
{-9e1 + @atand(x/-y)} |
| 47309 |
} |
| 47310 |
;% |
| 47311 |
% \end{macrocode} |
| 47312 |
%\begin{lverb} |
| 47313 |
% atan2d(y,x) = Argd(x,y) |
| 47314 |
%\end{lverb} |
| 47315 |
% \begin{macrocode} |
| 47316 |
\xintdeffloatfunc @atan2d(y,x) := @Argd(x, y);% |
| 47317 |
% \end{macrocode} |
| 47318 |
%\begin{lverb} |
| 47319 |
% pArg(x,y) function from 0 (included) to 2π (excluded) |
| 47320 |
% I hesitated between pArg, Argpos, and Argplus. Opting for pArg in the end. |
| 47321 |
%\end{lverb} |
| 47322 |
% \begin{macrocode} |
| 47323 |
\xintdeffloatfunc @pArg(x, y):= (y>x)? |
| 47324 |
{(y>-x)? |
| 47325 |
{@Piover2 - @atan(x/y)} |
| 47326 |
{@Pi + @atan(y/x)} |
| 47327 |
} |
| 47328 |
{(y>-x)? |
| 47329 |
{(y<0)? |
| 47330 |
{@twoPi + @atan(y/x)} |
| 47331 |
{@atan(y/x)} |
| 47332 |
} |
| 47333 |
{@threePiover2 + @atan(x/-y)} |
| 47334 |
} |
| 47335 |
;% |
| 47336 |
% \end{macrocode} |
| 47337 |
%\begin{lverb} |
| 47338 |
% pArgd(x,y) function from 0 (included) to 360 (excluded) |
| 47339 |
%\end{lverb} |
| 47340 |
% \begin{macrocode} |
| 47341 |
\xintdeffloatfunc @pArgd(x, y):=(y>x)? |
| 47342 |
{(y>-x)? |
| 47343 |
{9e1 - @atan(x/y)*@oneRadian} |
| 47344 |
{18e1 + @atan(y/x)*@oneRadian} |
| 47345 |
} |
| 47346 |
{(y>-x)? |
| 47347 |
{(y<0e0)? |
| 47348 |
{36e1 + @atan(y/x)*@oneRadian} |
| 47349 |
{@atan(y/x)*@oneRadian} |
| 47350 |
} |
| 47351 |
{27e1 + @atan(x/-y)*@oneRadian} |
| 47352 |
} |
| 47353 |
;% |
| 47354 |
% \end{macrocode} |
| 47355 |
% \subsection{Restore \cs{xintdeffloatfunc} to its normal state, with no extra digits} |
| 47356 |
% \begin{macrocode} |
| 47357 |
\expandafter\let |
| 47358 |
\csname XINT_flexpr_exec_+\expandafter\endcsname |
| 47359 |
\csname XINT_flexpr_exec_+_\endcsname |
| 47360 |
\expandafter\let |
| 47361 |
\csname XINT_flexpr_exec_-\expandafter\endcsname |
| 47362 |
\csname XINT_flexpr_exec_-_\endcsname |
| 47363 |
\expandafter\let |
| 47364 |
\csname XINT_flexpr_exec_*\expandafter\endcsname |
| 47365 |
\csname XINT_flexpr_exec_*_\endcsname |
| 47366 |
\expandafter\let |
| 47367 |
\csname XINT_flexpr_exec_/\expandafter\endcsname |
| 47368 |
\csname XINT_flexpr_exec_/_\endcsname |
| 47369 |
\expandafter\let |
| 47370 |
\csname XINT_flexpr_func_sqr\expandafter\endcsname |
| 47371 |
\csname XINT_flexpr_sqrfunc\endcsname |
| 47372 |
\expandafter\let |
| 47373 |
\csname XINT_flexpr_func_sqrt\expandafter\endcsname |
| 47374 |
\csname XINT_flexpr_sqrtfunc\endcsname |
| 47375 |
\expandafter\let |
| 47376 |
\csname XINT_flexpr_func_inv\expandafter\endcsname |
| 47377 |
\csname XINT_flexpr_invfunc\endcsname |
| 47378 |
% \end{macrocode} |
| 47379 |
% \subsection{Let the functions be known to the \cshnolabel{xintexpr} parser} |
| 47380 |
%\begin{lverb} |
| 47381 |
% We use here float_dgtormax which uses the smaller of Digits and 64. |
| 47382 |
%\end{lverb} |
| 47383 |
% \begin{macrocode} |
| 47384 |
\edef\XINTinFloatdigitsormax{\noexpand\XINTinFloat[\the\numexpr\XINTdigitsormax]}% |
| 47385 |
\edef\XINTinFloatSdigitsormax{\noexpand\XINTinFloatS[\the\numexpr\XINTdigitsormax]}% |
| 47386 |
\xintFor #1 in {sin, cos, tan, sec, csc, cot, |
| 47387 |
asin, acos, atan}\do |
| 47388 |
{% |
| 47389 |
\xintdeffloatfunc #1(x) := float_dgtormax(@#1(x));% |
| 47390 |
\xintdeffloatfunc #1d(x) := float_dgtormax(@#1d(x));% |
| 47391 |
\xintdeffunc #1(x) := float_dgtormax(\xintfloatexpr @#1(sfloat_dgtormax(x))\relax);% |
| 47392 |
\xintdeffunc #1d(x):= float_dgtormax(\xintfloatexpr @#1d(sfloat_dgtormax(x))\relax);% |
| 47393 |
}% |
| 47394 |
\xintFor #1 in {Arg, pArg, atan2}\do |
| 47395 |
{% |
| 47396 |
\xintdeffloatfunc #1(x, y) := float_dgtormax(@#1(x, y));% |
| 47397 |
\xintdeffloatfunc #1d(x, y) := float_dgtormax(@#1d(x, y));% |
| 47398 |
\xintdeffunc #1(x, y) := |
| 47399 |
float_dgtormax(\xintfloatexpr @#1(sfloat_dgtormax(x), sfloat_dgtormax(y))\relax);% |
| 47400 |
\xintdeffunc #1d(x, y):= |
| 47401 |
float_dgtormax(\xintfloatexpr @#1d(sfloat_dgtormax(x), sfloat_dgtormax(y))\relax);% |
| 47402 |
}% |
| 47403 |
\xintdeffloatfunc sinc(x):= float_dgtormax(@sinc(x));% |
| 47404 |
\xintdeffunc sinc(x):= float_dgtormax(\xintfloatexpr @sinc(sfloat_dgtormax(x))\relax);% |
| 47405 |
% \end{macrocode} |
| 47406 |
% \subsection{Synonyms: \cshn{@tg()}, \cshn{@cotg()}} |
| 47407 |
%\begin{lverb} |
| 47408 |
% These are my childhood notations and I am attached to them. In |
| 47409 |
% radians only, and for \xintfloateval only. We skip some overhead here by using a \let at core level. |
| 47410 |
%\end{lverb} |
| 47411 |
% \begin{macrocode} |
| 47412 |
\expandafter\let\csname XINT_flexpr_func_tg\expandafter\endcsname |
| 47413 |
\csname XINT_flexpr_func_tan\endcsname |
| 47414 |
\expandafter\let\csname XINT_flexpr_func_cotg\expandafter\endcsname |
| 47415 |
\csname XINT_flexpr_func_cot\endcsname |
| 47416 |
% \end{macrocode} |
| 47417 |
% \subsection{Final clean-up} |
| 47418 |
%\begin{lverb} |
| 47419 |
% Restore used dummy variables to their status prior to the package reloading. |
| 47420 |
% On first loading this is not needed, but I have not added a way to check |
| 47421 |
% here whether this a first loading or a re-loading. |
| 47422 |
%\end{lverb} |
| 47423 |
% \begin{macrocode} |
| 47424 |
\xintdefvar twoPi := float_dgtormax(@twoPi);% |
| 47425 |
\xintdefvar threePiover2 := float_dgtormax(@threePiover2);% |
| 47426 |
\xintdefvar Pi := float_dgtormax(@Pi);% |
| 47427 |
\xintdefvar Piover2 := float_dgtormax(@Piover2);% |
| 47428 |
\xintdefvar oneDegree := float_dgtormax(@oneDegree);% |
| 47429 |
\xintdefvar oneRadian := float_dgtormax(@oneRadian);% |
| 47430 |
\xintunassignvar{@twoPi}\xintunassignvar{@threePiover2}% |
| 47431 |
\xintunassignvar{@Pi}\xintunassignvar{@Piover2}% |
| 47432 |
\xintunassignvar{@oneRadian}\xintunassignvar{@oneDegree}% |
| 47433 |
\xintFor* #1 in {iDTVtuwxyzX}\do{\xintrestorevariable{#1}}% |
| 47434 |
\XINTtrigendinput% |
| 47435 |
% \end{macrocode} |
| 47436 |
% \StoreCodelineNo {xinttrig} |
| 47437 |
% \cleardoublepage\let\xinttrignameUp\undefined |
| 47438 |
%\gardesactifs |
| 47439 |
%\let</xinttrig>\relax |
| 47440 |
%\let<*xintlog>\gardesinactifs |
| 47441 |
%</xinttrig>^^A-------------------------------------------------- |
| 47442 |
%<*xintlog>^^A--------------------------------------------------- |
| 47443 |
%^^A -*- coding: utf-8; mode: doctex; fill-column: 78; sentence-end-double-space: t; eval: (auto-fill-mode -1); fill-paragraph-function: nil; -*- |
| 47444 |
% \clearpage\csname xintlognameUp\endcsname |
| 47445 |
% \let\MakePrivateLetters\xintMakePrivateLetters |
| 47446 |
% \section{Package \xintlognameimp implementation} |
| 47447 |
% \RaisedLabel{sec:logimp} |
| 47448 |
% \etocarticlestylenomarks |
| 47449 |
% \etocsetnexttocdepth {subsubsection} |
| 47450 |
% |
| 47451 |
% \localtableofcontents |
| 47452 |
% |
| 47453 |
% \etocsettocstyle{}{} |
| 47454 |
% |
| 47455 |
% In 2019, at 1.3e release I almost included extended precision for log() and |
| 47456 |
% exp() but the time I could devote to xint expired. Finally, at long last, |
| 47457 |
% (and I had procrastinated far more than the two years since 2019) the 1.4e |
| 47458 |
% release in April 2021 brings log10(), pow10(), log(), pow() to P=Digits |
| 47459 |
% precision: up to 62 digits with at least (said roughly) 99\% chances of |
| 47460 |
% correct rounding (the design is targeting less than about 0.005ulp distance |
| 47461 |
% to mathematical value, before rounding). |
| 47462 |
% |
| 47463 |
% Implementation is EXPERIMENTAL. |
| 47464 |
% |
| 47465 |
% For up to Digits=8, it is simply based upon the poormanlog package. The |
| 47466 |
% probability of correct rounding will be less than for Digits>8, especially |
| 47467 |
% in the cases of Digits=8 and to a lesser extent Digits=7. And, for all |
| 47468 |
% Digits<=8, there is a systematic loss of rounding precision in the floating |
| 47469 |
% point sense in the case of log10(x) for inputs close to 1: |
| 47470 |
% |
| 47471 |
%\begin{lverb} |
| 47472 |
% |
| 47473 |
% Summary of limitations of log10() and pow10() in the case of Digits<=8: |
| 47474 |
%( - For log10(x) with x near 1, the precision of output as floating point& |
| 47475 |
% will be mechanically reduced from the fact that this is based on a fixed& |
| 47476 |
% point result, for example log10(1.0011871) is produced as 5.15245e-4,& |
| 47477 |
% which stands for 0.000515145 having indeed 9 correct fractional digits,& |
| 47478 |
% but only 6 correct digits in the floating point sense.& |
| 47479 |
% |
| 47480 |
% This feature affects the entire range Digits<=8. |
| 47481 |
%: - Even if limiting to inputs x with 1.26<x<10 (1.26 is a bit more than& |
| 47482 |
% 10^0.1 hence its choice as lower bound), the poormanlog documentation& |
| 47483 |
% mentions an absolute error possibly up to about 1e-9. In practice a& |
| 47484 |
% test of 10000 random inputs 1.26<x<10 revealed 9490 correctly rounded& |
| 47485 |
% log10(x) at 8 digits (and the 510 non-correctly rounded ones with an error& |
| 47486 |
% of 1 in last digit compared to correct rounding). So correct rounding& |
| 47487 |
% achieved only in about 95$% of cases here.& |
| 47488 |
% |
| 47489 |
% At 7 digits the same 10000 random& |
| 47490 |
% inputs are correctly rounded in 99.4$% of cases, and at 6 digits it is& |
| 47491 |
% 99.94$% of cases.& |
| 47492 |
% |
| 47493 |
% Again with Digits=8, the log10(i) for i in 1..1000 are all correctly& |
| 47494 |
% rounded to 8 digits with two exceptions: log10(3) and log10(297) with a& |
| 47495 |
% 1ulp error. And the log(i) in the same range are correctly rounded to 8& |
| 47496 |
% digits with the 15 exceptions i= 99, 105, 130, 178, 224, 329, 446, 464,& |
| 47497 |
% 564, 751, 772, 777, 886, 907, 962, whose natural logarithms& |
| 47498 |
% are obtained with a 1ulp error. |
| 47499 |
%: - Regarding the computation of 10^x, I obtained for -1<x<1 the following& |
| 47500 |
% with 10000 random inputs: 518/10000 errors at 1ulp, 60/10000, and 8/10000,& |
| 47501 |
% at respectively Digits = 8, 7, 6 so chances of correct rounding are& |
| 47502 |
% respectively about 95$%, 99.4$% and more than 99.9$%. |
| 47503 |
%) |
| 47504 |
%\end{lverb} |
| 47505 |
% |
| 47506 |
% Despite its limitations the poormanlog based approach used for Digits up to |
| 47507 |
% 8 has the advantage of speed (at least 8X compared to working with 16 |
| 47508 |
% digits) and is largely precise enough for plots. |
| 47509 |
% |
| 47510 |
% For 9 digits or more, the observed precision in some random tests appears to |
| 47511 |
% be at least of 99.9\% chances of correct rounding, and the log10(x) with x |
| 47512 |
% near 1 are correctly (if not really efficiently) handled in the floating |
| 47513 |
% point sense for the output. The poormanlog approximate log10() is still used |
| 47514 |
% to boot-strap the process, generally. The pow10() at Digits=9 or more is |
| 47515 |
% done independently of poormanlog. |
| 47516 |
% |
| 47517 |
% All of this is done on top of my 2013 structures for floating point |
| 47518 |
% computations which have always been marked as provisory and rudimentary and |
| 47519 |
% instills intrinsic non-efficiency: |
| 47520 |
% |
| 47521 |
%\begin{lverb} |
| 47522 |
%( - no internal data format for a ``floating point number at P digits'', |
| 47523 |
%: - mantissa lengths are again and again computed, |
| 47524 |
%: - digits are not pre-organized say in blocks of 4 by 4 or 8 by 8, |
| 47525 |
%: - floating point multiplication is done via an *exact* multiplication, then& |
| 47526 |
% rounding to P digits! |
| 47527 |
%) |
| 47528 |
%\end{lverb} |
| 47529 |
% |
| 47530 |
% This is legacy of the fact that the project was initially devoted to big |
| 47531 |
% integers only, but in the weeks that followed its inception in March 2013 I |
| 47532 |
% added more and more functionalities without a well laid out preliminary |
| 47533 |
% plan. |
| 47534 |
% |
| 47535 |
% Anyway, for years I have felt a better foundation would help achieve at |
| 47536 |
% least something such as 2X gain (perhaps the last item by itself, if |
| 47537 |
% improved upon, would bring most of such 2X gain?) |
| 47538 |
% |
| 47539 |
% I did not try to optimize for the default 16 digits, the goal being more of |
| 47540 |
% having a general scalable structure in place and there is no difficulty to |
| 47541 |
% go up to 100 digits precision if one stores extended pre-computed constants |
| 47542 |
% and increases the length of the ``series'' support. |
| 47543 |
% |
| 47544 |
% Apart from log(10) and its inverse, no other logarithms are stored or |
| 47545 |
% pre-computed: the rest of the stored data is the same for pow10() and |
| 47546 |
% log10() and consists of the fractional powers 10\string^±0.i, |
| 47547 |
% 10\string^±0.0i, ..., 10\string^±0.00000i at P+5 and also at P+10 digits. |
| 47548 |
% |
| 47549 |
% In order to reduce the loading time of the package the inverses are not |
| 47550 |
% computed internally (as this would require costly divisions) but simply |
| 47551 |
% hard-coded with enough digits to cover the allowed Digits range. |
| 47552 |
% |
| 47553 |
% |
| 47554 |
% \subsection{Catcodes, \protect\eTeX{} and reload detection} |
| 47555 |
% \changed{1.4l} |
| 47556 |
%\begin{lverb} |
| 47557 |
% Silly paranoid modification of \z in case { and } do not have their |
| 47558 |
% normal catcodes when xintlog.sty is reloaded (initial loading via |
| 47559 |
% xintexpr.sty does not need this), to define \XINTlogendinput there and not |
| 47560 |
% after the \endgroup from \z has already restored possibly bad catcodes. |
| 47561 |
% |
| 47562 |
% |
| 47563 |
% 1.4l handles much better the situation with \usepackage{xintlog} without |
| 47564 |
% previous loading of xintexpr (or same with \input and etex). Instead of |
| 47565 |
% aborting with a message (which actually was wrong with LaTeX since 1.4e, |
| 47566 |
% mentioning \input in place of \usepackage), it will initiate loading |
| 47567 |
% xintexpr itself. This required an adaptation at end of xintexpr and some |
| 47568 |
% care to not leave bad catcodes. |
| 47569 |
% |
| 47570 |
%\end{lverb} |
| 47571 |
% \begin{macrocode} |
| 47572 |
\begingroup\catcode61\catcode48\catcode32=10\relax% |
| 47573 |
\catcode13=5 % ^^M |
| 47574 |
\endlinechar=13 % |
| 47575 |
\catcode123=1 % { |
| 47576 |
\catcode125=2 % } |
| 47577 |
\catcode64=11 % @ |
| 47578 |
\catcode35=6 % # |
| 47579 |
\catcode44=12 % , |
| 47580 |
\catcode46=12 % . |
| 47581 |
\catcode58=12 % : |
| 47582 |
\catcode94=7 % ^ |
| 47583 |
\def\empty{}\def\space{ }\newlinechar10 |
| 47584 |
\def\z{\endgroup}% |
| 47585 |
\expandafter\let\expandafter\x\csname [email protected]\endcsname |
| 47586 |
\expandafter\let\expandafter\w\csname [email protected]\endcsname |
| 47587 |
\expandafter |
| 47588 |
\ifx\csname PackageWarningNoLine\endcsname\relax |
| 47589 |
\def\y#1#2{\immediate\write128{^^JPackage #1 Warning:^^J% |
| 47590 |
\space\space\space\space#2.^^J}}% |
| 47591 |
\else |
| 47592 |
\def\y#1#2{\PackageWarningNoLine{#1}{#2}}% |
| 47593 |
\fi |
| 47594 |
\expandafter |
| 47595 |
\ifx\csname numexpr\endcsname\relax |
| 47596 |
\y{xintlog}{\numexpr not available, aborting input}% |
| 47597 |
\def\z{\endgroup\endinput}% |
| 47598 |
\else |
| 47599 |
\ifx\w\relax % xintexpr.sty not yet loaded. |
| 47600 |
\edef\MsgBrk{^^J\space\space\space\space}% |
| 47601 |
\y{xintlog}% |
| 47602 |
{\ifx\x\empty |
| 47603 |
xintlog should not be loaded directly\MessageBreak |
| 47604 |
The correct way is \string\usepackage{xintexpr}.\MessageBreak |
| 47605 |
Will try that now% |
| 47606 |
\else |
| 47607 |
First loading of xintlog.sty should be via |
| 47608 |
\string\input\space xintexpr.sty\relax\MsgBrk |
| 47609 |
Will try that now% |
| 47610 |
\fi |
| 47611 |
}% |
| 47612 |
\ifx\x\empty |
| 47613 |
\def\z{\endgroup\RequirePackage{xintexpr}\endinput}% |
| 47614 |
\else |
| 47615 |
\def\z{\endgroup\input xintexpr.sty\relax\endinput}% |
| 47616 |
\fi |
| 47617 |
\else |
| 47618 |
\def\z{\endgroup\edef\XINTlogendinput{\XINTrestorecatcodes\noexpand\endinput}}% |
| 47619 |
\fi |
| 47620 |
\fi |
| 47621 |
\z% |
| 47622 |
% \end{macrocode} |
| 47623 |
%\begin{lverb} |
| 47624 |
% Here we set catcodes to the package values, the current settings |
| 47625 |
% having been saved in the \XINTlogendinput macro. We arrive here only if |
| 47626 |
% xintlog is either loaded from xintexpr or is being reloaded via an \input |
| 47627 |
% from \xintreloadxintlog. Else we aborted right before via \endinput and do |
| 47628 |
% not modify catcodes. As xintexpr inputs xintlog.sty at a time the catcode |
| 47629 |
% configuration is already the package one we pay attention to not use |
| 47630 |
% \XINTsetupcatcodes which would badly redefine \XINTrestorecatcodesendinput |
| 47631 |
% as executed at end of xintexpr.sty. There is slight inefficiency here to |
| 47632 |
% execute \XINTsetcatcodes when xintexpr initiated the xintlog loading, but |
| 47633 |
% let's live with it. |
| 47634 |
%\end{lverb} |
| 47635 |
% \begin{macrocode} |
| 47636 |
\XINTsetcatcodes% |
| 47637 |
% \end{macrocode} |
| 47638 |
% \subsection{Library identification} |
| 47639 |
% If the file has already been loaded, let's skip the |\ProvidesPackage|. |
| 47640 |
% Else let's do it and set a flag to indicate loading happened at least once |
| 47641 |
% already. |
| 47642 |
% \changed{1.4l} |
| 47643 |
% Message also to Terminal not only log file. |
| 47644 |
% \begin{macrocode} |
| 47645 |
\ifcsname xintlibver@log\endcsname |
| 47646 |
\expandafter\xint_firstoftwo |
| 47647 |
\else |
| 47648 |
\expandafter\xint_secondoftwo |
| 47649 |
\fi |
| 47650 |
{\immediate\write128{Reloading xintlog library using Digits=\xinttheDigits.}}% |
| 47651 |
{\expandafter\gdef\csname xintlibver@log\endcsname{2025/09/06 v1.4o}% |
| 47652 |
\XINT_providespackage |
| 47653 |
\ProvidesPackage{xintlog}% |
| 47654 |
[2025/09/06 v1.4o Logarithms and exponentials for xintexpr (JFB)]% |
| 47655 |
}% |
| 47656 |
% \end{macrocode} |
| 47657 |
% \subsection{\csh{xintreloadxintlog}} |
| 47658 |
%\begin{lverb} |
| 47659 |
% Now needed at 1.4e. |
| 47660 |
% |
| 47661 |
%\end{lverb} |
| 47662 |
% \begin{macrocode} |
| 47663 |
\def\xintreloadxintlog{\input xintlog.sty }% |
| 47664 |
% \end{macrocode} |
| 47665 |
% \subsection{Loading the \cshn{poormanlog} package} |
| 47666 |
%\begin{lverb} |
| 47667 |
% Attention to the catcode regime when loading poormanlog. |
| 47668 |
% |
| 47669 |
% |
| 47670 |
% Also, for xintlog.sty to be multiple-times loadable, we need to avoid using |
| 47671 |
% LaTeX's \RequirePackage twice. |
| 47672 |
% |
| 47673 |
%\end{lverb} |
| 47674 |
% \begin{macrocode} |
| 47675 |
\xintexprSafeCatcodes |
| 47676 |
\unless\ifdefined\XINTinFloatPowTen |
| 47677 |
\ifdefined\RequirePackage |
| 47678 |
\RequirePackage{poormanlog}% |
| 47679 |
\else |
| 47680 |
\input poormanlog.tex |
| 47681 |
\fi\fi |
| 47682 |
\xintexprRestoreCatcodes |
| 47683 |
% \end{macrocode} |
| 47684 |
% \subsection{Macro layer on top of the poormanlog package} |
| 47685 |
%\begin{lverb} |
| 47686 |
% This was moved here with some macro renames from xintfrac on occasion |
| 47687 |
% of 1.4e release. |
| 47688 |
% |
| 47689 |
% Breaking changes at 1.4e: |
| 47690 |
% |
| 47691 |
%( - \poormanloghack now a no-op (removed at 1.4m), |
| 47692 |
%: - \xintLog was used for \xinteval and differed slightly from its& |
| 47693 |
% counterpart used for \xintfloateval, the latter float-rounded& |
| 47694 |
% to P = Digits, the former did not and kept completly meaning-less& |
| 47695 |
% digits in output. Both macros now replaced by a \PoorManLog& |
| 47696 |
% which will always float round the output to P = Digits. Because xint& |
| 47697 |
% does not really implement a fixed point interface anyhow. |
| 47698 |
%: - \xintExp (used in \xinteval) and another macro (used in \xintfloateval)& |
| 47699 |
% did not use a sufficiently long approximation to 1/log(10) to& |
| 47700 |
% support precisely enough exp(x) if output of the order of 10^10000 for& |
| 47701 |
% example, (last two digits wrong then)& |
| 47702 |
% and situation became worse for very high values such as exp(1e8)& |
| 47703 |
% which had only 4 digits correct. |
| 47704 |
% The new \PoorManExp which replaces them is more careful... and for& |
| 47705 |
% example exp(12345678) obtains correct rounding (Digits=8). |
| 47706 |
%: - \XINTinFloatxintLog and \XINTinFloatxintExp were removed; they were& |
| 47707 |
% used for log() and exp() in \xintfloateval, and differed from \xintLog& |
| 47708 |
% and \xintExp a bit, now renamed to \PoorManLog and \PoorManExp. |
| 47709 |
%: - \PoorManPower has simply disappeared, see \XINTinFloatSciPow and \xintPow. |
| 47710 |
%) |
| 47711 |
% |
| 47712 |
% See the general xintlog introduction for some comments on the achieved |
| 47713 |
% precision and probabilities of correct rounding. |
| 47714 |
% |
| 47715 |
%\end{lverb} |
| 47716 |
% |
| 47717 |
% \subsubsection{\csh{PoorManLogBaseTen}, \csh{PoorManLog}} |
| 47718 |
%\begin{lverb} |
| 47719 |
% 1.3f. Code originally in poormanlog v0.04 got transferred here. It |
| 47720 |
% produces the logarithm in base 10 with an error (believed to be at most) of |
| 47721 |
% the order of 1 unit in the 9th (i.e. last, fixed point) fractional |
| 47722 |
% digit. Testing seems to indicate the error is never exceeding 2 units in the |
| 47723 |
% 9th place, in worst cases. |
| 47724 |
% |
| 47725 |
% These macros will still be the support macros for \xintfloatexpr log10(), |
| 47726 |
% pow10(), etc... up to Digits=8 and the poormanlog logarithm is used as |
| 47727 |
% starting point for higher precision if Digits is at least 9. |
| 47728 |
% |
| 47729 |
% Notice that \PML@999999999. expands (in \numexpr) to 1000000000 (ten |
| 47730 |
% digits), which is the only case with the output having ten digits. But there |
| 47731 |
% is no need here to treat this case especially, it works fine in |
| 47732 |
% \PML@logbaseten. |
| 47733 |
% |
| 47734 |
% Breaking change at 1.4e: for consistency with various considerations |
| 47735 |
% on floats, the output will be float rounded to P=Digits. |
| 47736 |
% |
| 47737 |
% One could envision the \xinteval variant to keep 9 fractional digits |
| 47738 |
% (it is known the last one may very well be off by 1 unit). But this |
| 47739 |
% creates complications of principles. |
| 47740 |
% |
| 47741 |
% All of this is very strange because the logarithm clearly shows the |
| 47742 |
% deficiencies of the whole idea of floating point arithmetic, logarithm goes |
| 47743 |
% from floating point to fixed point, and coercing it into pure floating point |
| 47744 |
% has moral costs. Anyway, I shall obide. |
| 47745 |
% |
| 47746 |
%\end{lverb} |
| 47747 |
% \begin{macrocode} |
| 47748 |
\def\PoorManLogBaseTen{\romannumeral0\poormanlogbaseten}% |
| 47749 |
\def\poormanlogbaseten #1% |
| 47750 |
{% |
| 47751 |
\XINTinfloat[\XINTdigits]% |
| 47752 |
{\romannumeral0\expandafter\PML@logbaseten\romannumeral0\XINTinfloat[9]{#1}}% |
| 47753 |
}% |
| 47754 |
\def\PoorManLogBaseTen_raw%#1 |
| 47755 |
{% |
| 47756 |
\romannumeral0\expandafter\PML@logbaseten\romannumeral0\XINTinfloat[9]%{#1}% |
| 47757 |
}% |
| 47758 |
\def\PML@logbaseten#1[#2]% |
| 47759 |
{% |
| 47760 |
\xintiiadd{\xintDSx{-9}{\the\numexpr#2+8\relax}}{\the\numexpr\PML@#1.}[-9]% |
| 47761 |
}% |
| 47762 |
\def\PoorManLog#1% |
| 47763 |
{% |
| 47764 |
\XINTinFloat[\XINTdigits]{\xintMul{\PoorManLogBaseTen_raw{#1}}{23025850923[-10]}}% |
| 47765 |
}% |
| 47766 |
% \end{macrocode} |
| 47767 |
% \subsubsection{\csh{PoorManPowerOfTen}, \csh{PoorManExp}} |
| 47768 |
%\begin{lverb} |
| 47769 |
% Originally in poormanlog v0.04, got transferred into xintfrac.sty at |
| 47770 |
% 1.3f, then here into xintlog.sty at 1.4e. |
| 47771 |
% |
| 47772 |
% Produces 10^x with 9 digits of float precision, with an error (believed to |
| 47773 |
% be) at most 2 units in the last place, when 0<x<1. Of course for this the |
| 47774 |
% input must be precise enough to have 9 fractional digits of **fixed point** |
| 47775 |
% precision. |
| 47776 |
% |
| 47777 |
% Breaking change at 1.4e: output always float-rounded at P=Digits. |
| 47778 |
% |
| 47779 |
% The 1.3f definition for \xintExp (now \PoorManExp) was not careful enough |
| 47780 |
% (see comments above) for very large exponents. This has been corrected at |
| 47781 |
% 1.4e. Formerly exp(12345678) produced shameful 6.3095734e5361659 where only |
| 47782 |
% the first digit (and exponent...) is correct! Now, with \xintDigits*:=8;, |
| 47783 |
% exp(12345678) will produce 6.7725836e5361659 which is correct rounding to 8 |
| 47784 |
% digits. Sorry if your rover expedition to Mars ended in failure due to using |
| 47785 |
% my software. I was not expecting anyone to use it so I did back then in 2019 |
| 47786 |
% a bit too expeditively the \xintExp thing on top of 10^x. |
| 47787 |
% |
| 47788 |
% The 1.4e \PoorManExp replaces and amends deceased \xintExp. |
| 47789 |
% |
| 47790 |
% Before using \xintRound we screen out the case of zero as \xintRound in this |
| 47791 |
% case outputs no fractional digits. |
| 47792 |
%\end{lverb} |
| 47793 |
% \begin{macrocode} |
| 47794 |
\def\PoorManPowerOfTen{\romannumeral0\poormanpoweroften}% |
| 47795 |
\def\poormanpoweroften #1% |
| 47796 |
{% |
| 47797 |
\expandafter\PML@powoften@out |
| 47798 |
\the\numexpr\expandafter\PML@powoften\romannumeral0\xintraw{#1}% |
| 47799 |
}% |
| 47800 |
\def\PML@powoften@out#1[#2]{\XINTinfloat[\XINTdigits]{#1[#2]}}% |
| 47801 |
\def\PML@powoften#1% |
| 47802 |
{% |
| 47803 |
\xint_UDzerominusfork |
| 47804 |
#1-\PML@powoften@zero |
| 47805 |
0#1\PML@powoften@neg |
| 47806 |
0-\PML@powoften@pos |
| 47807 |
\krof #1% |
| 47808 |
}% |
| 47809 |
\def\PML@powoften@zero 0/1[0]{1\relax/1[0]}% |
| 47810 |
\def\PML@powoften@pos#1[#2]% |
| 47811 |
{% |
| 47812 |
\expandafter\PML@powoften@pos@a\romannumeral0\xintround{9}{#1[#2]}.% |
| 47813 |
}% |
| 47814 |
\def\PML@powoften@pos@a#1.#2.{\PML@Pa#2.\expandafter[\the\numexpr-8+#1]}% |
| 47815 |
\def\PML@powoften@neg#1[#2]% |
| 47816 |
{% |
| 47817 |
\expandafter\PML@powoften@neg@a\romannumeral0\xintround{9}{#1[#2]}.% |
| 47818 |
}% |
| 47819 |
\def\PML@powoften@neg@a#1.#2.% |
| 47820 |
{% |
| 47821 |
\ifnum#2=\xint_c_ \xint_afterfi{1\relax/1[#1]}\else |
| 47822 |
\expandafter\expandafter\expandafter |
| 47823 |
\PML@Pa\expandafter\xint_gobble_i\the\numexpr2000000000-#2.% |
| 47824 |
\expandafter[\the\numexpr-9+#1\expandafter]\fi |
| 47825 |
}% |
| 47826 |
\def\PoorManExp#1{\PoorManPowerOfTen{\xintMul{#1}{43429448190325182765[-20]}}}% |
| 47827 |
% \end{macrocode} |
| 47828 |
% \subsubsection{Removed: \csh{PoorManPower}, see \cshnolabel{XINTinFloatSciPow}} |
| 47829 |
%\begin{lverb} |
| 47830 |
% Removed at 1.4e. See \XINTinFloatSciPow. |
| 47831 |
%\end{lverb} |
| 47832 |
% \subsection{Macro support for powers} |
| 47833 |
% |
| 47834 |
% \subsubsection{\csh{XINTinFloatSciPow}} |
| 47835 |
% |
| 47836 |
% |
| 47837 |
%\begin{lverb} |
| 47838 |
% |
| 47839 |
% This is the new name and extension of \XINTinFloatPowerH which was |
| 47840 |
% a non user-documented macro used for a^b previously, and previously |
| 47841 |
% was located in $xintfracnameimp. |
| 47842 |
% |
| 47843 |
% A check is done whether the exponent is integer or half-integer, and if |
| 47844 |
% positive, the legacy \xintFloatPower/\xintFloatSqrt macros are used. The |
| 47845 |
% rationale is that: |
| 47846 |
% |
| 47847 |
%( - they give faster evaluations for integer exponent b < 10000 (and beyond) |
| 47848 |
%: - they operate at any value of Digits |
| 47849 |
%: - they keep accuracy even with gigantic exponents, whereas the pow10()/log10()& |
| 47850 |
% path starts losing accuracy for b about 1e8. In fact at 1.4e it was even& |
| 47851 |
% for b about 1000, as log10(A) was not computed with enough fractional& |
| 47852 |
% digits, except for 0.8<A<1.26 (roughly), for this usage. At the 1.4f& |
| 47853 |
% bugfix we compute log10(A) with enough accuracy for A^b to be safe with& |
| 47854 |
% b as large as 1e7, and show visible degradation only for b about 1e9. |
| 47855 |
%) |
| 47856 |
% |
| 47857 |
% The user documentation of \xintFloatPower mentions a 0.52 ulp(Z) error where |
| 47858 |
% Z is the computed result, which seems not as good as the kind of accuracy we |
| 47859 |
% target for pow10() (for -1<x<1) and log10() (for 1<x<10) which is more like |
| 47860 |
% about 0.505ulp. Perhaps in future I will examine if I need to increase a |
| 47861 |
% bit the theoretical accuracy of \xintFloatPower but at time of 1.4e/1.4f |
| 47862 |
% release I have left it standing as is. |
| 47863 |
% |
| 47864 |
% The check whether exponent is integer or half-integer is not on the value |
| 47865 |
% but on the representation. Even in \xintfloatexpr, input such |
| 47866 |
% 10^\xintexpr4/2\relax is possible, and 4/2 will not be recognized as integer |
| 47867 |
% to avoid costly overhead. 3/2 will not be recognized as half-integer. |
| 47868 |
% But 2.0 will be recognized as integer, 25e-1 as half-integer. |
| 47869 |
% |
| 47870 |
% In the computation of A^b, A will be float-rounded to Digits, but the |
| 47871 |
% exponent b will be handled "as is" until last minute. Recall that the |
| 47872 |
% \xintfloatexpr parser does not automatically float round isolated inputs, |
| 47873 |
% this happens only once involved in computations. |
| 47874 |
% |
| 47875 |
% In the Digits<=8 branch we do the same as for Digits>8 since 1.4f. At 1.4e I |
| 47876 |
% had strangely chosen (for "speed", but that was anyhow questionable for |
| 47877 |
% integer exponents less than 10 for example) to always use log10()/pow10()... |
| 47878 |
% But with only 9 fractional digits for the logarithms, exponents such as 1000 |
| 47879 |
% naturally led to last 2 or 3 digits being wrong and let's not even mention |
| 47880 |
% when the exponent was of the order or 1e6... now A^1000 and A^1000.5 are |
| 47881 |
% accurately computed and one can handle a^1000.1 as a^1000*a^0.1 |
| 47882 |
% |
| 47883 |
% I wrote the code during 1.4e to 1.4f transition for doing this split of |
| 47884 |
% exponent automatically, but it induced a very significant time penalty down |
| 47885 |
% the line for fractional exponents, whereas currently a^b is computed at |
| 47886 |
% Digits=8 with perfectly acceptable accuracy for fractional abs(b)<10, and at |
| 47887 |
% high speed, and accuracy for big exponents can be obtained by manually |
| 47888 |
% splitting as above (although the above has no user interface for keeping |
| 47889 |
% each contribution with its extra digits; a single one for a^h, -1<h<1). |
| 47890 |
%\end{lverb} |
| 47891 |
% \begin{macrocode} |
| 47892 |
\def\XINTinFloatSciPow{\romannumeral0\XINTinfloatscipow}% |
| 47893 |
\def\XINTinfloatscipow#1#2% |
| 47894 |
{% |
| 47895 |
\expandafter\XINT_scipow_a\romannumeral0\xintrez{#2}\XINT_scipow_int{#1}% |
| 47896 |
}% |
| 47897 |
\def\XINT_scipow_a #1% |
| 47898 |
{% |
| 47899 |
\xint_gob_til_zero#1\XINT_scipow_Biszero0\XINT_scipow_b#1% |
| 47900 |
}% |
| 47901 |
\def\XINT_scipow_Biszero#1]#2#3{ 1[0]}% |
| 47902 |
\def\XINT_scipow_b #1#2/#3[#4]#5% |
| 47903 |
{% |
| 47904 |
\unless\if1\XINT_is_One#3XY\xint_dothis\XINT_scipow_c\fi |
| 47905 |
\ifnum#4<\xint_c_mone\xint_dothis\XINT_scipow_c\fi |
| 47906 |
\ifnum#4=\xint_c_mone |
| 47907 |
\if5\xintLDg{#1#2} % |
| 47908 |
\xint_afterfi{\xint_dothis\XINT_scipow_halfint}\else |
| 47909 |
\xint_afterfi{\xint_dothis\XINT_scipow_c}% |
| 47910 |
\fi |
| 47911 |
\fi |
| 47912 |
\xint_orthat#5#1#2/#3[#4]% |
| 47913 |
}% |
| 47914 |
\def\XINT_scipow_int #1/1[#2]#3% |
| 47915 |
{% |
| 47916 |
\expandafter\XINT_flpower_checkB_a |
| 47917 |
\romannumeral0\XINT_dsx_addzeros{#2}#1;.\XINTdigits.{#3}{\XINTinfloatS[\XINTdigits]}% |
| 47918 |
}% |
| 47919 |
% \end{macrocode} |
| 47920 |
%\begin{lverb} |
| 47921 |
% The \XINT_flpowerh_finish is the sole remnant of \XINTinFloatPowerH |
| 47922 |
% which was formerly stitched to \xintFloatPower and checked for half-integer |
| 47923 |
% exponent. |
| 47924 |
%\end{lverb} |
| 47925 |
% \begin{macrocode} |
| 47926 |
\def\XINT_scipow_halfint#1/1[#2]#3% |
| 47927 |
{% |
| 47928 |
\expandafter\XINT_flpower_checkB_a |
| 47929 |
\romannumeral0\xintdsr{\xintDouble{#1}}.\XINTdigits.{#3}\XINT_flpowerh_finish |
| 47930 |
}% |
| 47931 |
\def\XINT_flpowerh_finish #1% |
| 47932 |
{% |
| 47933 |
\XINTinfloatS[\XINTdigits]{\XINTinFloatSqrt[\XINTdigits+\xint_c_iii]{#1}}% |
| 47934 |
}% |
| 47935 |
\def\XINT_tmpa#1.{% |
| 47936 |
\def\XINT_scipow_c ##1[##2]##3% |
| 47937 |
{% |
| 47938 |
\expandafter\XINT_scipow_d\romannumeral0\XINTinfloatS[#1]{##3}\xint:##1[##2]\xint: |
| 47939 |
}% |
| 47940 |
}\expandafter\XINT_tmpa\the\numexpr\XINTdigits.% |
| 47941 |
\def\XINT_scipow_d #1% |
| 47942 |
{% |
| 47943 |
\xint_UDzerominusfork |
| 47944 |
#1-\XINT_scipow_Aiszero |
| 47945 |
0#1\XINT_scipow_Aisneg |
| 47946 |
0-\XINT_scipow_Aispos |
| 47947 |
\krof #1% |
| 47948 |
}% |
| 47949 |
\def\XINT_scipow_Aiszero #1\xint:#2#3\xint: |
| 47950 |
{% |
| 47951 |
% \end{macrocode} |
| 47952 |
%\begin{lverb} |
| 47953 |
% Missing NaN and Infinity causes problems. Inserting something |
| 47954 |
% like 1["7FFF8000] is risky as certain macros convert [N] into N zeros... |
| 47955 |
% so the run can appear to stall and will crash possibly badly if we do that. |
| 47956 |
% There is some usage in relation to ilog10 in xint.sty and xintfrac.sty |
| 47957 |
% of "7FFF8000 but here I will stay prudent and insert the usual 0 value |
| 47958 |
% (changed at 1.4g) |
| 47959 |
%\end{lverb} |
| 47960 |
% \begin{macrocode} |
| 47961 |
\if-#2\xint_dothis |
| 47962 |
{\XINT_signalcondition{InvalidOperation}{0 raised to power #2#3.}{}{ 0[0]}}\fi |
| 47963 |
\xint_orthat{ 0[0]}% |
| 47964 |
}% |
| 47965 |
\def\XINT_scipow_Aispos #1\xint:#2\xint: |
| 47966 |
{% |
| 47967 |
\XINTinfloatpowten{\xintMul{#2}{\XINTinFloatLogTen_xdgout#1}}% |
| 47968 |
}% |
| 47969 |
% \end{macrocode} |
| 47970 |
%\begin{lverb} |
| 47971 |
% If a^b with a<0, we arrive here only if b was not considered to be |
| 47972 |
% an integer exponent. So let's raise an error. |
| 47973 |
%\end{lverb} |
| 47974 |
% \begin{macrocode} |
| 47975 |
\def\XINT_scipow_Aisneg #1#2\xint:#3\xint: |
| 47976 |
{% |
| 47977 |
\XINT_signalcondition{InvalidOperation}% |
| 47978 |
{Fractional power #3 of negative #1#2.}{}{ 0[0]}% |
| 47979 |
}% |
| 47980 |
\ifnum\XINTdigits<9 |
| 47981 |
% \end{macrocode} |
| 47982 |
%\begin{lverb} |
| 47983 |
% At 1.4f we only need for Digits up to 8 to insert usage of poormanlog |
| 47984 |
% for non integer, non half-integer exponents. At 1.4e the code was more |
| 47985 |
% complicated because I had strangely opted for using always the log10() |
| 47986 |
% path. However we have to be careful to use \PML@logbaseten with 9 digits |
| 47987 |
% always. |
| 47988 |
% |
| 47989 |
% As the legacy macros used for integer and half-integer exponents float-round |
| 47990 |
% the input to Digits digits, we must do the same here for coherence. Which |
| 47991 |
% induces some small complications here. |
| 47992 |
%\end{lverb} |
| 47993 |
% \begin{macrocode} |
| 47994 |
\def\XINT_tmpa#1.#2.#3.{% |
| 47995 |
\def\XINT_scipow_c ##1[##2]##3% |
| 47996 |
{% |
| 47997 |
\expandafter\XINT_scipow_d |
| 47998 |
\romannumeral0\expandafter\XINT_scipow_c_i |
| 47999 |
\romannumeral0\XINTinfloat[#1]{##3}\xint:##1[##2]\xint: |
| 48000 |
}% |
| 48001 |
\def\XINT_scipow_c_i##1[##2]{ ##1#3[##2-#2]}% |
| 48002 |
}\expandafter\XINT_tmpa\the\numexpr\XINTdigits\expandafter.% |
| 48003 |
\the\numexpr9-\XINTdigits\expandafter.% |
| 48004 |
\romannumeral\xintreplicate{9-\XINTdigits}0.% |
| 48005 |
\def\XINT_scipow_Aispos #1\xint:#2\xint: |
| 48006 |
{% |
| 48007 |
\poormanpoweroften{\xintMul{#2}{\romannumeral0\expandafter\PML@logbaseten#1}}% |
| 48008 |
}% |
| 48009 |
\fi |
| 48010 |
% \end{macrocode} |
| 48011 |
% \subsubsection{\cshnolabel{xintPow}} |
| 48012 |
%\begin{lverb} |
| 48013 |
% |
| 48014 |
% Support macro for a^b in \xinteval. This overloads the original |
| 48015 |
% $xintfracnameimp macro, keeping its original meaning only for integer |
| 48016 |
% exponents, which are not too big: for exact evaluation of A^b, we want the |
| 48017 |
% output to not have more than about 10000 digits (separately for numerator |
| 48018 |
% and denominator). For this we limit b depending on the length of A, simply |
| 48019 |
% we want b to be smaller than the rounded value of 10000 divided by the |
| 48020 |
% length of A. For one-digit A, this would give 10000 as maximal exponent but |
| 48021 |
% due to organization of code related to avoir arithmetic overflow (we can't |
| 48022 |
% immediately operate in \numexpr with b as it is authorized to be beyond TeX |
| 48023 |
% bound), the maximal exponent is 9999. |
| 48024 |
% |
| 48025 |
% The criterion, which guarantees output (numerator and |
| 48026 |
% denominator separately) does not exceed by much 10000 digits if at all is |
| 48027 |
% that the exponent should be less than the (rounded in the sense of \numexpr) |
| 48028 |
% quotient of 10000 by the number of digits of a (considering separately |
| 48029 |
% numerator and denominator). |
| 48030 |
% |
| 48031 |
% The decision whether to compute A^b exactly depends on the length of |
| 48032 |
% internal representation of A. So 9^9999 is evaluated exactly (in \xinteval) |
| 48033 |
% but for 9.0 it is 9.0^5000 the maximal power. This may change in future. |
| 48034 |
% |
| 48035 |
% 1.4e had the following bug (for Digits>8): big integer exponents used the |
| 48036 |
% log10()/pow10() based approach rather than the legacy macro path which goes |
| 48037 |
% via \xintFloatPower, as done by \xintfloateval! As a result powers with very |
| 48038 |
% large integer exponents were more precise in \xintfloateval than in \xinteval! |
| 48039 |
% |
| 48040 |
% 1.4f fixes this. Also, it handles Digits<=8 as Digits>8, bringing much |
| 48041 |
% simplification here. |
| 48042 |
%\end{lverb} |
| 48043 |
% \begin{macrocode} |
| 48044 |
\def\xintPow{\romannumeral0\xintpow}% |
| 48045 |
\def\xintpow#1#2% |
| 48046 |
{% |
| 48047 |
\expandafter\XINT_scipow_a\romannumeral0\xintrez{#2}\XINT_pow_int{#1}% |
| 48048 |
}% |
| 48049 |
% \end{macrocode} |
| 48050 |
%\begin{lverb} |
| 48051 |
% In case of half-integer exponent the \XINT_scipow_a will have |
| 48052 |
% triggered usage of the (new incarnation) of \XINTinFloatPowerH which combines |
| 48053 |
% \xintFloatPower and square root extraction. So we only have to handle here |
| 48054 |
% the case of integer exponents which will trigger execution of this |
| 48055 |
% \XINT_pow_int macro passed as parameter to \xintpow. |
| 48056 |
%\end{lverb} |
| 48057 |
% \begin{macrocode} |
| 48058 |
\def\XINT_pow_int #1/1[#2]% |
| 48059 |
{% |
| 48060 |
\expandafter\XINT_pow_int_a\romannumeral0\XINT_dsx_addzeros{#2}#1;.% |
| 48061 |
}% |
| 48062 |
% \end{macrocode} |
| 48063 |
%\begin{lverb} |
| 48064 |
% 1.4e had a bug here for integer exponents >= 10000: they triggered |
| 48065 |
% going back to the floating point routine but at a late location where |
| 48066 |
% the log10()/pow10() approach is used. |
| 48067 |
%\end{lverb} |
| 48068 |
% \begin{macrocode} |
| 48069 |
\def\XINT_pow_int_a #1#2.% |
| 48070 |
{% |
| 48071 |
\ifnum\if-#1\xintLength{#2}\else\xintLength{#1#2}\fi>\xint_c_iv |
| 48072 |
\expandafter\XINT_pow_bigint |
| 48073 |
\else\expandafter\XINT_pow_int_b |
| 48074 |
\fi #1#2.% |
| 48075 |
}% |
| 48076 |
% \end{macrocode} |
| 48077 |
%\begin{lverb} |
| 48078 |
% At 1.4f we correctly jump to the appropriate entry point into the |
| 48079 |
% \xintFloatPower routine of $xintfracnameimp, in case of a big integer |
| 48080 |
% exponent. |
| 48081 |
%\end{lverb} |
| 48082 |
% \begin{macrocode} |
| 48083 |
\def\XINT_pow_bigint #1.#2% |
| 48084 |
{% |
| 48085 |
\XINT_flpower_checkB_a#1.\XINTdigits.{#2}{\XINTinfloatS[\XINTdigits]}% |
| 48086 |
}% |
| 48087 |
\def\XINT_pow_int_b #1.#2% |
| 48088 |
{% |
| 48089 |
% \end{macrocode} |
| 48090 |
%\begin{lverb} |
| 48091 |
% We now check if the output will not be too bulky. We use here (on the |
| 48092 |
% a of a^b) \xintraw, not \xintrez, on purpose so that for example 9.0^9999 |
| 48093 |
% is computed in floating point sense but 9^9999 is computed exactly. However |
| 48094 |
% 9.0^5000 will be computed exactly. And if I used \xintrez here \xinteval{100^2} |
| 48095 |
% would print 10000.0 and \xinteval{100^3} would print 1.0e6. Thus situation |
| 48096 |
% is complex. |
| 48097 |
% |
| 48098 |
% By the way I am happy to see that 9.0*9.0 in |
| 48099 |
% \xinteval does print 81.0 but the truth is that internally it does have the |
| 48100 |
% more bulky 8100/1[-2] maybe I should make some revision of this, i.e. use |
| 48101 |
% rather systematically \xintREZ on input rather than \xintRaw (note taken on |
| 48102 |
% 2021/05/08 at time of doing 1.4f bugfix release). |
| 48103 |
%\end{lverb} |
| 48104 |
% \begin{macrocode} |
| 48105 |
\expandafter\XINT_pow_int_c\romannumeral0\xintraw{#2}\xint:#1\xint: |
| 48106 |
}% |
| 48107 |
% \end{macrocode} |
| 48108 |
%\begin{lverb} |
| 48109 |
% The \XINT_fpow_fork is (quasi top level) entry point we have found |
| 48110 |
% into the legacy \xintPow routine of $xintfracnameimp. Its interface is a bit |
| 48111 |
% weird, but let's not worry about this now. |
| 48112 |
% |
| 48113 |
%\end{lverb} |
| 48114 |
% \begin{macrocode} |
| 48115 |
\def\XINT_pow_int_c#1#2/#3[#4]\xint:#5\xint: |
| 48116 |
{% |
| 48117 |
\if0\ifnum\numexpr\xint_c_x^iv/% |
| 48118 |
(\xintLength{#1#2}\if-#1-\xint_c_i\fi)<\XINT_Abs#5 % |
| 48119 |
1\else |
| 48120 |
\ifnum\numexpr\xint_c_x^iv/\xintLength{#3}<\XINT_Abs#5 % |
| 48121 |
1\else |
| 48122 |
0\fi\fi |
| 48123 |
\expandafter\XINT_fpow_fork\else\expandafter\XINT_pow_bigint_i |
| 48124 |
\fi |
| 48125 |
#5\Z{#4}{#1#2}{#3}% |
| 48126 |
}% |
| 48127 |
% \end{macrocode} |
| 48128 |
%\begin{lverb} |
| 48129 |
% \XINT_pow_bigint_i is like \XINT_pow_bigint but has its parameters |
| 48130 |
% organized differently. |
| 48131 |
%\end{lverb} |
| 48132 |
% \begin{macrocode} |
| 48133 |
\def\XINT_pow_bigint_i#1\Z#2#3#4% |
| 48134 |
{% |
| 48135 |
\XINT_flpower_checkB_a#1.\XINTdigits.{#3/#4[#2]}{\XINTinfloatS[\XINTdigits]}% |
| 48136 |
}% |
| 48137 |
% \end{macrocode} |
| 48138 |
% \subsection{Macro support for \cshnolabel{xintexpr} and \cshnolabel{xintfloatexpr} syntax} |
| 48139 |
% \subsubsection{The \cshn{log10()} and \cshn{pow10()} functions} |
| 48140 |
%\begin{lverb} |
| 48141 |
% Up to 8 digits included we use the poormanlog based ones. |
| 48142 |
%\end{lverb} |
| 48143 |
% \begin{macrocode} |
| 48144 |
\ifnum\XINTdigits<9 |
| 48145 |
\expandafter\def\csname XINT_expr_func_log10\endcsname#1#2#3% |
| 48146 |
{% |
| 48147 |
\expandafter #1\expandafter #2\expandafter{% |
| 48148 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 48149 |
{\romannumeral`&&@\PoorManLogBaseTen#3}}% |
| 48150 |
}% |
| 48151 |
\expandafter\def\csname XINT_expr_func_pow10\endcsname#1#2#3% |
| 48152 |
{% |
| 48153 |
\expandafter #1\expandafter #2\expandafter{% |
| 48154 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 48155 |
{\romannumeral`&&@\PoorManPowerOfTen#3}}% |
| 48156 |
}% |
| 48157 |
\else |
| 48158 |
\expandafter\def\csname XINT_expr_func_log10\endcsname#1#2#3% |
| 48159 |
{% |
| 48160 |
\expandafter #1\expandafter #2\expandafter{% |
| 48161 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 48162 |
{\romannumeral`&&@\XINTinFloatLogTen#3}}% |
| 48163 |
}% |
| 48164 |
\expandafter\def\csname XINT_expr_func_pow10\endcsname#1#2#3% |
| 48165 |
{% |
| 48166 |
\expandafter #1\expandafter #2\expandafter{% |
| 48167 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 48168 |
{\romannumeral`&&@\XINTinFloatPowTen#3}}% |
| 48169 |
}% |
| 48170 |
\fi |
| 48171 |
\expandafter\let\csname XINT_flexpr_func_log10\expandafter\endcsname |
| 48172 |
\csname XINT_expr_func_log10\endcsname |
| 48173 |
\expandafter\let\csname XINT_flexpr_func_pow10\expandafter\endcsname |
| 48174 |
\csname XINT_expr_func_pow10\endcsname |
| 48175 |
% \end{macrocode} |
| 48176 |
% \subsubsection{The \cshn{log()}, \cshn{exp()} functions} |
| 48177 |
% \begin{macrocode} |
| 48178 |
\ifnum\XINTdigits<9 |
| 48179 |
\def\XINT_expr_func_log #1#2#3% |
| 48180 |
{% |
| 48181 |
\expandafter #1\expandafter #2\expandafter{% |
| 48182 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 48183 |
{\romannumeral`&&@\PoorManLog#3}}% |
| 48184 |
}% |
| 48185 |
\def\XINT_expr_func_exp #1#2#3% |
| 48186 |
{% |
| 48187 |
\expandafter #1\expandafter #2\expandafter{% |
| 48188 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 48189 |
{\romannumeral`&&@\PoorManExp#3}}% |
| 48190 |
}% |
| 48191 |
\let\XINT_flexpr_func_log\XINT_expr_func_log |
| 48192 |
\let\XINT_flexpr_func_exp\XINT_expr_func_exp |
| 48193 |
\else |
| 48194 |
\def\XINT_expr_func_log #1#2#3% |
| 48195 |
{% |
| 48196 |
\expandafter #1\expandafter #2\expandafter{% |
| 48197 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 48198 |
{\romannumeral`&&@\XINTinFloatLog#3}}% |
| 48199 |
}% |
| 48200 |
\def\XINT_expr_func_exp #1#2#3% |
| 48201 |
{% |
| 48202 |
\expandafter #1\expandafter #2\expandafter{% |
| 48203 |
\romannumeral`&&@\XINT:NEhook:f:one:from:one |
| 48204 |
{\romannumeral`&&@\XINTinFloatExp#3}}% |
| 48205 |
}% |
| 48206 |
\let\XINT_flexpr_func_log\XINT_expr_func_log |
| 48207 |
\let\XINT_flexpr_func_exp\XINT_expr_func_exp |
| 48208 |
\fi |
| 48209 |
% \end{macrocode} |
| 48210 |
% \subsubsection{The \cshn{pow()} function} |
| 48211 |
%\begin{lverb} |
| 48212 |
% The mapping of ** and ^ to \XINTinFloatSciPow (in \xintfloatexpr |
| 48213 |
% context) and \xintPow (in \xintexpr context), |
| 48214 |
% is done in $xintexprnameimp. |
| 48215 |
%\end{lverb} |
| 48216 |
% \begin{macrocode} |
| 48217 |
\def\XINT_expr_func_pow #1#2#3% |
| 48218 |
{% |
| 48219 |
\expandafter #1\expandafter #2\expandafter{% |
| 48220 |
\romannumeral`&&@\XINT:NEhook:f:one:from:two |
| 48221 |
{\romannumeral`&&@\xintPow#3}}% |
| 48222 |
}% |
| 48223 |
\def\XINT_flexpr_func_pow #1#2#3% |
| 48224 |
{% |
| 48225 |
\expandafter #1\expandafter #2\expandafter{% |
| 48226 |
\romannumeral`&&@\XINT:NEhook:f:one:from:two |
| 48227 |
{\romannumeral`&&@\XINTinFloatSciPow#3}}% |
| 48228 |
}% |
| 48229 |
% \end{macrocode} |
| 48230 |
% \subsection{End of package loading for low Digits} |
| 48231 |
% \begin{macrocode} |
| 48232 |
\ifnum\XINTdigits<9 \expandafter\XINTlogendinput\fi% |
| 48233 |
% \end{macrocode} |
| 48234 |
% \subsection{Stored constants} |
| 48235 |
%\begin{lverb} |
| 48236 |
% The constants were obtained from Maple at 80 digits: fractional power |
| 48237 |
% of 10, but only one logarithm log(10). |
| 48238 |
% |
| 48239 |
% Currently the code whether for exponential or logarihm will not screen out 0 |
| 48240 |
% digits and even will do silly multiplication by 10^0 = 1 in that case, and |
| 48241 |
% we need to store such silly values. |
| 48242 |
% |
| 48243 |
% We add the data for the 10^-0.i etc... because pre-computing them on the fly |
| 48244 |
% significantly adds overhead to the package loading. |
| 48245 |
% |
| 48246 |
% The fractional powers of ten with D+5 digits are used to compute pow10() |
| 48247 |
% function, those with D+10 digits are used to compute log10() function. This |
| 48248 |
% is done with |
| 48249 |
% an elevated precision for two reasons: |
| 48250 |
%( - handling of inputs near 1, |
| 48251 |
%: - in order for a^b = pow10(b*log10(a)) to keep accuracy& |
| 48252 |
% even with large exponents, say in absolute value up to 1e7,& |
| 48253 |
% degradation beginning to show-up at 1e8. |
| 48254 |
%) |
| 48255 |
%\end{lverb} |
| 48256 |
% \def\macro@font{\ttfamily \hfuzz 30pt } |
| 48257 |
% \begin{macrocode} |
| 48258 |
\def\XINT_tmpa{1[0]}% |
| 48259 |
\expandafter\let\csname XINT_c_1_0\endcsname\XINT_tmpa |
| 48260 |
\expandafter\let\csname XINT_c_2_0\endcsname\XINT_tmpa |
| 48261 |
\expandafter\let\csname XINT_c_3_0\endcsname\XINT_tmpa |
| 48262 |
\expandafter\let\csname XINT_c_4_0\endcsname\XINT_tmpa |
| 48263 |
\expandafter\let\csname XINT_c_5_0\endcsname\XINT_tmpa |
| 48264 |
\expandafter\let\csname XINT_c_6_0\endcsname\XINT_tmpa |
| 48265 |
\expandafter\let\csname XINT_c_1_0_x\endcsname\XINT_tmpa |
| 48266 |
\expandafter\let\csname XINT_c_2_0_x\endcsname\XINT_tmpa |
| 48267 |
\expandafter\let\csname XINT_c_3_0_x\endcsname\XINT_tmpa |
| 48268 |
\expandafter\let\csname XINT_c_4_0_x\endcsname\XINT_tmpa |
| 48269 |
\expandafter\let\csname XINT_c_5_0_x\endcsname\XINT_tmpa |
| 48270 |
\expandafter\let\csname XINT_c_6_0_x\endcsname\XINT_tmpa |
| 48271 |
\expandafter\let\csname XINT_c_1_0_inv\endcsname\XINT_tmpa |
| 48272 |
\expandafter\let\csname XINT_c_2_0_inv\endcsname\XINT_tmpa |
| 48273 |
\expandafter\let\csname XINT_c_3_0_inv\endcsname\XINT_tmpa |
| 48274 |
\expandafter\let\csname XINT_c_4_0_inv\endcsname\XINT_tmpa |
| 48275 |
\expandafter\let\csname XINT_c_5_0_inv\endcsname\XINT_tmpa |
| 48276 |
\expandafter\let\csname XINT_c_6_0_inv\endcsname\XINT_tmpa |
| 48277 |
\expandafter\let\csname XINT_c_1_0_inv_x\endcsname\XINT_tmpa |
| 48278 |
\expandafter\let\csname XINT_c_2_0_inv_x\endcsname\XINT_tmpa |
| 48279 |
\expandafter\let\csname XINT_c_3_0_inv_x\endcsname\XINT_tmpa |
| 48280 |
\expandafter\let\csname XINT_c_4_0_inv_x\endcsname\XINT_tmpa |
| 48281 |
\expandafter\let\csname XINT_c_5_0_inv_x\endcsname\XINT_tmpa |
| 48282 |
\expandafter\let\csname XINT_c_6_0_inv_x\endcsname\XINT_tmpa |
| 48283 |
\def\XINT_tmpa#1#2#3#4;% |
| 48284 |
{\expandafter\edef\csname XINT_c_#1_#2\endcsname |
| 48285 |
{\XINTinFloat[\XINTdigitsormax+5]{#3#4[-79]}}% |
| 48286 |
\expandafter\edef\csname XINT_c_#1_#2_x\endcsname |
| 48287 |
{\XINTinFloat[\XINTdigitsormax+10]{#3#4[-79]}}% |
| 48288 |
}% |
| 48289 |
% 10^0.i |
| 48290 |
\XINT_tmpa 1 1 12589254117941672104239541063958006060936174094669310691079230195266476157825020;% |
| 48291 |
\XINT_tmpa 1 2 15848931924611134852021013733915070132694421338250390683162968123166568636684540;% |
| 48292 |
\XINT_tmpa 1 3 19952623149688796013524553967395355579862743154053460992299136670049309106980490;% |
| 48293 |
\XINT_tmpa 1 4 25118864315095801110850320677993273941585181007824754286798884209082432477235613;% |
| 48294 |
\XINT_tmpa 1 5 31622776601683793319988935444327185337195551393252168268575048527925944386392382;% |
| 48295 |
\XINT_tmpa 1 6 39810717055349725077025230508775204348767703729738044686528414806022485386945804;% |
| 48296 |
\XINT_tmpa 1 7 50118723362727228500155418688494576806047198983281926392969745588901125568883069;% |
| 48297 |
\XINT_tmpa 1 8 63095734448019324943436013662234386467294525718822872452772952883349494329768681;% |
| 48298 |
\XINT_tmpa 1 9 79432823472428150206591828283638793258896063175548433209232392931695569719148754;% |
| 48299 |
% 10^0.0i |
| 48300 |
\XINT_tmpa 2 1 10232929922807541309662751748198778273411640572379813085994255856738296458625172;% |
| 48301 |
\XINT_tmpa 2 2 10471285480508995334645020315281400790567914715039292120056525299012577641023719;% |
| 48302 |
\XINT_tmpa 2 3 10715193052376064174083022246945087339158659633422172707894501914136771607653870;% |
| 48303 |
\XINT_tmpa 2 4 10964781961431850131437136061411270464271158762483023169080841607885740984711300;% |
| 48304 |
\XINT_tmpa 2 5 11220184543019634355910389464779057367223085073605529624450744481701033026862244;% |
| 48305 |
\XINT_tmpa 2 6 11481536214968827515462246116628360182562102373996119340874991068894793593040890;% |
| 48306 |
\XINT_tmpa 2 7 11748975549395295417220677651268442278134317971793124791953875805007912852226246;% |
| 48307 |
\XINT_tmpa 2 8 12022644346174129058326127151935204486942664354881189151104892745683155052368222;% |
| 48308 |
\XINT_tmpa 2 9 12302687708123815342415404364750907389955639574572144413097319170011637639124482;% |
| 48309 |
% 10^0.00i |
| 48310 |
\XINT_tmpa 3 1 10023052380778996719154048893281105540536684535421606464116348523047431367720401;% |
| 48311 |
\XINT_tmpa 3 2 10046157902783951424046519858132787392010166060319618489538315083825599423438638;% |
| 48312 |
\XINT_tmpa 3 3 10069316688518041699296607872661381368099438247964820601930206419324524707606686;% |
| 48313 |
\XINT_tmpa 3 4 10092528860766844119155277641202580844111492027373621434478800545314309618714957;% |
| 48314 |
\XINT_tmpa 3 5 10115794542598985244409323144543146957419235215102899054703546688078254946034250;% |
| 48315 |
\XINT_tmpa 3 6 10139113857366794119988279023017296985954042032867436525450889437280417044987125;% |
| 48316 |
\XINT_tmpa 3 7 10162486928706956276733661150135543062420167220622552197768982666050994284378619;% |
| 48317 |
\XINT_tmpa 3 8 10185913880541169240797988673338257820431768224957171297560936579346433061037662;% |
| 48318 |
\XINT_tmpa 3 9 10209394837076799554149033101487543990018213667630072574873723356334069913329713;% |
| 48319 |
% 10^0.000i |
| 48320 |
\XINT_tmpa 4 1 10002302850208247526835942556719413318678216124626534526963475845228205382579041;% |
| 48321 |
\XINT_tmpa 4 2 10004606230728403216239656646745503559081482371024284871882409614422496765669196;% |
| 48322 |
\XINT_tmpa 4 3 10006910141682589957025973521996241909035914023642264228577379693841345823180462;% |
| 48323 |
\XINT_tmpa 4 4 10009214583192958761081718336761022426385537997384755843291864010938378093197023;% |
| 48324 |
\XINT_tmpa 4 5 10011519555381688769842032367472488618040778885656970999331288116685029387850446;% |
| 48325 |
\XINT_tmpa 4 6 10013825058370987260768186632475607982636715641432550952229573271596547716373358;% |
| 48326 |
\XINT_tmpa 4 7 10016131092283089653826887255241073941084503769368844606021481400409002185558343;% |
| 48327 |
\XINT_tmpa 4 8 10018437657240259517971072914549205297136779497498835020699531587537662833033174;% |
| 48328 |
\XINT_tmpa 4 9 10020744753364788577622204725249622301332888222801030351604197113557132455165040;% |
| 48329 |
% 10^0.0000i |
| 48330 |
\XINT_tmpa 5 1 10000230261160268806710649793464495797824846841503180050673957122443571394978721;% |
| 48331 |
\XINT_tmpa 5 2 10000460527622557806255008596155855743730116854295068547616656160734125748005947;% |
| 48332 |
\XINT_tmpa 5 3 10000690799386989083565213461287219981856579552059660369243804541364501659468630;% |
| 48333 |
\XINT_tmpa 5 4 10000921076453684726384543254593368743049141124080210677706489564626675960578367;% |
| 48334 |
\XINT_tmpa 5 5 10001151358822766825267483384008265483772370538793312970508590203623535763866465;% |
| 48335 |
\XINT_tmpa 5 6 10001381646494357473579790530833073090516914490540536234536867917078761046656260;% |
| 48336 |
\XINT_tmpa 5 7 10001611939468578767498557382394677469502542123237272447312733350028467607076918;% |
| 48337 |
\XINT_tmpa 5 8 10001842237745552806012277366194752842273812293689190856411757410911882303011468;% |
| 48338 |
\XINT_tmpa 5 9 10002072541325401690920909385549403068574626162727745910217443397959031898734024;% |
| 48339 |
% 10^0.00000i |
| 48340 |
\XINT_tmpa 6 1 10000023025877439451356029805459000097926504781151663770980171880313737943886754;% |
| 48341 |
\XINT_tmpa 6 2 10000046051807898005897723104514851394069452605882077809669546315010724085277647;% |
| 48342 |
\XINT_tmpa 6 3 10000069077791375785706217087438809625967243923218032821061587553353589726808164;% |
| 48343 |
\XINT_tmpa 6 4 10000092103827872912862930047032391734439796534302560512742030066798473305401477;% |
| 48344 |
\XINT_tmpa 6 5 10000115129917389509449561379274639104559958866285946533811801963402821672829477;% |
| 48345 |
\XINT_tmpa 6 6 10000138156059925697548091583969382297005329013199894805417325991907389143667949;% |
| 48346 |
\XINT_tmpa 6 7 10000161182255481599240782265392507269793911275470978276390154932321984777772469;% |
| 48347 |
\XINT_tmpa 6 8 10000184208504057336610176132939223090407041937631374389422968832433217547184883;% |
| 48348 |
\XINT_tmpa 6 9 10000207234805653031739097001771331138303016031686764989867510425362339583809842;% |
| 48349 |
\def\XINT_tmpa#1#2#3#4;% |
| 48350 |
{\expandafter\edef |
| 48351 |
\csname XINT_c_#1_#2_inv\endcsname{\XINTinFloat[\XINTdigitsormax+5]{#3#4[-80]}}% |
| 48352 |
\expandafter\edef |
| 48353 |
\csname XINT_c_#1_#2_inv_x\endcsname{\XINTinFloat[\XINTdigitsormax+10]{#3#4[-80]}}% |
| 48354 |
}% |
| 48355 |
% 10^-0.i |
| 48356 |
\XINT_tmpa 1 1 79432823472428150206591828283638793258896063175548433209232392931695569719148754;% |
| 48357 |
\XINT_tmpa 1 2 63095734448019324943436013662234386467294525718822872452772952883349494329768681;% |
| 48358 |
\XINT_tmpa 1 3 50118723362727228500155418688494576806047198983281926392969745588901125568883069;% |
| 48359 |
\XINT_tmpa 1 4 39810717055349725077025230508775204348767703729738044686528414806022485386945804;% |
| 48360 |
\XINT_tmpa 1 5 31622776601683793319988935444327185337195551393252168268575048527925944386392382;% |
| 48361 |
\XINT_tmpa 1 6 25118864315095801110850320677993273941585181007824754286798884209082432477235613;% |
| 48362 |
\XINT_tmpa 1 7 19952623149688796013524553967395355579862743154053460992299136670049309106980490;% |
| 48363 |
\XINT_tmpa 1 8 15848931924611134852021013733915070132694421338250390683162968123166568636684540;% |
| 48364 |
\XINT_tmpa 1 9 12589254117941672104239541063958006060936174094669310691079230195266476157825020;% |
| 48365 |
% 10^-0.0i |
| 48366 |
\XINT_tmpa 2 1 97723722095581068269707600696156123863427170069897801526639004097175507042084888;% |
| 48367 |
\XINT_tmpa 2 2 95499258602143594972395937950148401513087269708053320302465127242741421479104601;% |
| 48368 |
\XINT_tmpa 2 3 93325430079699104353209661168364840720225485199736026149257155811788093771138272;% |
| 48369 |
\XINT_tmpa 2 4 91201083935590974212095940791872333509323858755696109214760361851771695487999100;% |
| 48370 |
\XINT_tmpa 2 5 89125093813374552995310868107829696398587478293004836994794349506746891059190135;% |
| 48371 |
\XINT_tmpa 2 6 87096358995608063751082742520877054774747128501284704090761796673224328569285177;% |
| 48372 |
\XINT_tmpa 2 7 85113803820237646781712631859248682794521725442067093899553745086385146367436049;% |
| 48373 |
\XINT_tmpa 2 8 83176377110267100616669140273840405263880767161887438462740286611379995442629360;% |
| 48374 |
\XINT_tmpa 2 9 81283051616409924654127879773132980187568851100062454636602325121954484722491710;% |
| 48375 |
% 10^-0.00i |
| 48376 |
\XINT_tmpa 3 1 99770006382255331719442194285376231055211861394573154624878230890945476532432225;% |
| 48377 |
\XINT_tmpa 3 2 99540541735152696244806147089510943107144177264574823668081299845609359857038344;% |
| 48378 |
\XINT_tmpa 3 3 99311604842093377157642607688515474663519162181123336122073822476734517364853150;% |
| 48379 |
\XINT_tmpa 3 4 99083194489276757440828314388392035249938006860819409201135652190410238171119287;% |
| 48380 |
\XINT_tmpa 3 5 98855309465693884028524792978202683686410726723055209558576898759166522286083202;% |
| 48381 |
\XINT_tmpa 3 6 98627948563121047157261523093421290951784086730437722805070296627452491731402556;% |
| 48382 |
\XINT_tmpa 3 7 98401110576113374484101831088824192144756194053451911515003663381199842081528019;% |
| 48383 |
\XINT_tmpa 3 8 98174794301998439937928161622872240632362817134775142288598128693131032909278350;% |
| 48384 |
\XINT_tmpa 3 9 97948998540869887269961493687844910565420716785032030061251916654655049965062649;% |
| 48385 |
% 10^-0.000i |
| 48386 |
\XINT_tmpa 4 1 99976976799815658635141604638981297541396466984477711459083930684685186989697929;% |
| 48387 |
\XINT_tmpa 4 2 99953958900308784552845777251512089759003230012954649234748668826546533498169555;% |
| 48388 |
\XINT_tmpa 4 3 99930946300258992168693777702512591351888960684418033717545524043693899420866954;% |
| 48389 |
\XINT_tmpa 4 4 99907938998446176870082987427724649318531547584410414997787083472394558389284098;% |
| 48390 |
\XINT_tmpa 4 5 99884936993650514951538205746462968844845952521633937925370747725933629958238429;% |
| 48391 |
\XINT_tmpa 4 6 99861940284652463550037839584112909891259691850983307437097305856727153967481065;% |
| 48392 |
\XINT_tmpa 4 7 99838948870232760580354983175435314251655958968480344701699631967048474751069525;% |
| 48393 |
\XINT_tmpa 4 8 99815962749172424670413384320528274471550942114263604264788586703624513163664479;% |
| 48394 |
\XINT_tmpa 4 9 99792981920252755096658293766085025870392854106037465990011216356523334125368417;% |
| 48395 |
% 10^-0.0000i |
| 48396 |
\XINT_tmpa 5 1 99997697441416293040019992468837639003787989306240470048763511538639048400765328;% |
| 48397 |
\XINT_tmpa 5 2 99995394935850346394065999228750187791584034668237852053859761641089829514536011;% |
| 48398 |
\XINT_tmpa 5 3 99993092483300939297147020491645017932348508508297743745039515152378182676736684;% |
| 48399 |
\XINT_tmpa 5 4 99990790083766851012380885556584619169980753943113396677545915245611923361705686;% |
| 48400 |
\XINT_tmpa 5 5 99988487737246860830993605587529673614422529030613405900998412734419982883669223;% |
| 48401 |
\XINT_tmpa 5 6 99986185443739748072318726405984801565268578044798475766025647187221659622450651;% |
| 48402 |
\XINT_tmpa 5 7 99983883203244292083796681298546635825139453823571398432959235283529730820181019;% |
| 48403 |
\XINT_tmpa 5 8 99981581015759272240974143839353881367972777961073357987943600347058023396510672;% |
| 48404 |
\XINT_tmpa 5 9 99979278881283467947503380727439017235290006415950636109257677645557027950744160;% |
| 48405 |
% 10^-0.00000i |
| 48406 |
\XINT_tmpa 6 1 99999769741755795297487775997495948154386159348543852707438213487494386559762090;% |
| 48407 |
\XINT_tmpa 6 2 99999539484041779185217876175552674518572114763104546143049036309870762496098218;% |
| 48408 |
\XINT_tmpa 6 3 99999309226857950442387361668529812394860404492721699528707852590634886516924591;% |
| 48409 |
\XINT_tmpa 6 4 99999078970204307848196104610199226516866442484686906173860803560254163287393673;% |
| 48410 |
\XINT_tmpa 6 5 99998848714080850181846788127272455158309917012010320554498356105168896062430977;% |
| 48411 |
\XINT_tmpa 6 6 99998618458487576222544906332928167145404344730731751204389698696345970645201375;% |
| 48412 |
\XINT_tmpa 6 7 99998388203424484749498764320339633772810463403640242228131015918494067456365331;% |
| 48413 |
\XINT_tmpa 6 8 99998157948891574541919478156202215623119146605983303201215215949834619332550929;% |
| 48414 |
\XINT_tmpa 6 9 99997927694888844379020974874260864289829523807763942234420930258187873904191138;% |
| 48415 |
% log(10) |
| 48416 |
\edef\XINT_c_logten |
| 48417 |
{\XINTinFloat[\XINTdigitsormax+4] |
| 48418 |
{23025850929940456840179914546843642076011014886287729760333279009675726096773525[-79]}}% |
| 48419 |
\edef\XINT_c_oneoverlogten |
| 48420 |
{\XINTinFloat[\XINTdigitsormax+4] |
| 48421 |
{43429448190325182765112891891660508229439700580366656611445378316586464920887077[-80]}}% |
| 48422 |
\edef\XINT_c_oneoverlogten_xx |
| 48423 |
{\XINTinFloat[\XINTdigitsormax+14] |
| 48424 |
{43429448190325182765112891891660508229439700580366656611445378316586464920887077[-80]}}% |
| 48425 |
% \end{macrocode} |
| 48426 |
% \def\macro@font{\ttfamily} |
| 48427 |
% \subsection{April 2021: at last, \csh{XINTinFloatPowTen}, \csh{XINTinFloatExp}} |
| 48428 |
%\begin{lverb} |
| 48429 |
% Done April 2021. I have procrastinated (or did not have time to |
| 48430 |
% devote to this) at least 5 years, even more. |
| 48431 |
% |
| 48432 |
% Speed improvements will have to wait to long delayed refactoring of core |
| 48433 |
% floating point support which is still in the 2013 primitive state ! |
| 48434 |
% |
| 48435 |
% I did not try to optimize for say 16 digits, as I was more focused on |
| 48436 |
% reaching 60 digits in a reasonably efficient manner (trigonometric functions |
| 48437 |
% achieved this since 2019) in the same coding framework. Finally, up to 62 digits. |
| 48438 |
% |
| 48439 |
% The stored constants are log(10) at P+4 digits and the powers 10^0.d, |
| 48440 |
% 10^0.0d, etc, up to 10^0.00000d for d=1..9, as well as their inverses, at |
| 48441 |
% P+5 and P+10 digits. The constants were obtained from Maple at 80 digits. |
| 48442 |
% |
| 48443 |
% Initially I constructed the exponential series exp(h) as one big unique nested |
| 48444 |
% macro. It contained pre-rounded values of the 1/i! but would float-round h |
| 48445 |
% to various numbers of digits, with always the full initial h as input. |
| 48446 |
% |
| 48447 |
% After having experimented with the logarithm, I redid exp(h) = 1 + h(1 + |
| 48448 |
% h(1/2 + ...)) with many macros in order to have more readable code, and to |
| 48449 |
% dynamically cut-off more and more digits from h the deeper it is used. See |
| 48450 |
% the logarithm code for (perhaps) more comments. |
| 48451 |
% |
| 48452 |
% The thresholds have been obtained from considerations including an hmax |
| 48453 |
% (a bit more than 0.5 log(10) 10^-6). Here is the table: |
| 48454 |
% |
| 48455 |
%( - maximal value of P: 8, 15, 21, 28, 35, 42, 48, 55, 62 |
| 48456 |
%: - last included term: /1, /2, /6, /4!, /5!, /6!, /7!, /8!, /9! |
| 48457 |
%) |
| 48458 |
% |
| 48459 |
% Computations are done morally targeting P+4 fractional fixed point digits, |
| 48460 |
% with a stopping criteria at say about 5e(-P-4), which was used for the table |
| 48461 |
% above using only the worst case. As the used macros are a mix of exact |
| 48462 |
% operations and floating point reductions this is in practice a bit |
| 48463 |
% different. The h will be initially float rounded to P-1 digits. It is |
| 48464 |
% cut-off more and more, the deeper nested it is used. |
| 48465 |
% |
| 48466 |
% The code for this evaluation of 10^x is very poor with x very near zero: it |
| 48467 |
% does silly multiplication by 1, and uses more terms of exponential series |
| 48468 |
% than would then be necessary. |
| 48469 |
% |
| 48470 |
% For the computation of exp(x) as 10^(c*x) with c=log(10)^-1, we need more |
| 48471 |
% precise c the larger abs(x) is. For abs(x)<1 (or 2), the c with P+4 |
| 48472 |
% fractional digits is sufficient. But decimal exponents are more or less |
| 48473 |
% allowed to be near the TeX maximum 2^31-1, which means that abs(x) could be |
| 48474 |
% as big as 0.5e10, and we then need c with P+14 digits to cover that range. |
| 48475 |
% |
| 48476 |
% I am hesitating whether to first examine integral part of abs(x) and for |
| 48477 |
% example to use c with either P+4, P+9 or P+14 digits, and also take this |
| 48478 |
% opportunity to inject an error message if x is too big before TeX arithmetic |
| 48479 |
% overflow happens later on. For time being I will use overhead of |
| 48480 |
% oneoverlogten having ample enough digits... |
| 48481 |
% |
| 48482 |
% The exponent received as input is float rounded to P + 14 digits. In |
| 48483 |
% practice the input will be already a P-digits float. The motivation here is |
| 48484 |
% for low Digits situation: but this done so that for example with Digits=4, |
| 48485 |
% we want exp(12345) not to be evaluated as exp(12350) which would have no |
| 48486 |
% meaning at all. The +14 is because we have prepared 1/log(10) with that many |
| 48487 |
% significant digits. This conundrum is due to the inadequation of the world |
| 48488 |
% of floating point numbers with exp() and log(): clearly exp() goes from |
| 48489 |
% fixed point to floating point and log() goes from floating point to fixed |
| 48490 |
% point, and coercing them to work inside the sole floating point domain is |
| 48491 |
% not mathematically natural. Although admittedly it does create interesting |
| 48492 |
% mathematical questions! A similar situation applies to functions such as |
| 48493 |
% cos() and sin(), what sense is there in the expression cos(exp(50)) for |
| 48494 |
% example with 16 digits precision? My opinion is that it does not make ANY |
| 48495 |
% sense. Anyway, I shall obide. |
| 48496 |
% |
| 48497 |
% As \XINTinFloatS will not add unnecessarily trailing zeros, the |
| 48498 |
% \XINTdigits+14 is not really an enormous overhead for integer exponents, |
| 48499 |
% such as in the example above the 12345, or more realistically small integer |
| 48500 |
% exponents, and if the input is already float rounded to P digits, the |
| 48501 |
% overhead is also not enormous (float-rounding is costly when the input is a |
| 48502 |
% fraction). |
| 48503 |
% |
| 48504 |
% \XINTinfloatpowten will receive an input with at least P+14 and up to 2P+28 |
| 48505 |
% digits... fortunaltely with no fraction part and will start rounding it in |
| 48506 |
% the fixed point sense of its input to P+4 digits after decimal point, which |
| 48507 |
% is not enormously costly. |
| 48508 |
% |
| 48509 |
% Of course all these things pile up... |
| 48510 |
%\end{lverb} |
| 48511 |
% \begin{macrocode} |
| 48512 |
\def\XINTinFloatExp{\romannumeral0\XINTinfloatexp}% |
| 48513 |
\def\XINT_tmpa#1.{% |
| 48514 |
\def\XINTinfloatexp##1% |
| 48515 |
{% |
| 48516 |
\XINTinfloatpowten |
| 48517 |
{\xintMul{\XINT_c_oneoverlogten_xx}{\XINTinFloatS[#1]{##1}}}% |
| 48518 |
}% |
| 48519 |
}\expandafter\XINT_tmpa\the\numexpr\XINTdigitsormax+14.% |
| 48520 |
% \end{macrocode} |
| 48521 |
%\begin{lverb} |
| 48522 |
% Here is how the reduction to computations of an exp(h) via series is done. |
| 48523 |
% |
| 48524 |
% Starting from x, after initial argument normalization, it is fixed-point |
| 48525 |
% rounded to 6 fractional digits giving x'' = ±n.d_1...d_6 (which may be 0). |
| 48526 |
% |
| 48527 |
% I have to resist temptation using very low level routines here and wisely |
| 48528 |
% will employ the available user-level stuff. One computes then the |
| 48529 |
% difference x-x'' which gives some eta, and the h will be log(10).eta. The |
| 48530 |
% subtraction and multiplication are done exactly then float rounded to P-1 |
| 48531 |
% digits to obtain the h. |
| 48532 |
% |
| 48533 |
% Then exp(h) is computed. And to finish it is multiplied with the stored |
| 48534 |
% 10^±0.d_1, 10^±0.0d_2, etc...., constants and its decimal exponent is |
| 48535 |
% increased by ±n. These operations are done at P+5 floating point digits. The |
| 48536 |
% final result is then float-rounded to the target P digits. |
| 48537 |
% |
| 48538 |
% Currently I may use nested macros for some operations but will perhaps |
| 48539 |
% revise in future (it makes tracing very complicated if one does not have |
| 48540 |
% intermediate macros). The exponential series itself was initially only one |
| 48541 |
% single macro, but as commented above I have now modified it. |
| 48542 |
%\end{lverb} |
| 48543 |
% \begin{macrocode} |
| 48544 |
\def\XINTinFloatPowTen{\romannumeral0\XINTinfloatpowten}% |
| 48545 |
\def\XINT_tmpa#1.{% |
| 48546 |
\def\XINTinfloatpowten##1% |
| 48547 |
{% |
| 48548 |
\expandafter\XINT_powten_fork |
| 48549 |
\romannumeral0\xintiround{#1}{##1}[-#1]% |
| 48550 |
}% |
| 48551 |
}\expandafter\XINT_tmpa\the\numexpr\XINTdigitsormax+4.% |
| 48552 |
\def\XINT_powten_fork#1% |
| 48553 |
{% |
| 48554 |
\xint_UDzerominusfork |
| 48555 |
#1-\XINT_powten_zero |
| 48556 |
0#1\XINT_powten_neg |
| 48557 |
0-\XINT_powten_pos |
| 48558 |
\krof #1% |
| 48559 |
}% |
| 48560 |
\def\XINT_powten_zero #1[#2]{ 1[0]}% |
| 48561 |
% \end{macrocode} |
| 48562 |
%\begin{lverb} |
| 48563 |
% This rounding may produce 0.000000 but will always have 6 exactly |
| 48564 |
% fractional digits, because the special case of a zero input was filtered out |
| 48565 |
% preventively. |
| 48566 |
%\end{lverb} |
| 48567 |
% \begin{macrocode} |
| 48568 |
\def\XINT_powten_pos#1[#2]% |
| 48569 |
{% |
| 48570 |
\expandafter\XINT_powten_pos_a\romannumeral0\xintround{6}{#1[#2]}#1[#2]% |
| 48571 |
}% |
| 48572 |
\def\XINT_tmpa #1.#2.#3.{% |
| 48573 |
\def\XINT_powten_pos_a ##1.##2##3##4##5##6##7##8[##9]% |
| 48574 |
{% |
| 48575 |
\expandafter\XINT_infloate |
| 48576 |
\romannumeral0\XINTinfloat[#3]{% |
| 48577 |
\xintMul{\csname XINT_c_1_##2\endcsname}{% |
| 48578 |
\XINTinFloat[#1]{% |
| 48579 |
\xintMul{\csname XINT_c_2_##3\endcsname}{% |
| 48580 |
\XINTinFloat[#1]{% |
| 48581 |
\xintMul{\csname XINT_c_3_##4\endcsname}{% |
| 48582 |
\XINTinFloat[#1]{% |
| 48583 |
\xintMul{\csname XINT_c_4_##5\endcsname}{% |
| 48584 |
\XINTinFloat[#1]{% |
| 48585 |
\xintMul{\csname XINT_c_5_##6\endcsname}{% |
| 48586 |
\XINTinFloat[#1]{% |
| 48587 |
\xintMul{\csname XINT_c_6_##7\endcsname}{% |
| 48588 |
\xintAdd{1[0]}{% |
| 48589 |
\expandafter\XINT_Exp_series_a_ii |
| 48590 |
\romannumeral0\XINTinfloat[#2]{% |
| 48591 |
\xintMul{\XINT_c_logten}% |
| 48592 |
{\xintAdd{-##1.##2##3##4##5##6##7}{##8[##9]}}% |
| 48593 |
}% |
| 48594 |
\xint: |
| 48595 |
}% |
| 48596 |
}}}}}}}}}}}}{##1}% |
| 48597 |
}}\expandafter\XINT_tmpa |
| 48598 |
\the\numexpr\XINTdigitsormax+5\expandafter.% |
| 48599 |
\the\numexpr\XINTdigitsormax-1\expandafter.% |
| 48600 |
\the\numexpr\XINTdigitsormax.% |
| 48601 |
% \end{macrocode} |
| 48602 |
%\begin{lverb} |
| 48603 |
% This rounding may produce -0.000000 but will always have 6 exactly |
| 48604 |
% fractional digits and a leading minus sign. |
| 48605 |
%\end{lverb} |
| 48606 |
% \begin{macrocode} |
| 48607 |
\def\XINT_powten_neg#1[#2]% |
| 48608 |
{% |
| 48609 |
\expandafter\XINT_powten_neg_a\romannumeral0\xintround{6}{#1[#2]}#1[#2]% |
| 48610 |
}% |
| 48611 |
\def\XINT_tmpa #1.#2.#3.{% |
| 48612 |
\def\XINT_powten_neg_a -##1.##2##3##4##5##6##7##8[##9]% |
| 48613 |
{% |
| 48614 |
\expandafter\XINT_infloate |
| 48615 |
\romannumeral0\XINTinfloat[#3]{% |
| 48616 |
\xintMul{\csname XINT_c_1_##2_inv\endcsname}{% |
| 48617 |
\XINTinFloat[#1]{% |
| 48618 |
\xintMul{\csname XINT_c_2_##3_inv\endcsname}{% |
| 48619 |
\XINTinFloat[#1]{% |
| 48620 |
\xintMul{\csname XINT_c_3_##4_inv\endcsname}{% |
| 48621 |
\XINTinFloat[#1]{% |
| 48622 |
\xintMul{\csname XINT_c_4_##5_inv\endcsname}{% |
| 48623 |
\XINTinFloat[#1]{% |
| 48624 |
\xintMul{\csname XINT_c_5_##6_inv\endcsname}{% |
| 48625 |
\XINTinFloat[#1]{% |
| 48626 |
\xintMul{\csname XINT_c_6_##7_inv\endcsname}{% |
| 48627 |
\xintAdd{1[0]}{% |
| 48628 |
\expandafter\XINT_Exp_series_a_ii |
| 48629 |
\romannumeral0\XINTinfloat[#2]{% |
| 48630 |
\xintMul{\XINT_c_logten}% |
| 48631 |
{\xintAdd{##1.##2##3##4##5##6##7}{##8[##9]}}% |
| 48632 |
}% |
| 48633 |
\xint: |
| 48634 |
}% |
| 48635 |
}}}}}}}}}}}}{-##1}% |
| 48636 |
}}\expandafter\XINT_tmpa |
| 48637 |
\the\numexpr\XINTdigitsormax+5\expandafter.% |
| 48638 |
\the\numexpr\XINTdigitsormax-1\expandafter.% |
| 48639 |
\the\numexpr\XINTdigitsormax.% |
| 48640 |
% \end{macrocode} |
| 48641 |
% \subsubsection{Exponential series} |
| 48642 |
%\begin{lverb} |
| 48643 |
% Or rather here h(1 + h(1/2 + h (1/6 + ....))). Upto at most h^9/9! |
| 48644 |
% term. |
| 48645 |
% |
| 48646 |
% The used initial h has been float rounded to P-1 digits. |
| 48647 |
%\end{lverb} |
| 48648 |
% \begin{macrocode} |
| 48649 |
\def\XINT_tmpa#1.#2.{% |
| 48650 |
\def\XINT_Exp_series_a_ii##1\xint: |
| 48651 |
{% |
| 48652 |
\expandafter\XINT_Exp_series_b |
| 48653 |
\romannumeral0\XINTinfloatS[#1]{##1}\xint:##1\xint: |
| 48654 |
}% |
| 48655 |
\def\XINT_Exp_series_b##1[##2]\xint: |
| 48656 |
{% |
| 48657 |
\expandafter\XINT_Exp_series_c_ |
| 48658 |
\romannumeral0\xintadd{1}{\xintHalf{##10}[##2-1]}\xint: |
| 48659 |
}% |
| 48660 |
\def\XINT_Exp_series_c_##1\xint:##2\xint: |
| 48661 |
{% |
| 48662 |
\XINTinFloat[#2]{\xintMul{##1}{##2}}% |
| 48663 |
}% |
| 48664 |
}% |
| 48665 |
\expandafter\XINT_tmpa |
| 48666 |
\the\numexpr\XINTdigitsormax-6\expandafter.% |
| 48667 |
\the\numexpr\XINTdigitsormax-1.% |
| 48668 |
\ifnum\XINTdigits>15 |
| 48669 |
\def\XINT_tmpa#1.#2.#3.#4.{% |
| 48670 |
\def\XINT_Exp_series_a_ii##1\xint: |
| 48671 |
{% |
| 48672 |
\expandafter\XINT_Exp_series_a_iii |
| 48673 |
\romannumeral0\XINTinfloatS[#2]{##1}\xint:##1\xint: |
| 48674 |
}% |
| 48675 |
\def\XINT_Exp_series_a_iii##1\xint: |
| 48676 |
{% |
| 48677 |
\expandafter\XINT_Exp_series_b |
| 48678 |
\romannumeral0\XINTinfloatS[#1]{##1}\xint:##1\xint: |
| 48679 |
}% |
| 48680 |
\def\XINT_Exp_series_b##1[##2]\xint: |
| 48681 |
{% |
| 48682 |
\expandafter\XINT_Exp_series_c_i |
| 48683 |
\romannumeral0\xintadd{#3}{##1/6[##2]}\xint: |
| 48684 |
}% |
| 48685 |
\def\XINT_Exp_series_c_i##1\xint:##2\xint: |
| 48686 |
{% |
| 48687 |
\expandafter\XINT_Exp_series_c_ |
| 48688 |
\romannumeral0\xintadd{#4}{\XINTinFloat[#2]{\xintMul{##1}{##2}}}\xint: |
| 48689 |
}% |
| 48690 |
}\expandafter\XINT_tmpa |
| 48691 |
\the\numexpr\XINTdigitsormax-13\expandafter.% |
| 48692 |
\the\numexpr\XINTdigitsormax-6.% |
| 48693 |
{5[-1]}.% |
| 48694 |
{1[0]}.% |
| 48695 |
\fi |
| 48696 |
\ifnum\XINTdigits>21 |
| 48697 |
\def\XINT_tmpa#1.#2.#3.#4.{% |
| 48698 |
\def\XINT_Exp_series_a_iii##1\xint: |
| 48699 |
{% |
| 48700 |
\expandafter\XINT_Exp_series_a_iv |
| 48701 |
\romannumeral0\XINTinfloatS[#2]{##1}\xint:##1\xint: |
| 48702 |
}% |
| 48703 |
\def\XINT_Exp_series_a_iv##1\xint: |
| 48704 |
{% |
| 48705 |
\expandafter\XINT_Exp_series_b |
| 48706 |
\romannumeral0\XINTinfloatS[#1]{##1}\xint:##1\xint: |
| 48707 |
}% |
| 48708 |
\def\XINT_Exp_series_b##1[##2]\xint: |
| 48709 |
{% |
| 48710 |
\expandafter\XINT_Exp_series_c_ii |
| 48711 |
\romannumeral0\xintadd{#3}{##1/24[##2]}\xint: |
| 48712 |
}% |
| 48713 |
\def\XINT_Exp_series_c_ii##1\xint:##2\xint: |
| 48714 |
{% |
| 48715 |
\expandafter\XINT_Exp_series_c_i |
| 48716 |
\romannumeral0\xintadd{#4}{\XINTinFloat[#2]{\xintMul{##1}{##2}}}\xint: |
| 48717 |
}% |
| 48718 |
}\expandafter\XINT_tmpa |
| 48719 |
\the\numexpr\XINTdigitsormax-19\expandafter.% |
| 48720 |
\the\numexpr\XINTdigitsormax-13\expandafter.% |
| 48721 |
\romannumeral0\XINTinfloat[\XINTdigitsormax-13]{1/6[0]}.% |
| 48722 |
{5[-1]}.% |
| 48723 |
\fi |
| 48724 |
\ifnum\XINTdigits>28 |
| 48725 |
\def\XINT_tmpa #1 #2 #3 #4 #5 #6 #7 % |
| 48726 |
{% |
| 48727 |
\def\XINT_tmpb ##1##2##3##4% |
| 48728 |
{% |
| 48729 |
\def\XINT_tmpc####1.####2.####3.####4.% |
| 48730 |
{% |
| 48731 |
\def##2########1\xint: |
| 48732 |
{% |
| 48733 |
\expandafter##1% |
| 48734 |
\romannumeral0\XINTinfloatS[####2]{########1}\xint:########1\xint: |
| 48735 |
}% |
| 48736 |
\def##1########1\xint: |
| 48737 |
{% |
| 48738 |
\expandafter\XINT_Exp_series_b |
| 48739 |
\romannumeral0\XINTinfloatS[####1]{########1}\xint:########1\xint: |
| 48740 |
}% |
| 48741 |
\def\XINT_Exp_series_b########1[########2]\xint: |
| 48742 |
{% |
| 48743 |
\expandafter##3% |
| 48744 |
\romannumeral0\xintadd{####3}{########1/#5[########2]}\xint: |
| 48745 |
}% |
| 48746 |
\def##3########1\xint:########2\xint: |
| 48747 |
{% |
| 48748 |
\expandafter##4% |
| 48749 |
\romannumeral0\xintadd{####4}% |
| 48750 |
{\XINTinFloat[####2]{\xintMul{########1}{########2}}}\xint: |
| 48751 |
}% |
| 48752 |
}% |
| 48753 |
}% |
| 48754 |
\expandafter\XINT_tmpb |
| 48755 |
\csname XINT_Exp_series_a_\romannumeral\numexpr#1\expandafter\endcsname |
| 48756 |
\csname XINT_Exp_series_a_\romannumeral\numexpr#1-1\expandafter\endcsname |
| 48757 |
\csname XINT_Exp_series_c_\romannumeral\numexpr#1-2\expandafter\endcsname |
| 48758 |
\csname XINT_Exp_series_c_\romannumeral\numexpr#1-3\endcsname |
| 48759 |
\expandafter\XINT_tmpc |
| 48760 |
\the\numexpr\XINTdigitsormax-#2\expandafter.% |
| 48761 |
\the\numexpr\XINTdigitsormax-#3\expandafter.\expanded{% |
| 48762 |
\XINTinFloat[\XINTdigitsormax-#3]{1/#6[0]}.% |
| 48763 |
\XINTinFloat[\XINTdigitsormax-#4]{1/#7[0]}.% |
| 48764 |
}% |
| 48765 |
}% |
| 48766 |
\XINT_tmpa 5 26 19 13 120 24 6 %<-- keep space |
| 48767 |
\ifnum\XINTdigits>35 \XINT_tmpa 6 33 26 19 720 120 24 \fi |
| 48768 |
\ifnum\XINTdigits>42 \XINT_tmpa 7 40 33 26 5040 720 120 \fi |
| 48769 |
\ifnum\XINTdigits>48 \XINT_tmpa 8 46 40 33 40320 5040 720 \fi |
| 48770 |
\ifnum\XINTdigits>55 \XINT_tmpa 9 53 46 40 362880 40320 5040 \fi |
| 48771 |
\fi |
| 48772 |
% \end{macrocode} |
| 48773 |
% \subsection{April 2021: at last \csh{XINTinFloagLogTen}, \csh{XINTinFloatLog}} |
| 48774 |
%\begin{lverb} |
| 48775 |
% Attention that this is not supposed to be used with \XINTdigits at |
| 48776 |
% 8 or less, it will crash if that is the case. The log10() and log() |
| 48777 |
% functions in case \XINTdigits is at most 8 are mapped to \PoormanLogBaseTen |
| 48778 |
% respectively \PoormanLog macros. |
| 48779 |
% |
| 48780 |
% In the explications here I use the function names rather than the macro |
| 48781 |
% names. |
| 48782 |
% |
| 48783 |
% Both log(x) and log10(x) are on top of an underlying macro which will |
| 48784 |
% produce z and h such that x is about 10^z e^h (with h being small is |
| 48785 |
% obtained via a log series). Then log(x) computes log(10)z+h whereas log10(x) |
| 48786 |
% computes as z+h/log(10). |
| 48787 |
% |
| 48788 |
% There will be three branches [NO FINALLY ONLY TWO BRANCHES SINCE 1.4f] |
| 48789 |
% according to situation of x relative to 1. Let y be the math value log10(x) |
| 48790 |
% that we want to approximate to target precision P digits. P is assumed at |
| 48791 |
% least 9. |
| 48792 |
% |
| 48793 |
% I will describe the algorithm roughly, but skip its underlying support |
| 48794 |
% analysis; at some point I mention "fixed point calculations", but in |
| 48795 |
% practice it is not done exactly that way, but describing it would be |
| 48796 |
% complicated so look at the code which is very readable (by the author, at |
| 48797 |
% the present time). |
| 48798 |
% |
| 48799 |
% First we compute z = ±n.d_1d_2...d_6 as the rounded to 6 fractional digits |
| 48800 |
% approximation of y=log10(x) obtained by first using the poormanlog macros on x |
| 48801 |
% (float rounded to 9 digits) then rounding as above. |
| 48802 |
% |
| 48803 |
% Warning: this description is not in sync with the code, now the case where |
| 48804 |
% d_1d_2...d_6 is 000000 is filtered out and one jumps directly either to case |
| 48805 |
% I if n≠0 or to case III if n=0. The case when rounding produces a z equal |
| 48806 |
% to zero is also handled especially. |
| 48807 |
% |
| 48808 |
% WARNING: at 1.4f, the CASE I was REMOVED. Everything is handled as CASE II |
| 48809 |
% or exceptionally case III. Indeed this removal was observed to simply cost |
| 48810 |
% about 10$% extra time at D=16 digits, which was deemed an acceptable cost. |
| 48811 |
% The cost is certainly higher at D=9 but also relatively lower at high |
| 48812 |
% D's. It means that logarithms are always computed with 9, not 4, safety |
| 48813 |
% **fractional** digits, and this allows to compute powers accurately with |
| 48814 |
% exponents say up to 1e7, degradation starting to show at 1e8 and for sure at |
| 48815 |
% 1e9. However for integer and half-integer exponents the old routine |
| 48816 |
% \xintFloatPower will still be used, and perhaps it will need some increased |
| 48817 |
% precision update as the documented 0.52ulp error bound is higher than our |
| 48818 |
% more stringent standards of 2021. |
| 48819 |
% |
| 48820 |
% CASE I: [removed at 1.4f!] |
| 48821 |
% either n is NOT zero or d_1d_2....d_6 is at least 100001. Then we |
| 48822 |
% compute X = 10^(-z)*x which is near 1, by using the table of powers of |
| 48823 |
% 10, using P+5 digits significands. Then we compute (exactly) eta = X-1, |
| 48824 |
% (which is in absolute value less than 0.0000012) |
| 48825 |
% and obtain |
| 48826 |
% y as z + log(10)^(-1) times log(1+eta) |
| 48827 |
% where log(1+eta) = eta - eta^2/2 + eta^3/3- ... is "computed with |
| 48828 |
% P+4 fractional fixed point digits" [1]_ according to the following table: |
| 48829 |
% |
| 48830 |
%( - maximal value of P: 9, 15, 21, 27, 33, 39, 45, 51, 57, 63 |
| 48831 |
%: - last included term: /1, /2, /3, /4, /5, /6, /7, /8, /9, /10 |
| 48832 |
%) |
| 48833 |
% |
| 48834 |
% .. [1] this "P+4" includes leading fractional zeroes so in practice it will |
| 48835 |
% rather be done as eta(1 - eta(1/2 + eta(1/3-...))), and the inner sums will |
| 48836 |
% be done in various precisions, the top level (external) eta probably at P-1 |
| 48837 |
% digits, the first inner eta at P-7 digits, the next at P-13, something in |
| 48838 |
% this style. The heuristics is simple: at P=9 we don't need the first inner |
| 48839 |
% eta, so let's use there P-9 or rather P-7 digits by security. Similarly at |
| 48840 |
% P=3 we would not need at all the eta, so let's use the top level one rounded |
| 48841 |
% at P-3+2 = P-1 digits. And there is a shift by 6 less digits at each inner |
| 48842 |
% level. RÉFLÉCHIR SI C'EST PAS PLUTÔT P-2 ICI, suffisant au regard de la |
| 48843 |
% précision par ailleurs pour la réduction près de 1. |
| 48844 |
% |
| 48845 |
% The sequence of maximal P's is simply an arithmetic progression. |
| 48846 |
% |
| 48847 |
% The addition of z will trigger the final rounding to P digits. |
| 48848 |
% The inverse of log(10) is precomputed with P+4 digits. |
| 48849 |
% |
| 48850 |
% This case I essentially handles x such as max(x,1/x)>10^0.1=1.2589... |
| 48851 |
% |
| 48852 |
% CASE II: n is zero and d_1d_2....d_6 is not zero. We operate as in CASE I, |
| 48853 |
% up to the following differences: |
| 48854 |
%( - the table of fractional powers of 10 is used with P+10 significands. |
| 48855 |
%: - the X is also computed with P+10 digits, i.e. eta = X-1 (which obeys& |
| 48856 |
% the given estimate) is estimated with P+9 [2]_ fractional fixed points digits& |
| 48857 |
% and the log series will be evaluated in this sense. |
| 48858 |
%: - the constant log(10)^(-1) is still used with only P+4 digits |
| 48859 |
%) |
| 48860 |
% |
| 48861 |
% The log series is terminated according to the following table: |
| 48862 |
%( - maximal value of P: 4, 10, 16, 22, 28, 34, 40, 46, 52, 58, 64 |
| 48863 |
%: - last included term: /1, /2, /3, /4, /5, /6, /7, /8, /9, /10 |
| 48864 |
%) |
| 48865 |
% |
| 48866 |
% Again the P's are in arithmetic progression, the same as before shifted by |
| 48867 |
% 5. |
| 48868 |
% |
| 48869 |
% .. [2] same remark as above. The top level eta in eta(1 - eta(1/2 - |
| 48870 |
% eta(...))) will use P+4 significant digits, but the first inner eta will be |
| 48871 |
% used with only P-2 digits, the next inner one with P-8 digits etc... |
| 48872 |
% |
| 48873 |
% This case II handles the x which are near 1, but not as close as 10^±0.000001. |
| 48874 |
% |
| 48875 |
% CASE III: z=0. In this case X = x = 1+eta and we use the log series in |
| 48876 |
% this sense : log(10)^(-1)*eta*(1 - eta/2 + eta^2/3-....) |
| 48877 |
% where again log(10)^(-1) has been precomputed with P+4 digits |
| 48878 |
% and morally the series uses P+4 fractional digits (P+3 would probably |
| 48879 |
% be enough for the precision I want, need to check my notes) |
| 48880 |
% and the thresholds table is: |
| 48881 |
%( - maximal value of P: 3, 9, 15, 21, 27, 33, 39, 45, 51, 57, 63 |
| 48882 |
%: - last included term: /1, /2, /3, /4, /5, /6, /7, /8, /9, /10, /11 |
| 48883 |
%) |
| 48884 |
% |
| 48885 |
% This is same progression but shifted by one. |
| 48886 |
% |
| 48887 |
% To summarize some relevant aspects: |
| 48888 |
%( - this algorithm uses only log(10)^(-1) as precomputed logarithm |
| 48889 |
%: - in particular the logarithms of small integers 2, 3, 5,... are& |
| 48890 |
% not pre-computed. Added note: I have now tested at 16, 32, 48 and 62& |
| 48891 |
% digits that all of the log10(n), for n = 1..1000, are computed with& |
| 48892 |
% correct rounding. In fact, generally speaking, random testing of a& |
| 48893 |
% about 20000 inputs has failed to reveal a single non-correct& |
| 48894 |
% rounding. Naturally, randomly testing is not the way to corner& |
| 48895 |
% the software into its weak points... |
| 48896 |
%: - it uses two tables of fractional powers of ten: one with P+5 digits and& |
| 48897 |
% another one with extended precision at P+10 digits. |
| 48898 |
%: - it needs three distinct implementations of the log series. |
| 48899 |
%: - it does not use the well-known trick reducing to using only odd powers& |
| 48900 |
% in the log series (somehow I have come to dread divisions, even though& |
| 48901 |
% here as is well-known it could be replaced with some product, my& |
| 48902 |
% impression was that what is gained on one side is lost on the other,& |
| 48903 |
% for the range of P I am targeting, i.e. P up to about 60.) |
| 48904 |
%: - all of this is experimental (in particular the previous item was not& |
| 48905 |
% done perhaps out of sheer laziness) |
| 48906 |
%) |
| 48907 |
% |
| 48908 |
% Absolutely no error check is done whether the input x is really positive. |
| 48909 |
% As seen above the maximal target precision is 63 (not 64). |
| 48910 |
% |
| 48911 |
% Update for 1.4f: when the logarithm is computed via case I, i.e. basically |
| 48912 |
% always except roughly for 0.8<a<1.26, its fractional part has only about 4 |
| 48913 |
% safety digits. This is barely enough for a^b with b near 1000 and certainly |
| 48914 |
% not enough for a^b with b of the order 10000. |
| 48915 |
% |
| 48916 |
% I hesitated with the option to always handle b as N+h with N integer for |
| 48917 |
% which we can use old \xintFloatPower (which perhaps I will have to update to |
| 48918 |
% ensure better than the 0.52ulp it mentions in its documentation). But in |
| 48919 |
% the end, I decided to simply add a variant where case I is handled as case |
| 48920 |
% II, i.e. with 9 not 4 safety fractional digits for the logarithm. This |
| 48921 |
% variant will be the one used by the power function for fractional exponents |
| 48922 |
% (non integer, non half-integer). |
| 48923 |
% |
| 48924 |
%\end{lverb} |
| 48925 |
% \begin{macrocode} |
| 48926 |
\def\XINT_tmpa#1.{% |
| 48927 |
\def\XINTinFloatLog{\romannumeral0\XINTinfloatlog}% |
| 48928 |
\def\XINTinfloatlog |
| 48929 |
{% |
| 48930 |
\expandafter\XINT_log_out |
| 48931 |
\romannumeral0\expandafter\XINT_logtenxdg_a |
| 48932 |
\romannumeral0\XINTinfloat[#1]%{##1} |
| 48933 |
}% |
| 48934 |
\def\XINT_log_out ##1\xint:##2\xint: |
| 48935 |
{% |
| 48936 |
\XINTinfloat[#1]% |
| 48937 |
{\xintAdd{\xintMul{\XINT_c_logten}{##1}}{##2}}% |
| 48938 |
}% |
| 48939 |
\def\XINTinFloatLogTen{\romannumeral0\XINTinfloatlogten}% |
| 48940 |
\def\XINTinfloatlogten |
| 48941 |
{% |
| 48942 |
\expandafter\XINT_logten_out |
| 48943 |
\romannumeral0\expandafter\XINT_logtenxdg_a |
| 48944 |
\romannumeral0\XINTinfloat[#1]%{##1} |
| 48945 |
}% |
| 48946 |
\def\XINT_logten_out ##1\xint:##2\xint: |
| 48947 |
{% |
| 48948 |
\XINTinfloat[#1]% |
| 48949 |
{\xintAdd{##1}{\xintMul{\XINT_c_oneoverlogten}{##2}}}% |
| 48950 |
}% |
| 48951 |
}\expandafter\XINT_tmpa\the\numexpr\XINTdigitsormax.% |
| 48952 |
\def\XINTinFloatLogTen_xdgout%#1[#2] |
| 48953 |
{% |
| 48954 |
\romannumeral0\expandafter\XINT_logten_xdgout\romannumeral0\XINT_logtenxdg_a |
| 48955 |
}% |
| 48956 |
\def\XINT_logten_xdgout #1\xint:#2\xint: |
| 48957 |
{% |
| 48958 |
\xintadd{#1}{\xintMul{\XINT_c_oneoverlogten_xx}{#2}}% |
| 48959 |
}% |
| 48960 |
% \end{macrocode} |
| 48961 |
%\begin{lverb} |
| 48962 |
% No check is done whether input is negative or vanishes. We apply |
| 48963 |
% \XINTinfloat[9] which if input is not zero always produces 9 digits (and |
| 48964 |
% perhaps a minus sign) the first digit is non-zero. This is the expected |
| 48965 |
% input to \numexpr\PML@<digits><dot>.\relax |
| 48966 |
% |
| 48967 |
% The variants xdg_a, xdg_b, xdg_c, xdg_d were added at 1.4f to always go via |
| 48968 |
% II or III, ensuring more fractional digits to the logarithm for accuracy of |
| 48969 |
% fractional powers with big exponents. "Old" 1.4e routines were removed. |
| 48970 |
%\end{lverb} |
| 48971 |
% \begin{macrocode} |
| 48972 |
\def\XINT_logtenxdg_a#1[#2]% |
| 48973 |
{% |
| 48974 |
\expandafter\XINT_logtenxdg_b |
| 48975 |
\romannumeral0\XINTinfloat[9]{#1[#2]}#1[#2]% |
| 48976 |
}% |
| 48977 |
\def\XINT_logtenxdg_b#1[#2]% |
| 48978 |
{% |
| 48979 |
\expandafter\XINT_logtenxdg_c |
| 48980 |
\romannumeral0\xintround{6}% |
| 48981 |
{\xintiiAdd{\xintDSx{-9}{\the\numexpr#2+8\relax}}% |
| 48982 |
{\the\numexpr\PML@#1.\relax}% |
| 48983 |
[-9]}% |
| 48984 |
\xint: |
| 48985 |
}% |
| 48986 |
% \end{macrocode} |
| 48987 |
%\begin{lverb} |
| 48988 |
% If we were either in 100000000[0] or 999999999[-1] for the #1[#2] |
| 48989 |
% \XINT_logten_b input, and only in those cases, the \xintRound{6} produced |
| 48990 |
% "0". We are very near 1 and will treat this as case III, but this is |
| 48991 |
% sub-optimal. |
| 48992 |
%\end{lverb} |
| 48993 |
% \begin{macrocode} |
| 48994 |
\def\XINT_logtenxdg_c #1#2% |
| 48995 |
{% |
| 48996 |
\xint_gob_til_xint:#2\XINT_logten_IV\xint: |
| 48997 |
\XINT_logtenxdg_d #1#2% |
| 48998 |
}% |
| 48999 |
\def\XINT_logten_IV\xint:\XINT_logtenxdg_d0{\XINT_logten_f_III}% |
| 49000 |
% \end{macrocode} |
| 49001 |
%\begin{lverb} |
| 49002 |
% Here we are certain that \xintRound{6} produced a decimal point and |
| 49003 |
% 6 fractional digit tokens #2, but they can be zeros and also -0.000000 is possible. |
| 49004 |
% |
| 49005 |
% If #1 vanishes and #2>100000 we are in case I. |
| 49006 |
% |
| 49007 |
% If #1 vanishes and 100000>=#2>0 we are in case II. |
| 49008 |
% |
| 49009 |
% If #1 and #2 vanish we are in case III. |
| 49010 |
% |
| 49011 |
% If #1 does not vanish we are in case I with a direct quicker access if #2 vanishes. |
| 49012 |
% |
| 49013 |
% Attention to the sign of #1, it is checked later on. |
| 49014 |
% |
| 49015 |
% At 1.4f, we handle the case I with as many digits as case II (and exceptionnally case III). |
| 49016 |
% |
| 49017 |
%\end{lverb} |
| 49018 |
% \begin{macrocode} |
| 49019 |
\def\XINT_logtenxdg_d #1.#2\xint: |
| 49020 |
{% |
| 49021 |
\ifcase |
| 49022 |
\ifnum#1=\xint_c_ |
| 49023 |
\ifnum #2=\xint_c_ \xint_c_iii\else \xint_c_ii\fi |
| 49024 |
\else |
| 49025 |
\ifnum#2>\xint_c_ \xint_c_ii\else \xint_c_\fi |
| 49026 |
\fi |
| 49027 |
\expandafter\XINT_logten_f_Isp |
| 49028 |
\or% never |
| 49029 |
\or\expandafter\XINT_logten_f_IorII |
| 49030 |
\else\expandafter\XINT_logten_f_III |
| 49031 |
\fi |
| 49032 |
#1.#2\xint: |
| 49033 |
}% |
| 49034 |
\def\XINT_logten_f_IorII#1% |
| 49035 |
{% |
| 49036 |
\xint_UDsignfork |
| 49037 |
#1\XINT_logten_f_IorII_neg |
| 49038 |
-\XINT_logten_f_IorII_pos |
| 49039 |
\krof #1% |
| 49040 |
}% |
| 49041 |
% \end{macrocode} |
| 49042 |
%\begin{lverb} |
| 49043 |
% We are here only with a non-zero ##1, so no risk of a -0[0] which |
| 49044 |
% would be illegal usage of A[N] raw format. A negative ##1 is no trouble in ##3-##1. |
| 49045 |
%\end{lverb} |
| 49046 |
% \begin{macrocode} |
| 49047 |
\def\XINT_tmpa#1.{% |
| 49048 |
\def\XINT_logten_f_Isp##1.000000\xint:##2[##3]% |
| 49049 |
{% |
| 49050 |
{##1[0]}\xint: |
| 49051 |
{\expandafter\XINT_LogTen_serII_a_ii |
| 49052 |
\romannumeral0\XINTinfloatS[#1]{\xintAdd{##2[##3-##1]}{-1[0]}}% |
| 49053 |
\xint: |
| 49054 |
}\xint: |
| 49055 |
}% |
| 49056 |
}\expandafter\XINT_tmpa\the\numexpr\XINTdigitsormax.% |
| 49057 |
\def\XINT_tmpa#1.{% |
| 49058 |
\def\XINT_logten_f_III##1\xint:##2[##3]% |
| 49059 |
{% |
| 49060 |
{0[0]}\xint: |
| 49061 |
{\expandafter\XINT_LogTen_serIII_a_ii |
| 49062 |
\romannumeral0\XINTinfloatS[#1]{\xintAdd{##2[##3]}{-1[0]}}% |
| 49063 |
\xint: |
| 49064 |
}\xint: |
| 49065 |
}}\expandafter\XINT_tmpa\the\numexpr\XINTdigitsormax+4.% |
| 49066 |
\def\XINT_tmpa#1.#2.{% |
| 49067 |
\def\XINT_logten_f_IorII_pos##1.##2##3##4##5##6##7\xint:##8[##9]% |
| 49068 |
{% |
| 49069 |
{\the\numexpr##1##2##3##4##5##6##7[-6]}\xint: |
| 49070 |
{\expandafter\XINT_LogTen_serII_a_ii |
| 49071 |
\romannumeral0\XINTinfloat[#2]% |
| 49072 |
{\xintAdd{-1[0]}% |
| 49073 |
{\xintMul{\csname XINT_c_1_##2_inv_x\endcsname}{% |
| 49074 |
\XINTinFloat[#1]{% |
| 49075 |
\xintMul{\csname XINT_c_2_##3_inv_x\endcsname}{% |
| 49076 |
\XINTinFloat[#1]{% |
| 49077 |
\xintMul{\csname XINT_c_3_##4_inv_x\endcsname}{% |
| 49078 |
\XINTinFloat[#1]{% |
| 49079 |
\xintMul{\csname XINT_c_4_##5_inv_x\endcsname}{% |
| 49080 |
\XINTinFloat[#1]{% |
| 49081 |
\xintMul{\csname XINT_c_5_##6_inv_x\endcsname}{% |
| 49082 |
\XINTinFloat[#1]{% |
| 49083 |
\xintMul{\csname XINT_c_6_##7_inv_x\endcsname} |
| 49084 |
{##8[##9-##1]}% |
| 49085 |
}}}}}}}}}}% |
| 49086 |
}% |
| 49087 |
}\xint: |
| 49088 |
}\xint: |
| 49089 |
}% |
| 49090 |
\def\XINT_logten_f_IorII_neg##1.##2##3##4##5##6##7\xint:##8[##9]% |
| 49091 |
{% |
| 49092 |
{\the\numexpr##1##2##3##4##5##6##7[-6]}\xint: |
| 49093 |
{\expandafter\XINT_LogTen_serII_a_ii |
| 49094 |
\romannumeral0\XINTinfloat[#2]% |
| 49095 |
{\xintAdd{-1[0]}% |
| 49096 |
{\xintMul{\csname XINT_c_1_##2_x\endcsname}{% |
| 49097 |
\XINTinFloat[#1]{% |
| 49098 |
\xintMul{\csname XINT_c_2_##3_x\endcsname}{% |
| 49099 |
\XINTinFloat[#1]{% |
| 49100 |
\xintMul{\csname XINT_c_3_##4_x\endcsname}{% |
| 49101 |
\XINTinFloat[#1]{% |
| 49102 |
\xintMul{\csname XINT_c_4_##5_x\endcsname}{% |
| 49103 |
\XINTinFloat[#1]{% |
| 49104 |
\xintMul{\csname XINT_c_5_##6_x\endcsname}{% |
| 49105 |
\XINTinFloat[#1]{% |
| 49106 |
\xintMul{\csname XINT_c_6_##7_x\endcsname} |
| 49107 |
{##8[##9-##1]}% |
| 49108 |
}}}}}}}}}}% |
| 49109 |
}% |
| 49110 |
}\xint: |
| 49111 |
}\xint: |
| 49112 |
}% |
| 49113 |
}\expandafter\XINT_tmpa |
| 49114 |
\the\numexpr\XINTdigitsormax+10\expandafter.\the\numexpr\XINTdigitsormax+4.% |
| 49115 |
% \end{macrocode} |
| 49116 |
%\begin{lverb} |
| 49117 |
% Initially all of this was done in a single big nested macro but the |
| 49118 |
% float-rounding of argument to less digits worked again each time from |
| 49119 |
% initial long input; the advantage on the other hand was that the 1/i |
| 49120 |
% constants were all pre-computed and rounded. |
| 49121 |
% |
| 49122 |
% Pre-coding the successive rounding to six digits less at each stage could be |
| 49123 |
% done via a single loop which would then walk back up inserting coeffs like |
| 49124 |
% 1/#1 having no special optimizing tricks. Pre-computing the 1/#1 too is |
| 49125 |
% possible but then one would have to copy the full set of such constants |
| 49126 |
% (which would be pre-computed depending on P), and this will add grabbing |
| 49127 |
% overhead in the loop expansion. Or one defines macros to hold the |
| 49128 |
% pre-rounded constants. |
| 49129 |
% |
| 49130 |
% Finally I do define macros, not only to hold the constants but to hold the |
| 49131 |
% whole build-up. Sacrificing brevity of code to benefit of expansion "speed". |
| 49132 |
% |
| 49133 |
% Firts one prepares eta, with P+4 digits for mantissa, and then hands it over |
| 49134 |
% to the log series. This will proceed via first preparing eta\xint: eta\xint: |
| 49135 |
% .... eta\xint:, the leftmost ones being more and more reduced in number of |
| 49136 |
% digits. Finally one goes back up to the right, the hard-coded number of |
| 49137 |
% steps depending on value of P=\XINTdigits at time of reloading of |
| 49138 |
% package. This number of steps is hard-coded in the number of macros which |
| 49139 |
% get defined. |
| 49140 |
% |
| 49141 |
% Descending (leftwards) chain: _a, Turning point: _b, Ascending: _c. |
| 49142 |
% |
| 49143 |
% As it is very easy to make silly typing mistakes in the numerous macros I |
| 49144 |
% have refactored a number of times the set-up to make manual verification |
| 49145 |
% straightforward. Automatization is possible but the _b macros complicate |
| 49146 |
% things, each one is its own special case. In the end the set-up will define |
| 49147 |
% then redefine some _a and the (finally unique) _b macro, this allows easier |
| 49148 |
% to read code, with no nesting of conditionals or else branches. |
| 49149 |
% |
| 49150 |
% Actually series III and series II differ by only a shift by and we could use |
| 49151 |
% always the slightly more costly series III in place of series II. But that |
| 49152 |
% would add one un-needed term and a bit overhead to the default P which is |
| 49153 |
% 16... |
| 49154 |
% |
| 49155 |
% (1.4f: hesitation on 2021/05/09 after removal or case I log series should |
| 49156 |
% I not follow the simplifying logic and use always the slightly more costly III?) |
| 49157 |
%\end{lverb} |
| 49158 |
% |
| 49159 |
% \subsubsection{Log series, case II} |
| 49160 |
% \begin{macrocode} |
| 49161 |
\def\XINT_tmpa#1.#2.{% |
| 49162 |
\def\XINT_LogTen_serII_a_ii##1\xint: |
| 49163 |
{% |
| 49164 |
\expandafter\XINT_LogTen_serII_b |
| 49165 |
\romannumeral0\XINTinfloatS[#1]{##1}\xint:##1\xint: |
| 49166 |
}% |
| 49167 |
\def\XINT_LogTen_serII_b#1[#2]\xint: |
| 49168 |
{% |
| 49169 |
\expandafter\XINT_LogTen_serII_c_ |
| 49170 |
\romannumeral0\xintadd{1}{\xintiiOpp\xintHalf{#10}[#2-1]}\xint: |
| 49171 |
}% |
| 49172 |
\def\XINT_LogTen_serII_c_##1\xint:##2\xint: |
| 49173 |
{% |
| 49174 |
\XINTinFloat[#2]{\xintMul{##1}{##2}}% |
| 49175 |
}% |
| 49176 |
}% |
| 49177 |
\expandafter\XINT_tmpa |
| 49178 |
\the\numexpr\XINTdigitsormax-2\expandafter.% |
| 49179 |
\the\numexpr\XINTdigitsormax+4.% |
| 49180 |
\ifnum\XINTdigits>10 |
| 49181 |
\def\XINT_tmpa#1.#2.#3.#4.{% |
| 49182 |
\def\XINT_LogTen_serII_a_ii##1\xint: |
| 49183 |
{% |
| 49184 |
\expandafter\XINT_LogTen_serII_a_iii |
| 49185 |
\romannumeral0\XINTinfloatS[#2]{##1}\xint:##1\xint: |
| 49186 |
}% |
| 49187 |
\def\XINT_LogTen_serII_a_iii##1\xint: |
| 49188 |
{% |
| 49189 |
\expandafter\XINT_LogTen_serII_b |
| 49190 |
\romannumeral0\XINTinfloatS[#1]{##1}\xint:##1\xint: |
| 49191 |
}% |
| 49192 |
\def\XINT_LogTen_serII_b##1[##2]\xint: |
| 49193 |
{% |
| 49194 |
\expandafter\XINT_LogTen_serII_c_i |
| 49195 |
\romannumeral0\xintadd{#3}{##1/3[##2]}\xint: |
| 49196 |
}% |
| 49197 |
\def\XINT_LogTen_serII_c_i##1\xint:##2\xint: |
| 49198 |
{% |
| 49199 |
\expandafter\XINT_LogTen_serII_c_ |
| 49200 |
\romannumeral0\xintadd{#4}{\XINTinFloat[#2]{\xintMul{##1}{##2}}}\xint: |
| 49201 |
}% |
| 49202 |
}\expandafter\XINT_tmpa |
| 49203 |
\the\numexpr\XINTdigitsormax-8\expandafter.% |
| 49204 |
\the\numexpr\XINTdigitsormax-2.% |
| 49205 |
{-5[-1]}.% |
| 49206 |
{1[0]}.% |
| 49207 |
\fi |
| 49208 |
\ifnum\XINTdigits>16 |
| 49209 |
\def\XINT_tmpa#1.#2.#3.#4.{% |
| 49210 |
\def\XINT_LogTen_serII_a_iii##1\xint: |
| 49211 |
{% |
| 49212 |
\expandafter\XINT_LogTen_serII_a_iv |
| 49213 |
\romannumeral0\XINTinfloatS[#2]{##1}\xint:##1\xint: |
| 49214 |
}% |
| 49215 |
\def\XINT_LogTen_serII_a_iv##1\xint: |
| 49216 |
{% |
| 49217 |
\expandafter\XINT_LogTen_serII_b |
| 49218 |
\romannumeral0\XINTinfloatS[#1]{##1}\xint:##1\xint: |
| 49219 |
}% |
| 49220 |
\def\XINT_LogTen_serII_b##1[##2]\xint: |
| 49221 |
{% |
| 49222 |
\expandafter\XINT_LogTen_serII_c_ii |
| 49223 |
\romannumeral0\xintadd{#3}{\xintiiMul{-25}{##1}[##2-2]}\xint: |
| 49224 |
}% |
| 49225 |
\def\XINT_LogTen_serII_c_ii##1\xint:##2\xint: |
| 49226 |
{% |
| 49227 |
\expandafter\XINT_LogTen_serII_c_i |
| 49228 |
\romannumeral0\xintadd{#4}{\XINTinFloat[#2]{\xintMul{##1}{##2}}}\xint: |
| 49229 |
}% |
| 49230 |
}\expandafter\XINT_tmpa |
| 49231 |
\the\numexpr\XINTdigitsormax-14\expandafter.% |
| 49232 |
\the\numexpr\XINTdigitsormax-8\expandafter.% |
| 49233 |
\romannumeral0\XINTinfloat[\XINTdigitsormax-8]{1/3[0]}.% |
| 49234 |
{-5[-1]}.% |
| 49235 |
\fi |
| 49236 |
\ifnum\XINTdigits>22 |
| 49237 |
\def\XINT_tmpa#1.#2.#3.#4.{% |
| 49238 |
\def\XINT_LogTen_serII_a_iv##1\xint: |
| 49239 |
{% |
| 49240 |
\expandafter\XINT_LogTen_serII_a_v |
| 49241 |
\romannumeral0\XINTinfloatS[#2]{##1}\xint:##1\xint: |
| 49242 |
}% |
| 49243 |
\def\XINT_LogTen_serII_a_v##1\xint: |
| 49244 |
{% |
| 49245 |
\expandafter\XINT_LogTen_serII_b |
| 49246 |
\romannumeral0\XINTinfloatS[#1]{##1}\xint:##1\xint: |
| 49247 |
}% |
| 49248 |
\def\XINT_LogTen_serII_b##1[##2]\xint: |
| 49249 |
{% |
| 49250 |
\expandafter\XINT_LogTen_serII_c_iii |
| 49251 |
\romannumeral0\xintadd{#3}{\xintDouble{##1}[##2-1]}\xint: |
| 49252 |
}% |
| 49253 |
\def\XINT_LogTen_serII_c_iii##1\xint:##2\xint: |
| 49254 |
{% |
| 49255 |
\expandafter\XINT_LogTen_serII_c_ii |
| 49256 |
\romannumeral0\xintadd{#4}{\XINTinFloat[#2]{\xintMul{##1}{##2}}}\xint: |
| 49257 |
}% |
| 49258 |
}\expandafter\XINT_tmpa |
| 49259 |
\the\numexpr\XINTdigitsormax-20\expandafter.% |
| 49260 |
\the\numexpr\XINTdigitsormax-14\expandafter.\expanded{% |
| 49261 |
{-25[-2]}.% |
| 49262 |
\XINTinFloat[\XINTdigitsormax-8]{1/3[0]}.% |
| 49263 |
}% |
| 49264 |
\fi |
| 49265 |
\ifnum\XINTdigits>28 |
| 49266 |
\def\XINT_tmpa#1.#2.#3.#4.{% |
| 49267 |
\def\XINT_LogTen_serII_a_v##1\xint: |
| 49268 |
{% |
| 49269 |
\expandafter\XINT_LogTen_serII_a_vi |
| 49270 |
\romannumeral0\XINTinfloatS[#2]{##1}\xint:##1\xint: |
| 49271 |
}% |
| 49272 |
\def\XINT_LogTen_serII_a_vi##1\xint: |
| 49273 |
{% |
| 49274 |
\expandafter\XINT_LogTen_serII_b |
| 49275 |
\romannumeral0\XINTinfloatS[#1]{##1}\xint:##1\xint: |
| 49276 |
}% |
| 49277 |
\def\XINT_LogTen_serII_b##1[##2]\xint: |
| 49278 |
{% |
| 49279 |
\expandafter\XINT_LogTen_serII_c_iv |
| 49280 |
\romannumeral0\xintadd{#3}{\xintiiOpp##1/6[##2]}\xint: |
| 49281 |
}% |
| 49282 |
\def\XINT_LogTen_serII_c_iv##1\xint:##2\xint: |
| 49283 |
{% |
| 49284 |
\expandafter\XINT_LogTen_serII_c_iii |
| 49285 |
\romannumeral0\xintadd{#4}{\XINTinFloat[#2]{\xintMul{##1}{##2}}}\xint: |
| 49286 |
}% |
| 49287 |
}\expandafter\XINT_tmpa |
| 49288 |
\the\numexpr\XINTdigitsormax-26\expandafter.% |
| 49289 |
\the\numexpr\XINTdigitsormax-20.% |
| 49290 |
{2[-1]}.% |
| 49291 |
{-25[-2]}.% |
| 49292 |
\fi |
| 49293 |
\ifnum\XINTdigits>34 |
| 49294 |
\def\XINT_tmpa#1.#2.#3.#4.{% |
| 49295 |
\def\XINT_LogTen_serII_a_vi##1\xint: |
| 49296 |
{% |
| 49297 |
\expandafter\XINT_LogTen_serII_a_vii |
| 49298 |
\romannumeral0\XINTinfloatS[#2]{##1}\xint:##1\xint: |
| 49299 |
}% |
| 49300 |
\def\XINT_LogTen_serII_a_vii##1\xint: |
| 49301 |
{% |
| 49302 |
\expandafter\XINT_LogTen_serII_b |
| 49303 |
\romannumeral0\XINTinfloatS[#1]{##1}\xint:##1\xint: |
| 49304 |
}% |
| 49305 |
\def\XINT_LogTen_serII_b##1[##2]\xint: |
| 49306 |
{% |
| 49307 |
\expandafter\XINT_LogTen_serII_c_v |
| 49308 |
\romannumeral0\xintadd{#3}{##1/7[##2]}\xint: |
| 49309 |
}% |
| 49310 |
\def\XINT_LogTen_serII_c_v##1\xint:##2\xint: |
| 49311 |
{% |
| 49312 |
\expandafter\XINT_LogTen_serII_c_iv |
| 49313 |
\romannumeral0\xintadd{#4}{\XINTinFloat[#2]{\xintMul{##1}{##2}}}\xint: |
| 49314 |
}% |
| 49315 |
}\expandafter\XINT_tmpa |
| 49316 |
\the\numexpr\XINTdigitsormax-32\expandafter.% |
| 49317 |
\the\numexpr\XINTdigitsormax-26\expandafter.% |
| 49318 |
\romannumeral0\XINTinfloatS[\XINTdigitsormax-26]{-1/6[0]}.% |
| 49319 |
{2[-1]}.% |
| 49320 |
\fi |
| 49321 |
\ifnum\XINTdigits>40 |
| 49322 |
\def\XINT_tmpa#1.#2.#3.#4.{% |
| 49323 |
\def\XINT_LogTen_serII_a_vii##1\xint: |
| 49324 |
{% |
| 49325 |
\expandafter\XINT_LogTen_serII_a_viii |
| 49326 |
\romannumeral0\XINTinfloatS[#2]{##1}\xint:##1\xint: |
| 49327 |
}% |
| 49328 |
\def\XINT_LogTen_serII_a_viii##1\xint: |
| 49329 |
{% |
| 49330 |
\expandafter\XINT_LogTen_serII_b |
| 49331 |
\romannumeral0\XINTinfloatS[#1]{##1}\xint:##1\xint: |
| 49332 |
}% |
| 49333 |
\def\XINT_LogTen_serII_b##1[##2]\xint: |
| 49334 |
{% |
| 49335 |
\expandafter\XINT_LogTen_serII_c_vi |
| 49336 |
\romannumeral0\xintadd{#3}{\xintiiMul{-125}{##1}[##2-3]}\xint: |
| 49337 |
}% |
| 49338 |
\def\XINT_LogTen_serII_c_vi##1\xint:##2\xint: |
| 49339 |
{% |
| 49340 |
\expandafter\XINT_LogTen_serII_c_v |
| 49341 |
\romannumeral0\xintadd{#4}{\XINTinFloat[#2]{\xintMul{##1}{##2}}}\xint: |
| 49342 |
}% |
| 49343 |
}\expandafter\XINT_tmpa |
| 49344 |
\the\numexpr\XINTdigitsormax-38\expandafter.% |
| 49345 |
\the\numexpr\XINTdigitsormax-32\expandafter.\expanded{% |
| 49346 |
\XINTinFloat[\XINTdigitsormax-32]{1/7[0]}.% |
| 49347 |
\XINTinFloat[\XINTdigitsormax-26]{-1/6[0]}.% |
| 49348 |
}% |
| 49349 |
\fi |
| 49350 |
\ifnum\XINTdigits>46 |
| 49351 |
\def\XINT_tmpa#1.#2.#3.#4.{% |
| 49352 |
\def\XINT_LogTen_serII_a_viii##1\xint: |
| 49353 |
{% |
| 49354 |
\expandafter\XINT_LogTen_serII_a_ix |
| 49355 |
\romannumeral0\XINTinfloatS[#2]{##1}\xint:##1\xint: |
| 49356 |
}% |
| 49357 |
\def\XINT_LogTen_serII_a_ix##1\xint: |
| 49358 |
{% |
| 49359 |
\expandafter\XINT_LogTen_serII_b |
| 49360 |
\romannumeral0\XINTinfloatS[#1]{##1}\xint:##1\xint: |
| 49361 |
}% |
| 49362 |
\def\XINT_LogTen_serII_b##1[##2]\xint: |
| 49363 |
{% |
| 49364 |
\expandafter\XINT_LogTen_serII_c_vii |
| 49365 |
\romannumeral0\xintadd{#3}{##1/9[##2]}\xint: |
| 49366 |
}% |
| 49367 |
\def\XINT_LogTen_serII_c_vii##1\xint:##2\xint: |
| 49368 |
{% |
| 49369 |
\expandafter\XINT_LogTen_serII_c_vi |
| 49370 |
\romannumeral0\xintadd{#4}{\XINTinFloat[#2]{\xintMul{##1}{##2}}}\xint: |
| 49371 |
}% |
| 49372 |
}\expandafter\XINT_tmpa |
| 49373 |
\the\numexpr\XINTdigitsormax-44\expandafter.% |
| 49374 |
\the\numexpr\XINTdigitsormax-38\expandafter.\expanded{% |
| 49375 |
{-125[-3]}.% |
| 49376 |
\XINTinFloat[\XINTdigitsormax-32]{1/7[0]}.% |
| 49377 |
}% |
| 49378 |
\fi |
| 49379 |
\ifnum\XINTdigits>52 |
| 49380 |
\def\XINT_tmpa#1.#2.#3.#4.{% |
| 49381 |
\def\XINT_LogTen_serII_a_ix##1\xint: |
| 49382 |
{% |
| 49383 |
\expandafter\XINT_LogTen_serII_a_x |
| 49384 |
\romannumeral0\XINTinfloatS[#2]{##1}\xint:##1\xint: |
| 49385 |
}% |
| 49386 |
\def\XINT_LogTen_serII_a_x##1\xint: |
| 49387 |
{% |
| 49388 |
\expandafter\XINT_LogTen_serII_b |
| 49389 |
\romannumeral0\XINTinfloatS[#1]{##1}\xint:##1\xint: |
| 49390 |
}% |
| 49391 |
\def\XINT_LogTen_serII_b##1[##2]\xint: |
| 49392 |
{% |
| 49393 |
\expandafter\XINT_LogTen_serII_c_viii |
| 49394 |
\romannumeral0\xintadd{#3}{\xintiiOpp##1[##2-1]}\xint: |
| 49395 |
}% |
| 49396 |
\def\XINT_LogTen_serII_c_viii##1\xint:##2\xint: |
| 49397 |
{% |
| 49398 |
\expandafter\XINT_LogTen_serII_c_vii |
| 49399 |
\romannumeral0\xintadd{#4}{\XINTinFloat[#2]{\xintMul{##1}{##2}}}\xint: |
| 49400 |
}% |
| 49401 |
}\expandafter\XINT_tmpa |
| 49402 |
\the\numexpr\XINTdigitsormax-50\expandafter.% |
| 49403 |
\the\numexpr\XINTdigitsormax-44\expandafter.% |
| 49404 |
\romannumeral0\XINTinfloat[\XINTdigitsormax-44]{1/9[0]}.% |
| 49405 |
{-125[-3]}.% |
| 49406 |
\fi |
| 49407 |
\ifnum\XINTdigits>58 |
| 49408 |
\def\XINT_tmpa#1.#2.#3.#4.{% |
| 49409 |
\def\XINT_LogTen_serII_a_x##1\xint: |
| 49410 |
{% |
| 49411 |
\expandafter\XINT_LogTen_serII_a_xi |
| 49412 |
\romannumeral0\XINTinfloatS[#2]{##1}\xint:##1\xint: |
| 49413 |
}% |
| 49414 |
\def\XINT_LogTen_serII_a_xi##1\xint: |
| 49415 |
{% |
| 49416 |
\expandafter\XINT_LogTen_serII_b |
| 49417 |
\romannumeral0\XINTinfloatS[#1]{##1}\xint:##1\xint: |
| 49418 |
}% |
| 49419 |
\def\XINT_LogTen_serII_b##1[##2]\xint: |
| 49420 |
{% |
| 49421 |
\expandafter\XINT_LogTen_serII_c_ix |
| 49422 |
\romannumeral0\xintadd{#3}{##1/11[##2]}\xint: |
| 49423 |
}% |
| 49424 |
\def\XINT_LogTen_serII_c_ix##1\xint:##2\xint: |
| 49425 |
{% |
| 49426 |
\expandafter\XINT_LogTen_serII_c_viii |
| 49427 |
\romannumeral0\xintadd{#4}{\XINTinFloat[#2]{\xintMul{##1}{##2}}}\xint: |
| 49428 |
}% |
| 49429 |
}\expandafter\XINT_tmpa |
| 49430 |
\the\numexpr\XINTdigitsormax-56\expandafter.% |
| 49431 |
\the\numexpr\XINTdigitsormax-50\expandafter.\expanded{% |
| 49432 |
{-1[-1]}.% |
| 49433 |
\XINTinFloat[\XINTdigitsormax-44]{1/9[0]}.% |
| 49434 |
}% |
| 49435 |
\fi |
| 49436 |
% \end{macrocode} |
| 49437 |
% \subsubsection{Log series, case III} |
| 49438 |
% \begin{macrocode} |
| 49439 |
\def\XINT_tmpa#1.#2.{% |
| 49440 |
\def\XINT_LogTen_serIII_a_ii##1\xint: |
| 49441 |
{% |
| 49442 |
\expandafter\XINT_LogTen_serIII_b |
| 49443 |
\romannumeral0\XINTinfloatS[#1]{##1}\xint:##1\xint: |
| 49444 |
}% |
| 49445 |
\def\XINT_LogTen_serIII_b#1[#2]\xint: |
| 49446 |
{% |
| 49447 |
\expandafter\XINT_LogTen_serIII_c_ |
| 49448 |
\romannumeral0\xintadd{1}{\xintiiOpp\xintHalf{#10}[#2-1]}\xint: |
| 49449 |
}% |
| 49450 |
\def\XINT_LogTen_serIII_c_##1\xint:##2\xint: |
| 49451 |
{% |
| 49452 |
\XINTinFloat[#2]{\xintMul{##1}{##2}}% |
| 49453 |
}% |
| 49454 |
}% |
| 49455 |
\expandafter\XINT_tmpa |
| 49456 |
\the\numexpr\XINTdigitsormax-1\expandafter.% |
| 49457 |
\the\numexpr\XINTdigitsormax+4.% |
| 49458 |
\ifnum\XINTdigits>9 |
| 49459 |
\def\XINT_tmpa#1.#2.#3.#4.{% |
| 49460 |
\def\XINT_LogTen_serIII_a_ii##1\xint: |
| 49461 |
{% |
| 49462 |
\expandafter\XINT_LogTen_serIII_a_iii |
| 49463 |
\romannumeral0\XINTinfloatS[#2]{##1}\xint:##1\xint: |
| 49464 |
}% |
| 49465 |
\def\XINT_LogTen_serIII_a_iii##1\xint: |
| 49466 |
{% |
| 49467 |
\expandafter\XINT_LogTen_serIII_b |
| 49468 |
\romannumeral0\XINTinfloatS[#1]{##1}\xint:##1\xint: |
| 49469 |
}% |
| 49470 |
\def\XINT_LogTen_serIII_b##1[##2]\xint: |
| 49471 |
{% |
| 49472 |
\expandafter\XINT_LogTen_serIII_c_i |
| 49473 |
\romannumeral0\xintadd{#3}{##1/3[##2]}\xint: |
| 49474 |
}% |
| 49475 |
\def\XINT_LogTen_serIII_c_i##1\xint:##2\xint: |
| 49476 |
{% |
| 49477 |
\expandafter\XINT_LogTen_serIII_c_ |
| 49478 |
\romannumeral0\xintadd{#4}{\XINTinFloat[#2]{\xintMul{##1}{##2}}}\xint: |
| 49479 |
}% |
| 49480 |
}\expandafter\XINT_tmpa |
| 49481 |
\the\numexpr\XINTdigitsormax-7\expandafter.% |
| 49482 |
\the\numexpr\XINTdigitsormax-1.% |
| 49483 |
{-5[-1]}.% |
| 49484 |
{1[0]}.% |
| 49485 |
\fi |
| 49486 |
\ifnum\XINTdigits>15 |
| 49487 |
\def\XINT_tmpa#1.#2.#3.#4.{% |
| 49488 |
\def\XINT_LogTen_serIII_a_iii##1\xint: |
| 49489 |
{% |
| 49490 |
\expandafter\XINT_LogTen_serIII_a_iv |
| 49491 |
\romannumeral0\XINTinfloatS[#2]{##1}\xint:##1\xint: |
| 49492 |
}% |
| 49493 |
\def\XINT_LogTen_serIII_a_iv##1\xint: |
| 49494 |
{% |
| 49495 |
\expandafter\XINT_LogTen_serIII_b |
| 49496 |
\romannumeral0\XINTinfloatS[#1]{##1}\xint:##1\xint: |
| 49497 |
}% |
| 49498 |
\def\XINT_LogTen_serIII_b##1[##2]\xint: |
| 49499 |
{% |
| 49500 |
\expandafter\XINT_LogTen_serIII_c_ii |
| 49501 |
\romannumeral0\xintadd{#3}{\xintiiMul{-25}{##1}[##2-2]}\xint: |
| 49502 |
}% |
| 49503 |
\def\XINT_LogTen_serIII_c_ii##1\xint:##2\xint: |
| 49504 |
{% |
| 49505 |
\expandafter\XINT_LogTen_serIII_c_i |
| 49506 |
\romannumeral0\xintadd{#4}{\XINTinFloat[#2]{\xintMul{##1}{##2}}}\xint: |
| 49507 |
}% |
| 49508 |
}\expandafter\XINT_tmpa |
| 49509 |
\the\numexpr\XINTdigitsormax-13\expandafter.% |
| 49510 |
\the\numexpr\XINTdigitsormax-7\expandafter.% |
| 49511 |
\romannumeral0\XINTinfloat[\XINTdigitsormax-7]{1/3[0]}.% |
| 49512 |
{-5[-1]}.% |
| 49513 |
\fi |
| 49514 |
\ifnum\XINTdigits>21 |
| 49515 |
\def\XINT_tmpa#1.#2.#3.#4.{% |
| 49516 |
\def\XINT_LogTen_serIII_a_iv##1\xint: |
| 49517 |
{% |
| 49518 |
\expandafter\XINT_LogTen_serIII_a_v |
| 49519 |
\romannumeral0\XINTinfloatS[#2]{##1}\xint:##1\xint: |
| 49520 |
}% |
| 49521 |
\def\XINT_LogTen_serIII_a_v##1\xint: |
| 49522 |
{% |
| 49523 |
\expandafter\XINT_LogTen_serIII_b |
| 49524 |
\romannumeral0\XINTinfloatS[#1]{##1}\xint:##1\xint: |
| 49525 |
}% |
| 49526 |
\def\XINT_LogTen_serIII_b##1[##2]\xint: |
| 49527 |
{% |
| 49528 |
\expandafter\XINT_LogTen_serIII_c_iii |
| 49529 |
\romannumeral0\xintadd{#3}{\xintDouble{##1}[##2-1]}\xint: |
| 49530 |
}% |
| 49531 |
\def\XINT_LogTen_serIII_c_iii##1\xint:##2\xint: |
| 49532 |
{% |
| 49533 |
\expandafter\XINT_LogTen_serIII_c_ii |
| 49534 |
\romannumeral0\xintadd{#4}{\XINTinFloat[#2]{\xintMul{##1}{##2}}}\xint: |
| 49535 |
}% |
| 49536 |
}\expandafter\XINT_tmpa |
| 49537 |
\the\numexpr\XINTdigitsormax-19\expandafter.% |
| 49538 |
\the\numexpr\XINTdigitsormax-13\expandafter.\expanded{% |
| 49539 |
{-25[-2]}.% |
| 49540 |
\XINTinFloat[\XINTdigitsormax-7]{1/3[0]}.% |
| 49541 |
}% |
| 49542 |
\fi |
| 49543 |
\ifnum\XINTdigits>27 |
| 49544 |
\def\XINT_tmpa#1.#2.#3.#4.{% |
| 49545 |
\def\XINT_LogTen_serIII_a_v##1\xint: |
| 49546 |
{% |
| 49547 |
\expandafter\XINT_LogTen_serIII_a_vi |
| 49548 |
\romannumeral0\XINTinfloatS[#2]{##1}\xint:##1\xint: |
| 49549 |
}% |
| 49550 |
\def\XINT_LogTen_serIII_a_vi##1\xint: |
| 49551 |
{% |
| 49552 |
\expandafter\XINT_LogTen_serIII_b |
| 49553 |
\romannumeral0\XINTinfloatS[#1]{##1}\xint:##1\xint: |
| 49554 |
}% |
| 49555 |
\def\XINT_LogTen_serIII_b##1[##2]\xint: |
| 49556 |
{% |
| 49557 |
\expandafter\XINT_LogTen_serIII_c_iv |
| 49558 |
\romannumeral0\xintadd{#3}{\xintiiOpp##1/6[##2]}\xint: |
| 49559 |
}% |
| 49560 |
\def\XINT_LogTen_serIII_c_iv##1\xint:##2\xint: |
| 49561 |
{% |
| 49562 |
\expandafter\XINT_LogTen_serIII_c_iii |
| 49563 |
\romannumeral0\xintadd{#4}{\XINTinFloat[#2]{\xintMul{##1}{##2}}}\xint: |
| 49564 |
}% |
| 49565 |
}\expandafter\XINT_tmpa |
| 49566 |
\the\numexpr\XINTdigitsormax-25\expandafter.% |
| 49567 |
\the\numexpr\XINTdigitsormax-19.% |
| 49568 |
{2[-1]}.% |
| 49569 |
{-25[-2]}.% |
| 49570 |
\fi |
| 49571 |
\ifnum\XINTdigits>33 |
| 49572 |
\def\XINT_tmpa#1.#2.#3.#4.{% |
| 49573 |
\def\XINT_LogTen_serIII_a_vi##1\xint: |
| 49574 |
{% |
| 49575 |
\expandafter\XINT_LogTen_serIII_a_vii |
| 49576 |
\romannumeral0\XINTinfloatS[#2]{##1}\xint:##1\xint: |
| 49577 |
}% |
| 49578 |
\def\XINT_LogTen_serIII_a_vii##1\xint: |
| 49579 |
{% |
| 49580 |
\expandafter\XINT_LogTen_serIII_b |
| 49581 |
\romannumeral0\XINTinfloatS[#1]{##1}\xint:##1\xint: |
| 49582 |
}% |
| 49583 |
\def\XINT_LogTen_serIII_b##1[##2]\xint: |
| 49584 |
{% |
| 49585 |
\expandafter\XINT_LogTen_serIII_c_v |
| 49586 |
\romannumeral0\xintadd{#3}{##1/7[##2]}\xint: |
| 49587 |
}% |
| 49588 |
\def\XINT_LogTen_serIII_c_v##1\xint:##2\xint: |
| 49589 |
{% |
| 49590 |
\expandafter\XINT_LogTen_serIII_c_iv |
| 49591 |
\romannumeral0\xintadd{#4}{\XINTinFloat[#2]{\xintMul{##1}{##2}}}\xint: |
| 49592 |
}% |
| 49593 |
}\expandafter\XINT_tmpa |
| 49594 |
\the\numexpr\XINTdigitsormax-31\expandafter.% |
| 49595 |
\the\numexpr\XINTdigitsormax-25\expandafter.% |
| 49596 |
\romannumeral0\XINTinfloatS[\XINTdigitsormax-25]{-1/6[0]}.% |
| 49597 |
{2[-1]}.% |
| 49598 |
\fi |
| 49599 |
\ifnum\XINTdigits>39 |
| 49600 |
\def\XINT_tmpa#1.#2.#3.#4.{% |
| 49601 |
\def\XINT_LogTen_serIII_a_vii##1\xint: |
| 49602 |
{% |
| 49603 |
\expandafter\XINT_LogTen_serIII_a_viii |
| 49604 |
\romannumeral0\XINTinfloatS[#2]{##1}\xint:##1\xint: |
| 49605 |
}% |
| 49606 |
\def\XINT_LogTen_serIII_a_viii##1\xint: |
| 49607 |
{% |
| 49608 |
\expandafter\XINT_LogTen_serIII_b |
| 49609 |
\romannumeral0\XINTinfloatS[#1]{##1}\xint:##1\xint: |
| 49610 |
}% |
| 49611 |
\def\XINT_LogTen_serIII_b##1[##2]\xint: |
| 49612 |
{% |
| 49613 |
\expandafter\XINT_LogTen_serIII_c_vi |
| 49614 |
\romannumeral0\xintadd{#3}{\xintiiMul{-125}{##1}[##2-3]}\xint: |
| 49615 |
}% |
| 49616 |
\def\XINT_LogTen_serIII_c_vi##1\xint:##2\xint: |
| 49617 |
{% |
| 49618 |
\expandafter\XINT_LogTen_serIII_c_v |
| 49619 |
\romannumeral0\xintadd{#4}{\XINTinFloat[#2]{\xintMul{##1}{##2}}}\xint: |
| 49620 |
}% |
| 49621 |
}\expandafter\XINT_tmpa |
| 49622 |
\the\numexpr\XINTdigitsormax-37\expandafter.% |
| 49623 |
\the\numexpr\XINTdigitsormax-31\expandafter.\expanded{% |
| 49624 |
\XINTinFloat[\XINTdigitsormax-31]{1/7[0]}.% |
| 49625 |
\XINTinFloat[\XINTdigitsormax-25]{-1/6[0]}.% |
| 49626 |
}% |
| 49627 |
\fi |
| 49628 |
\ifnum\XINTdigits>45 |
| 49629 |
\def\XINT_tmpa#1.#2.#3.#4.{% |
| 49630 |
\def\XINT_LogTen_serIII_a_viii##1\xint: |
| 49631 |
{% |
| 49632 |
\expandafter\XINT_LogTen_serIII_a_ix |
| 49633 |
\romannumeral0\XINTinfloatS[#2]{##1}\xint:##1\xint: |
| 49634 |
}% |
| 49635 |
\def\XINT_LogTen_serIII_a_ix##1\xint: |
| 49636 |
{% |
| 49637 |
\expandafter\XINT_LogTen_serIII_b |
| 49638 |
\romannumeral0\XINTinfloatS[#1]{##1}\xint:##1\xint: |
| 49639 |
}% |
| 49640 |
\def\XINT_LogTen_serIII_b##1[##2]\xint: |
| 49641 |
{% |
| 49642 |
\expandafter\XINT_LogTen_serIII_c_vii |
| 49643 |
\romannumeral0\xintadd{#3}{##1/9[##2]}\xint: |
| 49644 |
}% |
| 49645 |
\def\XINT_LogTen_serIII_c_vii##1\xint:##2\xint: |
| 49646 |
{% |
| 49647 |
\expandafter\XINT_LogTen_serIII_c_vi |
| 49648 |
\romannumeral0\xintadd{#4}{\XINTinFloat[#2]{\xintMul{##1}{##2}}}\xint: |
| 49649 |
}% |
| 49650 |
}\expandafter\XINT_tmpa |
| 49651 |
\the\numexpr\XINTdigitsormax-43\expandafter.% |
| 49652 |
\the\numexpr\XINTdigitsormax-37\expandafter.\expanded{% |
| 49653 |
{-125[-3]}.% |
| 49654 |
\XINTinFloat[\XINTdigitsormax-31]{1/7[0]}.% |
| 49655 |
}% |
| 49656 |
\fi |
| 49657 |
\ifnum\XINTdigits>51 |
| 49658 |
\def\XINT_tmpa#1.#2.#3.#4.{% |
| 49659 |
\def\XINT_LogTen_serIII_a_ix##1\xint: |
| 49660 |
{% |
| 49661 |
\expandafter\XINT_LogTen_serIII_a_x |
| 49662 |
\romannumeral0\XINTinfloatS[#2]{##1}\xint:##1\xint: |
| 49663 |
}% |
| 49664 |
\def\XINT_LogTen_serIII_a_x##1\xint: |
| 49665 |
{% |
| 49666 |
\expandafter\XINT_LogTen_serIII_b |
| 49667 |
\romannumeral0\XINTinfloatS[#1]{##1}\xint:##1\xint: |
| 49668 |
}% |
| 49669 |
\def\XINT_LogTen_serIII_b##1[##2]\xint: |
| 49670 |
{% |
| 49671 |
\expandafter\XINT_LogTen_serIII_c_viii |
| 49672 |
\romannumeral0\xintadd{#3}{\xintiiOpp##1[##2-1]}\xint: |
| 49673 |
}% |
| 49674 |
\def\XINT_LogTen_serIII_c_viii##1\xint:##2\xint: |
| 49675 |
{% |
| 49676 |
\expandafter\XINT_LogTen_serIII_c_vii |
| 49677 |
\romannumeral0\xintadd{#4}{\XINTinFloat[#2]{\xintMul{##1}{##2}}}\xint: |
| 49678 |
}% |
| 49679 |
}\expandafter\XINT_tmpa |
| 49680 |
\the\numexpr\XINTdigitsormax-49\expandafter.% |
| 49681 |
\the\numexpr\XINTdigitsormax-43\expandafter.% |
| 49682 |
\romannumeral0\XINTinfloat[\XINTdigitsormax-43]{1/9[0]}.% |
| 49683 |
{-125[-3]}.% |
| 49684 |
\fi |
| 49685 |
\ifnum\XINTdigits>57 |
| 49686 |
\def\XINT_tmpa#1.#2.#3.#4.{% |
| 49687 |
\def\XINT_LogTen_serIII_a_x##1\xint: |
| 49688 |
{% |
| 49689 |
\expandafter\XINT_LogTen_serIII_a_xi |
| 49690 |
\romannumeral0\XINTinfloatS[#2]{##1}\xint:##1\xint: |
| 49691 |
}% |
| 49692 |
\def\XINT_LogTen_serIII_a_xi##1\xint: |
| 49693 |
{% |
| 49694 |
\expandafter\XINT_LogTen_serIII_b |
| 49695 |
\romannumeral0\XINTinfloatS[#1]{##1}\xint:##1\xint: |
| 49696 |
}% |
| 49697 |
\def\XINT_LogTen_serIII_b##1[##2]\xint: |
| 49698 |
{% |
| 49699 |
\expandafter\XINT_LogTen_serIII_c_ix |
| 49700 |
\romannumeral0\xintadd{#3}{##1/11[##2]}\xint: |
| 49701 |
}% |
| 49702 |
\def\XINT_LogTen_serIII_c_ix##1\xint:##2\xint: |
| 49703 |
{% |
| 49704 |
\expandafter\XINT_LogTen_serIII_c_viii |
| 49705 |
\romannumeral0\xintadd{#4}{\XINTinFloat[#2]{\xintMul{##1}{##2}}}\xint: |
| 49706 |
}% |
| 49707 |
}\expandafter\XINT_tmpa |
| 49708 |
\the\numexpr\XINTdigitsormax-55\expandafter.% |
| 49709 |
\the\numexpr\XINTdigitsormax-49\expandafter.\expanded{% |
| 49710 |
{-1[-1]}.% |
| 49711 |
\XINTinFloat[\XINTdigitsormax-43]{1/9[0]}.% |
| 49712 |
}% |
| 49713 |
\fi |
| 49714 |
\XINTlogendinput% |
| 49715 |
% \end{macrocode} |
| 49716 |
% \StoreCodelineNo {xintlog} |
| 49717 |
% \cleardoublepage\let\xintlognameUp\undefined |
| 49718 |
% \MakePercentComment |
| 49719 |
%</xintlog>------------------------------------------------------ |
| 49720 |
%<*dtx>----------------------------------------------------------- |
| 49721 |
\iffalse |
| 49722 |
% grep -c -e "^{%" xint*sty |
| 49723 |
xint.sty:205 |
| 49724 |
xintbinhex.sty:95 |
| 49725 |
xintcfrac.sty:183 |
| 49726 |
xintcore.sty:267 |
| 49727 |
xintexpr.sty:493 |
| 49728 |
xintfrac.sty:522 |
| 49729 |
xintgcd.sty:41 |
| 49730 |
xintkernel.sty:17 |
| 49731 |
xintlog.sty:149 |
| 49732 |
xintseries.sty:48 |
| 49733 |
xinttools.sty:157 |
| 49734 |
xinttrig.sty:66 |
| 49735 |
\fi |
| 49736 |
% grep -o "^{%" xint*sty | wc -l |
| 49737 |
\def\totala{2243} |
| 49738 |
\iffalse |
| 49739 |
% grep -c -e "^}%" xint*sty |
| 49740 |
xint.sty:204 |
| 49741 |
xintbinhex.sty:94 |
| 49742 |
xintcfrac.sty:183 |
| 49743 |
xintcore.sty:265 |
| 49744 |
xintexpr.sty:474 |
| 49745 |
xintfrac.sty:530 |
| 49746 |
xintgcd.sty:43 |
| 49747 |
xintkernel.sty:18 |
| 49748 |
xintlog.sty:150 |
| 49749 |
xintseries.sty:48 |
| 49750 |
xinttools.sty:156 |
| 49751 |
xinttrig.sty:65 |
| 49752 |
\fi |
| 49753 |
% grep -o "^}%" xint*sty | wc -l |
| 49754 |
\def\totalb{2230} |
| 49755 |
\cleardoublepage |
| 49756 |
\section{Cumulative line and macro count} |
| 49757 |
|
| 49758 |
% le 6 juin 2022 j'ajoute le décompte des macros |
| 49759 |
\def\mymacro #1{\mymacroaux #1} |
| 49760 |
\def\mymacroaux #1#2#3{\strut |
| 49761 |
\csname #1nameimp\endcsname&\dtt{#2}&(\dtt{#3})\tabularnewline } |
| 49762 |
\indent |
| 49763 |
\begin{tabular}[t]{rrr} |
| 49764 |
module&lines¯os\tabularnewline |
| 49765 |
\xintApplyInline\mymacro\storedlinecounts |
| 49766 |
\end{tabular} |
| 49767 |
\hfil |
| 49768 |
\begin{minipage}[t]{10cm} |
| 49769 |
\def\mymacroaux #1#2#3{#2}% |
| 49770 |
|
| 49771 |
Total number of code lines: |
| 49772 |
\dtt{\the\numexpr |
| 49773 |
\xintListWithSep+{\xintApply\mymacro\storedlinecounts}\relax }. |
| 49774 |
\ifdefined\totala |
| 49775 |
(but \dtt{\the\numexpr \totala+\totalb\relax} lines among them |
| 49776 |
start either with \{\% or with \}\%). \fi |
| 49777 |
Each package starts with circa \dtt{50} lines dealing with catcodes, |
| 49778 |
package identification and reloading management, also for Plain |
| 49779 |
\TeX\strut. |
| 49780 |
|
| 49781 |
\bigskip |
| 49782 |
\def\mymacroaux #1#2#3{#3}% |
| 49783 |
|
| 49784 |
Total number of def'ed (or let'ed) macros: \dtt{\the\numexpr |
| 49785 |
\xintListWithSep+{\xintApply\mymacro\storedlinecounts}\relax }. |
| 49786 |
This is an approximation as some macros are def'ed in a way escaping |
| 49787 |
the automated detection, in particular this applies to |
| 49788 |
\xintexprnameimp macros associated to infix operators and syntax |
| 49789 |
elements, whose construction uses |
| 49790 |
|\csname|-based definitions with a template and auxiliary macros. |
| 49791 |
Their number has |
| 49792 |
been evaluated manually at being at least about \dtt{452} (this is |
| 49793 |
incorporated into the \xintexprnameimp count shown left, and the |
| 49794 |
total above.) |
| 49795 |
|
| 49796 |
\bigskip |
| 49797 |
|
| 49798 |
Version {\xintbndlversion} of {\xintbndldate}.\par |
| 49799 |
\end{minipage} |
| 49800 |
|
| 49801 |
\CheckSum {40137}% 1.4o |
| 49802 |
% 40137 pour 1.4n, 38900 pour 1.4m, 39032 pour 1.4l, |
| 49803 |
% 38925 pour 1.4k, 38590 pour 1.4j, 38591 pour 1.4i, 38427 pour 1.4h |
| 49804 |
% 38423 pour 1.4g, 38212 pour 1.4f, 38813 pour 1.4e, 35184 pour 1.4d |
| 49805 |
% 35109 pour 1.4c, 35103 pour 1.4b, 34648 pour 1.4a, 34575 pour 1.4 |
| 49806 |
% 33497 pour 1.3f, 33274 pour 1.3e, 31601 pour 1.3d, 31122 pour 1.3c |
| 49807 |
% 31069 pour 1.3b, 30482 pour 1.3a, 30621 pour 1.3, 30988 pour 1.2q, |
| 49808 |
% 30982 pour 1.2p, 30524 pour 1.2o, 30303 pour 1.2h, 30403 pour 1.2i, |
| 49809 |
% 30750 pour 1.2j, 30677 pour 1.2k, 30931 pour 1.2l, 30439 pour 1.2m, |
| 49810 |
% 30253 pour 1.2n |
| 49811 |
\makeatletter\check@checksum |
| 49812 |
\Finale |
| 49813 |
%% End of file xint.dtx |