\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;b \le -1.83333069166780128 \cdot 10^{209}:\\
\;\;\;\;\frac{b}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{1}{\sqrt{c \cdot c + d \cdot d}}\\
\end{array}double f(double a, double b, double c, double d) {
double r122417 = a;
double r122418 = c;
double r122419 = r122417 * r122418;
double r122420 = b;
double r122421 = d;
double r122422 = r122420 * r122421;
double r122423 = r122419 + r122422;
double r122424 = r122418 * r122418;
double r122425 = r122421 * r122421;
double r122426 = r122424 + r122425;
double r122427 = r122423 / r122426;
return r122427;
}
double f(double a, double b, double c, double d) {
double r122428 = b;
double r122429 = -1.8333306916678013e+209;
bool r122430 = r122428 <= r122429;
double r122431 = c;
double r122432 = r122431 * r122431;
double r122433 = d;
double r122434 = r122433 * r122433;
double r122435 = r122432 + r122434;
double r122436 = sqrt(r122435);
double r122437 = r122428 / r122436;
double r122438 = a;
double r122439 = r122438 * r122431;
double r122440 = r122428 * r122433;
double r122441 = r122439 + r122440;
double r122442 = r122441 / r122436;
double r122443 = 1.0;
double r122444 = r122443 / r122436;
double r122445 = r122442 * r122444;
double r122446 = r122430 ? r122437 : r122445;
return r122446;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.3 |
|---|---|
| Target | 0.5 |
| Herbie | 27.2 |
if b < -1.8333306916678013e+209Initial program 40.6
rmApplied add-sqr-sqrt40.6
Applied associate-/r*40.6
Taylor expanded around 0 52.0
if -1.8333306916678013e+209 < b Initial program 25.2
rmApplied add-sqr-sqrt25.2
Applied associate-/r*25.1
rmApplied div-inv25.2
Final simplification27.2
herbie shell --seed 2020056
(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))))