\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 r62038 = a;
double r62039 = c;
double r62040 = r62038 * r62039;
double r62041 = b;
double r62042 = d;
double r62043 = r62041 * r62042;
double r62044 = r62040 + r62043;
double r62045 = r62039 * r62039;
double r62046 = r62042 * r62042;
double r62047 = r62045 + r62046;
double r62048 = r62044 / r62047;
return r62048;
}
double f(double a, double b, double c, double d) {
double r62049 = d;
double r62050 = 7.389276722766794e+104;
bool r62051 = r62049 <= r62050;
double r62052 = a;
double r62053 = c;
double r62054 = r62052 * r62053;
double r62055 = b;
double r62056 = r62055 * r62049;
double r62057 = r62054 + r62056;
double r62058 = r62053 * r62053;
double r62059 = r62049 * r62049;
double r62060 = r62058 + r62059;
double r62061 = sqrt(r62060);
double r62062 = r62057 / r62061;
double r62063 = r62062 / r62061;
double r62064 = r62055 / r62061;
double r62065 = r62051 ? r62063 : r62064;
return r62065;
}




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