\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 r128877 = a;
double r128878 = c;
double r128879 = r128877 * r128878;
double r128880 = b;
double r128881 = d;
double r128882 = r128880 * r128881;
double r128883 = r128879 + r128882;
double r128884 = r128878 * r128878;
double r128885 = r128881 * r128881;
double r128886 = r128884 + r128885;
double r128887 = r128883 / r128886;
return r128887;
}
double f(double a, double b, double c, double d) {
double r128888 = a;
double r128889 = c;
double r128890 = r128888 * r128889;
double r128891 = b;
double r128892 = d;
double r128893 = r128891 * r128892;
double r128894 = r128890 + r128893;
double r128895 = r128889 * r128889;
double r128896 = r128892 * r128892;
double r128897 = r128895 + r128896;
double r128898 = r128894 / r128897;
double r128899 = 7.355127360692946e+283;
bool r128900 = r128898 <= r128899;
double r128901 = sqrt(r128897);
double r128902 = r128894 / r128901;
double r128903 = r128902 / r128901;
double r128904 = -1.0;
double r128905 = r128904 * r128888;
double r128906 = r128905 / r128901;
double r128907 = r128900 ? r128903 : r128906;
return r128907;
}




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))))