# Addition/Multiplication of quantities with uncertainties in siunitx

Related with this question, I would like to perform arithmetic operations of siunitx numbers that have uncertainties. For example multiply two numbers using \mult{0.2(1)e2}{2(1)e2} should give 0.4(3)e4 calculating the error in quadrature. Ignoring the uncertainties and giving 0.4e4 is also fine. The problem is that the input numbers contain uncertainties because they are given in a series of macros using the parenthesis form for the errors, and they are not handled correctly by the expl3 module.

Edit: This is a MWE although it does not work at the moment. If a round off parameter of 2 is supplied to the function it should give 5.45.

\documentclass{article}

\usepackage{siunitx}
\usepackage{expl3}

\newcommand{\a}{6.0(1)e2}
\newcommand{\b}{1.1(1)e2}

\ExplSyntaxOn
\NewDocumentCommand \Func {m m m}
{
\fp_eval:n { round( #1/#2, #3 ) }
}
\ExplSyntaxOff

\begin{document}

\Func{\a}{\b}{2}

\end{document}

• Could you supply us with your actual use-case as input in the form of a minimal example? We need to know whether you manually type 0.2(1), or whether you get that from a file, or perhaps it's part of a n (expandable) macro. Again, a minimal example (that starts with \documentclass{article} and ends with \end{document}). – Werner May 23 '17 at 17:45
• I have added a minimal example – gypaetus May 23 '17 at 18:03

The following code will at least achieve one of your goals: calculating the result and ignoring the uncertainty (the example will output 5.45).

If you would like to calculate the uncertainties have a look at \regex_extract_... in interface3.pdf which allows you to make a match out of the regex below and then use the numbers given to calculate the error as you like.

\documentclass{article}

\usepackage{siunitx}
\usepackage{expl3}

\newcommand{\one}{6.0(1)e2}
\newcommand{\two}{1.1(1)e2}

\ExplSyntaxOn
\NewDocumentCommand \Func {m m m}
{
\tl_set:Nx \l_tmpa_tl { #1 }
\regex_replace_once:nnN { $$\d$$ } { } \l_tmpa_tl
\tl_set:Nx \l_tmpb_tl { #2 }
\regex_replace_once:nnN { $$\d$$ } { } \l_tmpb_tl
\fp_eval:n { round( \l_tmpa_tl / \l_tmpb_tl, #3 ) }
}
\ExplSyntaxOff

\begin{document}

\Func{\one}{\two}{2}

\end{document}