\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 7.355127360692946109502946832371947729711 \cdot 10^{283}:\\
\;\;\;\;\frac{\frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \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 r112868 = a;
double r112869 = c;
double r112870 = r112868 * r112869;
double r112871 = b;
double r112872 = d;
double r112873 = r112871 * r112872;
double r112874 = r112870 + r112873;
double r112875 = r112869 * r112869;
double r112876 = r112872 * r112872;
double r112877 = r112875 + r112876;
double r112878 = r112874 / r112877;
return r112878;
}
double f(double a, double b, double c, double d) {
double r112879 = a;
double r112880 = c;
double r112881 = r112879 * r112880;
double r112882 = b;
double r112883 = d;
double r112884 = r112882 * r112883;
double r112885 = r112881 + r112884;
double r112886 = r112880 * r112880;
double r112887 = r112883 * r112883;
double r112888 = r112886 + r112887;
double r112889 = r112885 / r112888;
double r112890 = 7.355127360692946e+283;
bool r112891 = r112889 <= r112890;
double r112892 = sqrt(r112888);
double r112893 = r112885 / r112892;
double r112894 = r112893 / r112892;
double r112895 = -1.0;
double r112896 = r112895 * r112879;
double r112897 = r112896 / r112892;
double r112898 = r112891 ? r112894 : r112897;
return r112898;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.2 |
|---|---|
| Target | 0.4 |
| Herbie | 25.4 |
if (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < 7.355127360692946e+283Initial program 14.2
rmApplied add-sqr-sqrt14.2
Applied associate-/r*14.1
if 7.355127360692946e+283 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) Initial program 62.9
rmApplied add-sqr-sqrt62.9
Applied associate-/r*62.9
Taylor expanded around -inf 59.8
Final simplification25.4
herbie shell --seed 2020001
(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))))