\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;a \le 6.495480430581795464113836761587821513134 \cdot 10^{224}:\\
\;\;\;\;\frac{\frac{b \cdot d + c \cdot a}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{d \cdot d + c \cdot c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-a}{\sqrt{d \cdot d + c \cdot c}}\\
\end{array}double f(double a, double b, double c, double d) {
double r6018890 = a;
double r6018891 = c;
double r6018892 = r6018890 * r6018891;
double r6018893 = b;
double r6018894 = d;
double r6018895 = r6018893 * r6018894;
double r6018896 = r6018892 + r6018895;
double r6018897 = r6018891 * r6018891;
double r6018898 = r6018894 * r6018894;
double r6018899 = r6018897 + r6018898;
double r6018900 = r6018896 / r6018899;
return r6018900;
}
double f(double a, double b, double c, double d) {
double r6018901 = a;
double r6018902 = 6.4954804305817955e+224;
bool r6018903 = r6018901 <= r6018902;
double r6018904 = b;
double r6018905 = d;
double r6018906 = r6018904 * r6018905;
double r6018907 = c;
double r6018908 = r6018907 * r6018901;
double r6018909 = r6018906 + r6018908;
double r6018910 = r6018905 * r6018905;
double r6018911 = r6018907 * r6018907;
double r6018912 = r6018910 + r6018911;
double r6018913 = sqrt(r6018912);
double r6018914 = r6018909 / r6018913;
double r6018915 = r6018914 / r6018913;
double r6018916 = -r6018901;
double r6018917 = r6018916 / r6018913;
double r6018918 = r6018903 ? r6018915 : r6018917;
return r6018918;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.6 |
|---|---|
| Target | 0.5 |
| Herbie | 27.2 |
if a < 6.4954804305817955e+224Initial program 25.6
rmApplied add-sqr-sqrt25.6
Applied associate-/r*25.5
if 6.4954804305817955e+224 < a Initial program 42.0
rmApplied add-sqr-sqrt42.0
Applied associate-/r*41.9
Taylor expanded around -inf 52.0
Simplified52.0
Final simplification27.2
herbie shell --seed 2019171
(FPCore (a b c d)
:name "Complex division, real part"
: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))))