\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -4.78970221325173028480304050242606063264 \cdot 10^{151}:\\
\;\;\;\;\frac{-b}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{elif}\;c \le 7.209078410675664983392874709740943245737 \cdot 10^{132}:\\
\;\;\;\;\frac{\frac{b \cdot c}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)} - \frac{\frac{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 r5188663 = b;
double r5188664 = c;
double r5188665 = r5188663 * r5188664;
double r5188666 = a;
double r5188667 = d;
double r5188668 = r5188666 * r5188667;
double r5188669 = r5188665 - r5188668;
double r5188670 = r5188664 * r5188664;
double r5188671 = r5188667 * r5188667;
double r5188672 = r5188670 + r5188671;
double r5188673 = r5188669 / r5188672;
return r5188673;
}
double f(double a, double b, double c, double d) {
double r5188674 = c;
double r5188675 = -4.78970221325173e+151;
bool r5188676 = r5188674 <= r5188675;
double r5188677 = b;
double r5188678 = -r5188677;
double r5188679 = d;
double r5188680 = hypot(r5188679, r5188674);
double r5188681 = r5188678 / r5188680;
double r5188682 = 7.209078410675665e+132;
bool r5188683 = r5188674 <= r5188682;
double r5188684 = r5188677 * r5188674;
double r5188685 = r5188684 / r5188680;
double r5188686 = r5188685 / r5188680;
double r5188687 = a;
double r5188688 = r5188679 * r5188687;
double r5188689 = r5188688 / r5188680;
double r5188690 = r5188689 / r5188680;
double r5188691 = r5188686 - r5188690;
double r5188692 = r5188677 / r5188680;
double r5188693 = r5188683 ? r5188691 : r5188692;
double r5188694 = r5188676 ? r5188681 : r5188693;
return r5188694;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.1 |
|---|---|
| Target | 0.4 |
| Herbie | 12.6 |
if c < -4.78970221325173e+151Initial program 44.6
Simplified44.6
rmApplied add-sqr-sqrt44.6
Applied associate-/r*44.6
rmApplied fma-udef44.6
Applied hypot-def44.6
Taylor expanded around -inf 13.0
Simplified13.0
if -4.78970221325173e+151 < c < 7.209078410675665e+132Initial program 19.2
Simplified19.2
rmApplied add-sqr-sqrt19.2
Applied associate-/r*19.1
rmApplied fma-udef19.1
Applied hypot-def19.1
rmApplied fma-udef19.1
Applied hypot-def12.1
rmApplied div-sub12.1
Applied div-sub12.1
if 7.209078410675665e+132 < c Initial program 42.3
Simplified42.3
rmApplied add-sqr-sqrt42.3
Applied associate-/r*42.3
rmApplied fma-udef42.3
Applied hypot-def42.3
Taylor expanded around inf 14.4
Final simplification12.6
herbie shell --seed 2019168 +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))))