\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le 1.728464397415736153089988456136233162691 \cdot 10^{95}:\\
\;\;\;\;\frac{\frac{a \cdot c + d \cdot b}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{\sqrt{c \cdot c + d \cdot d}}\\
\end{array}double f(double a, double b, double c, double d) {
double r91394 = a;
double r91395 = c;
double r91396 = r91394 * r91395;
double r91397 = b;
double r91398 = d;
double r91399 = r91397 * r91398;
double r91400 = r91396 + r91399;
double r91401 = r91395 * r91395;
double r91402 = r91398 * r91398;
double r91403 = r91401 + r91402;
double r91404 = r91400 / r91403;
return r91404;
}
double f(double a, double b, double c, double d) {
double r91405 = c;
double r91406 = 1.7284643974157362e+95;
bool r91407 = r91405 <= r91406;
double r91408 = a;
double r91409 = r91408 * r91405;
double r91410 = d;
double r91411 = b;
double r91412 = r91410 * r91411;
double r91413 = r91409 + r91412;
double r91414 = r91405 * r91405;
double r91415 = r91410 * r91410;
double r91416 = r91414 + r91415;
double r91417 = sqrt(r91416);
double r91418 = r91413 / r91417;
double r91419 = r91418 / r91417;
double r91420 = r91408 / r91417;
double r91421 = r91407 ? r91419 : r91420;
return r91421;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.0 |
|---|---|
| Target | 0.4 |
| Herbie | 25.8 |
if c < 1.7284643974157362e+95Initial program 23.0
rmApplied add-sqr-sqrt23.0
Applied associate-/r*22.9
Simplified22.9
if 1.7284643974157362e+95 < c Initial program 39.0
rmApplied add-sqr-sqrt39.0
Applied associate-/r*39.0
Simplified39.0
Taylor expanded around inf 38.3
Final simplification25.8
herbie shell --seed 2019209
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:herbie-target
(if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d)))))
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))