\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -9.959880769521784 \cdot 10^{+162}:\\
\;\;\;\;\frac{-b}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{elif}\;c \le 1.6080482430506382 \cdot 10^{+147}:\\
\;\;\;\;\frac{\left(b \cdot c - d \cdot a\right) \cdot \frac{1}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{\mathsf{hypot}\left(d, c\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r4736885 = b;
double r4736886 = c;
double r4736887 = r4736885 * r4736886;
double r4736888 = a;
double r4736889 = d;
double r4736890 = r4736888 * r4736889;
double r4736891 = r4736887 - r4736890;
double r4736892 = r4736886 * r4736886;
double r4736893 = r4736889 * r4736889;
double r4736894 = r4736892 + r4736893;
double r4736895 = r4736891 / r4736894;
return r4736895;
}
double f(double a, double b, double c, double d) {
double r4736896 = c;
double r4736897 = -9.959880769521784e+162;
bool r4736898 = r4736896 <= r4736897;
double r4736899 = b;
double r4736900 = -r4736899;
double r4736901 = d;
double r4736902 = hypot(r4736901, r4736896);
double r4736903 = r4736900 / r4736902;
double r4736904 = 1.6080482430506382e+147;
bool r4736905 = r4736896 <= r4736904;
double r4736906 = r4736899 * r4736896;
double r4736907 = a;
double r4736908 = r4736901 * r4736907;
double r4736909 = r4736906 - r4736908;
double r4736910 = 1.0;
double r4736911 = r4736910 / r4736902;
double r4736912 = r4736909 * r4736911;
double r4736913 = r4736912 / r4736902;
double r4736914 = r4736899 / r4736902;
double r4736915 = r4736905 ? r4736913 : r4736914;
double r4736916 = r4736898 ? r4736903 : r4736915;
return r4736916;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.4 |
|---|---|
| Target | 0.5 |
| Herbie | 12.6 |
if c < -9.959880769521784e+162Initial program 43.3
Simplified43.3
rmApplied add-sqr-sqrt43.3
Applied associate-/r*43.3
rmApplied fma-udef43.3
Applied hypot-def43.3
Taylor expanded around -inf 12.9
Simplified12.9
if -9.959880769521784e+162 < c < 1.6080482430506382e+147Initial program 19.0
Simplified19.0
rmApplied add-sqr-sqrt19.0
Applied associate-/r*18.9
rmApplied fma-udef18.9
Applied hypot-def18.9
rmApplied div-inv19.0
Simplified12.4
if 1.6080482430506382e+147 < c Initial program 43.4
Simplified43.4
rmApplied add-sqr-sqrt43.4
Applied associate-/r*43.4
rmApplied fma-udef43.4
Applied hypot-def43.4
rmApplied div-inv43.4
Simplified27.3
Taylor expanded around inf 13.4
Final simplification12.6
herbie shell --seed 2019134 +o rules:numerics
(FPCore (a b c d)
:name "Complex division, imag part"
: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))))