Debian Codegraph @

texmf-dist/source/latex/l3packages/xfp/xfp.dtx

raw
1 % \iffalse meta-comment
2 %
3 %% File: xfp.dtx
4 %
5 % Copyright (C) 2017-2025 The LaTeX Project
6 %
7 % It may be distributed and/or modified under the conditions of the
8 % LaTeX Project Public License (LPPL), either version 1.3c of this
9 % license or (at your option) any later version. The latest version
10 % of this license is in the file
11 %
12 % https://www.latex-project.org/lppl.txt
13 %
14 % This file is part of the "l3packages bundle" (The Work in LPPL)
15 % and all files in that bundle must be distributed together.
16 %
17 % -----------------------------------------------------------------------
18 %
19 % The development version of the bundle can be found at
20 %
21 % https://github.com/latex3/latex3
22 %
23 % for those people who are interested.
24 %
25 %<*driver|package>
26 % The version of expl3 required is tested as early as possible, as
27 % some really old versions do not define \ProvidesExplPackage.
28 \RequirePackage{expl3}[2018/02/21]
29 %<package>\@ifpackagelater{expl3}{2018/02/21}
30 %<package> {}
31 %<package> {%
32 %<package> \PackageError{xfp}{Support package l3kernel too old}
33 %<package> {%
34 %<package> Please install an up to date version of l3kernel\MessageBreak
35 %<package> using your TeX package manager or from CTAN.\MessageBreak
36 %<package> \MessageBreak
37 %<package> Loading xfp will abort!%
38 %<package> }%
39 %<package> \endinput
40 %<package> }
41 %</driver|package>
42 %<*driver>
43 \documentclass[full]{l3doc}
44 \usepackage{amstext}
45 \begin{document}
46 \DocInput{\jobname.dtx}
47 \end{document}
48 %</driver>
49 % \fi
50 %
51 % \providecommand\nan{\texttt{NaN}}
52 %
53 % \title{^^A
54 % The \pkg{xfp} package\\ Floating Point Unit^^A
55 % }
56 %
57 % \author{^^A
58 % The \LaTeX{} Project\thanks
59 % {^^A
60 % E-mail:
61 % \href{mailto:[email protected]}
62 % {[email protected]}^^A
63 % }^^A
64 % }
65 %
66 % \date{Released 2025-10-09}
67 %
68 % \maketitle
69 %
70 % \begin{documentation}
71 %
72 % The two functions provided by this package are part of the \LaTeX{}
73 % format starting with 2022-06-01 release. This package is
74 % therefore no longer needed and only provided to be able to
75 % process older documents loading.
76 %
77 % This package provides a \LaTeXe{} document-level interface to the \LaTeX{}3
78 % floating point unit (part of \pkg{expl3}). It also provides a parallel
79 % integer expression interface for convenience.
80 %
81 % \begin{function}[EXP]{\fpeval}
82 % The expandable command \cs{fpeval} takes as its argument a floating
83 % point expression and produces a result using the normal rules of
84 % mathematics. As this command is expandable it can be used where \TeX{}
85 % requires a number and for example within a low-level \cs{edef} operation
86 % to give a purely numerical result.
87 % \end{function}
88 %
89 % Briefly, the floating point expressions may comprise:
90 % \begin{itemize}
91 % \item Basic arithmetic: addition $x+y$, subtraction $x-y$,
92 % multiplication $x*y$, division $x/y$, square root~$\sqrt{x}$,
93 % and parentheses.
94 % \item Comparison operators: $x\mathop{\mathtt{<}}y$,
95 % $x\mathop{\mathtt{<=}}y$, $x\mathop{\mathtt{>?}}y$,
96 % $x\mathop{\mathtt{!=}}y$ etc.
97 % \item Boolean logic: sign $\operatorname{sign} x$,
98 % negation $\mathop{!}x$, conjunction
99 % $x\mathop{\&\&}y$, disjunction $x\mathop{\vert\vert}y$, ternary
100 % operator $x\mathop{?}y\mathop{:}z$.
101 % \item Exponentials: $\exp x$, $\ln x$, $x^y$.
102 % \item Integer factorial: $\operatorname{fact} x$.
103 % \item Trigonometry: $\sin x$, $\cos x$, $\tan x$, $\cot x$, $\sec
104 % x$, $\csc x$ expecting their arguments in radians, and
105 % $\operatorname{sind} x$, $\operatorname{cosd} x$,
106 % $\operatorname{tand} x$, $\operatorname{cotd} x$,
107 % $\operatorname{secd} x$, $\operatorname{cscd} x$ expecting their
108 % arguments in degrees.
109 % \item Inverse trigonometric functions: $\operatorname{asin} x$,
110 % $\operatorname{acos} x$, $\operatorname{atan} x$,
111 % $\operatorname{acot} x$, $\operatorname{asec} x$,
112 % $\operatorname{acsc} x$ giving a result in radians, and
113 % $\operatorname{asind} x$, $\operatorname{acosd} x$,
114 % $\operatorname{atand} x$, $\operatorname{acotd} x$,
115 % $\operatorname{asecd} x$, $\operatorname{acscd} x$ giving a result
116 % in degrees.
117 % \item Extrema: $\max(x_{1},x_{2},\ldots)$, $\min(x_{1},x_{2},\ldots)$,
118 % $\operatorname{abs}(x)$.
119 % \item Rounding functions, controlled by two optional
120 % values, $n$ (number of places, $0$ by default) and
121 % $t$ (behavior on a tie, $\nan$ by default):
122 % \begin{itemize}
123 % \item $\operatorname{trunc}(x,n)$ rounds towards zero,
124 % \item $\operatorname{floor}(x,n)$ rounds towards~$-\infty$,
125 % \item $\operatorname{ceil}(x,n)$ rounds towards~$+\infty$,
126 % \item $\operatorname{round}(x,n,t)$ rounds to the closest value, with
127 % ties rounded to an even value by default, towards zero if $t=0$,
128 % towards $+\infty$ if $t>0$ and towards $-\infty$ if $t<0$.
129 % \end{itemize}
130 % \item Random numbers: $\mathop{rand}()$, $\mathop{randint}(m,n)$.
131 % \item Constants: \texttt{pi}, \texttt{deg} (one degree in radians).
132 % \item Dimensions, automatically expressed in points, \emph{e.g.},
133 % \texttt{pc} is~$12$.
134 % \item Automatic conversion (no need for \cs{number}) of
135 % integer, dimension, and skip variables to floating points numbers,
136 % expressing dimensions in points and ignoring the stretch and
137 % shrink components of skips.
138 % \item Tuples: $(x_1,\ldots{},x_n)$ that can be added together,
139 % multiplied or divided by a floating point number, and nested.
140 % \end{itemize}
141 %
142 % An example of use could be the following.
143 % \begin{verbatim}
144 % \LaTeX{} can now compute: $ \frac{\sin (3.5)}{2} + 2\cdot 10^{-3}
145 % = \fpeval{sin(3.5)/2 + 2e-3} $.
146 % \end{verbatim}
147 %
148 % \begin{function}[EXP]{\inteval}
149 % The expandable command \cs{inteval} takes as its argument an integer
150 % expression and produces a result using the normal rules of
151 % mathematics. The operations recognized are |+|, |-|, |*| and |/| plus
152 % parentheses. Division occurs with \emph{rounding}, and ties are rounded
153 % away from zero. As this command is
154 % expandable it can be used where \TeX{} requires a number and for example
155 % within a low-level \cs{edef} operation to give a purely numerical result.
156 % \end{function}
157 %
158 % An example of use could be the following.
159 % \begin{verbatim}
160 % \LaTeX{} can now compute: The sum of the numbers is $\inteval{1 + 2 + 3}$.
161 % \end{verbatim}
162 %
163 % \end{documentation}
164 %
165 % \begin{implementation}
166 %
167 % \section{\pkg{xfp} implementation}
168 %
169 % \begin{macrocode}
170 %<*package>
171 % \end{macrocode}
172 %
173 % \begin{macrocode}
174 \ProvidesExplPackage{xfp}{2025-10-09}{}
175 {L3 Floating point unit}
176 % \end{macrocode}
177 %
178 % \begin{macro}{\fpeval}
179 % A document level wrapper around the code level function. This
180 % definition will be moved to the \LaTeXe{} format so we just
181 % ``provide'' it in case this package gets loaded in documents
182 % processed with a new format.
183 % \begin{macrocode}
184 \ProvideExpandableDocumentCommand \fpeval { m } { \fp_eval:n {#1} }
185 % \end{macrocode}
186 % \end{macro}
187 %
188 % \begin{macro}{\inteval}
189 % A second one, this time around an \eTeX{} primitive.
190 % \begin{macrocode}
191 \ProvideExpandableDocumentCommand \inteval { m } { \int_eval:n {#1} }
192 % \end{macrocode}
193 % \end{macro}
194 %
195 % \begin{macrocode}
196 %</package>
197 % \end{macrocode}
198 %
199 % \end{implementation}
200 %
201 % \PrintIndex