\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le 1.44736579362970321 \cdot 10^{65}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{\sqrt{c \cdot c + d \cdot d}}\\
\end{array}double f(double a, double b, double c, double d) {
double r106716 = a;
double r106717 = c;
double r106718 = r106716 * r106717;
double r106719 = b;
double r106720 = d;
double r106721 = r106719 * r106720;
double r106722 = r106718 + r106721;
double r106723 = r106717 * r106717;
double r106724 = r106720 * r106720;
double r106725 = r106723 + r106724;
double r106726 = r106722 / r106725;
return r106726;
}
double f(double a, double b, double c, double d) {
double r106727 = c;
double r106728 = 1.4473657936297032e+65;
bool r106729 = r106727 <= r106728;
double r106730 = a;
double r106731 = r106730 * r106727;
double r106732 = b;
double r106733 = d;
double r106734 = r106732 * r106733;
double r106735 = r106731 + r106734;
double r106736 = r106727 * r106727;
double r106737 = r106733 * r106733;
double r106738 = r106736 + r106737;
double r106739 = r106735 / r106738;
double r106740 = sqrt(r106738);
double r106741 = r106730 / r106740;
double r106742 = r106729 ? r106739 : r106741;
return r106742;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.3 |
|---|---|
| Target | 0.4 |
| Herbie | 26.3 |
if c < 1.4473657936297032e+65Initial program 23.4
if 1.4473657936297032e+65 < c Initial program 37.2
rmApplied add-sqr-sqrt37.2
Applied associate-/r*37.2
Taylor expanded around inf 37.2
Final simplification26.3
herbie shell --seed 2020047
(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))))