From 285f2e662f6dc37d227660aeb7624cac13004686 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Sun, 22 Aug 2021 03:00:40 +0000 Subject: CTAN sync 202108220300 --- macros/latex/contrib/siunitx/siunitx-number.dtx | 137 ++++++++++++++---------- 1 file changed, 82 insertions(+), 55 deletions(-) (limited to 'macros/latex/contrib/siunitx/siunitx-number.dtx') diff --git a/macros/latex/contrib/siunitx/siunitx-number.dtx b/macros/latex/contrib/siunitx/siunitx-number.dtx index 924aaa3b0f..25e15ca4bb 100644 --- a/macros/latex/contrib/siunitx/siunitx-number.dtx +++ b/macros/latex/contrib/siunitx/siunitx-number.dtx @@ -2765,11 +2765,16 @@ % \begin{macro}[EXP]{\@@_round_uncertainty:nnnnnnn} % \begin{macro}[EXP]{\@@_round_uncertainty_end:nn} % \begin{macro}[EXP]{\@@_round_uncertainty:nnn} -% \begin{macro}[EXP]{\@@_round_uncertainty:nnnnn, \@@_round_uncertainty_aux:nnnnn} -% \begin{macro}[EXP]{\@@_round_uncertainty_aux:nnnnnn} +% \begin{macro}[EXP]{\@@_round_uncertainty:nnnn} +% \begin{macro}[EXP]{\@@_round_uncertainty:nnnnn} +% \begin{macro}[EXP] +% { +% \@@_round_uncertainty_simple:nnnnnn , +% \@@_round_uncertainty_shift:nnnnnn +% } % \begin{macro}[EXP]{\@@_round_uncertainty_shift:nn} % \begin{macro}[EXP]{\@@_round_uncertainty_shift:nnnw} -% \begin{macro}[EXP]{\@@_round_uncertainty_shift:nnnn} +% \begin{macro}[EXP]{\@@_round_uncertainty_shift_aux:nnnnn} % \begin{macro}[EXP] % { % \@@_round_uncertainty_engineering:nnn , @@ -2808,66 +2813,73 @@ { \exp_not:n { {#1} {#2} } } % \end{macrocode} % Round the uncertainty first: this is needed to get the number of places -% correct (for the case where the uncertainty rounds up to |1...|). Once that -% is done, it's just a question of working out the digits in the main part. +% correct. Once that is done, it's just a question of working out the digits +% in the main part. % \begin{macrocode} \cs_new:Npn \@@_round_uncertainty:nnn #1#2#3 { - \exp_last_unbraced:Nf \@@_round_uncertainty:nnnnn + \exp_args:Nf \@@_round_uncertainty:nnnn { - \@@_round:fnn - { - \int_eval:n - { \tl_count:n {#3} - \l_@@_round_precision_int } - } - { } {#3} + \int_eval:n + { \tl_count:n {#3} - \l_@@_round_precision_int } } {#1} {#2} {#3} } -\cs_new:Npn \@@_round_uncertainty:nnnnn #1#2#3#4#5 +\cs_new:Npn \@@_round_uncertainty:nnnn #1#2#3#4 { - \exp_args:Nff \@@_round_uncertainty_aux:nnnnn - { \int_eval:n { \tl_count:n {#5} - \tl_count:n {#2} } } - {#1} {#2} {#3} {#4} + \exp_last_unbraced:Nf \@@_round_uncertainty:nnnnn + { \@@_round:nnn {#1} { } {#4} } + {#2} {#3} {#1} } % \end{macrocode} -% The first argument here deals with the case where we've lost digits -% in the uncertainty and it's purely located in the integer part. +% Here, we need to work out how many digits to zero-fill the uncertainty, for +% the case where it crosses into the integer part. This depends on whether +% the uncertainty rounded up, which also links to additional treatment. We +% therefore split paths here. % \begin{macrocode} -\cs_new:Npn \@@_round_uncertainty_aux:nnnnn #1#2#3#4#5 +\cs_new:Npn \@@_round_uncertainty:nnnnn #1#2#3#4#5 { - \exp_args:Nf \@@_round_uncertainty_aux:nnnnnn + \tl_if_blank:nTF {#1} { - \prg_replicate:nn - { \int_max:nn { #1 - \tl_count:n {#5} } { 0 } } - { 0 } + \exp_args:Nf \@@_round_uncertainty_simple:nnnnn + { + \prg_replicate:nn + { + \int_max:nn + { 0 - ( \tl_count:n {#4} - \tl_count:n {#2} - #5 + 1 ) } + { 0 } + } + { 0 } + } + {#3} {#4} {#2} {#5} } - {#1} {#2} {#3} {#4} {#5} + { \@@_round_uncertainty_shift:nnnnn {#3} {#4} {#1} {#2} {#5} } + } -\cs_new:Npn \@@_round_uncertainty_aux:nnnnnn #1#2#3#4#5#6 +% \end{macrocode} +% The simple case: round and pad out the uncertainty as required. +% \begin{macrocode} +\cs_new:Npn \@@_round_uncertainty_simple:nnnnn #1#2#3#4#5 { - \tl_if_blank:nTF {#3} - { - \@@_round:nnn - {#2} - {#5} {#6} - { { S } { #4 #1 } } - } - { - \exp_args:Ne \@@_round_uncertainty_shift:nn - { - \@@_round:fnn - { \int_eval:n { #2 + 1 } } - {#5} {#6} - } - { { S } { #3 #1 } } - } + \@@_round:nnn + {#5} + {#2} {#3} + { { S } { #4 #1 } } + } +% \end{macrocode} +% \begin{macrocode} +\cs_new:Npn \@@_round_uncertainty_shift:nnnnn #1#2#3#4#5 + { + \exp_args:Ne \@@_round_uncertainty_shift:nn + { \@@_round:fnn { \int_eval:n { #5 + 1 } } {#1} {#2} } + {#5} } % \end{macrocode} -% We now have to clear up the exponent, plus deal with the case where -% rounding has resulted in the entire value being uncertain (|1(1)| with -% some exponent). The latter shows up if the uncertainty is too long or if -% we match a specific pattern. +% If the padding length is the same as the number of integer digits, then +% we have a pathological case and need to filter out. They show up as they +% have the either the precision greater than the length of the integer +% part, or have a value of exactly $10$ when the exponent mode is +% scientific. % \begin{macrocode} \cs_new:Npn \@@_round_uncertainty_shift:nn #1#2 { \@@_round_uncertainty_shift:nnnw #1 {#2} } @@ -2876,24 +2888,38 @@ { #4 \bool_lazy_and:nnTF + { \int_compare_p:nNn {#3} > { \tl_count:n {#1} } } { - \int_compare_p:nNn - { \tl_count:o { \use_ii:nn #3 } } = \l_@@_round_precision_int - } - { - ! \str_if_eq_p:nn { {#1} {#2} {#3} } { { 10 } { } { { S } { 1 } } } + ! \bool_lazy_and_p:nn + { \str_if_eq_p:Vn \l_@@_exponent_mode_tl { scientific } } + { \str_if_eq_p:nn { #1.#2 } { 10. } } } { - \use:c - { @@_round_ \l_@@_exponent_mode_tl :nn } - {#1} {#2} - \@@_round_places_end:nnn {#3} {#5} {#6} + \exp_args:Nf \@@_round_uncertainty_shift_aux:nnnnn + { + \prg_replicate:nn + { + \tl_if_blank:nTF {#2} + { \int_min:nn {#3} { \tl_count:n {#1} - 1 } } + { 0 } + } + { 0 } + } + {#1} {#2} } { \use:c { @@_round_uncertainty_ \l_@@_exponent_mode_tl :nnn } - {#1} {#5} {#6} + {#1} } + {#5} {#6} + } +\cs_new:Npn \@@_round_uncertainty_shift_aux:nnnnn #1#2#3#4#5 + { + \use:c + { @@_round_ \l_@@_exponent_mode_tl :nn } + {#2} {#3} + \@@_round_places_end:nnn { { S } { 1 #1 } } {#4} {#5} } % \end{macrocode} % With the data available, adjust the output such that the uncertainty @@ -2949,6 +2975,7 @@ % \end{macro} % \end{macro} % \end{macro} +% \end{macro} % % \begin{macro}{\@@_zero_decimal:NN} % \begin{macro}[EXP]{\@@_zero_decimal:nnnnnnn} -- cgit v1.2.3