\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -1.7011328718966327 \cdot 10^{+126}:\\
\;\;\;\;\frac{-b}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{elif}\;c \le 3.326984136021426 \cdot 10^{+169}:\\
\;\;\;\;\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 r4021025 = b;
double r4021026 = c;
double r4021027 = r4021025 * r4021026;
double r4021028 = a;
double r4021029 = d;
double r4021030 = r4021028 * r4021029;
double r4021031 = r4021027 - r4021030;
double r4021032 = r4021026 * r4021026;
double r4021033 = r4021029 * r4021029;
double r4021034 = r4021032 + r4021033;
double r4021035 = r4021031 / r4021034;
return r4021035;
}
double f(double a, double b, double c, double d) {
double r4021036 = c;
double r4021037 = -1.7011328718966327e+126;
bool r4021038 = r4021036 <= r4021037;
double r4021039 = b;
double r4021040 = -r4021039;
double r4021041 = d;
double r4021042 = hypot(r4021041, r4021036);
double r4021043 = r4021040 / r4021042;
double r4021044 = 3.326984136021426e+169;
bool r4021045 = r4021036 <= r4021044;
double r4021046 = r4021039 * r4021036;
double r4021047 = a;
double r4021048 = r4021041 * r4021047;
double r4021049 = r4021046 - r4021048;
double r4021050 = 1.0;
double r4021051 = r4021050 / r4021042;
double r4021052 = r4021049 * r4021051;
double r4021053 = r4021052 / r4021042;
double r4021054 = r4021039 / r4021042;
double r4021055 = r4021045 ? r4021053 : r4021054;
double r4021056 = r4021038 ? r4021043 : r4021055;
return r4021056;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.7 |
|---|---|
| Target | 0.4 |
| Herbie | 12.2 |
if c < -1.7011328718966327e+126Initial program 41.4
Simplified41.4
rmApplied add-sqr-sqrt41.4
Applied associate-/r*41.4
rmApplied fma-udef41.4
Applied hypot-def41.4
rmApplied div-inv41.4
Simplified26.5
Taylor expanded around -inf 13.7
Simplified13.7
if -1.7011328718966327e+126 < c < 3.326984136021426e+169Initial program 19.2
Simplified19.2
rmApplied add-sqr-sqrt19.2
Applied associate-/r*19.1
rmApplied fma-udef19.1
Applied hypot-def19.1
rmApplied div-inv19.2
Simplified11.7
if 3.326984136021426e+169 < c Initial program 43.2
Simplified43.2
rmApplied add-sqr-sqrt43.2
Applied associate-/r*43.2
rmApplied fma-udef43.2
Applied hypot-def43.2
Taylor expanded around inf 13.4
Final simplification12.2
herbie shell --seed 2019138 +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))))