\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 r4713114 = b;
double r4713115 = c;
double r4713116 = r4713114 * r4713115;
double r4713117 = a;
double r4713118 = d;
double r4713119 = r4713117 * r4713118;
double r4713120 = r4713116 - r4713119;
double r4713121 = r4713115 * r4713115;
double r4713122 = r4713118 * r4713118;
double r4713123 = r4713121 + r4713122;
double r4713124 = r4713120 / r4713123;
return r4713124;
}
double f(double a, double b, double c, double d) {
double r4713125 = c;
double r4713126 = -7.729339549361261e+115;
bool r4713127 = r4713125 <= r4713126;
double r4713128 = b;
double r4713129 = d;
double r4713130 = hypot(r4713125, r4713129);
double r4713131 = r4713128 / r4713130;
double r4713132 = -r4713131;
double r4713133 = 1.512622379546738e+155;
bool r4713134 = r4713125 <= r4713133;
double r4713135 = a;
double r4713136 = -r4713129;
double r4713137 = r4713135 * r4713136;
double r4713138 = fma(r4713128, r4713125, r4713137);
double r4713139 = r4713138 / r4713130;
double r4713140 = r4713139 / r4713130;
double r4713141 = r4713134 ? r4713140 : r4713131;
double r4713142 = r4713127 ? r4713132 : r4713141;
return r4713142;
}




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))))