\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -1.4037038847053747 \cdot 10^{+154}:\\
\;\;\;\;\frac{-b}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{elif}\;c \le 1.8584161242035747 \cdot 10^{+93}:\\
\;\;\;\;\frac{\frac{1}{\frac{\mathsf{hypot}\left(d, c\right)}{b \cdot c - a \cdot d}}}{\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 r1960697 = b;
double r1960698 = c;
double r1960699 = r1960697 * r1960698;
double r1960700 = a;
double r1960701 = d;
double r1960702 = r1960700 * r1960701;
double r1960703 = r1960699 - r1960702;
double r1960704 = r1960698 * r1960698;
double r1960705 = r1960701 * r1960701;
double r1960706 = r1960704 + r1960705;
double r1960707 = r1960703 / r1960706;
return r1960707;
}
double f(double a, double b, double c, double d) {
double r1960708 = c;
double r1960709 = -1.4037038847053747e+154;
bool r1960710 = r1960708 <= r1960709;
double r1960711 = b;
double r1960712 = -r1960711;
double r1960713 = d;
double r1960714 = hypot(r1960713, r1960708);
double r1960715 = r1960712 / r1960714;
double r1960716 = 1.8584161242035747e+93;
bool r1960717 = r1960708 <= r1960716;
double r1960718 = 1.0;
double r1960719 = r1960711 * r1960708;
double r1960720 = a;
double r1960721 = r1960720 * r1960713;
double r1960722 = r1960719 - r1960721;
double r1960723 = r1960714 / r1960722;
double r1960724 = r1960718 / r1960723;
double r1960725 = r1960724 / r1960714;
double r1960726 = r1960711 / r1960714;
double r1960727 = r1960717 ? r1960725 : r1960726;
double r1960728 = r1960710 ? r1960715 : r1960727;
return r1960728;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.8 |
|---|---|
| Target | 0.4 |
| Herbie | 12.8 |
if c < -1.4037038847053747e+154Initial program 43.9
Simplified43.9
rmApplied add-sqr-sqrt43.9
Applied associate-/r*43.9
rmApplied fma-udef43.9
Applied hypot-def43.9
rmApplied fma-udef43.9
Applied hypot-def27.1
Taylor expanded around -inf 13.2
Simplified13.2
if -1.4037038847053747e+154 < c < 1.8584161242035747e+93Initial program 18.9
Simplified18.9
rmApplied add-sqr-sqrt18.9
Applied associate-/r*18.8
rmApplied fma-udef18.8
Applied hypot-def18.8
rmApplied fma-udef18.8
Applied hypot-def11.7
rmApplied clear-num11.8
if 1.8584161242035747e+93 < c Initial program 37.5
Simplified37.5
rmApplied add-sqr-sqrt37.5
Applied associate-/r*37.5
rmApplied fma-udef37.5
Applied hypot-def37.5
rmApplied fma-udef37.5
Applied hypot-def24.3
Taylor expanded around inf 15.9
Final simplification12.8
herbie shell --seed 2019151 +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))))