diff options
Diffstat (limited to 'Master/texmf-dist/source/latex/expl3/l3fp.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/expl3/l3fp.dtx | 128 |
1 files changed, 83 insertions, 45 deletions
diff --git a/Master/texmf-dist/source/latex/expl3/l3fp.dtx b/Master/texmf-dist/source/latex/expl3/l3fp.dtx index 9d9a06d7272..e8ecdad5480 100644 --- a/Master/texmf-dist/source/latex/expl3/l3fp.dtx +++ b/Master/texmf-dist/source/latex/expl3/l3fp.dtx @@ -35,7 +35,7 @@ \RequirePackage{l3names} %</driver|package> %\fi -\GetIdInfo$Id: l3fp.dtx 2029 2010-09-19 13:59:02Z joseph $ +\GetIdInfo$Id: l3fp.dtx 2080 2010-10-27 11:02:09Z joseph $ {L3 Experimental floating-point operations} %\iffalse %<*driver> @@ -3779,9 +3779,10 @@ %\begin{macro}[aux]{\fp_compare_aux:N} %\begin{macro}[aux]{\fp_compare_=:} %\begin{macro}[aux]{\fp_compare_<:} -%\begin{macro}[aux]{\fp_compare_>:} +%\begin{macro}[aux]{\fp_compare_<_aux:} %\begin{macro}[aux]{\fp_compare_absolute_a>b:} %\begin{macro}[aux]{\fp_compare_absolute_a<b:} +%\begin{macro}[aux]{\fp_compare_>:} % The idea for the comparisons is to provide two versions: slower and % faster. The lead off for both is the same: get the two numbers % read and then look for a function to handle the comparison. @@ -3852,61 +3853,79 @@ \tex_fi:D } % \end{macrocode} -% For comparators life is a lot more complex, as there are three cases -% for the integer part (equality as well as greater and less than). The -% code here is quite repetitive to keep speed up, and simply does -% exhaustive checks. +% Comparing two values is quite complex. First, there is a filter step +% to check if one or other of the given values is zero. If it is then +% the result is relatively easy to determine. % \begin{macrocode} \cs_new_protected_nopar:cpn { fp_compare_>: } { - \tex_ifnum:D \l_fp_input_a_sign_int > \l_fp_input_b_sign_int - \group_end: - \prg_return_true: - \tex_else:D - \tex_ifnum:D \l_fp_input_a_sign_int < \l_fp_input_b_sign_int + \tex_ifnum:D \etex_numexpr:D + \l_fp_input_a_integer_int + \l_fp_input_a_decimal_int + = \c_zero + \tex_ifnum:D \etex_numexpr:D + \l_fp_input_b_integer_int + \l_fp_input_b_decimal_int + = \c_zero \group_end: \prg_return_false: \tex_else:D - \tex_ifnum:D \l_fp_input_a_sign_int > \c_zero - \use:c { fp_compare_absolute_a > b: } + \tex_ifnum:D \l_fp_input_b_sign_int > \c_zero + \group_end: + \prg_return_false: \tex_else:D - \use:c { fp_compare_absolute_a < b: } + \group_end: + \prg_return_true: \tex_fi:D - \tex_fi:D + \tex_fi:D + \tex_else:D + \tex_ifnum:D \etex_numexpr:D + \l_fp_input_b_integer_int + \l_fp_input_b_decimal_int + = \c_zero + \tex_ifnum:D \l_fp_input_a_sign_int > \c_zero + \group_end: + \prg_return_true: + \tex_else:D + \group_end: + \prg_return_false: + \tex_fi:D + \tex_else:D + \use:c { fp_compare_>_aux: } + \tex_fi:D \tex_fi:D } -\cs_new_protected_nopar:cpn { fp_compare_<: } { - \tex_ifnum:D \l_fp_input_b_sign_int > \l_fp_input_a_sign_int +% \end{macrocode} +% Next, check the sign of the input: this again may give an obvious +% result. If both signs are the same, then hand off to comparing the +% absolute values. +% \begin{macrocode} +\cs_new_protected_nopar:cpn { fp_compare_>_aux: } { + \tex_ifnum:D \l_fp_input_a_sign_int > \l_fp_input_b_sign_int \group_end: \prg_return_true: \tex_else:D - \tex_ifnum:D \l_fp_input_b_sign_int < \l_fp_input_a_sign_int + \tex_ifnum:D \l_fp_input_a_sign_int < \l_fp_input_b_sign_int \group_end: \prg_return_false: \tex_else:D - \tex_ifnum:D \l_fp_input_b_sign_int > \c_zero - \use:c { fp_compare_absolute_a < b: } + \tex_ifnum:D \l_fp_input_a_sign_int > \c_zero + \use:c { fp_compare_absolute_a>b: } \tex_else:D - \use:c { fp_compare_absolute_a > b: } + \use:c { fp_compare_absolute_a<b: } \tex_fi:D \tex_fi:D - \tex_fi:D + \tex_fi:D } -\cs_new_protected_nopar:cpn { fp_compare_absolute_a > b: } { +% \end{macrocode} +% Rather long runs of checks, as there is the need to go through each +% layer of the input and do the comparison. There is also the need to +% avoid messing up with equal inputs at each stage. +% \begin{macrocode} +\cs_new_protected_nopar:cpn { fp_compare_absolute_a>b: } { \tex_ifnum:D \l_fp_input_a_exponent_int > \l_fp_input_b_exponent_int \group_end: \prg_return_true: \tex_else:D \tex_ifnum:D \l_fp_input_a_exponent_int < \l_fp_input_b_exponent_int - \tex_ifnum:D - \etex_numexpr:D - \l_fp_input_b_integer_int + \l_fp_input_b_decimal_int - = \c_zero - \group_end: - \prg_return_true: - \tex_else:D - \group_end: - \prg_return_false: - \tex_fi:D + \group_end: + \prg_return_false: \tex_else:D \tex_ifnum:D \l_fp_input_a_integer_int > \l_fp_input_b_integer_int \group_end: @@ -3930,18 +3949,10 @@ \tex_fi:D \tex_fi:D } -\cs_new_protected_nopar:cpn { fp_compare_absolute_a < b: } { +\cs_new_protected_nopar:cpn { fp_compare_absolute_a<b: } { \tex_ifnum:D \l_fp_input_b_exponent_int > \l_fp_input_a_exponent_int - \tex_ifnum:D - \etex_numexpr:D - \l_fp_input_b_integer_int + \l_fp_input_b_decimal_int - = \c_zero - \group_end: - \prg_return_false: - \tex_else:D - \group_end: - \prg_return_true: - \tex_fi:D + \group_end: + \prg_return_true: \tex_else:D \tex_ifnum:D \l_fp_input_b_exponent_int < \l_fp_input_a_exponent_int \group_end: @@ -3969,8 +3980,35 @@ \tex_fi:D \tex_fi:D } - % \end{macrocode} +% This is just a case of reversing the two input values and then +% running the tests already defined. +% \begin{macrocode} +\cs_new_protected_nopar:cpn { fp_compare_<: } { + \tl_set:Nx \l_fp_tmp_tl + { + \int_set:Nn \exp_not:N \l_fp_input_a_sign_int + { \int_use:N \l_fp_input_b_sign_int } + \int_set:Nn \exp_not:N \l_fp_input_a_integer_int + { \int_use:N \l_fp_input_b_integer_int } + \int_set:Nn \exp_not:N \l_fp_input_a_decimal_int + { \int_use:N \l_fp_input_b_decimal_int } + \int_set:Nn \exp_not:N \l_fp_input_a_exponent_int + { \int_use:N \l_fp_input_b_exponent_int } + \int_set:Nn \exp_not:N \l_fp_input_b_sign_int + { \int_use:N \l_fp_input_a_sign_int } + \int_set:Nn \exp_not:N \l_fp_input_b_integer_int + { \int_use:N \l_fp_input_a_integer_int } + \int_set:Nn \exp_not:N \l_fp_input_b_decimal_int + { \int_use:N \l_fp_input_a_decimal_int } + \int_set:Nn \exp_not:N \l_fp_input_b_exponent_int + { \int_use:N \l_fp_input_a_exponent_int } + } + \l_fp_tmp_tl + \use:c { fp_compare_>: } +} +% \end{macrocode} +%\end{macro} %\end{macro} %\end{macro} %\end{macro} |