\sqrt[3]{\frac{1}{2 \cdot a} \cdot \left(\left(-g\right) + \sqrt{g \cdot g - h \cdot h}\right)} + \sqrt[3]{\frac{1}{2 \cdot a} \cdot \left(\left(-g\right) - \sqrt{g \cdot g - h \cdot h}\right)}\begin{array}{l}
\mathbf{if}\;g \le -6.9942495558715367 \cdot 10^{-172}:\\
\;\;\;\;\sqrt[3]{\frac{1}{2 \cdot a}} \cdot \sqrt[3]{\left(-g\right) + \left|\sqrt[3]{g \cdot g - h \cdot h}\right| \cdot \sqrt{\sqrt[3]{g \cdot g - h \cdot h}}} + \sqrt[3]{\frac{1}{2 \cdot a}} \cdot \sqrt[3]{\left(-g\right) - \sqrt{g \cdot g - h \cdot h}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\frac{1}{2 \cdot a} \cdot \left(\left(-g\right) + \sqrt{g \cdot g - h \cdot h}\right)} + \sqrt[3]{\frac{1}{2 \cdot a}} \cdot \sqrt[3]{-2 \cdot g}\\
\end{array}double code(double g, double h, double a) {
return (cbrt(((1.0 / (2.0 * a)) * (-g + sqrt(((g * g) - (h * h)))))) + cbrt(((1.0 / (2.0 * a)) * (-g - sqrt(((g * g) - (h * h)))))));
}
double code(double g, double h, double a) {
double temp;
if ((g <= -6.994249555871537e-172)) {
temp = ((cbrt((1.0 / (2.0 * a))) * cbrt((-g + (fabs(cbrt(((g * g) - (h * h)))) * sqrt(cbrt(((g * g) - (h * h)))))))) + (cbrt((1.0 / (2.0 * a))) * cbrt((-g - sqrt(((g * g) - (h * h)))))));
} else {
temp = (cbrt(((1.0 / (2.0 * a)) * (-g + sqrt(((g * g) - (h * h)))))) + (cbrt((1.0 / (2.0 * a))) * cbrt((-2.0 * g))));
}
return temp;
}



Bits error versus g



Bits error versus h



Bits error versus a
Results
if g < -6.994249555871537e-172Initial program 35.5
rmApplied cbrt-prod35.4
rmApplied cbrt-prod31.9
rmApplied add-cube-cbrt31.9
Applied sqrt-prod31.9
Simplified31.9
if -6.994249555871537e-172 < g Initial program 37.0
rmApplied cbrt-prod33.1
Taylor expanded around inf 32.1
Final simplification32.0
herbie shell --seed 2020066 +o rules:numerics
(FPCore (g h a)
:name "2-ancestry mixing, positive discriminant"
:precision binary64
(+ (cbrt (* (/ 1 (* 2 a)) (+ (- g) (sqrt (- (* g g) (* h h)))))) (cbrt (* (/ 1 (* 2 a)) (- (- g) (sqrt (- (* g g) (* h h))))))))