Debian Codegraph @

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

raw
1 % \iffalse meta-comment
2 %
3 %% File: l3fp-trig.dtx
4 %
5 % Copyright (C) 2011-2026 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 "l3kernel 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>
26 \documentclass[full,kernel]{l3doc}
27 \begin{document}
28 \DocInput{\jobname.dtx}
29 \end{document}
30 %</driver>
31 % \fi
32 %
33 % \title{^^A
34 % The \pkg{l3fp-trig} module\\
35 % Floating point trigonometric functions^^A
36 % }
37 % \author{^^A
38 % The \LaTeX{} Project\thanks
39 % {^^A
40 % E-mail:
41 % \href{mailto:[email protected]}
42 % {[email protected]}^^A
43 % }^^A
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-trig} implementation}
56 %
57 % \begin{macrocode}
58 %<*code>
59 % \end{macrocode}
60 %
61 % \begin{macrocode}
62 %<@@=fp>
63 % \end{macrocode}
64 %
65 % \begin{macro}[EXP]
66 % {
67 % \@@_parse_word_acos:N ,
68 % \@@_parse_word_acosd:N ,
69 % \@@_parse_word_acsc:N ,
70 % \@@_parse_word_acscd:N ,
71 % \@@_parse_word_asec:N ,
72 % \@@_parse_word_asecd:N ,
73 % \@@_parse_word_asin:N ,
74 % \@@_parse_word_asind:N ,
75 % \@@_parse_word_cos:N ,
76 % \@@_parse_word_cosd:N ,
77 % \@@_parse_word_cot:N ,
78 % \@@_parse_word_cotd:N ,
79 % \@@_parse_word_csc:N ,
80 % \@@_parse_word_cscd:N ,
81 % \@@_parse_word_sec:N ,
82 % \@@_parse_word_secd:N ,
83 % \@@_parse_word_sin:N ,
84 % \@@_parse_word_sind:N ,
85 % \@@_parse_word_tan:N ,
86 % \@@_parse_word_tand:N ,
87 % }
88 % Unary functions.
89 % \begin{macrocode}
90 \tl_map_inline:nn
91 {
92 {acos} {acsc} {asec} {asin}
93 {cos} {cot} {csc} {sec} {sin} {tan}
94 }
95 {
96 \cs_new:cpe { @@_parse_word_#1:N }
97 {
98 \exp_not:N \@@_parse_unary_function:NNN
99 \exp_not:c { @@_#1_o:w }
100 \exp_not:N \use_i:nn
101 }
102 \cs_new:cpe { @@_parse_word_#1d:N }
103 {
104 \exp_not:N \@@_parse_unary_function:NNN
105 \exp_not:c { @@_#1_o:w }
106 \exp_not:N \use_ii:nn
107 }
108 }
109 % \end{macrocode}
110 % \end{macro}
111 %
112 % \begin{macro}[EXP]
113 % {
114 % \@@_parse_word_acot:N , \@@_parse_word_acotd:N,
115 % \@@_parse_word_atan:N , \@@_parse_word_atand:N,
116 % }
117 % Those functions may receive a variable number of arguments.
118 % \begin{macrocode}
119 \cs_new:Npn \@@_parse_word_acot:N
120 { \@@_parse_function:NNN \@@_acot_o:Nw \use_i:nn }
121 \cs_new:Npn \@@_parse_word_acotd:N
122 { \@@_parse_function:NNN \@@_acot_o:Nw \use_ii:nn }
123 \cs_new:Npn \@@_parse_word_atan:N
124 { \@@_parse_function:NNN \@@_atan_o:Nw \use_i:nn }
125 \cs_new:Npn \@@_parse_word_atand:N
126 { \@@_parse_function:NNN \@@_atan_o:Nw \use_ii:nn }
127 % \end{macrocode}
128 % \end{macro}
129 %
130 % \subsection{Direct trigonometric functions}
131 %
132 % The approach for all trigonometric functions (sine, cosine, tangent,
133 % cotangent, cosecant, and secant), with arguments given in radians or
134 % in degrees, is the same.
135 % \begin{itemize}
136 % \item Filter out special cases ($\pm 0$, $\pm\inf$ and \nan{}).
137 % \item Keep the sign for later, and work with the absolute value
138 % $\lvert x\rvert$ of the argument.
139 % \item Small numbers ($\lvert x\rvert<1$ in radians, $\lvert
140 % x\rvert<10$ in degrees) are converted to fixed point numbers (and
141 % to radians if $\lvert x\rvert$ is in degrees).
142 % \item For larger numbers, we need argument reduction. Subtract a
143 % multiple of $\pi/2$ (in degrees,~$90$) to bring the number to the
144 % range to $[0, \pi/2)$ (in degrees, $[0,90)$).
145 % \item Reduce further to $[0, \pi/4]$ (in degrees, $[0,45]$) using
146 % $\sin x = \cos (\pi/2-x)$, and when working in degrees, convert to
147 % radians.
148 % \item Use the appropriate power series depending on the octant
149 % $\lfloor\frac{|x|}{\pi/4}\rfloor \mod 8$ (in degrees, the same
150 % formula with $\pi/4\to 45$), the sign, and the function to
151 % compute.
152 % \end{itemize}
153 %
154 % \subsubsection{Filtering special cases}
155 %
156 % \begin{macro}[EXP]{\@@_sin_o:w}
157 % This function, and its analogs for \texttt{cos}, \texttt{csc},
158 % \texttt{sec}, \texttt{tan}, and \texttt{cot} instead of
159 % \texttt{sin}, are followed either by \cs{use_i:nn} and a float in
160 % radians or by \cs{use_ii:nn} and a float in degrees. The sine of
161 % $\pm 0$ or \nan{} is the same float. The sine of $\pm\infty$ raises
162 % an invalid operation exception with the appropriate function name.
163 % Otherwise, call the \texttt{trig} function to perform argument
164 % reduction and if necessary convert the reduced argument to radians.
165 % Then, \cs{@@_sin_series_o:NNwwww} is called to compute the
166 % Taylor series: this function receives a sign~|#3|, an initial octant
167 % of~$0$, and the function \cs{@@_ep_to_float_o:wwN} which converts the
168 % result of the series to a floating point directly rather than taking
169 % its inverse, since $\sin(x) = \#3 \sin\lvert x\rvert$.
170 % \begin{macrocode}
171 \cs_new:Npn \@@_sin_o:w #1 \s_@@ \@@_chk:w #2#3#4\@@_sep: @
172 {
173 \if_case:w #2 \exp_stop_f:
174 \@@_case_return_same_o:w
175 \or: \@@_case_use:nw
176 {
177 \@@_trig:NNNNNwn #1 \@@_sin_series_o:NNwwww
178 \@@_ep_to_float_o:wwN #3 0
179 }
180 \or: \@@_case_use:nw
181 { \@@_invalid_operation_o:fw { #1 { sin } { sind } } }
182 \else: \@@_case_return_same_o:w
183 \fi:
184 \s_@@ \@@_chk:w #2 #3 #4\@@_sep:
185 }
186 % \end{macrocode}
187 % \end{macro}
188 %
189 % \begin{macro}[EXP]{\@@_cos_o:w}
190 % The cosine of $\pm 0$ is $1$. The cosine of $\pm\infty$ raises an
191 % invalid operation exception. The cosine of \nan{} is itself.
192 % Otherwise, the \texttt{trig} function reduces the argument to at
193 % most half a right-angle and converts if necessary to radians. We
194 % then call the same series as for sine, but using a positive
195 % sign~|0| regardless of the sign of~$x$, and with an initial octant
196 % of~$2$, because $\cos(x) = + \sin(\pi/2 + \lvert x\rvert)$.
197 % \begin{macrocode}
198 \cs_new:Npn \@@_cos_o:w #1 \s_@@ \@@_chk:w #2#3\@@_sep: @
199 {
200 \if_case:w #2 \exp_stop_f:
201 \@@_case_return_o:Nw \c_one_fp
202 \or: \@@_case_use:nw
203 {
204 \@@_trig:NNNNNwn #1 \@@_sin_series_o:NNwwww
205 \@@_ep_to_float_o:wwN 0 2
206 }
207 \or: \@@_case_use:nw
208 { \@@_invalid_operation_o:fw { #1 { cos } { cosd } } }
209 \else: \@@_case_return_same_o:w
210 \fi:
211 \s_@@ \@@_chk:w #2 #3\@@_sep:
212 }
213 % \end{macrocode}
214 % \end{macro}
215 %
216 % \begin{macro}[EXP]{\@@_csc_o:w}
217 % The cosecant of $\pm 0$ is $\pm \infty$ with the same sign, with a
218 % division by zero exception (see \cs{@@_cot_zero_o:Nfw} defined
219 % below), which requires the function name. The cosecant of
220 % $\pm\infty$ raises an invalid operation exception. The cosecant of
221 % \nan{} is itself. Otherwise, the \texttt{trig} function performs
222 % the argument reduction, and converts if necessary to radians before
223 % calling the same series as for sine, using the sign~|#3|, a starting
224 % octant of~$0$, and inverting during the conversion from the fixed
225 % point sine to the floating point result, because $\csc(x) = \#3
226 % \big( \sin\lvert x\rvert\big)^{-1}$.
227 % \begin{macrocode}
228 \cs_new:Npn \@@_csc_o:w #1 \s_@@ \@@_chk:w #2#3#4\@@_sep: @
229 {
230 \if_case:w #2 \exp_stop_f:
231 \@@_cot_zero_o:Nfw #3 { #1 { csc } { cscd } }
232 \or: \@@_case_use:nw
233 {
234 \@@_trig:NNNNNwn #1 \@@_sin_series_o:NNwwww
235 \@@_ep_inv_to_float_o:wwN #3 0
236 }
237 \or: \@@_case_use:nw
238 { \@@_invalid_operation_o:fw { #1 { csc } { cscd } } }
239 \else: \@@_case_return_same_o:w
240 \fi:
241 \s_@@ \@@_chk:w #2 #3 #4\@@_sep:
242 }
243 % \end{macrocode}
244 % \end{macro}
245 %
246 % \begin{macro}[EXP]{\@@_sec_o:w}
247 % The secant of $\pm 0$ is $1$. The secant of $\pm \infty$ raises an
248 % invalid operation exception. The secant of \nan{} is itself.
249 % Otherwise, the \texttt{trig} function reduces the argument and turns
250 % it to radians before calling the same series as for sine, using a
251 % positive sign~$0$, a starting octant of~$2$, and inverting upon
252 % conversion, because $\sec(x) = + 1 / \sin(\pi/2 + \lvert x\rvert)$.
253 % \begin{macrocode}
254 \cs_new:Npn \@@_sec_o:w #1 \s_@@ \@@_chk:w #2#3\@@_sep: @
255 {
256 \if_case:w #2 \exp_stop_f:
257 \@@_case_return_o:Nw \c_one_fp
258 \or: \@@_case_use:nw
259 {
260 \@@_trig:NNNNNwn #1 \@@_sin_series_o:NNwwww
261 \@@_ep_inv_to_float_o:wwN 0 2
262 }
263 \or: \@@_case_use:nw
264 { \@@_invalid_operation_o:fw { #1 { sec } { secd } } }
265 \else: \@@_case_return_same_o:w
266 \fi:
267 \s_@@ \@@_chk:w #2 #3\@@_sep:
268 }
269 % \end{macrocode}
270 % \end{macro}
271 %
272 % \begin{macro}[EXP]{\@@_tan_o:w}
273 % The tangent of $\pm 0$ or \nan{} is the same floating point number.
274 % The tangent of $\pm\infty$ raises an invalid operation exception.
275 % Once more, the \texttt{trig} function does the argument reduction
276 % step and conversion to radians before calling
277 % \cs{@@_tan_series_o:NNwwww}, with a sign~|#3| and an initial octant
278 % of~$1$ (this shift is somewhat arbitrary). See \cs{@@_cot_o:w} for
279 % an explanation of the $0$~argument.
280 % \begin{macrocode}
281 \cs_new:Npn \@@_tan_o:w #1 \s_@@ \@@_chk:w #2#3#4\@@_sep: @
282 {
283 \if_case:w #2 \exp_stop_f:
284 \@@_case_return_same_o:w
285 \or: \@@_case_use:nw
286 {
287 \@@_trig:NNNNNwn #1
288 \@@_tan_series_o:NNwwww 0 #3 1
289 }
290 \or: \@@_case_use:nw
291 { \@@_invalid_operation_o:fw { #1 { tan } { tand } } }
292 \else: \@@_case_return_same_o:w
293 \fi:
294 \s_@@ \@@_chk:w #2 #3 #4\@@_sep:
295 }
296 % \end{macrocode}
297 % \end{macro}
298 %
299 % \begin{macro}[EXP]{\@@_cot_o:w}
300 % \begin{macro}[EXP]{\@@_cot_zero_o:Nfw}
301 % The cotangent of $\pm 0$ is $\pm \infty$ with the same sign, with a
302 % division by zero exception (see \cs{@@_cot_zero_o:Nfw}. The
303 % cotangent of $\pm\infty$ raises an invalid operation exception. The
304 % cotangent of \nan{} is itself. We use $\cot x = - \tan (\pi/2 +
305 % x)$, and the initial octant for the tangent was chosen to be $1$, so
306 % the octant here starts at $3$. The change in sign is obtained by
307 % feeding \cs{@@_tan_series_o:NNwwww} two signs rather than just the
308 % sign of the argument: the first of those indicates whether we
309 % compute tangent or cotangent. Those signs are eventually combined.
310 % \begin{macrocode}
311 \cs_new:Npn \@@_cot_o:w #1 \s_@@ \@@_chk:w #2#3#4\@@_sep: @
312 {
313 \if_case:w #2 \exp_stop_f:
314 \@@_cot_zero_o:Nfw #3 { #1 { cot } { cotd } }
315 \or: \@@_case_use:nw
316 {
317 \@@_trig:NNNNNwn #1
318 \@@_tan_series_o:NNwwww 2 #3 3
319 }
320 \or: \@@_case_use:nw
321 { \@@_invalid_operation_o:fw { #1 { cot } { cotd } } }
322 \else: \@@_case_return_same_o:w
323 \fi:
324 \s_@@ \@@_chk:w #2 #3 #4\@@_sep:
325 }
326 \cs_new:Npn \@@_cot_zero_o:Nfw #1#2#3 \fi:
327 {
328 \fi:
329 \token_if_eq_meaning:NNTF 0 #1
330 { \exp_args:NNf \@@_division_by_zero_o:Nnw \c_inf_fp }
331 { \exp_args:NNf \@@_division_by_zero_o:Nnw \c_minus_inf_fp }
332 {#2}
333 }
334 % \end{macrocode}
335 % \end{macro}
336 % \end{macro}
337 %
338 % \subsubsection{Distinguishing small and large arguments}
339 %
340 % \begin{macro}[EXP]{\@@_trig:NNNNNwn}
341 % The first argument is \cs{use_i:nn} if the operand is in radians and
342 % \cs{use_ii:nn} if it is in degrees. Arguments |#2| to~|#5| control
343 % what trigonometric function we compute, and |#6| to~|#8| are pieces
344 % of a normal floating point number. Call the \texttt{_series}
345 % function~|#2|, with arguments |#3|, either a conversion function
346 % (\cs{@@_ep_to_float_o:wN} or \cs{@@_ep_inv_to_float_o:wN}) or a sign $0$
347 % or~$2$ when computing tangent or cotangent; |#4|, a sign $0$ or~$2$;
348 % the octant, computed in an integer expression starting with~|#5| and
349 % stopped by a period; and a fixed point number obtained from the
350 % floating point number by argument reduction (if necessary) and
351 % conversion to radians (if necessary). Any argument reduction
352 % adjusts the octant accordingly by leaving a (positive) shift into
353 % its integer expression. Let us explain the integer comparison. Two
354 % of the four \cs{exp_after:wN} are expanded, the expansion hits the
355 % test, which is true if the float is at least~$1$ when working in
356 % radians, and at least $10$ when working in degrees. Then one of the
357 % remaining \cs{exp_after:wN} hits |#1|, which picks the \texttt{trig}
358 % or \texttt{trigd} function in whichever branch of the conditional
359 % was taken. The final \cs{exp_after:wN} closes the conditional. At
360 % the end of the day, a number is \texttt{large} if it is $\geq 1$ in
361 % radians or $\geq 10$ in degrees, and \texttt{small} otherwise. All
362 % four \texttt{trig}/\texttt{trigd} auxiliaries receive the operand as
363 % an extended-precision number.
364 % \begin{macrocode}
365 \cs_new:Npn \@@_trig:NNNNNwn #1#2#3#4#5 \s_@@ \@@_chk:w 1#6#7#8\@@_sep:
366 {
367 \exp_after:wN #2
368 \exp_after:wN #3
369 \exp_after:wN #4
370 \int_value:w \@@_int_eval:w #5
371 \exp_after:wN \exp_after:wN \exp_after:wN \exp_after:wN
372 \if_int_compare:w #7 > #1 0 1 \exp_stop_f:
373 #1 \@@_trig_large:ww \@@_trigd_large:ww
374 \else:
375 #1 \@@_trig_small:ww \@@_trigd_small:ww
376 \fi:
377 #7,#8{0000}{0000}\@@_sep:
378 }
379 % \end{macrocode}
380 % \end{macro}
381 %
382 % \subsubsection{Small arguments}
383 %
384 % \begin{macro}[EXP]{\@@_trig_small:ww}
385 % This receives a small extended-precision number in radians and
386 % converts it to a fixed point number. Some trailing digits may be
387 % lost in the conversion, so we keep the original floating point
388 % number around: when computing sine or tangent (or their inverses),
389 % the last step is to multiply by the floating point number (as
390 % an extended-precision number) rather than the fixed point number.
391 % The period serves to end the integer expression for the octant.
392 % \begin{macrocode}
393 \cs_new:Npn \@@_trig_small:ww #1,#2\@@_sep:
394 { \@@_ep_to_fixed:wwn #1,#2\@@_sep: . #1,#2\@@_sep: }
395 % \end{macrocode}
396 % \end{macro}
397 %
398 % \begin{macro}[EXP]{\@@_trigd_small:ww}
399 % Convert the extended-precision number to radians, then call
400 % \cs{@@_trig_small:ww} to massage it in the form appropriate for the
401 % \texttt{_series} auxiliary.
402 % \begin{macrocode}
403 \cs_new:Npn \@@_trigd_small:ww #1,#2\@@_sep:
404 {
405 \@@_ep_mul_raw:wwwwN
406 -1,{1745}{3292}{5199}{4329}{5769}{2369}\@@_sep: #1,#2\@@_sep:
407 \@@_trig_small:ww
408 }
409 % \end{macrocode}
410 % \end{macro}
411 %
412 % \subsubsection{Argument reduction in degrees}
413 %
414 % \begin{macro}[rEXP]
415 % {
416 % \@@_trigd_large:ww, \@@_trigd_large_auxi:nnnnwNNNN,
417 % \@@_trigd_large_auxii:wNw, \@@_trigd_large_auxiii:www
418 % }
419 % Note that $25\times 360 = 9000$, so $10^{k+1} \equiv 10^{k}
420 % \pmod{360}$ for $k\geq 3$. When the exponent~|#1| is very large, we
421 % can thus safely replace it by~$22$ (or even~$19$). We turn the
422 % floating point number into a fixed point number with two blocks of
423 % $8$~digits followed by five blocks of $4$~digits. The original
424 % float is $100\times\meta{block_1}\cdots\meta{block_3}.
425 % \meta{block_4}\cdots\meta{block_7}$, or is equal to it modulo~$360$
426 % if the exponent~|#1| is very large. The first auxiliary finds
427 % $\meta{block_1} + \meta{block_2} \pmod{9}$, a single digit, and
428 % prepends it to the $4$~digits of \meta{block_3}. It also unpacks
429 % \meta{block_4} and grabs the $4$~digits of \meta{block_7}. The
430 % second auxiliary grabs the \meta{block_3} plus any contribution from
431 % the first two blocks as~|#1|, the first digit of \meta{block_4}
432 % (just after the decimal point in hundreds of degrees) as~|#2|, and
433 % the three other digits as~|#3|. It finds the quotient and remainder
434 % of |#1#2| modulo~$9$, adds twice the quotient to the integer
435 % expression for the octant, and places the remainder (between $0$
436 % and~$8$) before |#3| to form a new \meta{block_4}. The resulting
437 % fixed point number is $x\in [0, 0.9]$. If $x\geq 0.45$, we add~$1$
438 % to the octant and feed $0.9-x$ with an exponent of~$2$ (to
439 % compensate the fact that we are working in units of hundreds of
440 % degrees rather than degrees) to \cs{@@_trigd_small:ww}. Otherwise,
441 % we feed it~$x$ with an exponent of~$2$. The third auxiliary also
442 % discards digits which were not packed into the various
443 % \meta{blocks}. Since the original exponent~|#1| is at least~$2$,
444 % those are all~$0$ and no precision is lost (|#6| and~|#7| are
445 % four~$0$ each).
446 % \begin{macrocode}
447 \cs_new:Npn \@@_trigd_large:ww #1, #2#3#4#5#6#7\@@_sep:
448 {
449 \exp_after:wN \@@_pack_eight:wNNNNNNNN
450 \exp_after:wN \@@_pack_eight:wNNNNNNNN
451 \exp_after:wN \@@_pack_twice_four:wNNNNNNNN
452 \exp_after:wN \@@_pack_twice_four:wNNNNNNNN
453 \exp_after:wN \@@_trigd_large_auxi:nnnnwNNNN
454 \exp_after:wN \@@_sep:
455 \exp:w \exp_end_continue_f:w
456 \prg_replicate:nn { \int_max:nn { 22 - #1 } { 0 } } { 0 }
457 #2#3#4#5#6#7 0000 0000 0000 !
458 }
459 \cs_new:Npn \@@_trigd_large_auxi:nnnnwNNNN #1#2#3#4#5\@@_sep: #6#7#8#9
460 {
461 \exp_after:wN \@@_trigd_large_auxii:wNw
462 \int_value:w \@@_int_eval:w #1 + #2
463 - (#1 + #2 - 4) / 9 * 9 \@@_int_eval_end:
464 #3\@@_sep:
465 #4\@@_sep: #5{#6#7#8#9}\@@_sep:
466 }
467 \cs_new:Npn \@@_trigd_large_auxii:wNw #1\@@_sep: #2#3\@@_sep:
468 {
469 + (#1#2 - 4) / 9 * 2
470 \exp_after:wN \@@_trigd_large_auxiii:www
471 \int_value:w \@@_int_eval:w #1#2
472 - (#1#2 - 4) / 9 * 9 \@@_int_eval_end: #3 \@@_sep:
473 }
474 \cs_new:Npn \@@_trigd_large_auxiii:www #1\@@_sep: #2\@@_sep: #3!
475 {
476 \if_int_compare:w #1 < 4500 \exp_stop_f:
477 \exp_after:wN \@@_use_i_until_s:nw
478 \exp_after:wN \@@_fixed_continue:wn
479 \else:
480 + 1
481 \fi:
482 \@@_fixed_sub:wwn {9000}{0000}{0000}{0000}{0000}{0000}\@@_sep:
483 {#1}#2{0000}{0000}\@@_sep:
484 { \@@_trigd_small:ww 2, }
485 }
486 % \end{macrocode}
487 % \end{macro}
488 %
489 % \subsubsection{Argument reduction in radians}
490 %
491 % Arguments greater or equal to~$1$ need to be reduced to a range where
492 % we only need a few terms of the Taylor series. We reduce to the range
493 % $[0,2\pi]$ by subtracting multiples of~$2\pi$, then to the smaller
494 % range $[0,\pi/2]$ by subtracting multiples of~$\pi/2$ (keeping track
495 % of how many times~$\pi/2$ is subtracted), then to $[0,\pi/4]$ by
496 % mapping $x\to \pi/2 - x$ if appropriate. When the argument is very
497 % large, say, $10^{100}$, an equally large multiple of~$2\pi$ must be
498 % subtracted, hence we must work with a very good approximation
499 % of~$2\pi$ in order to get a sensible remainder modulo~$2\pi$.
500 %
501 % Specifically, we multiply the argument by an approximation
502 % of~$1/(2\pi)$ with $\ExplSyntaxOn\int_eval:n { \c__fp_max_exponent_int
503 % + 48 }\ExplSyntaxOff$~digits, then discard the integer part of the
504 % result, keeping $52$~digits of the fractional part. From the
505 % fractional part of $x/(2\pi)$ we deduce the octant (quotient of the
506 % first three digits by~$125$). We then multiply by $8$ or~$-8$ (the
507 % latter when the octant is odd), ignore any integer part (related to
508 % the octant), and convert the fractional part to an extended precision
509 % number, before multiplying by~$\pi/4$ to convert back to a value in
510 % radians in $[0,\pi/4]$.
511 %
512 % It is possible to prove that given the precision of floating points
513 % and their range of exponents, the $52$~digits may start at most with
514 % $24$~zeros. The $5$~last digits are affected by carries from
515 % computations which are not done, hence we are left with at least $52 -
516 % 24 - 5 = 23$ significant digits, enough to round correctly up to
517 % $0.6\cdot\text{ulp}$ in all cases.
518 %
519 % \begin{variable}[EXP]{\c_@@_trig_intarray}
520 % This integer array stores blocks of $8$~decimals of
521 % $10^{-16}/(2\pi)$. Each entry is $10^8$ plus an $8$~digit number
522 % storing $8$ decimals. In total we store $10112$~decimals of
523 % $10^{-16}/(2\pi)$. The number of decimals we really need is the
524 % maximum exponent plus the number of digits we later need,~$52$,
525 % plus~$12$ ($4-1$~groups of $4$~digits). The memory footprint ($1/2$
526 % byte per digit) is the same as an earlier method of storing the data
527 % as a control sequence name, but the major advantage is that we can
528 % unpack specific subsets of the digits without unpacking the $10112$
529 % decimals.
530 % \begin{macrocode}
531 \intarray_const_from_clist:Nn \c_@@_trig_intarray
532 {
533 100000000, 100000000, 115915494, 130918953, 135768883, 176337251,
534 143620344, 159645740, 145644874, 176673440, 158896797, 163422653,
535 150901138, 102766253, 108595607, 128427267, 157958036, 189291184,
536 161145786, 152877967, 141073169, 198392292, 139966937, 140907757,
537 130777463, 196925307, 168871739, 128962173, 197661693, 136239024,
538 117236290, 111832380, 111422269, 197557159, 140461890, 108690267,
539 139561204, 189410936, 193784408, 155287230, 199946443, 140024867,
540 123477394, 159610898, 132309678, 130749061, 166986462, 180469944,
541 186521878, 181574786, 156696424, 110389958, 174139348, 160998386,
542 180991999, 162442875, 158517117, 188584311, 117518767, 116054654,
543 175369880, 109739460, 136475933, 137680593, 102494496, 163530532,
544 171567755, 103220324, 177781639, 171660229, 146748119, 159816584,
545 106060168, 103035998, 113391198, 174988327, 186654435, 127975507,
546 100162406, 177564388, 184957131, 108801221, 199376147, 168137776,
547 147378906, 133068046, 145797848, 117613124, 127314069, 196077502,
548 145002977, 159857089, 105690279, 167851315, 125210016, 131774602,
549 109248116, 106240561, 145620314, 164840892, 148459191, 143521157,
550 154075562, 100871526, 160680221, 171591407, 157474582, 172259774,
551 162853998, 175155329, 139081398, 117724093, 158254797, 107332871,
552 190406999, 175907657, 170784934, 170393589, 182808717, 134256403,
553 166895116, 162545705, 194332763, 112686500, 126122717, 197115321,
554 112599504, 138667945, 103762556, 108363171, 116952597, 158128224,
555 194162333, 143145106, 112353687, 185631136, 136692167, 114206974,
556 169601292, 150578336, 105311960, 185945098, 139556718, 170995474,
557 165104316, 123815517, 158083944, 129799709, 199505254, 138756612,
558 194458833, 106846050, 178529151, 151410404, 189298850, 163881607,
559 176196993, 107341038, 199957869, 118905980, 193737772, 106187543,
560 122271893, 101366255, 126123878, 103875388, 181106814, 106765434,
561 108282785, 126933426, 179955607, 107903860, 160352738, 199624512,
562 159957492, 176297023, 159409558, 143011648, 129641185, 157771240,
563 157544494, 157021789, 176979240, 194903272, 194770216, 164960356,
564 153181535, 144003840, 168987471, 176915887, 163190966, 150696440,
565 147769706, 187683656, 177810477, 197954503, 153395758, 130188183,
566 186879377, 166124814, 195305996, 155802190, 183598751, 103512712,
567 190432315, 180498719, 168687775, 194656634, 162210342, 104440855,
568 149785037, 192738694, 129353661, 193778292, 187359378, 143470323,
569 102371458, 137923557, 111863634, 119294601, 183182291, 196416500,
570 187830793, 131353497, 179099745, 186492902, 167450609, 189368909,
571 145883050, 133703053, 180547312, 132158094, 131976760, 132283131,
572 141898097, 149822438, 133517435, 169898475, 101039500, 168388003,
573 197867235, 199608024, 100273901, 108749548, 154787923, 156826113,
574 199489032, 168997427, 108349611, 149208289, 103776784, 174303550,
575 145684560, 183671479, 130845672, 133270354, 185392556, 120208683,
576 193240995, 162211753, 131839402, 109707935, 170774965, 149880868,
577 160663609, 168661967, 103747454, 121028312, 119251846, 122483499,
578 111611495, 166556037, 196967613, 199312829, 196077608, 127799010,
579 107830360, 102338272, 198790854, 102387615, 157445430, 192601191,
580 100543379, 198389046, 154921248, 129516070, 172853005, 122721023,
581 160175233, 113173179, 175931105, 103281551, 109373913, 163964530,
582 157926071, 180083617, 195487672, 146459804, 173977292, 144810920,
583 109371257, 186918332, 189588628, 139904358, 168666639, 175673445,
584 114095036, 137327191, 174311388, 106638307, 125923027, 159734506,
585 105482127, 178037065, 133778303, 121709877, 134966568, 149080032,
586 169885067, 141791464, 168350828, 116168533, 114336160, 173099514,
587 198531198, 119733758, 144420984, 116559541, 152250643, 139431286,
588 144403838, 183561508, 179771645, 101706470, 167518774, 156059160,
589 187168578, 157939226, 123475633, 117111329, 198655941, 159689071,
590 198506887, 144230057, 151919770, 156900382, 118392562, 120338742,
591 135362568, 108354156, 151729710, 188117217, 195936832, 156488518,
592 174997487, 108553116, 159830610, 113921445, 144601614, 188452770,
593 125114110, 170248521, 173974510, 138667364, 103872860, 109967489,
594 131735618, 112071174, 104788993, 168886556, 192307848, 150230570,
595 157144063, 163863202, 136852010, 174100574, 185922811, 115721968,
596 100397824, 175953001, 166958522, 112303464, 118773650, 143546764,
597 164565659, 171901123, 108476709, 193097085, 191283646, 166919177,
598 169387914, 133315566, 150669813, 121641521, 100895711, 172862384,
599 126070678, 145176011, 113450800, 169947684, 122356989, 162488051,
600 157759809, 153397080, 185475059, 175362656, 149034394, 145420581,
601 178864356, 183042000, 131509559, 147434392, 152544850, 167491429,
602 108647514, 142303321, 133245695, 111634945, 167753939, 142403609,
603 105438335, 152829243, 142203494, 184366151, 146632286, 102477666,
604 166049531, 140657343, 157553014, 109082798, 180914786, 169343492,
605 127376026, 134997829, 195701816, 119643212, 133140475, 176289748,
606 140828911, 174097478, 126378991, 181699939, 148749771, 151989818,
607 172666294, 160183053, 195832752, 109236350, 168538892, 128468247,
608 125997252, 183007668, 156937583, 165972291, 198244297, 147406163,
609 181831139, 158306744, 134851692, 185973832, 137392662, 140243450,
610 119978099, 140402189, 161348342, 173613676, 144991382, 171541660,
611 163424829, 136374185, 106122610, 186132119, 198633462, 184709941,
612 183994274, 129559156, 128333990, 148038211, 175011612, 111667205,
613 119125793, 103552929, 124113440, 131161341, 112495318, 138592695,
614 184904438, 146807849, 109739828, 108855297, 104515305, 139914009,
615 188698840, 188365483, 166522246, 168624087, 125401404, 100911787,
616 142122045, 123075334, 173972538, 114940388, 141905868, 142311594,
617 163227443, 139066125, 116239310, 162831953, 123883392, 113153455,
618 163815117, 152035108, 174595582, 101123754, 135976815, 153401874,
619 107394340, 136339780, 138817210, 104531691, 182951948, 179591767,
620 139541778, 179243527, 161740724, 160593916, 102732282, 187946819,
621 136491289, 149714953, 143255272, 135916592, 198072479, 198580612,
622 169007332, 118844526, 179433504, 155801952, 149256630, 162048766,
623 116134365, 133992028, 175452085, 155344144, 109905129, 182727454,
624 165911813, 122232840, 151166615, 165070983, 175574337, 129548631,
625 120411217, 116380915, 160616116, 157320000, 183306114, 160618128,
626 103262586, 195951602, 146321661, 138576614, 180471993, 127077713,
627 116441201, 159496011, 106328305, 120759583, 148503050, 179095584,
628 198298218, 167402898, 138551383, 123957020, 180763975, 150429225,
629 198476470, 171016426, 197438450, 143091658, 164528360, 132493360,
630 143546572, 137557916, 113663241, 120457809, 196971566, 134022158,
631 180545794, 131328278, 100552461, 132088901, 187421210, 192448910,
632 141005215, 149680971, 113720754, 100571096, 134066431, 135745439,
633 191597694, 135788920, 179342561, 177830222, 137011486, 142492523,
634 192487287, 113132021, 176673607, 156645598, 127260957, 141566023,
635 143787436, 129132109, 174858971, 150713073, 191040726, 143541417,
636 197057222, 165479803, 181512759, 157912400, 125344680, 148220261,
637 173422990, 101020483, 106246303, 137964746, 178190501, 181183037,
638 151538028, 179523433, 141955021, 135689770, 191290561, 143178787,
639 192086205, 174499925, 178975690, 118492103, 124206471, 138519113,
640 188147564, 102097605, 154895793, 178514140, 141453051, 151583964,
641 128232654, 106020603, 131189158, 165702720, 186250269, 191639375,
642 115278873, 160608114, 155694842, 110322407, 177272742, 116513642,
643 134366992, 171634030, 194053074, 180652685, 109301658, 192136921,
644 141431293, 171341061, 157153714, 106203978, 147618426, 150297807,
645 186062669, 169960809, 118422347, 163350477, 146719017, 145045144,
646 161663828, 146208240, 186735951, 102371302, 190444377, 194085350,
647 134454426, 133413062, 163074595, 113830310, 122931469, 134466832,
648 185176632, 182415152, 110179422, 164439571, 181217170, 121756492,
649 119644493, 196532222, 118765848, 182445119, 109401340, 150443213,
650 198586286, 121083179, 139396084, 143898019, 114787389, 177233102,
651 186310131, 148695521, 126205182, 178063494, 157118662, 177825659,
652 188310053, 151552316, 165984394, 109022180, 163144545, 121212978,
653 197344714, 188741258, 126822386, 102360271, 109981191, 152056882,
654 134723983, 158013366, 106837863, 128867928, 161973236, 172536066,
655 185216856, 132011948, 197807339, 158419190, 166595838, 167852941,
656 124187182, 117279875, 106103946, 106481958, 157456200, 160892122,
657 184163943, 173846549, 158993202, 184812364, 133466119, 170732430,
658 195458590, 173361878, 162906318, 150165106, 126757685, 112163575,
659 188696307, 145199922, 100107766, 176830946, 198149756, 122682434,
660 179367131, 108412102, 119520899, 148191244, 140487511, 171059184,
661 141399078, 189455775, 118462161, 190415309, 134543802, 180893862,
662 180732375, 178615267, 179711433, 123241969, 185780563, 176301808,
663 184386640, 160717536, 183213626, 129671224, 126094285, 140110963,
664 121826276, 151201170, 122552929, 128965559, 146082049, 138409069,
665 107606920, 103954646, 119164002, 115673360, 117909631, 187289199,
666 186343410, 186903200, 157966371, 103128612, 135698881, 176403642,
667 152540837, 109810814, 183519031, 121318624, 172281810, 150845123,
668 169019064, 166322359, 138872454, 163073727, 128087898, 130041018,
669 194859136, 173742589, 141812405, 167291912, 138003306, 134499821,
670 196315803, 186381054, 124578934, 150084553, 128031351, 118843410,
671 107373060, 159565443, 173624887, 171292628, 198074235, 139074061,
672 178690578, 144431052, 174262641, 176783005, 182214864, 162289361,
673 192966929, 192033046, 169332843, 181580535, 164864073, 118444059,
674 195496893, 153773183, 167266131, 130108623, 158802128, 180432893,
675 144562140, 147978945, 142337360, 158506327, 104399819, 132635916,
676 168734194, 136567839, 101281912, 120281622, 195003330, 112236091,
677 185875592, 101959081, 122415367, 194990954, 148881099, 175891989,
678 108115811, 163538891, 163394029, 123722049, 184837522, 142362091,
679 100834097, 156679171, 100841679, 157022331, 178971071, 102928884,
680 189701309, 195339954, 124415335, 106062584, 139214524, 133864640,
681 134324406, 157317477, 155340540, 144810061, 177612569, 108474646,
682 114329765, 143900008, 138265211, 145210162, 136643111, 197987319,
683 102751191, 144121361, 169620456, 193602633, 161023559, 162140467,
684 102901215, 167964187, 135746835, 187317233, 110047459, 163339773,
685 124770449, 118885134, 141536376, 100915375, 164267438, 145016622,
686 113937193, 106748706, 128815954, 164819775, 119220771, 102367432,
687 189062690, 170911791, 194127762, 112245117, 123546771, 115640433,
688 135772061, 166615646, 174474627, 130562291, 133320309, 153340551,
689 138417181, 194605321, 150142632, 180008795, 151813296, 175497284,
690 167018836, 157425342, 150169942, 131069156, 134310662, 160434122,
691 105213831, 158797111, 150754540, 163290657, 102484886, 148697402,
692 187203725, 198692811, 149360627, 140384233, 128749423, 132178578,
693 177507355, 171857043, 178737969, 134023369, 102911446, 196144864,
694 197697194, 134527467, 144296030, 189437192, 154052665, 188907106,
695 162062575, 150993037, 199766583, 167936112, 181374511, 104971506,
696 115378374, 135795558, 167972129, 135876446, 130937572, 103221320,
697 124605656, 161129971, 131027586, 191128460, 143251843, 143269155,
698 129284585, 173495971, 150425653, 199302112, 118494723, 121323805,
699 116549802, 190991967, 168151180, 122483192, 151273721, 199792134,
700 133106764, 121874844, 126215985, 112167639, 167793529, 182985195,
701 185453921, 106957880, 158685312, 132775454, 133229161, 198905318,
702 190537253, 191582222, 192325972, 178133427, 181825606, 148823337,
703 160719681, 101448145, 131983362, 137910767, 112550175, 128826351,
704 183649210, 135725874, 110356573, 189469487, 154446940, 118175923,
705 106093708, 128146501, 185742532, 149692127, 164624247, 183221076,
706 154737505, 168198834, 156410354, 158027261, 125228550, 131543250,
707 139591848, 191898263, 104987591, 115406321, 103542638, 190012837,
708 142615518, 178773183, 175862355, 117537850, 169565995, 170028011,
709 158412588, 170150030, 117025916, 174630208, 142412449, 112839238,
710 105257725, 114737141, 123102301, 172563968, 130555358, 132628403,
711 183638157, 168682846, 143304568, 105994018, 170010719, 152092970,
712 117799058, 132164175, 179868116, 158654714, 177489647, 116547948,
713 183121404, 131836079, 184431405, 157311793, 149677763, 173989893,
714 102277656, 107058530, 140837477, 152640947, 143507039, 152145247,
715 101683884, 107090870, 161471944, 137225650, 128231458, 172995869,
716 173831689, 171268519, 139042297, 111072135, 107569780, 137262545,
717 181410950, 138270388, 198736451, 162848201, 180468288, 120582913,
718 153390138, 135649144, 130040157, 106509887, 192671541, 174507066,
719 186888783, 143805558, 135011967, 145862340, 180595327, 124727843,
720 182925939, 157715840, 136885940, 198993925, 152416883, 178793572,
721 179679516, 154076673, 192703125, 164187609, 162190243, 104699348,
722 159891990, 160012977, 174692145, 132970421, 167781726, 115178506,
723 153008552, 155999794, 102099694, 155431545, 127458567, 104403686,
724 168042864, 184045128, 181182309, 179349696, 127218364, 192935516,
725 120298724, 169583299, 148193297, 183358034, 159023227, 105261254,
726 121144370, 184359584, 194433836, 138388317, 175184116, 108817112,
727 151279233, 137457721, 193398208, 119005406, 132929377, 175306906,
728 160741530, 149976826, 147124407, 176881724, 186734216, 185881509,
729 191334220, 175930947, 117385515, 193408089, 157124410, 163472089,
730 131949128, 180783576, 131158294, 100549708, 191802336, 165960770,
731 170927599, 101052702, 181508688, 197828549, 143403726, 142729262,
732 110348701, 139928688, 153550062, 106151434, 130786653, 196085995,
733 100587149, 139141652, 106530207, 100852656, 124074703, 166073660,
734 153338052, 163766757, 120188394, 197277047, 122215363, 138511354,
735 183463624, 161985542, 159938719, 133367482, 104220974, 149956672,
736 170250544, 164232439, 157506869, 159133019, 137469191, 142980999,
737 134242305, 150172665, 121209241, 145596259, 160554427, 159095199,
738 168243130, 184279693, 171132070, 121049823, 123819574, 171759855,
739 119501864, 163094029, 175943631, 194450091, 191506160, 149228764,
740 132319212, 197034460, 193584259, 126727638, 168143633, 109856853,
741 127860243, 132141052, 133076065, 188414958, 158718197, 107124299,
742 159592267, 181172796, 144388537, 196763139, 127431422, 179531145,
743 100064922, 112650013, 132686230, 121550837,
744 }
745 % \end{macrocode}
746 % \end{variable}
747 %
748 % \begin{macro}[rEXP]
749 % {
750 % \@@_trig_large:ww,
751 % \@@_trig_large_auxi:w,
752 % \@@_trig_large_auxii:w,
753 % \@@_trig_large_auxiii:w,
754 % }
755 % The exponent~|#1| is between $1$ and~$\ExplSyntaxOn \int_use:N
756 % \c__fp_max_exponent_int$. We wish to look up decimals
757 % $10^{\text{\texttt{\#1}}-16}/(2\pi)$ starting from the digit
758 % $|#1|+1$. Since they are stored in batches of~$8$, compute
759 % $\lfloor|#1|/8\rfloor$ and fetch blocks of $8$ digits starting
760 % there. The numbering of items in \cs{c_@@_trig_intarray} starts
761 % at~$1$, so the block $\lfloor|#1|/8\rfloor+1$ contains the digit we
762 % want, at one of the eight positions. Each call to \cs{int_value:w}
763 % \cs{__kernel_intarray_item:Nn} expands the next, until being stopped
764 % by \cs{@@_trig_large_auxiii:w} using \cs{exp_stop_f:}. Once all
765 % these blocks are unpacked, the \cs{exp_stop_f:} and $0$ to $7$
766 % digits are removed by \cs[no-index]{use_none:n\ldots{}n}.
767 % Finally, \cs{@@_trig_large_auxii:w} packs $64$ digits (there are
768 % between $65$ and $72$ at this point) into groups of~$4$ and the
769 % \texttt{auxv} auxiliary is called.
770 % \begin{macrocode}
771 \cs_new:Npn \@@_trig_large:ww #1, #2#3#4#5#6\@@_sep:
772 {
773 \exp_after:wN \@@_trig_large_auxi:w
774 \int_value:w \@@_int_eval:w (#1 - 4) / 8 \exp_after:wN ,
775 \int_value:w #1 , \@@_sep:
776 {#2}{#3}{#4}{#5} \@@_sep:
777 }
778 \cs_new:Npn \@@_trig_large_auxi:w #1, #2,
779 {
780 \exp_after:wN \exp_after:wN
781 \exp_after:wN \@@_trig_large_auxii:w
782 \cs:w
783 use_none:n \prg_replicate:nn { #2 - #1 * 8 } { n }
784 \exp_after:wN
785 \cs_end:
786 \int_value:w
787 \__kernel_intarray_item:Nn \c_@@_trig_intarray
788 { \@@_int_eval:w #1 + 1 \scan_stop: }
789 \exp_after:wN \@@_trig_large_auxiii:w \int_value:w
790 \__kernel_intarray_item:Nn \c_@@_trig_intarray
791 { \@@_int_eval:w #1 + 2 \scan_stop: }
792 \exp_after:wN \@@_trig_large_auxiii:w \int_value:w
793 \__kernel_intarray_item:Nn \c_@@_trig_intarray
794 { \@@_int_eval:w #1 + 3 \scan_stop: }
795 \exp_after:wN \@@_trig_large_auxiii:w \int_value:w
796 \__kernel_intarray_item:Nn \c_@@_trig_intarray
797 { \@@_int_eval:w #1 + 4 \scan_stop: }
798 \exp_after:wN \@@_trig_large_auxiii:w \int_value:w
799 \__kernel_intarray_item:Nn \c_@@_trig_intarray
800 { \@@_int_eval:w #1 + 5 \scan_stop: }
801 \exp_after:wN \@@_trig_large_auxiii:w \int_value:w
802 \__kernel_intarray_item:Nn \c_@@_trig_intarray
803 { \@@_int_eval:w #1 + 6 \scan_stop: }
804 \exp_after:wN \@@_trig_large_auxiii:w \int_value:w
805 \__kernel_intarray_item:Nn \c_@@_trig_intarray
806 { \@@_int_eval:w #1 + 7 \scan_stop: }
807 \exp_after:wN \@@_trig_large_auxiii:w \int_value:w
808 \__kernel_intarray_item:Nn \c_@@_trig_intarray
809 { \@@_int_eval:w #1 + 8 \scan_stop: }
810 \exp_after:wN \@@_trig_large_auxiii:w \int_value:w
811 \__kernel_intarray_item:Nn \c_@@_trig_intarray
812 { \@@_int_eval:w #1 + 9 \scan_stop: }
813 \exp_stop_f:
814 }
815 \cs_new:Npn \@@_trig_large_auxii:w
816 {
817 \@@_pack_twice_four:wNNNNNNNN \@@_pack_twice_four:wNNNNNNNN
818 \@@_pack_twice_four:wNNNNNNNN \@@_pack_twice_four:wNNNNNNNN
819 \@@_pack_twice_four:wNNNNNNNN \@@_pack_twice_four:wNNNNNNNN
820 \@@_pack_twice_four:wNNNNNNNN \@@_pack_twice_four:wNNNNNNNN
821 \@@_trig_large_auxv:www \@@_sep:
822 }
823 \cs_new:Npn \@@_trig_large_auxiii:w 1 { \exp_stop_f: }
824 % \end{macrocode}
825 % \end{macro}
826 %
827 % \begin{macro}[rEXP]
828 % {
829 % \@@_trig_large_auxv:www,
830 % \@@_trig_large_auxvi:wnnnnnnnn,
831 % \@@_trig_large_pack:NNNNNw
832 % }
833 % First come the first $64$~digits of the fractional part of
834 % $10^{\text{\texttt{\#1}}-16}/(2\pi)$, arranged in $16$~blocks
835 % of~$4$, and ending with a \cs{@@_sep:}. Then a few more digits of the
836 % same fractional part, ending with a \cs{@@_sep:}, then $4$~blocks of
837 % $4$~digits holding the significand of the original argument.
838 % Multiply the $16$-digit significand with the $64$-digit fractional
839 % part: the \texttt{auxvi} auxiliary receives the significand
840 % as~|#2#3#4#5| and $16$~digits of the fractional part as~|#6#7#8#9|,
841 % and computes one step of the usual ladder of \texttt{pack} functions
842 % we use for multiplication (see \emph{e.g.,} \cs{@@_fixed_mul:wwn}),
843 % then discards one block of the fractional part to set things up for
844 % the next step of the ladder. We perform $13$~such steps, replacing
845 % the last \texttt{middle} shift by the appropriate \texttt{trailing}
846 % shift, then discard the significand and remaining $3$~blocks from
847 % the fractional part, as there are not enough digits to compute any
848 % more step in the ladder. The last \cs{@@_sep:} closes the ladder, and
849 % we return control to the \texttt{auxvii} auxiliary.
850 % \begin{macrocode}
851 \cs_new:Npn \@@_trig_large_auxv:www #1\@@_sep: #2\@@_sep: #3\@@_sep:
852 {
853 \exp_after:wN \@@_use_i_until_s:nw
854 \exp_after:wN \@@_trig_large_auxvii:w
855 \int_value:w \@@_int_eval:w \c_@@_leading_shift_int
856 \prg_replicate:nn { 13 }
857 { \@@_trig_large_auxvi:wnnnnnnnn }
858 + \c_@@_trailing_shift_int - \c_@@_middle_shift_int
859 \@@_use_i_until_s:nw
860 \@@_sep: #3 #1 \@@_sep: \@@_sep:
861 }
862 \cs_new:Npn \@@_trig_large_auxvi:wnnnnnnnn #1\@@_sep: #2#3#4#5#6#7#8#9
863 {
864 \exp_after:wN \@@_trig_large_pack:NNNNNw
865 \int_value:w \@@_int_eval:w \c_@@_middle_shift_int
866 + #2*#9 + #3*#8 + #4*#7 + #5*#6
867 #1\@@_sep: {#2}{#3}{#4}{#5} {#7}{#8}{#9}
868 }
869 \cs_new:Npn \@@_trig_large_pack:NNNNNw #1#2#3#4#5#6\@@_sep:
870 { + #1#2#3#4#5 \@@_sep: #6 }
871 % \end{macrocode}
872 % \end{macro}
873 %
874 % \begin{macro}[rEXP]
875 % {
876 % \@@_trig_large_auxvii:w,
877 % \@@_trig_large_auxviii:w,
878 % }
879 % \begin{macro}[EXP]
880 % {
881 % \@@_trig_large_auxix:Nw,
882 % \@@_trig_large_auxx:wNNNNN,
883 % \@@_trig_large_auxxi:w
884 % }
885 % The \texttt{auxvii} auxiliary is followed by $52$~digits and a
886 % \cs{@@_sep:}. We find the octant as the integer part of $8$~times what
887 % follows, or equivalently as the integer part of $|#1#2#3|/125$, and
888 % add it to the surrounding integer expression for the octant. We
889 % then compute $8$~times the $52$-digit number, with a minus sign if
890 % the octant is odd. Again, the last \texttt{middle} shift is
891 % converted to a \texttt{trailing} shift. Any integer part (including
892 % negative values which come up when the octant is odd) is discarded
893 % by \cs{@@_use_i_until_s:nw}. The resulting fractional part should
894 % then be converted to radians by multiplying by~$2\pi/8$, but first,
895 % build an extended precision number by abusing
896 % \cs{@@_ep_to_ep_loop:N} with the appropriate trailing markers.
897 % Finally, \cs{@@_trig_small:ww} sets up the argument for the
898 % functions which compute the Taylor series.
899 % \begin{macrocode}
900 \cs_new:Npn \@@_trig_large_auxvii:w #1#2#3
901 {
902 \exp_after:wN \@@_trig_large_auxviii:ww
903 \int_value:w \@@_int_eval:w (#1#2#3 - 62) / 125 \@@_sep:
904 #1#2#3
905 }
906 \cs_new:Npn \@@_trig_large_auxviii:ww #1\@@_sep:
907 {
908 + #1
909 \if_int_odd:w #1 \exp_stop_f:
910 \exp_after:wN \@@_trig_large_auxix:Nw
911 \exp_after:wN -
912 \else:
913 \exp_after:wN \@@_trig_large_auxix:Nw
914 \exp_after:wN +
915 \fi:
916 }
917 \cs_new:Npn \@@_trig_large_auxix:Nw
918 {
919 \exp_after:wN \@@_use_i_until_s:nw
920 \exp_after:wN \@@_trig_large_auxxi:w
921 \int_value:w \@@_int_eval:w \c_@@_leading_shift_int
922 \prg_replicate:nn { 13 }
923 { \@@_trig_large_auxx:wNNNNN }
924 + \c_@@_trailing_shift_int - \c_@@_middle_shift_int
925 \@@_sep:
926 }
927 \cs_new:Npn \@@_trig_large_auxx:wNNNNN #1\@@_sep: #2 #3#4#5#6
928 {
929 \exp_after:wN \@@_trig_large_pack:NNNNNw
930 \int_value:w \@@_int_eval:w \c_@@_middle_shift_int
931 #2 8 * #3#4#5#6
932 #1\@@_sep: #2
933 }
934 \cs_new:Npn \@@_trig_large_auxxi:w #1\@@_sep:
935 {
936 \exp_after:wN \@@_ep_mul_raw:wwwwN
937 \int_value:w \@@_int_eval:w 0 \@@_ep_to_ep_loop:N #1 \@@_sep: \@@_sep: !
938 0,{7853}{9816}{3397}{4483}{0961}{5661}\@@_sep:
939 \@@_trig_small:ww
940 }
941 % \end{macrocode}
942 % \end{macro}
943 % \end{macro}
944 %
945 % \subsubsection{Computing the power series}
946 %
947 % \begin{macro}[EXP]
948 % {\@@_sin_series_o:NNwwww, \@@_sin_series_aux_o:NNnwww}
949 % Here we receive a conversion function \cs{@@_ep_to_float_o:wwN} or
950 % \cs{@@_ep_inv_to_float_o:wwN}, a \meta{sign} ($0$ or~$2$), a
951 % (non-negative) \meta{octant} delimited by a dot, a \meta{fixed
952 % point} number delimited by a \cs{@@_sep:}, and an extended-precision
953 % number. The auxiliary receives:
954 % \begin{itemize}
955 % \item the conversion function~|#1|;
956 % \item the final sign, which depends on the octant~|#3| and the
957 % sign~|#2|;
958 % \item the octant~|#3|, which controls the series we use;
959 % \item the square |#4 * #4| of the argument as a fixed point number,
960 % computed with \cs{@@_fixed_mul:wwn};
961 % \item the number itself as an extended-precision number.
962 % \end{itemize}
963 % If the octant is in $\{1,2,5,6,\ldots{}\}$, we are near an extremum
964 % of the function and we use the series
965 % \[
966 % \cos(x) = 1 - x^2 \bigg( \frac{1}{2!} - x^2 \bigg( \frac{1}{4!}
967 % - x^2 \bigg( \cdots \bigg) \bigg) \bigg) .
968 % \]
969 % Otherwise, the series
970 % \[
971 % \sin(x) = x \bigg( 1 - x^2 \bigg( \frac{1}{3!} - x^2 \bigg(
972 % \frac{1}{5!} - x^2 \bigg( \cdots \bigg) \bigg) \bigg) \bigg)
973 % \]
974 % is used. Finally, the extended-precision number is converted to a
975 % floating point number with the given sign, and \cs{@@_sanitize:Nw}
976 % checks for overflow and underflow.
977 % \begin{macrocode}
978 \cs_new:Npn \@@_sin_series_o:NNwwww #1#2#3. #4\@@_sep:
979 {
980 \@@_fixed_mul:wwn #4\@@_sep: #4\@@_sep:
981 {
982 \exp_after:wN \@@_sin_series_aux_o:NNnwww
983 \exp_after:wN #1
984 \int_value:w
985 \if_int_odd:w \@@_int_eval:w (#3 + 2) / 4 \@@_int_eval_end:
986 #2
987 \else:
988 \if_meaning:w #2 0 2 \else: 0 \fi:
989 \fi:
990 {#3}
991 }
992 }
993 \cs_new:Npn \@@_sin_series_aux_o:NNnwww #1#2#3 #4\@@_sep: #5,#6\@@_sep:
994 {
995 \if_int_odd:w \@@_int_eval:w #3 / 2 \@@_int_eval_end:
996 \exp_after:wN \use_i:nn
997 \else:
998 \exp_after:wN \use_ii:nn
999 \fi:
1000 { % 1/18!
1001 \@@_fixed_mul_sub_back:wwwn {0000}{0000}{0000}{0001}{5619}{2070}\@@_sep:
1002 #4\@@_sep:
1003 {0000}{0000}{0000}{0477}{9477}{3324}\@@_sep:
1004 \@@_fixed_mul_sub_back:wwwn #4\@@_sep:
1005 {0000}{0000}{0011}{4707}{4559}{7730}\@@_sep:
1006 \@@_fixed_mul_sub_back:wwwn #4\@@_sep:
1007 {0000}{0000}{2087}{6756}{9878}{6810}\@@_sep:
1008 \@@_fixed_mul_sub_back:wwwn #4\@@_sep:
1009 {0000}{0027}{5573}{1922}{3985}{8907}\@@_sep:
1010 \@@_fixed_mul_sub_back:wwwn #4\@@_sep:
1011 {0000}{2480}{1587}{3015}{8730}{1587}\@@_sep:
1012 \@@_fixed_mul_sub_back:wwwn #4\@@_sep:
1013 {0013}{8888}{8888}{8888}{8888}{8889}\@@_sep:
1014 \@@_fixed_mul_sub_back:wwwn #4\@@_sep:
1015 {0416}{6666}{6666}{6666}{6666}{6667}\@@_sep:
1016 \@@_fixed_mul_sub_back:wwwn #4\@@_sep:
1017 {5000}{0000}{0000}{0000}{0000}{0000}\@@_sep:
1018 \@@_fixed_mul_sub_back:wwwn#4\@@_sep:
1019 {10000}{0000}{0000}{0000}{0000}{0000}\@@_sep:
1020 { \@@_fixed_continue:wn 0, }
1021 }
1022 { % 1/17!
1023 \@@_fixed_mul_sub_back:wwwn {0000}{0000}{0000}{0028}{1145}{7254}\@@_sep:
1024 #4\@@_sep:
1025 {0000}{0000}{0000}{7647}{1637}{3182}\@@_sep:
1026 \@@_fixed_mul_sub_back:wwwn #4\@@_sep:
1027 {0000}{0000}{0160}{5904}{3836}{8216}\@@_sep:
1028 \@@_fixed_mul_sub_back:wwwn #4\@@_sep:
1029 {0000}{0002}{5052}{1083}{8544}{1719}\@@_sep:
1030 \@@_fixed_mul_sub_back:wwwn #4\@@_sep:
1031 {0000}{0275}{5731}{9223}{9858}{9065}\@@_sep:
1032 \@@_fixed_mul_sub_back:wwwn #4\@@_sep:
1033 {0001}{9841}{2698}{4126}{9841}{2698}\@@_sep:
1034 \@@_fixed_mul_sub_back:wwwn #4\@@_sep:
1035 {0083}{3333}{3333}{3333}{3333}{3333}\@@_sep:
1036 \@@_fixed_mul_sub_back:wwwn #4\@@_sep:
1037 {1666}{6666}{6666}{6666}{6666}{6667}\@@_sep:
1038 \@@_fixed_mul_sub_back:wwwn#4\@@_sep:
1039 {10000}{0000}{0000}{0000}{0000}{0000}\@@_sep:
1040 { \@@_ep_mul:wwwwn 0, } #5,#6\@@_sep:
1041 }
1042 {
1043 \exp_after:wN \@@_sanitize:Nw
1044 \exp_after:wN #2
1045 \int_value:w \@@_int_eval:w #1
1046 }
1047 #2
1048 }
1049 % \end{macrocode}
1050 % \end{macro}
1051 %
1052 % \begin{macro}[EXP]
1053 % {\@@_tan_series_o:NNwwww, \@@_tan_series_aux_o:Nnwww}
1054 % Contrarily to \cs{@@_sin_series_o:NNwwww} which received a
1055 % conversion auxiliary as~|#1|, here, |#1| is $0$ for tangent
1056 % and $2$ for
1057 % cotangent. Consider first the case of the tangent. The octant |#3|
1058 % starts at $1$, which means that it is $1$ or $2$ for $\lvert
1059 % x\rvert\in[0,\pi/2]$, it is $3$ or $4$ for $\lvert
1060 % x\rvert\in[\pi/2,\pi]$, and so on: the intervals on which
1061 % $\tan\lvert x\rvert\geq 0$ coincide with those for which $\lfloor
1062 % (|#3| + 1) / 2\rfloor$ is odd. We also have to take into account
1063 % the original sign of $x$ to get the sign of the final result; it is
1064 % straightforward to check that the first \cs{int_value:w} expansion
1065 % produces $0$ for a positive final result, and $2$ otherwise. A
1066 % similar story holds for $\cot(x)$.
1067 %
1068 % The auxiliary receives the sign, the octant, the square of the
1069 % (reduced) input, and the (reduced) input (an extended-precision
1070 % number) as arguments. It then
1071 % computes the numerator and denominator of
1072 % \[
1073 % \tan(x) \simeq
1074 % \frac{x (1 - x^2 (a_1 - x^2 (a_2 - x^2 (a_3 - x^2 (a_4 - x^2 a_5)))))}
1075 % {1 - x^2 (b_1 - x^2 (b_2 - x^2 (b_3 - x^2 (b_4 - x^2 b_5))))} .
1076 % \]
1077 % The ratio is computed by \cs{@@_ep_div:wwwwn}, then converted to a
1078 % floating point number. For octants~|#3| (really, quadrants) next to
1079 % a pole of the
1080 % functions, the fixed point numerator and denominator are exchanged
1081 % before computing the ratio. Note that this \cs{if_int_odd:w} test
1082 % relies on the fact that the octant is at least~$1$.
1083 % \begin{macrocode}
1084 \cs_new:Npn \@@_tan_series_o:NNwwww #1#2#3. #4\@@_sep:
1085 {
1086 \@@_fixed_mul:wwn #4\@@_sep: #4\@@_sep:
1087 {
1088 \exp_after:wN \@@_tan_series_aux_o:Nnwww
1089 \int_value:w
1090 \if_int_odd:w \@@_int_eval:w #3 / 2 \@@_int_eval_end:
1091 \exp_after:wN \reverse_if:N
1092 \fi:
1093 \if_meaning:w #1#2 2 \else: 0 \fi:
1094 {#3}
1095 }
1096 }
1097 \cs_new:Npn \@@_tan_series_aux_o:Nnwww #1 #2 #3\@@_sep: #4,#5\@@_sep:
1098 {
1099 \@@_fixed_mul_sub_back:wwwn {0000}{0000}{1527}{3493}{0856}{7059}\@@_sep:
1100 #3\@@_sep:
1101 {0000}{0159}{6080}{0274}{5257}{6472}\@@_sep:
1102 \@@_fixed_mul_sub_back:wwwn #3\@@_sep:
1103 {0002}{4571}{2320}{0157}{2558}{8481}\@@_sep:
1104 \@@_fixed_mul_sub_back:wwwn #3\@@_sep:
1105 {0115}{5830}{7533}{5397}{3168}{2147}\@@_sep:
1106 \@@_fixed_mul_sub_back:wwwn #3\@@_sep:
1107 {1929}{8245}{6140}{3508}{7719}{2982}\@@_sep:
1108 \@@_fixed_mul_sub_back:wwwn #3\@@_sep:
1109 {10000}{0000}{0000}{0000}{0000}{0000}\@@_sep:
1110 { \@@_ep_mul:wwwwn 0, } #4,#5\@@_sep:
1111 {
1112 \@@_fixed_mul_sub_back:wwwn {0000}{0007}{0258}{0681}{9408}{4706}\@@_sep:
1113 #3\@@_sep:
1114 {0000}{2343}{7175}{1399}{6151}{7670}\@@_sep:
1115 \@@_fixed_mul_sub_back:wwwn #3\@@_sep:
1116 {0019}{2638}{4588}{9232}{8861}{3691}\@@_sep:
1117 \@@_fixed_mul_sub_back:wwwn #3\@@_sep:
1118 {0536}{6357}{0691}{4344}{6852}{4252}\@@_sep:
1119 \@@_fixed_mul_sub_back:wwwn #3\@@_sep:
1120 {5263}{1578}{9473}{6842}{1052}{6315}\@@_sep:
1121 \@@_fixed_mul_sub_back:wwwn#3\@@_sep:
1122 {10000}{0000}{0000}{0000}{0000}{0000}\@@_sep:
1123 {
1124 \reverse_if:N \if_int_odd:w
1125 \@@_int_eval:w (#2 - 1) / 2 \@@_int_eval_end:
1126 \exp_after:wN \@@_reverse_args:Nww
1127 \fi:
1128 \@@_ep_div:wwwwn 0,
1129 }
1130 }
1131 {
1132 \exp_after:wN \@@_sanitize:Nw
1133 \exp_after:wN #1
1134 \int_value:w \@@_int_eval:w \@@_ep_to_float_o:wwN
1135 }
1136 #1
1137 }
1138 % \end{macrocode}
1139 % \end{macro}
1140 %
1141 % \subsection{Inverse trigonometric functions}
1142 %
1143 % All inverse trigonometric functions (arcsine, arccosine, arctangent,
1144 % arccotangent, arccosecant, and arcsecant) are based on a function
1145 % often denoted \texttt{atan2}. This function is accessed directly by
1146 % feeding two arguments to arctangent, and is defined by \(\operatorname{atan}(y, x) =
1147 % \operatorname{atan}(y/x)\) for generic \(y\) and~\(x\). Its advantages over the
1148 % conventional arctangent is that it takes values in $[-\pi,\pi]$ rather
1149 % than $[-\pi/2,\pi/2]$, and that it is better behaved in boundary
1150 % cases. Other inverse trigonometric functions are expressed in terms
1151 % of \(\operatorname{atan}\) as
1152 % \begin{align}
1153 % \operatorname{acos} x & = \operatorname{atan}(\sqrt{1-x^2}, x) \\
1154 % \operatorname{asin} x & = \operatorname{atan}(x, \sqrt{1-x^2}) \\
1155 % \operatorname{asec} x & = \operatorname{atan}(\sqrt{x^2-1}, 1) \\
1156 % \operatorname{acsc} x & = \operatorname{atan}(1, \sqrt{x^2-1}) \\
1157 % \operatorname{atan} x & = \operatorname{atan}(x, 1) \\
1158 % \operatorname{acot} x & = \operatorname{atan}(1, x) .
1159 % \end{align}
1160 % Rather than introducing a new function, \texttt{atan2}, the arctangent
1161 % function \texttt{atan} is overloaded: it can take one or two
1162 % arguments. In the comments below, following many texts, we call the
1163 % first argument~$y$ and the second~$x$, because $\operatorname{atan}(y, x) = \operatorname{atan}(y
1164 % / x)$ is the angular coordinate of the point $(x, y)$.
1165 %
1166 % As for direct trigonometric functions, the first step in computing
1167 % $\operatorname{atan}(y, x)$ is argument reduction. The sign of~$y$ gives that
1168 % of the result. We distinguish eight regions where the point $(x,
1169 % \lvert y\rvert)$ can lie, of angular size roughly $\pi/8$,
1170 % characterized by their \enquote{octant}, between $0$ and~$7$ included. In
1171 % each region, we compute an arctangent as a Taylor series, then shift
1172 % this arctangent by the appropriate multiple of $\pi/4$ and sign to get
1173 % the result. Here is a list of octants, and how we compute the
1174 % arctangent (we assume $y>0$: otherwise replace $y$ by~$-y$ below):
1175 % \begin{itemize}
1176 % \item[0] $0 < \lvert y\rvert < 0.41421 x$, then
1177 % $\operatorname{atan}\frac{\lvert y\rvert}{x}$
1178 % is given by a nicely convergent Taylor series;
1179 % \item[1] $0 < 0.41421 x < \lvert y\rvert < x$, then
1180 % $\operatorname{atan}\frac{\lvert y\rvert}{x}
1181 % = \frac{\pi}{4}-\operatorname{atan}\frac{x-\lvert y\rvert}{x+\lvert y\rvert}$;
1182 % \item[2] $0 < 0.41421 \lvert y\rvert < x < \lvert y\rvert$, then
1183 % $\operatorname{atan}\frac{\lvert y\rvert}{x}
1184 % = \frac{\pi}{4}+\operatorname{atan}\frac{-x+\lvert y\rvert}{x+\lvert y\rvert}$;
1185 % \item[3] $0 < x < 0.41421 \lvert y\rvert$, then
1186 % $\operatorname{atan}\frac{\lvert y\rvert}{x}
1187 % = \frac{\pi}{2}-\operatorname{atan}\frac{x}{\lvert y\rvert}$;
1188 % \item[4] $0 < -x < 0.41421 \lvert y\rvert$, then
1189 % $\operatorname{atan}\frac{\lvert y\rvert}{x}
1190 % = \frac{\pi}{2}+\operatorname{atan}\frac{-x}{\lvert y\rvert}$;
1191 % \item[5] $0 < 0.41421 \lvert y\rvert < -x < \lvert y\rvert$, then
1192 % $\operatorname{atan}\frac{\lvert y\rvert}{x}
1193 % =\frac{3\pi}{4}-\operatorname{atan}\frac{x+\lvert y\rvert}{-x+\lvert y\rvert}$;
1194 % \item[6] $0 < -0.41421 x < \lvert y\rvert < -x$, then
1195 % $\operatorname{atan}\frac{\lvert y\rvert}{x}
1196 % =\frac{3\pi}{4}+\operatorname{atan}\frac{-x-\lvert y\rvert}{-x+\lvert y\rvert}$;
1197 % \item[7] $0 < \lvert y\rvert < -0.41421 x$, then
1198 % $\operatorname{atan}\frac{\lvert y\rvert}{x}
1199 % = \pi-\operatorname{atan}\frac{\lvert y\rvert}{-x}$.
1200 % \end{itemize}
1201 % In the following, we denote by~$z$ the ratio among
1202 % $\lvert\frac{y}{x}\rvert$, $\lvert\frac{x}{y}\rvert$,
1203 % $\lvert\frac{x+y}{x-y}\rvert$, $\lvert\frac{x-y}{x+y}\rvert$ which
1204 % appears in the right-hand side above.
1205 %
1206 % \subsubsection{Arctangent and arccotangent}
1207 %
1208 % \begin{macro}[EXP]{\@@_atan_o:Nw, \@@_acot_o:Nw, \@@_atan_default:w}
1209 % The parsing step manipulates \texttt{atan} and \texttt{acot} like
1210 % \texttt{min} and \texttt{max}, reading in an array of operands, but
1211 % also leaves \cs{use_i:nn} or \cs{use_ii:nn} depending on whether the
1212 % result should be given in radians or in degrees. The helper
1213 % \cs{@@_parse_function_one_two:nnw} checks that the operand is one or
1214 % two floating point numbers (not tuples) and leaves its second
1215 % argument or its tail accordingly (its first argument is used for
1216 % error messages). More precisely if we are given a single floating
1217 % point number \cs{@@_atan_default:w} places \cs{c_one_fp} (expanded)
1218 % after it; otherwise \cs{@@_atan_default:w} is omitted by
1219 % \cs{@@_parse_function_one_two:nnw}.
1220 % \begin{macrocode}
1221 \cs_new:Npn \@@_atan_o:Nw #1
1222 {
1223 \@@_parse_function_one_two:nnw
1224 { #1 { atan } { atand } }
1225 { \@@_atan_default:w \@@_atanii_o:Nww #1 }
1226 }
1227 \cs_new:Npn \@@_acot_o:Nw #1
1228 {
1229 \@@_parse_function_one_two:nnw
1230 { #1 { acot } { acotd } }
1231 { \@@_atan_default:w \@@_acotii_o:Nww #1 }
1232 }
1233 \cs_new:Npe \@@_atan_default:w #1#2#3 @ { #1 #2 #3 \c_one_fp @ }
1234 % \end{macrocode}
1235 % \end{macro}
1236 %
1237 % \begin{macro}[EXP]{\@@_atanii_o:Nww, \@@_acotii_o:Nww}
1238 % If either operand is \texttt{nan}, we return it. If both are
1239 % normal, we call \cs{@@_atan_normal_o:NNnwNnw}. If both are zero or
1240 % both infinity, we call \cs{@@_atan_inf_o:NNNw} with argument~$2$,
1241 % leading to a result among $\{\pm\pi/4, \pm 3\pi/4\}$ (in degrees,
1242 % $\{\pm 45, \pm 135\}$). Otherwise, one is much bigger than the
1243 % other, and we call \cs{@@_atan_inf_o:NNNw} with either an argument
1244 % of~$4$, leading to the values $\pm\pi/2$ (in degrees,~$\pm 90$),
1245 % or~$0$, leading to $\{\pm 0, \pm\pi\}$ (in degrees, $\{\pm 0,\pm
1246 % 180\}$). Since $\operatorname{acot}(x, y) = \operatorname{atan}(y, x)$,
1247 % \cs{@@_acotii_o:ww} simply reverses its two arguments.
1248 % \begin{macrocode}
1249 \cs_new:Npn \@@_atanii_o:Nww
1250 #1 \s_@@ \@@_chk:w #2#3#4\@@_sep: \s_@@ \@@_chk:w #5 #6 @
1251 {
1252 \if_meaning:w 3 #2 \@@_case_return_i_o:ww \fi:
1253 \if_meaning:w 3 #5 \@@_case_return_ii_o:ww \fi:
1254 \if_case:w
1255 \if_meaning:w #2 #5
1256 \if_meaning:w 1 #2 10 \else: 0 \fi:
1257 \else:
1258 \if_int_compare:w #2 > #5 \exp_stop_f: 1 \else: 2 \fi:
1259 \fi:
1260 \exp_stop_f:
1261 \@@_case_return:nw { \@@_atan_inf_o:NNNw #1 #3 2 }
1262 \or: \@@_case_return:nw { \@@_atan_inf_o:NNNw #1 #3 4 }
1263 \or: \@@_case_return:nw { \@@_atan_inf_o:NNNw #1 #3 0 }
1264 \fi:
1265 \@@_atan_normal_o:NNnwNnw #1
1266 \s_@@ \@@_chk:w #2#3#4\@@_sep:
1267 \s_@@ \@@_chk:w #5 #6
1268 }
1269 \cs_new:Npn \@@_acotii_o:Nww #1#2\@@_sep: #3\@@_sep:
1270 { \@@_atanii_o:Nww #1#3\@@_sep: #2\@@_sep: }
1271 % \end{macrocode}
1272 % \end{macro}
1273 %
1274 % \begin{macro}[EXP]{\@@_atan_inf_o:NNNw}
1275 % This auxiliary is called whenever one number is $\pm 0$ or
1276 % $\pm\infty$ (and neither is \nan{}). Then the result only depends
1277 % on the signs, and its value is a multiple of $\pi/4$. We use the
1278 % same auxiliary as for normal numbers,
1279 % \cs{@@_atan_combine_o:NwwwwwN}, with arguments the final sign~|#2|;
1280 % the octant~|#3|; $\operatorname{atan} z/z=1$ as a fixed point number; $z=0$~as a
1281 % fixed point number; and $z=0$~as an extended-precision number.
1282 % Given the values we provide, $\operatorname{atan} z$ is computed to be~$0$,
1283 % and the result is $[|#3|/2]\cdot\pi/4$ if the sign~|#5| of~$x$
1284 % is positive, and $[(7-|#3|)/2]\cdot\pi/4$ for negative~$x$, where
1285 % the divisions are rounded up.
1286 % \begin{macrocode}
1287 \cs_new:Npn \@@_atan_inf_o:NNNw #1#2#3 \s_@@ \@@_chk:w #4#5#6\@@_sep:
1288 {
1289 \exp_after:wN \@@_atan_combine_o:NwwwwwN
1290 \exp_after:wN #2
1291 \int_value:w \@@_int_eval:w
1292 \if_meaning:w 2 #5 7 - \fi: #3 \exp_after:wN \@@_sep:
1293 \c_@@_one_fixed_tl
1294 {0000}{0000}{0000}{0000}{0000}{0000}\@@_sep:
1295 0,{0000}{0000}{0000}{0000}{0000}{0000}\@@_sep: #1
1296 }
1297 % \end{macrocode}
1298 % \end{macro}
1299 %
1300 % \begin{macro}[EXP]{\@@_atan_normal_o:NNnwNnw}
1301 % Here we simply reorder the floating point data into a pair of signed
1302 % extended-precision numbers, that is, a sign, an exponent ending with
1303 % a comma, and a six-block mantissa ending with a \cs{@@_sep:}. This
1304 % extended precision is required by other inverse trigonometric
1305 % functions, to compute things like $\operatorname{atan}(x,\sqrt{1-x^2})$ without
1306 % intermediate rounding errors.
1307 % \begin{macrocode}
1308 \cs_new_protected:Npn \@@_atan_normal_o:NNnwNnw
1309 #1 \s_@@ \@@_chk:w 1#2#3#4\@@_sep: \s_@@ \@@_chk:w 1#5#6#7\@@_sep:
1310 {
1311 \@@_atan_test_o:NwwNwwN
1312 #2 #3, #4{0000}{0000}\@@_sep:
1313 #5 #6, #7{0000}{0000}\@@_sep: #1
1314 }
1315 % \end{macrocode}
1316 % \end{macro}
1317 %
1318 % \begin{macro}[EXP]{\@@_atan_test_o:NwwNwwN}
1319 % This receives: the sign~|#1| of~$y$, its exponent~|#2|, its $24$
1320 % digits~|#3| in groups of~$4$, and similarly for~$x$. We prepare to
1321 % call \cs{@@_atan_combine_o:NwwwwwN} which expects the sign~|#1|, the
1322 % octant, the ratio $(\operatorname{atan} z)/z = 1 - \cdots$, and the value of~$z$,
1323 % both as a fixed point number and as an extended-precision floating
1324 % point number with a mantissa in $[0.01,1)$. For now, we place |#1|
1325 % as a first argument, and start an integer expression for the octant.
1326 % The sign of $x$ does not affect~$z$, so we simply leave
1327 % a contribution to the octant: $\meta{octant} \to 7 - \meta{octant}$
1328 % for negative~$x$. Then we order $\lvert y\rvert$ and $\lvert
1329 % x\rvert$ in a non-decreasing order: if $\lvert y\rvert > \lvert
1330 % x\rvert$, insert $3-$ in the expression for the octant, and swap the
1331 % two numbers. The finer test with $0.41421$ is done by
1332 % \cs{@@_atan_div:wnwwnw} after the operands have been ordered.
1333 % \begin{macrocode}
1334 \cs_new:Npn \@@_atan_test_o:NwwNwwN #1#2,#3\@@_sep: #4#5,#6\@@_sep:
1335 {
1336 \exp_after:wN \@@_atan_combine_o:NwwwwwN
1337 \exp_after:wN #1
1338 \int_value:w \@@_int_eval:w
1339 \if_meaning:w 2 #4
1340 7 - \@@_int_eval:w
1341 \fi:
1342 \if_int_compare:w
1343 \@@_ep_compare:wwww #2,#3\@@_sep: #5,#6\@@_sep: > \c_zero_int
1344 3 -
1345 \exp_after:wN \@@_reverse_args:Nww
1346 \fi:
1347 \@@_atan_div:wnwwnw #2,#3\@@_sep: #5,#6\@@_sep:
1348 }
1349 % \end{macrocode}
1350 % \end{macro}
1351 %
1352 % \begin{macro}[rEXP]{\@@_atan_div:wnwwnw, \@@_atan_near:wwwn}
1353 % \begin{macro}[EXP]{\@@_atan_near_aux:wwn}
1354 % This receives two positive numbers $a$ and~$b$ (equal to $\lvert
1355 % x\rvert$ and~$\lvert y\rvert$ in some order), each as an exponent
1356 % and $6$~blocks of $4$~digits, such that $0<a<b$. If $0.41421b<a$,
1357 % the two numbers are \enquote{near}, hence the point $(y,x)$ that we
1358 % started with is closer to the diagonals $\{\lvert y\rvert = \lvert
1359 % x\rvert\}$ than to the axes $\{xy = 0\}$. In that case, the octant
1360 % is~$1$ (possibly combined with the $7-$ and $3-$ inserted earlier)
1361 % and we wish to compute $\operatorname{atan}\frac{b-a}{a+b}$. Otherwise, the
1362 % octant is~$0$ (again, combined with earlier terms) and we wish to
1363 % compute $\operatorname{atan}\frac{a}{b}$. In any case, call \cs{@@_atan_auxi:ww}
1364 % followed by~$z$, as a comma-delimited exponent and a fixed point
1365 % number.
1366 % \begin{macrocode}
1367 \cs_new:Npn \@@_atan_div:wnwwnw #1,#2#3\@@_sep: #4,#5#6\@@_sep:
1368 {
1369 \if_int_compare:w
1370 \@@_int_eval:w 41421 * #5 < #2 000
1371 \if_case:w \@@_int_eval:w #4 - #1 \@@_int_eval_end:
1372 00 \or: 0 \fi:
1373 \exp_stop_f:
1374 \exp_after:wN \@@_atan_near:wwwn
1375 \fi:
1376 0
1377 \@@_ep_div:wwwwn #1,{#2}#3\@@_sep: #4,{#5}#6\@@_sep:
1378 \@@_atan_auxi:ww
1379 }
1380 \cs_new:Npn \@@_atan_near:wwwn
1381 0 \@@_ep_div:wwwwn #1,#2\@@_sep: #3,
1382 {
1383 1
1384 \@@_ep_to_fixed:wwn #1 - #3, #2\@@_sep:
1385 \@@_atan_near_aux:wwn
1386 }
1387 \cs_new:Npn \@@_atan_near_aux:wwn #1\@@_sep: #2\@@_sep:
1388 {
1389 \@@_fixed_add:wwn #1\@@_sep: #2\@@_sep:
1390 { \@@_fixed_sub:wwn #2\@@_sep: #1\@@_sep: { \@@_ep_div:wwwwn 0, } 0, }
1391 }
1392 % \end{macrocode}
1393 % \end{macro}
1394 % \end{macro}
1395 %
1396 % \begin{macro}[EXP]{\@@_atan_auxi:ww, \@@_atan_auxii:w}
1397 % Convert~$z$ from a representation as an exponent and a fixed point
1398 % number in $[0.01,1)$ to a fixed point number only, then set up the
1399 % call to \cs{@@_atan_Taylor_loop:www}, followed by the fixed point
1400 % representation of~$z$ and the old representation.
1401 % \begin{macrocode}
1402 \cs_new:Npn \@@_atan_auxi:ww #1,#2\@@_sep:
1403 { \@@_ep_to_fixed:wwn #1,#2\@@_sep: \@@_atan_auxii:w #1,#2\@@_sep: }
1404 \cs_new:Npn \@@_atan_auxii:w #1\@@_sep:
1405 {
1406 \@@_fixed_mul:wwn #1\@@_sep: #1\@@_sep:
1407 {
1408 \@@_atan_Taylor_loop:www 39 \@@_sep:
1409 {0000}{0000}{0000}{0000}{0000}{0000} \@@_sep:
1410 }
1411 ! #1\@@_sep:
1412 }
1413 % \end{macrocode}
1414 % \end{macro}
1415 %
1416 % \begin{macro}[EXP]
1417 % {\@@_atan_Taylor_loop:www, \@@_atan_Taylor_break:w}
1418 % We compute the series of $(\operatorname{atan} z)/z$. A typical intermediate
1419 % stage has $|#1|=2k-1$, $|#2| =
1420 % \frac{1}{2k+1}-z^2(\frac{1}{2k+3}-z^2(\cdots-z^2\frac{1}{39}))$, and
1421 % $|#3|=z^2$. To go to the next step $k\to k-1$, we compute
1422 % $\frac{1}{2k-1}$, then subtract from it $z^2$ times |#2|. The loop
1423 % stops when $k=0$: then |#2| is $(\operatorname{atan} z)/z$, and there is a need to
1424 % clean up all the unnecessary data, end the integer expression
1425 % computing the octant with a \cs{@@_sep:}, and leave the result~|#2|
1426 % afterwards.
1427 % \begin{macrocode}
1428 \cs_new:Npn \@@_atan_Taylor_loop:www #1\@@_sep: #2\@@_sep: #3\@@_sep:
1429 {
1430 \if_int_compare:w #1 = - \c_one_int
1431 \@@_atan_Taylor_break:w
1432 \fi:
1433 \exp_after:wN \@@_fixed_div_int:wwN \c_@@_one_fixed_tl #1\@@_sep:
1434 \@@_rrot:www \@@_fixed_mul_sub_back:wwwn #2\@@_sep: #3\@@_sep:
1435 {
1436 \exp_after:wN \@@_atan_Taylor_loop:www
1437 \int_value:w \@@_int_eval:w #1 - 2 \@@_sep:
1438 }
1439 #3\@@_sep:
1440 }
1441 \cs_new:Npn \@@_atan_Taylor_break:w
1442 \fi: #1 \@@_fixed_mul_sub_back:wwwn #2\@@_sep: #3 !
1443 { \fi: \@@_sep: #2 \@@_sep: }
1444 % \end{macrocode}
1445 % \end{macro}
1446 %
1447 % \begin{macro}[EXP]
1448 % {\@@_atan_combine_o:NwwwwwN, \@@_atan_combine_aux:ww}
1449 % This receives a \meta{sign}, an \meta{octant}, a fixed point value
1450 % of $(\operatorname{atan} z)/z$, a fixed point number~$z$, and another
1451 % representation of~$z$, as an \meta{exponent} and the fixed point
1452 % number $10^{-\meta{exponent}} z$, followed by either \cs{use_i:nn}
1453 % (when working in radians) or \cs{use_ii:nn} (when working in
1454 % degrees). The function computes the floating point result
1455 % \begin{equation}
1456 % \meta{sign} \left(
1457 % \left\lceil\frac{\meta{octant}}{2}\right\rceil
1458 % \frac{\pi}{4}
1459 % + (-1)^{\meta{octant}} \frac{\operatorname{atan} z}{z} \cdot z\right) \,,
1460 % \end{equation}
1461 % multiplied by $180/\pi$ if working in degrees, and using in any case
1462 % the most appropriate representation of~$z$. The floating point
1463 % result is passed to \cs{@@_sanitize:Nw}, which checks for overflow
1464 % or underflow. If the octant is~$0$, leave the exponent~|#5| for
1465 % \cs{@@_sanitize:Nw}, and multiply $|#3|=\frac{\operatorname{atan} z}{z}$
1466 % with~|#6|, the adjusted~$z$. Otherwise, multiply $|#3|=\frac{\operatorname{atan}
1467 % z}{z}$ with $|#4|=z$, then compute the appropriate multiple of
1468 % $\frac{\pi}{4}$ and add or subtract the product $|#3|\cdot|#4|$. In
1469 % both cases, convert to a floating point with
1470 % \cs{@@_fixed_to_float_o:wN}.
1471 % \begin{macrocode}
1472 \cs_new:Npn \@@_atan_combine_o:NwwwwwN
1473 #1 #2\@@_sep: #3\@@_sep: #4\@@_sep: #5,#6\@@_sep: #7
1474 {
1475 \exp_after:wN \@@_sanitize:Nw
1476 \exp_after:wN #1
1477 \int_value:w \@@_int_eval:w
1478 \if_meaning:w 0 #2
1479 \exp_after:wN \use_i:nn
1480 \else:
1481 \exp_after:wN \use_ii:nn
1482 \fi:
1483 { #5 \@@_fixed_mul:wwn #3\@@_sep: #6\@@_sep: }
1484 {
1485 \@@_fixed_mul:wwn #3\@@_sep: #4\@@_sep:
1486 {
1487 \exp_after:wN \@@_atan_combine_aux:ww
1488 \int_value:w \@@_int_eval:w #2 / 2 \@@_sep: #2\@@_sep:
1489 }
1490 }
1491 { #7 \@@_fixed_to_float_o:wN \@@_fixed_to_float_rad_o:wN }
1492 #1
1493 }
1494 \cs_new:Npn \@@_atan_combine_aux:ww #1\@@_sep: #2\@@_sep:
1495 {
1496 \@@_fixed_mul_short:wwn
1497 {7853}{9816}{3397}{4483}{0961}{5661}\@@_sep:
1498 {#1}{0000}{0000}\@@_sep:
1499 {
1500 \if_int_odd:w #2 \exp_stop_f:
1501 \exp_after:wN \@@_fixed_sub:wwn
1502 \else:
1503 \exp_after:wN \@@_fixed_add:wwn
1504 \fi:
1505 }
1506 }
1507 % \end{macrocode}
1508 % \end{macro}
1509 %
1510 % \subsubsection{Arcsine and arccosine}
1511 %
1512 % \begin{macro}[EXP]{\@@_asin_o:w}
1513 % Again, the first argument provided by \pkg{l3fp-parse} is
1514 % \cs{use_i:nn} if we are to work in radians and \cs{use_ii:nn} for
1515 % degrees. Then comes a floating point number. The arcsine of $\pm
1516 % 0$ or \nan{} is the same floating point number. The arcsine of
1517 % $\pm\infty$ raises an invalid operation exception. Otherwise, call
1518 % an auxiliary common with \cs{@@_acos_o:w}, feeding it information
1519 % about what function is being performed (for \enquote{invalid operation}
1520 % exceptions).
1521 % \begin{macrocode}
1522 \cs_new:Npn \@@_asin_o:w #1 \s_@@ \@@_chk:w #2#3\@@_sep: @
1523 {
1524 \if_case:w #2 \exp_stop_f:
1525 \@@_case_return_same_o:w
1526 \or:
1527 \@@_case_use:nw
1528 { \@@_asin_normal_o:NfwNnnnnw #1 { #1 { asin } { asind } } }
1529 \or:
1530 \@@_case_use:nw
1531 { \@@_invalid_operation_o:fw { #1 { asin } { asind } } }
1532 \else:
1533 \@@_case_return_same_o:w
1534 \fi:
1535 \s_@@ \@@_chk:w #2 #3\@@_sep:
1536 }
1537 % \end{macrocode}
1538 % \end{macro}
1539 %
1540 % \begin{macro}[EXP]{\@@_acos_o:w}
1541 % The arccosine of $\pm 0$ is $\pi / 2$ (in degrees,~$90$). The
1542 % arccosine of $\pm\infty$ raises an invalid operation exception. The
1543 % arccosine of \nan{} is itself. Otherwise, call an auxiliary common
1544 % with \cs{@@_sin_o:w}, informing it that it was called by
1545 % \texttt{acos} or \texttt{acosd}, and preparing to swap some
1546 % arguments down the line.
1547 % \begin{macrocode}
1548 \cs_new:Npn \@@_acos_o:w #1 \s_@@ \@@_chk:w #2#3\@@_sep: @
1549 {
1550 \if_case:w #2 \exp_stop_f:
1551 \@@_case_use:nw { \@@_atan_inf_o:NNNw #1 0 4 }
1552 \or:
1553 \@@_case_use:nw
1554 {
1555 \@@_asin_normal_o:NfwNnnnnw #1 { #1 { acos } { acosd } }
1556 \@@_reverse_args:Nww
1557 }
1558 \or:
1559 \@@_case_use:nw
1560 { \@@_invalid_operation_o:fw { #1 { acos } { acosd } } }
1561 \else:
1562 \@@_case_return_same_o:w
1563 \fi:
1564 \s_@@ \@@_chk:w #2 #3\@@_sep:
1565 }
1566 % \end{macrocode}
1567 % \end{macro}
1568 %
1569 % \begin{macro}[EXP]{\@@_asin_normal_o:NfwNnnnnw}
1570 % If the exponent~|#5| is at most $0$, the operand lies
1571 % within $(-1,1)$ and the operation is permitted: call
1572 % \cs{@@_asin_auxi_o:NnNww} with the appropriate arguments. If the
1573 % number is exactly~$\pm 1$ (the test works because we know that
1574 % $|#5|\geq 1$, $|#6#7|\geq 10000000$, $|#8#9|\geq 0$, with equality
1575 % only for $\pm 1$), we also call \cs{@@_asin_auxi_o:NnNww}.
1576 % Otherwise, \cs{@@_use_i:ww} gets rid of the \texttt{asin} auxiliary,
1577 % and raises instead an invalid operation, because the operand is
1578 % outside the domain of arcsine or arccosine.
1579 % \begin{macrocode}
1580 \cs_new:Npn \@@_asin_normal_o:NfwNnnnnw
1581 #1#2#3 \s_@@ \@@_chk:w 1#4#5#6#7#8#9\@@_sep:
1582 {
1583 \if_int_compare:w #5 < \c_one_int
1584 \exp_after:wN \@@_use_none_until_s:w
1585 \fi:
1586 \if_int_compare:w \@@_int_eval:w #5 + #6#7 + #8#9 = 1000 0001 ~
1587 \exp_after:wN \@@_use_none_until_s:w
1588 \fi:
1589 \@@_use_i:ww
1590 \@@_invalid_operation_o:fw {#2}
1591 \s_@@ \@@_chk:w 1#4{#5}{#6}{#7}{#8}{#9}\@@_sep:
1592 \@@_asin_auxi_o:NnNww
1593 #1 {#3} #4 #5,{#6}{#7}{#8}{#9}{0000}{0000}\@@_sep:
1594 }
1595 % \end{macrocode}
1596 % \end{macro}
1597 %
1598 % \begin{macro}[EXP]{\@@_asin_auxi_o:NnNww, \@@_asin_isqrt:wn}
1599 % We compute $x/\sqrt{1-x^2}$. This function is used by \texttt{asin}
1600 % and \texttt{acos}, but also by \texttt{acsc} and \texttt{asec} after
1601 % inverting the operand, thus it must manipulate extended-precision
1602 % numbers. First evaluate $1-x^2$ as $(1+x)(1-x)$: this behaves
1603 % better near~$x=1$. We do the addition/subtraction with fixed point
1604 % numbers (they are not implemented for extended-precision floats),
1605 % but go back to extended-precision floats to multiply and compute the
1606 % inverse square root $1/\sqrt{1-x^2}$. Finally, multiply by the
1607 % (positive) extended-precision float $\lvert x\rvert$, and feed the
1608 % (signed) result, and the number~$+1$, as arguments to the arctangent
1609 % function. When computing the arccosine, the arguments
1610 % $x/\sqrt{1-x^2}$ and~$+1$ are swapped by~|#2|
1611 % (\cs{@@_reverse_args:Nww} in that case) before
1612 % \cs{@@_atan_test_o:NwwNwwN} is evaluated. Note that the arctangent
1613 % function requires normalized arguments, hence the need for
1614 % \texttt{ep_to_ep} and \texttt{continue} after \texttt{ep_mul}.
1615 % \begin{macrocode}
1616 \cs_new:Npn \@@_asin_auxi_o:NnNww #1#2#3#4,#5\@@_sep:
1617 {
1618 \@@_ep_to_fixed:wwn #4,#5\@@_sep:
1619 \@@_asin_isqrt:wn
1620 \@@_ep_mul:wwwwn #4,#5\@@_sep:
1621 \@@_ep_to_ep:wwN
1622 \@@_fixed_continue:wn
1623 { #2 \@@_atan_test_o:NwwNwwN #3 }
1624 0 1,{1000}{0000}{0000}{0000}{0000}{0000}\@@_sep: #1
1625 }
1626 \cs_new:Npn \@@_asin_isqrt:wn #1\@@_sep:
1627 {
1628 \exp_after:wN \@@_fixed_sub:wwn \c_@@_one_fixed_tl #1\@@_sep:
1629 {
1630 \@@_fixed_add_one:wN #1\@@_sep:
1631 \@@_fixed_continue:wn { \@@_ep_mul:wwwwn 0, } 0,
1632 }
1633 \@@_ep_isqrt:wwn
1634 }
1635 % \end{macrocode}
1636 % \end{macro}
1637 %
1638 % \subsubsection{Arccosecant and arcsecant}
1639 %
1640 % \begin{macro}[EXP]{\@@_acsc_o:w}
1641 % Cases are mostly labeled by~|#2|, except when |#2| is~$2$: then we
1642 % use |#3#2|, which is $02=2$ when the number is $+\infty$ and
1643 % $22$~when the number is $-\infty$. The arccosecant of $\pm 0$
1644 % raises an invalid operation exception. The arccosecant of
1645 % $\pm\infty$ is $\pm 0$ with the same sign. The arcosecant of \nan{}
1646 % is itself. Otherwise, \cs{@@_acsc_normal_o:NfwNnw} does some more
1647 % tests, keeping the function name (\texttt{acsc} or \texttt{acscd})
1648 % as an argument for invalid operation exceptions.
1649 % \begin{macrocode}
1650 \cs_new:Npn \@@_acsc_o:w #1 \s_@@ \@@_chk:w #2#3#4\@@_sep: @
1651 {
1652 \if_case:w \if_meaning:w 2 #2 #3 \fi: #2 \exp_stop_f:
1653 \@@_case_use:nw
1654 { \@@_invalid_operation_o:fw { #1 { acsc } { acscd } } }
1655 \or: \@@_case_use:nw
1656 { \@@_acsc_normal_o:NfwNnw #1 { #1 { acsc } { acscd } } }
1657 \or: \@@_case_return_o:Nw \c_zero_fp
1658 \or: \@@_case_return_same_o:w
1659 \else: \@@_case_return_o:Nw \c_minus_zero_fp
1660 \fi:
1661 \s_@@ \@@_chk:w #2 #3 #4\@@_sep:
1662 }
1663 % \end{macrocode}
1664 % \end{macro}
1665 %
1666 % \begin{macro}[EXP]{\@@_asec_o:w}
1667 % The arcsecant of $\pm 0$ raises an invalid operation exception. The
1668 % arcsecant of $\pm\infty$ is $\pi / 2$ (in degrees,~$90$). The
1669 % arcosecant of \nan{} is itself. Otherwise, do some more tests,
1670 % keeping the function name \texttt{asec} (or \texttt{asecd}) as an
1671 % argument for invalid operation exceptions, and a
1672 % \cs{@@_reverse_args:Nww} following precisely that appearing in
1673 % \cs{@@_acos_o:w}.
1674 % \begin{macrocode}
1675 \cs_new:Npn \@@_asec_o:w #1 \s_@@ \@@_chk:w #2#3\@@_sep: @
1676 {
1677 \if_case:w #2 \exp_stop_f:
1678 \@@_case_use:nw
1679 { \@@_invalid_operation_o:fw { #1 { asec } { asecd } } }
1680 \or:
1681 \@@_case_use:nw
1682 {
1683 \@@_acsc_normal_o:NfwNnw #1 { #1 { asec } { asecd } }
1684 \@@_reverse_args:Nww
1685 }
1686 \or: \@@_case_use:nw { \@@_atan_inf_o:NNNw #1 0 4 }
1687 \else: \@@_case_return_same_o:w
1688 \fi:
1689 \s_@@ \@@_chk:w #2 #3\@@_sep:
1690 }
1691 % \end{macrocode}
1692 % \end{macro}
1693 %
1694 % \begin{macro}[EXP]{\@@_acsc_normal_o:NfwNnw}
1695 % If the exponent is non-positive, the operand is less than~$1$ in
1696 % absolute value, which is always an invalid operation: complain.
1697 % Otherwise, compute the inverse of the operand, and feed it to
1698 % \cs{@@_asin_auxi_o:NnNww} (with all the appropriate arguments). This
1699 % computes what we want thanks to
1700 % $\operatorname{acsc}(x)=\operatorname{asin}(1/x)$ and
1701 % $\operatorname{asec}(x)=\operatorname{acos}(1/x)$.
1702 % \begin{macrocode}
1703 \cs_new:Npn \@@_acsc_normal_o:NfwNnw #1#2#3 \s_@@ \@@_chk:w 1#4#5#6\@@_sep:
1704 {
1705 \int_compare:nNnTF {#5} < 1
1706 {
1707 \@@_invalid_operation_o:fw {#2}
1708 \s_@@ \@@_chk:w 1#4{#5}#6\@@_sep:
1709 }
1710 {
1711 \@@_ep_div:wwwwn
1712 1,{1000}{0000}{0000}{0000}{0000}{0000}\@@_sep:
1713 #5,#6{0000}{0000}\@@_sep:
1714 { \@@_asin_auxi_o:NnNww #1 {#3} #4 }
1715 }
1716 }
1717 % \end{macrocode}
1718 % \end{macro}
1719 %
1720 % \begin{macrocode}
1721 %</code>
1722 % \end{macrocode}
1723 %
1724 % \end{implementation}
1725 %
1726 % \PrintChanges
1727 %
1728 % \PrintIndex