Debian Codegraph @

texmf-dist/source/latex/l3kernel/l3fp-functions.dtx

raw
1 % \iffalse
2 %
3 %% File l3fp-functions.dtx (C) Copyright 2012-2018,2020,2021,2023 The LaTeX Project
4 %
5 % It may be distributed and/or modified under the conditions of the
6 % LaTeX Project Public License (LPPL), either version 1.3c of this
7 % license or (at your option) any later version. The latest version
8 % of this license is in the file
9 %
10 % http://www.latex-project.org/lppl.txt
11 %
12 % This file is part of the "l3kernel bundle" (The Work in LPPL)
13 % and all files in that bundle must be distributed together.
14 %
15 % -----------------------------------------------------------------------
16 %
17 % The development version of the bundle can be found at
18 %
19 % https://github.com/latex3/latex3
20 %
21 % for those people who are interested.
22 %
23 %<*driver>
24 \documentclass[full]{l3doc}
25 \usepackage{amsmath}
26 \begin{document}
27 \DocInput{\jobname.dtx}
28 \end{document}
29 %</driver>
30 % \fi
31 %
32 % \title{^^A
33 % The \pkg{l3fp-functions} module\\ Floating point functions^^A
34 % }
35 %
36 % \author{^^A
37 % The \LaTeX{} Project\thanks
38 % {^^A
39 % E-mail:
40 % \href{mailto:[email protected]}
41 % {[email protected]}^^A
42 % }^^A
43 % }
44 %
45 % \date{Released 2026-05-15}
46 %
47 % \maketitle
48 %
49 % \begin{documentation}
50 %
51 % \end{documentation}
52 %
53 % \begin{implementation}
54 %
55 % \section{\pkg{l3fp-functions} implementation}
56 %
57 % \begin{macrocode}
58 %<*code>
59 % \end{macrocode}
60 %
61 % \begin{macrocode}
62 %<@@=fp>
63 % \end{macrocode}
64 %
65 % \subsection{Declaring functions}
66 %
67 % \begin{macro}{\fp_new_function:n}
68 % \begin{macro}{\@@_new_function:n}
69 % \begin{macrocode}
70 \cs_new_protected:Npn \fp_new_function:n #1
71 { \exp_args:No \@@_new_function:n { \tl_to_str:n {#1} } }
72 \cs_new_protected:Npn \@@_new_function:n #1
73 {
74 \@@_id_if_invalid:nTF {#1}
75 { \msg_error:nnn { fp } { id-invalid } {#1} }
76 {
77 \cs_if_exist:cT { @@_parse_word_#1:N }
78 {
79 \msg_error:nnn
80 { fp } { id-already-defined } {#1}
81 \cs_undefine:c { @@_parse_word_#1:N }
82 \cs_undefine:c { @@_#1_o:w }
83 }
84 \@@_function_set_parsing:Nn \cs_gset_eq:NN {#1}
85 }
86 }
87 % \end{macrocode}
88 % \end{macro}
89 % \end{macro}
90 %
91 % \begin{macro}
92 % {\@@_function_set_parsing:Nn, \@@_function_set_parsing_aux:NNn}
93 % \begin{macrocode}
94 \cs_new_protected:Npn \@@_function_set_parsing:Nn #1#2
95 {
96 \exp_args:NNc \@@_function_set_parsing_aux:NNn #1
97 { @@_parse_word_#2:N } {#2}
98 }
99 \cs_new_protected:Npn \@@_function_set_parsing_aux:NNn #1#2#3
100 {
101 \cs_set:Npe \@@_tmp:w
102 {
103 \exp_not:N \@@_parse_function:NNN
104 \exp_not:N \@@_function_o:w
105 \exp_not:c { @@_#3_o:w }
106 }
107 \cs_if_eq:NNF #2 \@@_tmp:w
108 {
109 \cs_if_exist:NTF #2
110 {
111 \msg_warning:nnnn
112 { fp } { id-used-elsewhere } {#3} { function }
113 #1 #2 \@@_tmp:w
114 }
115 {
116 \cs_new_eq:NN #2 \scan_stop: % to declare the function
117 #1 #2 \@@_tmp:w
118 }
119 }
120 }
121 % \end{macrocode}
122 % \end{macro}
123 %
124 % \begin{macro}[EXP]{\@@_function_o:w}
125 % \begin{macrocode}
126 \cs_new:Npn \@@_function_o:w #1#2 @
127 {
128 \cs_if_exist:NTF #1
129 { #1 #2 @ }
130 {
131 \exp_after:wN \s_@@_symbolic
132 \exp_after:wN \@@_symbolic_chk:w
133 \exp_after:wN \@@_function_o:w
134 \exp_after:wN #1
135 \exp_after:wN ,
136 \exp_after:wN {
137 \exp:w \exp_end_continue_f:w
138 \@@_exp_after_array_f:w #2 \s_@@_expr_stop
139 \exp_after:wN
140 }
141 \exp_after:wN \@@_sep:
142 }
143 }
144 % \end{macrocode}
145 % \end{macro}
146 %
147 % \subsection{Defining functions by their expression}
148 %
149 % \begin{variable}{\l_@@_function_arg_int}
150 % Labels the arguments of a function being defined.
151 % \begin{macrocode}
152 \int_new:N \l_@@_function_arg_int
153 % \end{macrocode}
154 % \end{variable}
155 %
156 % \begin{macro}{\fp_set_function:nnn}
157 % \begin{macro}{\@@_set_function:Nnnn}
158 % \begin{syntax}
159 % \cs{fp_set_function:nnn} \Arg{identifier}
160 % \Arg{comma-list of variables} \Arg{expression}
161 % \end{syntax}
162 % Sets the \meta{identifier} to stand for a function which expects
163 % some arguments defined by the \meta{comma-list of variables}, and
164 % evaluates to the \meta{expression}.
165 % \begin{macrocode}
166 \cs_new_protected:Npn \fp_set_function:nnn #1
167 {
168 \exp_args:NNo \@@_set_function:Nnnn \cs_set_eq:cN
169 { \tl_to_str:n {#1} }
170 }
171 \cs_new_protected:Npn \@@_set_function:Nnnn #1#2#3#4
172 {
173 \@@_id_if_invalid:nTF {#2}
174 { \msg_error:nnn { fp } { id-invalid } {#2} }
175 {
176 \cs_if_exist:cF { @@_parse_word_#2:N }
177 {
178 \msg_error:nnn {fp} { id-undefined } {#2}
179 \@@_function_set_parsing:Nn \cs_set_eq:NN {#2}
180 }
181 \group_begin:
182 \int_zero:N \l_@@_function_arg_int
183 \exp_args:No \clist_map_inline:nn { \tl_to_str:n {#3} }
184 {
185 \int_incr:N \l_@@_function_arg_int
186 \exp_args:Ne \@@_clear_variable_aux:n
187 {
188 \c_underscore_str \tex_romannumeral:D \l_@@_function_arg_int
189 }
190 \fp_clear_variable:n {##1}
191 \cs_set_nopar:cpe { l_@@_variable_##1_fp }
192 {
193 \exp_not:N \s__fp_symbolic
194 \exp_not:N \@@_symbolic_chk:w
195 \exp_not:N \@@_function_arg_o:w
196 \int_use:N \l_@@_function_arg_int
197 ########1 , { } \@@_sep:
198 }
199 }
200 \cs_set:Npn \@@_function_arg_o:w ##1 @
201 {
202 \exp_after:wN \s_@@_symbolic
203 \exp_after:wN \@@_symbolic_chk:w
204 \exp_after:wN \@@_function_arg_o:w
205 \tex_romannumeral:D
206 \@@_exp_after_symbolic_loop:N ##1
207 { , \tex_romannumeral:D \use_none:nn }
208 \exp_after:wN \c_zero_int
209 \exp_after:wN { \exp_after:wN } \exp_after:wN \@@_sep:
210 }
211 \fp_set:Nn \l_@@_symbolic_fp {#4}
212 \use:e
213 {
214 \exp_not:n { \cs_gset:Npn \@@_tmp:w ##1 }
215 { \exp_not:o { \l_@@_symbolic_fp } }
216 }
217 \use:e
218 {
219 \exp_not:n { \cs_gset:Npn \@@_tmp:w ##1 @ }
220 {
221 \exp_not:N \@@_exp_after_symbolic_f:nw
222 \exp_not:n { { \exp_after:wN \exp_stop_f: } }
223 \exp_not:o { \@@_tmp:w { . , {##1} } }
224 }
225 }
226 \group_end:
227 #1 { @@_#2_o:w } \@@_tmp:w
228 }
229 }
230 % \end{macrocode}
231 % \end{macro}
232 %
233 % \begin{macro}[EXP]
234 % {
235 % \@@_function_arg_o:w,
236 % \@@_function_arg_few:w,
237 % \@@_function_arg_get:w
238 % }
239 % \begin{macrocode}
240 \cs_new:Npn \@@_function_arg_o:w #1. #2
241 {
242 \if_meaning:w @ #2
243 \exp_after:wN \@@_function_arg_few:w
244 \fi:
245 \if_int_compare:w #1 = \c_one_int
246 \exp_after:wN \@@_function_arg_get:w
247 \fi:
248 \@@_use_i_until_s:nw
249 {
250 \exp_after:wN \@@_function_arg_o:w
251 \int_value:w \int_eval:n { #1 - 1 } .
252 }
253 #2
254 }
255 \cs_new:Npn \@@_function_arg_few:w #1 @ { \exp_after:wN \c_nan_fp }
256 \cs_new:Npn \@@_function_arg_get:w #1#2#3\@@_sep: #4 @
257 {
258 \@@_exp_after_array_f:w #3\@@_sep: \s_@@_expr_stop
259 \exp_after:wN \exp_stop_f:
260 }
261 % \end{macrocode}
262 % \end{macro}
263 % \end{macro}
264 %
265 % \begin{macro}{\fp_clear_function:n}
266 % \begin{macro}{\@@_clear_function:n}
267 % \begin{macrocode}
268 \cs_new_protected:Npn \fp_clear_function:n #1
269 { \exp_args:No \@@_clear_function:n { \tl_to_str:n {#1} } }
270 \cs_new_protected:Npn \@@_clear_function:n #1
271 {
272 \@@_id_if_invalid:nTF {#1}
273 { \msg_error:nnn { fp } { id-invalid } {#1} }
274 {
275 \cs_set_eq:cN { @@_#1_o:w } \tex_undefine:D
276 \@@_function_set_parsing:Nn \cs_set_eq:NN {#1}
277 }
278 }
279 % \end{macrocode}
280 % \end{macro}
281 % \end{macro}
282 %
283 % ^^A todo: add check for number of args
284 %
285 % \begin{macrocode}
286 %</code>
287 % \end{macrocode}
288 %
289 % \end{implementation}
290 %
291 % \PrintIndex