\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \le 1.6421156666632428 \cdot 10^{+125}:\\
\;\;\;\;\frac{b \cdot d + a \cdot c}{d \cdot d + c \cdot c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{\sqrt{d \cdot d + c \cdot c}}\\
\end{array}double f(double a, double b, double c, double d) {
double r4413492 = a;
double r4413493 = c;
double r4413494 = r4413492 * r4413493;
double r4413495 = b;
double r4413496 = d;
double r4413497 = r4413495 * r4413496;
double r4413498 = r4413494 + r4413497;
double r4413499 = r4413493 * r4413493;
double r4413500 = r4413496 * r4413496;
double r4413501 = r4413499 + r4413500;
double r4413502 = r4413498 / r4413501;
return r4413502;
}
double f(double a, double b, double c, double d) {
double r4413503 = d;
double r4413504 = 1.6421156666632428e+125;
bool r4413505 = r4413503 <= r4413504;
double r4413506 = b;
double r4413507 = r4413506 * r4413503;
double r4413508 = a;
double r4413509 = c;
double r4413510 = r4413508 * r4413509;
double r4413511 = r4413507 + r4413510;
double r4413512 = r4413503 * r4413503;
double r4413513 = r4413509 * r4413509;
double r4413514 = r4413512 + r4413513;
double r4413515 = r4413511 / r4413514;
double r4413516 = sqrt(r4413514);
double r4413517 = r4413506 / r4413516;
double r4413518 = r4413505 ? r4413515 : r4413517;
return r4413518;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.2 |
|---|---|
| Target | 0.5 |
| Herbie | 25.1 |
if d < 1.6421156666632428e+125Initial program 22.6
rmApplied *-un-lft-identity22.6
Applied associate-/l*22.8
rmApplied *-un-lft-identity22.8
Applied *-un-lft-identity22.8
Applied times-frac22.8
Simplified22.8
Simplified22.6
if 1.6421156666632428e+125 < d Initial program 39.4
rmApplied add-sqr-sqrt39.4
Applied associate-/r*39.4
rmApplied div-inv39.4
Taylor expanded around 0 38.7
Final simplification25.1
herbie shell --seed 2019134
(FPCore (a b c d)
:name "Complex division, real part"
: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))))