\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \le 5.290220499438646573779156255085041511729 \cdot 10^{298}:\\
\;\;\;\;\frac{\frac{1}{\frac{\sqrt{c \cdot c + d \cdot d}}{a \cdot c + b \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1 \cdot a}{\sqrt{c \cdot c + d \cdot d}}\\
\end{array}double f(double a, double b, double c, double d) {
double r100390 = a;
double r100391 = c;
double r100392 = r100390 * r100391;
double r100393 = b;
double r100394 = d;
double r100395 = r100393 * r100394;
double r100396 = r100392 + r100395;
double r100397 = r100391 * r100391;
double r100398 = r100394 * r100394;
double r100399 = r100397 + r100398;
double r100400 = r100396 / r100399;
return r100400;
}
double f(double a, double b, double c, double d) {
double r100401 = a;
double r100402 = c;
double r100403 = r100401 * r100402;
double r100404 = b;
double r100405 = d;
double r100406 = r100404 * r100405;
double r100407 = r100403 + r100406;
double r100408 = r100402 * r100402;
double r100409 = r100405 * r100405;
double r100410 = r100408 + r100409;
double r100411 = r100407 / r100410;
double r100412 = 5.290220499438647e+298;
bool r100413 = r100411 <= r100412;
double r100414 = 1.0;
double r100415 = sqrt(r100410);
double r100416 = r100415 / r100407;
double r100417 = r100414 / r100416;
double r100418 = r100417 / r100415;
double r100419 = -1.0;
double r100420 = r100419 * r100401;
double r100421 = r100420 / r100415;
double r100422 = r100413 ? r100418 : r100421;
return r100422;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.1 |
|---|---|
| Target | 0.4 |
| Herbie | 25.4 |
if (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < 5.290220499438647e+298Initial program 14.4
rmApplied add-sqr-sqrt14.4
Applied associate-/r*14.3
rmApplied clear-num14.4
if 5.290220499438647e+298 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) Initial program 63.4
rmApplied add-sqr-sqrt63.4
Applied associate-/r*63.4
Taylor expanded around -inf 60.3
Final simplification25.4
herbie shell --seed 2019304
(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))))