\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 3.766759969790304202832221196437063478932 \cdot 10^{296}:\\
\;\;\;\;\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{b}{\sqrt{c \cdot c + d \cdot d}}\\
\end{array}double f(double a, double b, double c, double d) {
double r124505 = a;
double r124506 = c;
double r124507 = r124505 * r124506;
double r124508 = b;
double r124509 = d;
double r124510 = r124508 * r124509;
double r124511 = r124507 + r124510;
double r124512 = r124506 * r124506;
double r124513 = r124509 * r124509;
double r124514 = r124512 + r124513;
double r124515 = r124511 / r124514;
return r124515;
}
double f(double a, double b, double c, double d) {
double r124516 = a;
double r124517 = c;
double r124518 = r124516 * r124517;
double r124519 = b;
double r124520 = d;
double r124521 = r124519 * r124520;
double r124522 = r124518 + r124521;
double r124523 = r124517 * r124517;
double r124524 = r124520 * r124520;
double r124525 = r124523 + r124524;
double r124526 = r124522 / r124525;
double r124527 = 3.766759969790304e+296;
bool r124528 = r124526 <= r124527;
double r124529 = 1.0;
double r124530 = sqrt(r124525);
double r124531 = r124530 / r124522;
double r124532 = r124529 / r124531;
double r124533 = r124532 / r124530;
double r124534 = r124519 / r124530;
double r124535 = r124528 ? r124533 : r124534;
return r124535;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.9 |
|---|---|
| Target | 0.4 |
| Herbie | 25.2 |
if (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < 3.766759969790304e+296Initial program 14.2
rmApplied add-sqr-sqrt14.2
Applied associate-/r*14.1
rmApplied clear-num14.2
if 3.766759969790304e+296 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) Initial program 63.5
rmApplied add-sqr-sqrt63.5
Applied associate-/r*63.5
Taylor expanded around 0 60.4
Final simplification25.2
herbie shell --seed 2019350
(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))))