\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -5.58972528481860216307208015835708105017 \cdot 10^{116}:\\
\;\;\;\;\frac{-b}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 4.790153388469599519369386020665188076147 \cdot 10^{114}:\\
\;\;\;\;\frac{\frac{b \cdot c}{\mathsf{hypot}\left(c, d\right)} - \frac{a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r5147800 = b;
double r5147801 = c;
double r5147802 = r5147800 * r5147801;
double r5147803 = a;
double r5147804 = d;
double r5147805 = r5147803 * r5147804;
double r5147806 = r5147802 - r5147805;
double r5147807 = r5147801 * r5147801;
double r5147808 = r5147804 * r5147804;
double r5147809 = r5147807 + r5147808;
double r5147810 = r5147806 / r5147809;
return r5147810;
}
double f(double a, double b, double c, double d) {
double r5147811 = c;
double r5147812 = -5.589725284818602e+116;
bool r5147813 = r5147811 <= r5147812;
double r5147814 = b;
double r5147815 = -r5147814;
double r5147816 = d;
double r5147817 = hypot(r5147811, r5147816);
double r5147818 = r5147815 / r5147817;
double r5147819 = 4.7901533884695995e+114;
bool r5147820 = r5147811 <= r5147819;
double r5147821 = r5147814 * r5147811;
double r5147822 = r5147821 / r5147817;
double r5147823 = a;
double r5147824 = r5147823 * r5147816;
double r5147825 = r5147824 / r5147817;
double r5147826 = r5147822 - r5147825;
double r5147827 = r5147826 / r5147817;
double r5147828 = r5147814 / r5147817;
double r5147829 = r5147820 ? r5147827 : r5147828;
double r5147830 = r5147813 ? r5147818 : r5147829;
return r5147830;
}




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.7 |
if c < -5.589725284818602e+116Initial program 41.3
Simplified41.3
rmApplied add-sqr-sqrt41.3
Applied associate-/r*41.3
rmApplied clear-num41.5
Simplified28.7
rmApplied associate-/r*28.1
Simplified28.1
Taylor expanded around -inf 15.8
Simplified15.8
if -5.589725284818602e+116 < c < 4.7901533884695995e+114Initial program 18.6
Simplified18.6
rmApplied add-sqr-sqrt18.6
Applied associate-/r*18.5
rmApplied clear-num18.7
Simplified11.8
rmApplied associate-/r*11.4
Simplified11.3
rmApplied div-sub11.3
if 4.7901533884695995e+114 < c Initial program 40.4
Simplified40.4
rmApplied add-sqr-sqrt40.4
Applied associate-/r*40.4
rmApplied clear-num40.4
Simplified27.7
rmApplied associate-/r*27.2
Simplified27.1
Taylor expanded around inf 15.4
Final simplification12.7
herbie shell --seed 2019200 +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))))