\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 8.757218044757217587065948698275685768631 \cdot 10^{298}:\\
\;\;\;\;\frac{\left(a \cdot c + b \cdot d\right) \cdot \frac{1}{\sqrt{c \cdot c + d \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 r114860 = a;
double r114861 = c;
double r114862 = r114860 * r114861;
double r114863 = b;
double r114864 = d;
double r114865 = r114863 * r114864;
double r114866 = r114862 + r114865;
double r114867 = r114861 * r114861;
double r114868 = r114864 * r114864;
double r114869 = r114867 + r114868;
double r114870 = r114866 / r114869;
return r114870;
}
double f(double a, double b, double c, double d) {
double r114871 = a;
double r114872 = c;
double r114873 = r114871 * r114872;
double r114874 = b;
double r114875 = d;
double r114876 = r114874 * r114875;
double r114877 = r114873 + r114876;
double r114878 = r114872 * r114872;
double r114879 = r114875 * r114875;
double r114880 = r114878 + r114879;
double r114881 = r114877 / r114880;
double r114882 = 8.757218044757218e+298;
bool r114883 = r114881 <= r114882;
double r114884 = 1.0;
double r114885 = sqrt(r114880);
double r114886 = r114884 / r114885;
double r114887 = r114877 * r114886;
double r114888 = r114887 / r114885;
double r114889 = r114874 / r114885;
double r114890 = r114883 ? r114888 : r114889;
return r114890;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.0 |
|---|---|
| Target | 0.5 |
| Herbie | 25.2 |
if (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < 8.757218044757218e+298Initial program 14.0
rmApplied add-sqr-sqrt14.1
Applied associate-/r*14.0
rmApplied div-inv14.0
if 8.757218044757218e+298 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) Initial program 63.6
rmApplied add-sqr-sqrt63.6
Applied associate-/r*63.6
Taylor expanded around 0 60.6
Final simplification25.2
herbie shell --seed 2019303
(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))))