\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 r106110 = a;
double r106111 = c;
double r106112 = r106110 * r106111;
double r106113 = b;
double r106114 = d;
double r106115 = r106113 * r106114;
double r106116 = r106112 + r106115;
double r106117 = r106111 * r106111;
double r106118 = r106114 * r106114;
double r106119 = r106117 + r106118;
double r106120 = r106116 / r106119;
return r106120;
}
double f(double a, double b, double c, double d) {
double r106121 = a;
double r106122 = c;
double r106123 = r106121 * r106122;
double r106124 = b;
double r106125 = d;
double r106126 = r106124 * r106125;
double r106127 = r106123 + r106126;
double r106128 = r106122 * r106122;
double r106129 = r106125 * r106125;
double r106130 = r106128 + r106129;
double r106131 = r106127 / r106130;
double r106132 = 7.355127360692946e+283;
bool r106133 = r106131 <= r106132;
double r106134 = sqrt(r106130);
double r106135 = r106127 / r106134;
double r106136 = r106135 / r106134;
double r106137 = -1.0;
double r106138 = r106137 * r106121;
double r106139 = r106138 / r106134;
double r106140 = r106133 ? r106136 : r106139;
return r106140;
}




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