\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \le 7.389276722766793942363821003152316862188 \cdot 10^{104}:\\
\;\;\;\;\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{b}{\sqrt{c \cdot c + d \cdot d}}\\
\end{array}double f(double a, double b, double c, double d) {
double r65074 = a;
double r65075 = c;
double r65076 = r65074 * r65075;
double r65077 = b;
double r65078 = d;
double r65079 = r65077 * r65078;
double r65080 = r65076 + r65079;
double r65081 = r65075 * r65075;
double r65082 = r65078 * r65078;
double r65083 = r65081 + r65082;
double r65084 = r65080 / r65083;
return r65084;
}
double f(double a, double b, double c, double d) {
double r65085 = d;
double r65086 = 7.389276722766794e+104;
bool r65087 = r65085 <= r65086;
double r65088 = a;
double r65089 = c;
double r65090 = r65088 * r65089;
double r65091 = b;
double r65092 = r65091 * r65085;
double r65093 = r65090 + r65092;
double r65094 = r65089 * r65089;
double r65095 = r65085 * r65085;
double r65096 = r65094 + r65095;
double r65097 = sqrt(r65096);
double r65098 = r65093 / r65097;
double r65099 = r65098 / r65097;
double r65100 = r65091 / r65097;
double r65101 = r65087 ? r65099 : r65100;
return r65101;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.2 |
|---|---|
| Target | 0.4 |
| Herbie | 26.0 |
if d < 7.389276722766794e+104Initial program 23.2
rmApplied add-sqr-sqrt23.2
Applied associate-/r*23.2
if 7.389276722766794e+104 < d Initial program 39.2
rmApplied add-sqr-sqrt39.2
Applied associate-/r*39.2
Taylor expanded around 0 38.6
Final simplification26.0
herbie shell --seed 2019326
(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))))