\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{\frac{b \cdot c - d \cdot a}{\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 r5295990 = b;
double r5295991 = c;
double r5295992 = r5295990 * r5295991;
double r5295993 = a;
double r5295994 = d;
double r5295995 = r5295993 * r5295994;
double r5295996 = r5295992 - r5295995;
double r5295997 = r5295991 * r5295991;
double r5295998 = r5295994 * r5295994;
double r5295999 = r5295997 + r5295998;
double r5296000 = r5295996 / r5295999;
return r5296000;
}
double f(double a, double b, double c, double d) {
double r5296001 = c;
double r5296002 = -1.477885392425796e+104;
bool r5296003 = r5296001 <= r5296002;
double r5296004 = b;
double r5296005 = d;
double r5296006 = hypot(r5296005, r5296001);
double r5296007 = r5296004 / r5296006;
double r5296008 = -r5296007;
double r5296009 = 1.3360538186501758e+147;
bool r5296010 = r5296001 <= r5296009;
double r5296011 = r5296004 * r5296001;
double r5296012 = a;
double r5296013 = r5296005 * r5296012;
double r5296014 = r5296011 - r5296013;
double r5296015 = r5296014 / r5296006;
double r5296016 = r5296015 / r5296006;
double r5296017 = r5296010 ? r5296016 : r5296007;
double r5296018 = r5296003 ? r5296008 : r5296017;
return r5296018;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.9 |
|---|---|
| Target | 0.4 |
| Herbie | 12.9 |
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
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 simplification12.9
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))))