\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -7.729339549361261 \cdot 10^{+115}:\\
\;\;\;\;-\frac{b}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 1.512622379546738 \cdot 10^{+155}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(b, c, a \cdot \left(-d\right)\right)}{\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 r4665703 = b;
double r4665704 = c;
double r4665705 = r4665703 * r4665704;
double r4665706 = a;
double r4665707 = d;
double r4665708 = r4665706 * r4665707;
double r4665709 = r4665705 - r4665708;
double r4665710 = r4665704 * r4665704;
double r4665711 = r4665707 * r4665707;
double r4665712 = r4665710 + r4665711;
double r4665713 = r4665709 / r4665712;
return r4665713;
}
double f(double a, double b, double c, double d) {
double r4665714 = c;
double r4665715 = -7.729339549361261e+115;
bool r4665716 = r4665714 <= r4665715;
double r4665717 = b;
double r4665718 = d;
double r4665719 = hypot(r4665714, r4665718);
double r4665720 = r4665717 / r4665719;
double r4665721 = -r4665720;
double r4665722 = 1.512622379546738e+155;
bool r4665723 = r4665714 <= r4665722;
double r4665724 = a;
double r4665725 = -r4665718;
double r4665726 = r4665724 * r4665725;
double r4665727 = fma(r4665717, r4665714, r4665726);
double r4665728 = r4665727 / r4665719;
double r4665729 = r4665728 / r4665719;
double r4665730 = r4665723 ? r4665729 : r4665720;
double r4665731 = r4665716 ? r4665721 : r4665730;
return r4665731;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.7 |
|---|---|
| Target | 0.4 |
| Herbie | 12.6 |
if c < -7.729339549361261e+115Initial program 40.9
rmApplied add-sqr-sqrt40.9
Applied associate-/r*40.9
rmApplied hypot-def40.9
rmApplied hypot-def26.5
Taylor expanded around -inf 15.5
Simplified15.5
if -7.729339549361261e+115 < c < 1.512622379546738e+155Initial program 18.5
rmApplied add-sqr-sqrt18.5
Applied associate-/r*18.4
rmApplied hypot-def18.4
rmApplied hypot-def11.4
rmApplied fma-neg11.4
if 1.512622379546738e+155 < c Initial program 45.9
rmApplied add-sqr-sqrt45.9
Applied associate-/r*45.9
rmApplied hypot-def45.9
rmApplied hypot-def27.9
Taylor expanded around inf 15.7
Final simplification12.6
herbie shell --seed 2019162 +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))))