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