\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \le 3.67504458165974214 \cdot 10^{89}:\\
\;\;\;\;\frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{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 r121009 = b;
double r121010 = c;
double r121011 = r121009 * r121010;
double r121012 = a;
double r121013 = d;
double r121014 = r121012 * r121013;
double r121015 = r121011 - r121014;
double r121016 = r121010 * r121010;
double r121017 = r121013 * r121013;
double r121018 = r121016 + r121017;
double r121019 = r121015 / r121018;
return r121019;
}
double f(double a, double b, double c, double d) {
double r121020 = d;
double r121021 = 3.675044581659742e+89;
bool r121022 = r121020 <= r121021;
double r121023 = b;
double r121024 = c;
double r121025 = r121023 * r121024;
double r121026 = a;
double r121027 = r121026 * r121020;
double r121028 = r121025 - r121027;
double r121029 = r121024 * r121024;
double r121030 = r121020 * r121020;
double r121031 = r121029 + r121030;
double r121032 = sqrt(r121031);
double r121033 = r121028 / r121032;
double r121034 = r121033 / r121032;
double r121035 = -r121026;
double r121036 = r121035 / r121032;
double r121037 = r121022 ? r121034 : r121036;
return r121037;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.7 |
|---|---|
| Target | 0.5 |
| Herbie | 26.5 |
if d < 3.675044581659742e+89Initial program 23.7
rmApplied add-sqr-sqrt23.7
Applied associate-/r*23.6
if 3.675044581659742e+89 < d Initial program 38.6
rmApplied add-sqr-sqrt38.7
Applied associate-/r*38.6
Taylor expanded around 0 38.0
Simplified38.0
Final simplification26.5
herbie shell --seed 2020042
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
:herbie-target
(if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d)))))
(/ (- (* b c) (* a d)) (+ (* c c) (* d d))))