\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \le 1.26556292468671579 \cdot 10^{88}:\\
\;\;\;\;\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 r77221 = a;
double r77222 = c;
double r77223 = r77221 * r77222;
double r77224 = b;
double r77225 = d;
double r77226 = r77224 * r77225;
double r77227 = r77223 + r77226;
double r77228 = r77222 * r77222;
double r77229 = r77225 * r77225;
double r77230 = r77228 + r77229;
double r77231 = r77227 / r77230;
return r77231;
}
double f(double a, double b, double c, double d) {
double r77232 = d;
double r77233 = 1.2655629246867158e+88;
bool r77234 = r77232 <= r77233;
double r77235 = a;
double r77236 = c;
double r77237 = r77235 * r77236;
double r77238 = b;
double r77239 = r77238 * r77232;
double r77240 = r77237 + r77239;
double r77241 = r77236 * r77236;
double r77242 = r77232 * r77232;
double r77243 = r77241 + r77242;
double r77244 = sqrt(r77243);
double r77245 = r77240 / r77244;
double r77246 = r77245 / r77244;
double r77247 = r77238 / r77244;
double r77248 = r77234 ? r77246 : r77247;
return r77248;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.9 |
|---|---|
| Target | 0.4 |
| Herbie | 25.7 |
if d < 1.2655629246867158e+88Initial program 22.9
rmApplied add-sqr-sqrt22.9
Applied associate-/r*22.8
if 1.2655629246867158e+88 < d Initial program 38.6
rmApplied add-sqr-sqrt38.6
Applied associate-/r*38.6
Taylor expanded around 0 38.0
Final simplification25.7
herbie shell --seed 2019195
(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))))