4

I have a problem with the siunitx package. In some cases the rounding is not correct (the position of the comma is not correct, see in the MWE I provided below).

Do you have any suggestions?

\documentclass[12pt, a4paper]{scrartcl}

\usepackage{siunitx}
\sisetup{round-mode=uncertainty, uncertainty-mode = separate, round-precision=3}

\begin{document}
Hello, this is a test with the package siuntix:

\num{0.478747 \pm 0.231349} (correct rounding)

\num{0.266548 \pm 10.8466}

The correct output should be instead: 0.3\,\pm \,10.8
\end{document}
2
  • 1
    Welcome to TeX.SE!
    – Zarko
    Aug 6 at 13:27
  • 1
    The uncertainty here is bigger than the value, so the rounding is meaningless; that said, I guess an error and/or totally sero output would be useful
    – Joseph Wright
    Aug 6 at 18:42

1 Answer 1

3

The next release of siunitx will check that there are enough digits to give a non-zero result on rounding to uncertainty. For the present, use:

\cs_gset:Npn \__siunitx_number_round_uncertainty:nnn #1#2#3
  {
     \__siunitx_number_round_uncertainty_check:nnnw {#1} {#2} {#3}
       #1#2 \q_recursion_tail \q_recursion_stop
  }
\cs_new:Npn \__siunitx_number_round_uncertainty_check:nnnw #1#2#3#4
  {
    \quark_if_recursion_tail_stop_do:Nn #4 { { 0 } { } { } }
    \int_compare:nNnTF {#4} = 0
      { \__siunitx_number_round_uncertainty_check:nnnw }
      { \__siunitx_number_round_uncertainty_check:Nnnnw #4 }
        {#1} {#2} {#3}
  }
\cs_new:Npn \__siunitx_number_round_uncertainty_check:Nnnnw #1#2#3#4#5
  \q_recursion_tail \q_recursion_stop
  {
    \int_compare:nNnTF { \tl_count:n {#1#5} } < { \tl_count:n {#4} }
      { { 0 } { } { } }
      {\__siunitx_number_round_uncertainty_aux:nnn {#2} {#3} {#4} }
  }
\cs_gset:Npn \__siunitx_number_round_uncertainty_aux:nnn #1#2#3
  {
    \exp_args:Nf \__siunitx_number_round_uncertainty:nnnn
      {
        \int_eval:n
          { \tl_count:n {#3} - \l__siunitx_number_round_precision_int }
      }
      {#1} {#2} {#3}
  }

(Note that this does not give your 'expected' result, which is wrong as the uncertainty is such that there is no useful value in the data.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.