summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/l3kernel/l3fp-types.dtx
blob: 0d589c9549f501acb3b1f38d5339b9cb163f76f5 (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
% \iffalse
%
%% File l3fp-types.dtx (C) Copyright 2012-2015,2017,2018,2020,2021,2023 The LaTeX 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
%
%    http://www.latex-project.org/lppl.txt
%
% This file is part of the "l3kernel 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>
\documentclass[full]{l3doc}
\usepackage{amsmath}
\begin{document}
  \DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \title{^^A
%   The \pkg{l3fp-types} module\\ Floating point types^^A
% }
%
% \author{^^A
%  The \LaTeX{} Project\thanks
%    {^^A
%      E-mail:
%        \href{mailto:latex-team@latex-project.org}
%          {latex-team@latex-project.org}^^A
%    }^^A
% }
%
% \date{Released 2024-03-14}
%
% \maketitle
%
% \begin{documentation}
%
% \end{documentation}
%
% \begin{implementation}
%
% \section{\pkg{l3fp-types} implementation}
%
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%
%    \begin{macrocode}
%<@@=fp>
%    \end{macrocode}
%
% \subsection{Support for types}
%
% Despite lack of documentation, the \pkg{l3fp} internals support types.
% Each additional type must define
% \begin{itemize}
%   \item |\s__fp_|\meta{type} and |\__fp_|\meta{type}|_chk:w|;
%   \item |\__fp_exp_after_|\meta{type}|_f:nw|;
%   \item |\__fp_|\meta{type}|_to_|\meta{out}|:w| for \meta{out} among
%     |decimal|, |scientific|, |tl|;
% \end{itemize}
% and may define
% \begin{itemize}
%   \item |\__fp_|\meta{type}|_to_int:w| and |\__fp_|\meta{type}|_to_dim:w|;
%   \item |\__fp_|\meta{op}|_|\meta{type}|_o:w| for any of the \meta{op}
%     that the type implements, among |acos|, |acsc|, |asec|, |asin|,
%     |cos|, |cot|, |csc|, |exp|, |ln|, |not|, |sec|, |set_sign|, |sin|,
%     |tan|;
%   \item |\__fp_|\meta{type_1}|_|\meta{op}|_|\meta{type_2}|_o:ww| for
%     \meta{op} among |^*/-+&|\verb"|" and for every pair of types;
%   \item |\__fp_|\meta{type_1}|_bcmp_|\meta{type_2}|:ww| for every
%     pair of types.
% \end{itemize}
% The latter is set up in \pkg{l3fp-logic}.
%
% \subsection{Dispatch according to the type}
%
% \begin{macro}[EXP]
%   {\@@_types_cs_to_op:N, \@@_types_cs_to_op_auxi:wwwn}
%   From |\__fp_|\meta{op}|_o:w| produce \meta{op}, otherwise~|?|.
%    \begin{macrocode}
\cs_new:Npe \@@_types_cs_to_op:N #1
  {
    \exp_not:N \exp_after:wN \exp_not:N \@@_types_cs_to_op_auxi:wwwn
      \exp_not:N \token_to_str:N #1 \s_@@_mark
      \exp_not:N \@@_use_i_delimit_by_s_stop:nw
      \tl_to_str:n { @@_ _o:w } \s_@@_mark
        { \exp_not:N \@@_use_i_delimit_by_s_stop:nw ? }
      \s_@@_stop
  }
\use:e
  {
    \cs_new:Npn \exp_not:N \@@_types_cs_to_op_auxi:wwwn
      #1 \tl_to_str:n { @@_ } #2
      \tl_to_str:n { _o:w } #3 \s_@@_mark #4 { #4 {#2} }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[EXP]{\@@_types_unary:NNw}
% \begin{macro}[EXP]
%   {\@@_types_unary_auxi:nNw, \@@_types_unary_auxii:NnNw}
%   \begin{syntax}
%     \cs{@@_types_unary:NNw} |\__fp_|\meta{function}|_o:w|
%     ~~\meta{token} \meta{operand} |@|
%   \end{syntax}
%    \begin{macrocode}
\cs_new:Npn \@@_types_unary:NNw #1
  {
    \exp_args:Nf \@@_types_unary_auxi:nNw
      { \@@_types_cs_to_op:N #1 }
  }
\cs_new:Npn \@@_types_unary_auxi:nNw #1#2#3
  {
    \exp_after:wN \@@_types_unary_auxii:NnNw
    \cs:w @@_#1 \@@_type_from_scan:N #3 _o:w \cs_end:
    {#1}
    #2#3
  }
\cs_new:Npn \@@_types_unary_auxii:NnNw #1#2#3
  {
    \token_if_eq_meaning:NNTF \scan_stop: #1
      { \@@_invalid_operation_o:nw {#2} }
      { #1 #3 }
  }
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}[EXP]{\@@_types_binary:Nww}
% \begin{macro}[EXP]
%   {\@@_types_binary_auxi:Nww, \@@_types_binary_auxii:NNww}
%   \begin{syntax}
%     \cs{@@_types_binary:Nww} |\__fp_|\meta{binop}|_o:ww|
%     ~~\meta{operand_1} \meta{operand_2} |@|
%   \end{syntax}
%    \begin{macrocode}
\cs_new:Npn \@@_types_binary:Nww #1
  {
    \exp_last_unbraced:Nf \@@_types_binary_auxi:Nww
      { \@@_types_cs_to_op:N #1 }
  }
\cs_new:Npn \@@_types_binary_auxi:Nww #1#2#3; #4#5; @
  {
    \exp_after:wN \@@_types_binary_auxii:NNww
    \cs:w
      @@
      \@@_type_from_scan:N #2
      _#1
      \@@_type_from_scan:N #4
      _o:ww
    \cs_end:
    #1 #2#3; #4#5;
  }
\cs_new:Npn \@@_types_binary_auxii:NNww #1#2
  {
    \token_if_eq_meaning:NNTF \scan_stop: #1
      { \@@_invalid_operation_o:Nww #2 }
      {#1}
  }
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%
% \end{implementation}
%
% \PrintIndex