diff options
Diffstat (limited to 'Master/texmf-dist/source/latex/l3kernel/l3fp-parse.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/l3kernel/l3fp-parse.dtx | 158 |
1 files changed, 76 insertions, 82 deletions
diff --git a/Master/texmf-dist/source/latex/l3kernel/l3fp-parse.dtx b/Master/texmf-dist/source/latex/l3kernel/l3fp-parse.dtx index 5fe3aaac4d9..1aa0956212d 100644 --- a/Master/texmf-dist/source/latex/l3kernel/l3fp-parse.dtx +++ b/Master/texmf-dist/source/latex/l3kernel/l3fp-parse.dtx @@ -22,7 +22,7 @@ % %<*driver> \documentclass[full]{l3doc} -\GetIdInfo$Id: l3fp-parse.dtx 6877 2017-02-10 03:59:09Z bruno $ +\GetIdInfo$Id: l3fp-parse.dtx 6943 2017-02-17 16:47:59Z bruno $ {L3 Floating-point expression parsing} \begin{document} \DocInput{\jobname.dtx} @@ -195,17 +195,17 @@ % already found, |12345|. This integer is unfinished, causing the % second \cs{exp_after:wN} to expand, and to trigger the construction % \cs{exp:w}, which expands |\operand:w|, defined to read -% what follows and make a number out of it, then leave \cs{c_zero}, the +% what follows and make a number out of it, then leave \cs{exp_end:}, the % number, and a semicolon in the input stream. Once |\operand:w| is % done expanding, we obtain essentially % \begin{quote}\ttfamily % \cs{exp_after:wN} |\add:ww| \cs{__int_value:w} 12345 ; \newline -% \cs{exp:w} \cs{c_zero} 333444 ; +% \cs{exp:w} \cs{exp_end:} 333444 ; % \end{quote} % where in fact \cs{exp_after:wN} has already been expanded, % \cs{__int_value:w} has already seen |12345|, and % \cs{exp:w} is still looking for a number. It finds -% \cs{c_zero}, hence expands to nothing. Now, \cs{__int_value:w} sees +% \cs{exp_end:}, hence expands to nothing. Now, \cs{__int_value:w} sees % the \texttt{;}, which cannot be part of a number. The expansion % stops, and we are left with % \begin{quote}\ttfamily @@ -499,33 +499,33 @@ % \item If the next token is a control sequence, it could be the % special marker \cs{s_@@_mark}, and % otherwise it is a case of juxtaposing numbers, such as -% |2\c_three|, with an implied multiplication. +% |2\c_zero|, with an implied multiplication. % \item If the next token is a letter, it is also a case of % juxtaposition, as letters cannot be proper infix operators. % \item Otherwise (including in the case of digits), if the token is a % known infix operator, the appropriate % |\__fp_infix_|\meta{operator}|:N| function is built, and if it % does not exist, we complain. In particular, the juxtaposition -% |\c_three 2| is disallowed. +% |\c_zero 2| is disallowed. % \end{itemize} % % In the above, we need to test whether a character token~|#1| is a % digit: % \begin{verbatim} -% \if_int_compare:w \c_nine < 1 \token_to_str:N #1 \exp_stop_f: +% \if_int_compare:w 9 < 1 \token_to_str:N #1 \exp_stop_f: % is a digit % \else: % not a digit % \fi: % \end{verbatim} -% To exclude |0|, replace \cs{c_nine} by \cs{c_ten}. The use of +% To exclude |0|, replace |9| by |10|. The use of % \cs{token_to_str:N} ensures that a digit with any catcode is detected. % To test if a character token is a letter, we need to work with its % character code, testing if |`#1| lies in $[65,90]$ (uppercase letters) % or $[97,112]$ (lowercase letters) % \begin{verbatim} % \if_int_compare:w \__int_eval:w -% ( `#1 \if_int_compare:w `#1 > `Z - 32 \fi: ) / 26 = \c_three +% ( `#1 \if_int_compare:w `#1 > `Z - 32 \fi: ) / 26 = 3 \exp_stop_f: % is a letter % \else: % not a letter @@ -698,7 +698,7 @@ { \cs_new:cpn { @@_parse_digits_ #1 :N } ##1 { - \if_int_compare:w \c_nine < 1 \token_to_str:N ##1 \exp_stop_f: + \if_int_compare:w 9 < 1 \token_to_str:N ##1 \exp_stop_f: \token_to_str:N ##1 \exp_after:wN #2 \exp:w \else: \@@_parse_return_semicolon:w #3 ##1 @@ -745,7 +745,7 @@ \exp_after:wN \@@_parse_one_register:NN \fi: \else: - \if_int_compare:w \c_nine < 1 \token_to_str:N #2 \exp_stop_f: + \if_int_compare:w 9 < 1 \token_to_str:N #2 \exp_stop_f: \exp_after:wN \exp_after:wN \exp_after:wN \@@_parse_one_digit:NN \else: @@ -940,7 +940,7 @@ \exp_after:wN #1 \exp:w \exp_end_continue_f:w \exp_after:wN \@@_sanitize:wN - \__int_value:w \__int_eval:w \c_zero \@@_parse_trim_zeros:N + \__int_value:w \__int_eval:w 0 \@@_parse_trim_zeros:N } % \end{macrocode} % \end{macro} @@ -956,8 +956,8 @@ { \if_int_compare:w \__int_eval:w - ( `#2 \if_int_compare:w `#2 > `Z - \c_thirty_two \fi: ) / 26 - = \c_three + ( `#2 \if_int_compare:w `#2 > `Z - 32 \fi: ) / 26 + = 3 \exp_stop_f: \exp_after:wN \@@_parse_word:Nw \exp_after:wN #1 \exp_after:wN #2 @@ -1005,13 +1005,12 @@ \exp_end_continue_f:w \if_int_compare:w \if_catcode:w \scan_stop: \exp_not:N #1 - \c_zero + 0 \else: \__int_eval:w - ( `#1 \if_int_compare:w `#1 > `Z - \c_thirty_two \fi: ) - / 26 + ( `#1 \if_int_compare:w `#1 > `Z - 32 \fi: ) / 26 \fi: - = \c_three + = 3 \exp_stop_f: \exp_after:wN #1 \exp:w \exp_after:wN \@@_parse_letters:N \exp:w @@ -1100,7 +1099,7 @@ { \fi: \fi: - \if_int_compare:w \c_nine < 1 \token_to_str:N #1 \exp_stop_f: + \if_int_compare:w 9 < 1 \token_to_str:N #1 \exp_stop_f: \exp_after:wN \@@_parse_large:N \else: \exp_after:wN \@@_parse_zero: @@ -1123,7 +1122,7 @@ \cs_new:Npn \@@_parse_strim_zeros:N #1 { \if:w 0 \exp_not:N #1 - - \c_one + - 1 \exp_after:wN \@@_parse_strim_zeros:N \exp:w \else: \@@_parse_strim_end:w #1 @@ -1133,7 +1132,7 @@ \cs_new:Npn \@@_parse_strim_end:w #1 \fi: \@@_parse_expand:w { \fi: - \if_int_compare:w \c_nine < 1 \token_to_str:N #1 \exp_stop_f: + \if_int_compare:w 9 < 1 \token_to_str:N #1 \exp_stop_f: \exp_after:wN \@@_parse_small:N \else: \exp_after:wN \@@_parse_zero: @@ -1191,7 +1190,7 @@ % We leave \meta{digits} \meta{zeros} in the input stream: the % functions used to grab digits are such that this constitutes digits % $1$ through~$8$ of the significand. Then prepare to pack $8$~more -% digits, with an exponent shift of \cs{c_zero} (this shift is used in +% digits, with an exponent shift of zero (this shift is used in % the case of a large significand). If |#4|~is a digit, leave it % behind for the packing function, and read $6$~more digits to reach a % total of $15$~digits: further digits are involved in the rounding. @@ -1202,9 +1201,9 @@ { #1 #2 \exp_after:wN \@@_parse_pack_trailing:NNNNNNww - \exp_after:wN \c_zero + \exp_after:wN 0 \__int_value:w \__int_eval:w 1 - \if_int_compare:w \c_nine < 1 \token_to_str:N #4 \exp_stop_f: + \if_int_compare:w 9 < 1 \token_to_str:N #4 \exp_stop_f: \token_to_str:N #4 \exp_after:wN \@@_parse_small_trailing:wwNN \__int_value:w 1 @@ -1226,14 +1225,14 @@ % stream. If the \meta{next~token} is a digit, it is the $16$th % digit, we keep it, then the \texttt{small_round} auxiliary considers % this digit and all further digits to perform the rounding: the -% function expands to nothing, to |+\c_zero| or to |+\c_one|. +% function expands to nothing, to |+0| or to |+1|. % Otherwise, there is no $16$-th digit, so we put a~$0$, and look for % an exponent. % \begin{macrocode} \cs_new:Npn \@@_parse_small_trailing:wwNN 1 #1 ; #2; #3 #4 { #1 #2 - \if_int_compare:w \c_nine < 1 \token_to_str:N #4 \exp_stop_f: + \if_int_compare:w 9 < 1 \token_to_str:N #4 \exp_stop_f: \token_to_str:N #4 \exp_after:wN \@@_parse_small_round:NN \exp_after:wN #4 @@ -1260,7 +1259,7 @@ % argument is~$2$. The \texttt{trailing} function has an exponent % shift as its first argument, which we add to the exponent found in % the |e...| syntax. If the trailing digits cause a carry, the -% integer expression for the leading digits is incremented (|+ \c_one| +% integer expression for the leading digits is incremented (|+1| % in the code below). If the leading digits propagate this carry all % the way up, the function \cs{@@_parse_pack_carry:w} increments the % exponent, and changes the significand from |0000...| to |1000...|: @@ -1269,7 +1268,7 @@ % \begin{macrocode} \cs_new:Npn \@@_parse_pack_trailing:NNNNNNww #1 #2 #3#4#5#6 #7; #8 ; { - \if_meaning:w 2 #2 + \c_one \fi: + \if_meaning:w 2 #2 + 1 \fi: ; #8 + #1 ; {#3#4#5#6} {#7}; } \cs_new:Npn \@@_parse_pack_leading:NNNNNww #1 #2#3#4#5 #6; #7; @@ -1279,7 +1278,7 @@ ; 0 {#2#3#4#5} {#6} } \cs_new:Npn \@@_parse_pack_carry:w \fi: ; 0 #1 - { \fi: + \c_one ; 0 {1000} } + { \fi: + 1 ; 0 {1000} } % \end{macrocode} % \end{macro} % @@ -1325,10 +1324,10 @@ % \begin{macrocode} \cs_new:Npn \@@_parse_large_leading:wwNN 1 #1 ; #2; #3 #4 { - + \c_eight - #3 + + \c_@@_half_prec_int - #3 \exp_after:wN \@@_parse_pack_leading:NNNNNww \__int_value:w \__int_eval:w 1 #1 - \if_int_compare:w \c_nine < 1 \token_to_str:N #4 \exp_stop_f: + \if_int_compare:w 9 < 1 \token_to_str:N #4 \exp_stop_f: \exp_after:wN \@@_parse_large_trailing:wwNN \__int_value:w 1 \token_to_str:N #4 \exp_after:wN \@@_parse_digits_vi:N @@ -1346,7 +1345,7 @@ \else: #2 \exp_after:wN \@@_parse_pack_trailing:NNNNNNww - \exp_after:wN \c_zero + \exp_after:wN 0 \__int_value:w 1 0000 0000 \@@_parse_exponent:Nw #4 \fi: @@ -1376,16 +1375,16 @@ % \begin{macrocode} \cs_new:Npn \@@_parse_large_trailing:wwNN 1 #1 ; #2; #3 #4 { - \if_int_compare:w \c_nine < 1 \token_to_str:N #4 \exp_stop_f: + \if_int_compare:w 9 < 1 \token_to_str:N #4 \exp_stop_f: \exp_after:wN \@@_parse_pack_trailing:NNNNNNww - \exp_after:wN \c_eight + \exp_after:wN \c_@@_half_prec_int \__int_value:w \__int_eval:w 1 #1 \token_to_str:N #4 \exp_after:wN \@@_parse_large_round:NN \exp_after:wN #4 \exp:w \else: \exp_after:wN \@@_parse_pack_trailing:NNNNNNww - \__int_value:w \__int_eval:w \c_seven - #3 \exp_stop_f: + \__int_value:w \__int_eval:w 7 - #3 \exp_stop_f: \__int_value:w \__int_eval:w 1 #1 \if:w . \exp_not:N #4 \exp_after:wN \@@_parse_small_trailing:wwNN @@ -1412,15 +1411,15 @@ % small or large). It should appear in an integer expression. This % function reads digits one by one, until reaching a non-digit, and % adds~$1$ to the integer expression for each digit. If all digits -% found are~$0$, the function ends the expression by |;\c_zero|, -% otherwise by |;\c_one|. This is done by switching the loop to +% found are~$0$, the function ends the expression by |;0|, +% otherwise by |;1|. This is done by switching the loop to % |round_up| at the first non-zero digit, thus we avoid to test % whether digits are~$0$ or not once we see a first non-zero digit. % \begin{macrocode} \cs_new:Npn \@@_parse_round_loop:N #1 { - \if_int_compare:w \c_nine < 1 \token_to_str:N #1 \exp_stop_f: - + \c_one + \if_int_compare:w 9 < 1 \token_to_str:N #1 \exp_stop_f: + + 1 \if:w 0 \token_to_str:N #1 \exp_after:wN \@@_parse_round_loop:N \exp:w @@ -1429,18 +1428,18 @@ \exp:w \fi: \else: - \@@_parse_return_semicolon:w \c_zero #1 + \@@_parse_return_semicolon:w 0 #1 \fi: \@@_parse_expand:w } \cs_new:Npn \@@_parse_round_up:N #1 { - \if_int_compare:w \c_nine < 1 \token_to_str:N #1 \exp_stop_f: - + \c_one + \if_int_compare:w 9 < 1 \token_to_str:N #1 \exp_stop_f: + + 1 \exp_after:wN \@@_parse_round_up:N \exp:w \else: - \@@_parse_return_semicolon:w \c_one #1 + \@@_parse_return_semicolon:w 1 #1 \fi: \@@_parse_expand:w } @@ -1451,7 +1450,7 @@ % After the loop \cs{@@_parse_round_loop:N}, this function fetches an % exponent with \cs{@@_parse_exponent:N}, and combines it with the % number of digits counted by \cs{@@_parse_round_loop:N}. At the same -% time, the result \cs{c_zero} or \cs{c_one} is added to the +% time, the result |0| or |1| is added to the % surrounding integer expression. % \begin{macrocode} \cs_new:Npn \@@_parse_round_after:wN #1; #2 @@ -1467,11 +1466,11 @@ % Here, |#1|~is the digit that we are currently rounding (we only care % whether it is even or odd). If |#2|~is not a digit, then fetch an % exponent and expand to |;|\meta{exponent} only. Otherwise, we will -% expand to |+\c_zero| or |+\c_one|, then |;|\meta{exponent}. To +% expand to |+0| or |+1|, then |;|\meta{exponent}. To % decide which, call \cs{@@_round_s:NNNw} to know whether to round up, % giving it as arguments a sign~$0$ (all explicit numbers are % positive), the digit |#1|~to round, the first following digit~|#2|, -% and either |+\c_zero| or |+\c_one| depending on whether the +% and either |+0| or |+1| depending on whether the % following digits are all zero or not. This last argument is % obtained by \cs{@@_parse_round_loop:N}, whose number of digits we % discard by multiplying it by~$0$. The exponent which follows the @@ -1479,7 +1478,7 @@ % \begin{macrocode} \cs_new:Npn \@@_parse_small_round:NN #1#2 { - \if_int_compare:w \c_nine < 1 \token_to_str:N #2 \exp_stop_f: + \if_int_compare:w 9 < 1 \token_to_str:N #2 \exp_stop_f: + \exp_after:wN \@@_round_s:NNNw \exp_after:wN 0 @@ -1487,7 +1486,7 @@ \exp_after:wN #2 \__int_value:w \__int_eval:w \exp_after:wN \@@_parse_round_after:wN - \__int_value:w \__int_eval:w \c_zero * \__int_eval:w \c_zero + \__int_value:w \__int_eval:w 0 * \__int_eval:w 0 \exp_after:wN \@@_parse_round_loop:N \exp:w \else: @@ -1520,7 +1519,7 @@ % \begin{macrocode} \cs_new:Npn \@@_parse_large_round:NN #1#2 { - \if_int_compare:w \c_nine < 1 \token_to_str:N #2 \exp_stop_f: + \if_int_compare:w 9 < 1 \token_to_str:N #2 \exp_stop_f: + \exp_after:wN \@@_round_s:NNNw \exp_after:wN 0 @@ -1528,7 +1527,7 @@ \exp_after:wN #2 \__int_value:w \__int_eval:w \exp_after:wN \@@_parse_large_round_aux:wNN - \__int_value:w \__int_eval:w \c_one + \__int_value:w \__int_eval:w 1 \exp_after:wN \@@_parse_round_loop:N \else: %^^A could be dot, or e, or other \exp_after:wN \@@_parse_large_round_test:NN @@ -1553,12 +1552,12 @@ \exp_after:wN \@@_parse_round_after:wN \__int_value:w \__int_eval:w #1 \if:w . \exp_not:N #3 - + \c_zero * \__int_eval:w \c_zero + + 0 * \__int_eval:w 0 \exp_after:wN \@@_parse_round_loop:N \exp:w \exp_after:wN \@@_parse_expand:w \else: \exp_after:wN ; - \exp_after:wN \c_zero + \exp_after:wN 0 \exp_after:wN #3 \fi: } @@ -1633,7 +1632,7 @@ \cs_new:Npn \@@_parse_exponent_aux:N #1 { \if_int_compare:w \if_catcode:w \scan_stop: \exp_not:N #1 - \c_zero \else: `#1 \fi: > `9 \exp_stop_f: + 0 \else: `#1 \fi: > `9 \exp_stop_f: 0 \exp_after:wN ; \exp_after:wN e \else: \exp_after:wN \@@_parse_exponent_sign:N @@ -1665,7 +1664,7 @@ % \begin{macrocode} \cs_new:Npn \@@_parse_exponent_body:N #1 { - \if_int_compare:w \c_nine < 1 \token_to_str:N #1 \exp_stop_f: + \if_int_compare:w 9 < 1 \token_to_str:N #1 \exp_stop_f: \token_to_str:N #1 \exp_after:wN \@@_parse_exponent_digits:N \exp:w @@ -1692,7 +1691,7 @@ % \begin{macrocode} \cs_new:Npn \@@_parse_exponent_digits:N #1 { - \if_int_compare:w \c_nine < 1 \token_to_str:N #1 \exp_stop_f: + \if_int_compare:w 9 < 1 \token_to_str:N #1 \exp_stop_f: \token_to_str:N #1 \exp_after:wN \@@_parse_exponent_digits:N \exp:w @@ -1723,7 +1722,8 @@ \if_catcode:w \scan_stop: \exp_not:N #1 \if_meaning:w \scan_stop: #1 \if_int_compare:w - \__str_if_eq_x:nn { \s_@@ } { \exp_not:N #1 } = \c_zero + \__str_if_eq_x:nn { \s_@@ } { \exp_not:N #1 } + = 0 \exp_stop_f: 0 \__msg_kernel_expandable_error:nnn { kernel } { fp-after-e } { floating~point~ } @@ -1737,7 +1737,7 @@ \else: \if_int_compare:w \__str_if_eq_x:nn { \__int_value:w #1 } { \tex_the:D #1 } - = \c_zero + = 0 \exp_stop_f: \__int_value:w #1 \else: 0 @@ -1826,7 +1826,7 @@ \exp_after:wN #1 \exp:w \exp_end_continue_f:w \exp_after:wN \@@_sanitize:wN - \__int_value:w \__int_eval:w \c_zero \@@_parse_strim_zeros:N + \__int_value:w \__int_eval:w 0 \@@_parse_strim_zeros:N } % \end{macrocode} % \end{macro} @@ -2111,6 +2111,8 @@ % \end{macro} % % \begin{macro}[aux, EXP]{\@@_parse_word_round:N, \@@_parse_round:Nw} +% \begin{macro}[aux, deprecated = 2017-12-31]{round+, round0, round-} +% This looks for |+|, |-|, |0| after |round|. That syntax is deprecated. % \begin{macrocode} \cs_new:Npn \@@_parse_word_round:N #1#2 { @@ -2133,6 +2135,7 @@ #1 #2 \@@_round_to_nearest:NNN #3#4 { #2 #1 #3 } % \end{macrocode} % \end{macro} +% \end{macro} % % \subsection{Main functions} % @@ -2231,7 +2234,7 @@ \if_catcode:w \scan_stop: \exp_not:N #2 \if_int_compare:w \__str_if_eq_x:nn { \s_@@_mark } { \exp_not:N #2 } - = \c_zero + = 0 \exp_stop_f: \exp_after:wN \exp_after:wN \exp_after:wN \@@_parse_infix_mark:NNN \else: @@ -2241,9 +2244,8 @@ \else: \if_int_compare:w \__int_eval:w - ( `#2 \if_int_compare:w `#2 > `Z - \c_thirty_two \fi: ) - / 26 - = \c_three + ( `#2 \if_int_compare:w `#2 > `Z - 32 \fi: ) / 26 + = 3 \exp_stop_f: \exp_after:wN \exp_after:wN \exp_after:wN \@@_parse_infix_juxtapose:N \else: @@ -2592,29 +2594,20 @@ % } % \begin{macrocode} \cs_new:cpn { @@_parse_infix_<:N } #1 - { - \@@_parse_compare:NNNNNNN #1 \c_one - \c_zero \c_zero \c_zero \c_zero < - } + { \@@_parse_compare:NNNNNNN #1 1 0 0 0 0 < } \cs_new:cpn { @@_parse_infix_=:N } #1 - { - \@@_parse_compare:NNNNNNN #1 \c_one - \c_zero \c_zero \c_zero \c_zero = - } + { \@@_parse_compare:NNNNNNN #1 1 0 0 0 0 = } \cs_new:cpn { @@_parse_infix_>:N } #1 - { - \@@_parse_compare:NNNNNNN #1 \c_one - \c_zero \c_zero \c_zero \c_zero > - } + { \@@_parse_compare:NNNNNNN #1 1 0 0 0 0 > } \cs_new:cpn { @@_parse_infix_!:N } #1 { \exp_after:wN \@@_parse_compare:NNNNNNN \exp_after:wN #1 - \exp_after:wN \c_zero - \exp_after:wN \c_one - \exp_after:wN \c_one - \exp_after:wN \c_one - \exp_after:wN \c_one + \exp_after:wN 0 + \exp_after:wN 1 + \exp_after:wN 1 + \exp_after:wN 1 + \exp_after:wN 1 } \cs_new:Npn \@@_parse_excl_error: { @@ -2636,7 +2629,7 @@ { \if_case:w \if_catcode:w \scan_stop: \exp_not:N #7 - \c_four + 4 \exp_stop_f: \else: \__int_eval:w `#7 - `< \__int_eval_end: \fi: @@ -2676,12 +2669,13 @@ { \if_int_odd:w \if_meaning:w \c_zero_fp #3 - \c_zero + 0 \else: \if_case:w \@@_compare_back:ww #8 #2 \exp_stop_f: #5 \or: #6 \or: #7 \else: #4 \fi: \fi: + \exp_stop_f: \exp_after:wN \@@_parse_apply_compare_aux:NNwN \exp_after:wN \c_one_fp \else: @@ -2748,7 +2742,7 @@ { \@@_new_function:Ncfnn #1 { @@_user_ \cs_to_str:N #1 } - { \int_eval:n { \tl_count:n {#2} / \c_two } } + { \int_eval:n { \tl_count:n {#2} / 2 } } {#2} } \cs_new_protected:Npn \@@_new_function:NNnnn #1#2#3#4#5 |