\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -5.593465816654883 \cdot 10^{+120}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{elif}\;c \le 5.890254338149143 \cdot 10^{+202}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(c, a, d \cdot b\right)}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{\mathsf{hypot}\left(d, c\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r3697601 = a;
double r3697602 = c;
double r3697603 = r3697601 * r3697602;
double r3697604 = b;
double r3697605 = d;
double r3697606 = r3697604 * r3697605;
double r3697607 = r3697603 + r3697606;
double r3697608 = r3697602 * r3697602;
double r3697609 = r3697605 * r3697605;
double r3697610 = r3697608 + r3697609;
double r3697611 = r3697607 / r3697610;
return r3697611;
}
double f(double a, double b, double c, double d) {
double r3697612 = c;
double r3697613 = -5.593465816654883e+120;
bool r3697614 = r3697612 <= r3697613;
double r3697615 = a;
double r3697616 = -r3697615;
double r3697617 = d;
double r3697618 = hypot(r3697617, r3697612);
double r3697619 = r3697616 / r3697618;
double r3697620 = 5.890254338149143e+202;
bool r3697621 = r3697612 <= r3697620;
double r3697622 = b;
double r3697623 = r3697617 * r3697622;
double r3697624 = fma(r3697612, r3697615, r3697623);
double r3697625 = r3697624 / r3697618;
double r3697626 = r3697625 / r3697618;
double r3697627 = r3697615 / r3697618;
double r3697628 = r3697621 ? r3697626 : r3697627;
double r3697629 = r3697614 ? r3697619 : r3697628;
return r3697629;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.3 |
|---|---|
| Target | 0.4 |
| Herbie | 12.5 |
if c < -5.593465816654883e+120Initial program 40.2
Simplified40.2
rmApplied add-sqr-sqrt40.2
Applied associate-/r*40.2
rmApplied clear-num40.3
Simplified25.6
rmApplied associate-/r*24.9
Simplified24.9
Taylor expanded around -inf 13.6
Simplified13.6
if -5.593465816654883e+120 < c < 5.890254338149143e+202Initial program 20.3
Simplified20.3
rmApplied add-sqr-sqrt20.3
Applied associate-/r*20.2
rmApplied clear-num20.5
Simplified13.0
rmApplied associate-/r*12.6
Simplified12.5
if 5.890254338149143e+202 < c Initial program 41.7
Simplified41.7
rmApplied add-sqr-sqrt41.7
Applied associate-/r*41.7
rmApplied clear-num41.7
Simplified30.9
rmApplied associate-/r*29.9
Simplified29.8
Taylor expanded around inf 11.0
Final simplification12.5
herbie shell --seed 2019158 +o rules:numerics
(FPCore (a b c d)
:name "Complex division, real part"
:herbie-target
(if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d)))))
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))