\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 1.072590712044738796816282539617368693581 \cdot 10^{262}:\\
\;\;\;\;\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{-1 \cdot a}{\sqrt{c \cdot c + d \cdot d}}\\
\end{array}double f(double a, double b, double c, double d) {
double r185750 = a;
double r185751 = c;
double r185752 = r185750 * r185751;
double r185753 = b;
double r185754 = d;
double r185755 = r185753 * r185754;
double r185756 = r185752 + r185755;
double r185757 = r185751 * r185751;
double r185758 = r185754 * r185754;
double r185759 = r185757 + r185758;
double r185760 = r185756 / r185759;
return r185760;
}
double f(double a, double b, double c, double d) {
double r185761 = a;
double r185762 = c;
double r185763 = r185761 * r185762;
double r185764 = b;
double r185765 = d;
double r185766 = r185764 * r185765;
double r185767 = r185763 + r185766;
double r185768 = r185762 * r185762;
double r185769 = r185765 * r185765;
double r185770 = r185768 + r185769;
double r185771 = r185767 / r185770;
double r185772 = 1.0725907120447388e+262;
bool r185773 = r185771 <= r185772;
double r185774 = 1.0;
double r185775 = sqrt(r185770);
double r185776 = r185774 / r185775;
double r185777 = r185767 * r185776;
double r185778 = r185777 / r185775;
double r185779 = -1.0;
double r185780 = r185779 * r185761;
double r185781 = r185780 / r185775;
double r185782 = r185773 ? r185778 : r185781;
return r185782;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.3 |
|---|---|
| Target | 0.5 |
| Herbie | 25.8 |
if (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < 1.0725907120447388e+262Initial program 14.1
rmApplied add-sqr-sqrt14.1
Applied associate-/r*14.1
rmApplied div-inv14.1
if 1.0725907120447388e+262 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) Initial program 61.5
rmApplied add-sqr-sqrt61.5
Applied associate-/r*61.5
Taylor expanded around -inf 59.5
Final simplification25.8
herbie shell --seed 2019294
(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))))