\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \le 1.022096285157088796449452448047526613473 \cdot 10^{92}:\\
\;\;\;\;\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 r139047 = a;
double r139048 = c;
double r139049 = r139047 * r139048;
double r139050 = b;
double r139051 = d;
double r139052 = r139050 * r139051;
double r139053 = r139049 + r139052;
double r139054 = r139048 * r139048;
double r139055 = r139051 * r139051;
double r139056 = r139054 + r139055;
double r139057 = r139053 / r139056;
return r139057;
}
double f(double a, double b, double c, double d) {
double r139058 = d;
double r139059 = 1.0220962851570888e+92;
bool r139060 = r139058 <= r139059;
double r139061 = a;
double r139062 = c;
double r139063 = r139061 * r139062;
double r139064 = b;
double r139065 = r139064 * r139058;
double r139066 = r139063 + r139065;
double r139067 = r139062 * r139062;
double r139068 = r139058 * r139058;
double r139069 = r139067 + r139068;
double r139070 = sqrt(r139069);
double r139071 = r139066 / r139070;
double r139072 = r139071 / r139070;
double r139073 = r139064 / r139070;
double r139074 = r139060 ? r139072 : r139073;
return r139074;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.8 |
|---|---|
| Target | 0.4 |
| Herbie | 26.6 |
if d < 1.0220962851570888e+92Initial program 23.9
rmApplied add-sqr-sqrt23.9
Applied associate-/r*23.8
if 1.0220962851570888e+92 < d Initial program 39.6
rmApplied add-sqr-sqrt39.6
Applied associate-/r*39.6
Taylor expanded around 0 39.1
Final simplification26.6
herbie shell --seed 2019347
(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))))