I know my answer is slightly off-topic. However there was in comments to main answer some discussion about numerical stability. With xint which computes algebra exactly you don't have to worry about whether some subtraction will induce lost digits; sure the square-root must be approximated but once done, all other computations being exact need no tricks about how to do the algebra best.
The second point is that there is a difficulty with siunitx
's \num
parsing being done before expansion of its argument. I had no such problem with for example \numprint
macro from numprint
package. So second point of answer is to explain how to use siunitx
's \num
with arguments evaluated via xint computations.
\documentclass[ngerman]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{siunitx}
\usepackage{xintexpr}
% workaround problem with siunitx \num parsing before expanding
% workaround done in a way allowing \num's optional parameters
\newcommand\numx[2][]{\begingroup\if\relax\detokenize{#1}\relax
\def\x{\endgroup\num}\else
\def\x{\endgroup\num[#1]}\fi
\expandafter\x\expandafter{\romannumeral-`0#2}}
% for example something like
% \numx[scientific-notation=true]{\xinttheiexpr[#1] x2\relax}
% in code below would work.
% when using numprint's \np I encountered no problem like the \num's ones
% no workaround as in the above appeared necessary then
% \usepackage[autolanguage, np]{numprint}
% \let\numx\np
\newcommand\quadSol[4][2]{%
% #1 = user specified fixed point precision for rounding the output
% #2 = a, #3 = b, #4 = c in ax^2 + bx + c
% IT IS ASSUMED a IS NOT ZERO
Die Gleichung mit $a=#2$, $b=#3$, $c=#4$ hat
\begingroup
%
% \xintdefvar does computations exactly with rational numbers
% the sqrt(x) function computes with the prevailing float
% precision set by \xintDigits. Default: 16 decimal digits.
% one can also do sqrt(x, P) for using another precision.
%
% \xinttheiexpr[N] does exact computation like \xintdefvar
% or \xinttheexpr, but it rounds final result to N decimal digits
% after decimal mark. There is no removal of trailing
% zeroes (this should be job of formatting macro).
%
\xintdefvar a := #2;%
\xintdefvar b := #3;%
\xintdefvar c := #4;%
\xintdefvar Delta := b*b - 4a*c;%
\xintifSgn{\xinttheexpr sgn(Delta)\relax}
{keine reellen Lösungen.}
{eine doppelte Lösung
${}\approx\numx{\xinttheiexpr[#1] -b/2a\relax}$.}
{zwei Lösungen
% We don't have to worry about numerical unstability because
% \xintdefvar (contrarily to \xintdeffloatvar) computes exactly!
% All the "loss" is in the square-root...
% By the way, let's compute it once only
% (use sqrt(Delta, P) for other precision P).
\xintdefvar sqrtDelta := sqrt(Delta);%
% The order x1, x2 is chosen to get x1 < x2 if a>0
\xintdefvar x1 := (-b-sqrtDelta)/2a;%
\xintdefvar x2 := (-b+sqrtDelta)/2a;%
%
% if we had been worried about numerical stability, we would have first
% defined x1 (if b>0) then get x2 by c/a/x1 formula.
%
% but we are not worried because we compute exactly...
% once the square root is approximated as a floating point number (by default
% with 16 digits of precision).
%
% Raw output from \xinttheexpr can not be fed to \num as it is in A/B[X]
% format. So we use \xinttheiexpr[N] (fixed-point) or \xintthefloatexpr[N]
% (floating-point, uses scientific notation only if exponent is out of
% -5,..,5 range as in Maple output).
%
$x_{1}\approx \numx{\xinttheiexpr[#1] x1\relax}$
and
$x_{2}\approx \numx{\xinttheiexpr[#1] x2\relax}$.
%\par
% Their sum is
% $x_1 + x_2 \approx \numx{\xinttheiexpr[#1] x1 + x2\relax}$, and their product
% ix $x_1 x_2 \approx \numx{\xinttheiexpr[#1] x1*x2\relax}$.
}%
\endgroup\par\medskip
}
\begin{document}
\quadSol{1}{2}{5}
\quadSol{1}{2}{-5}
\quadSol{1}{200}{1}
\quadSol[12]{1}{200}{1}
\quadSol{1}{10000}{1}
\quadSol[12]{1}{10000}{1}
% \quadSol{1}{-\xinttheiexpr[2] 1.73+3.27\relax}{\xinttheiexpr[4] 1.73*3.27\relax}
\end{document}
