\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -1.47788539242579584930401717666761308705 \cdot 10^{104}:\\
\;\;\;\;\frac{-b}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{elif}\;c \le 1.336053818650175824019993309646752305462 \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 r5273918 = b;
double r5273919 = c;
double r5273920 = r5273918 * r5273919;
double r5273921 = a;
double r5273922 = d;
double r5273923 = r5273921 * r5273922;
double r5273924 = r5273920 - r5273923;
double r5273925 = r5273919 * r5273919;
double r5273926 = r5273922 * r5273922;
double r5273927 = r5273925 + r5273926;
double r5273928 = r5273924 / r5273927;
return r5273928;
}
double f(double a, double b, double c, double d) {
double r5273929 = c;
double r5273930 = -1.477885392425796e+104;
bool r5273931 = r5273929 <= r5273930;
double r5273932 = b;
double r5273933 = -r5273932;
double r5273934 = d;
double r5273935 = hypot(r5273934, r5273929);
double r5273936 = r5273933 / r5273935;
double r5273937 = 1.3360538186501758e+147;
bool r5273938 = r5273929 <= r5273937;
double r5273939 = r5273932 * r5273929;
double r5273940 = a;
double r5273941 = r5273934 * r5273940;
double r5273942 = r5273939 - r5273941;
double r5273943 = 1.0;
double r5273944 = r5273943 / r5273935;
double r5273945 = r5273942 * r5273944;
double r5273946 = r5273945 / r5273935;
double r5273947 = r5273932 / r5273935;
double r5273948 = r5273938 ? r5273946 : r5273947;
double r5273949 = r5273931 ? r5273936 : r5273948;
return r5273949;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.9 |
|---|---|
| Target | 0.4 |
| Herbie | 13.0 |
if c < -1.477885392425796e+104Initial program 39.8
Simplified39.8
rmApplied add-sqr-sqrt39.8
Applied associate-/r*39.7
rmApplied fma-udef39.7
Applied hypot-def39.7
rmApplied fma-udef39.7
Applied hypot-def27.0
Taylor expanded around -inf 16.6
Simplified16.6
if -1.477885392425796e+104 < c < 1.3360538186501758e+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 fma-udef18.9
Applied hypot-def11.7
rmApplied div-inv11.8
if 1.3360538186501758e+147 < c Initial program 42.8
Simplified42.8
rmApplied add-sqr-sqrt42.8
Applied associate-/r*42.8
rmApplied fma-udef42.8
Applied hypot-def42.8
rmApplied fma-udef42.8
Applied hypot-def27.8
Taylor expanded around inf 14.0
Final simplification13.0
herbie shell --seed 2019172 +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))))